Skip to content

Commit

Permalink
Move CRU initialisation to cable_driver_init_cru
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanBryan51 committed Nov 27, 2024
1 parent 4e66633 commit 9170df7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 57 deletions.
31 changes: 30 additions & 1 deletion src/offline/cable_driver_init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ MODULE cable_driver_init_mod
gswpfile, &
globalMetfile, &
set_group_output_values, &
timeunits
timeunits, &
exists
USE casadimension, ONLY : icycle
USE casavariable, ONLY : casafile
USE cable_namelist_util, ONLY : &
Expand All @@ -37,6 +38,7 @@ MODULE cable_driver_init_mod
USE cable_phys_constants_mod, ONLY : CTFRZ => TFRZ
USE cable_input_module, ONLY : open_met_file
USE CABLE_PLUME_MIP, ONLY : PLUME_MIP_TYPE, PLUME_MIP_INIT
USE CABLE_CRU, ONLY : CRU_TYPE, CRU_INIT
IMPLICIT NONE
PRIVATE

Expand Down Expand Up @@ -95,6 +97,7 @@ MODULE cable_driver_init_mod
PUBLIC :: cable_driver_init
PUBLIC :: cable_driver_init_gswp
PUBLIC :: cable_driver_init_plume
PUBLIC :: cable_driver_init_cru
PUBLIC :: cable_driver_init_site
PUBLIC :: cable_driver_init_default

Expand Down Expand Up @@ -283,4 +286,30 @@ SUBROUTINE cable_driver_init_plume(dels, koffset, PLUME)

END SUBROUTINE cable_driver_init_plume

SUBROUTINE cable_driver_init_cru(dels, koffset, CRU)
!* Model initialisation routine (CRU specific).
! TRENDY experiment using CRU-NCEP.
REAL, INTENT(OUT) :: dels !! Time step size in seconds
INTEGER, INTENT(OUT) :: koffset !! Timestep to start at
TYPE(CRU_TYPE), INTENT(OUT) :: CRU

CHARACTER(len=9) :: str1, str2, str3

CALL CRU_INIT(CRU)
dels = CRU%dtsecs
koffset = 0
leaps = .FALSE. ! No leap years in CRU-NCEP
exists%Snowf = .FALSE.
! No snow in CRU-NCEP, so ensure it will be determined from temperature
! in CABLE
WRITE(str1,'(i4)') cable_user%YearStart
str1 = ADJUSTL(str1)
WRITE(str2,'(i2)') 1
str2 = ADJUSTL(str2)
WRITE(str3,'(i2)') 1
str3 = ADJUSTL(str3)
timeunits="seconds since "//TRIM(str1)//"-"//TRIM(str2)//"-"//TRIM(str3)//"00:00"

END SUBROUTINE cable_driver_init_cru

END MODULE cable_driver_init_mod
33 changes: 4 additions & 29 deletions src/offline/cable_mpimaster.F90
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ MODULE cable_mpimaster

CONTAINS

SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME)
SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME, CRU)

USE mpi

USE cable_def_types_mod
USE cable_IO_vars_module, ONLY: logn,gswpfile,ncciy,leaps,globalMetfile, &
output,check,&
patch_type,landpt,&
timeunits, exists, output, &
timeunits, output, &
calendar
USE cable_common_module, ONLY: ktau_gl, kend_gl, knode_gl, cable_user, &
cable_runtime, fileName, &
Expand Down Expand Up @@ -212,7 +212,7 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME)
! PLUME-MIP only
USE CABLE_PLUME_MIP, ONLY: PLUME_MIP_TYPE, PLUME_MIP_GET_MET,&
PLUME_MIP_INIT
USE CABLE_CRU, ONLY: CRU_TYPE, CRU_GET_SUBDIURNAL_MET, CRU_INIT
USE CABLE_CRU, ONLY: CRU_TYPE, CRU_GET_SUBDIURNAL_MET

USE landuse_constant, ONLY: mstate,mvmax,mharvw
USE landuse_variable
Expand All @@ -228,6 +228,7 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME)
INTEGER, INTENT(INOUT) :: koffset !! Timestep to start at
INTEGER, INTENT(INOUT) :: kend !! No. of time steps in run
TYPE(PLUME_MIP_TYPE), INTENT(IN) :: PLUME
TYPE(CRU_TYPE), INTENT(IN) :: CRU

