@@ -30,6 +30,7 @@ module MOM_cap_methods
3030public :: mom_import
3131public :: mom_export
3232public :: state_diagnose
33+ public :: ChkErr
3334
3435private :: State_getImport
3536private :: State_setExport
@@ -251,9 +252,9 @@ subroutine mom_import(ocean_public, ocean_grid, importState, ice_ocean_boundary,
251252
252253
253254 !- ---
254- ! Partitioned Stokes Drift Components
255+ ! Partitioned Stokes Drift Components
255256 !- ---
256- if ( associated (ice_ocean_boundary% ustkb) ) then
257+ if ( associated (ice_ocean_boundary% ustkb) ) then
257258 allocate (stkx1(isc:iec,jsc:jec))
258259 allocate (stky1(isc:iec,jsc:jec))
259260 allocate (stkx2(isc:iec,jsc:jec))
@@ -765,15 +766,18 @@ subroutine State_SetExport(state, fldname, isc, iec, jsc, jec, input, ocean_grid
765766
766767end subroutine State_SetExport
767768
769+ ! > This subroutine writes the minimum, maximum and sum of each field
770+ ! ! contained within an ESMF state.
768771subroutine state_diagnose (State , string , rc )
769772
770773 ! ----------------------------------------------
771774 ! Diagnose status of State
772775 ! ----------------------------------------------
773776
774- type (ESMF_State), intent (in ) :: state
775- character (len=* ), intent (in ) :: string
776- integer , intent (out ) :: rc
777+ type (ESMF_State), intent (in ) :: state ! < An ESMF State
778+ character (len=* ), intent (in ) :: string ! < A string indicating whether the State is an
779+ ! ! import or export State
780+ integer , intent (out ) :: rc ! < Return code
777781
778782 ! local variables
779783 integer :: i,j,n
@@ -787,19 +791,19 @@ subroutine state_diagnose(State, string, rc)
787791 ! ----------------------------------------------
788792
789793 call ESMF_StateGet(state, itemCount= fieldCount, rc= rc)
790- if (chkerr (rc,__LINE__,u_FILE_u)) return
794+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
791795 allocate (lfieldnamelist(fieldCount))
792796
793797 call ESMF_StateGet(state, itemNameList= lfieldnamelist, rc= rc)
794- if (chkerr (rc,__LINE__,u_FILE_u)) return
798+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
795799
796800 do n = 1 , fieldCount
797801
798802 call ESMF_StateGet(state, itemName= lfieldnamelist(n), field= lfield, rc= rc)
799- if (chkerr (rc,__LINE__,u_FILE_u)) return
803+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
800804
801805 call field_getfldptr(lfield, fldptr1= dataPtr1d, fldptr2= dataPtr2d, rank= lrank, rc= rc)
802- if (chkerr (rc,__LINE__,u_FILE_u)) return
806+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
803807
804808 if (lrank == 0 ) then
805809 ! no local data
@@ -829,23 +833,16 @@ subroutine state_diagnose(State, string, rc)
829833
830834end subroutine state_diagnose
831835
832- ! ===============================================================================
833-
836+ ! > Obtain a pointer to a rank 1 or rank 2 ESMF field
834837subroutine field_getfldptr (field , fldptr1 , fldptr2 , rank , abort , rc )
835838
836- ! ----------------------------------------------
837- ! for a field, determine rank and return fldptr1 or fldptr2
838- ! abort is true by default and will abort if fldptr is not yet allocated in field
839- ! rank returns 0, 1, or 2. 0 means fldptr not allocated and abort=false
840- ! ----------------------------------------------
841-
842839 ! input/output variables
843- type (ESMF_Field) , intent (in ) :: field
844- real (ESMF_KIND_R8 ), pointer , intent (inout ), optional :: fldptr1(:)
845- real (ESMF_KIND_R8 ), pointer , intent (inout ), optional :: fldptr2(:,:)
846- integer , intent (out ) , optional :: rank
847- logical , intent (in ) , optional :: abort
848- integer , intent (out ) , optional :: rc
840+ type (ESMF_Field) , intent (in ) :: field ! < An ESMF field
841+ real (ESMF_KIND_R8 ), pointer , intent (inout ), optional :: fldptr1(:) ! < A pointer to a rank 1 ESMF field
842+ real (ESMF_KIND_R8 ), pointer , intent (inout ), optional :: fldptr2(:,:) ! < A pointer to a rank 2 ESMF field
843+ integer , intent (out ) , optional :: rank ! < Field rank
844+ logical , intent (in ) , optional :: abort ! < Abort code
845+ integer , intent (out ) , optional :: rc ! < Return code
849846
850847 ! local variables
851848 type (ESMF_GeomType_Flag) :: geomtype
@@ -872,7 +869,7 @@ subroutine field_getfldptr(field, fldptr1, fldptr2, rank, abort, rc)
872869 lrank = - 99
873870
874871 call ESMF_FieldGet(field, status= status, rc= rc)
875- if (chkerr (rc,__LINE__,u_FILE_u)) return
872+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
876873
877874 if (status /= ESMF_FIELDSTATUS_COMPLETE) then
878875 lrank = 0
@@ -886,20 +883,20 @@ subroutine field_getfldptr(field, fldptr1, fldptr2, rank, abort, rc)
886883 else
887884
888885 call ESMF_FieldGet(field, geomtype= geomtype, rc= rc)
889- if (chkerr (rc,__LINE__,u_FILE_u)) return
886+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
890887
891888 if (geomtype == ESMF_GEOMTYPE_GRID) then
892889 call ESMF_FieldGet(field, rank= lrank, rc= rc)
893- if (chkerr (rc,__LINE__,u_FILE_u)) return
890+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
894891 elseif (geomtype == ESMF_GEOMTYPE_MESH) then
895892 call ESMF_FieldGet(field, rank= lrank, rc= rc)
896- if (chkerr (rc,__LINE__,u_FILE_u)) return
893+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
897894 call ESMF_FieldGet(field, mesh= lmesh, rc= rc)
898- if (chkerr (rc,__LINE__,u_FILE_u)) return
895+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
899896 call ESMF_MeshGet(lmesh, numOwnedNodes= nnodes, numOwnedElements= nelements, rc= rc)
900- if (chkerr (rc,__LINE__,u_FILE_u)) return
897+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
901898 if (nnodes == 0 .and. nelements == 0 ) lrank = 0
902- else
899+ else
903900 call ESMF_LogWrite(trim (subname)// " : ERROR geomtype not supported " , &
904901 ESMF_LOGMSG_INFO)
905902 rc = ESMF_FAILURE
@@ -917,7 +914,7 @@ subroutine field_getfldptr(field, fldptr1, fldptr2, rank, abort, rc)
917914 return
918915 endif
919916 call ESMF_FieldGet(field, farrayPtr= fldptr1, rc= rc)
920- if (chkerr (rc,__LINE__,u_FILE_u)) return
917+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
921918 elseif (lrank == 2 ) then
922919 if (.not. present (fldptr2)) then
923920 call ESMF_LogWrite(trim (subname)// " : ERROR missing rank=2 array " , &
@@ -926,7 +923,7 @@ subroutine field_getfldptr(field, fldptr1, fldptr2, rank, abort, rc)
926923 return
927924 endif
928925 call ESMF_FieldGet(field, farrayPtr= fldptr2, rc= rc)
929- if (chkerr (rc,__LINE__,u_FILE_u)) return
926+ if (ChkErr (rc,__LINE__,u_FILE_u)) return
930927 else
931928 call ESMF_LogWrite(trim (subname)// " : ERROR in rank " , &
932929 ESMF_LOGMSG_ERROR, line= __LINE__, file= u_FILE_u)
@@ -942,16 +939,17 @@ subroutine field_getfldptr(field, fldptr1, fldptr2, rank, abort, rc)
942939
943940end subroutine field_getfldptr
944941
945- logical function chkerr (rc , line , file )
946- integer , intent (in ) :: rc
947- integer , intent (in ) :: line
948- character (len=* ), intent (in ) :: file
942+ ! > Returns true if ESMF_LogFoundError() determines that rc is an error code. Otherwise false.
943+ logical function ChkErr (rc , line , file )
944+ integer , intent (in ) :: rc ! < return code to check
945+ integer , intent (in ) :: line ! < Integer source line number
946+ character (len=* ), intent (in ) :: file ! < User-provided source file name
949947 integer :: lrc
950- chkerr = .false.
948+ ChkErr = .false.
951949 lrc = rc
952950 if (ESMF_LogFoundError(rcToCheck= lrc, msg= ESMF_LOGERR_PASSTHRU, line= line, file= file)) then
953- chkerr = .true.
951+ ChkErr = .true.
954952 endif
955- end function chkerr
953+ end function ChkErr
956954
957955end module MOM_cap_methods
0 commit comments