source: XIOS/trunk/src/test/test_new_features.f90 @ 821

Last change on this file since 821 was 821, checked in by mhnguyen, 8 years ago

Making some improvements of transformation algorithm

+) Correct the way to enlisting transformations in an element (domain, axis)
+) Optimize generic transformation to make sure temporary grid to be created on demand
+) Update some mpi tag to prevent conflict
+) Correct some minor stuffs
+) Update documents

Test
+) On Curie
+) all test pass

  • Property svn:executable set to *
File size: 9.3 KB
Line 
1PROGRAM test_new_features
2
3  USE xios
4  USE mod_wait
5  IMPLICIT NONE
6  INCLUDE "mpif.h"
7  INTEGER :: rank
8  INTEGER :: size
9  INTEGER :: ierr
10
11  CHARACTER(len=*),PARAMETER :: id="client"
12  INTEGER :: comm
13  TYPE(xios_duration) :: dtime
14  TYPE(xios_date) :: date
15  CHARACTER(len=15) :: calendar_type
16  TYPE(xios_context) :: ctx_hdl
17  INTEGER,PARAMETER :: ni_glo=100
18  INTEGER,PARAMETER :: nj_glo=100
19  INTEGER,PARAMETER :: llm=5
20  INTEGER,PARAMETER :: llmInterPolated=4
21  DOUBLE PRECISION  :: lval(llm)=1, tsTemp, lvalInterPolated(llmInterPolated)=1
22  TYPE(xios_field) :: field_hdl
23  TYPE(xios_fieldgroup) :: fieldgroup_hdl
24  TYPE(xios_file) :: file_hdl
25  LOGICAL :: ok
26  LOGICAL,ALLOCATABLE :: mask_glo(:),mask(:)
27
28  DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo
29  DOUBLE PRECISION,DIMENSION(4,ni_glo,nj_glo) :: bnds_lon_glo, bnds_lat_glo
30  DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm), lval_ni_glo(ni_glo), lval_nj_glo(nj_glo)
31  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:,:), field_All_Axis(:,:,:), lonvalue(:) , &
32                                  field_Axis(:), lvaln(:), lval_ni(:), lval_nj(:), field_Two_Axis(:,:), lvalnInterp(:), &
33                                  lontransformed(:,:), lattransformed(:,:), lon_glotransformed(:,:), lat_glotransformed(:,:), &
34                                  bnds_lon(:,:,:), bnds_lat(:,:,:)
35  INTEGER :: ni,ibegin,iend,nj,jbegin,jend, nAxis, axisBegin, axisEnd
36  INTEGER :: axisterpBegin, nAxisinterp, axisinterpEnd
37  INTEGER :: niDomInterp,ibeginDomInterp,iendDomInterp,njDomInterp,jbeginDomInterp,jendDomInterp, niDomGlo, njDomGlo
38  INTEGER :: i,j,k,l,ts,n
39
40!!! MPI Initialization
41
42  CALL MPI_INIT(ierr)
43
44  CALL init_wait
45
46!!! XIOS Initialization (get the local communicator)
47  CALL xios_initialize(id,return_comm=comm)
48
49  CALL MPI_COMM_RANK(comm,rank,ierr)
50  CALL MPI_COMM_SIZE(comm,size,ierr)
51
52  DO j=1,nj_glo
53    DO i=1,ni_glo
54      lon_glo(i,j)=(i-1)+(j-1)*ni_glo
55      lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo
56      DO k = 1,4
57        bnds_lon_glo(1,i,j) = lon_glo(i,j)
58        bnds_lon_glo(2,i,j) = lon_glo(i,j)-10
59        bnds_lon_glo(3,i,j) = lon_glo(i,j)
60        bnds_lon_glo(4,i,j) = lon_glo(i,j)+10
61
62        bnds_lat_glo(1,i,j) = lat_glo(i,j) -10
63        bnds_lat_glo(2,i,j) = lat_glo(i,j)
64        bnds_lat_glo(3,i,j) = lat_glo(i,j) -10
65        bnds_lat_glo(4,i,j) = lat_glo(i,j)
66      ENDDO
67      lval_ni_glo(i) = i-1
68      DO l=1,llm
69        field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l
70      ENDDO
71    ENDDO
72    lval_nj_glo(j) = j-1
73  ENDDO
74  ni = ni_glo
75  ibegin = 0
76  iend = ibegin + ni - 1
77
78  jbegin=0
79  CALL Distribute_index(jbegin, jend, nj, nj_glo, rank, size)
80
81  DO j=1,llm
82    lval(j) = j *10
83  ENDDO
84  axisBegin = 0
85  CALL Distribute_index(axisBegin, axisEnd, nAxis, llm, rank, size)
86
87  DO j=1,llmInterPolated
88    lvalInterPolated(j) = j * 12
89  ENDDO
90  axisterpBegin = 0
91  CALL Distribute_index(axisterpBegin, axisinterpEnd, nAxisinterp, llmInterPolated, rank, size)
92
93  niDomGlo = ni_glo - 4
94  njDomGlo = nj_glo - 4
95  ALLOCATE(lon_glotransformed(niDomGlo,njDomGlo), lat_glotransformed(niDomGlo,njDomGlo))
96  DO j=1,njDomGlo
97    DO i=1,niDomGlo
98      lon_glotransformed(i,j)=(i-1)+(j-1)*niDomGlo
99      lat_glotransformed(i,j)=1000+(i-1)+(j-1)*niDomGlo
100    ENDDO
101  ENDDO
102
103  niDomInterp = niDomGlo; ibeginDomInterp = 0
104  jbeginDomInterp = 0
105  CALL Distribute_index(jbeginDomInterp, jendDomInterp, njDomInterp, njDomGlo, rank, size)
106
107  ALLOCATE(field_A(0:ni+1,-1:nj+2,llm), field_Two_Axis(ni_glo,1:nj), field_Axis(nAxis), field_All_Axis(1:ni,1:nj,llm), &
108          lon(ni,nj),lat(ni,nj), lonvalue(ni*nj), &
109          lvaln(nAxis), lval_ni(ni), lval_nj(nj), lvalnInterp(nAxisinterp), &
110          lontransformed(niDomInterp, njDomInterp), lattransformed(niDomInterp, njDomInterp), &
111          bnds_lon(4,ni,nj), bnds_lat(4,ni,nj))
112
113  ALLOCATE(mask(nj))
114  DO i = 1, nj
115!    IF (MOD(i,2)>=0) THEN
116!      mask(i)=.FALSE.
117!    ELSE
118      mask(i)=.TRUE.
119!    ENDIF
120  ENDDO
121  lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1)
122  lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1)
123  bnds_lon(:,:,:) = bnds_lon_glo(:,ibegin+1:iend+1,jbegin+1:jend+1)
124  bnds_lat(:,:,:) = bnds_lat_glo(:,ibegin+1:iend+1,jbegin+1:jend+1)
125  lontransformed(:,:) = lon_glotransformed(ibeginDomInterp+1:iendDomInterp+1,jbeginDomInterp+1:jendDomInterp+1)
126  lattransformed(:,:) = lat_glotransformed(ibeginDomInterp+1:iendDomInterp+1,jbeginDomInterp+1:jendDomInterp+1)
127  field_A(1:ni,1:nj,:) = field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
128  field_Axis(1:nAxis)  = field_A_glo(1,1,axisBegin+1:axisEnd+1)
129  field_Two_Axis(:,1:nj)  = field_A_glo(:,jbegin+1:jend+1,1)
130  field_All_Axis(1:ni,1:nj,:) = field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
131
132  lvaln(1:nAxis) = lval(axisBegin+1:axisEnd+1)
133  lval_nj(1:nj) = lval_nj_glo(jbegin+1:jend+1);
134  lval_ni(1:ni) = lval_ni_glo(ibegin+1:iend+1);
135  lvalnInterp(1:nAxisinterp) = lvalInterPolated(axisterpBegin+1:axisinterpEnd+1)
136
137  CALL xios_context_initialize("test",comm)
138  CALL xios_get_handle("test",ctx_hdl)
139  CALL xios_set_current_context(ctx_hdl)
140
141  CALL xios_get_calendar_type(calendar_type)
142  PRINT *, "calendar_type = ", calendar_type
143
144  CALL xios_set_axis_attr("axis_A", n_glo=ni_glo, begin=ibegin, n=ni, value=lval_ni)
145  CALL xios_set_axis_attr("axis_B", n_glo=nj_glo, begin=jbegin, n=nj, value=lval_nj, mask=mask)
146  CALL xios_set_axis_attr("axis_C", n_glo=llm, value=lval)
147  CALL xios_set_axis_attr("axis_D", n_glo=llm, begin=axisBegin, n=nAxis, value=lvaln)
148  CALL xios_set_axis_attr("axis_E", n_glo=llmInterPolated, value=lvalnInterp, begin=axisterpBegin, n=nAxisinterp)
149  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj)
150  CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
151  CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat, type='curvilinear')
152  CALL xios_set_domain_attr("domain_A",bounds_lon_2d=bnds_lon,bounds_lat_2d=bnds_lat, nvertex=4, type='curvilinear')
153
154  CALL xios_set_domain_attr("domain_A_transformed", ni_glo=niDomGlo, nj_glo=njDomGlo, &
155                            type='rectilinear')
156!                                                    ibegin=ibeginDomInterp, ni=niDomInterp, jbegin=jbeginDomInterp, nj=njDomInterp)
157!  CALL xios_set_domain_attr("domain_A_transformed", lonvalue_2D=lontransformed, &
158!                                                    latvalue_2D=lattransformed)
159
160  CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
161
162!  CALL xios_get_handle("field_definition",fieldgroup_hdl)
163!  CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
164!  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
165!
166!  CALL xios_get_handle("output",file_hdl)
167!  CALL xios_add_child(file_hdl,field_hdl)
168!  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_C")
169
170  dtime%second = 3600
171  CALL xios_set_timestep(dtime)
172
173  ! The calendar is created as soon as the calendar type is defined. This way
174  ! calendar operations can be used before the context definition is closed
175  CALL xios_get_time_origin(date)
176  PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year)
177  PRINT *, "--> day length = ", xios_get_day_length_in_seconds()
178  PRINT *, "time_origin = ", date
179  PRINT *, "xios_date_get_second_of_year(time_origin) = ", xios_date_get_second_of_year(date)
180  PRINT *, "xios_date_get_day_of_year(time_origin) = ", xios_date_get_day_of_year(date)
181  PRINT *, "xios_date_get_fraction_of_year(time_origin) = ", xios_date_get_fraction_of_year(date)
182  PRINT *, "xios_date_get_second_of_day(time_origin) = ", xios_date_get_second_of_day(date)
183  PRINT *, "xios_date_get_fraction_of_day(time_origin) = ", xios_date_get_fraction_of_day(date)
184  dtime%timestep = 1
185  dtime = 0.5 * dtime
186  PRINT *, "duration = ", dtime
187  date = date + 3 * (dtime + dtime)
188  PRINT *, "date = time_origin + 3 * (duration + duration) = ", date
189  PRINT *, "xios_date_convert_to_seconds(date) = ", xios_date_convert_to_seconds(date)
190  PRINT *, "xios_date_convert_to_seconds(date - 2.5h) = ", xios_date_convert_to_seconds(date - 2.5 * xios_hour)
191
192  ni=0 ; lonvalue(:)=0
193!  CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_1D=lonvalue)
194
195!  print *,"ni",ni
196!  print *,"lonvalue",lonvalue ;
197
198  CALL xios_is_defined_field_attr("field_A",enabled=ok)
199  PRINT *,"field_A : attribute enabled is defined ? ",ok
200  CALL xios_close_context_definition()
201
202  PRINT*,"field field_A is active ? ",xios_field_is_active("field_A")
203  DO ts=1,24*10
204    CALL xios_update_calendar(ts)
205    CALL xios_send_field("field_A",field_A)
206    CALL xios_send_field("field_Axis",field_Axis)
207    CALL xios_send_field("field_Two_Axis",field_Two_Axis)
208    CALL xios_send_field("field_All_Axis",field_All_Axis)
209    tsTemp = ts
210    CALL xios_send_scalar("field_Scalar", tsTemp)
211    CALL wait_us(5000) ;
212  ENDDO
213
214  CALL xios_context_finalize()
215
216  DEALLOCATE(field_A, field_Two_Axis, field_Axis, field_All_Axis, &
217             lon, lat, lonvalue, &
218             lvaln, lval_ni, lval_nj, lvalnInterp, &
219             bnds_lon, bnds_lat)
220
221  DEALLOCATE(mask)
222
223  CALL MPI_COMM_FREE(comm, ierr)
224
225  CALL xios_finalize()
226
227  CALL MPI_FINALIZE(ierr)
228
229CONTAINS
230  SUBROUTINE Distribute_index(ibegin, iend, ni, nglob, rank, size)
231    INTEGER, INTENT(INOUT) :: ibegin, iend, ni
232    INTEGER, INTENT(IN)    :: nglob, rank, size
233    DO n=0,size-1
234      ni=nglob/size
235      IF (n<MOD(nglob,size)) ni=ni+1
236      IF (n==rank) exit
237      ibegin=ibegin+ni
238    ENDDO
239    iend=ibegin+ni-1
240  END SUBROUTINE Distribute_index
241END PROGRAM test_new_features
Note: See TracBrowser for help on using the repository browser.