ESMF_FactorRead Subroutine

public subroutine ESMF_FactorRead(filename, factorList, factorIndexList, rc)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
real(kind=ESMF_KIND_R8), intent(out), dimension(:), allocatable :: factorList
integer, intent(out), dimension(:, :), allocatable :: factorIndexList
integer, intent(out), optional :: rc

Calls

proc~~esmf_factorread~~CallsGraph proc~esmf_factorread ESMF_FactorRead proc~esmf_logseterror ESMF_LogSetError proc~esmf_factorread->proc~esmf_logseterror esmf_breakpoint esmf_breakpoint proc~esmf_logseterror->esmf_breakpoint proc~esmf_logrc2msg ESMF_LogRc2Msg proc~esmf_logseterror->proc~esmf_logrc2msg proc~esmf_logwrite ESMF_LogWrite proc~esmf_logseterror->proc~esmf_logwrite c_esmc_loggeterrormsg c_esmc_loggeterrormsg proc~esmf_logrc2msg->c_esmc_loggeterrormsg c_esmc_vmwtime c_esmc_vmwtime proc~esmf_logwrite->c_esmc_vmwtime proc~esmf_logclose ESMF_LogClose proc~esmf_logwrite->proc~esmf_logclose proc~esmf_logflush ESMF_LogFlush proc~esmf_logwrite->proc~esmf_logflush proc~esmf_logopenfile ESMF_LogOpenFile proc~esmf_logwrite->proc~esmf_logopenfile proc~esmf_utiliounitflush ESMF_UtilIOUnitFlush proc~esmf_logwrite->proc~esmf_utiliounitflush proc~esmf_utilstring2array ESMF_UtilString2Array proc~esmf_logwrite->proc~esmf_utilstring2array proc~esmf_logclose->proc~esmf_logflush proc~esmf_logflush->proc~esmf_utiliounitflush proc~esmf_utilarray2string ESMF_UtilArray2String proc~esmf_logflush->proc~esmf_utilarray2string proc~esmf_logopenfile->proc~esmf_utiliounitflush proc~esmf_utiliounitget ESMF_UtilIOUnitGet proc~esmf_logopenfile->proc~esmf_utiliounitget

Called by

