Skip to content

Commit

Permalink
Properly import coupling fields when running with separate run phases (
Browse files Browse the repository at this point in the history
…#406)

* Ensure timestamp of imported fields is set before checking the time.
* Add missing specialization method to verify import fields for run phase 1.
  • Loading branch information
rmontuoro authored Oct 5, 2021
1 parent b811a6c commit 95ff1ca
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions fv3_cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine SetServices(gcomp, rc)

! specializations required to support 'inline' run sequences
call NUOPC_CompSpecialize(gcomp, specLabel=label_CheckImport, &
specPhaseLabel="phase1", specRoutine=NUOPC_NoOp, rc=rc)
specPhaseLabel="phase1", specRoutine=fv3_checkimport, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

call NUOPC_CompSpecialize(gcomp, specLabel=label_TimestampExport, &
Expand Down Expand Up @@ -1212,7 +1212,7 @@ subroutine fv3_checkimport(gcomp, rc)
type(ESMF_Clock) :: clock
type(ESMF_Time) :: currTime, invalidTime
type(ESMF_State) :: importState
logical :: timeCheck1,timeCheck2
logical :: isValid
type(ESMF_Field),pointer :: fieldList(:)
character(len=128) :: fldname
character(esmf_maxstr) :: msgString
Expand Down Expand Up @@ -1250,25 +1250,32 @@ subroutine fv3_checkimport(gcomp, rc)
call ESMF_FieldGet(fieldList(n), name=fldname, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

nf = queryImportFields(fldname)
timeCheck1 = NUOPC_IsAtTime(fieldList(n), invalidTime, rc=rc)
! check if import field carries a valid timestamp
call NUOPC_GetTimestamp(fieldList(n), isValid=isValid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

if (timeCheck1) then
importFieldsValid(nf) = .false.
! if(mtype==0) print *,'in fv3_checkimport,',trim(fldname),' is set unvalid, nf=',nf,' at time',date(1:6)
else
timeCheck2 = NUOPC_IsAtTime(fieldList(n), currTime, rc=rc)
if (isValid) then
! if timestamp is set, check if it is valid
isValid = .not.NUOPC_IsAtTime(fieldList(n), invalidTime, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end if

! store field status in internal array
nf = queryImportFields(fldname)
importFieldsValid(nf) = isValid

if (.not.timeCheck2) then
!TODO: introduce and use INCOMPATIBILITY return codes!!!!
if (isValid) then
! check if field is current
isValid = NUOPC_IsAtTime(fieldList(n), currTime, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (.not.isValid) then
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
msg="NUOPC INCOMPATIBILITY DETECTED: Import Field not at current time", &
msg="NUOPC INCOMPATIBILITY DETECTED: Import Field " &
// trim(fldname) // " not at current time", &
line=__LINE__, file=__FILE__, rcToReturn=rc)
return
endif
endif
return
end if
end if
write(msgString,'(A,2i4,l3)') "fv3_checkimport "//trim(fldname),n,nf,importFieldsValid(nf)
call ESMF_LogWrite(msgString,ESMF_LOGMSG_INFO,rc=rc)
enddo
Expand Down

0 comments on commit 95ff1ca

Please sign in to comment.