Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7d53910
Remove unused file
Whyborn Dec 12, 2025
b042689
Start substitution of datetime with initialisation
Whyborn Dec 16, 2025
0a75dc1
Add datetime module
Whyborn Dec 16, 2025
fe75799
Minor changes to make it compile
Whyborn Dec 16, 2025
4500c9e
Add end of period checks and apply them to is_casa_time
Whyborn Dec 16, 2025
8237986
More instances of specific timings being updated
Whyborn Dec 22, 2025
fb2f462
Take dt out of cable_input
Whyborn Jan 7, 2026
2a06a3d
Fix some typos
Whyborn Jan 7, 2026
6c73c32
try removing seemingly unused nday and ndays
Whyborn Jan 7, 2026
dd14d05
Temporarily reintroduce old IS_CASA_TIME function
Whyborn Jan 8, 2026
7677535
Change CASAONLY_LUC version of IS_CASA_TIME
Whyborn Jan 8, 2026
6915dd3
Remove doubly defined variable and re-add required variable
Whyborn Jan 8, 2026
2d6443b
Remove unused ktau variable from biogeochem
Whyborn Jan 8, 2026
a10efb5
Remove ktau from biogeochem body
Whyborn Jan 8, 2026
4e43da6
Reorder function args to be more logical
Whyborn Jan 8, 2026
ee020af
Fix data type of ktauday
Whyborn Jan 9, 2026
8470c00
Re-add accidentally removed line
Whyborn Jan 9, 2026
6ef1d3f
Fix is_casa_time args and move dt definition
Whyborn Jan 9, 2026
0d8a67d
missing s in keyword arg
Whyborn Jan 9, 2026
4a4c19a
Try to get the MPI building as well, and fix ts_start not being updated
Whyborn Jan 9, 2026
d142e36
Merge remote-tracking branch 'origin/656-use-datetime-to-control-time…
Whyborn Jan 9, 2026
946a0cc
add missing module
Whyborn Jan 9, 2026
4ad5260
Move calender selection to the offline driver
Whyborn Jan 9, 2026
6e2cd1e
Correct setcalendar name
Whyborn Jan 9, 2026
79e5cff
Import leaps to the main driver
Whyborn Jan 9, 2026
3c321a1
Fix type
Whyborn Jan 9, 2026
c1cd117
Fix typo
Whyborn Jan 9, 2026
af4d847
Final couple of fixes
Whyborn Jan 9, 2026
94487d0
Update ts_start at end of timestep
Whyborn Jan 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ else()
src/params/cable_maths_constants_mod.F90
src/util/cable_runtime_opts_mod.F90
src/util/cable_common.F90
src/util/datetime_module.f90
src/shared/casa_offline_inout.F90
src/shared/casa_ncdf.F90
src/offline/cable_iovars.F90
Expand Down

This file was deleted.

21 changes: 8 additions & 13 deletions src/offline/CASAONLY_LUC.F90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBROUTINE CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
SUBROUTINE CASAONLY_LUC(dels, curr_time, ktauday, veg,soil,casabiome,casapool, &
casaflux,casamet,casabal,phen,POP,climate,LALLOC,LUC_EXPT, POPLUC, &
sum_casapool, sum_casaflux )

Expand All @@ -24,15 +24,14 @@ SUBROUTINE CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
USE casa_cable
USE casa_inout_module
USE biogeochem_mod, ONLY : biogeochem
USE casa_offline_inout_module, ONLY : WRITE_CASA_OUTPUT_NC
USE casa_offline_inout_module, ONLY : WRITE_CASA_OUTPUT_NC
use datetime_module, only: datetime


IMPLICIT NONE
!!CLN CHARACTER(LEN=99), INTENT(IN) :: fcnpspin
REAL, INTENT(IN) :: dels
INTEGER, INTENT(IN) :: kstart
INTEGER, INTENT(IN) :: kend
INTEGER, INTENT(IN) :: LALLOC
INTEGER, INTENT(IN) :: LALLOC, ktauday
TYPE (veg_parameter_type), INTENT(INOUT) :: veg ! vegetation parameters
TYPE (soil_parameter_type), INTENT(INOUT) :: soil ! soil parameters
TYPE (casa_biome), INTENT(INOUT) :: casabiome
Expand All @@ -48,6 +47,7 @@ SUBROUTINE CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
TYPE (casa_pool) , INTENT(INOUT) :: sum_casapool
TYPE (casa_flux) , INTENT(INOUT) :: sum_casaflux

type(datetime), intent(in) :: curr_time