proc~~esmf_factorread~~CalledByGraph proc~esmf_factorread ESMF_FactorRead proc~esmf_arraysmmstorefromfile ESMF_ArraySMMStoreFromFile proc~esmf_arraysmmstorefromfile->proc~esmf_factorread interface~esmf_arraysmmstore ESMF_ArraySMMStore proc~esmf_arraysmmstorefromfile->interface~esmf_arraysmmstore proc~esmf_arraysmmstorefromfiletp ESMF_ArraySMMStoreFromFileTP proc~esmf_arraysmmstorefromfiletp->proc~esmf_factorread proc~esmf_arraysmmstorefromfiletp->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorefromfile ESMF_FieldSMMStoreFromFile proc~esmf_fieldsmmstorefromfile->proc~esmf_factorread interface~esmf_fieldsmmstore ESMF_FieldSMMStore proc~esmf_fieldsmmstorefromfile->interface~esmf_fieldsmmstore proc~esmf_fieldsmmstorefromfiletr ESMF_FieldSMMStoreFromFileTR proc~esmf_fieldsmmstorefromfiletr->proc~esmf_factorread proc~esmf_fieldsmmstorefromfiletr->interface~esmf_fieldsmmstore interface~esmf_arraysmmstore->proc~esmf_arraysmmstorefromfile interface~esmf_arraysmmstore->proc~esmf_arraysmmstorefromfiletp interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorefromfile interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorefromfiletr proc~esmf_fieldregridstorex ESMF_FieldRegridStoreX proc~esmf_fieldregridstorex->interface~esmf_fieldsmmstore proc~esmf_fieldsmmstorei4 ESMF_FieldSMMStoreI4 proc~esmf_fieldsmmstorei4->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorei4tr ESMF_FieldSMMStoreI4TR proc~esmf_fieldsmmstorei4tr->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorei8 ESMF_FieldSMMStoreI8 proc~esmf_fieldsmmstorei8->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorei8tr ESMF_FieldSMMStoreI8TR proc~esmf_fieldsmmstorei8tr->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorenf ESMF_FieldSMMStoreNF proc~esmf_fieldsmmstorenf->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorenftr ESMF_FieldSMMStoreNFTR proc~esmf_fieldsmmstorenftr->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorer4 ESMF_FieldSMMStoreR4 proc~esmf_fieldsmmstorer4->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorer4tr ESMF_FieldSMMStoreR4TR proc~esmf_fieldsmmstorer4tr->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorer8 ESMF_FieldSMMStoreR8 proc~esmf_fieldsmmstorer8->interface~esmf_arraysmmstore proc~esmf_fieldsmmstorer8tr ESMF_FieldSMMStoreR8TR proc~esmf_fieldsmmstorer8tr->interface~esmf_arraysmmstore proc~f_esmf_smmstore f_esmf_smmstore proc~f_esmf_smmstore->interface~esmf_fieldsmmstore proc~test_regrid_store_from_file test_regrid_store_from_file proc~test_regrid_store_from_file->interface~esmf_fieldsmmstore proc~test_regridmatrix test_regridMatrix proc~test_regridmatrix->interface~esmf_fieldsmmstore proc~test_regridmatrixfactor test_regridMatrixFactor proc~test_regridmatrixfactor->interface~esmf_fieldsmmstore proc~test_regridsmmarbgrid test_regridSMMArbGrid proc~test_regridsmmarbgrid->interface~esmf_fieldsmmstore proc~test_smm test_smm proc~test_smm->interface~esmf_arraysmmstore proc~user_init~28 user_init proc~user_init~28->interface~esmf_fieldsmmstore proc~user_init~36 user_init proc~user_init~36->interface~esmf_arraysmmstore proc~user_init~53 user_init proc~user_init~53->interface~esmf_arraysmmstore proc~user_init~84 user_init proc~user_init~84->interface~esmf_fieldsmmstore program~esmf_arrayarbidxsmmutest ESMF_ArrayArbIdxSMMUTest program~esmf_arrayarbidxsmmutest->interface~esmf_arraysmmstore program~esmf_arraysparsematmulex ESMF_ArraySparseMatMulEx program~esmf_arraysparsematmulex->interface~esmf_arraysmmstore program~esmf_rhandlebitforbitex ESMF_RHandleBitForBitEx program~esmf_rhandlebitforbitex->interface~esmf_arraysmmstore program~fieldsmmex FieldSMMEx program~fieldsmmex->interface~esmf_fieldsmmstore

Source Code

subroutine ESMF_FactorRead(filename, factorList, factorIndexList, rc)

! ! ARGUMENTS:
    character(len=*), intent(in) :: filename
    real(ESMF_KIND_R8), dimension(:), allocatable, intent(out) :: factorList
    integer, dimension(:, :), allocatable, intent(out) :: factorIndexList
    integer, intent(out), optional :: rc

!-------------------------------------------------------------------------------
! !DESCRIPTION:
!
! The arguments are:
!
! \begin{description}
!
! \item [filename]
!       Path to the file containing weights for creating an {\tt ESMF\_RouteHandle}.
!       See ~(\ref{sec:weightfileformat}) for a description of the SCRIP weight
!       file format. Only "row", "col", and "S" variables are required. They
!       must be one-dimensional with dimension "n\_s".
!
! \item [factorList]
!       The weight factors / interpolation weights to be read from file.
!
! \item [factorIndexList]
!       The indices into the source and destination arrays to be read from file. The
!       first dimension are the source indices. The second dimension are the
!       destination indices.
!
! \item [{[rc]}]
!       Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!
! \end{description}
!
!EOPI
!-------------------------------------------------------------------------------

    ! LOCAL VARIABLES ----------------------------------------------------------

    ! Variable name for index into the destination array.
    character(len=3), parameter :: vfactorindexlist_dst = "row"
    ! Variable name for index into the source array.
    character(len=3), parameter :: vfactorindexlist_src = "col"
    ! Variable name for the factor value.
    character(len=1), parameter :: vfactorlist = "S"
    ! Dimensions for the factor variables.
    character(len=3), parameter :: dfactor = "n_s"

    integer :: ncid, varid, dimid, localPet, petCount, nElements, esplit, lb, ub, remainder
    integer, dimension(1) :: nElementsArray, startArray
    integer :: ncStatus, theSize
    type(ESMF_VM) :: vm

    ! --------------------------------------------------------------------------

