readVar1D Subroutine

public subroutine readVar1D(filename, varname, farray, rc)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: varname
real(kind=ESMF_KIND_R8), TARGET :: farray(:)
integer :: rc

Source Code

  subroutine readVar1D(filename, varname, farray, rc)

  character(len=*), intent(in) :: filename
  character(len=*), intent(in) :: varname
  real(ESMF_KIND_R8), TARGET  :: farray(:)
  integer                      :: rc

    character(len=128) :: errmsg
    integer, parameter :: nf90_noerror = 0
    integer :: ncStatus
    integer ::  gridid, varid

    rc = ESMF_FAILURE

#ifdef ESMF_NETCDF
    ncStatus = nf90_open (path=filename, mode=nf90_nowrite, ncid=gridid)
    errmsg = 'Fail to open '//trim(filename)
    if (CDFCheckError (ncStatus, &
            ESMF_METHOD, &
            ESMF_SRCLINE,&
            errmsg, &
            rc)) return

    ncStatus = nf90_inq_varid(gridid, varname, varid)
    errmsg = 'Data variable '//trim(varname)//' does not exist'
    if (CDFCheckError (ncStatus, &
            ESMF_METHOD, &
            ESMF_SRCLINE,&
            errmsg, &
            rc)) return

    ncStatus = nf90_get_var(gridid, varid, farray)
    errmsg = 'Fail to read variable '//trim(varname)
    if (CDFCheckError (ncStatus, &
            ESMF_METHOD, &
            ESMF_SRCLINE,&
            errmsg, &
            rc)) return
    rc = ESMF_SUCCESS
    return
#else
    call ESMF_LogSetError(rcToCheck=ESMF_RC_LIB_NOT_PRESENT, &
      msg="- ESMF_NETCDF not defined when lib was compiled", &
      ESMF_CONTEXT, rcToReturn=rc)
    return
#endif
  end subroutine readVar1D