File: C:\NOAA\NEMS_11731\src\chem\gocart\src\GMAO_Shared\MAPL_cfio\examples\testw_ex1.f90

1         program test
2     
3         use ESMF_CFIOGridMOD
4         use ESMF_CFIOVarInfoMOD
5         use ESMF_CFIOFileMOD
6         use ESMF_CFIOSdfMOD
7         use ESMF_CFIOMOD
8     
9     !   define ESMF_CFIO,  ESMF_CFIOVarInfo, and ESMF_CFIOGrid objects
10         type(ESMF_CFIO) :: cfio
11         type(ESMF_CFIOVarInfo), pointer :: vars(:)
12         type(ESMF_CFIOGrid), pointer :: grid
13     
14         character(len=20) :: fileName
15         real, pointer :: ts(:,:,:), ps(:,:,:)
16         integer :: fmode, rc
17         integer :: date, curTime, timeInc
18         real :: range(2) = (/-1.E10, 1.E10/)
19         logical :: twoD
20     
21         integer :: hhmmss(2) = (/0, 60000/)
22         integer :: i,j, t
23         real :: lon(72), lat(46), dlat, dlon
24         integer :: im=72, jm=46
25         logical :: passed = .true.
26     
27         fmode = 0
28     
29         dlat = 180./(jm-1)
30         dlon = 360./im
31         do i =1, im
32           lon(i) = -180 + (i-1)*dlon
33         end do
34         do j =1, jm
35           lat(j) = -90 + (j-1)*dlat
36         end do
37     
38     ! Create grid and set grid attributes
39         allocate(grid)
40         grid = ESMF_CFIOGridCreate(gName='test2d')
41         call ESMF_CFIOGridSet(grid, im=72, jm=46, lon=lon, lat=lat)
42     
43     !   read back im, jm
44         call ESMF_CFIOGridGet(grid, im=im, jm=jm)
45     
46     ! Create variable object and set variable attributes
47         allocate(vars(2))
48         vars(1) = ESMF_CFIOVarInfoCreate(vName='ps')
49         call ESMF_CFIOVarInfoSet(vars(1), vName='ps', vTitle='surface pressure', grid=grid)
50         call ESMF_CFIOVarInfoSet(vars(1), amiss=1.E15, scaleFactor=1., addOffSet=0.)
51         call ESMF_CFIOVarInfoSet(vars(1), standardName='ps', twoDimVar=.true.)
52         call ESMF_CFIOVarInfoSet(vars(1), validRange=range, vUnits='K')
53     
54         vars(2) = ESMF_CFIOVarInfoCreate(vName='ts')
55         call ESMF_CFIOVarInfoSet(vars(2),vName='ts',vTitle='skin temperature', grid=grid)
56         call ESMF_CFIOVarInfoSet(vars(2), standardName='tskin', twoDimVar=.true.)
57         call ESMF_CFIOVarInfoSet(vars(2), validRange=range, vUnits='K')
58     
59     ! Create CFIO object and set global attributes
60     
61         cfio =  ESMF_CFIOCreate(cfioObjName='ana')
62         call ESMF_CFIOSet(cfio, fName='GEOS5.ana.hdf', varObjs=vars, &
63                        grid=grid, date=20011201, BegTime=0, timeInc=60000)
64         call ESMF_CFIOSet(cfio, title="c403_cer_01: FVGCM Diagnostics",  &
65                        source="Global Modeling and Assimilation Office", &
66                        contact="data@gmao.gsfc.nasa.gov")
67         call ESMF_CFIOSet(cfio, history='File written by CFIO v1.0.0', &
68                convention='ESMF', institution="Global Modeling and Assimilation Office")
69         call ESMF_CFIOSet(cfio, references='see ESMF', comment='First CFIO test version',prec=0) 
70     
71     ! All metadata are set. Get some metadata to see what in the CFIO Obj.
72     
73         call ESMF_CFIOGet(cfio, nVars=nVars, date=date, begTime=curTime, &
74                        timeInc=timeInc, fName=fileName)
75     
76     ! Create output file
77         call ESMF_CFIOFileCreate(cfio)
78     
79     ! put some test data into the variables
80         allocate(ps(im,jm,1), ts(im,jm,1))
81     
82         do t = 1, 2
83            do j = 1, jm
84              do i = 1, im
85                 ps(i,j,1) = 100000 + (t-1)*cos(2*3.14*lat(j)/180.)*sin(2*3.14*2*lon(i)/360.)   
86                 ts(i,j,1) = 273 - (t-1)*sin(2*3.14*lat(j)/180.)*cos(2*3.14*2*lon(i)/360.)
87              enddo
88            enddo
89     
90     ! Write data to the output file
91     
92            call ESMF_CFIOVarWrite(cfio, 'ps', ps, date, hhmmss(t), rc=rc)
93            if ( rc .ne. 0 ) passed = .false.
94            call ESMF_CFIOVarWrite(cfio, 'ts', ts, date, hhmmss(t), rc=rc)
95            if ( rc .ne. 0 ) passed = .false.
96         end do
97     ! Close the file
98         call ESMF_CFIOFileClose(cfio)
99     
100         if ( passed ) then
101            print *, "testw_ex1: Passed"
102         else
103            print *, "testw_ex1: NOT Passed"
104         end if
105     
106         stop
107        end 
108