1 | PROGRAM test_grid |
---|
2 | |
---|
3 | USE xios |
---|
4 | USE mod_wait |
---|
5 | IMPLICIT NONE |
---|
6 | INCLUDE "mpif.h" |
---|
7 | |
---|
8 | INTEGER,PARAMETER :: il_unit=10 |
---|
9 | INTEGER :: comm, rank, size_loc, ierr |
---|
10 | INTEGER :: ni,ibegin,iend,nj,jbegin,jend |
---|
11 | INTEGER :: i,j,l,ts,n, nb_pt, il_run |
---|
12 | CHARACTER(len=*),PARAMETER :: id="client" |
---|
13 | CHARACTER(1000):: duration, timestep |
---|
14 | TYPE(xios_date) :: cdate, edate |
---|
15 | TYPE(xios_duration) :: dtime |
---|
16 | TYPE(xios_context) :: ctx_hdl |
---|
17 | REAL :: ilon,ilat |
---|
18 | DOUBLE PRECISION,ALLOCATABLE :: lon_glo(:,:),lat_glo(:,:),lval(:) |
---|
19 | DOUBLE PRECISION,ALLOCATABLE :: bounds_lon_glo(:,:,:),bounds_lat_glo(:,:,:) |
---|
20 | DOUBLE PRECISION,ALLOCATABLE :: field_A_glo (:,:,:), pressure_glo (:,:,:), height_glo (:,:,:) |
---|
21 | DOUBLE PRECISION,ALLOCATABLE :: pressure (:,:,:), height (:,:,:) |
---|
22 | DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),lonvalue(:,:) |
---|
23 | DOUBLE PRECISION,ALLOCATABLE :: bounds_lon(:,:,:),bounds_lat(:,:,:) ; |
---|
24 | DOUBLE PRECISION,ALLOCATABLE :: field_atm_2D(:,:),field_atm_3D(:,:,:),field_srf_2D(:),field_srf_3D(:,:) |
---|
25 | DOUBLE PRECISION,ALLOCATABLE :: field_oce_2D(:,:),field_oce_3D(:,:,:) |
---|
26 | INTEGER, ALLOCATABLE :: kindex(:) |
---|
27 | |
---|
28 | INTEGER :: ni_glo, nj_glo,llm |
---|
29 | |
---|
30 | NAMELIST /param_toy/ ni_glo, nj_glo,llm,timestep,duration |
---|
31 | |
---|
32 | !!! MPI Initialization |
---|
33 | |
---|
34 | CALL MPI_INIT(ierr) |
---|
35 | |
---|
36 | CALL init_wait |
---|
37 | |
---|
38 | !!! Lecture des parametres du run |
---|
39 | |
---|
40 | OPEN(unit=il_unit, file='param.def',status='old',iostat=ierr) |
---|
41 | READ (il_unit, nml=param_toy) |
---|
42 | !PRINT *, ni_glo, nj_glo,llm,duration |
---|
43 | |
---|
44 | !!! XIOS Initialization (get the local communicator) |
---|
45 | |
---|
46 | CALL xios_initialize(id,return_comm=comm) |
---|
47 | |
---|
48 | CALL MPI_COMM_RANK(comm,rank,ierr) |
---|
49 | CALL MPI_COMM_SIZE(comm,size_loc,ierr) |
---|
50 | |
---|
51 | !!! Initialisation et allocation des coordonnées globales et locales pour la grille réguliÚre |
---|
52 | |
---|
53 | ALLOCATE (lon_glo(ni_glo,nj_glo),lat_glo(ni_glo,nj_glo)) |
---|
54 | ALLOCATE(bounds_lon_glo(4,ni_glo,nj_glo)) |
---|
55 | ALLOCATE(bounds_lat_glo(4,ni_glo,nj_glo)) |
---|
56 | ALLOCATE (field_A_glo(ni_glo,nj_glo,llm)) |
---|
57 | ALLOCATE (pressure_glo(ni_glo,nj_glo,llm)) |
---|
58 | ALLOCATE (height_glo(ni_glo,nj_glo,llm)) |
---|
59 | ALLOCATE (lval(llm)) |
---|
60 | |
---|
61 | DO j=1,nj_glo |
---|
62 | DO i=1,ni_glo |
---|
63 | |
---|
64 | ilon=i-0.5 |
---|
65 | ilat=j-0.5 |
---|
66 | |
---|
67 | lat_glo(i,j)= 90-(ilat*180./ni_glo) |
---|
68 | lon_glo(i,j)= (ilon*360./nj_glo) |
---|
69 | |
---|
70 | bounds_lat_glo(1,i,j)= 90-((ilat-0.5)*180./ni_glo) |
---|
71 | bounds_lon_glo(1,i,j)=((ilon-0.5)*360./nj_glo) |
---|
72 | |
---|
73 | bounds_lat_glo(2,i,j)= 90-((ilat-0.5)*180./ni_glo) |
---|
74 | bounds_lon_glo(2,i,j)=((ilon+0.5)*360./nj_glo) |
---|
75 | |
---|
76 | bounds_lat_glo(3,i,j)= 90-((ilat+0.5)*180./ni_glo) |
---|
77 | bounds_lon_glo(3,i,j)=((ilon+0.5)*360./nj_glo) |
---|
78 | |
---|
79 | bounds_lat_glo(4,i,j)= 90-((ilat+0.5)*180./ni_glo) |
---|
80 | bounds_lon_glo(4,i,j)=((ilon-0.5)*360./nj_glo) |
---|
81 | |
---|
82 | DO l=1,llm |
---|
83 | field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l |
---|
84 | ! pressure at half levels. First index is high altitude, low pressure |
---|
85 | pressure_glo(i,j,l)=((l-0.)/llm)*100000 + (ilat -nj_glo/2.)/nj_glo * 10000 |
---|
86 | height_glo(i,j,l)=(llm-l+0.5)/llm * 15000 + ilat * 100 |
---|
87 | ENDDO |
---|
88 | ENDDO |
---|
89 | ENDDO |
---|
90 | ni=ni_glo ; ibegin=0 |
---|
91 | |
---|
92 | jbegin=0 |
---|
93 | DO n=0,size_loc-1 |
---|
94 | nj=nj_glo/size_loc |
---|
95 | IF (n<MOD(nj_glo,size_loc)) nj=nj+1 |
---|
96 | IF (n==rank) exit |
---|
97 | jbegin=jbegin+nj |
---|
98 | ENDDO |
---|
99 | |
---|
100 | iend=ibegin+ni-1 ; jend=jbegin+nj-1 |
---|
101 | |
---|
102 | ALLOCATE(lon(ni,nj),lat(ni,nj),lonvalue(ni,nj)) |
---|
103 | ALLOCATE(bounds_lon(4,ni,nj)) |
---|
104 | ALLOCATE(bounds_lat(4,ni,nj)) |
---|
105 | lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1) |
---|
106 | lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1) |
---|
107 | bounds_lon(:,:,:)=bounds_lon_glo(:,ibegin+1:iend+1,jbegin+1:jend+1) |
---|
108 | bounds_lat(:,:,:)=bounds_lat_glo(:,ibegin+1:iend+1,jbegin+1:jend+1) |
---|
109 | |
---|
110 | |
---|
111 | DO i=1,llm |
---|
112 | lval(i)=i |
---|
113 | ENDDO |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | !########################################################################### |
---|
118 | ! Contexte ATM |
---|
119 | !########################################################################### |
---|
120 | ALLOCATE(field_atm_2D(0:ni+1,-1:nj+2),field_atm_3D(0:ni+1,-1:nj+2,llm)) |
---|
121 | ALLOCATE(pressure(0:ni+1,-1:nj+2,llm)) |
---|
122 | ALLOCATE(height(0:ni+1,-1:nj+2,llm)) |
---|
123 | field_atm_2D(1:ni,1:nj)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1) |
---|
124 | field_atm_3D(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:) |
---|
125 | pressure(1:ni,1:nj,:)=pressure_glo(ibegin+1:iend+1,jbegin+1:jend+1,:) |
---|
126 | height(1:ni,1:nj,:)=height_glo(ibegin+1:iend+1,jbegin+1:jend+1,:) |
---|
127 | |
---|
128 | CALL xios_context_initialize("arpsfx",comm) |
---|
129 | CALL xios_get_handle("arpsfx",ctx_hdl) |
---|
130 | CALL xios_set_current_context(ctx_hdl) |
---|
131 | |
---|
132 | CALL xios_set_axis_attr("axis_atm",n_glo=llm ,value=lval) ; |
---|
133 | |
---|
134 | CALL xios_set_domain_attr("domain_atm",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj, type='rectilinear') |
---|
135 | CALL xios_set_domain_attr("domain_atm",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4) |
---|
136 | CALL xios_set_domain_attr("domain_atm",lonvalue_2D=lon,latvalue_2D=lat) |
---|
137 | CALL xios_set_domain_attr("domain_atm", nvertex=4, bounds_lon_2d=bounds_lon, bounds_lat_2d=bounds_lat) |
---|
138 | |
---|
139 | |
---|
140 | !!! Definition du timestep |
---|
141 | |
---|
142 | CALL xios_get_start_date(cdate) |
---|
143 | edate=cdate+xios_duration_convert_from_string(duration) |
---|
144 | dtime=xios_duration_convert_from_string(timestep) |
---|
145 | CALL xios_set_timestep(timestep=dtime) |
---|
146 | |
---|
147 | !!! Fin de la definition du contexte |
---|
148 | |
---|
149 | !CALL xios_close_context_definition() |
---|
150 | |
---|
151 | |
---|
152 | !########################################################################### |
---|
153 | ! Contexte SRF |
---|
154 | !########################################################################### |
---|
155 | |
---|
156 | !!! Initialisation des coordonnées globales et locales pour la grille indexee (1 point sur 2) |
---|
157 | |
---|
158 | nb_pt=ni*nj/2 |
---|
159 | ALLOCATE(kindex(nb_pt),field_srf_2D(nb_pt),field_srf_3D(nb_pt,llm)) |
---|
160 | DO i=1,nb_pt |
---|
161 | kindex(i)=2*i-1 |
---|
162 | ENDDO |
---|
163 | field_srf_2D(1:nb_pt)=RESHAPE(field_A_glo(ibegin+1:iend+1:2,jbegin+1:jend+1,1),(/ nb_pt /)) |
---|
164 | field_srf_3D(1:nb_pt,:)=RESHAPE(field_A_glo(ibegin+1:iend+1:2,jbegin+1:jend+1,:),(/ nb_pt,llm /)) |
---|
165 | |
---|
166 | !CALL xios_context_initialize("surface",comm) |
---|
167 | !CALL xios_get_handle("surface",ctx_hdl) |
---|
168 | !CALL xios_set_current_context(ctx_hdl) |
---|
169 | |
---|
170 | CALL xios_set_axis_attr("axis_srf",n_glo=llm ,value=lval) |
---|
171 | CALL xios_set_domain_attr("domain_srf",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj, type='rectilinear') |
---|
172 | CALL xios_set_domain_attr("domain_srf",data_dim=1, data_ibegin=0, data_ni=nb_pt) |
---|
173 | CALL xios_set_domain_attr("domain_srf",data_i_index=kindex) |
---|
174 | CALL xios_set_domain_attr("domain_srf",lonvalue_2D=lon,latvalue_2D=lat) |
---|
175 | CALL xios_set_domain_attr("domain_srf", nvertex=4, bounds_lon_2d=bounds_lon, bounds_lat_2d=bounds_lat) |
---|
176 | |
---|
177 | !!! Definition du timestep |
---|
178 | |
---|
179 | !dtime%second=timestep |
---|
180 | !dtime=xios_duration_convert_from_string(timestep) |
---|
181 | !CALL xios_set_timestep(timestep=dtime) |
---|
182 | |
---|
183 | !!! Fin de la definition du contexte SRF |
---|
184 | |
---|
185 | CALL xios_close_context_definition() |
---|
186 | |
---|
187 | !########################################################################### |
---|
188 | ! Contexte OCE |
---|
189 | !########################################################################### |
---|
190 | ALLOCATE(field_oce_2D(0:ni+1,-1:nj+2),field_oce_3D(0:ni+1,-1:nj+2,llm)) |
---|
191 | field_oce_2D(1:ni,1:nj)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1) |
---|
192 | field_oce_3D(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:) |
---|
193 | |
---|
194 | CALL xios_context_initialize("nemo",comm) |
---|
195 | CALL xios_get_handle("nemo",ctx_hdl) |
---|
196 | CALL xios_set_current_context(ctx_hdl) |
---|
197 | |
---|
198 | CALL xios_set_axis_attr("axis_oce",n_glo=llm ,value=lval) ; |
---|
199 | |
---|
200 | CALL xios_set_domain_attr("domain_oce",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj, type='curvilinear') |
---|
201 | CALL xios_set_domain_attr("domain_oce",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4) |
---|
202 | CALL xios_set_domain_attr("domain_oce",lonvalue_2D=lon,latvalue_2D=lat) |
---|
203 | |
---|
204 | |
---|
205 | !!! Definition du timestep |
---|
206 | |
---|
207 | dtime=xios_duration_convert_from_string(timestep) |
---|
208 | CALL xios_set_timestep(timestep=dtime) |
---|
209 | |
---|
210 | CALL xios_close_context_definition() |
---|
211 | |
---|
212 | !#################################################################################### |
---|
213 | !!! Boucle temporelle |
---|
214 | !#################################################################################### |
---|
215 | ts=1 |
---|
216 | cdate=cdate+dtime |
---|
217 | DO while ( cdate <= edate ) |
---|
218 | |
---|
219 | CALL xios_get_handle("arpsfx",ctx_hdl) |
---|
220 | CALL xios_set_current_context(ctx_hdl) |
---|
221 | |
---|
222 | !!! Mise a jour du pas de temps |
---|
223 | |
---|
224 | CALL xios_update_calendar(ts) |
---|
225 | |
---|
226 | !!! On donne la valeur du champ atm |
---|
227 | |
---|
228 | !print *,'sending field_atm_2d at timestep',ts |
---|
229 | CALL xios_send_field("field_atm_2D",field_atm_2D+ts) |
---|
230 | CALL xios_send_field("field_atm_3D",field_atm_3D+ts) |
---|
231 | CALL xios_send_field("field_grid",field_atm_3D+ts) |
---|
232 | CALL xios_send_field("pressure" ,pressure) |
---|
233 | CALL xios_send_field("height" ,height) |
---|
234 | |
---|
235 | !!! On change de contexte |
---|
236 | |
---|
237 | !CALL xios_get_handle("surface",ctx_hdl) |
---|
238 | !CALL xios_set_current_context(ctx_hdl) |
---|
239 | |
---|
240 | !!! Mise a jour du pas de temps |
---|
241 | |
---|
242 | !CALL xios_update_calendar(ts) |
---|
243 | |
---|
244 | !!! On donne la valeur du champ srf |
---|
245 | |
---|
246 | CALL xios_send_field("field_srf_2D",field_srf_2D) |
---|
247 | CALL xios_send_field("field_srf_3D",field_srf_3D) |
---|
248 | |
---|
249 | !!! On change de contexte |
---|
250 | |
---|
251 | CALL xios_get_handle("nemo",ctx_hdl) |
---|
252 | CALL xios_set_current_context(ctx_hdl) |
---|
253 | |
---|
254 | !!! Mise a jour du pas de temps |
---|
255 | |
---|
256 | CALL xios_update_calendar(ts) |
---|
257 | |
---|
258 | !!! On donne la valeur du champ srf |
---|
259 | |
---|
260 | CALL xios_send_field("field_oce_grid_2D",field_oce_2D) |
---|
261 | CALL xios_send_field("field_oce_grid_3D",field_oce_3D) |
---|
262 | |
---|
263 | !CALL wait_us(5000) ; |
---|
264 | cdate=cdate+dtime |
---|
265 | ts=ts+1 |
---|
266 | |
---|
267 | ENDDO |
---|
268 | |
---|
269 | !#################################################################################### |
---|
270 | !!! Finalisation |
---|
271 | !#################################################################################### |
---|
272 | |
---|
273 | !!! Fin des contextes |
---|
274 | |
---|
275 | CALL xios_context_finalize() |
---|
276 | CALL xios_get_handle("arpsfx",ctx_hdl) |
---|
277 | CALL xios_set_current_context(ctx_hdl) |
---|
278 | CALL xios_context_finalize() |
---|
279 | !CALL xios_get_handle("surface",ctx_hdl) |
---|
280 | !CALL xios_set_current_context(ctx_hdl) |
---|
281 | !CALL xios_context_finalize() |
---|
282 | |
---|
283 | DEALLOCATE(lon, lat, lonvalue, field_atm_2D, field_atm_3D) |
---|
284 | DEALLOCATE(pressure,height,pressure_glo,height_glo) |
---|
285 | DEALLOCATE(kindex, field_srf_2D, field_srf_3D) |
---|
286 | DEALLOCATE(field_oce_2D, field_oce_3D) |
---|
287 | DEALLOCATE(lon_glo,lat_glo,field_A_glo,lval) |
---|
288 | |
---|
289 | !!! Fin de XIOS |
---|
290 | |
---|
291 | CALL MPI_COMM_FREE(comm, ierr) |
---|
292 | |
---|
293 | CALL xios_finalize() |
---|
294 | |
---|
295 | CALL MPI_FINALIZE(ierr) |
---|
296 | |
---|
297 | END PROGRAM test_grid |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | |
---|
302 | |
---|
303 | |
---|