! $Id: ESMF_FieldArbGridUTest.F90,v 1.25 2011/06/30 14:49:38 oehmke Exp $ ! ! Earth System Modeling Framework ! Copyright 2002-2011, University Corporation for Atmospheric Research, ! Massachusetts Institute of Technology, Geophysical Fluid Dynamics ! Laboratory, University of Michigan, National Centers for Environmental ! Prediction, Los Alamos National Laboratory, Argonne National Laboratory, ! NASA Goddard Space Flight Center. ! Licensed under the University of Illinois-NCSA License. ! !============================================================================== ! program ESMF_FieldArbGridUTest !------------------------------------------------------------------------------ #include "ESMF.h" #define ESMF_METHOD "ESMF_TESTS" !============================================================================== !BOPI ! !PROGRAM: ESMF_FieldArbGridUTest - Unit tests for Field Create and Get methods on a arbitrarily distributed grid ! ! !DESCRIPTION: ! ! The code in this file drives F90 Field Arbitrary Grid unit tests . ! The companion folder Fieldsrc contains the definitions for the ! Field methods. !EOPI !----------------------------------------------------------------------------- ! !USES: use ESMF_TestMod ! test methods use ESMF use ESMF_GridUtilMod use ESMF_LogErrMod implicit none !------------------------------------------------------------------------------ ! The following line turns the CVS identifier string into a printable variable. character(*), parameter :: version = & '$Id' type(ESMF_Grid) :: grid2d, grid3d type(ESMF_VM) :: vm type(ESMF_ArraySpec) :: arrayspec1D, arrayspec2D, arrayspec3D type(ESMF_Array) :: array1d, array2d, array3d integer :: ind1d, xdim, ydim, zdim, total, x, y integer :: i, remain integer :: myPet, petCount, halfPets integer :: localCount integer, allocatable :: localIndices(:,:) integer :: localrc type(ESMF_Field) :: field, field1, field2, field3, field4, field5 real, dimension(:), pointer :: fptr1d real, dimension(:,:), pointer :: fptr2d real, dimension(:,:,:), pointer :: fptr3d logical :: correct integer :: rank, dimCount ! cumulative result: count failures; no failures equals "all pass" integer :: result = 0 ! individual test result code integer :: rc = 1 ! individual test failure message character(ESMF_MAXSTR) :: failMsg character(512) :: name call ESMF_TestStart(ESMF_SRCLINE, rc=rc) ! Calculate localIndices and localCount for a 100x200 2D arbitrary grid with ! an optional undistributed 3rd dimenison of size 4 ! get global VM call ESMF_VMGetGlobal(vm, rc=rc) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT) call ESMF_VMGet(vm, petCount=petCount, localPet=myPet, rc=rc) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT) ! grid dimension: xdim and ydim are arbitrarily distributed xdim = 100 ydim = 200 zdim = 4 ! calculate the localcount and the local indices based on the total number of PETS total = xdim*ydim halfPets = petCount/2 ! let's make the first half pet twice of the cells of the second half localCount = total/(petCount+halfPets) remain = total-localCount*(petCount+halfPets) if (myPet < halfPets) localCount = localCount*2 if (myPet == petCount-1) localCount = localCount+remain ! car deal the cells with the first half of the Pets gets two each time ! the remaining cells are given to the last Pet allocate(localIndices(localCount,2)) if (myPet < halfPets) then ind1d = myPet*2 do i=1,localCount,2 y = mod(ind1d,ydim)+1 x = ind1d/ydim+1 localIndices(i,1)=y localIndices(i,2)=x if (y