Skip to content

Commit

Permalink
Move consistency check initialisation into cable_driver_init
Browse files Browse the repository at this point in the history
Add new namelist options: filename%new_sumbal filename%trunk_sumbal
  • Loading branch information
SeanBryan51 committed Nov 15, 2024
1 parent 93c6cfb commit 8869691
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 73 deletions.
2 changes: 2 additions & 0 deletions documentation/docs/user_guide/inputs/cable_nml.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ applications. The following are annotated examples of cable.nml:
| filename%fxpft | character(len=500) | any string of max. 500 characters | uninitialised | Plant functional type fraction, wood harvest and secondary harvest file. |
| filename%fxluh2cable | character(len=500) | any string of max. 500 characters | uninitialised | 12 land-use states into 17 CABLE plant functional types mapping file name. |
| filename%gridnew | character(len=500) | any string of max. 500 characters | uninitialised | Updated gridinfo file name. |
| filename%trunk_sumbal | character(len=500) | any string of max. 500 characters | .trunk_sumbal | Input filename for combined fluxes at each timestep (control run) |
| filename%new_sumbal | character(len=500) | any string of max. 500 characters | new_sumbal | Output filename for combined fluxes at each timestep (current run) |
| vegparmnew | logical | .TRUE. .FALSE. | .FALSE. but was .TRUE. in ESM1.5 | Use new format for vegetation parameter files when .TRUE. |
| soilparmnew | logical | .TRUE. .FALSE. | uninitialised | Use new format for soil parameter files when .TRUE. |
| spinup | logical | .TRUE. .FALSE. | .FALSE. | Spin up the model when .TRUE. |
Expand Down
20 changes: 17 additions & 3 deletions src/offline/cable_driver_init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ MODULE cable_driver_init_mod
wiltParam, &
satuParam, &
cable_user, &
gw_params
gw_params, &
cable_runtime
USE cable_IO_vars_module, ONLY : &
soilparmnew, &
output, &
Expand Down Expand Up @@ -81,10 +82,13 @@ MODULE cable_driver_init_mod

CONTAINS

SUBROUTINE cable_driver_init(mpi_grp)
SUBROUTINE cable_driver_init(mpi_grp, trunk_sumbal)
!! Model initialisation routine for the CABLE offline driver.
TYPE(mpi_grp_t), INTENT(IN) :: mpi_grp !! MPI group to use
DOUBLE PRECISION, INTENT(OUT) :: trunk_sumbal
!! Reference value for quasi-bitwise reproducibility checks.

!! Model initialisation routine for the CABLE offline driver.
INTEGER :: ioerror

!check to see if first argument passed to cable is
!the name of the namelist file
Expand All @@ -102,6 +106,16 @@ SUBROUTINE cable_driver_init(mpi_grp)

cable_runtime%offline = .TRUE.

! Open, read and close the consistency check file.
! Check triggered by cable_user%consistency_check = .TRUE. in cable.nml
IF (mpi_grp%rank == 0 .AND. cable_user%consistency_check) THEN
OPEN(11, FILE=filename%trunk_sumbal, STATUS='old', ACTION='READ', IOSTAT=ioerror)
IF(ioerror == 0) THEN
READ(11, *) trunk_sumbal ! written by previous trunk version
ENDIF
CLOSE(11)
ENDIF

END SUBROUTINE cable_driver_init

END MODULE cable_driver_init_mod
27 changes: 5 additions & 22 deletions src/offline/cable_mpimaster.F90
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ MODULE cable_mpimaster

CONTAINS

SUBROUTINE mpidrv_master (comm)
SUBROUTINE mpidrv_master (comm, trunk_sumbal)

USE mpi

Expand Down Expand Up @@ -221,10 +221,11 @@ SUBROUTINE mpidrv_master (comm)
USE landuse_variable
USE bgcdriver_mod, ONLY : bgcdriver
USE casa_offline_inout_module, ONLY : WRITE_CASA_RESTART_NC, WRITE_CASA_OUTPUT_NC
IMPLICIT NONE

! MPI:
INTEGER :: comm ! MPI communicator for comms with the workers
DOUBLE PRECISION, INTENT(IN) :: trunk_sumbal
!! Reference value for quasi-bitwise reproducibility checks.

! CABLE namelist: model configuration, runtime/user switches
!CHARACTER(LEN=200), PARAMETER :: CABLE_NAMELIST='cable.nml'
Expand Down Expand Up @@ -308,21 +309,13 @@ SUBROUTINE mpidrv_master (comm)
INTEGER :: ierr
INTEGER :: rank, off, cnt

