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

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

Two server levels: merging with trunk r1137.
There are bugs.

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