! timing variables
INTEGER, PARAMETER :: kstart = 1 ! start of simulation
Expand Down Expand Up @@ -275,7 +276,6 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME)
TYPE (POP_TYPE) :: POP
TYPE(POPLUC_TYPE) :: POPLUC
TYPE (LUC_EXPT_TYPE) :: LUC_EXPT
TYPE (CRU_TYPE) :: CRU
TYPE (landuse_mp) :: lucmp
CHARACTER :: cyear*4
CHARACTER :: ncfile*99
Expand Down Expand Up @@ -342,33 +342,8 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME)
ENDIF

IF ( TRIM(cable_user%MetType) .EQ. 'plum' ) THEN
! CLN HERE PLUME modfications
kend = NINT(24.0*3600.0/dels) * LOY
ELSE IF ( TRIM(cable_user%MetType) .EQ. 'cru' ) THEN
! CLN HERE CRU modfications
IF ( CALL1 ) THEN

CALL CPU_TIME(etime)
CALL CRU_INIT( CRU )

dels = CRU%dtsecs
koffset = 0
leaps = .FALSE. ! No leap years in CRU-NCEP
exists%Snowf = .FALSE. ! No snow in CRU-NCEP, so ensure it will
! be determined from temperature in CABLE

WRITE(str1,'(i4)') CurYear
str1 = ADJUSTL(str1)
WRITE(str2,'(i2)') 1
str2 = ADJUSTL(str2)
WRITE(str3,'(i2)') 1
str3 = ADJUSTL(str3)
timeunits="seconds since "//TRIM(str1)//"-"//TRIM(str2)//"-"//TRIM(str3)//" &
00:00"


ENDIF

LOY = 365
kend = NINT(24.0*3600.0/dels) * LOY
ELSE IF (TRIM(cable_user%MetType) .EQ. 'gswp') THEN
Expand Down
7 changes: 5 additions & 2 deletions src/offline/cable_offline_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ PROGRAM cable_offline_driver
USE cable_mpiworker
USE cable_common_module, ONLY : cable_user
USE CABLE_PLUME_MIP, ONLY : PLUME_MIP_TYPE
USE CABLE_CRU, ONLY : CRU_TYPE

IMPLICIT NONE

Expand All @@ -23,6 +24,7 @@ PROGRAM cable_offline_driver
INTEGER :: kend !! No. of time steps in run
INTEGER, ALLOCATABLE :: GSWP_MID(:,:) !! NetCDF file IDs for GSWP met forcing
TYPE(PLUME_MIP_TYPE) :: PLUME
TYPE(CRU_TYPE) :: CRU

call mpi_mod_init()
mpi_grp = mpi_grp_t()
Expand All @@ -37,6 +39,7 @@ PROGRAM cable_offline_driver
CASE('plum')
CALL cable_driver_init_plume(dels, koffset, PLUME)
CASE('cru')
CALL cable_driver_init_cru(dels, koffset, CRU)
CASE('site')
CALL cable_driver_init_site()
CALL cable_driver_init_default(dels, koffset, kend)
Expand All @@ -48,10 +51,10 @@ PROGRAM cable_offline_driver
END SELECT

IF (mpi_grp%size == 1) THEN
CALL serialdrv(trunk_sumbal, NRRRR, dels, koffset, kend, GSWP_MID, PLUME)
CALL serialdrv(trunk_sumbal, NRRRR, dels, koffset, kend, GSWP_MID, PLUME, CRU)
ELSE
IF (mpi_grp%rank == 0) THEN
CALL mpidrv_master(mpi_grp%comm, trunk_sumbal, dels, koffset, kend, PLUME)
CALL mpidrv_master(mpi_grp%comm, trunk_sumbal, dels, koffset, kend, PLUME, CRU)
ELSE
CALL mpidrv_worker(mpi_grp%comm)
END IF
Expand Down
29 changes: 4 additions & 25 deletions src/offline/cable_serial.F90
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ MODULE cable_serial
USE cable_IO_vars_module, ONLY: logn,gswpfile,ncciy,leaps, &
fixedCO2,output,check,&
patch_type,landpt,&
defaultLAI, sdoy, smoy, syear, timeunits, exists, calendar, &
defaultLAI, sdoy, smoy, syear, timeunits, calendar, &
NO_CHECK
USE casa_ncdf_module, ONLY: is_casa_time
USE cable_common_module, ONLY: ktau_gl, kend_gl, knode_gl, cable_user, &
Expand Down Expand Up @@ -131,7 +131,7 @@ MODULE cable_serial
USE CABLE_PLUME_MIP, ONLY: PLUME_MIP_TYPE, PLUME_MIP_GET_MET,&
PLUME_MIP_INIT

