From 886969133e4e02ca01e2282442c46c6fea743be5 Mon Sep 17 00:00:00 2001 From: Sean Bryan Date: Tue, 12 Nov 2024 16:44:29 +1100 Subject: [PATCH] Move consistency check initialisation into cable_driver_init Add new namelist options: filename%new_sumbal filename%trunk_sumbal --- .../docs/user_guide/inputs/cable_nml.md | 2 + src/offline/cable_driver_init.F90 | 20 +++++++-- src/offline/cable_mpimaster.F90 | 27 +++--------- src/offline/cable_mpimaster_stub.F90 | 3 +- src/offline/cable_offline_driver.F90 | 7 ++-- src/offline/cable_serial.F90 | 29 +++---------- src/util/cable_common.F90 | 42 +++++++++---------- 7 files changed, 57 insertions(+), 73 deletions(-) diff --git a/documentation/docs/user_guide/inputs/cable_nml.md b/documentation/docs/user_guide/inputs/cable_nml.md index 1ac59f001..d8444e2ec 100644 --- a/documentation/docs/user_guide/inputs/cable_nml.md +++ b/documentation/docs/user_guide/inputs/cable_nml.md @@ -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. | diff --git a/src/offline/cable_driver_init.F90 b/src/offline/cable_driver_init.F90 index d9ef3c6e2..41a520866 100644 --- a/src/offline/cable_driver_init.F90 +++ b/src/offline/cable_driver_init.F90 @@ -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, & @@ -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 @@ -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 diff --git a/src/offline/cable_mpimaster.F90 b/src/offline/cable_mpimaster.F90 index d56499e2d..8ccf918c7 100644 --- a/src/offline/cable_mpimaster.F90 +++ b/src/offline/cable_mpimaster.F90 @@ -161,7 +161,7 @@ MODULE cable_mpimaster CONTAINS - SUBROUTINE mpidrv_master (comm) + SUBROUTINE mpidrv_master (comm, trunk_sumbal) USE mpi @@ -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' @@ -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 @@ -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) @@ -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) diff --git a/src/offline/cable_mpimaster_stub.F90 b/src/offline/cable_mpimaster_stub.F90 index 67c6387cf..9db59d90c 100644 --- a/src/offline/cable_mpimaster_stub.F90 +++ b/src/offline/cable_mpimaster_stub.F90 @@ -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 diff --git a/src/offline/cable_offline_driver.F90 b/src/offline/cable_offline_driver.F90 index 41666c479..bd19d0955 100644 --- a/src/offline/cable_offline_driver.F90 +++ b/src/offline/cable_offline_driver.F90 @@ -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 diff --git a/src/offline/cable_serial.F90 b/src/offline/cable_serial.F90 index 541b74662..5a5398cf1 100644 --- a/src/offline/cable_serial.F90 +++ b/src/offline/cable_serial.F90 @@ -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 @@ -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 @@ -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 @@ -268,7 +262,6 @@ SUBROUTINE serialdrv() REAL,ALLOCATABLE, SAVE :: xk(:,:) INTEGER :: nkend=0 - INTEGER :: ioerror INTEGER :: count_bal = 0 ! for landuse @@ -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) @@ -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) diff --git a/src/util/cable_common.F90 b/src/util/cable_common.F90 index f3d2a99c9..bcecd6bd2 100644 --- a/src/util/cable_common.F90 +++ b/src/util/cable_common.F90 @@ -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