TYPE (casa_met) :: casaspin
Expand All @@ -66,8 +66,7 @@ SUBROUTINE CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
INTEGER :: myearspin,nyear, yyyy, nyear_dump
CHARACTER(LEN=99) :: ncfile
CHARACTER(LEN=4) :: cyear
INTEGER :: ktau,ktauday,nday,idoy,ktaux,ktauy,nloop
INTEGER, SAVE :: ndays
INTEGER :: idoy
REAL, DIMENSION(mp) :: cleaf2met, cleaf2str, croot2met, croot2str, cwood2cwd
REAL, DIMENSION(mp) :: nleaf2met, nleaf2str, nroot2met, nroot2str, nwood2cwd
REAL, DIMENSION(mp) :: pleaf2met, pleaf2str, proot2met, proot2str, pwood2cwd
Expand Down Expand Up @@ -97,8 +96,6 @@ SUBROUTINE CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
Iw = POP%Iwood
ENDIF

ktauday=INT(24.0*3600.0/dels)
nday=(kend-kstart+1)/ktauday
ctime = 0
CALL zero_sum_casa(sum_casapool, sum_casaflux)
count_sum_casa = 0
Expand Down Expand Up @@ -131,7 +128,6 @@ SUBROUTINE CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
CALL read_casa_dump( ncfile,casamet, casaflux, phen,climate, 1,1,.TRUE. )
!!CLN901 format(A99)
DO idoy=1,mdyear
ktau=(idoy-1)*ktauday +ktauday

casamet%tairk(:) = casamet%Tairkspin(:,idoy)
casamet%tsoil(:,1) = casamet%Tsoilspin_1(:,idoy)
Expand All @@ -158,7 +154,7 @@ SUBROUTINE CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
climate%qtemp_max_last_year(:) = casamet%mtempspin(:,idoy)


CALL biogeochem(ktau,dels,idoy,LALLOC,veg,soil,casabiome,casapool,casaflux, &
CALL biogeochem(dels,idoy,LALLOC,veg,soil,casabiome,casapool,casaflux, &
casamet,casabal,phen,POP,climate,xnplimit,xkNlimiting,xklitter, &
xksoil,xkleaf,xkleafcold,xkleafdry,&
cleaf2met,cleaf2str,croot2met,croot2str,cwood2cwd, &
Expand Down Expand Up @@ -270,8 +266,7 @@ SUBROUTINE CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
ENDIF ! end of year


IF ( IS_CASA_TIME("write", yyyy, ktau, kstart, &
0, kend, ktauday, logn) ) THEN
IF ( IS_CASA_TIME("write", curr_time, logn) ) THEN
ctime = ctime +1

CALL update_sum_casa(sum_casapool, sum_casaflux, casapool, casaflux, &
Expand Down
66 changes: 20 additions & 46 deletions src/offline/cable_mpimaster.F90
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)
USE landuse_variable
USE bgcdriver_mod, ONLY : bgcdriver
USE casa_offline_inout_module, ONLY : WRITE_CASA_RESTART_NC, WRITE_CASA_OUTPUT_NC

use datetime_module
IMPLICIT NONE

! MPI:
Expand Down Expand Up @@ -329,7 +331,8 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)
integer, dimension(:), allocatable, save :: cstart,cend,nap
real(r_2), dimension(:,:,:), allocatable, save :: patchfrac_new


type(datetime) :: ts_start, ts_end
type(timedelta) :: dt

! END header

Expand All @@ -340,16 +343,12 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)

CurYear = YYYY

!ccc Set calendar attribute: dependant on the value of `leaps`
! dependant on the MetType and set during initialisation.
calendar = "noleap"
LOY = 365
IF ( leaps ) THEN
calendar = "standard"
ENDIF
IF ( leaps .AND. IS_LEAPYEAR( YYYY ) ) THEN
LOY = 366
ENDIF
ts_start = datetime(year=YYYY, month=1, day=1)

LOY = daysInYear(YYYY)

! Set kend for all cases bar princeton and gswp
kend = ktauday * LOY

SELECT CASE (TRIM(cable_user%MetType))
CASE ('gswp', 'prin')
Expand Down Expand Up @@ -458,6 +457,8 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)
! file themselves
CALL MPI_Bcast (dels, 1, MPI_REAL, 0, comm, ierr)

dt = timedelta(seconds=int(dels))

! MPI: need to know extents before creating datatypes
CALL find_extents

Expand Down Expand Up @@ -673,14 +674,6 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)
ENDIF


! IF ( CASAONLY .AND. IS_CASA_TIME("dread", yyyy, iktau, kstart, koffset, &
! kend, ktauday, logn) ) THEN
! WRITE(CYEAR,FMT="(I4)")CurYear + INT((ktau-kstart+koffset)/(LOY*ktauday))
! ncfile = TRIM(casafile%c2cdumppath)//'c2c_'//CYEAR//'_dump.nc'
! casa_it = NINT( REAL(iktau / ktauday) )
! CALL read_casa_dump( ncfile, casamet, casaflux,phen, casa_it, kend, .FALSE. )
! ENDIF

canopy%oldcansto=canopy%cansto

! Zero out lai where there is no vegetation acc. to veg. index
Expand Down Expand Up @@ -710,6 +703,7 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)
iktau = iktau + 1
oktau = oktau + 1

ts_end = ts_start + dt
WRITE(logn,*) 'Progress -',REAL(ktau)/REAL(kend)*100.0

