From 7c3a56794e28f85675729fcd3495009a064db529 Mon Sep 17 00:00:00 2001 From: mvertens Date: Wed, 24 Aug 2022 20:58:06 -0600 Subject: [PATCH 01/21] addition of namelist based skip restart functionality to dlnd, docn, drof, dwav (#180) * add skip_restart functionality to all components that can use it --- dlnd/cime_config/config_component.xml | 10 +++++++++ dlnd/cime_config/namelist_definition_dlnd.xml | 13 +++++++++++ dlnd/lnd_comp_nuopc.F90 | 22 +++++++++---------- docn/cime_config/buildnml | 6 +++++ docn/cime_config/config_component.xml | 10 +++++++++ docn/cime_config/namelist_definition_docn.xml | 13 +++++++++++ docn/ocn_comp_nuopc.F90 | 7 ++++-- drof/cime_config/config_component.xml | 10 +++++++++ drof/cime_config/namelist_definition_drof.xml | 13 +++++++++++ drof/rof_comp_nuopc.F90 | 8 ++++--- dwav/cime_config/config_component.xml | 10 +++++++++ dwav/cime_config/namelist_definition_dwav.xml | 13 +++++++++++ dwav/wav_comp_nuopc.F90 | 8 ++++--- 13 files changed, 124 insertions(+), 19 deletions(-) diff --git a/dlnd/cime_config/config_component.xml b/dlnd/cime_config/config_component.xml index 6fc60c254..ab40fa583 100644 --- a/dlnd/cime_config/config_component.xml +++ b/dlnd/cime_config/config_component.xml @@ -112,6 +112,16 @@ ending year to loop data over (only used when DLND_MODE is CPLHIST or GLC_CPLHIST) + + logical + TRUE,FALSE + FALSE + run_component_dlnd + env_run.xml + If set to true, than dlnd restarts will not be read on a continuation run. + + + ========================================= DLND naming conventions diff --git a/dlnd/cime_config/namelist_definition_dlnd.xml b/dlnd/cime_config/namelist_definition_dlnd.xml index 8fd3b160e..b10350b74 100644 --- a/dlnd/cime_config/namelist_definition_dlnd.xml +++ b/dlnd/cime_config/namelist_definition_dlnd.xml @@ -99,4 +99,17 @@ + + logical + dlnd + dlnd_nml + + If set to true, than dlnd restarts will not be read on a continuation run. + This capability is used, for example, in CTSM spinup runs. + + + $DLND_SKIP_RESTART_READ + + + diff --git a/dlnd/lnd_comp_nuopc.F90 b/dlnd/lnd_comp_nuopc.F90 index c97e5906e..cf99994c8 100644 --- a/dlnd/lnd_comp_nuopc.F90 +++ b/dlnd/lnd_comp_nuopc.F90 @@ -79,7 +79,7 @@ module cdeps_dlnd_comp character(CL) :: restfilm = nullstr ! model restart file namelist integer :: nx_global ! global nx dimension of model mesh integer :: ny_global ! global ny dimension of model mesh - + logical :: skip_restart_read = .false. ! true => skip restart read in continuation ! linked lists type(fldList_type) , pointer :: fldsExport => null() type(dfield_type) , pointer :: dfields => null() @@ -173,7 +173,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) !------------------------------------------------------------------------------- namelist / dlnd_nml / datamode, model_meshfile, model_maskfile, & - nx_global, ny_global, restfilm, force_prognostic_true + nx_global, ny_global, restfilm, skip_restart_read rc = ESMF_SUCCESS @@ -207,17 +207,17 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call shr_mpi_bcast(nx_global , mpicom, 'nx_global') call shr_mpi_bcast(ny_global , mpicom, 'ny_global') call shr_mpi_bcast(restfilm , mpicom, 'restfilm') - call shr_mpi_bcast(force_prognostic_true , mpicom, 'force_prognostic_true') + call shr_mpi_bcast(skip_restart_read , mpicom, 'skip_restart_read') ! write namelist input to standard out if (my_task == main_task) then - write(logunit,F00)' model_meshfile = ',trim(model_meshfile) - write(logunit,F00)' model_maskfile = ',trim(model_maskfile) - write(logunit ,*)' datamode = ',datamode - write(logunit ,*)' nx_global = ',nx_global - write(logunit ,*)' ny_global = ',ny_global - write(logunit ,*)' restfilm = ',trim(restfilm) - write(logunit ,*)' force_prognostic_true = ',force_prognostic_true + write(logunit,F00)' model_meshfile = ',trim(model_meshfile) + write(logunit,F00)' model_maskfile = ',trim(model_maskfile) + write(logunit,F00)' datamode = ',datamode + write(logunit,F01)' nx_global = ',nx_global + write(logunit,F01)' ny_global = ',ny_global + write(logunit,F00)' restfilm = ',trim(restfilm) + write(logunit,F02)' skip_restart_read = ',skip_restart_read endif ! Validate sdat datamode @@ -278,7 +278,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return ! Read restart if necessary - if (restart_read) then + if (restart_read .and. .not. skip_restart_read) then call dshr_restart_read(restfilm, rpfile, inst_suffix, nullstr, logunit, my_task, mpicom, sdat) end if diff --git a/docn/cime_config/buildnml b/docn/cime_config/buildnml index 546e43acc..43d221223 100755 --- a/docn/cime_config/buildnml +++ b/docn/cime_config/buildnml @@ -94,6 +94,12 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path if type(streamlist) == type(str()): streamlist = [] + # Determine if skip restart is asked for and if it is a valid request + skip_restart_read = case.get_value('DOCN_SKIP_RESTART_READ') + if skip_restart_read: + if docn_mode == 'som' or docn_mode == 'som_aquap': + expect (False, f"xml variable DOCN_SKIP_RESTART_READ cannot be TRUE for docn_mode {docn_mode}") + # Generate docn.streams.xml if needed print("docn_mode is {}".format(docn_mode)) if (re.search(r'sst_aquap[0-9]+',docn_mode) is not None) or (docn_mode == 'sst_aquap_constant'): diff --git a/docn/cime_config/config_component.xml b/docn/cime_config/config_component.xml index 6c51147ac..b24c73269 100644 --- a/docn/cime_config/config_component.xml +++ b/docn/cime_config/config_component.xml @@ -248,6 +248,16 @@ This is only used when DOCN_MODE=prescribed. + + logical + TRUE,FALSE + FALSE + run_component_docn + env_run.xml + If set to true, than docn restarts will not be read on a continuation run. + + + ========================================= DOCN naming conventions diff --git a/docn/cime_config/namelist_definition_docn.xml b/docn/cime_config/namelist_definition_docn.xml index c036ccd10..a33992213 100644 --- a/docn/cime_config/namelist_definition_docn.xml +++ b/docn/cime_config/namelist_definition_docn.xml @@ -190,4 +190,17 @@ + + logical + docn + docn_nml + + If set to true, than docn restarts will not be read on a continuation run. + This capability is used, for example, in CTSM spinup runs. + + + $DOCN_SKIP_RESTART_READ + + + diff --git a/docn/ocn_comp_nuopc.F90 b/docn/ocn_comp_nuopc.F90 index 964beabeb..64fde4257 100644 --- a/docn/ocn_comp_nuopc.F90 +++ b/docn/ocn_comp_nuopc.F90 @@ -96,6 +96,7 @@ module cdeps_docn_comp character(CL) :: restfilm = nullstr ! model restart file namelist integer :: nx_global integer :: ny_global + logical :: skip_restart_read = .false. ! true => skip restart read in continuation run ! linked lists type(fldList_type) , pointer :: fldsImport => null() @@ -191,7 +192,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) namelist / docn_nml / datamode, & model_meshfile, model_maskfile, & - restfilm, nx_global, ny_global, sst_constant_value + restfilm, nx_global, ny_global, sst_constant_value, skip_restart_read rc = ESMF_SUCCESS @@ -227,6 +228,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) write(logunit,F01)' nx_global = ',nx_global write(logunit,F01)' ny_global = ',ny_global write(logunit,F00)' restfilm = ',trim(restfilm) + write(logunit,F02)' skip_restart_read = ',skip_restart_read endif ! Broadcast namelist input @@ -237,6 +239,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call shr_mpi_bcast(ny_global , mpicom, 'ny_global') call shr_mpi_bcast(restfilm , mpicom, 'restfilm') call shr_mpi_bcast(sst_constant_value , mpicom, 'sst_constant_value') + call shr_mpi_bcast(skip_restart_read , mpicom, 'skip_restart_read') ! Special logic for prescribed aquaplanet if (datamode(1:9) == 'sst_aquap' .and. trim(datamode) /= 'sst_aquap_constant') then @@ -499,7 +502,7 @@ subroutine docn_comp_run(importState, exportState, clock, target_ymd, target_tod end select ! Read restart if needed - if (restart_read) then + if (restart_read .and. .not. skip_restart_read) then select case (trim(datamode)) case('sstdata', 'sst_aquap_file') call docn_datamode_copyall_restart_read(restfilm, inst_suffix, logunit, my_task, mpicom, sdat) diff --git a/drof/cime_config/config_component.xml b/drof/cime_config/config_component.xml index 7d0e8a62d..8400ada9d 100644 --- a/drof/cime_config/config_component.xml +++ b/drof/cime_config/config_component.xml @@ -125,6 +125,16 @@ ending year to loop data over (only used when DROF_MODE is CPLHIST) + + logical + TRUE,FALSE + FALSE + run_component_drof + env_run.xml + If set to true, than drof restarts will not be read on a continuation run. + + + ========================================= DROF naming conventions diff --git a/drof/cime_config/namelist_definition_drof.xml b/drof/cime_config/namelist_definition_drof.xml index ead6e9209..846139e12 100644 --- a/drof/cime_config/namelist_definition_drof.xml +++ b/drof/cime_config/namelist_definition_drof.xml @@ -104,4 +104,17 @@ + + logical + drof + drof_nml + + If set to true, than drof restarts will not be read on a continuation run. + This capability is used, for example, in CTSM spinup runs. + + + $DROF_SKIP_RESTART_READ + + + diff --git a/drof/rof_comp_nuopc.F90 b/drof/rof_comp_nuopc.F90 index c40f69932..281dc8a38 100644 --- a/drof/rof_comp_nuopc.F90 +++ b/drof/rof_comp_nuopc.F90 @@ -75,7 +75,7 @@ module cdeps_drof_comp character(CL) :: restfilm = nullstr ! model restart file namelist integer :: nx_global integer :: ny_global - + logical :: skip_restart_read = .false. ! true => skip restart read logical :: diagnose_data = .true. integer , parameter :: main_task=0 ! task number of main task character(*) , parameter :: rpfile = 'rpointer.rof' @@ -171,7 +171,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) !------------------------------------------------------------------------------- namelist / drof_nml / datamode, model_meshfile, model_maskfile, & - restfilm, nx_global, ny_global + restfilm, nx_global, ny_global, skip_restart_read rc = ESMF_SUCCESS @@ -206,6 +206,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) write(logunit,F01)' nx_global = ',nx_global write(logunit,F01)' ny_global = ',ny_global write(logunit,F00)' restfilm = ',trim(restfilm) + write(logunit,F02)' skip_restart_read = ',skip_restart_read end if ! broadcast namelist input @@ -215,6 +216,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call shr_mpi_bcast(nx_global , mpicom, 'nx_global') call shr_mpi_bcast(ny_global , mpicom, 'ny_global') call shr_mpi_bcast(restfilm , mpicom, 'restfilm') + call shr_mpi_bcast(skip_restart_read , mpicom, 'skip_restart_read') ! Validate datamode if (trim(datamode) == 'copyall') then @@ -389,7 +391,7 @@ subroutine drof_comp_run(exportState, target_ymd, target_tod, restart_write, rc) if (chkerr(rc,__LINE__,u_FILE_u)) return ! Read restart if needed - if (restart_read) then + if (restart_read .and. .not. skip_restart_read) then call dshr_restart_read(restfilm, rpfile, inst_suffix, nullstr, logunit, my_task, mpicom, sdat) end if diff --git a/dwav/cime_config/config_component.xml b/dwav/cime_config/config_component.xml index a3c97663e..9ac5c516e 100644 --- a/dwav/cime_config/config_component.xml +++ b/dwav/cime_config/config_component.xml @@ -36,6 +36,16 @@ DWAV mode + + logical + TRUE,FALSE + FALSE + run_component_dwav + env_run.xml + If set to true, than dwav restarts will not be read on a continuation run. + + + ========================================= DWAV naming conventions diff --git a/dwav/cime_config/namelist_definition_dwav.xml b/dwav/cime_config/namelist_definition_dwav.xml index ca479efbd..16517984f 100644 --- a/dwav/cime_config/namelist_definition_dwav.xml +++ b/dwav/cime_config/namelist_definition_dwav.xml @@ -97,4 +97,17 @@ + + logical + dwav + dwav_nml + + If set to true, than dwav restarts will not be read on a continuation run. + This capability is used, for example, in CTSM spinup runs. + + + $DWAV_SKIP_RESTART_READ + + + diff --git a/dwav/wav_comp_nuopc.F90 b/dwav/wav_comp_nuopc.F90 index 5bbf17106..d16e87775 100644 --- a/dwav/wav_comp_nuopc.F90 +++ b/dwav/wav_comp_nuopc.F90 @@ -76,7 +76,7 @@ module cdeps_dwav_comp character(CL) :: restfilm = nullstr ! model restart file namelist integer :: nx_global integer :: ny_global - + logical :: skip_restart_read = .false. ! true => skip restart read ! constants logical :: diagnose_data = .true. integer , parameter :: main_task=0 ! task number of main task @@ -168,7 +168,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) !------------------------------------------------------------------------------- namelist / dwav_nml / datamode, model_meshfile, model_maskfile, & - restfilm, nx_global, ny_global + restfilm, nx_global, ny_global, skip_restart_read rc = ESMF_SUCCESS @@ -203,6 +203,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) write(logunit,F01)' nx_global = ',nx_global write(logunit,F01)' ny_global = ',ny_global write(logunit,F00)' restfilm = ',trim(restfilm) + write(logunit,F02)' skip_restart_read = ',skip_restart_read endif ! broadcast namelist input @@ -212,6 +213,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call shr_mpi_bcast(nx_global , mpicom, 'nx_global') call shr_mpi_bcast(ny_global , mpicom, 'ny_global') call shr_mpi_bcast(restfilm , mpicom, 'restfilm') + call shr_mpi_bcast(skip_restart_read , mpicom, 'skip_restart_read') ! Call advertise phase if (trim(datamode) == 'copyall') then @@ -266,7 +268,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return ! Read restart if necessary - if (restart_read) then + if (restart_read .and. .not. skip_restart_read) then call dshr_restart_read(restfilm, rpfile, inst_suffix, nullstr, logunit, my_task, mpicom, sdat) end if From 184b6735f933e218aa45a73f16ae72187f2df2b7 Mon Sep 17 00:00:00 2001 From: mvertens Date: Thu, 25 Aug 2022 09:35:26 -0600 Subject: [PATCH 02/21] fixes aquap constant case (#183) --- docn/cime_config/config_component.xml | 2 +- docn/cime_config/namelist_definition_docn.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docn/cime_config/config_component.xml b/docn/cime_config/config_component.xml index b24c73269..c5bcd63df 100644 --- a/docn/cime_config/config_component.xml +++ b/docn/cime_config/config_component.xml @@ -111,7 +111,7 @@ -1 - 300 + 300. run_component_docn env_run.xml diff --git a/docn/cime_config/namelist_definition_docn.xml b/docn/cime_config/namelist_definition_docn.xml index a33992213..9020ac174 100644 --- a/docn/cime_config/namelist_definition_docn.xml +++ b/docn/cime_config/namelist_definition_docn.xml @@ -186,7 +186,7 @@ -1.0 - $DOCN_AQPCONST_VALUE + $DOCN_AQPCONST_VALUE From 623e114bb3f8a9bc25f9c6f8cfbce35fa421cbfa Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Mon, 29 Aug 2022 14:43:29 -0600 Subject: [PATCH 03/21] initialize logunit (#185) * initialize logunit * cleanup stream logunit initialization * remove unused variable logunit --- streams/dshr_strdata_mod.F90 | 128 +++++++++++++++++------------------ streams/dshr_stream_mod.F90 | 41 ++++++----- 2 files changed, 86 insertions(+), 83 deletions(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 27b0c0cb2..cabe05f7f 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -113,7 +113,6 @@ module dshr_strdata_mod type(shr_strdata_perstream), allocatable :: pstrm(:) ! stream info type(shr_stream_streamType), pointer :: stream(:)=> null() ! stream datatype logical :: mainproc - integer :: logunit ! stdout unit integer :: io_type ! pio info integer :: io_format ! pio info integer :: modeldt = 0 ! model dt in seconds @@ -198,9 +197,6 @@ subroutine shr_strdata_init_from_config(sdat, streamfilename, model_mesh, clock, rc = ESMF_SUCCESS call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO) - ! Initialize log unit - sdat%logunit = logunit - #ifdef CESMCOUPLED ! Initialize sdat pio sdat%pio_subsystem => shr_pio_getiosys(trim(compname)) @@ -217,10 +213,10 @@ subroutine shr_strdata_init_from_config(sdat, streamfilename, model_mesh, clock, sdat%mainproc = (localPet == main_task) #ifdef DISABLE_FoX - call shr_stream_init_from_esmfconfig(streamfilename, sdat%stream, sdat%logunit, & + call shr_stream_init_from_esmfconfig(streamfilename, sdat%stream, logunit, & sdat%pio_subsystem, sdat%io_type, sdat%io_format, rc=rc) #else - call shr_stream_init_from_xml(streamfilename, sdat%stream, sdat%mainproc, sdat%logunit, & + call shr_stream_init_from_xml(streamfilename, sdat%stream, sdat%mainproc, logunit, & sdat%pio_subsystem, sdat%io_type, sdat%io_format, trim(compname), rc=rc) #endif @@ -272,9 +268,7 @@ subroutine shr_strdata_init_from_inline(sdat, my_task, logunit, compname, & rc = ESMF_SUCCESS ! Initialize sdat%logunit and sdat%mainproc - sdat%logunit = logunit sdat%mainproc = (my_task == main_task) - if(sdat%mainproc) print *,__FILE__,__LINE__,'strm logunit is: ',logunit,trim(stream_filenames(1)) #ifdef CESMCOUPLED ! Initialize sdat pio sdat%pio_subsystem => shr_pio_getiosys(trim(compname)) @@ -420,7 +414,7 @@ subroutine shr_strdata_init(sdat, model_clock, stream_name, rc) if (filename /= 'none' .and. mainproc) then inquire(file=trim(filename),exist=fileExists) if (.not. fileExists) then - write(sdat%logunit,'(a)') "ERROR: file does not exist: "//trim(fileName) + write(sdat%stream(1)%logunit,'(a)') "ERROR: file does not exist: "//trim(fileName) call shr_sys_abort(subName//"ERROR: file does not exist: "//trim(fileName)) end if endif @@ -452,7 +446,7 @@ subroutine shr_strdata_init(sdat, model_clock, stream_name, rc) sdat%pstrm(ns)%stream_ub = 2 allocate(sdat%pstrm(ns)%fldbun_data(2)) if (mainproc) then - write(sdat%logunit,'(a,i8)') trim(subname)//" Creating field bundle array fldbun_data of size 2 for stream ",& + write(sdat%stream(1)%logunit,'(a,i8)') trim(subname)//" Creating field bundle array fldbun_data of size 2 for stream ",& ns end if else if(sdat%stream(ns)%readmode=='full_file') then @@ -479,7 +473,7 @@ subroutine shr_strdata_init(sdat, model_clock, stream_name, rc) if (chkerr(rc,__LINE__,u_FILE_u)) return if (mainproc) then if (i == 1) then - write(sdat%logunit,'(a,i8)') " adding field "//trim(sdat%pstrm(ns)%fldlist_model(nfld))//& + write(sdat%stream(1)%logunit,'(a,i8)') " adding field "//trim(sdat%pstrm(ns)%fldlist_model(nfld))//& " to fldbun_data for stream ",ns end if end if @@ -614,12 +608,12 @@ subroutine shr_strdata_init(sdat, model_clock, stream_name, rc) end if ! check that stream vector names are valid if (.not. shr_string_listIsValid(stream_vector_names)) then - write(sdat%logunit,*) trim(subname),' vec fldlist invalid m=',m,trim(stream_vector_names) + write(sdat%stream(1)%logunit,*) trim(subname),' vec fldlist invalid m=',m,trim(stream_vector_names) call shr_sys_abort(subname//': vec fldlist invalid:'//trim(stream_vector_names)) endif ! check that only 2 fields are contained for any vector pairing if (shr_string_listGetNum(stream_vector_names) /= 2) then - write(sdat%logunit,*) trim(subname),' vec fldlist ne 2 m=',m,trim(stream_vector_names) + write(sdat%stream(1)%logunit,*) trim(subname),' vec fldlist ne 2 m=',m,trim(stream_vector_names) call shr_sys_abort(subname//': vec fldlist ne 2:'//trim(stream_vector_names)) endif ! create stream vector field @@ -628,7 +622,7 @@ subroutine shr_strdata_init(sdat, model_clock, stream_name, rc) ungriddedLbound=(/1/), ungriddedUbound=(/2/), gridToFieldMap=(/2/), rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return if (mainproc) then - write(sdat%logunit,'(a,i8)') "creating ESMF stream vector field with names" //& + write(sdat%stream(1)%logunit,'(a,i8)') "creating ESMF stream vector field with names" //& trim(stream_vector_names)//" for stream ",ns end if end if @@ -653,7 +647,7 @@ subroutine shr_strdata_init(sdat, model_clock, stream_name, rc) else call shr_strdata_print(sdat, 'stream_data') end if - write(sdat%logunit,*) ' successfully initialized sdat' + write(sdat%stream(1)%logunit,*) ' successfully initialized sdat' endif end subroutine shr_strdata_init @@ -696,7 +690,7 @@ subroutine shr_strdata_get_stream_nlev(sdat, stream_index, rc) call pio_closefile(pioid) end if if (sdat%mainproc) then - write(sdat%logunit,*) trim(subname)//' stream_nlev = ',stream_nlev + write(sdat%stream(1)%logunit,*) trim(subname)//' stream_nlev = ',stream_nlev end if ! Set stream_nlev in the per-stream sdat info @@ -943,9 +937,9 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) end select if (debug > 0 .and. sdat%mainproc) then - write(sdat%logunit,*) trim(subname),' newData flag = ',ns,newData(ns) - write(sdat%logunit,*) trim(subname),' LB ymd,tod = ',ns,sdat%pstrm(ns)%ymdLB,sdat%pstrm(ns)%todLB - write(sdat%logunit,*) trim(subname),' UB ymd,tod = ',ns,sdat%pstrm(ns)%ymdUB,sdat%pstrm(ns)%todUB + write(sdat%stream(1)%logunit,*) trim(subname),' newData flag = ',ns,newData(ns) + write(sdat%stream(1)%logunit,*) trim(subname),' LB ymd,tod = ',ns,sdat%pstrm(ns)%ymdLB,sdat%pstrm(ns)%todLB + write(sdat%stream(1)%logunit,*) trim(subname),' UB ymd,tod = ',ns,sdat%pstrm(ns)%ymdUB,sdat%pstrm(ns)%todUB endif ! --------------------------------------------------------- @@ -969,10 +963,10 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if ((sdat%pstrm(ns)%dtmax/sdat%pstrm(ns)%dtmin) > sdat%stream(ns)%dtlimit) then if (sdat%mainproc) then - write(sdat%logunit,*) trim(subname),' ERROR: for stream ',ns - write(sdat%logunit,*) trim(subName),' ERROR: dtime, dtmax, dtmin, dtlimit = ',& + write(sdat%stream(1)%logunit,*) trim(subname),' ERROR: for stream ',ns + write(sdat%stream(1)%logunit,*) trim(subName),' ERROR: dtime, dtmax, dtmin, dtlimit = ',& dtime, sdat%pstrm(ns)%dtmax, sdat%pstrm(ns)%dtmin, sdat%stream(ns)%dtlimit - write(sdat%logunit,*) trim(subName),' ERROR: ymdLB, todLB, ymdUB, todUB = ', & + write(sdat%stream(1)%logunit,*) trim(subName),' ERROR: ymdLB, todLB, ymdUB, todUB = ', & sdat%pstrm(ns)%ymdLB, sdat%pstrm(ns)%todLB, sdat%pstrm(ns)%ymdUB, sdat%pstrm(ns)%todUB end if write(6,*) trim(subname),' ERROR: for stream ',ns @@ -1009,11 +1003,11 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_coszenC') call shr_tInterp_getCosz(coszen, sdat%model_lon, sdat%model_lat, ymdmod(ns), todmod, & sdat%eccen, sdat%mvelpp, sdat%lambm0, sdat%obliqr, sdat%stream(ns)%calendar, & - sdat%mainproc, sdat%logunit) + sdat%mainproc, sdat%stream(1)%logunit) call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_coszenC') if (debug > 0 .and. sdat%mainproc) then do n = 1,size(coszen) - write(sdat%logunit,'(a,i4,2x,2(i18,2x),i8,d20.10)')' stream,ymdmod,todmod,n,coszen= ',& + write(sdat%stream(1)%logunit,'(a,i4,2x,2(i18,2x),i8,d20.10)')' stream,ymdmod,todmod,n,coszen= ',& ns, ymd, tod, n, coszen(n) end do end if @@ -1028,11 +1022,11 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) call shr_tInterp_getAvgCosz(sdat%tavCoszen, sdat%model_lon, sdat%model_lat, & sdat%pstrm(ns)%ymdLB, sdat%pstrm(ns)%todLB, sdat%pstrm(ns)%ymdUB, sdat%pstrm(ns)%todUB, & sdat%eccen, sdat%mvelpp, sdat%lambm0, sdat%obliqr, sdat%modeldt, & - sdat%stream(ns)%calendar, sdat%mainproc, sdat%logunit, rc=rc) + sdat%stream(ns)%calendar, sdat%mainproc, sdat%stream(1)%logunit, rc=rc) call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_coszenN') if (debug > 0 .and. sdat%mainproc) then do n = 1,size(coszen) - write(sdat%logunit,'(a,i4,2x,4(i18,2x),i8,d20.10)')' stream,lbymd,lbsec,ubymd,ubsec,newdata,n,tavgCoszen= ',& + write(sdat%stream(1)%logunit,'(a,i4,2x,4(i18,2x),i8,d20.10)')' stream,lbymd,lbsec,ubymd,ubsec,newdata,n,tavgCoszen= ',& ns, sdat%pstrm(ns)%ymdLB, sdat%pstrm(ns)%todLB, sdat%pstrm(ns)%ymdUB, sdat%pstrm(ns)%todUB, & n, sdat%tavCoszen(n) end do @@ -1084,11 +1078,11 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_tint') call shr_tInterp_getFactors(sdat%pstrm(ns)%ymdlb, sdat%pstrm(ns)%todlb, & sdat%pstrm(ns)%ymdub, sdat%pstrm(ns)%todub, & - ymdmod(ns), todmod, flb, fub, calendar=sdat%stream(ns)%calendar, logunit=sdat%logunit, & + ymdmod(ns), todmod, flb, fub, calendar=sdat%stream(ns)%calendar, logunit=sdat%stream(1)%logunit, & algo=trim(sdat%stream(ns)%tinterpalgo), rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return if (debug > 0 .and. sdat%mainproc) then - write(sdat%logunit,'(a,i4,2(f10.5,2x))') & + write(sdat%stream(1)%logunit,'(a,i4,2(f10.5,2x))') & trim(subname)//' non-cosz-interp stream, flb, fub= ',ns,flb,fub endif do nf = 1,size(sdat%pstrm(ns)%fldlist_model) @@ -1198,27 +1192,27 @@ subroutine shr_strdata_print(sdat, name) character(*),parameter :: F90 = "('(shr_strdata_print) ',58('-'))" !------------------------------------------------------------------------------- - write(sdat%logunit,*) - write(sdat%logunit,F90) - write(sdat%logunit,F00) "name = ",trim(name) - write(sdat%logunit,F00) "calendar = ",trim(sdat%model_calendar) - write(sdat%logunit,F02) "eccen = ",sdat%eccen - write(sdat%logunit,F02) "mvelpp = ",sdat%mvelpp - write(sdat%logunit,F02) "lambm0 = ",sdat%lambm0 - write(sdat%logunit,F02) "obliqr = ",sdat%obliqr - write(sdat%logunit,F01) "pio_iotype = ",sdat%io_type - write(sdat%logunit,F01) "nstreams = ",shr_strdata_get_stream_count(sdat) - write(sdat%logunit,F05) "Per stream information " + write(sdat%stream(1)%logunit,*) + write(sdat%stream(1)%logunit,F90) + write(sdat%stream(1)%logunit,F00) "name = ",trim(name) + write(sdat%stream(1)%logunit,F00) "calendar = ",trim(sdat%model_calendar) + write(sdat%stream(1)%logunit,F02) "eccen = ",sdat%eccen + write(sdat%stream(1)%logunit,F02) "mvelpp = ",sdat%mvelpp + write(sdat%stream(1)%logunit,F02) "lambm0 = ",sdat%lambm0 + write(sdat%stream(1)%logunit,F02) "obliqr = ",sdat%obliqr + write(sdat%stream(1)%logunit,F01) "pio_iotype = ",sdat%io_type + write(sdat%stream(1)%logunit,F01) "nstreams = ",shr_strdata_get_stream_count(sdat) + write(sdat%stream(1)%logunit,F05) "Per stream information " do ns = 1, shr_strdata_get_stream_count(sdat) - write(sdat%logunit,F04) " taxMode (",ns,") = ",trim(sdat%stream(ns)%taxmode) - write(sdat%logunit,F07) " dtlimit (",ns,") = ",sdat%stream(ns)%dtlimit - write(sdat%logunit,F04) " mapalgo (",ns,") = ",trim(sdat%stream(ns)%mapalgo) - write(sdat%logunit,F04) " tintalgo(",ns,") = ",trim(sdat%stream(ns)%tinterpalgo) - write(sdat%logunit,F04) " readmode(",ns,") = ",trim(sdat%stream(ns)%readmode) - write(sdat%logunit,F04) " vectors (",ns,") = ",trim(sdat%stream(ns)%stream_vectors) - write(sdat%logunit,F01) " " + write(sdat%stream(1)%logunit,F04) " taxMode (",ns,") = ",trim(sdat%stream(ns)%taxmode) + write(sdat%stream(1)%logunit,F07) " dtlimit (",ns,") = ",sdat%stream(ns)%dtlimit + write(sdat%stream(1)%logunit,F04) " mapalgo (",ns,") = ",trim(sdat%stream(ns)%mapalgo) + write(sdat%stream(1)%logunit,F04) " tintalgo(",ns,") = ",trim(sdat%stream(ns)%tinterpalgo) + write(sdat%stream(1)%logunit,F04) " readmode(",ns,") = ",trim(sdat%stream(ns)%readmode) + write(sdat%stream(1)%logunit,F04) " vectors (",ns,") = ",trim(sdat%stream(ns)%stream_vectors) + write(sdat%stream(1)%logunit,F01) " " end do - write(sdat%logunit,F90) + write(sdat%stream(1)%logunit,F90) end subroutine shr_strdata_print @@ -1289,11 +1283,11 @@ subroutine shr_strdata_readLBUB(sdat, ns, mDate, mSec, newData, istr, rc) ! if model current date is outside of model lower or upper bound - find the stream bounds find_bounds = (rDateM < rDateLB .or. rDateM >= rDateUB) if (debug > 0 .and. sdat%mainproc) then - write(sdat%logunit,'(a,i4,2x,6(i18,2x),l7)')' stream,lbymd,lbsec,mdate,msec,ubymd,ubsec,newdata= ',ns,& + write(sdat%stream(1)%logunit,'(a,i4,2x,6(i18,2x),l7)')' stream,lbymd,lbsec,mdate,msec,ubymd,ubsec,newdata= ',ns,& sdat%pstrm(ns)%ymdLB,sdat%pstrm(ns)%todLB, & mdate,msec, & sdat%pstrm(ns)%ymdUB,sdat%pstrm(ns)%todUB,find_bounds - write(sdat%logunit,'(a,i4,2x,3(f20.3,2x),l7)')' stream,rdateLB,rdateM,rdateUB,newdata= ',& + write(sdat%stream(1)%logunit,'(a,i4,2x,3(f20.3,2x),l7)')' stream,rdateLB,rdateM,rdateUB,newdata= ',& ns,rdateLB,rdateM,rdateUB,find_bounds end if if (find_bounds) then @@ -1303,11 +1297,11 @@ subroutine shr_strdata_readLBUB(sdat, ns, mDate, mSec, newData, istr, rc) sdat%pstrm(ns)%ymdUB, dDateUB, sdat%pstrm(ns)%todUB, n_ub, filename_ub) call ESMF_TraceRegionExit(trim(istr)//'_fbound') if (debug > 0 .and. sdat%mainproc) then - write(sdat%logunit,'(a,i4,2x,6(i18,2x),l7)')' stream,lbymd,lbsec,mdate,msec,ubymd,ubsec,newdata= ',ns,& + write(sdat%stream(1)%logunit,'(a,i4,2x,6(i18,2x),l7)')' stream,lbymd,lbsec,mdate,msec,ubymd,ubsec,newdata= ',ns,& sdat%pstrm(ns)%ymdLB,sdat%pstrm(ns)%todLB,& mdate,msec, & sdat%pstrm(ns)%ymdUB,sdat%pstrm(ns)%todUB - write(sdat%logunit,'(a,i4,2x,3(f20.3,2x),l7)')' stream,rdateLB,rdateM,rdateUB,newdata= ',& + write(sdat%stream(1)%logunit,'(a,i4,2x,3(f20.3,2x),l7)')' stream,rdateLB,rdateM,rdateUB,newdata= ',& ns,rdateLB,rdateM,rdateUB,find_bounds end if endif @@ -1433,7 +1427,7 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & if (sdat%mainproc) then inquire(file=trim(fileName),exist=fileExists) if (.not. fileExists) then - write(sdat%logunit,F00) "ERROR: file does not exist: ", trim(fileName) + write(sdat%stream(1)%logunit,F00) "ERROR: file does not exist: ", trim(fileName) call shr_sys_abort(subName//"ERROR: file does not exist: "//trim(fileName)) end if endif @@ -1446,10 +1440,10 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & else ! otherwise close the old file if open and open new file if (fileopen) then - if (sdat%mainproc) write(sdat%logunit,F00) 'close : ',trim(currfile) + if (sdat%mainproc) write(sdat%stream(1)%logunit,F00) 'close : ',trim(currfile) call pio_closefile(pioid) endif - if (sdat%mainproc) write(sdat%logunit,F00) 'opening : ',trim(filename) + if (sdat%mainproc) write(sdat%stream(1)%logunit,F00) 'opening : ',trim(filename) rcode = pio_openfile(sdat%pio_subsystem, pioid, sdat%io_type, trim(filename), pio_nowrite) call shr_stream_setCurrFile(stream, fileopen=.true., currfile=trim(filename), currpioid=pioid) endif @@ -1462,7 +1456,7 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & if (ESMF_MeshIsCreated(per_stream%stream_mesh)) then if (.not. per_stream%stream_pio_iodesc_set) then - if (sdat%mainproc) write(sdat%logunit,F00) 'setting pio descriptor : ',trim(filename) + if (sdat%mainproc) write(sdat%stream(1)%logunit,F00) 'setting pio descriptor : ',trim(filename) call shr_strdata_set_stream_iodesc(sdat, per_stream, trim(per_stream%fldlist_stream(1)), & pioid, rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return @@ -1492,7 +1486,7 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & call ESMF_TraceRegionEnter(trim(istr)//'_readpio') if (sdat%mainproc) then - write(sdat%logunit,F02) 'reading file ' // trim(boundstr) //': ',trim(filename), nt + write(sdat%stream(1)%logunit,F02) 'reading file ' // trim(boundstr) //': ',trim(filename), nt endif if (ESMF_FieldIsCreated(per_stream%field_stream_vector)) then @@ -1551,7 +1545,7 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & call PIO_seterrorhandling(pioid, old_error_handle) if (debug>0 .and. sdat%mainproc) then - write(sdat%logunit,F02)' reading '//& + write(sdat%stream(1)%logunit,F02)' reading '//& trim(per_stream%fldlist_stream(nf))//' into '//trim(per_stream%fldlist_model(nf)),& ' at time index: ',nt end if @@ -1575,7 +1569,7 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & ! Single point streams are not allowed to have missing values if (stream%mapalgo == 'none' .and. any(data_real2d == fillvalue_r4)) then write(errmsg,*) ' ERROR: _Fillvalue found in stream input variable: '// trim(per_stream%fldlist_stream(nf)) - if(sdat%mainproc) write(sdat%logunit,*) trim(errmsg) + if(sdat%mainproc) write(sdat%stream(1)%logunit,*) trim(errmsg) call shr_sys_abort(errmsg) endif do lev = 1,stream_nlev @@ -1607,7 +1601,7 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & ! Single point streams are not allowed to have missing values if (stream%mapalgo == 'none' .and. any(data_real1d == fillvalue_r4)) then write(errmsg,*) ' ERROR: _Fillvalue found in stream input variable: '// trim(per_stream%fldlist_stream(nf)) - if(sdat%mainproc) write(sdat%logunit,*) trim(errmsg) + if(sdat%mainproc) write(sdat%stream(1)%logunit,*) trim(errmsg) call shr_sys_abort(errmsg) endif @@ -1640,7 +1634,7 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & ! Single point streams are not allowed to have missing values if (stream%mapalgo == 'none' .and. any(data_dbl2d == fillvalue_r8)) then write(errmsg,*) ' ERROR: _Fillvalue found in stream input variable: '// trim(per_stream%fldlist_stream(nf)) - if(sdat%mainproc) write(sdat%logunit,*) trim(errmsg) + if(sdat%mainproc) write(sdat%stream(1)%logunit,*) trim(errmsg) call shr_sys_abort(errmsg) endif do lev = 1,stream_nlev @@ -1672,7 +1666,7 @@ subroutine shr_strdata_readstrm(sdat, per_stream, stream, fldbun_data, & ! Single point streams are not allowed to have missing values if (stream%mapalgo == 'none' .and. any(data_dbl1d == fillvalue_r8)) then write(errmsg,*) ' ERROR: _Fillvalue found in stream input variable: '// trim(per_stream%fldlist_stream(nf)) - if(sdat%mainproc) write(sdat%logunit,*) trim(errmsg) + if(sdat%mainproc) write(sdat%stream(1)%logunit,*) trim(errmsg) call shr_sys_abort(errmsg) endif do n = 1,size(dataptr1d) @@ -1926,7 +1920,7 @@ subroutine shr_strdata_set_stream_iodesc(sdat, per_stream, fldname, pioid, rc) ! determine io descriptor if (ndims == 2) then if (sdat%mainproc) then - write(sdat%logunit,F00) 'setting iodesc for : '//trim(fldname)// & + write(sdat%stream(1)%logunit,F00) 'setting iodesc for : '//trim(fldname)// & ' with dimlens(1), dimlens2 = ',dimlens(1),dimlens(2),& ' variable has no time dimension ' end if @@ -1936,14 +1930,14 @@ subroutine shr_strdata_set_stream_iodesc(sdat, per_stream, fldname, pioid, rc) else if (ndims == 3) then rcode = pio_inq_dimname(pioid, dimids(ndims), dimname) if (stream_nlev > 1) then - write(sdat%logunit,F01) 'setting iodesc for : '//trim(fldname)// & + write(sdat%stream(1)%logunit,F01) 'setting iodesc for : '//trim(fldname)// & ' with dimlens(1), dimlens(2), dimlens(3) = ',dimlens(1),dimlens(2), dimlens(3), & ' variable has no time dimension '//trim(dimname) call pio_initdecomp(sdat%pio_subsystem, pio_iovartype, (/dimlens(1),dimlens(2),dimlens(3)/), compdof3d, & per_stream%stream_pio_iodesc) else if (trim(dimname) == 'time' .or. trim(dimname) == 'nt') then if (sdat%mainproc) then - write(sdat%logunit,F01) 'setting iodesc for : '//trim(fldname)// & + write(sdat%stream(1)%logunit,F01) 'setting iodesc for : '//trim(fldname)// & ' with dimlens(1), dimlens(2) = ',dimlens(1),dimlens(2),& ' variable as time dimension '//trim(dimname) end if @@ -1955,7 +1949,7 @@ subroutine shr_strdata_set_stream_iodesc(sdat, per_stream, fldname, pioid, rc) rcode = pio_inq_dimname(pioid, dimids(ndims), dimname) if (stream_nlev > 1 .and. (trim(dimname) == 'time' .or. trim(dimname) == 'nt')) then if (sdat%mainproc) then - write(sdat%logunit,F02) 'setting iodesc for : '//trim(fldname)// & + write(sdat%stream(1)%logunit,F02) 'setting iodesc for : '//trim(fldname)// & ' with dimlens(1), dimlens(2),dimlens(3) = ',dimlens(1),dimlens(2),dimlens(3),& ' variable has time dimension ' end if @@ -2009,7 +2003,7 @@ subroutine shr_strdata_get_stream_pointer_1d(sdat, strm_fld, strm_ptr, rc) fldptr1=strm_ptr, rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return if (sdat%mainproc) then - write(sdat%logunit,F00)' strm_ptr is allocated for stream field strm_'//trim(strm_fld) + write(sdat%stream(1)%logunit,F00)' strm_ptr is allocated for stream field strm_'//trim(strm_fld) end if found = .true. exit @@ -2049,7 +2043,7 @@ subroutine shr_strdata_get_stream_pointer_2d(sdat, strm_fld, strm_ptr, rc) fldptr2=strm_ptr, rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return if (sdat%mainproc) then - write(sdat%logunit,F00)' strm_ptr is allocated for stream field strm_'//trim(strm_fld) + write(sdat%stream(1)%logunit,F00)' strm_ptr is allocated for stream field strm_'//trim(strm_fld) end if found = .true. exit diff --git a/streams/dshr_stream_mod.F90 b/streams/dshr_stream_mod.F90 index 08f7dfd33..3075845ee 100644 --- a/streams/dshr_stream_mod.F90 +++ b/streams/dshr_stream_mod.F90 @@ -414,19 +414,19 @@ subroutine shr_stream_init_from_xml(streamfilename, streamdat, isroot_task, logu streamdat(i)%pio_iotype = io_type streamdat(i)%pio_ioformat = io_format #endif + ! Set logunit + streamdat(i)%logunit = logunit + call shr_stream_getCalendar(streamdat(i), 1, streamdat(i)%calendar) ! Error check if (trim(streamdat(i)%taxmode) == shr_stream_taxis_extend .and. streamdat(i)%dtlimit < 1.e10) then call shr_sys_abort(trim(subName)//" ERROR: if taxmode value is extend set dtlimit to 1.e30") end if + ! initialize flag that stream has been set + streamdat(i)%init = .true. enddo - ! Set logunit - streamdat(:)%logunit = logunit - - ! initialize flag that stream has been set - streamdat(:)%init = .true. end subroutine shr_stream_init_from_xml @@ -523,13 +523,12 @@ subroutine shr_stream_init_from_inline(streamdat, & streamdat(1)%varlist(n)%nameinmodel = trim(stream_fldlistModel(n)) end do + ! Initialize logunit + streamdat(:)%logunit = logunit ! Get stream calendar call shr_stream_getCalendar(streamdat(1), 1, calendar) streamdat(1)%calendar = trim(calendar) - ! Initialize logunit - streamdat(1)%logunit = logunit - ! Initialize flag that stream has been set streamdat(1)%init = .true. @@ -707,6 +706,9 @@ subroutine shr_stream_init_from_esmfconfig(streamfilename, streamdat, logunit, streamdat(i)%pio_subsystem => pio_subsystem streamdat(i)%pio_iotype = io_type streamdat(i)%pio_ioformat = io_format + ! Set logunit + streamdat(i)%logunit = logunit + call shr_stream_getCalendar(streamdat(i), 1, streamdat(i)%calendar) ! Error check @@ -716,9 +718,6 @@ subroutine shr_stream_init_from_esmfconfig(streamfilename, streamdat, logunit, enddo ! end loop nstrm - ! Set logunit - streamdat(:)%logunit = logunit - ! initialize flag that stream has been set streamdat(:)%init = .true. @@ -1468,6 +1467,7 @@ end subroutine shr_stream_getStreamFieldList !=============================================================================== subroutine shr_stream_getCalendar(strm, k, calendar) use pio, only : PIO_set_log_level, PIO_OFFSET_KIND + use ESMF, only: ESMF_VM, ESMF_VMGet, ESMF_VMGetCurrent ! Returns calendar name ! input/output parameters: @@ -1476,6 +1476,8 @@ subroutine shr_stream_getCalendar(strm, k, calendar) character(*) ,intent(out) :: calendar ! calendar name ! local + type(ESMF_VM) :: vm + integer :: myid integer :: vid, n character(CL) :: fileName character(CL) :: lcal @@ -1483,6 +1485,7 @@ subroutine shr_stream_getCalendar(strm, k, calendar) integer :: old_handle integer :: rCode integer :: ierr + integer :: rc character(*),parameter :: subName = '(shr_stream_getCalendar) ' !------------------------------------------------------------------------------- @@ -1490,12 +1493,18 @@ subroutine shr_stream_getCalendar(strm, k, calendar) calendar = ' ' if (k > strm%nfiles) call shr_sys_abort(subname//' ERROR: k gt nfiles') + call ESMF_VMGetCurrent(vm, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + + call ESMF_VMGet(vm, localPet=myid, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + fileName = strm%file(k)%name - ! TODO strm logunit is not set + if (.not. pio_file_is_open(strm%file(k)%fileid)) then - if(strm%logunit /= 6) write(strm%logunit, '(a)') trim(subname)//' opening stream filename = '//trim(filename) + if(myid == 0) write(strm%logunit, '(a)') trim(subname)//' opening stream filename = '//trim(filename) rcode = pio_openfile(strm%pio_subsystem, strm%file(k)%fileid, strm%pio_iotype, trim(filename)) - else if(strm%logunit /= 6) then + else if(myid == 0) then write(strm%logunit, '(a)') trim(subname)//' reading stream filename = '//trim(filename) endif @@ -1523,8 +1532,8 @@ subroutine shr_stream_getCalendar(strm, k, calendar) call shr_string_leftalign_and_convert_tabs(lcal) calendar = trim(shr_cal_calendarName(trim(lcal))) - ! TODO: add isroot_task - !write(strm%logunit, '(a)') trim(subname)//' closing stream filename = '//trim(filename) + + if(myid == 0) write(strm%logunit, '(a)') trim(subname)//' closing stream filename = '//trim(filename) call pio_closefile(strm%file(k)%fileid) end subroutine shr_stream_getCalendar From 6cac6d649c3e66bfecaf50a584dd5c0b95849a79 Mon Sep 17 00:00:00 2001 From: mvertens Date: Tue, 30 Aug 2022 11:20:22 -0600 Subject: [PATCH 04/21] fix som aquaplanet to run at resolutions other than f09 and f19 (#189) --- docn/cime_config/config_component.xml | 1 + docn/cime_config/stream_definition_docn.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/docn/cime_config/config_component.xml b/docn/cime_config/config_component.xml index c5bcd63df..2bcd256ba 100644 --- a/docn/cime_config/config_component.xml +++ b/docn/cime_config/config_component.xml @@ -125,6 +125,7 @@ $DIN_LOC_ROOT/ocn/docn7/SOM/default.som.forcing.aquaplanet.Qflux0_h30_sstQOBS.2degFV_c20170421.nc $DIN_LOC_ROOT/ocn/docn7/SOM/default.som.forcing.aquaplanet.Qflux0_h30_sstQOBS.1degFV_c20170421.nc + $DIN_LOC_ROOT/ocn/docn7/SOM/default.som.forcing.aquaplanet.Qflux0_h30_sstQOBS.1degFV_c20170421.nc run_component_docn env_run.xml diff --git a/docn/cime_config/stream_definition_docn.xml b/docn/cime_config/stream_definition_docn.xml index b9b4b41c4..4fb67edea 100644 --- a/docn/cime_config/stream_definition_docn.xml +++ b/docn/cime_config/stream_definition_docn.xml @@ -108,6 +108,7 @@ $DIN_LOC_ROOT/share/meshes/fv1.9x2.5_141008_ESMFmesh.nc $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc $DOCN_SOMAQP_DATAFILE From ed418eea119fa63f4334724332a85cd449c7d071 Mon Sep 17 00:00:00 2001 From: Adrianna Foster Date: Fri, 2 Sep 2022 09:56:58 -0600 Subject: [PATCH 05/21] Add ozone DATM streams (#188) Co-authored-by: Mariana Vertenstein Co-authored-by: Adrianna Foster --- datm/atm_comp_nuopc.F90 | 7 +- datm/cime_config/buildnml | 37 ++- datm/cime_config/config_component.xml | 24 +- datm/cime_config/namelist_definition_datm.xml | 13 + datm/cime_config/stream_definition_datm.xml | 280 +++++++++++++++++- datm/datm_datamode_clmncep_mod.F90 | 14 +- streams/dshr_stream_mod.F90 | 2 + 7 files changed, 370 insertions(+), 7 deletions(-) diff --git a/datm/atm_comp_nuopc.F90 b/datm/atm_comp_nuopc.F90 index 72c6b5972..99a91841b 100644 --- a/datm/atm_comp_nuopc.F90 +++ b/datm/atm_comp_nuopc.F90 @@ -124,6 +124,7 @@ module cdeps_datm_comp character(CL) :: factorFn_data = 'null' ! file containing correction factors data logical :: flds_presaero = .false. ! true => send valid prescribed aero fields to mediator logical :: flds_presndep = .false. ! true => send valid prescribed ndep fields to mediator + logical :: flds_preso3 = .false. ! true => send valid prescribed ozone fields to mediator logical :: flds_co2 = .false. ! true => send prescribed co2 to mediator logical :: flds_wiso = .false. ! true => send water isotopes to mediator character(CL) :: bias_correct = nullstr ! send bias correction fields to coupler @@ -230,7 +231,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) model_meshfile, model_maskfile, & nx_global, ny_global, restfilm, iradsw, factorFn_data, factorFn_mesh, & flds_presaero, flds_co2, flds_wiso, bias_correct, anomaly_forcing, & - skip_restart_read, flds_presndep + skip_restart_read, flds_presndep, flds_preso3 rc = ESMF_SUCCESS @@ -270,6 +271,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call shr_mpi_bcast(restfilm , mpicom, 'restfilm') call shr_mpi_bcast(flds_presaero , mpicom, 'flds_presaero') call shr_mpi_bcast(flds_presndep , mpicom, 'flds_presndep') + call shr_mpi_bcast(flds_preso3 , mpicom, 'flds_preso3') call shr_mpi_bcast(flds_co2 , mpicom, 'flds_co2') call shr_mpi_bcast(flds_wiso , mpicom, 'flds_wiso') call shr_mpi_bcast(skip_restart_read , mpicom, 'skip_restart_read') @@ -288,6 +290,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) write(logunit,F00)' factorFn_mesh = ',trim(factorFn_mesh) write(logunit,F02)' flds_presaero = ',flds_presaero write(logunit,F02)' flds_presndep = ',flds_presndep + write(logunit,F02)' flds_preso3 = ',flds_preso3 write(logunit,F02)' flds_co2 = ',flds_co2 write(logunit,F02)' flds_wiso = ',flds_wiso write(logunit,F02)' skip_restart_read = ',skip_restart_read @@ -319,7 +322,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('CLMNCEP') call datm_datamode_clmncep_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, flds_presndep, rc) + flds_co2, flds_wiso, flds_presaero, flds_presndep, flds_preso3, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('CPLHIST') call datm_datamode_cplhist_advertise(exportState, fldsExport, flds_scalar_name, & diff --git a/datm/cime_config/buildnml b/datm/cime_config/buildnml index 2ff95fdbe..575949b10 100755 --- a/datm/cime_config/buildnml +++ b/datm/cime_config/buildnml @@ -76,7 +76,7 @@ def _get_neon_data_availability(case, neonsite): oldestdate = datetime.strptime(neonatm[-10:],"%Y-%m.nc") neonatm = f'cdeps/{version}/{neonsite}/'+neonatm datavaliddate.append(neonatm) - if newestdate: + if newestdate: logger.info("Found tower data version {} for {} through {}".format(version, oldestdate, newestdate)) datavaliddate.sort() return datavaliddate @@ -105,6 +105,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path datm_topo = case.get_value("DATM_TOPO") datm_presaero = case.get_value("DATM_PRESAERO") datm_presndep = case.get_value("DATM_PRESNDEP") + datm_preso3 = case.get_value("DATM_PRESO3") datm_co2_tseries = case.get_value("DATM_CO2_TSERIES") atm_grid = case.get_value("ATM_GRID") model_grid = case.get_value("GRID") @@ -116,6 +117,8 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path "A DATM_MODE for CLM is incompatible with DATM_PRESAERO=none.") expect(datm_presndep != "none", "A DATM_MODE for CLM is incompatible with DATM_PRESNDEP=none.") + expect(datm_preso3 != "none", + "A DATM_MODE for CLM is incompatible with DATM_PRESO3=none.") expect(datm_topo != "none", "A DATM_MODE for CLM is incompatible with DATM_TOPO=none.") @@ -124,6 +127,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path logger.debug("DATM grid is {}".format(atm_grid)) logger.debug("DATM presaero mode is {}".format(datm_presaero)) logger.debug("DATM presndep mode is {}".format(datm_presndep)) + logger.debug("DATM preso3 mode is {}".format(datm_preso3)) logger.debug("DATM topo mode is {}".format(datm_topo)) # Initialize namelist defaults @@ -143,6 +147,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path config['datm_co2_tseries'] = datm_co2_tseries config['datm_presaero'] = datm_presaero config['datm_presndep'] = datm_presndep + config['datm_preso3'] = datm_preso3 if case.get_value('PTS_LON'): scol_lon = float(case.get_value('PTS_LON')) @@ -173,10 +178,13 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path streamlist.append("presaero.{}".format(datm_presaero)) if datm_presndep != "none": streamlist.append("presndep.{}".format(datm_presndep)) + if datm_preso3 != "none": + streamlist.append("preso3.{}".format(datm_preso3)) if datm_topo != "none": streamlist.append("topo.{}".format(datm_topo)) if datm_co2_tseries != "none": streamlist.append("co2tseries.{}".format(datm_co2_tseries)) + bias_correct = nmlgen.get_value("bias_correct") if bias_correct is not None: streamlist.append(bias_correct) @@ -189,10 +197,33 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path schema_file = os.path.join(_CDEPS_CONFIG,"stream_definition_v2.0.xsd") stream_file = os.path.join(_CDEPS_CONFIG,os.pardir, "datm","cime_config","stream_definition_datm.xml") streams = StreamCDEPS(stream_file, schema_file) - streams.create_stream_xml(streamlist, case, outfile, data_list_path, + streams.create_stream_xml(streamlist, case, outfile, data_list_path, os.path.join(caseroot,'user_nl_datm_streams'+inst_string), available_neon_data=available_neon_data) + +#################################################################################### +def _create_drv_flds_in(case, confdir): +#################################################################################### + datm_preso3 = case.get_value("DATM_PRESO3") + + # for now we are hard-coding this file name and values because we only need it for ozone + if datm_preso3 != "none": + + # Generate drv_flds_in file + outfile = os.path.join(confdir, "drv_flds_in") + ozone_nl_name = "&ozone_coupling_nl" + ozone_freq_par = "atm_ozone_frequency" + ozone_freq_val = "'multiday_average'" + nl_fin = "/" + + with open(outfile, "w") as drv_fl: + drv_fl.write("{}\n".format(ozone_nl_name)) + drv_fl.write(" {} = {}\n".format(ozone_freq_par, ozone_freq_val)) + drv_fl.write("{}\n".format(nl_fin)) + + + ############################################################################### def buildnml(case, caseroot, compname): ############################################################################### @@ -267,6 +298,8 @@ def buildnml(case, caseroot, compname): # create namelist and stream file(s) data component _create_namelists(case, confdir, inst_string, namelist_infile, nmlgen, data_list_path) + _create_drv_flds_in(case, confdir) + # copy namelist files and stream text files, to rundir copy_inputs_to_rundir(caseroot, compname, confdir, rundir, inst_string) diff --git a/datm/cime_config/config_component.xml b/datm/cime_config/config_component.xml index eed8a082d..9ff459f51 100644 --- a/datm/cime_config/config_component.xml +++ b/datm/cime_config/config_component.xml @@ -92,7 +92,7 @@ char - none,clim_1850,clim_2000,clim_2010,hist,SSP1-2.6,SSP2-4.5,SSP3-7.0,SSP5-3.4,SSP5-8.5 + none,clim_1850,clim_2000,clim_2010,hist,SSP1-2.6,SSP2-4.5,SSP3-7.0,SSP5-3.4,SSP5-8.5,cplhist clim_2000 clim_1850 @@ -112,6 +112,28 @@ DATM prescribed nitrogen deposition forcing + + char + none,clim_1850,clim_2000,clim_2010,hist,SSP2-4.5,SSP3-7.0,SSP5-8.5 + clim_2000 + + clim_1850 + clim_2000 + clim_2010 + SSP2-4.5 + SSP3-7.0 + SSP5-8.5 + hist + hist + + none + none + + run_component_datm + env_run.xml + DATM prescribed ozone forcing + + char none,observed,cplhist diff --git a/datm/cime_config/namelist_definition_datm.xml b/datm/cime_config/namelist_definition_datm.xml index 3ea0bef64..c677bffe0 100644 --- a/datm/cime_config/namelist_definition_datm.xml +++ b/datm/cime_config/namelist_definition_datm.xml @@ -279,6 +279,19 @@ + + logical + datm + datm_nml + + If true, prescribed o3 is sent from datm (must be true for running with CLM). + + + .true. + .false. + + + logical datm diff --git a/datm/cime_config/stream_definition_datm.xml b/datm/cime_config/stream_definition_datm.xml index d4228d246..c29decdca 100644 --- a/datm/cime_config/stream_definition_datm.xml +++ b/datm/cime_config/stream_definition_datm.xml @@ -187,6 +187,17 @@ presndep.SSP5-8.5 presndep.cplhist + ======================== + optional stream ozone (stream specified by xml variable DATM_PRESO3) + ======================== + preso3.clim_1850 + preso3.clim_2000 + preso3.hist + preso3.SSP2-4.5 + preso3.SSP3-7.0 + preso3.SSP5-8.5 + + ======================== optional stream topo (turned on and stream specified by xml variable DATM_TOPO) ======================== @@ -3999,6 +4010,273 @@ single + + + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + + + $DIN_LOC_ROOT/atm/cam/chem/trop_mozart_aero/aero/aerodep_clm_SSP585_b.e21.BSSP585cmip6.f09_g17.CMIP6-SSP5-8.5.001_2014-2101_monthly_0.9x1.25_c190419.nc + + + BCDEPWET Faxa_bcphiwet + BCPHODRY Faxa_bcphodry + BCPHIDRY Faxa_bcphidry + OCDEPWET Faxa_ocphiwet + OCPHIDRY Faxa_ocphidry + OCPHODRY Faxa_ocphodry + DSTX01WD Faxa_dstwet1 + DSTX01DD Faxa_dstdry1 + DSTX02WD Faxa_dstwet2 + DSTX02DD Faxa_dstdry2 + DSTX03WD Faxa_dstwet3 + DSTX03DD Faxa_dstdry3 + DSTX04WD Faxa_dstwet4 + DSTX04DD Faxa_dstdry4 + + null + + bilinear + + null + 2015 + 2015 + 2101 + 0 + + linear + + + cycle + + + 1.5 + + single + + + + + + + + + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + + + $DIN_LOC_ROOT/cdeps/datm/ozone/O3_surface.f09_g17.CMIP6-historical-WACCM.001.monthly.185001-201412.nc + + + O3 Sa_o3 + + null + + bilinear + + null + 1 + 1850 + 1850 + 0 + + linear + + + cycle + + + 1.5 + + single + + + + + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + + + $DIN_LOC_ROOT/cdeps/datm/ozone/O3_surface.f09_g17.CMIP6-historical-WACCM.001.monthly.185001-201412.nc + + + O3 Sa_o3 + + null + + bilinear + + null + 1 + 2000 + 2000 + 0 + + linear + + + cycle + + + 1.5 + + single + + + + + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + + + $DIN_LOC_ROOT/cdeps/datm/ozone/O3_surface.f09_g17.CMIP6-historical-WACCM.001.monthly.185001-201412.nc + + + O3 Sa_o3 + + null + + bilinear + + null + 1 + 2010 + 2010 + 0 + + linear + + + cycle + + + 1.5 + + single + + + + + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + + + $DIN_LOC_ROOT/cdeps/datm/ozone/O3_surface.f09_g17.CMIP6-historical-WACCM.001.monthly.185001-201412.nc + + + O3 Sa_o3 + + null + + bilinear + + null + 1850 + 1850 + 2014 + 0 + + linear + + + cycle + + + 1.5 + + single + + + + + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + + + $DIN_LOC_ROOT/cdeps/datm/ozone/O3_surface.f09_g17.CMIP6-SSP2-4.5-WACCM.001.monthly.201501-210012.nc + + + O3 Sa_o3 + + null + + bilinear + + null + 2015 + 2015 + 2100 + 0 + + linear + + + cycle + + + 1.5 + + single + + + + + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + + + $DIN_LOC_ROOT/cdeps/datm/ozone/O3_surface.f09_g17.CMIP6-SSP3-7.0-WACCM.001.monthly.201501-210012.nc + + + O3 Sa_o3 + + null + + bilinear + + null + 2015 + 2015 + 2100 + 0 + + linear + + + cycle + + + 1.5 + + single + + + + + $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc + + + $DIN_LOC_ROOT/cdeps/datm/ozone/O3_surface.f09_g17.CMIP6-SSP5-8.5-WACCM.001.monthly.201501-210012.nc + + + O3 Sa_o3 + + null + + bilinear + + null + 2015 + 2015 + 2100 + 0 + + linear + + + cycle + + + 1.5 + + single + + + + @@ -4168,7 +4446,7 @@ $DIN_LOC_ROOT/share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc - $DIN_LOC_ROOT/lnd/clm2/ndepdata/lnd/clm2/fndepdata/fndep_clm_f09_g17.CMIP6-SSP2-4.5-WACCM_1849-2101_monthly_c191007.nc + $DIN_LOC_ROOT/lnd/clm2/ndepdata/fndep_clm_f09_g17.CMIP6-SSP2-4.5-WACCM_1849-2101_monthly_c191007.nc NDEP_NHx_month Faxa_ndep_nhx diff --git a/datm/datm_datamode_clmncep_mod.F90 b/datm/datm_datamode_clmncep_mod.F90 index 0c4619c01..6c376d902 100644 --- a/datm/datm_datamode_clmncep_mod.F90 +++ b/datm/datm_datamode_clmncep_mod.F90 @@ -36,6 +36,7 @@ module datm_datamode_clmncep_mod real(r8), pointer :: Sa_dens(:) => null() real(r8), pointer :: Sa_pbot(:) => null() real(r8), pointer :: Sa_pslv(:) => null() + real(r8), pointer :: Sa_o3(:) => null() real(r8), pointer :: Faxa_lwdn(:) => null() real(r8), pointer :: Faxa_rainc(:) => null() real(r8), pointer :: Faxa_rainl(:) => null() @@ -113,7 +114,7 @@ module datm_datamode_clmncep_mod !=============================================================================== subroutine datm_datamode_clmncep_advertise(exportState, fldsexport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, flds_presndep, rc) + flds_co2, flds_wiso, flds_presaero, flds_presndep, flds_preso3, rc) ! input/output variables type(esmf_State) , intent(inout) :: exportState @@ -122,6 +123,7 @@ subroutine datm_datamode_clmncep_advertise(exportState, fldsexport, flds_scalar_ logical , intent(in) :: flds_wiso logical , intent(in) :: flds_presaero logical , intent(in) :: flds_presndep + logical , intent(in) :: flds_preso3 character(len=*) , intent(in) :: flds_scalar_name integer , intent(out) :: rc @@ -157,6 +159,9 @@ subroutine datm_datamode_clmncep_advertise(exportState, fldsexport, flds_scalar_ call dshr_fldList_add(fldsExport, 'Sa_co2prog') call dshr_fldList_add(fldsExport, 'Sa_co2diag') end if + if (flds_preso3) then + call dshr_fldList_add(fldsExport, 'Sa_o3') + end if if (flds_presaero) then call dshr_fldList_add(fldsExport, 'Faxa_bcph' , ungridded_lbound=1, ungridded_ubound=3) call dshr_fldList_add(fldsExport, 'Faxa_ocph' , ungridded_lbound=1, ungridded_ubound=3) @@ -309,6 +314,13 @@ subroutine datm_datamode_clmncep_init_pointers(importState, exportState, sdat, r if (ChkErr(rc,__LINE__,u_FILE_u)) return end if + call ESMF_StateGet(exportstate, 'Sa_o3', itemFlag, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + if (itemflag /= ESMF_STATEITEM_NOTFOUND) then + call dshr_state_getfldptr(exportState, 'Sa_o3', fldptr1=Sa_o3, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + end if + ! error check if (.not. associated(strm_wind) .or. .not. associated(strm_tbot)) then call shr_sys_abort(trim(subname)//' ERROR: wind and tbot must be in streams for CLMNCEP') diff --git a/streams/dshr_stream_mod.F90 b/streams/dshr_stream_mod.F90 index 3075845ee..301718133 100644 --- a/streams/dshr_stream_mod.F90 +++ b/streams/dshr_stream_mod.F90 @@ -1718,9 +1718,11 @@ subroutine shr_stream_restIO(pioid, streams, mode) rcode = pio_def_dim(pioid, 'strlen', CL, dimid_str) do k=1,size(streams) + ! maxnfiles is the maximum number of files across all streams if (streams(k)%nfiles > maxnfiles) then maxnfiles = streams(k)%nfiles endif + ! maxnt is the maximum number of time samples across all possible stream files do n=1,streams(k)%nFiles if( streams(k)%file(n)%nt > maxnt) then maxnt = streams(k)%file(n)%nt From 596c4ce40cba382c6602dd05ff477fa9dc693c5a Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 22 Sep 2022 07:48:04 -0600 Subject: [PATCH 06/21] correct mismatch of leap year --- streams/dshr_strdata_mod.F90 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index cabe05f7f..75943904f 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -19,7 +19,7 @@ module dshr_strdata_mod use ESMF , only : ESMF_FieldReGridStore, ESMF_FieldRedistStore, ESMF_UNMAPPEDACTION_IGNORE use ESMF , only : ESMF_TERMORDER_SRCSEQ, ESMF_FieldRegrid, ESMF_FieldFill, ESMF_FieldIsCreated use ESMF , only : ESMF_REGION_TOTAL, ESMF_FieldGet, ESMF_TraceRegionExit, ESMF_TraceRegionEnter - use ESMF , only : ESMF_LOGMSG_INFO, ESMF_LogWrite, ESMF_RC_ARG_VALUE + use ESMF , only : ESMF_LOGMSG_INFO, ESMF_LogWrite, ESMF_RC_ARG_OUTOFRANGE use shr_kind_mod , only : r8=>shr_kind_r8, r4=>shr_kind_r4, i2=>shr_kind_I2 use shr_kind_mod , only : cs=>shr_kind_cs, cl=>shr_kind_cl, cxx=>shr_kind_cxx use shr_sys_mod , only : shr_sys_abort @@ -948,11 +948,25 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if (newData(ns)) then ! Reset time bounds if newdata read in - call shr_cal_date2ymd(sdat%pstrm(ns)%ymdLB,year,month,day) + call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB,year,month,day) + print *,__FILE__,__LINE__,'Upper bound:',sdat%pstrm(ns)%ymdUB,year,month,day + call shr_cal_timeSet(timeLB,sdat%pstrm(ns)%ymdLB,0,sdat%stream(ns)%calendar,rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return + + call shr_cal_timeSet(timeUB,sdat%pstrm(ns)%ymdUB,0,sdat%stream(ns)%calendar,rc=rc) + if(rc .ne. ESMF_SUCCESS) then + if(month .eq. 2 .and. day .eq. 29) then + ! Change the date to 0301 (0229 + 72) + write(sdat%stream(1)%logunit, *) trim(subname),': Leap year date conflict, adjusting time upper bound' + sdat%pstrm(ns)%ymdUB = sdat%pstrm(ns)%ymdUB + 72 + call shr_cal_timeSet(timeUB,sdat%pstrm(ns)%ymdUB,0,sdat%stream(ns)%calendar,rc=rc) + endif + endif + print *,__FILE__,__LINE__,rc if (ChkErr(rc,__LINE__,u_FILE_u)) return + timeint = timeUB-timeLB call ESMF_TimeIntervalGet(timeint, StartTimeIn=timeLB, d=dday) if (ChkErr(rc,__LINE__,u_FILE_u)) return From 9433e3ae09567b6e39154833bf2a0420bc66abf7 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 22 Sep 2022 16:07:18 -0600 Subject: [PATCH 07/21] a better fix for leap year mismatch --- streams/dshr_strdata_mod.F90 | 13 ------------- streams/dshr_stream_mod.F90 | 6 ++++++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 75943904f..de2417b16 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -948,23 +948,10 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if (newData(ns)) then ! Reset time bounds if newdata read in - call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB,year,month,day) - print *,__FILE__,__LINE__,'Upper bound:',sdat%pstrm(ns)%ymdUB,year,month,day - call shr_cal_timeSet(timeLB,sdat%pstrm(ns)%ymdLB,0,sdat%stream(ns)%calendar,rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call shr_cal_timeSet(timeUB,sdat%pstrm(ns)%ymdUB,0,sdat%stream(ns)%calendar,rc=rc) - if(rc .ne. ESMF_SUCCESS) then - if(month .eq. 2 .and. day .eq. 29) then - ! Change the date to 0301 (0229 + 72) - write(sdat%stream(1)%logunit, *) trim(subname),': Leap year date conflict, adjusting time upper bound' - sdat%pstrm(ns)%ymdUB = sdat%pstrm(ns)%ymdUB + 72 - call shr_cal_timeSet(timeUB,sdat%pstrm(ns)%ymdUB,0,sdat%stream(ns)%calendar,rc=rc) - endif - endif - print *,__FILE__,__LINE__,rc if (ChkErr(rc,__LINE__,u_FILE_u)) return timeint = timeUB-timeLB diff --git a/streams/dshr_stream_mod.F90 b/streams/dshr_stream_mod.F90 index 301718133..95bc6e819 100644 --- a/streams/dshr_stream_mod.F90 +++ b/streams/dshr_stream_mod.F90 @@ -25,6 +25,7 @@ module dshr_stream_mod use shr_cal_mod , only : shr_cal_calendarName use shr_cal_mod , only : shr_cal_advDate use shr_cal_mod , only : shr_cal_advdateint + use shr_cal_mod , only : shr_cal_leapyear use dshr_methods_mod , only : chkerr use pio , only : pio_noerr, pio_seterrorhandling, pio_inq_att, pio_openfile, pio_closefile use pio , only : file_desc_t, pio_inq_varid, iosystem_desc_t, pio_file_is_open @@ -1159,6 +1160,11 @@ subroutine shr_stream_findBounds(strm, mDateIn, secIn, isroot_task, & dDateUB = strm%file(k_ub)%date(n_ub) call shr_cal_date2ymd(dDateUB,yy,mm,dd) yy = yy + (mYear-dYear) + if(mm == 2 .and. dd==29 .and. .not. shr_cal_leapyear(yy)) then + if(isroot_task) write(strm%logunit, *) 'Found leapyear mismatch', myear, dyear + mm = 3 + dd = 1 + endif call shr_cal_ymd2date(yy,mm,dd,mDateUB) secUB = strm%file(k_ub)%secs(n_ub) fileUB = strm%file(k_ub)%name From 9039bccfda63809fd25f36abc20b5ddcf50045f7 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 22 Sep 2022 16:21:40 -0600 Subject: [PATCH 08/21] add standalone function --- share/shr_cal_mod.F90 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/share/shr_cal_mod.F90 b/share/shr_cal_mod.F90 index 086fbec53..73380cf91 100644 --- a/share/shr_cal_mod.F90 +++ b/share/shr_cal_mod.F90 @@ -89,6 +89,7 @@ module shr_cal_mod public :: shr_cal_ymdtod2string ! translate ymdtod to string for filenames public :: shr_cal_datetod2string ! translate date to string for filenames public :: shr_cal_ymds2rday_offset ! translate yr,month,day,sec offset to a fractional day offset + public :: shr_cal_leapyear ! logical function: is this a leap year? ! !PUBLIC DATA MEMBERS: @@ -1410,5 +1411,18 @@ subroutine shr_cal_ymds2rday_offset(etime, rdays_offset, & if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) end subroutine shr_cal_ymds2rday_offset + logical function shr_cal_leapyear(yr) + integer, intent(in) :: yr + shr_cal_leapyear = .false. + if (real(yr)/4.0 == yr/4) then + if (real(yr)/100.0 == yr/100) then + if(real(yr)/400.0 == yr/400) then + shr_cal_leapyear = .true. + endif + else + shr_cal_leapyear = .true. + endif + endif + end function shr_cal_leapyear !=============================================================================== end module shr_cal_mod From f8f441687d3cb87eddc6fab29fe85467bee1571e Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 23 Sep 2022 11:54:39 -0600 Subject: [PATCH 09/21] now handling all edge cases --- datm/atm_comp_nuopc.F90 | 3 ++- streams/dshr_strdata_mod.F90 | 35 ++++++++++++++++++++++++++++++++--- streams/dshr_stream_mod.F90 | 5 ++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/datm/atm_comp_nuopc.F90 b/datm/atm_comp_nuopc.F90 index 99a91841b..285ac3356 100644 --- a/datm/atm_comp_nuopc.F90 +++ b/datm/atm_comp_nuopc.F90 @@ -445,7 +445,7 @@ end subroutine InitializeRealize !=============================================================================== subroutine ModelAdvance(gcomp, rc) - + use shr_file_mod, only : shr_file_setlogunit ! input/output variables type(ESMF_GridComp) :: gcomp integer, intent(out) :: rc @@ -472,6 +472,7 @@ subroutine ModelAdvance(gcomp, rc) !------------------------------------------------------------------------------- rc = ESMF_SUCCESS + call shr_file_setlogunit(logunit) call ESMF_TraceRegionEnter(subname) call memcheck(subname, 5, my_task==main_task) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index de2417b16..07e8a93b4 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -26,7 +26,7 @@ module dshr_strdata_mod use shr_const_mod , only : shr_const_pi, shr_const_cDay, shr_const_spval use shr_cal_mod , only : shr_cal_calendarname, shr_cal_timeSet use shr_cal_mod , only : shr_cal_noleap, shr_cal_gregorian - use shr_cal_mod , only : shr_cal_date2ymd, shr_cal_ymd2date + use shr_cal_mod , only : shr_cal_date2ymd, shr_cal_ymd2date, shr_cal_leapyear use shr_orb_mod , only : shr_orb_decl, shr_orb_cosz, shr_orb_undef_real #ifdef CESMCOUPLED use shr_pio_mod , only : shr_pio_getiosys, shr_pio_getiotype, shr_pio_getioformat @@ -846,9 +846,11 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) real(r8), pointer :: data_v_dst(:) ! pointer into field bundle type(ESMF_Time) :: timeLB, timeUB ! lb and ub times type(ESMF_TimeInterval) :: timeint ! delta time + character(CL) :: calendar integer :: dday ! delta days real(r8) :: dtime ! delta time integer :: year,month,day ! date year month day + integer :: datayear,datamonth,dataday ! data date year month day integer :: nstreams integer :: stream_index integer :: lsize @@ -900,6 +902,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ymdmod(ns) = ymd todmod = tod if (trim(sdat%model_calendar) /= trim(sdat%stream(ns)%calendar)) then + calendar = shr_cal_noleap if (( trim(sdat%model_calendar) == trim(shr_cal_gregorian)) .and. & (trim(sdat%stream(ns)%calendar) == trim(shr_cal_noleap))) then ! case (1), set feb 29 = feb 28 @@ -916,6 +919,31 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) trim(sdat%model_calendar),':',trim(sdat%stream(ns)%calendar) call shr_sys_abort(trim(subname)//' ERROR: mismatch calendar ') endif + else ! calendars are the same + if(trim(sdat%model_calendar) == trim(shr_cal_gregorian)) then + ! Both are in gregorian - but it's possible that there is a mismatch + ! such that the model is in leapyear but the data is not + call shr_cal_date2ymd (ymd,year,month,day) + call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) + + if(month == 2 .and. day==29) then + if(.not. shr_cal_leapyear(datayear)) then + ! model is in leap year but data is not + calendar = shr_cal_noleap + endif + else if(datamonth == 2) then + if(.not. shr_cal_leapyear(year)) then + if(debug .and. sdat%mainproc) then + write(logunit, *) subname,' dataday = ', dataday + endif + calendar = shr_cal_noleap + endif + else + calendar = sdat%model_calendar + endif + else + calendar = sdat%model_calendar + endif endif ! --------------------------------------------------------- @@ -948,10 +976,10 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if (newData(ns)) then ! Reset time bounds if newdata read in - call shr_cal_timeSet(timeLB,sdat%pstrm(ns)%ymdLB,0,sdat%stream(ns)%calendar,rc=rc) + call shr_cal_timeSet(timeLB,sdat%pstrm(ns)%ymdLB,0,calendar,rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call shr_cal_timeSet(timeUB,sdat%pstrm(ns)%ymdUB,0,sdat%stream(ns)%calendar,rc=rc) + call shr_cal_timeSet(timeUB,sdat%pstrm(ns)%ymdUB,0,calendar,rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return timeint = timeUB-timeLB @@ -965,6 +993,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if ((sdat%pstrm(ns)%dtmax/sdat%pstrm(ns)%dtmin) > sdat%stream(ns)%dtlimit) then if (sdat%mainproc) then write(sdat%stream(1)%logunit,*) trim(subname),' ERROR: for stream ',ns + write(sdat%stream(1)%logunit,*) trim(subname),' ERROR: dday = ',dday write(sdat%stream(1)%logunit,*) trim(subName),' ERROR: dtime, dtmax, dtmin, dtlimit = ',& dtime, sdat%pstrm(ns)%dtmax, sdat%pstrm(ns)%dtmin, sdat%stream(ns)%dtlimit write(sdat%stream(1)%logunit,*) trim(subName),' ERROR: ymdLB, todLB, ymdUB, todUB = ', & diff --git a/streams/dshr_stream_mod.F90 b/streams/dshr_stream_mod.F90 index 95bc6e819..ca8342749 100644 --- a/streams/dshr_stream_mod.F90 +++ b/streams/dshr_stream_mod.F90 @@ -819,6 +819,9 @@ subroutine shr_stream_findBounds(strm, mDateIn, secIn, isroot_task, & if (cycle) then dYear = yrFirst + modulo(mYear-yrAlign+(2*nYears),nYears) ! current data year + if(debug .and. isroot_task) then + write(strm%logunit, *) trim(subname), ' dyear, yrfirst, myear, yralign, nyears =', dyear, yrfirst, myear, yralign, nyears + endif else dYear = yrFirst + mYear - yrAlign endif @@ -1161,7 +1164,7 @@ subroutine shr_stream_findBounds(strm, mDateIn, secIn, isroot_task, & call shr_cal_date2ymd(dDateUB,yy,mm,dd) yy = yy + (mYear-dYear) if(mm == 2 .and. dd==29 .and. .not. shr_cal_leapyear(yy)) then - if(isroot_task) write(strm%logunit, *) 'Found leapyear mismatch', myear, dyear + if(isroot_task) write(strm%logunit, *) 'Found leapyear mismatch', myear, dyear, yy mm = 3 dd = 1 endif From 622a4184d28d3744f305bbd6c7358ab75e09071a Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 23 Sep 2022 11:58:01 -0600 Subject: [PATCH 10/21] fix issue with gnu compiler --- streams/dshr_stream_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streams/dshr_stream_mod.F90 b/streams/dshr_stream_mod.F90 index ca8342749..63d9cdb05 100644 --- a/streams/dshr_stream_mod.F90 +++ b/streams/dshr_stream_mod.F90 @@ -819,7 +819,7 @@ subroutine shr_stream_findBounds(strm, mDateIn, secIn, isroot_task, & if (cycle) then dYear = yrFirst + modulo(mYear-yrAlign+(2*nYears),nYears) ! current data year - if(debug .and. isroot_task) then + if(debug>0 .and. isroot_task) then write(strm%logunit, *) trim(subname), ' dyear, yrfirst, myear, yralign, nyears =', dyear, yrfirst, myear, yralign, nyears endif else From 0f3f7070c208a5de221577566b50e6dcfa6e7766 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 23 Sep 2022 12:01:06 -0600 Subject: [PATCH 11/21] fix issue with gnu compiler --- streams/dshr_strdata_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 07e8a93b4..4c9eb2666 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -933,7 +933,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) endif else if(datamonth == 2) then if(.not. shr_cal_leapyear(year)) then - if(debug .and. sdat%mainproc) then + if(debug>0 .and. sdat%mainproc) then write(logunit, *) subname,' dataday = ', dataday endif calendar = shr_cal_noleap From 1480393892413c5e5d1a05d418318816c16c4fef Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 23 Sep 2022 12:11:13 -0600 Subject: [PATCH 12/21] undo rework of logging, needs to be in a seperate pr --- datm/atm_comp_nuopc.F90 | 43 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/datm/atm_comp_nuopc.F90 b/datm/atm_comp_nuopc.F90 index 285ac3356..2c2a8825d 100644 --- a/datm/atm_comp_nuopc.F90 +++ b/datm/atm_comp_nuopc.F90 @@ -122,9 +122,7 @@ module cdeps_datm_comp integer :: iradsw = 0 ! radiation interval (input namelist) character(CL) :: factorFn_mesh = 'null' ! file containing correction factors mesh character(CL) :: factorFn_data = 'null' ! file containing correction factors data - logical :: flds_presaero = .false. ! true => send valid prescribed aero fields to mediator - logical :: flds_presndep = .false. ! true => send valid prescribed ndep fields to mediator - logical :: flds_preso3 = .false. ! true => send valid prescribed ozone fields to mediator + logical :: flds_presaero = .false. ! true => send valid prescribe aero fields to mediator logical :: flds_co2 = .false. ! true => send prescribed co2 to mediator logical :: flds_wiso = .false. ! true => send water isotopes to mediator character(CL) :: bias_correct = nullstr ! send bias correction fields to coupler @@ -133,7 +131,6 @@ module cdeps_datm_comp character(CL) :: restfilm = nullstr ! model restart file namelist integer :: nx_global ! global nx integer :: ny_global ! global ny - logical :: skip_restart_read = .false. ! true => skip restart read in continuation run ! linked lists type(fldList_type) , pointer :: fldsImport => null() @@ -230,8 +227,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) namelist / datm_nml / datamode, & model_meshfile, model_maskfile, & nx_global, ny_global, restfilm, iradsw, factorFn_data, factorFn_mesh, & - flds_presaero, flds_co2, flds_wiso, bias_correct, anomaly_forcing, & - skip_restart_read, flds_presndep, flds_preso3 + flds_presaero, flds_co2, flds_wiso, bias_correct, anomaly_forcing rc = ESMF_SUCCESS @@ -270,11 +266,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call shr_mpi_bcast(factorFn_mesh , mpicom, 'factorFn_mesh') call shr_mpi_bcast(restfilm , mpicom, 'restfilm') call shr_mpi_bcast(flds_presaero , mpicom, 'flds_presaero') - call shr_mpi_bcast(flds_presndep , mpicom, 'flds_presndep') - call shr_mpi_bcast(flds_preso3 , mpicom, 'flds_preso3') call shr_mpi_bcast(flds_co2 , mpicom, 'flds_co2') call shr_mpi_bcast(flds_wiso , mpicom, 'flds_wiso') - call shr_mpi_bcast(skip_restart_read , mpicom, 'skip_restart_read') ! write namelist input to standard out if (my_task == main_task) then @@ -289,11 +282,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) write(logunit,F00)' factorFn_data = ',trim(factorFn_data) write(logunit,F00)' factorFn_mesh = ',trim(factorFn_mesh) write(logunit,F02)' flds_presaero = ',flds_presaero - write(logunit,F02)' flds_presndep = ',flds_presndep - write(logunit,F02)' flds_preso3 = ',flds_preso3 write(logunit,F02)' flds_co2 = ',flds_co2 write(logunit,F02)' flds_wiso = ',flds_wiso - write(logunit,F02)' skip_restart_read = ',skip_restart_read end if ! Validate sdat datamode @@ -314,19 +304,19 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) select case (trim(datamode)) case ('CORE2_NYF', 'CORE2_IAF') call datm_datamode_core2_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, flds_presndep, rc) + flds_co2, flds_wiso, flds_presaero, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('CORE_IAF_JRA') call datm_datamode_jra_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, flds_presndep, rc) + flds_co2, flds_wiso, flds_presaero, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('CLMNCEP') call datm_datamode_clmncep_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, flds_presndep, flds_preso3, rc) + flds_co2, flds_wiso, flds_presaero, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('CPLHIST') call datm_datamode_cplhist_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, flds_presndep, rc) + flds_co2, flds_wiso, flds_presaero, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('ERA5') call datm_datamode_era5_advertise(exportState, fldsExport, flds_scalar_name, rc) @@ -413,7 +403,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) ! Initialize and update orbital values call dshr_orbital_init(gcomp, logunit, my_task == main_task, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call dshr_orbital_update(currTime, logunit, my_task == main_task, & + call dshr_orbital_update(clock, logunit, my_task == main_task, & orbEccen, orbObliqr, orbLambm0, orbMvelpp, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -445,7 +435,7 @@ end subroutine InitializeRealize !=============================================================================== subroutine ModelAdvance(gcomp, rc) - use shr_file_mod, only : shr_file_setlogunit + ! input/output variables type(ESMF_GridComp) :: gcomp integer, intent(out) :: rc @@ -472,7 +462,6 @@ subroutine ModelAdvance(gcomp, rc) !------------------------------------------------------------------------------- rc = ESMF_SUCCESS - call shr_file_setlogunit(logunit) call ESMF_TraceRegionEnter(subname) call memcheck(subname, 5, my_task==main_task) @@ -492,13 +481,13 @@ subroutine ModelAdvance(gcomp, rc) call shr_cal_ymd2date(yr, mon, day, next_ymd) ! Update the orbital values - call dshr_orbital_update(nextTime, logunit, my_task == main_task, & + call dshr_orbital_update(clock, logunit, my_task == main_task, & orbEccen, orbObliqr, orbLambm0, orbMvelpp, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return restart_write = dshr_check_restart_alarm(clock, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - + ! Run datm call ESMF_TraceRegionEnter('datm_run') call datm_comp_run(importstate, exportstate, next_ymd, next_tod, mon, & @@ -584,7 +573,7 @@ subroutine datm_comp_run(importState, exportState, target_ymd, target_tod, targe end select ! Read restart if needed - if (restart_read .and. .not. skip_restart_read) then + if (restart_read) then select case (trim(datamode)) case('CORE2_NYF','CORE2_IAF') call datm_datamode_core2_restart_read(restfilm, inst_suffix, logunit, my_task, mpicom, sdat) @@ -712,7 +701,6 @@ subroutine datm_init_dfields(rc) ! local variables integer :: n - character(CS) :: strm_flds2(2) character(CS) :: strm_flds3(3) character(CS) :: strm_flds4(4) integer :: rank @@ -739,10 +727,6 @@ subroutine datm_init_dfields(rc) exportState, logunit, mainproc, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return else if (rank == 2) then - ! The following maps stream input fields to export fields that have an ungridded dimension - ! TODO: in the future it might be better to change the format of the streams file to have two more entries - ! that could denote how the stream variables are mapped to export fields that have an ungridded dimension - select case (trim(lfieldnames(n))) case('Faxa_bcph') strm_flds3 = (/'Faxa_bcphidry', 'Faxa_bcphodry', 'Faxa_bcphiwet'/) @@ -776,11 +760,6 @@ subroutine datm_init_dfields(rc) strm_flds3 = (/'Faxa_snowl_16O', 'Faxa_snowl_18O', 'Faxa_snowl_HDO'/) call dshr_dfield_add(dfields, sdat, trim(lfieldnames(n)), strm_flds3, exportState, logunit, mainproc, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - case('Faxa_ndep') - strm_flds2 = (/'Faxa_ndep_nhx', 'Faxa_ndep_noy'/) - call dshr_dfield_add(dfields, sdat, trim(lfieldnames(n)), strm_flds2, exportState, logunit, mainproc, rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return - end select end if end do From a82c9b7dc4f91c1f949f808b6c3c997712da5e31 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 23 Sep 2022 12:15:30 -0600 Subject: [PATCH 13/21] get the base version correctly --- datm/atm_comp_nuopc.F90 | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/datm/atm_comp_nuopc.F90 b/datm/atm_comp_nuopc.F90 index 2c2a8825d..99a91841b 100644 --- a/datm/atm_comp_nuopc.F90 +++ b/datm/atm_comp_nuopc.F90 @@ -122,7 +122,9 @@ module cdeps_datm_comp integer :: iradsw = 0 ! radiation interval (input namelist) character(CL) :: factorFn_mesh = 'null' ! file containing correction factors mesh character(CL) :: factorFn_data = 'null' ! file containing correction factors data - logical :: flds_presaero = .false. ! true => send valid prescribe aero fields to mediator + logical :: flds_presaero = .false. ! true => send valid prescribed aero fields to mediator + logical :: flds_presndep = .false. ! true => send valid prescribed ndep fields to mediator + logical :: flds_preso3 = .false. ! true => send valid prescribed ozone fields to mediator logical :: flds_co2 = .false. ! true => send prescribed co2 to mediator logical :: flds_wiso = .false. ! true => send water isotopes to mediator character(CL) :: bias_correct = nullstr ! send bias correction fields to coupler @@ -131,6 +133,7 @@ module cdeps_datm_comp character(CL) :: restfilm = nullstr ! model restart file namelist integer :: nx_global ! global nx integer :: ny_global ! global ny + logical :: skip_restart_read = .false. ! true => skip restart read in continuation run ! linked lists type(fldList_type) , pointer :: fldsImport => null() @@ -227,7 +230,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) namelist / datm_nml / datamode, & model_meshfile, model_maskfile, & nx_global, ny_global, restfilm, iradsw, factorFn_data, factorFn_mesh, & - flds_presaero, flds_co2, flds_wiso, bias_correct, anomaly_forcing + flds_presaero, flds_co2, flds_wiso, bias_correct, anomaly_forcing, & + skip_restart_read, flds_presndep, flds_preso3 rc = ESMF_SUCCESS @@ -266,8 +270,11 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call shr_mpi_bcast(factorFn_mesh , mpicom, 'factorFn_mesh') call shr_mpi_bcast(restfilm , mpicom, 'restfilm') call shr_mpi_bcast(flds_presaero , mpicom, 'flds_presaero') + call shr_mpi_bcast(flds_presndep , mpicom, 'flds_presndep') + call shr_mpi_bcast(flds_preso3 , mpicom, 'flds_preso3') call shr_mpi_bcast(flds_co2 , mpicom, 'flds_co2') call shr_mpi_bcast(flds_wiso , mpicom, 'flds_wiso') + call shr_mpi_bcast(skip_restart_read , mpicom, 'skip_restart_read') ! write namelist input to standard out if (my_task == main_task) then @@ -282,8 +289,11 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) write(logunit,F00)' factorFn_data = ',trim(factorFn_data) write(logunit,F00)' factorFn_mesh = ',trim(factorFn_mesh) write(logunit,F02)' flds_presaero = ',flds_presaero + write(logunit,F02)' flds_presndep = ',flds_presndep + write(logunit,F02)' flds_preso3 = ',flds_preso3 write(logunit,F02)' flds_co2 = ',flds_co2 write(logunit,F02)' flds_wiso = ',flds_wiso + write(logunit,F02)' skip_restart_read = ',skip_restart_read end if ! Validate sdat datamode @@ -304,19 +314,19 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) select case (trim(datamode)) case ('CORE2_NYF', 'CORE2_IAF') call datm_datamode_core2_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, rc) + flds_co2, flds_wiso, flds_presaero, flds_presndep, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('CORE_IAF_JRA') call datm_datamode_jra_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, rc) + flds_co2, flds_wiso, flds_presaero, flds_presndep, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('CLMNCEP') call datm_datamode_clmncep_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, rc) + flds_co2, flds_wiso, flds_presaero, flds_presndep, flds_preso3, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('CPLHIST') call datm_datamode_cplhist_advertise(exportState, fldsExport, flds_scalar_name, & - flds_co2, flds_wiso, flds_presaero, rc) + flds_co2, flds_wiso, flds_presaero, flds_presndep, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return case ('ERA5') call datm_datamode_era5_advertise(exportState, fldsExport, flds_scalar_name, rc) @@ -403,7 +413,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) ! Initialize and update orbital values call dshr_orbital_init(gcomp, logunit, my_task == main_task, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call dshr_orbital_update(clock, logunit, my_task == main_task, & + call dshr_orbital_update(currTime, logunit, my_task == main_task, & orbEccen, orbObliqr, orbLambm0, orbMvelpp, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -481,13 +491,13 @@ subroutine ModelAdvance(gcomp, rc) call shr_cal_ymd2date(yr, mon, day, next_ymd) ! Update the orbital values - call dshr_orbital_update(clock, logunit, my_task == main_task, & + call dshr_orbital_update(nextTime, logunit, my_task == main_task, & orbEccen, orbObliqr, orbLambm0, orbMvelpp, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return restart_write = dshr_check_restart_alarm(clock, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - + ! Run datm call ESMF_TraceRegionEnter('datm_run') call datm_comp_run(importstate, exportstate, next_ymd, next_tod, mon, & @@ -573,7 +583,7 @@ subroutine datm_comp_run(importState, exportState, target_ymd, target_tod, targe end select ! Read restart if needed - if (restart_read) then + if (restart_read .and. .not. skip_restart_read) then select case (trim(datamode)) case('CORE2_NYF','CORE2_IAF') call datm_datamode_core2_restart_read(restfilm, inst_suffix, logunit, my_task, mpicom, sdat) @@ -701,6 +711,7 @@ subroutine datm_init_dfields(rc) ! local variables integer :: n + character(CS) :: strm_flds2(2) character(CS) :: strm_flds3(3) character(CS) :: strm_flds4(4) integer :: rank @@ -727,6 +738,10 @@ subroutine datm_init_dfields(rc) exportState, logunit, mainproc, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return else if (rank == 2) then + ! The following maps stream input fields to export fields that have an ungridded dimension + ! TODO: in the future it might be better to change the format of the streams file to have two more entries + ! that could denote how the stream variables are mapped to export fields that have an ungridded dimension + select case (trim(lfieldnames(n))) case('Faxa_bcph') strm_flds3 = (/'Faxa_bcphidry', 'Faxa_bcphodry', 'Faxa_bcphiwet'/) @@ -760,6 +775,11 @@ subroutine datm_init_dfields(rc) strm_flds3 = (/'Faxa_snowl_16O', 'Faxa_snowl_18O', 'Faxa_snowl_HDO'/) call dshr_dfield_add(dfields, sdat, trim(lfieldnames(n)), strm_flds3, exportState, logunit, mainproc, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return + case('Faxa_ndep') + strm_flds2 = (/'Faxa_ndep_nhx', 'Faxa_ndep_noy'/) + call dshr_dfield_add(dfields, sdat, trim(lfieldnames(n)), strm_flds2, exportState, logunit, mainproc, rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + end select end if end do From b0870996d759a9109dbb3076a8a021ccd456ab25 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 23 Sep 2022 13:54:47 -0600 Subject: [PATCH 14/21] use modulo here --- share/shr_cal_mod.F90 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/share/shr_cal_mod.F90 b/share/shr_cal_mod.F90 index 73380cf91..a562306f4 100644 --- a/share/shr_cal_mod.F90 +++ b/share/shr_cal_mod.F90 @@ -1411,18 +1411,21 @@ subroutine shr_cal_ymds2rday_offset(etime, rdays_offset, & if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) end subroutine shr_cal_ymds2rday_offset + !=============================================================================== logical function shr_cal_leapyear(yr) integer, intent(in) :: yr shr_cal_leapyear = .false. - if (real(yr)/4.0 == yr/4) then - if (real(yr)/100.0 == yr/100) then - if(real(yr)/400.0 == yr/400) then + if (modulo(yr, 4) == 0) then + if (modulo(yr, 100) == 0) then + if(modulo(yr, 400) == 0) then shr_cal_leapyear = .true. endif else shr_cal_leapyear = .true. endif endif + end function shr_cal_leapyear + !=============================================================================== end module shr_cal_mod From 413c55122b3d7879f233a9a468548af712d2ee2f Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Tue, 27 Sep 2022 07:46:08 -0600 Subject: [PATCH 15/21] remove unused ESMF variable --- streams/dshr_strdata_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 4c9eb2666..9e58fac0b 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -19,7 +19,7 @@ module dshr_strdata_mod use ESMF , only : ESMF_FieldReGridStore, ESMF_FieldRedistStore, ESMF_UNMAPPEDACTION_IGNORE use ESMF , only : ESMF_TERMORDER_SRCSEQ, ESMF_FieldRegrid, ESMF_FieldFill, ESMF_FieldIsCreated use ESMF , only : ESMF_REGION_TOTAL, ESMF_FieldGet, ESMF_TraceRegionExit, ESMF_TraceRegionEnter - use ESMF , only : ESMF_LOGMSG_INFO, ESMF_LogWrite, ESMF_RC_ARG_OUTOFRANGE + use ESMF , only : ESMF_LOGMSG_INFO, ESMF_LogWrite use shr_kind_mod , only : r8=>shr_kind_r8, r4=>shr_kind_r4, i2=>shr_kind_I2 use shr_kind_mod , only : cs=>shr_kind_cs, cl=>shr_kind_cl, cxx=>shr_kind_cxx use shr_sys_mod , only : shr_sys_abort From e3d1a6790d86b5376ca4456c9b6d97d6d35269c9 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Tue, 27 Sep 2022 08:03:44 -0600 Subject: [PATCH 16/21] add further documentation --- streams/dshr_strdata_mod.F90 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 9e58fac0b..64fff9aeb 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -786,7 +786,14 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ! on the time series input data. ! ! (0) The stream calendar and model calendar are identical: - ! Proceed in the standard way. + ! In this case it is still possible to have a mismatch if both are gregorian. + ! These cases are: + ! - Model is no_leap, data is Gregorian and leapyear date 2/29 is encountered in data - skip date + ! - Model is Gregorian, data is no_leap and leapyear date 2/29 is encountered in model - repeat 2/28 data + ! - Model is Gregorian, data is gregorian but leapyears do not align. + ! - if in model leap year repeat data from 2/28 + ! - if in data leap year skip date 2/29 + ! ! ! (1) The stream is a no leap calendar and the model is gregorian: ! Time interpolate on the noleap calendar. If the model date is Feb 29, From 4f30632cec329ca87136fabbaccbd99b48ca8290 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 29 Sep 2022 08:54:05 -0600 Subject: [PATCH 17/21] one more calendar mod --- streams/dshr_strdata_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 64fff9aeb..53e68d808 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -908,8 +908,8 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ! case(0) ymdmod(ns) = ymd todmod = tod + calendar = trim(sdat%stream(ns)%calendar) if (trim(sdat%model_calendar) /= trim(sdat%stream(ns)%calendar)) then - calendar = shr_cal_noleap if (( trim(sdat%model_calendar) == trim(shr_cal_gregorian)) .and. & (trim(sdat%stream(ns)%calendar) == trim(shr_cal_noleap))) then ! case (1), set feb 29 = feb 28 @@ -917,6 +917,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if (month == 2 .and. day == 29) then call shr_cal_ymd2date(year,2,28,ymdmod(ns)) endif + calendar = shr_cal_noleap else if ((trim(sdat%model_calendar) == trim(shr_cal_noleap)) .and. & (trim(sdat%stream(ns)%calendar) == trim(shr_cal_gregorian))) then ! case (2), feb 29 input data will be skipped automatically @@ -985,7 +986,6 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ! Reset time bounds if newdata read in call shr_cal_timeSet(timeLB,sdat%pstrm(ns)%ymdLB,0,calendar,rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call shr_cal_timeSet(timeUB,sdat%pstrm(ns)%ymdUB,0,calendar,rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return From 50439d3d47aacc6b6eb0206c430a761795c338e3 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 30 Sep 2022 08:24:32 -0600 Subject: [PATCH 18/21] handle edge case model no_leap, data gregorian --- streams/dshr_strdata_mod.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 53e68d808..0ed4eb62a 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -920,6 +920,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) calendar = shr_cal_noleap else if ((trim(sdat%model_calendar) == trim(shr_cal_noleap)) .and. & (trim(sdat%stream(ns)%calendar) == trim(shr_cal_gregorian))) then + calendar = shr_cal_noleap ! case (2), feb 29 input data will be skipped automatically else ! case (3), abort From fe1bcce0e5b640e0062607784f04bd69f81495d7 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 30 Sep 2022 14:45:50 -0600 Subject: [PATCH 19/21] correct edge case again, optimize code by moving part of if block --- streams/dshr_strdata_mod.F90 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 0ed4eb62a..10d56cb92 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -920,7 +920,10 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) calendar = shr_cal_noleap else if ((trim(sdat%model_calendar) == trim(shr_cal_noleap)) .and. & (trim(sdat%stream(ns)%calendar) == trim(shr_cal_gregorian))) then - calendar = shr_cal_noleap + call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) + if(.not. shr_cal_leapyear(datayear)) then + calendar = shr_cal_noleap + endif ! case (2), feb 29 input data will be skipped automatically else ! case (3), abort From f5c4a51358491ee21a2ab97ccf7b398b79c153d4 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 30 Sep 2022 17:07:57 -0600 Subject: [PATCH 20/21] not fully working when both calendars are GREGORIAN and model is out of sync with data --- streams/dshr_strdata_mod.F90 | 74 +++++++++++++++++------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 10d56cb92..adc9abd8d 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -918,46 +918,8 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) call shr_cal_ymd2date(year,2,28,ymdmod(ns)) endif calendar = shr_cal_noleap - else if ((trim(sdat%model_calendar) == trim(shr_cal_noleap)) .and. & - (trim(sdat%stream(ns)%calendar) == trim(shr_cal_gregorian))) then - call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) - if(.not. shr_cal_leapyear(datayear)) then - calendar = shr_cal_noleap - endif - ! case (2), feb 29 input data will be skipped automatically - else - ! case (3), abort - write(logunit,*) trim(subname),' ERROR: mismatch calendar ', & - trim(sdat%model_calendar),':',trim(sdat%stream(ns)%calendar) - call shr_sys_abort(trim(subname)//' ERROR: mismatch calendar ') - endif - else ! calendars are the same - if(trim(sdat%model_calendar) == trim(shr_cal_gregorian)) then - ! Both are in gregorian - but it's possible that there is a mismatch - ! such that the model is in leapyear but the data is not - call shr_cal_date2ymd (ymd,year,month,day) - call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) - - if(month == 2 .and. day==29) then - if(.not. shr_cal_leapyear(datayear)) then - ! model is in leap year but data is not - calendar = shr_cal_noleap - endif - else if(datamonth == 2) then - if(.not. shr_cal_leapyear(year)) then - if(debug>0 .and. sdat%mainproc) then - write(logunit, *) subname,' dataday = ', dataday - endif - calendar = shr_cal_noleap - endif - else - calendar = sdat%model_calendar - endif - else - calendar = sdat%model_calendar endif endif - ! --------------------------------------------------------- ! Determine if new data is read in - if so then copy ! fldbun_stream_ub to fldbun_stream_lb and read in new fldbun_stream_ub data @@ -987,6 +949,40 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ! --------------------------------------------------------- if (newData(ns)) then + if (trim(sdat%model_calendar) /= trim(sdat%stream(ns)%calendar)) then + if ((trim(sdat%model_calendar) == trim(shr_cal_noleap)) .and. & + (trim(sdat%stream(ns)%calendar) == trim(shr_cal_gregorian))) then + call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) + if(.not. shr_cal_leapyear(datayear)) then + calendar = shr_cal_noleap + endif + ! case (2), feb 29 input data will be skipped automatically + else if (.not. ( trim(sdat%model_calendar) == trim(shr_cal_gregorian)) .and. & + (trim(sdat%stream(ns)%calendar) == trim(shr_cal_noleap))) then + ! case (3), abort + write(logunit,*) trim(subname),' ERROR: mismatch calendar ', & + trim(sdat%model_calendar),':',trim(sdat%stream(ns)%calendar) + call shr_sys_abort(trim(subname)//' ERROR: mismatch calendar ') + endif + else ! calendars are the same + if(trim(sdat%model_calendar) == trim(shr_cal_gregorian)) then + ! Both are in gregorian - but it's possible that there is a mismatch + ! such that the model is in leapyear but the data is not + call shr_cal_date2ymd (ymd,year,month,day) + call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) + if(month == 2 .and. day >= 28) then + if(shr_cal_leapyear(year) .and. .not. shr_cal_leapyear(datayear)) then + ! model is in leap year but data is not + calendar = shr_cal_noleap + endif + else + calendar = sdat%model_calendar + endif + else + calendar = sdat%model_calendar + endif + endif + ! Reset time bounds if newdata read in call shr_cal_timeSet(timeLB,sdat%pstrm(ns)%ymdLB,0,calendar,rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -1010,7 +1006,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) write(sdat%stream(1)%logunit,*) trim(subName),' ERROR: ymdLB, todLB, ymdUB, todUB = ', & sdat%pstrm(ns)%ymdLB, sdat%pstrm(ns)%todLB, sdat%pstrm(ns)%ymdUB, sdat%pstrm(ns)%todUB end if - write(6,*) trim(subname),' ERROR: for stream ',ns + write(6,*) trim(subname),' ERROR: for stream ',ns, ' and calendar ',trim(calendar) write(6,*) trim(subName),' ERROR: dtime, dtmax, dtmin, dtlimit = ',& dtime, sdat%pstrm(ns)%dtmax, sdat%pstrm(ns)%dtmin, sdat%stream(ns)%dtlimit write(6,*) trim(subName),' ERROR: ymdLB, todLB, ymdUB, todUB = ', & From ae777199cae47ffe6eb6259af00a1e2a012bdaa4 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Sat, 1 Oct 2022 10:02:28 -0600 Subject: [PATCH 21/21] yet another calendar patch --- streams/dshr_strdata_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index adc9abd8d..19dee6043 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -895,7 +895,6 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) sdat%ymd = ymd sdat%tod = tod - if (nstreams > 0) then allocate(newData(nstreams)) allocate(ymdmod(nstreams)) @@ -909,6 +908,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ymdmod(ns) = ymd todmod = tod calendar = trim(sdat%stream(ns)%calendar) + call shr_cal_date2ymd (ymd,year,month,day) if (trim(sdat%model_calendar) /= trim(sdat%stream(ns)%calendar)) then if (( trim(sdat%model_calendar) == trim(shr_cal_gregorian)) .and. & (trim(sdat%stream(ns)%calendar) == trim(shr_cal_noleap))) then @@ -953,7 +953,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if ((trim(sdat%model_calendar) == trim(shr_cal_noleap)) .and. & (trim(sdat%stream(ns)%calendar) == trim(shr_cal_gregorian))) then call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) - if(.not. shr_cal_leapyear(datayear)) then + if(datamonth==3 .and. dataday==1 .and. month==2 .and. day==28) then calendar = shr_cal_noleap endif ! case (2), feb 29 input data will be skipped automatically