ESMF_MeshCreateFromFile Function

private function ESMF_MeshCreateFromFile(filename, fileformat, keywordEnforcer, convertToDual, addUserArea, maskFlag, varname, nodalDistgrid, elementDistgrid, coordSys, name, rc)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
type(ESMF_FileFormat_Flag), intent(in) :: fileformat
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
logical, intent(in), optional :: convertToDual
logical, intent(in), optional :: addUserArea
type(ESMF_MeshLoc), intent(in), optional :: maskFlag
character(len=*), intent(in), optional :: varname
type(ESMF_DistGrid), intent(in), optional :: nodalDistgrid
type(ESMF_DistGrid), intent(in), optional :: elementDistgrid
type(ESMF_CoordSys_Flag), intent(in), optional :: coordSys
character(len=*), intent(in), optional :: name
integer, intent(out), optional :: rc

Return Value type(ESMF_Mesh)


Source Code

    function ESMF_MeshCreateFromFile(filename, fileformat, keywordEnforcer, &
                 convertToDual, addUserArea, maskFlag, varname, &
                 nodalDistgrid, elementDistgrid, &
                 coordSys, name, rc)
!
!
! !RETURN VALUE:
    type(ESMF_Mesh)         :: ESMF_MeshCreateFromFile
! !ARGUMENTS:
    character(len=*),           intent(in)            :: filename
    type(ESMF_FileFormat_Flag), intent(in)            :: fileformat
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
    logical,                    intent(in),  optional :: convertToDual
    logical,                    intent(in),  optional :: addUserArea
    type(ESMF_MeshLoc),         intent(in),  optional :: maskFlag
    character(len=*),           intent(in),  optional :: varname
    type(ESMF_DistGrid),        intent(in),  optional :: nodalDistgrid
    type(ESMF_DistGrid),        intent(in),  optional :: elementDistgrid
    type(ESMF_CoordSys_Flag),   intent(in),  optional :: coordSys
    character(len=*),           intent(in),  optional :: name
    integer,                    intent(out), optional :: rc