! Vars for standard for quasi-bitwise reproducability b/n runs
! Check triggered by cable_user%consistency_check = .TRUE. in cable.nml
CHARACTER(len=30), PARAMETER :: &
Ftrunk_sumbal = ".trunk_sumbal", &
Fnew_sumbal = "new_sumbal"

DOUBLE PRECISION, SAVE :: &
trunk_sumbal = 0.0, & !
new_sumbal = 0.0, &
new_sumfpn = 0.0, &
new_sumfe = 0.0

INTEGER :: count_bal = 0
INTEGER :: nkend=0
INTEGER :: ioerror=0

INTEGER :: kk,m,np,ivt
INTEGER :: LALLOC
Expand All @@ -343,16 +336,6 @@ SUBROUTINE mpidrv_master (comm)

! END header

! Open, read and close the consistency check file.
! Check triggered by cable_user%consistency_check = .TRUE. in cable.nml
IF(cable_user%consistency_check) THEN
OPEN( 11, FILE = Ftrunk_sumbal,STATUS='old',ACTION='READ',IOSTAT=ioerror )
IF(ioerror==0) THEN
READ( 11, * ) trunk_sumbal ! written by previous trunk version
ENDIF
CLOSE(11)
ENDIF

! Open log file:
OPEN(logn,FILE=filename%log)

Expand Down Expand Up @@ -996,9 +979,9 @@ SUBROUTINE mpidrv_master (comm)
"Internal check shows in this version new_sumbal != trunk sumbal"
PRINT *, "The difference is: ", new_sumbal - trunk_sumbal
PRINT *, &
"Writing new_sumbal to the file:", TRIM(Fnew_sumbal)
"Writing new_sumbal to the file:", TRIM(filename%new_sumbal)

!CLN OPEN( 12, FILE = Fnew_sumbal )
!CLN OPEN( 12, FILE = filename%new_sumbal )
!CLN WRITE( 12, '(F20.7)' ) new_sumbal ! written by previous trunk version
!CLN CLOSE(12)

Expand Down
3 changes: 2 additions & 1 deletion src/offline/cable_mpimaster_stub.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ MODULE cable_mpimaster

CONTAINS

SUBROUTINE mpidrv_master(comm)
SUBROUTINE mpidrv_master(comm, trunk_sumbal)
!! Stub for when MPI is not available
INTEGER, INTENT(IN) :: comm
DOUBLE PRECISION, INTENT(IN) :: trunk_sumbal

! This should never be called!
STOP
Expand Down
7 changes: 4 additions & 3 deletions src/offline/cable_offline_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ PROGRAM cable_offline_driver

REAL :: etime ! Declare the type of etime()
TYPE(mpi_grp_t) :: mpi_grp
DOUBLE PRECISION :: trunk_sumbal

call mpi_mod_init()
mpi_grp = mpi_grp_t()

CALL cable_driver_init(mpi_grp)
CALL cable_driver_init(mpi_grp, trunk_sumbal)

IF (mpi_grp%size == 1) THEN
CALL serialdrv()
CALL serialdrv(trunk_sumbal)
ELSE
IF (mpi_grp%rank == 0) THEN
CALL mpidrv_master(mpi_grp%comm)
CALL mpidrv_master(mpi_grp%comm, trunk_sumbal)
ELSE
CALL mpidrv_worker(mpi_grp%comm)
END IF
Expand Down
29 changes: 6 additions & 23 deletions src/offline/cable_serial.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ MODULE cable_serial
NO_CHECK
USE casa_ncdf_module, ONLY: is_casa_time
USE cable_common_module, ONLY: ktau_gl, kend_gl, knode_gl, cable_user, &
cable_runtime, filename, myhome, &
filename, myhome, &
CurYear, &
IS_LEAPYEAR, &
kwidth_gl
Expand Down Expand Up @@ -152,9 +152,10 @@ MODULE cable_serial

CONTAINS

SUBROUTINE serialdrv()
SUBROUTINE serialdrv(trunk_sumbal)
!! Offline serial driver.

DOUBLE PRECISION, INTENT(IN) :: trunk_sumbal

! CABLE namelist: model configuration, runtime/user switches
!CHARACTER(LEN=200), PARAMETER :: CABLE_NAMELIST='cable.nml'
! try to read in namelist from command line argument
Expand Down Expand Up @@ -251,14 +252,7 @@ SUBROUTINE serialdrv()
!mpidiff
INTEGER :: i,x,kk,m,np,ivt

