1 | PROGRAM test_unstruct_complete |
---|
2 | |
---|
3 | USE xios |
---|
4 | USE mod_wait |
---|
5 | IMPLICIT NONE |
---|
6 | INCLUDE "mpif.h" |
---|
7 | INTEGER :: mpi_rank |
---|
8 | INTEGER :: mpi_size |
---|
9 | INTEGER :: ierr |
---|
10 | |
---|
11 | CHARACTER(len=*),PARAMETER :: id="client" |
---|
12 | INTEGER :: comm |
---|
13 | TYPE(xios_duration) :: dtime |
---|
14 | TYPE(xios_context) :: ctx_hdl |
---|
15 | INTEGER, PARAMETER :: nlon=60 |
---|
16 | INTEGER, PARAMETER :: nlat=30 |
---|
17 | INTEGER,PARAMETER :: ni_glo=100 |
---|
18 | INTEGER,PARAMETER :: nj_glo=100 |
---|
19 | INTEGER,PARAMETER :: llm=5 |
---|
20 | DOUBLE PRECISION :: lval(llm)=1 |
---|
21 | TYPE(xios_field) :: field_hdl |
---|
22 | TYPE(xios_fieldgroup) :: fieldgroup_hdl |
---|
23 | TYPE(xios_file) :: file_hdl |
---|
24 | LOGICAL :: ok |
---|
25 | |
---|
26 | DOUBLE PRECISION,ALLOCATABLE :: lon_glo(:),lat_glo(:) |
---|
27 | DOUBLE PRECISION,ALLOCATABLE :: bounds_lon_glo(:,:),bounds_lat_glo(:,:) |
---|
28 | DOUBLE PRECISION,ALLOCATABLE :: field_A_glo(:,:) |
---|
29 | INTEGER,ALLOCATABLE :: i_index_glo(:) |
---|
30 | INTEGER,ALLOCATABLE :: i_index(:) |
---|
31 | LOGICAL,ALLOCATABLE :: mask_glo(:),mask(:) |
---|
32 | DOUBLE PRECISION,ALLOCATABLE :: lon(:),lat(:),field_A_srf(:,:), lonvalue(:) ; |
---|
33 | DOUBLE PRECISION,ALLOCATABLE :: bounds_lon(:,:),bounds_lat(:,:) ; |
---|
34 | INTEGER :: ni,ibegin,iend,nj,jbegin,jend |
---|
35 | INTEGER :: i,j,l,ts,n |
---|
36 | INTEGER :: ncell_glo,ncell,ind |
---|
37 | REAL :: ilon,ilat |
---|
38 | DOUBLE PRECISION, PARAMETER :: Pi=3.14159265359 |
---|
39 | INTEGER :: list_ind(nlon,nlat) |
---|
40 | INTEGER :: rank,j1,j2,np,ncell_x |
---|
41 | INTEGER :: data_n_index |
---|
42 | INTEGER,ALLOCATABLE :: data_i_index(:) |
---|
43 | DOUBLE PRECISION,ALLOCATABLE :: field_A_compressed(:,:) |
---|
44 | |
---|
45 | CALL xios_initialize(id,return_comm=comm) |
---|
46 | CALL MPI_COMM_RANK(comm,mpi_rank,ierr) |
---|
47 | CALL MPI_COMM_SIZE(comm,mpi_size,ierr) |
---|
48 | |
---|
49 | CALL init_wait |
---|
50 | |
---|
51 | ncell_glo=0 |
---|
52 | DO j=1,nlat |
---|
53 | n = NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon) |
---|
54 | IF (n<8) n=8 |
---|
55 | ncell_glo=ncell_glo+n |
---|
56 | ENDDO |
---|
57 | |
---|
58 | ALLOCATE(lon_glo(ncell_glo)) |
---|
59 | ALLOCATE(lat_glo(ncell_glo)) |
---|
60 | ALLOCATE(bounds_lon_glo(4,ncell_glo)) |
---|
61 | ALLOCATE(bounds_lat_glo(4,ncell_glo)) |
---|
62 | ALLOCATE(i_index_glo(ncell_glo)) |
---|
63 | ALLOCATE(field_A_glo(ncell_glo,llm)) |
---|
64 | ALLOCATE(mask_glo(ncell_glo)) |
---|
65 | |
---|
66 | ind=0 |
---|
67 | DO j=1,nlat |
---|
68 | n = NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon) |
---|
69 | if (j==1) PRINT*,"--- ",n |
---|
70 | if (j==nlat) PRINT*,"--- ",n |
---|
71 | IF (n<8) n=8 |
---|
72 | |
---|
73 | DO i=1,n |
---|
74 | ind=ind+1 |
---|
75 | list_ind(i,j)=ind |
---|
76 | ilon=i-0.5 |
---|
77 | ilat=j-0.5 |
---|
78 | |
---|
79 | lat_glo(ind)= 90-(ilat*180./nlat) |
---|
80 | lon_glo(ind)= (ilon*360./n) |
---|
81 | |
---|
82 | |
---|
83 | bounds_lat_glo(1,ind)= 90-((ilat-0.5)*180./nlat) |
---|
84 | bounds_lon_glo(1,ind)=((ilon-0.5)*360./n) |
---|
85 | |
---|
86 | bounds_lat_glo(2,ind)= 90-((ilat-0.5)*180./nlat) |
---|
87 | bounds_lon_glo(2,ind)=((ilon+0.5)*360./n) |
---|
88 | |
---|
89 | bounds_lat_glo(3,ind)= 90-((ilat+0.5)*180./nlat) |
---|
90 | bounds_lon_glo(3,ind)=((ilon+0.5)*360./n) |
---|
91 | |
---|
92 | bounds_lat_glo(4,ind)= 90-((ilat+0.5)*180./nlat) |
---|
93 | bounds_lon_glo(4,ind)=((ilon-0.5)*360./n) |
---|
94 | |
---|
95 | ENDDO |
---|
96 | ENDDO |
---|
97 | |
---|
98 | ! mpi_size=32 |
---|
99 | rank=(mpi_size-1)/2 |
---|
100 | ncell_x=sqrt(ncell_glo*1./mpi_size) |
---|
101 | |
---|
102 | j1=nlat/2 |
---|
103 | DO WHILE(rank>=0) |
---|
104 | j2=MAX(j1-ncell_x+1,1) |
---|
105 | j=(j1+j2)/2 |
---|
106 | n=NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon) |
---|
107 | np = MIN(n/ncell_x,rank+1) ; |
---|
108 | if (j2==1) np=rank+1 |
---|
109 | |
---|
110 | PRINT *,"domain ",j2,j1,rank,np ; |
---|
111 | DO j=j2,j1 |
---|
112 | n=NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon) |
---|
113 | IF (n<8) n=8 |
---|
114 | DO i=1,n |
---|
115 | ind=list_ind(i,j) |
---|
116 | IF ( (i-1) < MOD(n,np)*(n/np+1)) THEN |
---|
117 | i_index_glo(ind) = rank - (i-1)/(n/np+1) |
---|
118 | ELSE |
---|
119 | i_index_glo(ind) = rank-(MOD(n,np)+ (i-1-MOD(n,np)*(n/np+1))/(n/np)) |
---|
120 | ENDIF |
---|
121 | ENDDO |
---|
122 | ENDDO |
---|
123 | rank=rank-np |
---|
124 | j1=j2-1 |
---|
125 | ENDDO |
---|
126 | |
---|
127 | rank=(mpi_size-1)/2+1 |
---|
128 | ncell_x=sqrt(ncell_glo*1./mpi_size) |
---|
129 | |
---|
130 | j1=nlat/2+1 |
---|
131 | DO WHILE(rank<=mpi_size-1) |
---|
132 | j2=MIN(j1+ncell_x-1,nlat) |
---|
133 | j=(j1+j2)/2 |
---|
134 | n=NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon) |
---|
135 | np = MIN(n/ncell_x,mpi_size-rank) ; |
---|
136 | if (j2==nlat) np=mpi_size-rank |
---|
137 | |
---|
138 | PRINT *,"domain ",j2,j1,rank,np ; |
---|
139 | DO j=j1,j2 |
---|
140 | n=NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon) |
---|
141 | IF (n<8) n=8 |
---|
142 | DO i=1,n |
---|
143 | ind=list_ind(i,j) |
---|
144 | IF ( (i-1) < MOD(n,np)*(n/np+1)) THEN |
---|
145 | i_index_glo(ind) = rank + (i-1)/(n/np+1) |
---|
146 | ELSE |
---|
147 | i_index_glo(ind) = rank+(MOD(n,np)+ (i-1-MOD(n,np)*(n/np+1))/(n/np)) |
---|
148 | ENDIF |
---|
149 | ENDDO |
---|
150 | ENDDO |
---|
151 | rank=rank+np |
---|
152 | j1=j2+1 |
---|
153 | ENDDO |
---|
154 | |
---|
155 | ncell=0 |
---|
156 | DO ind=1,ncell_glo |
---|
157 | IF (i_index_glo(ind)==mpi_rank) ncell=ncell+1 |
---|
158 | ENDDO |
---|
159 | ALLOCATE(i_index(ncell)) |
---|
160 | ALLOCATE(lon(ncell)) |
---|
161 | ALLOCATE(lat(ncell)) |
---|
162 | ALLOCATE(bounds_lon(4,ncell)) |
---|
163 | ALLOCATE(bounds_lat(4,ncell)) |
---|
164 | ALLOCATE(field_A_srf(ncell,llm)) |
---|
165 | ALLOCATE(mask(ncell)) |
---|
166 | ncell=0 |
---|
167 | data_n_index=0 |
---|
168 | DO ind=1,ncell_glo |
---|
169 | IF (i_index_glo(ind)==mpi_rank) THEN |
---|
170 | ncell=ncell+1 |
---|
171 | i_index(ncell)=ind-1 |
---|
172 | lon(ncell)=lon_glo(ind) |
---|
173 | lat(ncell)=lat_glo(ind) |
---|
174 | bounds_lon(:,ncell)=bounds_lon_glo(:,ind) |
---|
175 | bounds_lat(:,ncell)=bounds_lat_glo(:,ind) |
---|
176 | field_A_srf(ncell,:)=i_index_glo(ind) |
---|
177 | IF (MOD(ind,8)>=0 .AND. MOD(ind,8)<2) THEN |
---|
178 | mask(ncell)=.FALSE. |
---|
179 | ELSE |
---|
180 | mask(ncell)=.TRUE. |
---|
181 | data_n_index=data_n_index+1 |
---|
182 | ENDIF |
---|
183 | ENDIF |
---|
184 | ENDDO |
---|
185 | |
---|
186 | ALLOCATE(field_A_compressed(data_n_index,llm)) |
---|
187 | ALLOCATE(data_i_index(data_n_index)) |
---|
188 | data_n_index=0 |
---|
189 | DO ind=1,ncell |
---|
190 | IF (mask(ind)) THEN |
---|
191 | data_n_index=data_n_index+1 |
---|
192 | data_i_index(data_n_index)=ind |
---|
193 | field_A_compressed(data_n_index,:)=field_A_srf(ind,:) |
---|
194 | ENDIF |
---|
195 | ENDDO |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | CALL xios_context_initialize("surface",comm) |
---|
200 | CALL xios_get_handle("surface",ctx_hdl) |
---|
201 | CALL xios_set_current_context(ctx_hdl) |
---|
202 | |
---|
203 | CALL xios_set_axis_attr("axis_srf",size=llm ,value=lval) ; |
---|
204 | CALL xios_set_domain_attr("domain_srf",ni_glo=ncell_glo, ni=ncell, ibegin=1, i_index=RESHAPE(i_index,(/ncell,1/) )) |
---|
205 | CALL xios_set_domain_attr("domain_srf",data_dim=1, data_ni=data_n_index, data_n_index=data_n_index, data_i_index=data_i_index, type='unstructured') |
---|
206 | CALL xios_set_domain_attr("domain_srf",lonvalue=lon,latvalue=lat) |
---|
207 | CALL xios_set_domain_attr("domain_srf", nvertex=4, bounds_lon=bounds_lon, bounds_lat=bounds_lat ) |
---|
208 | |
---|
209 | |
---|
210 | dtime%second=3600 |
---|
211 | CALL xios_set_context_attr("surface", timestep=dtime) |
---|
212 | CALL xios_close_context_definition() |
---|
213 | |
---|
214 | DO ts=1,24*10 |
---|
215 | CALL xios_update_calendar(ts) |
---|
216 | CALL xios_send_field("field_A_srf",field_A_compressed) |
---|
217 | ENDDO |
---|
218 | |
---|
219 | CALL xios_context_finalize() |
---|
220 | CALL xios_finalize() |
---|
221 | |
---|
222 | END PROGRAM test_unstruct_complete |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | |
---|