From ccdba18c90b75b6d72942f3c8d4f04116a803853 Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Thu, 25 Oct 2018 13:26:53 -0600 Subject: [PATCH] Don't allow interpolation from a non-ciso case to a ciso case Due to https://github.com/ESCOMP/ctsm/issues/67, interpolation from a case without carbon isotopes to a case with carbon isotopes yields incorrect initialization values for the carbon isotopes. Now that we're turning carbon isotopes on via some semi-out-of-the-box usermods (for cmip6), it is becoming more important to check to make sure someone doesn't shoot themselves in the foot this way. This commit should be backed out once ESCOMP/ctsm#67 is resolved --- .../namelist_definition_clm4_5.xml | 10 +++ .../testmods_dirs/clm/ciso/user_nl_clm | 8 +++ .../clm/ciso_flexCN_FUN/user_nl_clm | 8 +++ src/init_interp/initInterp.F90 | 67 ++++++++++++++++++- src/main/clm_varctl.F90 | 8 +++ src/main/controlMod.F90 | 4 +- 6 files changed, 103 insertions(+), 2 deletions(-) diff --git a/bld/namelist_files/namelist_definition_clm4_5.xml b/bld/namelist_files/namelist_definition_clm4_5.xml index 0a4bbd9a28..f1ab4daa33 100644 --- a/bld/namelist_files/namelist_definition_clm4_5.xml +++ b/bld/namelist_files/namelist_definition_clm4_5.xml @@ -1963,6 +1963,16 @@ Flag to use the atmospheric time series of C13 concentrations from natural abund Filename with time series of atmospheric Delta C13 data, which use CMIP6 format. variables in file are "time" and "delta13co2_in_air". time variable is in format: years since 1850-01-01 0:0:0.0. units are permil. + + +There is a bug that causes incorrect values for C isotopes if running +init_interp from a case without C isotopes to a case with C isotopes +(https://github.com/ESCOMP/ctsm/issues/67). Normally, an error-check +prevents you from doing this interpolation (until we have fixed that +bug). However, we sometimes want to bypass this error-check in system +tests. This namelist flag bypasses this error-check. + diff --git a/cime_config/testdefs/testmods_dirs/clm/ciso/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/ciso/user_nl_clm index 0a40cd33a8..3b12a2772b 100644 --- a/cime_config/testdefs/testmods_dirs/clm/ciso/user_nl_clm +++ b/cime_config/testdefs/testmods_dirs/clm/ciso/user_nl_clm @@ -1,2 +1,10 @@ use_c13 = .true. use_c14 = .true. + + ! BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) There is a bug that causes incorrect values for C + ! isotopes if running init_interp from a case without C isotopes to a case with C + ! isotopes (https://github.com/ESCOMP/ctsm/issues/67). Normally, an error-check prevents + ! you from doing this interpolation (until we have fixed that bug). However, we + ! sometimes want to bypass this error-check in system tests. This namelist flag bypasses + ! this error-check. + for_testing_allow_interp_non_ciso_to_ciso = .true. diff --git a/cime_config/testdefs/testmods_dirs/clm/ciso_flexCN_FUN/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/ciso_flexCN_FUN/user_nl_clm index 9db1957c1c..32e584af82 100644 --- a/cime_config/testdefs/testmods_dirs/clm/ciso_flexCN_FUN/user_nl_clm +++ b/cime_config/testdefs/testmods_dirs/clm/ciso_flexCN_FUN/user_nl_clm @@ -2,3 +2,11 @@ use_c14 = .true. use_fun = .true. use_flexibleCN = .true. + + ! BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) There is a bug that causes incorrect values for C + ! isotopes if running init_interp from a case without C isotopes to a case with C + ! isotopes (https://github.com/ESCOMP/ctsm/issues/67). Normally, an error-check prevents + ! you from doing this interpolation (until we have fixed that bug). However, we + ! sometimes want to bypass this error-check in system tests. This namelist flag bypasses + ! this error-check. + for_testing_allow_interp_non_ciso_to_ciso = .true. diff --git a/src/init_interp/initInterp.F90 b/src/init_interp/initInterp.F90 index a5f31584bc..21c7ddb18c 100644 --- a/src/init_interp/initInterp.F90 +++ b/src/init_interp/initInterp.F90 @@ -49,6 +49,7 @@ module initInterpMod private :: interp_1d_int private :: interp_2d_double private :: limit_snlsno + private :: check_interp_non_ciso_to_ciso ! Private data @@ -227,12 +228,14 @@ subroutine initInterp (filei, fileo, bounds, glc_behavior) end if ! -------------------------------------------- - ! Open input and output initial conditions files (both just for reading now) + ! Open input and output initial conditions files ! -------------------------------------------- call ncd_pio_openfile (ncidi, trim(filei) , 0) call ncd_pio_openfile (ncido, trim(fileo), ncd_write) + call check_interp_non_ciso_to_ciso(ncidi) + ! -------------------------------------------- ! Determine dimensions and error checks on dimensions ! -------------------------------------------- @@ -1258,4 +1261,66 @@ subroutine limit_snlsno(ncido, bounds_o) deallocate(snlsno) end subroutine limit_snlsno + !----------------------------------------------------------------------- + subroutine check_interp_non_ciso_to_ciso(ncidi) + ! + ! !DESCRIPTION: + ! BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) There is a bug that causes incorrect values for + ! C isotopes if running init_interp from a case without C isotopes to a case with C + ! isotopes (https://github.com/ESCOMP/ctsm/issues/67). Here we check that the user + ! isn't trying to do an interpolation in that case. This check should be removed once + ! bug #67 is resolved. + ! + ! !USES: + use clm_varctl, only : use_c13, use_c14, for_testing_allow_interp_non_ciso_to_ciso + ! + ! !ARGUMENTS: + type(file_desc_t), intent(inout) :: ncidi + ! + ! !LOCAL VARIABLES: + type(Var_desc_t) :: vardesc ! pio variable descriptor + integer :: status ! return code + + character(len=*), parameter :: subname = 'check_interp_non_ciso_to_ciso' + !----------------------------------------------------------------------- + + if (.not. for_testing_allow_interp_non_ciso_to_ciso) then + if (use_c13) then + call pio_seterrorhandling(ncidi, PIO_BCAST_ERROR) + ! arbitrarily check leafc_13 (we could pick any c13 restart field) + status = pio_inq_varid(ncidi, name='leafc_13', vardesc=vardesc) + call pio_seterrorhandling(ncidi, PIO_INTERNAL_ERROR) + if (status /= PIO_noerr) then + if (masterproc) then + write(iulog,*) 'Cannot interpolate from a run without c13 to a run with c13,' + write(iulog,*) 'due to .' + write(iulog,*) 'Either use an input initial conditions file with c13 information,' + write(iulog,*) 'or re-spinup from cold start.' + end if + call endrun(msg='Cannot interpolate from a run without c13 to a run with c13', & + additional_msg=errMsg(sourcefile, __LINE__)) + end if + end if + + if (use_c14) then + call pio_seterrorhandling(ncidi, PIO_BCAST_ERROR) + ! arbitrarily check leafc_14 (we could pick any c14 restart field) + status = pio_inq_varid(ncidi, name='leafc_14', vardesc=vardesc) + call pio_seterrorhandling(ncidi, PIO_INTERNAL_ERROR) + if (status /= PIO_noerr) then + if (masterproc) then + write(iulog,*) 'Cannot interpolate from a run without c14 to a run with c14,' + write(iulog,*) 'due to .' + write(iulog,*) 'Either use an input initial conditions file with c14 information,' + write(iulog,*) 'or re-spinup from cold start.' + end if + call endrun(msg='Cannot interpolate from a run without c14 to a run with c14', & + additional_msg=errMsg(sourcefile, __LINE__)) + end if + end if + end if + + end subroutine check_interp_non_ciso_to_ciso + + end module initInterpMod diff --git a/src/main/clm_varctl.F90 b/src/main/clm_varctl.F90 index 938155c5dd..1351316599 100644 --- a/src/main/clm_varctl.F90 +++ b/src/main/clm_varctl.F90 @@ -189,6 +189,14 @@ module clm_varctl logical, public :: use_c13 = .false. ! true => use C-13 model logical, public :: use_c14 = .false. ! true => use C-14 model + ! BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) There is a bug that causes incorrect values for C + ! isotopes if running init_interp from a case without C isotopes to a case with C + ! isotopes (https://github.com/ESCOMP/ctsm/issues/67). Normally, an error-check prevents + ! you from doing this interpolation (until we have fixed that bug). However, we + ! sometimes want to bypass this error-check in system tests. This namelist flag bypasses + ! this error-check. + logical, public :: for_testing_allow_interp_non_ciso_to_ciso = .false. + !---------------------------------------------------------- ! FATES switches !---------------------------------------------------------- diff --git a/src/main/controlMod.F90 b/src/main/controlMod.F90 index ae9c2fcafe..51ac9d0892 100644 --- a/src/main/controlMod.F90 +++ b/src/main/controlMod.F90 @@ -214,7 +214,7 @@ subroutine control_init( ) namelist /clm_inparm/ no_frozen_nitrif_denitrif - namelist /clm_inparm/ use_c13, use_c14 + namelist /clm_inparm/ use_c13, use_c14, for_testing_allow_interp_non_ciso_to_ciso ! FATES Flags @@ -624,6 +624,7 @@ subroutine control_spmd() ! isotopes call mpi_bcast (use_c13, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (use_c14, 1, MPI_LOGICAL, 0, mpicom, ier) + call mpi_bcast (for_testing_allow_interp_non_ciso_to_ciso, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (use_fates, 1, MPI_LOGICAL, 0, mpicom, ier) @@ -860,6 +861,7 @@ subroutine control_print () write(iulog, *) ' use_c14 : ', use_c14 write(iulog, *) ' use_c14_bombspike : ', use_c14_bombspike write(iulog, *) ' atm_c14_filename : ', atm_c14_filename + write(iulog, *) ' for_testing_allow_interp_non_ciso_to_ciso : ', for_testing_allow_interp_non_ciso_to_ciso end if if (fsnowoptics == ' ') then