! Vars for standard for quasi-bitwise reproducability b/n runs
! Check triggered by cable_user%consistency_check = .TRUE. in cable.nml
CHARACTER(len=30), PARAMETER :: &
Ftrunk_sumbal = ".trunk_sumbal", &
Fnew_sumbal = "new_sumbal"

DOUBLE PRECISION :: &
trunk_sumbal = 0.0, & !
new_sumbal = 0.0, &
new_sumfpn = 0.0, &
new_sumfe = 0.0
Expand All @@ -268,7 +262,6 @@ SUBROUTINE serialdrv()
REAL,ALLOCATABLE, SAVE :: xk(:,:)

INTEGER :: nkend=0
INTEGER :: ioerror
INTEGER :: count_bal = 0

! for landuse
Expand All @@ -283,16 +276,6 @@ SUBROUTINE serialdrv()

! END header

! Open, read and close the consistency check file.
! Check triggered by cable_user%consistency_check = .TRUE. in cable.nml
IF(cable_user%consistency_check) THEN
OPEN( 11, FILE = Ftrunk_sumbal,STATUS='old',ACTION='READ',IOSTAT=ioerror )
IF(ioerror==0) THEN
READ( 11, * ) trunk_sumbal ! written by previous trunk version
ENDIF
CLOSE(11)
ENDIF

! Open log file:
OPEN(logn,FILE=filename%log)

Expand Down Expand Up @@ -974,9 +957,9 @@ SUBROUTINE serialdrv()
PRINT *, &
"Internal check shows in this version new_sumbal != trunk sumbal"
PRINT *, &
"Writing new_sumbal to the file:", TRIM(Fnew_sumbal)
"Writing new_sumbal to the file:", TRIM(filename%new_sumbal)

OPEN( 12, FILE = Fnew_sumbal )
OPEN( 12, FILE = filename%new_sumbal )
WRITE( 12, '(F20.7)' ) new_sumbal ! written by previous trunk version
CLOSE(12)

Expand Down
42 changes: 21 additions & 21 deletions src/util/cable_common.F90
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,28 @@ MODULE cable_common_module
! instantiate internal switches
TYPE(kbl_internal_switches), SAVE :: cable_runtime

! external files read/written by CABLE
TYPE filenames_type

CHARACTER(LEN=500) :: &
met, & ! name of file for CABLE input
path='./', & ! path for output and restart files for CABLE and CASA
out, & ! name of file for CABLE output
log, & ! name of file for execution log
restart_in = ' ', & ! name of restart file to read
restart_out,& ! name of restart file to read
LAI, & ! name of file for default LAI
TYPE, & ! file for default veg/soil type
veg, & ! file for vegetation parameters
soil, & ! name of file for soil parameters
soilcolor, & ! file for soil color(soilcolor_global_1x1.nc)
inits, & ! name of file for initialisations
soilIGBP, & ! name of file for IGBP soil map
gw_elev, & !name of file for gw/elevation data
fxpft, & !filename for PFT fraction and transition,wood harvest, secondary harvest
fxluh2cable,& !filename for mapping 12 luc states into 17 CABLE PFT
gridnew !filename for updated gridinfo file

!! External files read/written by CABLE
CHARACTER(LEN=500) :: &
met, & !! name of file for CABLE input
path='./', & !! path for output and restart files for CABLE and CASA
out, & !! name of file for CABLE output
log, & !! name of file for execution log
restart_in = ' ', & !! name of restart file to read
restart_out, & !! name of restart file to read
LAI, & !! name of file for default LAI
TYPE, & !! file for default veg/soil type
veg, & !! file for vegetation parameters
soil, & !! name of file for soil parameters
soilcolor, & !! file for soil color(soilcolor_global_1x1.nc)
inits, & !! name of file for initialisations
soilIGBP, & !! name of file for IGBP soil map
gw_elev, & !! name of file for gw/elevation data
fxpft, & !! filename for PFT fraction and transition,wood harvest, secondary harvest
fxluh2cable, & !! filename for mapping 12 luc states into 17 CABLE PFT
gridnew, & !! filename for updated gridinfo file
trunk_sumbal = ".trunk_sumbal", & !! input filename for combined fluxes at each timestep (control run)
new_sumbal = "new_sumbal" !! output filename for combined fluxes at each timestep (current run)

END TYPE filenames_type

Expand Down

0 comments on commit 8869691

Please sign in to comment.