!
! !DESCRIPTION:
!   Create a Mesh from a file. Provides options to convert to 3D and in the case of SCRIP
!   format files, allows the dual of the mesh to be created.
!
!   This call is {\em collective} across the current VM.
!
!   \begin{description}
!   \item [filename]
!         The name of the grid file
!   \item[fileformat]
!         The file format. The valid options are {\tt ESMF\_FILEFORMAT\_SCRIP}, {\tt ESMF\_FILEFORMAT\_ESMFMESH} and
!         {\tt ESMF\_FILEFORMAT\_UGRID}.
!         Please see Section~\ref{const:fileformatflag} for a detailed description of the options.
!   \item[{[convertToDual]}]
!         if {\tt .true.}, the mesh will be converted to its dual. If not specified,
!         defaults to {\tt .false.}.
!   \item[{[addUserArea]}]
!         if {\tt .true.}, the cell area will be read in from the GRID file.  This feature is
!         only supported when the grid file is in the SCRIP or ESMF format. If not specified,
!         defaults to {\tt .false.}.
!   \item[{[maskFlag]}]
!         If maskFlag is present, generate the mask using the missing\_value attribute defined in 'varname'
!         This flag is only supported when the grid file is in the UGRID format.
!         The value could be either {\tt ESMF\_MESHLOC\_NODE} or {\tt ESMF\_MESHLOC\_ELEMENT}.  If the value is
!         {\tt ESMF\_MESHLOC\_NODE}, the node mask will be generated and the variable has to be
!         defined on the "node" (specified by its {\tt location} attribute).  If the value is
!         {\tt ESMF\_MESHLOC\_ELEMENT}, the element mask will be generated and the variable has to be
!         defined on the "face" of the mesh.  If the variable is not defined on the right location,
!         no mask will be generated.  If not specified, no mask will be generated.
!   \item[{[varname]}]
!         If maskFlag is present, provide a variable name stored in the UGRID file and
!         the mask will be generated using the missing value of the data value of
!         this variable.  The first two dimensions of the variable has to be the
!         the longitude and the latitude dimension and the mask is derived from the
!         first 2D values of this variable even if this data is 3D, or 4D array. If not
!         specified, defaults to empty string.
!   \item [{[nodalDistgrid]}]
!         A Distgrid describing the user-specified distribution of
!         the nodes across the PETs.
!   \item [{[elementDistgrid]}]
!         A Distgrid describing the user-specified distribution of
!         the elements across the PETs.
!   \item[{[coordSys]}]
!         The coordinate system in which to store the mesh coordinate data.
!         If this setting doesn't match the coordinate system in the file, then
!         the coordinates in the file will be converted to this system during mesh
!         creation. It is currently an error to convert Cartesian file coordinates
!         into a spherical coordinate system.  
!         For a full list of options, please see Section~\ref{const:coordsys}.
!         If not specified, then defaults to the coordinate system in the file.  
!   \item [{[name]}]
!         The name of the Mesh.
!   \item [{[rc]}]
!         Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOP
!------------------------------------------------------------------------------
    type(ESMF_Mesh) :: myMesh
    integer::  localrc
    type(ESMF_Logical) :: localAddUserArea
    type(ESMF_Logical) :: localConvertToDual
    type(ESMF_CoordSys_Flag) :: localCoordSys
    type(ESMF_MeshLoc) :: localMaskFlag

    ! Check init status of arguments
    ESMF_INIT_CHECK_DEEP(ESMF_DistgridGetInit, nodalDistgrid, rc)
    ESMF_INIT_CHECK_DEEP(ESMF_DistgridGetInit, elementDistgrid, rc)


    ! Process optional arguments and at the same time convert to a format to go through to C
    localAddUserArea=ESMF_FALSE
    if (present(addUserArea)) then
       localAddUserArea=addUserArea
    endif

    localConvertToDual=ESMF_FALSE
    if (present(convertToDual)) then
       localConvertToDual=convertToDual
    endif

    localCoordSys=ESMF_COORDSYS_UNINIT
    if (present(coordSys)) then
       localCoordSys=coordSys
    endif

    localMaskFlag=ESMF_MESHLOC_NONE
    if (present(maskFlag)) then
       localMaskFlag=maskFlag
    endif


    ! Call into C 
    call c_ESMC_MeshCreateFromFile(ESMF_MeshCreateFromFile%this, &
         filename, fileformat, &
         localConvertToDual, localAddUserArea, &
         localCoordSys, &
         localMaskFlag, varname, & 
         nodalDistgrid, elementDistgrid, &
         localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
         ESMF_CONTEXT, rcToReturn=rc)) return


    ! Set nodeDistgrid in Mesh
    if (present(nodalDistgrid)) then
      call c_ESMC_MeshSetNodeDistGrid(ESMF_MeshCreateFromFile, nodalDistgrid, localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
    else
      call C_ESMC_MeshCreateNodeDistGrid(ESMF_MeshCreateFromFile, localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
    endif

    ! Set elementDistgrid in Mesh
    if (present(elementDistgrid)) then
      call c_ESMC_MeshSetElemDistGrid(ESMF_MeshCreateFromFile, elementDistgrid, localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
    else
      call C_ESMC_MeshCreateElemDistGrid(ESMF_MeshCreateFromFile, localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
    endif


    ! Set the name in Base object
    ! Do this here for now, but eventually move into above C func
    if (present(name)) then
      call c_ESMC_SetName(ESMF_MeshCreateFromFile, "Mesh", name, localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return
    endif


    ! Change status
    call C_ESMC_MeshSetStatus(ESMF_MeshCreateFromFile, ESMF_MESHSTATUS_COMPLETE)

    ! Set init status of arguments
    ESMF_INIT_SET_CREATED(ESMF_MeshCreateFromFile)

    ! Return success
    if (present(rc)) rc=ESMF_SUCCESS

end function ESMF_MeshCreateFromFile