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

Last change on this file since 827 was 827, checked in by mhnguyen, 5 years ago

Implementing dynamic interpolation on axis

+) Change grid transformation to make it more flexible
+) Make some small improvements

Test
+) On Curie
+) All test pass

  • Property svn:executable set to *
File size: 9.6 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), field_Value_glo(ni_glo,nj_glo,llm)
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(:,:,:), field_value(:,:,:)
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        field_Value_glo(i,j,l)=l*100
71      ENDDO
72    ENDDO
73    lval_nj_glo(j) = j-1
74  ENDDO
75  ni = ni_glo
76  ibegin = 0
77  iend = ibegin + ni - 1
78
79  jbegin=0
80  CALL Distribute_index(jbegin, jend, nj, nj_glo, rank, size)
81
82  DO j=1,llm
83    lval(j) = j *100
84  ENDDO
85  axisBegin = 0
86  CALL Distribute_index(axisBegin, axisEnd, nAxis, llm, rank, size)
87
88  DO j=1,llmInterPolated
89    lvalInterPolated(j) = j * 12
90  ENDDO
91  axisterpBegin = 0
92  CALL Distribute_index(axisterpBegin, axisinterpEnd, nAxisinterp, llmInterPolated, rank, size)
93
94  niDomGlo = ni_glo - 4
95  njDomGlo = nj_glo - 4
96  ALLOCATE(lon_glotransformed(niDomGlo,njDomGlo), lat_glotransformed(niDomGlo,njDomGlo))
97  DO j=1,njDomGlo
98    DO i=1,niDomGlo
99      lon_glotransformed(i,j)=(i-1)+(j-1)*niDomGlo
100      lat_glotransformed(i,j)=1000+(i-1)+(j-1)*niDomGlo
101    ENDDO
102  ENDDO
103
104  niDomInterp = niDomGlo; ibeginDomInterp = 0
105  jbeginDomInterp = 0
106  CALL Distribute_index(jbeginDomInterp, jendDomInterp, njDomInterp, njDomGlo, rank, size)
107
108  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), &
109          lon(ni,nj),lat(ni,nj), lonvalue(ni*nj), &
110          lvaln(nAxis), lval_ni(ni), lval_nj(nj), lvalnInterp(nAxisinterp), &
111          lontransformed(niDomInterp, njDomInterp), lattransformed(niDomInterp, njDomInterp), &
112          bnds_lon(4,ni,nj), bnds_lat(4,ni,nj), field_value(0:ni+1,-1:nj+2,llm))
113
114  ALLOCATE(mask(nj))
115  DO i = 1, nj
116!    IF (MOD(i,2)>=0) THEN
117!      mask(i)=.FALSE.
118!    ELSE
119      mask(i)=.TRUE.
120!    ENDIF
121  ENDDO
122  lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1)
123  lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1)
124  bnds_lon(:,:,:) = bnds_lon_glo(:,ibegin+1:iend+1,jbegin+1:jend+1)
125  bnds_lat(:,:,:) = bnds_lat_glo(:,ibegin+1:iend+1,jbegin+1:jend+1)
126  lontransformed(:,:) = lon_glotransformed(ibeginDomInterp+1:iendDomInterp+1,jbeginDomInterp+1:jendDomInterp+1)
127  lattransformed(:,:) = lat_glotransformed(ibeginDomInterp+1:iendDomInterp+1,jbeginDomInterp+1:jendDomInterp+1)
128  field_A(1:ni,1:nj,:) = field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
129  field_value(1:ni,1:nj,:) = field_Value_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
130  field_Axis(1:nAxis)  = field_A_glo(1,1,axisBegin+1:axisEnd+1)
131  field_Two_Axis(:,1:nj)  = field_A_glo(:,jbegin+1:jend+1,1)
132  field_All_Axis(1:ni,1:nj,:) = field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
133
134  lvaln(1:nAxis) = lval(axisBegin+1:axisEnd+1)
135  lval_nj(1:nj) = lval_nj_glo(jbegin+1:jend+1);
136  lval_ni(1:ni) = lval_ni_glo(ibegin+1:iend+1);
137  lvalnInterp(1:nAxisinterp) = lvalInterPolated(axisterpBegin+1:axisinterpEnd+1)
138
139  CALL xios_context_initialize("test",comm)
140  CALL xios_get_handle("test",ctx_hdl)
141  CALL xios_set_current_context(ctx_hdl)
142
143  CALL xios_get_calendar_type(calendar_type)
144  PRINT *, "calendar_type = ", calendar_type
145
146  CALL xios_set_axis_attr("axis_A", n_glo=ni_glo, begin=ibegin, n=ni, value=lval_ni)
147  CALL xios_set_axis_attr("axis_B", n_glo=nj_glo, begin=jbegin, n=nj, value=lval_nj, mask=mask)
148  CALL xios_set_axis_attr("axis_C", n_glo=llm, value=lval)
149  CALL xios_set_axis_attr("axis_D", n_glo=llm, begin=axisBegin, n=nAxis, value=lvaln)
150  CALL xios_set_axis_attr("axis_E", n_glo=llmInterPolated, value=lvalnInterp, begin=axisterpBegin, n=nAxisinterp)
151  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj)
152  CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
153  CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat, type='curvilinear')
154  CALL xios_set_domain_attr("domain_A",bounds_lon_2d=bnds_lon,bounds_lat_2d=bnds_lat, nvertex=4, type='curvilinear')
155
156  CALL xios_set_domain_attr("domain_A_transformed", ni_glo=niDomGlo, nj_glo=njDomGlo, &
157                            type='rectilinear')
158!                                                    ibegin=ibeginDomInterp, ni=niDomInterp, jbegin=jbeginDomInterp, nj=njDomInterp)
159!  CALL xios_set_domain_attr("domain_A_transformed", lonvalue_2D=lontransformed, &
160!                                                    latvalue_2D=lattransformed)
161
162  CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
163
164!  CALL xios_get_handle("field_definition",fieldgroup_hdl)
165!  CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
166!  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
167!
168!  CALL xios_get_handle("output",file_hdl)
169!  CALL xios_add_child(file_hdl,field_hdl)
170!  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_C")
171
172  dtime%second = 3600
173  CALL xios_set_timestep(dtime)
174
175  ! The calendar is created as soon as the calendar type is defined. This way
176  ! calendar operations can be used before the context definition is closed
177  CALL xios_get_time_origin(date)
178  PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year)
179  PRINT *, "--> day length = ", xios_get_day_length_in_seconds()
180  PRINT *, "time_origin = ", date
181  PRINT *, "xios_date_get_second_of_year(time_origin) = ", xios_date_get_second_of_year(date)
182  PRINT *, "xios_date_get_day_of_year(time_origin) = ", xios_date_get_day_of_year(date)
183  PRINT *, "xios_date_get_fraction_of_year(time_origin) = ", xios_date_get_fraction_of_year(date)
184  PRINT *, "xios_date_get_second_of_day(time_origin) = ", xios_date_get_second_of_day(date)
185  PRINT *, "xios_date_get_fraction_of_day(time_origin) = ", xios_date_get_fraction_of_day(date)
186  dtime%timestep = 1
187  dtime = 0.5 * dtime
188  PRINT *, "duration = ", dtime
189  date = date + 3 * (dtime + dtime)
190  PRINT *, "date = time_origin + 3 * (duration + duration) = ", date
191  PRINT *, "xios_date_convert_to_seconds(date) = ", xios_date_convert_to_seconds(date)
192  PRINT *, "xios_date_convert_to_seconds(date - 2.5h) = ", xios_date_convert_to_seconds(date - 2.5 * xios_hour)
193
194  ni=0 ; lonvalue(:)=0
195!  CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_1D=lonvalue)
196
197!  print *,"ni",ni
198!  print *,"lonvalue",lonvalue ;
199
200  CALL xios_is_defined_field_attr("field_A",enabled=ok)
201  PRINT *,"field_A : attribute enabled is defined ? ",ok
202  CALL xios_close_context_definition()
203
204  PRINT*,"field field_A is active ? ",xios_field_is_active("field_A")
205  DO ts=1,24*1
206    CALL xios_update_calendar(ts)
207    CALL xios_send_field("field_A",field_A)
208    CALL xios_send_field("field_Value",field_value)
209    CALL xios_send_field("field_Axis",field_Axis)
210    CALL xios_send_field("field_Two_Axis",field_Two_Axis)
211    CALL xios_send_field("field_All_Axis",field_All_Axis)
212    tsTemp = ts
213    CALL xios_send_scalar("field_Scalar", tsTemp)
214    CALL wait_us(5000) ;
215  ENDDO
216
217  CALL xios_context_finalize()
218
219  DEALLOCATE(field_A, field_Two_Axis, field_Axis, field_All_Axis, &
220             lon, lat, lonvalue, &
221             lvaln, lval_ni, lval_nj, lvalnInterp, &
222             bnds_lon, bnds_lat)
223
224  DEALLOCATE(mask)
225
226  CALL MPI_COMM_FREE(comm, ierr)
227
228  CALL xios_finalize()
229
230  CALL MPI_FINALIZE(ierr)
231
232CONTAINS
233  SUBROUTINE Distribute_index(ibegin, iend, ni, nglob, rank, size)
234    INTEGER, INTENT(INOUT) :: ibegin, iend, ni
235    INTEGER, INTENT(IN)    :: nglob, rank, size
236    DO n=0,size-1
237      ni=nglob/size
238      IF (n<MOD(nglob,size)) ni=ni+1
239      IF (n==rank) exit
240      ibegin=ibegin+ni
241    ENDDO
242    iend=ibegin+ni-1
243  END SUBROUTINE Distribute_index
244END PROGRAM test_new_features
Note: See TracBrowser for help on using the repository browser.