Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute cleanup, allow coupled executable to run as standalone #111

Merged
merged 34 commits into from
Nov 3, 2021
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
95f9ac3
Merge pull request #1 from NOAA-EMC/develop
DeniseWorthen Oct 4, 2019
39b5e91
Merge pull request #2 from NOAA-EMC/develop
DeniseWorthen Nov 23, 2019
eb563f4
Merge pull request #5 from NOAA-EMC/develop
DeniseWorthen Jan 1, 2020
584c900
Merge pull request #8 from NOAA-EMC/develop
DeniseWorthen Jan 16, 2020
95a1a3b
Merge pull request #9 from NOAA-EMC/develop
DeniseWorthen Jan 24, 2020
afd7481
Merge pull request #11 from NOAA-EMC/develop
DeniseWorthen Jan 28, 2020
eec1e4b
Merge pull request #16 from NOAA-EMC/develop
DeniseWorthen Feb 27, 2020
dc17f0d
Merge pull request #17 from NOAA-EMC/develop
DeniseWorthen Apr 2, 2020
b40ef25
Merge pull request #18 from NOAA-EMC/develop
DeniseWorthen Apr 16, 2020
62c1037
Merge pull request #19 from NOAA-EMC/develop
DeniseWorthen Apr 17, 2020
6e6fb73
Merge pull request #21 from NOAA-EMC/develop
DeniseWorthen Apr 20, 2020
083982c
Merge pull request #24 from NOAA-EMC/develop
DeniseWorthen Apr 24, 2020
fb49539
Merge pull request #27 from NOAA-EMC/develop
DeniseWorthen Apr 27, 2020
25cc1d5
Merge pull request #29 from NOAA-EMC/develop
DeniseWorthen Apr 28, 2020
4262519
Merge pull request #30 from NOAA-EMC/develop
DeniseWorthen May 12, 2020
f4d1c71
Merge pull request #31 from NOAA-EMC/develop
DeniseWorthen May 23, 2020
f968c00
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Jun 19, 2020
15248b7
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Jul 10, 2020
faf5d1c
cice6 compile (#71) (#34)
DeniseWorthen Jul 27, 2020
29430d4
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Jul 28, 2020
97ad165
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Aug 19, 2020
14b0d71
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Aug 27, 2020
3659794
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Sep 5, 2020
ce9463c
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Oct 16, 2020
7a8222b
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Nov 3, 2020
7424a01
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Apr 1, 2021
4fd565e
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Apr 2, 2021
14bad62
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Apr 22, 2021
680fa8f
Merge remote-tracking branch 'upstream/develop' into develop
DeniseWorthen Apr 27, 2021
a5fc946
Merge branch 'NOAA-EMC:develop' into develop
DeniseWorthen Jun 12, 2021
91a5983
Merge branch 'NOAA-EMC:develop' into develop
DeniseWorthen Jul 9, 2021
9111af8
Merge branch 'NOAA-EMC:develop' into develop
DeniseWorthen Jul 20, 2021
bfcc5e4
create clean cleanup branch
DeniseWorthen Oct 14, 2021
542bc0c
Merge branch 'NOAA-EMC:develop' into feature/attrclnup
DeniseWorthen Oct 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 53 additions & 112 deletions src/module_EARTH_GRID_COMP.F90
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ END SUBROUTINE EARTH_REGISTER
!

subroutine SetModelServices(driver, rc)
#ifdef CMEPS
use med_internalstate_mod , only : med_id
#endif

type(ESMF_GridComp) :: driver
integer, intent(out) :: rc

Expand All @@ -241,11 +239,7 @@ subroutine SetModelServices(driver, rc)
type(NUOPC_FreeFormat) :: attrFF, fdFF
logical :: found_comp
logical :: isPresent
#ifdef CMEPS
logical :: read_restart
character(ESMF_MAXSTR) :: cvalue
character(len=5) :: inst_suffix
#endif

rc = ESMF_SUCCESS

! query the Component for info
Expand Down Expand Up @@ -297,15 +291,16 @@ subroutine SetModelServices(driver, rc)
call ESMF_ConfigGetAttribute(config, valueList=compLabels, &
label="EARTH_component_list:", count=componentCount, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
#ifdef CMEPS
inst_suffix = ""

! obtain driver attributes (for CMEPS)
call ReadAttributes(driver, config, "DRIVER_attributes::", formatprint=printattr, rc=rc)
call ReadAttributes(driver, config, "DRIVER_attributes::", relaxedflag=.true., &
formatprint=printattr, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ReadAttributes(driver, config, "ALLCOMP_attributes::", formatprint=printattr, rc=rc)
call ReadAttributes(driver, config, "ALLCOMP_attributes::", relaxedflag=.true., &
formatprint=printattr, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! get starttype and set read_restart attribute in driver config list
call InitRestart(driver, config, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
#endif

! determine information for each component and add to the driver
do i=1, componentCount
Expand Down Expand Up @@ -431,7 +426,6 @@ subroutine SetModelServices(driver, rc)
#endif
#ifdef FRONT_CMEPS
if (trim(model) == "cmeps") then
med_id = i+1
call NUOPC_DriverAddComp(driver, trim(prefix), MED_SS, &
petList=petList, comp=comp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand All @@ -445,39 +439,11 @@ subroutine SetModelServices(driver, rc)
return
endif

! read and ingest free format component attributes
attrFF = NUOPC_FreeFormatCreate(config, &
label=trim(prefix)//"_attributes::", relaxedflag=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeIngest(comp, attrFF, addFlag=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_FreeFormatDestroy(attrFF, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call ESMF_ConfigFindNextLabel(config, &
label=trim(prefix)//"_modelio::", isPresent=isPresent, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent) then
attrFF = NUOPC_FreeFormatCreate(config, &
label=trim(prefix)//"_modelio::", relaxedflag=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeIngest(comp, attrFF, addFlag=.true., rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_FreeFormatDestroy(attrFF, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif
call AddAttributes(comp, driver, config, trim(prefix), rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

! clean-up
deallocate(petList)

#ifdef CMEPS
! Perform restarts if appropriate
call InitRestart(driver, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call AddAttributes(comp, driver, config, i+1, trim(prefix), inst_suffix, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
#endif
enddo

! clean-up
Expand Down Expand Up @@ -586,7 +552,6 @@ recursive subroutine ModifyCplLists(driver, importState, exportState, clock, &

!-----------------------------------------------------------------------------

#ifdef CMEPS
subroutine ReadAttributes(gcomp, config, label, relaxedflag, formatprint, rc)

use ESMF , only : ESMF_GridComp, ESMF_Config, ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_SUCCESS
Expand Down Expand Up @@ -631,7 +596,7 @@ subroutine ReadAttributes(gcomp, config, label, relaxedflag, formatprint, rc)

end subroutine ReadAttributes

subroutine InitRestart(driver, rc)
subroutine InitRestart(driver, config, rc)

!-----------------------------------------------------
! Determine if will restart and read pointer file if appropriate
Expand All @@ -643,12 +608,13 @@ subroutine InitRestart(driver, rc)

! input/output variables
type(ESMF_GridComp) , intent(inout) :: driver
type(ESMF_Config) , intent(inout) :: config
integer , intent(out) :: rc

! local variables
logical :: read_restart ! read the restart file, based on start_type
character(len=ESMF_MAXSTR) :: cvalue ! temporary
character(len=ESMF_MAXSTR) :: rest_case_name ! Short case identification
character(len=ESMF_MAXSTR) :: attribute !
character(len=*) , parameter :: subname = "(module_EARTH_GRID_COMP.F90:InitRestart)"
!-------------------------------------------

Expand All @@ -659,24 +625,22 @@ subroutine InitRestart(driver, rc)
! Carry out restart if appropriate
!-----------------------------------------------------

read_restart = IsRestart(driver, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! Add rest_case_name and read_restart to driver attributes
call NUOPC_CompAttributeAdd(driver, attrList=(/'rest_case_name','read_restart '/), rc=rc)
read_restart = IsRestart(driver, config, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

rest_case_name = ' '
call NUOPC_CompAttributeSet(driver, name='rest_case_name', value=rest_case_name, rc=rc)
attribute = 'read_restart'
! Add read_restart to driver attributes
call NUOPC_CompAttributeAdd(driver, attrList=(/trim(attribute)/), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

write(cvalue,*) read_restart
call NUOPC_CompAttributeSet(driver, name='read_restart', value=trim(cvalue), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite('Set attribute read_restart in driver ', ESMF_LOGMSG_INFO)

end subroutine InitRestart

function IsRestart(gcomp, rc)
function IsRestart(gcomp, config, rc)

use ESMF , only : ESMF_GridComp, ESMF_SUCCESS
use ESMF , only : ESMF_LogSetError, ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_RC_NOT_VALID
Expand All @@ -685,9 +649,11 @@ function IsRestart(gcomp, rc)
! input/output variables
logical :: IsRestart
type(ESMF_GridComp) , intent(inout) :: gcomp
type(ESMF_Config) , intent(inout) :: config
integer , intent(out) :: rc

! locals
logical :: isPresent, isSet
character(len=ESMF_MAXSTR) :: start_type ! Type of startup
character(len=ESMF_MAXSTR) :: msgstr
character(len=*) , parameter :: start_type_start = "startup"
Expand All @@ -699,26 +665,32 @@ function IsRestart(gcomp, rc)
rc = ESMF_SUCCESS

! First Determine if restart is read
call NUOPC_CompAttributeGet(gcomp, name='start_type', value=start_type, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name='start_type', value=start_type, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if ((trim(start_type) /= start_type_start) .and. &
(trim(start_type) /= start_type_cont ) .and. &
(trim(start_type) /= start_type_brnch)) then
write (msgstr, *) subname//': start_type invalid = '//trim(start_type)
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msgstr, line=__LINE__, file=__FILE__, rcToReturn=rc)
return
end if
if( isPresent .and. isSet) then
if ((trim(start_type) /= start_type_start) .and. &
(trim(start_type) /= start_type_cont ) .and. &
(trim(start_type) /= start_type_brnch)) then
write (msgstr, *) subname//': start_type invalid = '//trim(start_type)
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msgstr, line=__LINE__, file=__FILE__, rcToReturn=rc)
return
end if

!TODO: this is hard-wired to CIME start/continue types in terms of gcomp
IsRestart = .false.
if (trim(start_type) == trim(start_type_cont) .or. trim(start_type) == trim(start_type_brnch)) then
IsRestart = .true.
end if
!TODO: this is hard-wired to CIME start/continue types in terms of gcomp
IsRestart = .false.
if (trim(start_type) == trim(start_type_cont) .or. trim(start_type) == trim(start_type_brnch)) then
IsRestart = .true.
end if
else
IsRestart = .false.
call ESMF_LogWrite('No start_type attribute found, setting read_restart false ', ESMF_LOGMSG_INFO)
endif

end function IsRestart

subroutine AddAttributes(gcomp, driver, config, compid, compname, inst_suffix, rc)
subroutine AddAttributes(gcomp, driver, config, compname, rc)

! Add specific set of attributes to components from driver attributes

Expand All @@ -730,9 +702,7 @@ subroutine AddAttributes(gcomp, driver, config, compid, compname, inst_suffix, r
type(ESMF_GridComp) , intent(inout) :: gcomp
type(ESMF_GridComp) , intent(in) :: driver
type(ESMF_Config) , intent(inout) :: config
integer , intent(in) :: compid
character(len=*) , intent(in) :: compname
character(len=*) , intent(in) :: inst_suffix
integer , intent(inout) :: rc

! local variables
Expand All @@ -752,20 +722,8 @@ subroutine AddAttributes(gcomp, driver, config, compid, compname, inst_suffix, r
call ESMF_LogWrite(trim(subname)//": called", ESMF_LOGMSG_INFO)

!------
! Add compid to gcomp attributes
! Add restart flag to gcomp attributes
!------
!write(cvalue,*) compid
!call NUOPC_CompAttributeAdd(gcomp, attrList=(/'MCTID'/), rc=rc)
!if (chkerr(rc,__LINE__,u_FILE_u)) return
!call NUOPC_CompAttributeSet(gcomp, name='MCTID', value=trim(cvalue), rc=rc)
!if (chkerr(rc,__LINE__,u_FILE_u)) return

!------
! Add all the other attributes in AttrList (which have already been added to driver attributes)
!------
!allocate(attrList(5))
!attrList = (/"read_restart", "orb_eccen ", "orb_obliqr ", "orb_lambm0 ", "orb_mvelpp "/)
! TODO: orb_obliqr and orb_lambm0 not exist
allocate(attrList(1))
attrList = (/"read_restart"/)

Expand All @@ -774,61 +732,44 @@ subroutine AddAttributes(gcomp, driver, config, compid, compname, inst_suffix, r

do n = 1,size(attrList)
if (trim(attrList(n)) == "read_restart") then
call NUOPC_CompAttributeGet(driver, name="mediator_read_restart", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(driver, name="read_restart", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

read(cvalue,*) lvalue

if (.not. lvalue) then
call NUOPC_CompAttributeGet(driver, name=trim(attrList(n)), value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

call NUOPC_CompAttributeSet(gcomp, name=trim(attrList(n)), value=trim(cvalue), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
print*, trim(attrList(n))
print *, trim(attrList(n))
call NUOPC_CompAttributeGet(driver, name=trim(attrList(n)), value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeSet(gcomp, name=trim(attrList(n)), value=trim(cvalue), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
call ESMF_LogWrite('Added attribute '//trim(attrList(n))//' to '//trim(compname), ESMF_LOGMSG_INFO)
enddo
deallocate(attrList)

!------
! Add component specific attributes
!------
call ReadAttributes(gcomp, config, trim(compname)//"_attributes::", formatprint=printattr, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call ReadAttributes(gcomp, config, "ALLCOMP_attributes::", formatprint=printattr, rc=rc)
call ReadAttributes(gcomp, config, trim(compname)//"_attributes::", relaxedflag=.true., &
formatprint=printattr, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

!------
! Add multi-instance specific attributes
!------
call NUOPC_CompAttributeAdd(gcomp, attrList=(/'inst_index'/), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ReadAttributes(gcomp, config, trim(compname)//"_modelio::", relaxedflag=.true., &
formatprint=printattr, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

! add inst_index attribute (inst_index is not required for cime internal components)
! for now hard-wire inst_index to 1
inst_index = 1
write(cvalue,*) inst_index
call NUOPC_CompAttributeSet(gcomp, name='inst_index', value=trim(cvalue), rc=rc)
call ReadAttributes(gcomp, config, "ALLCOMP_attributes::", relaxedflag=.true., &
formatprint=printattr, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! add inst_suffix attribute
if (len_trim(inst_suffix) > 0) then
call NUOPC_CompAttributeAdd(gcomp, attrList=(/'inst_suffix'/), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call NUOPC_CompAttributeSet(gcomp, name='inst_suffix', value=inst_suffix, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

end subroutine AddAttributes
#endif
!
!-----------------------------------------------------------------------
!
Expand Down