program ut_ReGridding
use BundleTestSupport
implicit none
!CONTAINS
! Basic ESMF objects being used in this example
! ---------------------------------------------
type(ESMF_Grid) :: grid_new
type(ESMF_VM) :: vm ! ESMF Virtual Machine
! Basic information about the parallel environment
! PET = Persistent Execution Threads
! In the current implementation, a PET is equivalent
! to an MPI process
! ------------------------------------------------
integer :: myPET ! The local PET number
integer :: nPET ! The total number of PETs you are running on
integer :: status
integer :: Nx,Ny,nargs
integer :: IM_World_new, JM_World_new, lm_world
type(ESMF_FieldBundle) :: bundle,bundle_new
type(ESMF_Field) :: field
type(ESMF_Time) :: time
type(ESMF_TimeInterval) :: timeInterval
type(ESMF_Clock) :: clock
character(len=ESMF_MAXSTR) :: filename
integer :: i
character(len=2) :: pole_new,dateline_new
character(len=ESMF_MAXSTR) :: gridname
character(len=ESMF_MAXPATHLEN) :: str,astr
type(ESMF_CONFIG) :: cfoutput
type(FieldBundleWriter) :: newWriter
type(ServerManager) :: io_server
real, pointer :: ptr2d(:,:),ptr3d(:,:,:)
real :: cs_stretch_param(3)
! Initialize the ESMF. For performance reasons, it is important
! to turn OFF ESMF's automatic logging feature
! -------------------------------------------------------------
call ESMF_Initialize (LogKindFlag=ESMF_LOGKIND_NONE, vm=vm, _RC)
call ESMF_VMGet(vm, localPET=myPET, petCount=nPet, _RC)
call MAPL_Initialize(_RC)
call io_server%initialize(mpi_comm_world)
nx=1
ny=6
cs_stretch_param=cs_stretch_uninit
nargs = command_argument_count()
do i=1,nargs
call get_command_argument(i,str)
select case(trim(str))
case('-ogrid')
call get_command_argument(i+1,Gridname)
case('-nx')
call get_command_argument(i+1,astr)
read(astr,*)nx
case('-ny')
call get_command_argument(i+1,astr)
read(astr,*)ny
case('-o')
call get_command_argument(i+1,filename)
end select
enddo
call MAPL_GetNodeInfo (comm=MPI_COMM_WORLD, _RC)
call ESMF_CalendarSetDefault ( ESMF_CALKIND_GREGORIAN, _RC )
call ESMF_TimeSet(time, yy=2000, mm=3, dd=15, h=21, m=0, s=0,_RC)
call ESMF_TimeIntervalSet( TimeInterval, h=6, m=0, s=0, _RC )
Clock = ESMF_ClockCreate ( name="Eric", timeStep=TimeInterval, &
startTime=time, _RC )
call UnpackGridName(Gridname,im_world_new,jm_world_new,dateline_new,pole_new)
lm_world=3
cfoutput = create_cf(trim(gridname),im_world_new,jm_world_new,nx,ny,lm_world,cs_stretch_param,_RC)
grid_new=grid_manager%make_grid(cfoutput,prefix=trim(gridname)//".",_RC)
bundle=ESMF_FieldBundleCreate(name="cfio_bundle",_RC)
call ESMF_FieldBundleSet(bundle,grid=grid_new,_RC)
bundle_new=ESMF_FieldBundleCreate(name="cfio_bundle",_RC)
call ESMF_FieldBundleSet(bundle_new,grid=grid_new,_RC)
field=ESMF_FieldCreate(grid=grid_new,typekind=ESMF_TYPEKIND_R4,name="f2d",_RC)
call ESMF_AttributeSet(FIELD,'LONG_NAME','what_am_i',_RC)
call ESMF_AttributeSet(FIELD,'UNITS','NA',_RC)
call ESMF_AttributeSet(FIELD,'DIMS',MAPL_DimsHorzOnly,_RC)
call ESMF_AttributeSet(FIELD,'VLOCATION',MAPL_VLocationNone,_RC)
call ESMF_FieldGet(field,farrayPtr=ptr2d,_RC)
ptr2d=17.0
call MAPL_FieldBundleAdd(bundle,field,_RC)
field=ESMF_FieldCreate(grid=grid_new,typekind=ESMF_TYPEKIND_R4,name="f3d", &
ungriddedLBound=[1],ungriddedUBound=[lm_world],_RC)
call ESMF_AttributeSet(FIELD,'LONG_NAME','what_am_i',_RC)
call ESMF_AttributeSet(FIELD,'UNITS','NA',_RC)
call ESMF_AttributeSet(FIELD,'DIMS',MAPL_DimsHorzVert,_RC)
call ESMF_AttributeSet(FIELD,'VLOCATION',MAPL_VLocationCenter,_RC)
call ESMF_FieldGet(field,farrayPtr=ptr3d,_RC)
ptr3d=17.0
call MAPL_FieldBundleAdd(bundle,field,_RC)
call newWriter%create_from_bundle(bundle,clock,filename,_RC)
call newWriter%write_to_file(_RC)
call MAPL_Read_bundle(bundle_new,trim(filename),time=time,_RC)
call Compare_Bundle(bundle,bundle_new,1.0e6,_RC)
call io_server%finalize()
call MAPL_Finalize(_RC)
call ESMF_Finalize(_RC)
end program ut_ReGridding