source: XIOS/trunk/src/test/test_xios2_cmip6.f90 @ 2280

Last change on this file since 2280 was 1133, checked in by oabramkina, 7 years ago

Fixing a bug appearing during client/server initialization.

File size: 7.6 KB
Line 
1PROGRAM test_xios2_cmip6
2
3  USE xios
4  USE mod_wait
5  IMPLICIT NONE
6  INCLUDE "mpif.h"
7
8  INTEGER,PARAMETER :: model_timestep=600, 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  TYPE(xios_duration)  :: dtime
14  TYPE(xios_context) :: ctx_hdl
15  DOUBLE PRECISION,ALLOCATABLE :: lon_glo(:,:),lat_glo(:,:),lval(:)
16  DOUBLE PRECISION,ALLOCATABLE :: field_A_glo (:,:,:)
17  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),lonvalue(:,:)
18  DOUBLE PRECISION,ALLOCATABLE :: field_atm_2D(:,:),field_atm_3D(:,:,:),field_srf_2D(:),field_srf_3D(:,:)
19  DOUBLE PRECISION,ALLOCATABLE :: field_oce_2D(:,:),field_oce_3D(:,:,:)
20  INTEGER, ALLOCATABLE :: kindex(:)
21
22  INTEGER :: ni_glo, nj_glo,llm,nb_days_run,nb_run
23
24  NAMELIST /param_toy/ ni_glo, nj_glo,llm,nb_days_run,nb_run
25
26!!! MPI Initialization
27
28  CALL MPI_INIT(ierr)
29
30  CALL init_wait
31
32!!! Lecture des parametres du run
33
34  OPEN(unit=il_unit, file='param.def',status='old',iostat=ierr)
35  READ (il_unit, nml=param_toy)
36  PRINT *, ni_glo, nj_glo,llm,nb_days_run,nb_run
37
38!!! XIOS Initialization (get the local communicator)
39
40  CALL xios_initialize(id,return_comm=comm)
41
42  CALL MPI_COMM_RANK(comm,rank,ierr)
43  CALL MPI_COMM_SIZE(comm,size_loc,ierr)
44
45!!! Initialisation et allocation des coordonnées globales et locales pour la grille réguliÚre
46
47  ALLOCATE (lon_glo(ni_glo,nj_glo),lat_glo(ni_glo,nj_glo))
48  ALLOCATE (field_A_glo(ni_glo,nj_glo,llm))
49  ALLOCATE (lval(llm))
50
51  DO j=1,nj_glo
52    DO i=1,ni_glo
53      lon_glo(i,j)=(i-1)+(j-1)*ni_glo
54      lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo
55      DO l=1,llm
56        field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l
57      ENDDO
58    ENDDO
59  ENDDO
60  ni=ni_glo ; ibegin=0
61
62  jbegin=0
63  DO n=0,size_loc-1
64    nj=nj_glo/size_loc
65    IF (n<MOD(nj_glo,size_loc)) nj=nj+1
66    IF (n==rank) exit
67    jbegin=jbegin+nj
68  ENDDO
69
70  iend=ibegin+ni-1 ; jend=jbegin+nj-1
71
72  ALLOCATE(lon(ni,nj),lat(ni,nj),lonvalue(ni,nj))
73  lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1)
74  lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1)
75
76  DO i=1,llm
77    lval(i)=i
78  ENDDO
79
80!###########################################################################
81! Contexte ATM
82!###########################################################################
83  ALLOCATE(field_atm_2D(0:ni+1,-1:nj+2),field_atm_3D(0:ni+1,-1:nj+2,llm))
84  field_atm_2D(1:ni,1:nj)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1)
85  field_atm_3D(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
86
87  CALL xios_context_initialize("atmosphere",comm)
88  CALL xios_get_handle("atmosphere",ctx_hdl)
89  CALL xios_set_current_context(ctx_hdl)
90
91  CALL xios_set_axis_attr("axis_atm",n_glo=llm ,value=lval) ;
92
93  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')
94  CALL xios_set_domain_attr("domain_atm",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
95  CALL xios_set_domain_attr("domain_atm",lonvalue_2D=lon,latvalue_2D=lat)
96
97
98!!! Definition du timestep
99
100  dtime%second=model_timestep
101  CALL xios_set_timestep(timestep=dtime)
102
103!!! Fin de la definition du contexte
104
105  CALL xios_close_context_definition()
106
107
108!###########################################################################
109! Contexte SRF
110!###########################################################################
111
112!!! Initialisation des coordonnées globales et locales pour la grille indexee (1 point sur 2)
113
114    nb_pt=ni*nj/2
115    ALLOCATE(kindex(nb_pt),field_srf_2D(nb_pt),field_srf_3D(nb_pt,llm))
116    DO i=1,nb_pt
117      kindex(i)=2*i-1
118    ENDDO
119    field_srf_2D(1:nb_pt)=RESHAPE(field_A_glo(ibegin+1:iend+1:2,jbegin+1:jend+1,1),(/ nb_pt /))
120    field_srf_3D(1:nb_pt,:)=RESHAPE(field_A_glo(ibegin+1:iend+1:2,jbegin+1:jend+1,:),(/ nb_pt,llm /))
121
122  CALL xios_context_initialize("surface",comm)
123  CALL xios_get_handle("surface",ctx_hdl)
124  CALL xios_set_current_context(ctx_hdl)
125
126  CALL xios_set_axis_attr("axis_srf",n_glo=llm ,value=lval)
127  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')
128  CALL xios_set_domain_attr("domain_srf",data_dim=1, data_ibegin=0, data_ni=nb_pt)
129  CALL xios_set_domain_attr("domain_srf",data_i_index=kindex)
130  CALL xios_set_domain_attr("domain_srf",lonvalue_2D=lon,latvalue_2D=lat)
131
132!!! Definition du timestep
133
134  dtime%second=model_timestep
135  CALL xios_set_timestep(timestep=dtime)
136
137!!! Fin de la definition du contexte SRF
138
139  CALL xios_close_context_definition()
140
141!###########################################################################
142! Contexte OCE
143!###########################################################################
144  ALLOCATE(field_oce_2D(0:ni+1,-1:nj+2),field_oce_3D(0:ni+1,-1:nj+2,llm))
145  field_oce_2D(1:ni,1:nj)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1)
146  field_oce_3D(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
147
148  CALL xios_context_initialize("nemo",comm)
149  CALL xios_get_handle("nemo",ctx_hdl)
150  CALL xios_set_current_context(ctx_hdl)
151
152  CALL xios_set_axis_attr("axis_oce",n_glo=llm ,value=lval) ;
153
154  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')
155  CALL xios_set_domain_attr("domain_oce",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
156  CALL xios_set_domain_attr("domain_oce",lonvalue_2D=lon,latvalue_2D=lat)
157
158
159!!! Definition du timestep
160
161  dtime%second=model_timestep
162  CALL xios_set_timestep(timestep=dtime)
163
164  CALL xios_close_context_definition()
165
166!####################################################################################
167!!! Boucle temporelle
168!####################################################################################
169    DO ts=1,86400/model_timestep*nb_days_run
170
171      CALL xios_get_handle("atmosphere",ctx_hdl)
172      CALL xios_set_current_context(ctx_hdl)
173
174!!! Mise a jour du pas de temps
175
176      CALL xios_update_calendar(ts)
177
178!!! On donne la valeur du champ atm
179
180      CALL xios_send_field("field_atm_2D",field_atm_2D)
181      CALL xios_send_field("field_atm_3D",field_atm_3D)
182     
183!!! On change de contexte
184
185      CALL xios_get_handle("surface",ctx_hdl)
186      CALL xios_set_current_context(ctx_hdl)
187
188!!! Mise a jour du pas de temps
189
190      CALL xios_update_calendar(ts)
191
192!!! On donne la valeur du champ srf
193
194      CALL xios_send_field("field_srf_2D",field_srf_2D)
195      CALL xios_send_field("field_srf_3D",field_srf_3D)
196
197!!! On change de contexte
198
199      CALL xios_get_handle("nemo",ctx_hdl)
200      CALL xios_set_current_context(ctx_hdl)
201
202!!! Mise a jour du pas de temps
203
204      CALL xios_update_calendar(ts)
205
206!!! On donne la valeur du champ srf
207
208      CALL xios_send_field("field_oce_grid_2D",field_oce_2D)
209      CALL xios_send_field("field_oce_grid_3D",field_oce_3D)
210
211      CALL wait_us(5000) ;
212    ENDDO
213
214!####################################################################################
215!!! Finalisation
216!####################################################################################
217
218!!! Fin des contextes
219
220    CALL xios_context_finalize()
221    CALL xios_get_handle("atmosphere",ctx_hdl)
222    CALL xios_set_current_context(ctx_hdl)
223    CALL xios_context_finalize()
224    CALL xios_get_handle("surface",ctx_hdl)
225    CALL xios_set_current_context(ctx_hdl)
226    CALL xios_context_finalize()
227
228    DEALLOCATE(lon, lat, lonvalue, field_atm_2D, field_atm_3D)
229    DEALLOCATE(kindex, field_srf_2D, field_srf_3D)
230    DEALLOCATE(field_oce_2D, field_oce_3D)
231    DEALLOCATE(lon_glo,lat_glo,field_A_glo,lval)
232
233!!! Fin de XIOS
234
235    CALL MPI_COMM_FREE(comm, ierr)
236     
237    CALL xios_finalize()
238
239  CALL MPI_FINALIZE(ierr)
240
241END PROGRAM test_xios2_cmip6
242
243
244
245
246
247
Note: See TracBrowser for help on using the repository browser.