subroutine MAPL_GridCreate(GC, MAPLOBJ, ESMFGRID, srcGC, rc)
type(ESMF_GridComp), optional, intent(INOUT) :: GC
type (MAPL_MetaComp),optional, target, intent(INOUT) :: MAPLOBJ
type (ESMF_Grid), optional, intent( OUT) :: ESMFGRID
type(ESMF_GridComp), optional, intent(INout) :: srcGC
integer, optional, intent( OUT) :: rc
integer :: status
character(len=ESMF_MAXSTR) :: Comp_Name
character(len=ESMF_MAXSTR) :: IAm
type (ESMF_VM) :: VM
type (MAPL_MetaComp), pointer :: STATE
type (ESMF_Grid) :: GRID
integer :: nn,ny
character(len=ESMF_MAXSTR) :: GridName
character(len=2) :: dateline
#ifdef CREATE_REGULAR_GRIDS
logical :: isRegular
#endif
! Query GC
!---------
Iam='MAPL_GridCreate'
if(present(GC)) then
call ESMF_GridCompGet( GC, name=Comp_Name, rc = status )
_VERIFY(status)
Iam = trim(Comp_Name)//Iam
endif
! New option to get grid from existing component
!-----------------------------------------------
if(present(srcGC)) then
call ESMF_GridCompGet ( srcGC, grid=Grid, RC=status )
_VERIFY(status)
if(present(GC)) then
call ESMF_GridCompSet(GC, GRID=GRID, RC=status)
_VERIFY(status)
end if
if(present(ESMFGRID)) then
ESMFGRID=GRID
end if
_RETURN(ESMF_SUCCESS)
end if
call ESMF_VMGetCurrent(vm, rc=status)
_VERIFY(status)
! Get MAPL object
!----------------
if(present(GC)) then
_ASSERT(.not. present(MAPLOBJ),'needs informative message')
call MAPL_InternalStateGet(GC, STATE, RC=status)
_VERIFY(status)
elseif(present(MAPLOBJ)) then
STATE => MAPLOBJ
else
_FAIL('needs informative message')
endif
call MAPL_ConfigPrepend(state%cf,trim(comp_name),MAPL_CF_COMPONENT_SEPARATOR,'NX:',rc=status)
_VERIFY(status)
call MAPL_ConfigPrepend(state%cf,trim(comp_name),MAPL_CF_COMPONENT_SEPARATOR,'NY:',rc=status)
_VERIFY(status)
call ESMF_ConfigGetAttribute(state%cf,gridname,label=trim(comp_name)//MAPL_CF_COMPONENT_SEPARATOR//'GRIDNAME:',rc=status)
_VERIFY(status)
nn = len_trim(gridname)
dateline = gridname(nn-1:nn)
if (dateline == 'CF') then
call ESMF_ConfigGetAttribute(state%CF,ny,label=trim(COMP_Name)//MAPL_CF_COMPONENT_SEPARATOR//'NY:',rc=status)
_VERIFY(status)
call MAPL_ConfigSetAttribute(state%CF, value=ny/6, label=trim(COMP_Name)//MAPL_CF_COMPONENT_SEPARATOR//'NY:',rc=status)
_VERIFY(status)
end if
grid = grid_manager%make_grid(state%CF, prefix=trim(COMP_Name)//MAPL_CF_COMPONENT_SEPARATOR, rc=status)
_VERIFY(status)
call state%grid%set(grid, _RC)
if(present(GC)) then
call ESMF_GridCompSet(GC, GRID=GRID, RC=status)
_VERIFY(status)
end if
if(present(ESMFGRID)) then
ESMFGRID=GRID
end if
_RETURN(ESMF_SUCCESS)
contains
subroutine MAPL_ConfigPrepend(cf,prefix,separator,label,rc)
type(ESMF_Config), intent(inout) :: cf
character(len=*) , intent(in ) :: prefix
character(len=*) , intent(in ) :: separator
character(len=*) , intent(in ) :: label
integer, optional , intent(out ) :: rc
integer :: status
character(len=ESMF_MAXSTR) :: Iam = "MAPL_ConfigPrepend"
integer :: val
call ESMF_ConfigGetAttribute( cf, val, label=trim(prefix)//trim(separator)//trim(label), rc = status )
if (status /= ESMF_SUCCESS) then
call ESMF_ConfigGetAttribute(CF,val,label=trim(label),rc=status)
_VERIFY(status)
call MAPL_ConfigSetAttribute(CF, val, label=trim(prefix)//trim(separator)//trim(label),rc=status)
_VERIFY(status)
end if
_RETURN(ESMF_SUCCESS)
end subroutine MAPL_ConfigPrepend
end subroutine MAPL_GridCreate