Skip to content

Commit

Permalink
add explicit fldchk for fields w/ mult sources
Browse files Browse the repository at this point in the history
  • Loading branch information
DeniseWorthen committed Aug 10, 2023
1 parent 99a95ee commit a64074c
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions config_src/drivers/nuopc_cap/mom_cap_methods.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module MOM_cap_methods
end interface

private :: State_setExport
private :: state_fldchk

!> Get field pointer
interface State_GetFldPtr
Expand Down Expand Up @@ -135,17 +136,19 @@ subroutine mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary,
isc, iec, jsc, jec, ice_ocean_boundary%sw_flux_vis_dif, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! ?TODO: clearer if fldchks on alt import field names were here rather than in state_getimport
! -------
! Net longwave radiation (W/m2)
! -------
call state_getimport(importState, 'mean_net_lw_flx', &
isc, iec, jsc, jec, ice_ocean_boundary%lw_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'Faxa_lwnet', &
isc, iec, jsc, jec, ice_ocean_boundary%lw_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (state_fldchk(importState, 'mean_net_lw_flx')) then
call state_getimport(importState, 'mean_net_lw_flx', &
isc, iec, jsc, jec, ice_ocean_boundary%lw_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
if (state_fldchk(importState, 'Faxa_lwnet')) then
call state_getimport(importState, 'Faxa_lwnet', &
isc, iec, jsc, jec, ice_ocean_boundary%lw_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

!----
! zonal and meridional surface stress
Expand Down Expand Up @@ -177,24 +180,32 @@ subroutine mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary,
!----
! sensible heat flux (W/m2)
!----
call state_getimport(importState, 'mean_sensi_heat_flx', &
isc, iec, jsc, jec, ice_ocean_boundary%t_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (state_fldchk(importState, 'mean_sensi_heat_flx')) then
call state_getimport(importState, 'mean_sensi_heat_flx', &
isc, iec, jsc, jec, ice_ocean_boundary%t_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

call state_getimport(importState, 'Faxa_sen', &
isc, iec, jsc, jec, ice_ocean_boundary%t_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (state_fldchk(importState, 'Faxa_sen')) then
call state_getimport(importState, 'Faxa_sen', &
isc, iec, jsc, jec, ice_ocean_boundary%t_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

!----
! evaporation flux (W/m2)
!----
call state_getimport(importState, 'mean_evap_rate', &
isc, iec, jsc, jec, ice_ocean_boundary%q_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (state_fldchk(importState, 'mean_evap_rate')) then
call state_getimport(importState, 'mean_evap_rate', &
isc, iec, jsc, jec, ice_ocean_boundary%q_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

call state_getimport(importState, 'Faxa_evap', &
isc, iec, jsc, jec, ice_ocean_boundary%q_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (state_fldchk(importState, 'Faxa_evap')) then
call state_getimport(importState, 'Faxa_evap', &
isc, iec, jsc, jec, ice_ocean_boundary%q_flux, areacor=med2mod_areacor, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

!----
! liquid precipitation (rain)
Expand Down Expand Up @@ -1108,6 +1119,20 @@ subroutine field_getfldptr(field, fldptr1, fldptr2, rank, abort, rc)

end subroutine field_getfldptr

!> Return true if a field is in a state
logical function state_fldchk(State, fldname)

type(ESMF_State) , intent(in) :: State !< an ESMF state
character(len=*) , intent(in) :: fldname !< field name

! local variables
type(ESMF_StateItem_Flag) :: itemType
! ----------------------------------------------

call ESMF_StateGet(State, trim(fldname), itemType)
state_fldchk = (itemType /= ESMF_STATEITEM_NOTFOUND)
end function state_fldchk

!> Returns true if ESMF_LogFoundError() determines that rc is an error code. Otherwise false.
logical function ChkErr(rc, line, file)
integer, intent(in) :: rc !< return code to check
Expand Down

0 comments on commit a64074c

Please sign in to comment.