parseGridName Subroutine

public subroutine parseGridName(gridName, nX, nY, isCS, isDE, isPC)

The routine parseGridName determines a grid specification based on a string. The string can either be a standardized MAPL grid name (eg DE0180xPC0091, CF0024x6C) or a small number of shorthand options:

       4x5          GMAO 4x5 grid
       2x2.5        GMAO 2x2.5 grid
       1x1.25       GMAO 1x1.25 grid
       1x1          GMAO 1x1 grid
       0.5x0.625    GMAO 0.5x0.625 grid
       0.25x0.3125  GMAO 0.25x0.3125 grid

History

  • 09 Jan 2016 - S. D. Eastham - Initial version

Arguments

Type IntentOptional Attributes Name
character(len=255), intent(in) :: gridName
integer, intent(out) :: nX
integer, intent(out) :: nY
logical, intent(out), optional :: isCS
logical, intent(out), optional :: isDE
logical, intent(out), optional :: isPC

Called by

proc~~parsegridname~~CalledByGraph proc~parsegridname parseGridName proc~readinput ReadInput proc~readinput->proc~parsegridname

Source Code

      Subroutine parseGridName( gridName, nX, nY, isCS, isDE, isPC )
!
! !USES:
!

!
! !INPUT PARAMETERS:
!
      Character(Len=255), Intent(In)       :: gridName
!
! !OUTPUT PARAMETERS:
!
      Integer, Intent(Out)                 :: nX, nY
      Logical, Optional, Intent(Out)       :: isCS
      Logical, Optional, Intent(Out)       :: isDE
      Logical, Optional, Intent(Out)       :: isPC
!
!-----------------------------------------------------------------------
!
! !LOCAL VARIABLES:
!
      Integer                  :: nChar, xIdx
      Character(Len=255)       :: trimName
      Logical                  :: isCS_, isDE_, isPC_
      Real(sp)                 :: nFloat

      !=================================================================
      ! parseGridName starts here!
      !=================================================================

      ! Set defaults
      nX = 0
      nY = 0
      isCS_ = .True.
      isDE_ = .True.
      isPC_ = .True.

      ! Branching options
      ! First: check that we have enough characters to do anything useful
      trimName = AdjustL(gridName)
      nChar = len(Trim(trimName))

      ! Basic input check
      If (nChar > 1) Then
          If (trimName(1:1) == "C") Then
             ! Two possibilities
             ! C[N]         Shorthand
             ! CFNNNNx6C    MAPL notation
             ! Assume MAPL if last character is also C
             isCS_ = .True.
             isDE_ = .False.
             isPC_ = .False.
             If (trimName(nChar:nChar) == "C") Then
                Read(trimName(3:6),*) nFloat
             Else
                Read(trimName(2:),*) nFloat
             End If
             ! Check that the number was parseable
             If (nFloat == nFloat) Then
                nX = Int(nFloat)
                nY = nX * 6
             End If
          ElseIf (trimName(1:1) == "D") Then
             ! Fixed length MAPL lat-lon identifier
             isCS_ = .False.
             If (nChar.eq.13) Then
                ! Use as temporary error indicators
                nX = 0
                nY = 0
                Select Case (trimName(1:2))
                   Case ('DC')
                      isDE_ = .False.
                   Case ('DE')
                      isDE_ = .True.
                   Case Default
                      nX = -1
                End Select
                Select Case (trimName(8:9))
                   Case ('PC')
                      isPC_ = .True.
                   Case ('PE')
                      isPC_ = .False.
                   Case Default
                      nY = -1
                End Select
                If ((nX + nY) == 0) Then
                   ! Doing OK
                   Read(trimName(3:6),*) nFloat
                   If (nFloat == nFloat) nX = Int(nFloat)
                   Read(trimName(10:13),*) nFloat
                   If (nFloat == nFloat) nY = Int(nFloat)
                   If ((nX*nY) == 0) Then
                      nX = 0
                      nY = 0
                   End If
                End If
             End If
          Else
             ! Assume a GMAO shorthand string (lat-lon)
             isCS_ = .False.
             xIdx = Index(trimName,'x')
             ! Did we find an x?
             If (xIdx > 0) Then
                Read(trimName(1:(xIdx-1)),*) nFloat
                If (nFloat == nFloat) nY = Int(180.0/nFloat) + 1
                Read(trimName((xIdx+1):nChar),*) nFloat
                If (nFloat == nFloat) nX = Int(360.0/nFloat)
                If ((nX*nY == 0)) Then
                   nX = 0
                   nY = 0
                Else
                   ! Successful parse
                   isDE_ = .False.
                   isPC_ = .True.
                End If
             End If
          End If
      End If

      ! Assign outputs
      If (present(isCS)) isCS = isCS_
      If (present(isDE)) isDE = isDE_
      If (present(isPC)) isPC = isPC_

      End Subroutine parseGridName