IONCOpen Subroutine

private subroutine IONCOpen(IOComp, fileName, keywordEnforcer, filePath, localDe, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_GridComp), intent(inout) :: IOComp
character(len=*), intent(in) :: fileName
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
character(len=*), intent(in), optional :: filePath
integer, intent(in), optional :: localDe
integer, intent(out), optional :: rc

Source Code

  subroutine IONCOpen(IOComp, fileName, keywordEnforcer, filePath, localDe, rc)
    type(ESMF_GridComp), intent(inout)         :: IOComp
    character(len=*),    intent(in)            :: fileName
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
    character(len=*),    intent(in),  optional :: filePath
    integer,             intent(in),  optional :: localDe
    integer,             intent(out), optional :: rc

    ! -- local variables
    integer :: localrc
    integer :: ncStatus
    integer :: de, tileCount
    character(len=ESMF_MAXPATHLEN) :: fullName
    type(ioWrapper) :: is
    type(ESMF_Grid) :: grid

    ! -- begin
    if (present(rc)) rc = ESMF_SUCCESS

    if (.not.ESMF_GridCompIsPetLocal(IOComp)) return

#ifdef ESMF_NETCDF
    de = 0
    if (present(localDe)) de = localDe

    call ESMF_GridCompGetInternalState(IOComp, is, localrc)
    if (ESMF_LogFoundError(rcToCheck=localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return  ! bail out

    call ESMF_GridCompGet(IOComp, grid=grid, rc=localrc)
    if (ESMF_LogFoundError(rcToCheck=localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return  ! bail out

    call ESMF_GridGet(grid, tileCount=tileCount, rc=localrc)
    if (ESMF_LogFoundError(rcToCheck=localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return  ! bail out

    if (is % IO % IOLayout(de) % localIOflag) then

      if (tileCount > 1) then
        call IOFilenameGet(fullName, fileName, filePath=filePath, &
          tile=is % IO % IOLayout(de) % tile)
      else
        call IOFilenameGet(fullName, fileName, filePath=filePath)
      end if

      ncStatus = nf90_open(trim(fullName), NF90_NOWRITE, is % IO % IOLayout(de) % ncid)
      if (ESMF_LogFoundNetCDFError(ncerrToCheck=ncStatus, &
        msg="Error opening NetCDF data set: "//trim(fullName), &
        ESMF_CONTEXT, rcToReturn=rc)) return  ! bail out

    end if
#else
    call ESMF_LogSetError(rcToCheck=ESMF_RC_LIB_NOT_PRESENT, &
                 msg="- ESMF_NETCDF not defined when lib was compiled", &
                 ESMF_CONTEXT, rcToReturn=rc)
#endif

  end subroutine IONCOpen