read_grid_specification Subroutine

public subroutine read_grid_specification(Gfile, rc)

Arguments

Type IntentOptional Attributes Name
type(grid_record), intent(inout) :: Gfile
integer, intent(out) :: rc

Source Code

  subroutine read_grid_specification(Gfile, rc)
  !-----------------------------------------------------------------------------
  ! driver for reading the grid specifier files. Inputs a single grid record
  ! corresponding to a single specifier file of a single problem descriptor string. 
  !
  !-----------------------------------------------------------------------------

  ! arguments
  type(grid_record), intent(inout) :: Gfile 
  integer, intent(  out) :: rc

  ! local ESMF types
  type(ESMF_Config)      :: localcf

  ! local character strings
  character(THARN_MAXSTR) :: ltmp, lfilename

  ! local integers variables
  integer :: localrc ! local error status

  integer :: i, igrid, irank

  ! initialize return flag
  localrc = ESMF_RC_NOT_IMPL
  rc = ESMF_RC_NOT_IMPL

  !-----------------------------------------------------------------------------
  ! open the grid file
  !-----------------------------------------------------------------------------
  localcf = ESMF_ConfigCreate(rc=localrc)
  if( ESMF_LogFoundError(localrc, msg="cannot create config object",            &
                            rcToReturn=rc) ) return

  lfilename = Gfile%filename
  print*,'Opening Grid specifier file  ',trim( lfilename )
  call ESMF_ConfigLoadFile(localcf, trim( lfilename ), rc=localrc )
  if( ESMF_LogFoundError(localrc,                                           &
         msg="cannot load config file " // trim( lfilename ),                      &
         rcToReturn=rc) ) return

  !-----------------------------------------------------------------------------
  ! Search and extract the grid type specifier
  !-----------------------------------------------------------------------------
  call ESMF_ConfigFindLabel(localcf, 'map_type:', rc=localrc )
  if( ESMF_LogFoundError(localrc,                                           &
         msg="cannot find config label map_type:", rcToReturn=rc) ) return  

  call ESMF_ConfigGetAttribute(localcf, ltmp, rc=localrc)
  if( ESMF_LogFoundError(localrc,                                           &
         msg="cannot read config label map_type:" , rcToReturn=rc) ) return

  !-----------------------------------------------------------------------------
  ! Read the grid specifier file. The 'map_type' argument specifies the type 
  ! of grid specification to be read ( redistrbution or regridding ).
  !-----------------------------------------------------------------------------
  select case(trim(adjustL(ltmp)) )

     case('REDISTRIBUTION')
       print*,' read grid specification for redistribution test'
       call read_redistribution_grid(lfilename, Gfile%nGspecs, Gfile%src_grid, &
                Gfile%dst_grid,localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU,                   &
               rcToReturn=rc)) return

     case('REGRID')
       print*,' read grid specification for regridding test'
       call read_regridding_grid(lfilename, Gfile%nGspecs, Gfile%src_grid,      &
                Gfile%dst_grid, Gfile%testfunction, localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU,                   &
               rcToReturn=rc)) return
       
       if( debug_flag ) then
       !------------------------------------------------------------------------
       ! print out diagnostics
       !------------------------------------------------------------------------
       print*,'Number of grid specs', Gfile%nGspecs
       do igrid=1, Gfile%nGspecs
           print*,'====================================================='
           print*,igrid,'SRC rank: ', Gfile%src_grid(igrid)%grank
           do irank=1, Gfile%src_grid(igrid)%grank
             print*,'SRC grid type: ', Gfile%src_grid(igrid)%gtype(irank)%string
             print*,'SRC size/range:', Gfile%src_grid(igrid)%gsize(irank),'/',  &
                    Gfile%src_grid(igrid)%grange(irank,1),Gfile%src_grid(igrid)%grange(irank,2) 
             print*,'SRC grid units: ', Gfile%src_grid(igrid)%gunits(irank)%string
           enddo
           print*,igrid,'DST rank: ', Gfile%dst_grid(igrid)%grank
           do irank=1, Gfile%dst_grid(igrid)%grank
             print*,'DST grid type: ', Gfile%dst_grid(igrid)%gtype(irank)%string
             print*,'DST size/range: ', Gfile%dst_grid(igrid)%gsize(irank),'/',  &
                    Gfile%dst_grid(igrid)%grange(irank,1),Gfile%dst_grid(igrid)%grange(irank,2) 
             print*,'DST grid units: ', Gfile%dst_grid(igrid)%gunits(irank)%string
           enddo
           print*,'-----------------------------------------------------'
           print*,igrid,' testfunction: ', trim(Gfile%testfunction(igrid)%string)
           do i=1,Gfile%testfunction(igrid)%prank
             print*,' testfunction parameters: ',Gfile%testfunction(igrid)%param(i)
           enddo
           print*,'====================================================='
       enddo
       !------------------------------------------------------------------------
       ! print out diagnostics
       !------------------------------------------------------------------------
       endif

     case default
       ! error
       call ESMF_LogSetError( ESMF_FAILURE,                                 &
              msg="unknown grid type in " // trim(lfilename),                      &
              rcToReturn=rc)
       return
     end select
  !-----------------------------------------------------------------------------
  ! clean up CF     
  !-----------------------------------------------------------------------------
  call ESMF_ConfigDestroy(localcf, rc=localrc) 
  if( ESMF_LogFoundError(localrc, msg="cannot destroy config object",            &
                            rcToReturn=rc) ) return

              
  !-----------------------------------------------------------------------------
  rc = ESMF_SUCCESS     
  !-----------------------------------------------------------------------------
  end subroutine read_grid_specification