source: XIOS/trunk/src/test/test_second_server.f90 @ 1627

Last change on this file since 1627 was 1071, checked in by oabramkina, 7 years ago

dev: test for secondary servers added.

File size: 6.7 KB
Line 
1PROGRAM test_regular
2
3  USE xios
4  USE mod_wait
5  IMPLICIT NONE
6  INCLUDE "mpif.h"
7
8  INTEGER, PARAMETER :: ntime=1
9
10  CHARACTER(len=*),PARAMETER :: id="client"
11  TYPE(xios_duration)  :: dtime
12  TYPE(xios_context) :: ctx_hdl
13  TYPE(xios_field) :: field_hdl
14  TYPE(xios_fieldgroup) :: fieldgroup_hdl
15  TYPE(xios_file) :: file_hdl
16  LOGICAL :: ok
17  CHARACTER(len=256) :: crname
18  INTEGER :: ts, i
19  INTEGER :: comm 
20  INTEGER :: ierr
21  INTEGER :: size, rank
22
23  INTEGER :: nlon = 6 !20
24  INTEGER :: nlat = 6 !16
25  INTEGER :: ncell 
26 
27  INTEGER :: ilat, ilon, ind
28  DOUBLE PRECISION :: lon1, lon2, lat1, lat2
29  INTEGER :: ni, ibegin
30
31  DOUBLE PRECISION,ALLOCATABLE :: lon_glo(:)
32  DOUBLE PRECISION,ALLOCATABLE :: lat_glo(:)
33  DOUBLE PRECISION,ALLOCATABLE :: bounds_lon_glo(:,:)
34  DOUBLE PRECISION,ALLOCATABLE :: bounds_lat_glo(:,:)
35  DOUBLE PRECISION,ALLOCATABLE :: field_temp_glo(:,:)
36  DOUBLE PRECISION,ALLOCATABLE :: lon(:)
37  DOUBLE PRECISION,ALLOCATABLE :: lat(:)
38  DOUBLE PRECISION,ALLOCATABLE :: bounds_lon(:,:)
39  DOUBLE PRECISION,ALLOCATABLE :: bounds_lat(:,:)
40  DOUBLE PRECISION,ALLOCATABLE :: field_temp(:,:)
41  DOUBLE PRECISION,ALLOCATABLE :: field_temp1(:)
42  DOUBLE PRECISION,ALLOCATABLE :: field_temp2(:)
43  INTEGER,ALLOCATABLE  :: field_int(:)
44
45!!! MPI Initialization
46  CALL MPI_INIT(ierr)
47
48!!! XIOS Initialization (get the local communicator)
49  CALL xios_initialize(id,return_comm=comm)
50
51!!! Initialisation des coordonnées globales et locales pour la grille réguliÚre
52
53! Regions around the poles are not included into the grid
54! The whole grid is rectangular (nvertex=4)
55
56  ncell = nlon * (nlat-1)
57  ALLOCATE(lon_glo(ncell))
58  ALLOCATE(lat_glo(ncell))
59  ALLOCATE(bounds_lon_glo(4,ncell))
60  ALLOCATE(bounds_lat_glo(4,ncell))
61  ALLOCATE(field_temp_glo(ncell,ntime))
62
63
64  ind = 0
65  DO ilat = 1, nlat-1
66   DO ilon = 1, nlon
67
68      ind=ind+1
69
70      lon1 = 360./DBLE(nlon) * DBLE(ilon-1)
71      lon2 = lon1 + 360./DBLE(nlon)
72
73      lat1 = (90. + 90./DBLE(nlat)) - 180./DBLE(nlat)*DBLE(ilat)
74      lat2 = lat1 - 180./DBLE(nlat)
75
76      lon_glo(ind) = (lon1+lon2)*0.5
77      lat_glo(ind) = (lat1+lat2)*0.5 
78
79      bounds_lon_glo(1,ind) = lon1
80      bounds_lon_glo(2,ind) = lon2
81      bounds_lon_glo(3,ind) = lon2
82      bounds_lon_glo(4,ind) = lon1
83
84      bounds_lat_glo(1,ind) = lat1
85      bounds_lat_glo(2,ind) = lat1
86      bounds_lat_glo(3,ind) = lat2     
87      bounds_lat_glo(4,ind) = lat2     
88
89      field_temp_glo(ind,1) = DBLE(ind)
90
91    ENDDO
92  ENDDO
93
94! Initialization of local variables
95
96  CALL MPI_COMM_RANK(comm,rank,ierr)
97  CALL MPI_COMM_SIZE(comm,size,ierr)
98
99  IF (MOD(ncell, size) == 0) THEN
100    ni = ncell/size
101    ibegin = rank*ni
102  ELSE
103    IF (rank < MOD(ncell, size)) THEN
104      ni = ncell/size + 1
105      ibegin = rank*(ncell/size + 1)
106    ELSE
107      ni = ncell/size
108      IF (rank == MOD(ncell, size)) THEN
109        ibegin = rank*(ncell/size + 1)
110      ELSE
111        ibegin = MOD(ncell,size)*(ncell/size + 1) + (rank-MOD(ncell,size))*ncell/size
112      END IF
113    END IF
114  END IF
115
116  ALLOCATE(lon(ni))
117  ALLOCATE(lat(ni))
118  ALLOCATE(bounds_lon(4,ni))
119  ALLOCATE(bounds_lat(4,ni))
120  ALLOCATE(field_temp(ni,ntime)) 
121  ALLOCATE(field_temp1(ni))
122  ALLOCATE(field_temp2(ni))
123  ALLOCATE(field_int(ni))
124  lon = lon_glo(1+ibegin:ibegin+ni)
125  lat = lat_glo(1+ibegin:ibegin+ni)
126  bounds_lon(:,:) = bounds_lon_glo(:,1+ibegin:ibegin+ni)
127  bounds_lat(:,:) = bounds_lat_glo(:,1+ibegin:ibegin+ni)
128
129  !field_temp(:) = rank
130  field_temp1(:) = rank + 10
131  field_temp2(:) = rank + 20
132 
133 DO i = 1, ni
134  field_temp1 (i) = 100*rank + i
135  field_temp2 (i) = 0 !200*rank + i
136  !field_temp1 (i) = 10
137END DO
138
139!###########################################################################
140! Contexte ATM
141!###########################################################################
142
143  CALL xios_context_initialize("atmosphere",comm)
144  CALL xios_get_handle("atmosphere",ctx_hdl)
145  CALL xios_set_current_context(ctx_hdl)
146
147  CALL xios_define_calendar(type="Gregorian", &
148                            start_date=xios_date(2000, 01, 01, 00, 00, 00), &
149                            time_origin=xios_date(1999, 01, 01, 15, 00, 00))
150
151  CALL xios_set_domain_attr("atm_face", ni_glo=ncell, ibegin=ibegin, ni=ni, type='unstructured')
152  CALL xios_set_domain_attr("atm_face", lonvalue_1d=lon, latvalue_1d=lat)
153  CALL xios_set_domain_attr("atm_face", bounds_lon_1d=bounds_lon, bounds_lat_1d=bounds_lat)
154
155!!! Definition du timestep
156
157  dtime%second=3600
158  CALL xios_set_timestep(timestep=dtime)
159
160!!! Fin de la definition du contexte
161
162  CALL xios_close_context_definition()
163
164!###########################################################################
165! Contexte SRF
166!###########################################################################
167
168  CALL xios_context_initialize("surface",comm)
169  CALL xios_get_handle("surface",ctx_hdl)
170  CALL xios_set_current_context(ctx_hdl)
171
172  CALL xios_define_calendar(type="Gregorian", &
173                            start_date=xios_date(2000, 01, 01, 00, 00, 00), &
174                            time_origin=xios_date(1999, 01, 01, 15, 00, 00))
175
176  CALL xios_set_domain_attr("domain_srf", ni_glo=ncell, ibegin=ibegin, ni=ni, type='unstructured')
177  CALL xios_set_domain_attr("domain_srf", lonvalue_1d=lon, latvalue_1d=lat)
178  CALL xios_set_domain_attr("domain_srf", bounds_lon_1d=bounds_lon, bounds_lat_1d=bounds_lat)
179
180   
181!!! Definition du timestep
182
183  dtime%second=3600
184  CALL xios_set_timestep(timestep=dtime)
185
186!!! Fin de la definition du contexte
187
188  CALL xios_close_context_definition()
189
190
191!####################################################################################
192!!! Boucle temporelle
193!####################################################################################
194   
195    DO ts=1,ntime
196
197      CALL xios_get_handle("atmosphere",ctx_hdl)
198      CALL xios_set_current_context(ctx_hdl)
199
200!!! Mise a jour du pas de temps
201      CALL xios_update_calendar(ts)
202
203!!! On donne la valeur du champ atm
204     CALL xios_send_field("atm_temp1",field_temp1(:))
205     CALL xios_send_field("atm_temp2",field_temp2(:))
206
207     CALL xios_get_handle("surface",ctx_hdl)
208     CALL xios_set_current_context(ctx_hdl)
209
210!!! Mise a jour du pas de temps
211     CALL xios_update_calendar(ts)
212
213!!! On donne la valeur du champ srf
214     CALL xios_send_field("srf_temp",field_temp1(:))
215     CALL wait_us(5000) ;
216
217    ENDDO
218
219    CALL xios_context_finalize()
220
221    CALL xios_get_handle("atmosphere",ctx_hdl)
222    CALL xios_set_current_context(ctx_hdl)
223    CALL xios_context_finalize()
224
225    DEALLOCATE(lon_glo, lat_glo)
226    DEALLOCATE(bounds_lon_glo, bounds_lat_glo)
227    DEALLOCATE(field_temp_glo)
228    DEALLOCATE(lon, lat)
229    DEALLOCATE(bounds_lon, bounds_lat)
230    DEALLOCATE(field_temp)
231    DEALLOCATE(field_temp1, field_temp2)
232    DEALLOCATE(field_int)
233
234!!! Fin de XIOS
235
236    CALL MPI_COMM_FREE(comm, ierr)
237
238    CALL xios_finalize()
239
240    CALL MPI_FINALIZE(ierr)
241
242  END PROGRAM test_regular
243
244
245
246
247
248
Note: See TracBrowser for help on using the repository browser.