Skip to content

Commit

Permalink
Formatting and switch to usage of standard NUOPC Attribute "Namespace"
Browse files Browse the repository at this point in the history
when identifying the fields in nested state during output.
  • Loading branch information
theurich committed Dec 9, 2024
1 parent 2a215a5 commit 29c6804
Showing 1 changed file with 56 additions and 46 deletions.
102 changes: 56 additions & 46 deletions AtmOcnMirrorFieldsNestedProto/atm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ subroutine Advertise(model, rc)
file=__FILE__)) &
return ! bail out

call NUOPC_SetAttribute(importState, "FieldTransferPolicy", "transferAllAsNests", &
rc=rc)
call NUOPC_SetAttribute(importState, "FieldTransferPolicy", &
"transferAllAsNests", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
Expand Down Expand Up @@ -133,7 +133,8 @@ subroutine RealizeAccepted(model, rc)
allocate(importItemTypeList(importItemCount))

! query importState
call ESMF_StateGet(importState, nestedFlag=.false., itemNameList=importItemNameList, itemTypeList=importItemTypeList, rc=rc)
call ESMF_StateGet(importState, nestedFlag=.false., &
itemNameList=importItemNameList, itemTypeList=importItemTypeList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
Expand All @@ -144,14 +145,16 @@ subroutine RealizeAccepted(model, rc)
! query item
if (importItemTypeList(i) == ESMF_STATEITEM_STATE) then
! pull out nested state
call ESMF_StateGet(importState, itemName=importItemNameList(i), nestedState=importNestedState, rc=rc)
call ESMF_StateGet(importState, itemName=importItemNameList(i), &
nestedState=importNestedState, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
return ! bail out

! query nested state
call ESMF_StateGet(importNestedState, name=nestedStateName, itemCount=importNestedItemCount, rc=rc)
call ESMF_StateGet(importNestedState, name=nestedStateName, &
itemCount=importNestedItemCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
Expand All @@ -162,7 +165,8 @@ subroutine RealizeAccepted(model, rc)
allocate(importNestedItemTypeList(importNestedItemCount))

! query item name and types in the nested state
call ESMF_StateGet(importNestedState, itemNameList=importNestedItemNameList, &
call ESMF_StateGet(importNestedState, &
itemNameList=importNestedItemNameList, &
itemTypeList=importNestedItemTypeList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
Expand All @@ -171,9 +175,13 @@ subroutine RealizeAccepted(model, rc)

! loop over items in importNestedState
do j = 1, importNestedItemCount
call ESMF_LogWrite('realize '//trim(importNestedItemNameList(j))//' import field received from '//trim(nestedStateName), ESMF_LOGMSG_INFO)
call ESMF_LogWrite('realize '//&
trim(importNestedItemNameList(j))//&
' import field received from '//trim(nestedStateName), &
ESMF_LOGMSG_INFO)

call NUOPC_Realize(importNestedState, fieldName=trim(importNestedItemNameList(j)), rc=rc)
call NUOPC_Realize(importNestedState, &
fieldName=trim(importNestedItemNameList(j)), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
Expand All @@ -197,20 +205,20 @@ subroutine RealizeAccepted(model, rc)
subroutine Advance(model, rc)
type(ESMF_GridComp) :: model
integer, intent(out) :: rc

! local variables
type(ESMF_Clock) :: clock
type(ESMF_State) :: importState, exportState
type(ESMF_State) :: importNestedState
character(ESMF_MAXSTR) :: nestedStateName
character(ESMF_MAXSTR) :: namespace
character(ESMF_MAXSTR), allocatable :: importItemNameList(:)
type(ESMF_StateItem_Flag), allocatable :: importItemTypeList(:)
integer :: i, importItemCount
integer, save :: slice=1
character(len=160) :: msgString

rc = ESMF_SUCCESS

! query for clock, importState and exportState
call NUOPC_ModelGet(model, modelClock=clock, importState=importState, &
exportState=exportState, rc=rc)
Expand All @@ -220,12 +228,12 @@ subroutine Advance(model, rc)
return ! bail out

! HERE THE MODEL ADVANCES: currTime -> currTime + timeStep

! Because of the way that the internal Clock was set by default,
! its timeStep is equal to the parent timeStep. As a consequence the
! currTime + timeStep is equal to the stopTime of the internal Clock
! for this call of the Advance() routine.

call ESMF_ClockPrint(clock, options="currTime", &
preString="------>Advancing ATM from: ", unit=msgString, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
Expand All @@ -237,7 +245,7 @@ subroutine Advance(model, rc)
line=__LINE__, &
file=__FILE__)) &
return ! bail out

call ESMF_ClockPrint(clock, options="stopTime", &
preString="---------------------> to: ", unit=msgString, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
Expand All @@ -258,7 +266,7 @@ subroutine Advance(model, rc)
file=__FILE__)) &
return ! bail out

! query number of item in importState
! query number of item in importState
call ESMF_StateGet(importState, itemCount=importItemCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
Expand All @@ -270,43 +278,45 @@ subroutine Advance(model, rc)
allocate(importItemTypeList(importItemCount))

! query importState
call ESMF_StateGet(importState, nestedFlag=.false., itemNameList=importItemNameList, itemTypeList=importItemTypeList, rc=rc)
call ESMF_StateGet(importState, nestedFlag=.false., &
itemNameList=importItemNameList, itemTypeList=importItemTypeList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

! loop over items in importState
do i = 1, importItemCount
! query item
if (importItemTypeList(i) == ESMF_STATEITEM_STATE) then
! pull out nested state
call ESMF_StateGet(importState, &
itemName=importItemNameList(i), nestedState=importNestedState, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

call ESMF_StateGet(importNestedState, name=nestedStateName, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

! convert state name to lower case
nestedStateName = ESMF_UtilStringLowerCase(nestedStateName)

! write out the Fields in the importState and exportState
call NUOPC_Write(importNestedState, &
fileNamePrefix='field_atm_import_from_'//trim(nestedStateName)//'_', &
timeslice=slice, overwrite=.true., relaxedFlag=.true., rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
end if
end do
! query item
if (importItemTypeList(i) == ESMF_STATEITEM_STATE) then
! pull out nested state
call ESMF_StateGet(importState, &
itemName=importItemNameList(i), nestedState=importNestedState, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

call NUOPC_GetAttribute(importNestedState, name="Namespace", &
value=namespace, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

! convert state name to lower case
namespace = ESMF_UtilStringLowerCase(namespace)

! write out the Fields in the importState and exportState
call NUOPC_Write(importNestedState, &
fileNamePrefix='field_atm_import_namespace:'//trim(namespace)//'_', &
timeslice=slice, overwrite=.true., relaxedFlag=.true., rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
end if
end do
slice = slice+1

end subroutine
Expand Down

0 comments on commit 29c6804

Please sign in to comment.