IOFilenameGet Subroutine

private subroutine IOFilenameGet(fullName, fileName, keywordEnforcer, tile, filePath)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(out) :: fullName
character(len=*), intent(in) :: fileName
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
integer, intent(in), optional :: tile
character(len=*), intent(in), optional :: filePath

Source Code

  subroutine IOFilenameGet(fullName, fileName, keywordEnforcer, tile, filePath)
    character(len=*), intent(out)          :: fullName
    character(len=*), intent(in)           :: fileName
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
    integer,          intent(in), optional :: tile
    character(len=*), intent(in), optional :: filePath

    ! -- local variables
    integer :: iext, lstr
    character(len=ESMF_MAXSTR) :: fname
    character(len=*), parameter :: defext = ".nc"

    ! -- begin
    fname = ""
    fullName = ""

    if (present(tile)) then
      iext = index(fileName, ".", back=.true.)
      if (iext > 0) then
        write(fname, '(a,"tile",i0,a)') fileName(1:iext), tile, trim(fileName(iext:))
      else
        write(fname, '(a,"tile",i0,a)') trim(fileName), tile, defext
      end if
    else
      fname = fileName
    end if

    if (present(filePath)) then
      lstr = len_trim(filePath)
      if (filePath(lstr:lstr) == "/") then
        fullName = trim(filePath) // trim(fname)
      else
        fullName = trim(filePath) // "/" // trim(fname)
      end if
    else
      fullName = trim(fname)
    end if

  end subroutine IOFilenameGet