1 | PROGRAM test_remap |
---|
2 | |
---|
3 | USE xios |
---|
4 | USE mod_wait |
---|
5 | USE netcdf |
---|
6 | |
---|
7 | IMPLICIT NONE |
---|
8 | INCLUDE "mpif.h" |
---|
9 | INTEGER :: rank |
---|
10 | INTEGER :: size |
---|
11 | INTEGER :: ierr |
---|
12 | |
---|
13 | CHARACTER(len=*),PARAMETER :: id="client" |
---|
14 | INTEGER :: comm |
---|
15 | TYPE(xios_duration) :: dtime |
---|
16 | TYPE(xios_context) :: ctx_hdl |
---|
17 | |
---|
18 | DOUBLE PRECISION,ALLOCATABLE :: src_lon(:), dst_lon(:) |
---|
19 | DOUBLE PRECISION,ALLOCATABLE :: src_lat(:), dst_lat(:) |
---|
20 | DOUBLE PRECISION,ALLOCATABLE :: src_boundslon(:,:), dst_boundslon(:,:) |
---|
21 | DOUBLE PRECISION,ALLOCATABLE :: src_boundslat(:,:), dst_boundslat(:,:) |
---|
22 | DOUBLE PRECISION,ALLOCATABLE :: src_field_2D(:) |
---|
23 | DOUBLE PRECISION,ALLOCATABLE :: tmp_field_0(:), tmp_field_1(:), tmp_field_2(:) |
---|
24 | DOUBLE PRECISION,ALLOCATABLE :: src_field_3D(:,:), src_field_4D(:,:,:), lval(:), lval1(:), lval2(:), src_field_pression(:,:) |
---|
25 | LOGICAL,ALLOCATABLE :: src_mask_2D(:) |
---|
26 | INTEGER :: src_ni_glo, dst_ni_glo; |
---|
27 | INTEGER :: src_nvertex, dst_nvertex; |
---|
28 | INTEGER :: src_ibegin, dst_ibegin; |
---|
29 | INTEGER :: src_ni, dst_ni; |
---|
30 | INTEGER :: src_tmp_ni, src_tmp_nj, src_tmp_n; |
---|
31 | CHARACTER(LEN=*),PARAMETER :: src_file="h14.nc" |
---|
32 | CHARACTER(LEN=*),PARAMETER :: dst_file="r180x90.nc" |
---|
33 | INTEGER :: ncid |
---|
34 | INTEGER :: dimids(2) |
---|
35 | INTEGER :: div,remain |
---|
36 | INTEGER :: varid |
---|
37 | INTEGER :: ts |
---|
38 | INTEGER :: i |
---|
39 | INTEGER,PARAMETER :: llm=5, interpolatedLlm = 4, llm2 = 6 |
---|
40 | |
---|
41 | CALL MPI_INIT(ierr) |
---|
42 | CALL init_wait |
---|
43 | |
---|
44 | !!! XIOS Initialization (get the local communicator) |
---|
45 | |
---|
46 | CALL xios_initialize(id,return_comm=comm) |
---|
47 | CALL MPI_COMM_RANK(comm,rank,ierr) |
---|
48 | CALL MPI_COMM_SIZE(comm,size,ierr) |
---|
49 | |
---|
50 | ierr=NF90_OPEN(src_file, NF90_NOWRITE, ncid) |
---|
51 | ierr=NF90_INQ_VARID(ncid,"bounds_lon",varid) |
---|
52 | ierr=NF90_INQUIRE_VARIABLE(ncid, varid,dimids=dimids) |
---|
53 | ierr=NF90_INQUIRE_DIMENSION(ncid, dimids(1), len=src_nvertex) |
---|
54 | ierr=NF90_INQUIRE_DIMENSION(ncid, dimids(2), len=src_ni_glo) |
---|
55 | |
---|
56 | div = src_ni_glo/size |
---|
57 | remain = MOD( src_ni_glo, size ) |
---|
58 | IF (rank < remain) THEN |
---|
59 | src_ni=div+1 ; |
---|
60 | src_ibegin=rank*(div+1) ; |
---|
61 | ELSE |
---|
62 | src_ni=div ; |
---|
63 | src_ibegin= remain * (div+1) + (rank-remain) * div ; |
---|
64 | ENDIF |
---|
65 | |
---|
66 | ALLOCATE(src_lon(src_ni)) |
---|
67 | ALLOCATE(src_lat(src_ni)) |
---|
68 | ALLOCATE(src_boundslon(src_nvertex,src_ni)) |
---|
69 | ALLOCATE(src_boundslat(src_nvertex,src_ni)) |
---|
70 | ALLOCATE(src_field_2D(src_ni)) |
---|
71 | ALLOCATE(src_field_3D(src_ni,llm)) |
---|
72 | ALLOCATE(src_field_4D(src_ni,llm,llm2)) |
---|
73 | ALLOCATE(src_mask_2D(src_ni)) |
---|
74 | ALLOCATE(src_field_pression(src_ni,llm)) |
---|
75 | ALLOCATE(lval(llm)) |
---|
76 | ALLOCATE(lval1(interpolatedLlm)) |
---|
77 | ALLOCATE(lval2(llm2)) |
---|
78 | |
---|
79 | ierr=NF90_INQ_VARID(ncid,"lon",varid) |
---|
80 | ierr=NF90_GET_VAR(ncid,varid, src_lon, start=(/src_ibegin+1/),count=(/src_ni/)) |
---|
81 | ierr=NF90_INQ_VARID(ncid,"lat",varid) |
---|
82 | ierr=NF90_GET_VAR(ncid,varid, src_lat, start=(/src_ibegin+1/),count=(/src_ni/)) |
---|
83 | ierr=NF90_INQ_VARID(ncid,"bounds_lon",varid) |
---|
84 | ierr=NF90_GET_VAR(ncid,varid,src_boundslon, start=(/1,src_ibegin+1/),count=(/src_nvertex,src_ni/)) |
---|
85 | ierr=NF90_INQ_VARID(ncid,"bounds_lat",varid) |
---|
86 | ierr=NF90_GET_VAR(ncid,varid, src_boundslat, start=(/1,src_ibegin+1/),count=(/src_nvertex,src_ni/)) |
---|
87 | ierr=NF90_INQ_VARID(ncid,"val",varid) |
---|
88 | ierr=NF90_GET_VAR(ncid,varid, src_field_2D, start=(/src_ibegin+1/),count=(/src_ni/)) |
---|
89 | DO i=1,src_ni |
---|
90 | src_field_3D(i,:) = src_field_2D(i) |
---|
91 | IF (MOD(i,10)==0) THEN |
---|
92 | src_mask_2D(i)=.FALSE. |
---|
93 | ELSE |
---|
94 | src_mask_2D(i)=.TRUE. |
---|
95 | ENDIF |
---|
96 | ENDDO |
---|
97 | |
---|
98 | DO i=1,llm |
---|
99 | lval(i) = i*100 |
---|
100 | src_field_pression(:,i) = i * 100 |
---|
101 | src_field_3D(:,i) = src_field_3D(:,i) + i * 10 |
---|
102 | ENDDO |
---|
103 | |
---|
104 | DO i=1,llm2 |
---|
105 | src_field_4D(:,:,i) = src_field_3D(:,:) |
---|
106 | ENDDO |
---|
107 | |
---|
108 | DO i=1,interpolatedLlm |
---|
109 | lval2(i) = i*10 |
---|
110 | lval1(i) = i*10 + 2 |
---|
111 | ENDDO |
---|
112 | |
---|
113 | ierr=NF90_OPEN(dst_file, NF90_NOWRITE, ncid) |
---|
114 | ierr=NF90_INQ_VARID(ncid,"bounds_lon",varid) |
---|
115 | ierr=NF90_INQUIRE_VARIABLE(ncid, varid,dimids=dimids) |
---|
116 | ierr=NF90_INQUIRE_DIMENSION(ncid, dimids(1), len=dst_nvertex) |
---|
117 | ierr=NF90_INQUIRE_DIMENSION(ncid, dimids(2), len=dst_ni_glo) |
---|
118 | |
---|
119 | div = dst_ni_glo/size |
---|
120 | remain = MOD( dst_ni_glo, size ) |
---|
121 | IF (rank < remain) THEN |
---|
122 | dst_ni=div+1 ; |
---|
123 | dst_ibegin=rank*(div+1) ; |
---|
124 | ELSE |
---|
125 | dst_ni=div ; |
---|
126 | dst_ibegin= remain * (div+1) + (rank-remain) * div ; |
---|
127 | ENDIF |
---|
128 | |
---|
129 | ALLOCATE(dst_lon(dst_ni)) |
---|
130 | ALLOCATE(dst_lat(dst_ni)) |
---|
131 | ALLOCATE(dst_boundslon(dst_nvertex,dst_ni)) |
---|
132 | ALLOCATE(dst_boundslat(dst_nvertex,dst_ni)) |
---|
133 | |
---|
134 | ierr=NF90_INQ_VARID(ncid,"lon",varid) |
---|
135 | ierr=NF90_GET_VAR(ncid,varid, dst_lon, start=(/dst_ibegin+1/),count=(/dst_ni/)) |
---|
136 | ierr=NF90_INQ_VARID(ncid,"lat",varid) |
---|
137 | ierr=NF90_GET_VAR(ncid,varid, dst_lat, start=(/dst_ibegin+1/),count=(/dst_ni/)) |
---|
138 | ierr=NF90_INQ_VARID(ncid,"bounds_lon",varid) |
---|
139 | ierr=NF90_GET_VAR(ncid,varid,dst_boundslon, start=(/1,dst_ibegin+1/),count=(/dst_nvertex,dst_ni/)) |
---|
140 | ierr=NF90_INQ_VARID(ncid,"bounds_lat",varid) |
---|
141 | ierr=NF90_GET_VAR(ncid,varid, dst_boundslat, start=(/1,dst_ibegin+1/),count=(/dst_nvertex,dst_ni/)) |
---|
142 | |
---|
143 | |
---|
144 | CALL xios_context_initialize("test",comm) |
---|
145 | CALL xios_get_handle("test",ctx_hdl) |
---|
146 | CALL xios_set_current_context(ctx_hdl) |
---|
147 | |
---|
148 | CALL xios_set_domain_attr("src_domain", ni_glo=src_ni_glo, ibegin=src_ibegin, ni=src_ni, type="unstructured") |
---|
149 | CALL xios_set_domain_attr("src_domain", lonvalue_1D=src_lon, latvalue_1D=src_lat, & |
---|
150 | bounds_lon_1D=src_boundslon, bounds_lat_1D=src_boundslat, nvertex=src_nvertex) |
---|
151 | |
---|
152 | CALL xios_set_domain_attr("src_domain_clone", ni_glo=src_ni_glo, ibegin=src_ibegin, ni=src_ni, type="unstructured") |
---|
153 | CALL xios_set_domain_attr("src_domain_clone", lonvalue_1D=src_lon, latvalue_1D=src_lat, & |
---|
154 | bounds_lon_1D=src_boundslon, bounds_lat_1D=src_boundslat, nvertex=src_nvertex, & |
---|
155 | mask_1d=src_mask_2D) |
---|
156 | |
---|
157 | CALL xios_set_axis_attr("src_axis", n_glo=llm, value=lval) |
---|
158 | CALL xios_set_axis_attr("nq", n_glo=llm2, value=lval2) |
---|
159 | |
---|
160 | CALL xios_set_domain_attr("dst_domain", ni_glo=dst_ni_glo, ibegin=dst_ibegin, ni=dst_ni, type="unstructured") |
---|
161 | CALL xios_set_domain_attr("dst_domain", lonvalue_1D=dst_lon, latvalue_1D=dst_lat, & |
---|
162 | bounds_lon_1D=dst_boundslon, bounds_lat_1D=dst_boundslat, nvertex=dst_nvertex) |
---|
163 | |
---|
164 | dtime%second = 3600 |
---|
165 | CALL xios_set_timestep(dtime) |
---|
166 | |
---|
167 | CALL xios_close_context_definition() |
---|
168 | CALL xios_get_domain_attr("src_domain_regular_read", ni=src_tmp_ni, nj=src_tmp_nj) |
---|
169 | ALLOCATE(tmp_field_0(src_tmp_ni*src_tmp_nj)) |
---|
170 | |
---|
171 | ! CALL xios_get_axis_attr("src_axis_curvilinear_read", n=src_tmp_n) |
---|
172 | ! CALL xios_get_domain_attr("src_domain_curvilinear_read", ni=src_tmp_ni, nj=src_tmp_nj) |
---|
173 | ! ALLOCATE(tmp_field_1(src_tmp_ni*src_tmp_nj*src_tmp_n)) |
---|
174 | |
---|
175 | ! CALL xios_get_domain_attr("src_domain_unstructured_read", ni=src_tmp_ni, nj=src_tmp_nj) |
---|
176 | ! ALLOCATE(tmp_field_2(src_tmp_ni*src_tmp_nj)) |
---|
177 | |
---|
178 | DO ts=1,1 |
---|
179 | CALL xios_recv_field("src_field_regular", tmp_field_0) |
---|
180 | ! CALL xios_recv_field("src_field_curvilinear", tmp_field_1) |
---|
181 | ! CALL xios_recv_field("src_field_unstructured", tmp_field_2) |
---|
182 | CALL xios_update_calendar(ts) |
---|
183 | CALL xios_send_field("src_field_2D",src_field_2D) |
---|
184 | CALL xios_send_field("src_field_2D_clone",src_field_2D) |
---|
185 | CALL xios_send_field("src_field_3D",src_field_3D) |
---|
186 | ! CALL xios_send_field("src_field_4D",src_field_4D) |
---|
187 | ! CALL xios_send_field("src_field_3D_pression",src_field_pression) |
---|
188 | CALL xios_send_field("tmp_field_0",tmp_field_0) |
---|
189 | ! CALL xios_send_field("tmp_field_1",tmp_field_1) |
---|
190 | ! CALL xios_send_field("tmp_field_2",tmp_field_2) |
---|
191 | CALL wait_us(5000) ; |
---|
192 | ENDDO |
---|
193 | |
---|
194 | CALL xios_context_finalize() |
---|
195 | |
---|
196 | DEALLOCATE(src_lon, src_lat, src_boundslon,src_boundslat, src_field_2D) |
---|
197 | DEALLOCATE(dst_lon, dst_lat, dst_boundslon,dst_boundslat) |
---|
198 | ! DEALLOCATE(tmp_field_0, tmp_field_1, tmp_field_2) |
---|
199 | |
---|
200 | CALL MPI_COMM_FREE(comm, ierr) |
---|
201 | |
---|
202 | CALL xios_finalize() |
---|
203 | |
---|
204 | CALL MPI_FINALIZE(ierr) |
---|
205 | |
---|
206 | END PROGRAM test_remap |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | |
---|
211 | |
---|