USE CABLE_CRU, ONLY: CRU_TYPE, CRU_GET_SUBDIURNAL_MET, CRU_INIT
USE CABLE_CRU, ONLY: CRU_TYPE, CRU_GET_SUBDIURNAL_MET
USE CABLE_site, ONLY: site_TYPE, site_INIT, site_GET_CO2_Ndep

! LUC_EXPT only
Expand All @@ -153,7 +153,7 @@ MODULE cable_serial

CONTAINS

SUBROUTINE serialdrv(trunk_sumbal, NRRRR, dels, koffset, kend, GSWP_MID, PLUME)
SUBROUTINE serialdrv(trunk_sumbal, NRRRR, dels, koffset, kend, GSWP_MID, PLUME, CRU)
!! Offline serial driver.
DOUBLE PRECISION, INTENT(IN) :: trunk_sumbal
!! Reference value for quasi-bitwise reproducibility checks.
Expand All @@ -163,6 +163,7 @@ SUBROUTINE serialdrv(trunk_sumbal, NRRRR, dels, koffset, kend, GSWP_MID, PLUME)
INTEGER, INTENT(INOUT) :: kend !! No. of time steps in run
INTEGER, ALLOCATABLE, INTENT(INOUT) :: GSWP_MID(:,:) !! NetCDF file IDs for GSWP met forcing
TYPE(PLUME_MIP_TYPE), INTENT(IN) :: PLUME
TYPE(CRU_TYPE), INTENT(IN) :: CRU

! timing variables
INTEGER, PARAMETER :: kstart = 1 ! start of simulation
Expand Down Expand Up @@ -216,7 +217,6 @@ SUBROUTINE serialdrv(trunk_sumbal, NRRRR, dels, koffset, kend, GSWP_MID, PLUME)
! vh_js !
TYPE (POP_TYPE) :: POP
TYPE(POPLUC_TYPE) :: POPLUC
TYPE (CRU_TYPE) :: CRU
TYPE (site_TYPE) :: site
TYPE (LUC_EXPT_TYPE) :: LUC_EXPT
TYPE (landuse_mp) :: lucmp
Expand Down Expand Up @@ -328,27 +328,6 @@ SUBROUTINE serialdrv(trunk_sumbal, NRRRR, dels, koffset, kend, GSWP_MID, PLUME)
kend = NINT(24.0*3600.0/dels) * LOY
ELSE IF ( TRIM(cable_user%MetType) .EQ. 'cru' ) THEN
! TRENDY experiment using CRU-NCEP
IF ( CALL1 ) THEN

CALL CPU_TIME(etime)
CALL CRU_INIT( CRU )

dels = CRU%dtsecs
koffset = 0
leaps = .FALSE. ! No leap years in CRU-NCEP
exists%Snowf = .FALSE. ! No snow in CRU-NCEP, so ensure it will
! be determined from temperature in CABLE

WRITE(str1,'(i4)') CurYear
str1 = ADJUSTL(str1)
WRITE(str2,'(i2)') 1
str2 = ADJUSTL(str2)
WRITE(str3,'(i2)') 1
str3 = ADJUSTL(str3)
timeunits="seconds since "//TRIM(str1)//"-"//TRIM(str2)//"-"//TRIM(str3)//"00:00"
calendar = "noleap"

ENDIF
LOY = 365
kend = NINT(24.0*3600.0/dels) * LOY
ELSE IF ( TRIM(cable_user%MetType) .EQ. 'site' ) THEN
Expand Down

0 comments on commit 9170df7

Please sign in to comment.