#ifdef ESMF_NETCDF
    ! Initialize return code; assume routine not implemented
    if (present(rc)) rc = ESMF_RC_NOT_IMPL

    ! Get all VM information
    call ESMF_VMGetCurrent(vm, rc=rc)
    if (ESMF_LogFoundError(rc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! Set up local pet info
    call ESMF_VMGet(vm, localPet=localPet, petCount=petCount, rc=rc)
    if (ESMF_LogFoundError(rc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! --------------------------------------------------------------------------

    ! Open the netCDF file.
    ncStatus = nf90_open(filename, NF90_NOWRITE, ncid)
    if (ESMF_NetCDFCheckError(ncStatus, ESMF_METHOD, filename, __LINE__, rc)) return

    ! Get the number of factors from the target netCDF file.
    nElements = ESMF_NetCDFInquireDimension(dfactor, ncid=ncid, rc=rc)
    if (ESMF_LogFoundError(rc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! Compute the lower and upper bounds for the current PET -------------------

    esplit = floor(real(nElements) / real(petCount))
    remainder = nElements - esplit*petCount
    if (localPet<remainder) then
      lb = localPet * (esplit+1) + 1
      theSize = esplit+1
    else
      lb = localPet * esplit + remainder + 1
      theSize = esplit
    endif
    ub = lb + theSize - 1

    ! --------------------------------------------------------------------------

    ! Convert to arrays as expected by the netCDF Fortran interface. Set the size
    ! of the factor arrays to zero if the localPet will not read any values.
    startArray = (/lb/)
    nElementsArray = (/theSize/)

    ! Allocate our factor arrays now that we know the size of the dimension.
    allocate(factorList(theSize))
    allocate(factorIndexList(2, theSize))

    !--- Fill variables from the netCDF file -----------------------------------

    ! Only read from file if the lower bound is reasonable - falls inside the size
    ! of the target variable.
    if (lb <= nElements) then
      ncStatus = nf90_inq_varid(ncid, vfactorindexlist_dst, varid)
      if (ESMF_NetCDFCheckError(ncStatus, ESMF_METHOD, filename, __LINE__, rc)) &
        return
      ncStatus = nf90_get_var(ncid, varid, factorIndexList(2, :), &
        start=startArray, count=nElementsArray)
      if (ESMF_NetCDFCheckError(ncStatus, ESMF_METHOD, filename, __LINE__, rc)) &
        return

      ncStatus = nf90_inq_varid(ncid, vfactorindexlist_src, varid)
      if (ESMF_NetCDFCheckError(ncStatus, ESMF_METHOD, filename, __LINE__, rc)) &
        return
      ncStatus = nf90_get_var(ncid, varid, factorIndexList(1, :), &
        start=startArray, count=nElementsArray)
      if (ESMF_NetCDFCheckError(ncStatus, ESMF_METHOD, filename, __LINE__, rc)) &
        return

      ncStatus = nf90_inq_varid(ncid, vfactorlist, varid)
      if (ESMF_NetCDFCheckError(ncStatus, ESMF_METHOD, filename, __LINE__, rc)) &
        return
      ncStatus = nf90_get_var(ncid, varid, factorList, start=startArray, &
        count=nElementsArray)
      if (ESMF_NetCDFCheckError(ncStatus, ESMF_METHOD, filename, __LINE__, rc)) &
        return
    endif

    !---------------------------------------------------------------------------

    ! Close the file.
    ncStatus = nf90_close(ncid)
    if (ESMF_NetCDFCheckError(ncStatus, ESMF_METHOD, filename, __LINE__, rc)) return

    if (present(rc)) rc = ESMF_SUCCESS
#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 ESMF_FactorRead