met%year = imet%year
Expand Down Expand Up @@ -748,15 +742,6 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)
(TRIM(cable_user%MetType) .NE. 'gswp3') .AND. &
(TRIM(cable_user%MetType) .NE. 'prin' )) CurYear = met%year(1)

!$ IF ( CASAONLY .AND. IS_CASA_TIME("dread", yyyy, iktau, kstart, koffset, &
!$ kend, ktauday, logn) ) THEN
!$ ! CLN READ FROM FILE INSTEAD !
!$ WRITE(CYEAR,FMT="(I4)")CurYear + INT((ktau-kstart+koffset)/(LOY*ktauday))
!$ ncfile = TRIM(casafile%c2cdumppath)//'c2c_'//CYEAR//'_dump.nc'
!$ casa_it = NINT( REAL(iktau / ktauday) )
!$ CALL read_casa_dump( ncfile, casamet, casaflux, casa_it, kend, .FALSE. )
!$ ENDIF

! Zero out lai where there is no vegetation acc. to veg. index
WHERE ( iveg%iveg(:) .GE. 14 ) iveg%vlai = 0.

Expand All @@ -775,8 +760,7 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)
CALL MPI_Waitall (wnp, recv_req, recv_stats, ierr)
! receive casa dump requirements from worker
IF ( ((.NOT.spinup).OR.(spinup.AND.spinConv)) .AND. &
( IS_CASA_TIME("dwrit", yyyy, oktau, kstart, &
koffset, kend, ktauday, logn) ) ) THEN
( IS_CASA_TIME("dwrit", ts_start, logn) ) ) THEN
CALL master_receive ( ocomm, oktau, casa_dump_ts )

! CALL MPI_Waitall (wnp, recv_req, recv_stats, ierr)
Expand All @@ -792,16 +776,6 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)
CALL master_send_input (icomm, inp_ts, iktau)
! CALL MPI_Waitall (wnp, inp_req, inp_stats, ierr)

!$ IF ( ((.NOT.spinup).OR.(spinup.AND.spinConv)) .AND. &
!$ ( IS_CASA_TIME("dwrit", yyyy, oktau, kstart, &
!$ koffset, kend, ktauday, logn) ) ) THEN
!$ WRITE(CYEAR,FMT="(I4)") CurYear + INT((ktau-kstart)/(LOY*ktauday))
!$ ncfile = TRIM(casafile%c2cdumppath)//'c2c_'//CYEAR//'_dump.nc'
!$ CALL write_casa_dump( ncfile, casamet , casaflux, idoy, &
!$ kend/ktauday )
!$
!$ ENDIF

IF (((.NOT.spinup).OR.(spinup.AND.spinConv)).AND. &
MOD((ktau-kstart+1),ktauday)==0) THEN
IF ( CABLE_USER%CASA_DUMP_WRITE ) THEN
Expand Down Expand Up @@ -838,8 +812,7 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)

IF ((.NOT.spinup).OR.(spinup.AND.spinConv)) THEN
IF (icycle >0) THEN
IF ( IS_CASA_TIME("write", yyyy, oktau, kstart, &
koffset, kend, ktauday, logn) ) THEN
IF ( IS_CASA_TIME("write", ts_start, logn) ) THEN
ctime = ctime +1


Expand Down Expand Up @@ -913,6 +886,8 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)

CALL1 = .FALSE.

ts_start = ts_end

!WRITE(*,*) " ktauloop end ", ktau, CurYear


Expand All @@ -934,9 +909,8 @@ SUBROUTINE mpidrv_master (comm, dels, koffset, kend, PLUME, CRU)

CALL master_receive (ocomm, oktau, casa_ts)

IF ( ((.NOT.spinup).OR.(spinup.AND.spinConv)) .AND. &
( IS_CASA_TIME("dwrit", yyyy, oktau, kstart, &
koffset, kend, ktauday, logn) ) ) THEN
IF (((.NOT.spinup).OR.(spinup.AND.spinConv)) .AND. &
( IS_CASA_TIME("dwrit", ts_start, logn))) THEN
CALL master_receive ( ocomm, oktau, casa_dump_ts )

ENDIF
Expand Down Expand Up @@ -8265,7 +8239,7 @@ SUBROUTINE master_CASAONLY_LUC( dels,kstart,kend,veg,casabiome,casapool, &
!$ ! zero annual sums
!$ if (idoy==1) CALL casa_cnpflux(casaflux,casapool,casabal,.TRUE.)

!$ CALL biogeochem(ktau,dels,idoy,LALLOC,veg,soil,casabiome,casapool,casaflux, &
!$ CALL biogeochem(dels,idoy,LALLOC,veg,soil,casabiome,casapool,casaflux, &
!$ casamet,casabal,phen,POP,climate,xnplimit,xkNlimiting,xklitter, &
!$ xksoil,xkleaf,xkleafcold,xkleafdry,&
!$ cleaf2met,cleaf2str,croot2met,croot2str,cwood2cwd, &
Expand Down
Loading