1 | MODULE iom |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE iom *** |
---|
4 | !! Input/Output manager : Library to read input files |
---|
5 | !!====================================================================== |
---|
6 | !! History : 2.0 ! 2005-12 (J. Belier) Original code |
---|
7 | !! 2.0 ! 2006-02 (S. Masson) Adaptation to NEMO |
---|
8 | !! 3.0 ! 2007-07 (D. Storkey) Changes to iom_gettime |
---|
9 | !! 3.4 ! 2012-12 (R. Bourdalle-Badie and G. Reffray) add C1D case |
---|
10 | !! 3.6 ! 2014-15 DIMG format removed |
---|
11 | !! 3.6 ! 2015-15 (J. Harle) Added procedure to read REAL attributes |
---|
12 | !! 4.0 ! 2017-11 (M. Andrejczuk) Extend IOM interface to write any 3D fields |
---|
13 | !!---------------------------------------------------------------------- |
---|
14 | |
---|
15 | !!---------------------------------------------------------------------- |
---|
16 | !! iom_open : open a file read only |
---|
17 | !! iom_close : close a file or all files opened by iom |
---|
18 | !! iom_get : read a field (interfaced to several routines) |
---|
19 | !! iom_varid : get the id of a variable in a file |
---|
20 | !! iom_rstput : write a field in a restart file (interfaced to several routines) |
---|
21 | !!---------------------------------------------------------------------- |
---|
22 | USE dom_oce ! ocean space and time domain |
---|
23 | USE c1d ! 1D vertical configuration |
---|
24 | USE flo_oce ! floats module declarations |
---|
25 | USE lbclnk ! lateal boundary condition / mpp exchanges |
---|
26 | USE iom_def ! iom variables definitions |
---|
27 | USE iom_nf90 ! NetCDF format with native NetCDF library |
---|
28 | USE in_out_manager ! I/O manager |
---|
29 | USE lib_mpp ! MPP library |
---|
30 | #if defined key_iomput |
---|
31 | USE sbc_oce , ONLY : nn_fsbc, ght_abl, ghw_abl, e3t_abl, e3w_abl, jpka, jpkam1 |
---|
32 | USE icb_oce , ONLY : nclasses, class_num ! !: iceberg classes |
---|
33 | #if defined key_si3 |
---|
34 | USE ice , ONLY : jpl |
---|
35 | #endif |
---|
36 | USE domngb ! ocean space and time domain |
---|
37 | USE phycst ! physical constants |
---|
38 | USE dianam ! build name of file |
---|
39 | USE xios |
---|
40 | # endif |
---|
41 | USE ioipsl, ONLY : ju2ymds ! for calendar |
---|
42 | USE crs ! Grid coarsening |
---|
43 | #if defined key_top |
---|
44 | USE trc, ONLY : profsed |
---|
45 | #endif |
---|
46 | USE lib_fortran |
---|
47 | USE diu_bulk, ONLY : ln_diurnal_only, ln_diurnal |
---|
48 | USE iom_nf90 |
---|
49 | USE netcdf |
---|
50 | |
---|
51 | IMPLICIT NONE |
---|
52 | PUBLIC ! must be public to be able to access iom_def through iom |
---|
53 | |
---|
54 | #if defined key_iomput |
---|
55 | LOGICAL, PUBLIC, PARAMETER :: lk_iomput = .TRUE. !: iom_put flag |
---|
56 | #else |
---|
57 | LOGICAL, PUBLIC, PARAMETER :: lk_iomput = .FALSE. !: iom_put flag |
---|
58 | #endif |
---|
59 | PUBLIC iom_init, iom_init_closedef, iom_swap, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_get_var |
---|
60 | PUBLIC iom_chkatt, iom_getatt, iom_putatt, iom_getszuld, iom_rstput, iom_delay_rst, iom_put |
---|
61 | PUBLIC iom_use, iom_context_finalize, iom_update_file_name, iom_miss_val |
---|
62 | |
---|
63 | PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d |
---|
64 | PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d |
---|
65 | PRIVATE iom_p1d, iom_p2d, iom_p3d, iom_p4d |
---|
66 | #if defined key_iomput |
---|
67 | PRIVATE iom_set_domain_attr, iom_set_axis_attr, iom_set_field_attr, iom_set_file_attr, iom_get_file_attr, iom_set_grid_attr |
---|
68 | PRIVATE set_grid, set_grid_bounds, set_scalar, set_xmlatt, set_mooring, iom_sdate |
---|
69 | PRIVATE iom_set_rst_context, iom_set_rstr_active |
---|
70 | # endif |
---|
71 | PRIVATE iom_set_rstw_active |
---|
72 | |
---|
73 | INTERFACE iom_get |
---|
74 | MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d |
---|
75 | END INTERFACE |
---|
76 | INTERFACE iom_getatt |
---|
77 | MODULE PROCEDURE iom_g0d_iatt, iom_g1d_iatt, iom_g0d_ratt, iom_g1d_ratt, iom_g0d_catt |
---|
78 | END INTERFACE |
---|
79 | INTERFACE iom_putatt |
---|
80 | MODULE PROCEDURE iom_p0d_iatt, iom_p1d_iatt, iom_p0d_ratt, iom_p1d_ratt, iom_p0d_catt |
---|
81 | END INTERFACE |
---|
82 | INTERFACE iom_rstput |
---|
83 | MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d |
---|
84 | END INTERFACE |
---|
85 | INTERFACE iom_put |
---|
86 | MODULE PROCEDURE iom_p0d, iom_p1d, iom_p2d, iom_p3d, iom_p4d |
---|
87 | END INTERFACE iom_put |
---|
88 | |
---|
89 | !! * Substitutions |
---|
90 | # include "do_loop_substitute.h90" |
---|
91 | !!---------------------------------------------------------------------- |
---|
92 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
93 | !! $Id$ |
---|
94 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
95 | !!---------------------------------------------------------------------- |
---|
96 | CONTAINS |
---|
97 | |
---|
98 | SUBROUTINE iom_init( cdname, fname, idfp, ld_tmppatch, ld_closedef ) |
---|
99 | !!---------------------------------------------------------------------- |
---|
100 | !! *** ROUTINE *** |
---|
101 | !! |
---|
102 | !! ** Purpose : |
---|
103 | !! |
---|
104 | !!---------------------------------------------------------------------- |
---|
105 | CHARACTER(len=*), INTENT(in) :: cdname |
---|
106 | CHARACTER(len=*), OPTIONAL, INTENT(in) :: fname |
---|
107 | INTEGER , OPTIONAL, INTENT(in) :: idfp ! pointer to netcdf file for restart reading with XIOS |
---|
108 | LOGICAL , OPTIONAL, INTENT(in) :: ld_tmppatch |
---|
109 | LOGICAL , OPTIONAL, INTENT(in) :: ld_closedef |
---|
110 | #if defined key_iomput |
---|
111 | ! |
---|
112 | TYPE(xios_duration) :: dtime = xios_duration(0, 0, 0, 0, 0, 0) |
---|
113 | TYPE(xios_date) :: start_date |
---|
114 | CHARACTER(len=lc) :: clname |
---|
115 | INTEGER :: irefyear, irefmonth, irefday |
---|
116 | INTEGER :: ji |
---|
117 | LOGICAL :: llrst_context ! is context related to restart |
---|
118 | LOGICAL :: llrstr, llrstw |
---|
119 | INTEGER :: inum |
---|
120 | ! |
---|
121 | REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zt_bnds, zw_bnds |
---|
122 | REAL(wp), DIMENSION(2,jpkam1) :: za_bnds ! ABL vertical boundaries |
---|
123 | LOGICAL :: ll_tmppatch = .TRUE. !: seb: patch before we remove periodicity |
---|
124 | INTEGER :: nldi_save, nlei_save !: and close boundaries in output files |
---|
125 | INTEGER :: nldj_save, nlej_save !: |
---|
126 | LOGICAL :: ll_closedef |
---|
127 | !!---------------------------------------------------------------------- |
---|
128 | ! |
---|
129 | ! seb: patch before we remove periodicity and close boundaries in output files |
---|
130 | IF( PRESENT(ld_tmppatch) ) THEN ; ll_tmppatch = ld_tmppatch |
---|
131 | ELSE ; ll_tmppatch = .TRUE. |
---|
132 | ENDIF |
---|
133 | IF ( ll_tmppatch ) THEN |
---|
134 | nldi_save = nldi ; nlei_save = nlei |
---|
135 | nldj_save = nldj ; nlej_save = nlej |
---|
136 | IF( nimpp == 1 ) nldi = 1 |
---|
137 | IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi |
---|
138 | IF( njmpp == 1 ) nldj = 1 |
---|
139 | IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj |
---|
140 | ENDIF |
---|
141 | ! |
---|
142 | ll_closedef = .TRUE. |
---|
143 | IF ( PRESENT(ld_closedef) ) ll_closedef = ld_closedef |
---|
144 | ! |
---|
145 | ALLOCATE( zt_bnds(2,jpk), zw_bnds(2,jpk) ) |
---|
146 | ! |
---|
147 | IF(lwp) write(numout, *) 'TEST IOM_INIT: ', TRIM(cdname),' File: ', TRIM(fname) |
---|
148 | IF(lwp) CALL FLUSH(numout) |
---|
149 | clname = cdname |
---|
150 | IF( TRIM(Agrif_CFixed()) /= '0' ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(cdname) |
---|
151 | CALL xios_context_initialize(TRIM(clname), mpi_comm_oce) |
---|
152 | CALL iom_swap( cdname ) |
---|
153 | |
---|
154 | llrstr = (TRIM(cdname) == TRIM(crxios_context)) .OR. (TRIM(cdname) == TRIM(crixios_context)) |
---|
155 | llrstr = llrstr .OR. (TRIM(cdname) == TRIM(crtxios_context)) |
---|
156 | llrstr = llrstr .OR. (TRIM(cdname) == TRIM(crsxios_context)) |
---|
157 | |
---|
158 | llrstw = (TRIM(cdname) == TRIM(cwxios_context)) .OR. (TRIM(cdname) == TRIM(cwixios_context)) |
---|
159 | llrstw = llrstw .OR. (TRIM(cdname) == TRIM(cwtxios_context)) |
---|
160 | llrstw = llrstw .OR. (TRIM(cdname) == TRIM(cwsxios_context)) |
---|
161 | |
---|
162 | llrst_context = llrstr .OR. llrstw |
---|
163 | |
---|
164 | ! Calendar type is now defined in xml file |
---|
165 | IF (.NOT.(xios_getvar('ref_year' ,irefyear ))) irefyear = 1900 |
---|
166 | IF (.NOT.(xios_getvar('ref_month',irefmonth))) irefmonth = 01 |
---|
167 | IF (.NOT.(xios_getvar('ref_day' ,irefday ))) irefday = 01 |
---|
168 | |
---|
169 | SELECT CASE ( nleapy ) ! Choose calendar for IOIPSL |
---|
170 | CASE ( 1) ; CALL xios_define_calendar( TYPE = "Gregorian", time_origin = xios_date(irefyear,irefmonth,irefday,00,00,00), & |
---|
171 | & start_date = xios_date(nyear,nmonth,nday,0,0,0) ) |
---|
172 | CASE ( 0) ; CALL xios_define_calendar( TYPE = "NoLeap" , time_origin = xios_date(irefyear,irefmonth,irefday,00,00,00), & |
---|
173 | & start_date = xios_date(nyear,nmonth,nday,0,0,0) ) |
---|
174 | CASE (30) ; CALL xios_define_calendar( TYPE = "D360" , time_origin = xios_date(irefyear,irefmonth,irefday,00,00,00), & |
---|
175 | & start_date = xios_date(nyear,nmonth,nday,0,0,0) ) |
---|
176 | END SELECT |
---|
177 | |
---|
178 | ! horizontal grid definition |
---|
179 | IF(.NOT.llrst_context) CALL set_scalar |
---|
180 | ! |
---|
181 | IF( TRIM(cdname) == TRIM(cxios_context) ) THEN |
---|
182 | CALL set_grid( "T", glamt, gphit, .FALSE., .FALSE. ) |
---|
183 | CALL set_grid( "U", glamu, gphiu, .FALSE., .FALSE. ) |
---|
184 | CALL set_grid( "V", glamv, gphiv, .FALSE., .FALSE. ) |
---|
185 | CALL set_grid( "W", glamt, gphit, .FALSE., .FALSE. ) |
---|
186 | CALL set_grid_znl( gphit ) |
---|
187 | ! |
---|
188 | IF( ln_cfmeta ) THEN ! Add additional grid metadata |
---|
189 | CALL iom_set_domain_attr("grid_T", area = e1e2t(nldi:nlei, nldj:nlej)) |
---|
190 | CALL iom_set_domain_attr("grid_U", area = e1e2u(nldi:nlei, nldj:nlej)) |
---|
191 | CALL iom_set_domain_attr("grid_V", area = e1e2v(nldi:nlei, nldj:nlej)) |
---|
192 | CALL iom_set_domain_attr("grid_W", area = e1e2t(nldi:nlei, nldj:nlej)) |
---|
193 | CALL set_grid_bounds( "T", glamf, gphif, glamt, gphit ) |
---|
194 | CALL set_grid_bounds( "U", glamv, gphiv, glamu, gphiu ) |
---|
195 | CALL set_grid_bounds( "V", glamu, gphiu, glamv, gphiv ) |
---|
196 | CALL set_grid_bounds( "W", glamf, gphif, glamt, gphit ) |
---|
197 | ENDIF |
---|
198 | ENDIF |
---|
199 | ! |
---|
200 | IF( TRIM(cdname) == TRIM(cxios_context)//"_crs" ) THEN |
---|
201 | CALL dom_grid_crs ! Save the parent grid information & Switch to coarse grid domain |
---|
202 | ! |
---|
203 | CALL set_grid( "T", glamt_crs, gphit_crs, .FALSE., .FALSE. ) |
---|
204 | CALL set_grid( "U", glamu_crs, gphiu_crs, .FALSE., .FALSE. ) |
---|
205 | CALL set_grid( "V", glamv_crs, gphiv_crs, .FALSE., .FALSE. ) |
---|
206 | CALL set_grid( "W", glamt_crs, gphit_crs, .FALSE., .FALSE. ) |
---|
207 | CALL set_grid_znl( gphit_crs ) |
---|
208 | ! |
---|
209 | CALL dom_grid_glo ! Return to parent grid domain |
---|
210 | ! |
---|
211 | IF( ln_cfmeta .AND. .NOT. llrst_context) THEN ! Add additional grid metadata |
---|
212 | CALL iom_set_domain_attr("grid_T", area = e1e2t_crs(nldi:nlei, nldj:nlej)) |
---|
213 | CALL iom_set_domain_attr("grid_U", area = e1u_crs(nldi:nlei, nldj:nlej) * e2u_crs(nldi:nlei, nldj:nlej)) |
---|
214 | CALL iom_set_domain_attr("grid_V", area = e1v_crs(nldi:nlei, nldj:nlej) * e2v_crs(nldi:nlei, nldj:nlej)) |
---|
215 | CALL iom_set_domain_attr("grid_W", area = e1e2t_crs(nldi:nlei, nldj:nlej)) |
---|
216 | CALL set_grid_bounds( "T", glamf_crs, gphif_crs, glamt_crs, gphit_crs ) |
---|
217 | CALL set_grid_bounds( "U", glamv_crs, gphiv_crs, glamu_crs, gphiu_crs ) |
---|
218 | CALL set_grid_bounds( "V", glamu_crs, gphiu_crs, glamv_crs, gphiv_crs ) |
---|
219 | CALL set_grid_bounds( "W", glamf_crs, gphif_crs, glamt_crs, gphit_crs ) |
---|
220 | ENDIF |
---|
221 | ENDIF |
---|
222 | ! |
---|
223 | ! vertical grid definition |
---|
224 | IF(.NOT.llrst_context) THEN |
---|
225 | CALL iom_set_axis_attr( "deptht", paxis = gdept_1d ) |
---|
226 | CALL iom_set_axis_attr( "depthu", paxis = gdept_1d ) |
---|
227 | CALL iom_set_axis_attr( "depthv", paxis = gdept_1d ) |
---|
228 | CALL iom_set_axis_attr( "depthw", paxis = gdepw_1d ) |
---|
229 | |
---|
230 | ! ABL |
---|
231 | IF( .NOT. ALLOCATED(ght_abl) ) THEN ! force definition for xml files (xios) |
---|
232 | ALLOCATE( ght_abl(jpka), ghw_abl(jpka), e3t_abl(jpka), e3w_abl(jpka) ) ! default allocation needed by iom |
---|
233 | ght_abl(:) = -1._wp ; ghw_abl(:) = -1._wp |
---|
234 | e3t_abl(:) = -1._wp ; e3w_abl(:) = -1._wp |
---|
235 | ENDIF |
---|
236 | CALL iom_set_axis_attr( "ght_abl", ght_abl(2:jpka) ) |
---|
237 | CALL iom_set_axis_attr( "ghw_abl", ghw_abl(2:jpka) ) |
---|
238 | |
---|
239 | ! Add vertical grid bounds |
---|
240 | zt_bnds(2,: ) = gdept_1d(:) |
---|
241 | zt_bnds(1,2:jpk ) = gdept_1d(1:jpkm1) |
---|
242 | zt_bnds(1,1 ) = gdept_1d(1) - e3w_1d(1) |
---|
243 | zw_bnds(1,: ) = gdepw_1d(:) |
---|
244 | zw_bnds(2,1:jpkm1) = gdepw_1d(2:jpk) |
---|
245 | zw_bnds(2,jpk: ) = gdepw_1d(jpk) + e3t_1d(jpk) |
---|
246 | CALL iom_set_axis_attr( "deptht", bounds=zw_bnds ) |
---|
247 | CALL iom_set_axis_attr( "depthu", bounds=zw_bnds ) |
---|
248 | CALL iom_set_axis_attr( "depthv", bounds=zw_bnds ) |
---|
249 | CALL iom_set_axis_attr( "depthw", bounds=zt_bnds ) |
---|
250 | |
---|
251 | ! ABL |
---|
252 | za_bnds(1,:) = ghw_abl(1:jpkam1) |
---|
253 | za_bnds(2,:) = ghw_abl(2:jpka ) |
---|
254 | CALL iom_set_axis_attr( "ght_abl", bounds=za_bnds ) |
---|
255 | za_bnds(1,:) = ght_abl(2:jpka ) |
---|
256 | za_bnds(2,:) = ght_abl(2:jpka ) + e3w_abl(2:jpka) |
---|
257 | CALL iom_set_axis_attr( "ghw_abl", bounds=za_bnds ) |
---|
258 | |
---|
259 | CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,jpnfl) /) ) |
---|
260 | # if defined key_si3 |
---|
261 | CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) ) |
---|
262 | ! SIMIP diagnostics (4 main arctic straits) |
---|
263 | CALL iom_set_axis_attr( "nstrait", (/ (REAL(ji,wp), ji=1,4) /) ) |
---|
264 | # endif |
---|
265 | #if defined key_top |
---|
266 | IF( ALLOCATED(profsed) ) CALL iom_set_axis_attr( "profsed", paxis = profsed ) |
---|
267 | #endif |
---|
268 | CALL iom_set_axis_attr( "icbcla", class_num ) |
---|
269 | CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) ) ! strange syntaxe and idea... |
---|
270 | CALL iom_set_axis_attr( "iax_26C", (/ REAL(26,wp) /) ) ! strange syntaxe and idea... |
---|
271 | CALL iom_set_axis_attr( "iax_28C", (/ REAL(28,wp) /) ) ! strange syntaxe and idea... |
---|
272 | CALL iom_set_axis_attr( "basin" , (/ (REAL(ji,wp), ji=1,5) /) ) |
---|
273 | ENDIF |
---|
274 | ! |
---|
275 | ! automatic definitions of some of the xml attributs |
---|
276 | IF(lwp) write(numout, *) 'TEST IOM_INIT: ', TRIM(cdname), TRIM(cdname) == TRIM(crixios_context) |
---|
277 | IF(lwp) CALL FLUSH(numout) |
---|
278 | IF(llrstr) THEN |
---|
279 | IF(PRESENT(idfp)) THEN |
---|
280 | CALL iom_set_rst_context(.TRUE.) |
---|
281 | !set which fields will be read from restart file |
---|
282 | CALL iom_set_rstr_active(fname, idfp) |
---|
283 | ELSE |
---|
284 | CALL ctl_stop( 'iom_init:', 'restart read with XIOS: missing pointer to NETCDF file' ) |
---|
285 | ENDIF |
---|
286 | ELSE IF(llrstw) THEN |
---|
287 | CALL iom_set_rstw_file(fname) |
---|
288 | ELSE |
---|
289 | CALL set_xmlatt |
---|
290 | ENDIF |
---|
291 | ! |
---|
292 | ! set time step length |
---|
293 | dtime%second = rn_Dt |
---|
294 | CALL xios_set_timestep( dtime ) |
---|
295 | ! |
---|
296 | ! conditional closure of context definition |
---|
297 | IF ( ll_closedef ) CALL iom_init_closedef |
---|
298 | ! |
---|
299 | DEALLOCATE( zt_bnds, zw_bnds ) |
---|
300 | ! |
---|
301 | IF ( ll_tmppatch ) THEN |
---|
302 | nldi = nldi_save ; nlei = nlei_save |
---|
303 | nldj = nldj_save ; nlej = nlej_save |
---|
304 | ENDIF |
---|
305 | #endif |
---|
306 | ! |
---|
307 | END SUBROUTINE iom_init |
---|
308 | |
---|
309 | SUBROUTINE iom_init_closedef(cdname) |
---|
310 | !!---------------------------------------------------------------------- |
---|
311 | !! *** SUBROUTINE iom_init_closedef *** |
---|
312 | !!---------------------------------------------------------------------- |
---|
313 | !! |
---|
314 | !! ** Purpose : Closure of context definition |
---|
315 | !! |
---|
316 | !!---------------------------------------------------------------------- |
---|
317 | CHARACTER(len=*), OPTIONAL, INTENT(IN) :: cdname |
---|
318 | #if defined key_iomput |
---|
319 | LOGICAL :: llrstw |
---|
320 | |
---|
321 | IF(lwp) write(numout, *) 'XIOS CLOSE definitions for: ', TRIM(cdname) |
---|
322 | llrstw = .FALSE. |
---|
323 | IF(PRESENT(cdname)) THEN |
---|
324 | llrstw = (TRIM(cdname) == TRIM(cwxios_context)) |
---|
325 | llrstw = llrstw .OR. (TRIM(cdname) == TRIM(cwixios_context)) |
---|
326 | llrstw = llrstw .OR. (TRIM(cdname) == TRIM(cwtxios_context)) |
---|
327 | llrstw = llrstw .OR. (TRIM(cdname) == TRIM(cwsxios_context)) |
---|
328 | ENDIF |
---|
329 | |
---|
330 | IF( llrstw ) THEN |
---|
331 | !set names of the fields in restart file IF using XIOS to write data |
---|
332 | CALL iom_set_rst_context(.FALSE.) |
---|
333 | CALL xios_close_context_definition() |
---|
334 | ELSE |
---|
335 | CALL xios_close_context_definition() |
---|
336 | CALL xios_update_calendar( 0 ) |
---|
337 | ENDIF |
---|
338 | #else |
---|
339 | IF( .FALSE. ) WRITE(numout,*) 'iom_init_closedef: should not see this' ! useless statement to avoid compilation warnings |
---|
340 | #endif |
---|
341 | |
---|
342 | END SUBROUTINE iom_init_closedef |
---|
343 | |
---|
344 | SUBROUTINE iom_set_rstr_active(cdfname, idnum) |
---|
345 | !!--------------------------------------------------------------------- |
---|
346 | !! *** SUBROUTINE iom_set_rstr_active *** |
---|
347 | !! |
---|
348 | !! ** Purpose : define file name in XIOS context for reading restart file, |
---|
349 | !! enable variables present in restart file for reading with XIOS |
---|
350 | !!--------------------------------------------------------------------- |
---|
351 | |
---|
352 | !sets enabled = .TRUE. for each field in restart file |
---|
353 | CHARACTER(len=*), INTENT(IN) :: cdfname |
---|
354 | INTEGER , INTENT(IN) :: idnum |
---|
355 | #if defined key_iomput |
---|
356 | INTEGER :: ndims, nvars, natts, unlimitedDimId, dimlen, xtype,mdims |
---|
357 | TYPE(xios_field) :: field_hdl |
---|
358 | TYPE(xios_file) :: file_hdl |
---|
359 | TYPE(xios_filegroup) :: filegroup_hdl |
---|
360 | INTEGER :: dimids(4), jv,i, idim |
---|
361 | CHARACTER(LEN=256) :: clinfo ! info character |
---|
362 | INTEGER, ALLOCATABLE :: indimlens(:) |
---|
363 | CHARACTER(LEN=nf90_max_name), ALLOCATABLE :: indimnames(:) |
---|
364 | CHARACTER(LEN=nf90_max_name) :: dimname, varname |
---|
365 | LOGICAL :: lmeta |
---|
366 | |
---|
367 | !failed to build with AGRIF |
---|
368 | ! meta(1:NMETA) = ["nav_lat", & |
---|
369 | ! "nav_lon", "nav_lev", "time_instant", & |
---|
370 | ! "time_instant_bounds", "time_counter", & |
---|
371 | ! "time_counter_bounds", "x", "y", "numcat"] |
---|
372 | |
---|
373 | meta(1) = "nav_lat" |
---|
374 | meta(2) = "nav_lon" |
---|
375 | meta(3) = "nav_lev" |
---|
376 | meta(4) = "time_instant" |
---|
377 | meta(5) = "time_instant_bounds" |
---|
378 | meta(6) = "time_counter" |
---|
379 | meta(7) = "time_counter_bounds" |
---|
380 | meta(8) = "x" |
---|
381 | meta(9) = "y" |
---|
382 | meta(10) = "numcat" |
---|
383 | |
---|
384 | clinfo = ' iom_set_rstr_active, file: '//TRIM(cdfname) |
---|
385 | |
---|
386 | IF(lwp) write(numout, *) TRIM(clinfo) |
---|
387 | IF(lwp) CALL FLUSH(numout) |
---|
388 | !set name of the restart file and enable available fields |
---|
389 | CALL xios_get_handle("file_definition", filegroup_hdl ) |
---|
390 | CALL xios_add_child(filegroup_hdl, file_hdl, 'rrestart') |
---|
391 | CALL xios_set_file_attr( "rrestart", name=trim(cdfname), type="one_file", & |
---|
392 | par_access="collective", enabled=.TRUE., mode="read", & |
---|
393 | output_freq=xios_timestep) |
---|
394 | |
---|
395 | CALL iom_nf90_check( nf90_inquire(idnum, ndims, nvars, natts ), clinfo ) |
---|
396 | ALLOCATE(indimlens(ndims), indimnames(ndims)) |
---|
397 | CALL iom_nf90_check( nf90_inquire(idnum, unlimitedDimId = unlimitedDimId ), clinfo ) |
---|
398 | |
---|
399 | DO idim = 1, ndims |
---|
400 | CALL iom_nf90_check( nf90_inquire_dimension(idnum, idim, dimname, dimlen ), clinfo ) |
---|
401 | indimlens(idim) = dimlen |
---|
402 | indimnames(idim) = dimname |
---|
403 | ENDDO |
---|
404 | |
---|
405 | DO jv =1, nvars |
---|
406 | lmeta = .FALSE. |
---|
407 | CALL iom_nf90_check( nf90_inquire_variable(idnum, jv, varname, xtype, ndims, dimids, natts ), clinfo ) |
---|
408 | DO i = 1, NMETA |
---|
409 | IF(TRIM(varname) == TRIM(meta(i))) THEN |
---|
410 | lmeta = .TRUE. |
---|
411 | ENDIF |
---|
412 | ENDDO |
---|
413 | IF(.NOT.lmeta) THEN |
---|
414 | CALL xios_add_child(file_hdl, field_hdl, TRIM(varname)) |
---|
415 | if(lwp) write(numout, *) 'ADD field: ', TRIM(varname) |
---|
416 | IF(lwp) CALL FLUSH(numout) |
---|
417 | mdims = ndims |
---|
418 | |
---|
419 | IF(ANY(dimids(1:ndims) == unlimitedDimId)) THEN |
---|
420 | mdims = mdims - 1 |
---|
421 | ENDIF |
---|
422 | |
---|
423 | IF(mdims == 3) THEN |
---|
424 | if(lwp) write(numout, *) '3D', indimlens(ndims) |
---|
425 | IF(lwp) CALL FLUSH(numout) |
---|
426 | |
---|
427 | CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), & |
---|
428 | domain_ref="grid_N", axis_ref=TRIM(iom_axis(indimlens(ndims))), & |
---|
429 | prec = 8, operation = "instant") |
---|
430 | ELSEIF(mdims == 2) THEN |
---|
431 | if(lwp) write(numout, *) '2D' |
---|
432 | IF(lwp) CALL FLUSH(numout) |
---|
433 | |
---|
434 | CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), & |
---|
435 | domain_ref="grid_N", prec = 8, operation = "instant") |
---|
436 | ELSEIF(mdims == 1) THEN |
---|
437 | if(lwp) write(numout, *) '1D', indimlens(ndims) |
---|
438 | IF(lwp) CALL FLUSH(numout) |
---|
439 | |
---|
440 | CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), & |
---|
441 | axis_ref=TRIM(iom_axis(indimlens(ndims))), prec = 8, operation = "instant") |
---|
442 | ELSEIF(mdims == 0) THEN |
---|
443 | if(lwp) write(numout, *) '0D' |
---|
444 | IF(lwp) CALL FLUSH(numout) |
---|
445 | |
---|
446 | CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), & |
---|
447 | scalar_ref = "grid_scalar", prec = 8, operation = "instant") |
---|
448 | ELSE |
---|
449 | if(lwp) write(numout, *) 'WAHT?' |
---|
450 | IF(lwp) CALL FLUSH(numout) |
---|
451 | |
---|
452 | WRITE(ctmp1,*) 'iom_set_rstr_active: variable ', TRIM(varname) ,' incorrect number of dimensions' |
---|
453 | CALL ctl_stop( 'iom_set_rstr_active:', ctmp1 ) |
---|
454 | ENDIF |
---|
455 | ENDIF |
---|
456 | ENDDO |
---|
457 | DEALLOCATE(indimlens, indimnames) |
---|
458 | #endif |
---|
459 | END SUBROUTINE iom_set_rstr_active |
---|
460 | |
---|
461 | SUBROUTINE iom_set_rstw_file(cdrst_file) |
---|
462 | !!--------------------------------------------------------------------- |
---|
463 | !! *** SUBROUTINE iom_set_rstw_file *** |
---|
464 | !! |
---|
465 | !! ** Purpose : define file name in XIOS context for writing restart |
---|
466 | !!--------------------------------------------------------------------- |
---|
467 | CHARACTER(len=*) :: cdrst_file |
---|
468 | #if defined key_iomput |
---|
469 | TYPE(xios_file) :: file_hdl |
---|
470 | TYPE(xios_filegroup) :: filegroup_hdl |
---|
471 | INTEGER :: i |
---|
472 | CHARACTER(lc) :: clpath |
---|
473 | |
---|
474 | !set name of the restart file and enable available fields |
---|
475 | IF(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS write) to: ',cdrst_file |
---|
476 | IF(lwp) CALL FLUSH(numout) |
---|
477 | CALL xios_get_handle("file_definition", filegroup_hdl ) |
---|
478 | CALL xios_add_child(filegroup_hdl, file_hdl, 'wrestart') |
---|
479 | IF(nxioso.eq.1) THEN |
---|
480 | CALL xios_set_file_attr( "wrestart", type="one_file", enabled=.TRUE.,& |
---|
481 | mode="write", output_freq=xios_timestep) |
---|
482 | if(lwp) write(numout,*) 'OPEN ', trim(cdrst_file), ' in one_file mode' |
---|
483 | ELSE |
---|
484 | CALL xios_set_file_attr( "wrestart", type="multiple_file", enabled=.TRUE.,& |
---|
485 | mode="write", output_freq=xios_timestep) |
---|
486 | if(lwp) write(numout,*) 'OPEN ', trim(cdrst_file), ' in multiple_file mode' |
---|
487 | ENDIF |
---|
488 | CALL xios_set_file_attr( "wrestart", name=trim(cdrst_file)) |
---|
489 | #endif |
---|
490 | END SUBROUTINE iom_set_rstw_file |
---|
491 | |
---|
492 | |
---|
493 | SUBROUTINE iom_set_rstw_active(sdfield, rd0, rd1, rd2, rd3) |
---|
494 | !!--------------------------------------------------------------------- |
---|
495 | !! *** SUBROUTINE iom_set_rstw_active *** |
---|
496 | !! |
---|
497 | !! ** Purpose : define file name in XIOS context for writing restart |
---|
498 | !! enable variables present in restart file for writing |
---|
499 | !!--------------------------------------------------------------------- |
---|
500 | !sets enabled = .TRUE. for each field in restart file |
---|
501 | CHARACTER(len = *), INTENT(IN) :: sdfield |
---|
502 | REAL(wp), OPTIONAL, INTENT(IN) :: rd0 |
---|
503 | REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(:) :: rd1 |
---|
504 | REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(:, :) :: rd2 |
---|
505 | REAL(wp), OPTIONAL, INTENT(IN), DIMENSION(:, :, :) :: rd3 |
---|
506 | #if defined key_iomput |
---|
507 | TYPE(xios_field) :: field_hdl |
---|
508 | TYPE(xios_file) :: file_hdl |
---|
509 | INTEGER :: i |
---|
510 | CHARACTER(lc) :: clpath |
---|
511 | CHARACTER(len=1024) :: fname |
---|
512 | CHARACTER(len=lc) :: axis_ref |
---|
513 | |
---|
514 | CALL xios_get_handle("wrestart", file_hdl) |
---|
515 | !define fields for restart context |
---|
516 | CALL xios_add_child(file_hdl, field_hdl, TRIM(sdfield)) |
---|
517 | |
---|
518 | IF(PRESENT(rd3)) THEN |
---|
519 | IF(lwp) write(numout, *) TRIM(sdfield), ' 3D ', size(rd3,3) |
---|
520 | IF(lwp) CALL FLUSH(numout) |
---|
521 | CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(sdfield), & |
---|
522 | domain_ref="grid_N", axis_ref=TRIM(iom_axis(size(rd3, 3))), & |
---|
523 | prec = 8, operation = "instant") |
---|
524 | ENDIF |
---|
525 | |
---|
526 | IF(PRESENT(rd2)) THEN |
---|
527 | IF(lwp) write(numout, *) TRIM(sdfield), ' 2D' |
---|
528 | IF(lwp) CALL FLUSH(numout) |
---|
529 | CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(sdfield), & |
---|
530 | domain_ref="grid_N", prec = 8, operation = "instant") |
---|
531 | ENDIF |
---|
532 | |
---|
533 | IF(PRESENT(rd1)) THEN |
---|
534 | IF(lwp) write(numout, *) TRIM(sdfield), ' 1D ', size(rd1,1) |
---|
535 | IF(lwp) CALL FLUSH(numout) |
---|
536 | CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(sdfield), & |
---|
537 | axis_ref=TRIM(iom_axis(size(rd1, 1))), prec = 8, operation = "instant") |
---|
538 | ENDIF |
---|
539 | |
---|
540 | IF(PRESENT(rd0)) THEN |
---|
541 | IF(lwp) write(numout, *) TRIM(sdfield), ' 0D' |
---|
542 | IF(lwp) CALL FLUSH(numout) |
---|
543 | CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(sdfield), & |
---|
544 | scalar_ref = "grid_scalar", prec = 8, operation = "instant") |
---|
545 | ENDIF |
---|
546 | #endif |
---|
547 | END SUBROUTINE iom_set_rstw_active |
---|
548 | |
---|
549 | FUNCTION iom_axis(idlev) result(axis_ref) |
---|
550 | !!--------------------------------------------------------------------- |
---|
551 | !! *** FUNCTION iom_axis *** |
---|
552 | !! |
---|
553 | !! ** Purpose : Used for grid definition when XIOS is used to read/write |
---|
554 | !! restart. Returns axis corresponding to the number of levels |
---|
555 | !! given as an input variable. Axes are defined in routine |
---|
556 | !! iom_set_rst_context |
---|
557 | !!--------------------------------------------------------------------- |
---|
558 | INTEGER, INTENT(IN) :: idlev |
---|
559 | CHARACTER(len=lc) :: axis_ref |
---|
560 | CHARACTER(len=12) :: str |
---|
561 | IF(idlev == jpk) THEN |
---|
562 | axis_ref="nav_lev" |
---|
563 | #if defined key_si3 |
---|
564 | ELSEIF(idlev == jpl) THEN |
---|
565 | axis_ref="numcat" |
---|
566 | #endif |
---|
567 | ELSE |
---|
568 | write(str, *) idlev |
---|
569 | CALL ctl_stop( 'iom_axis', 'Definition for axis with '//TRIM(ADJUSTL(str))//' levels missing') |
---|
570 | ENDIF |
---|
571 | END FUNCTION iom_axis |
---|
572 | |
---|
573 | SUBROUTINE iom_set_rst_context(ld_rstr) |
---|
574 | !!--------------------------------------------------------------------- |
---|
575 | !! *** SUBROUTINE iom_set_rst_context *** |
---|
576 | !! |
---|
577 | !! ** Purpose : Define domain, axis and grid for restart (read/write) |
---|
578 | !! context |
---|
579 | !! |
---|
580 | !!--------------------------------------------------------------------- |
---|
581 | LOGICAL, INTENT(IN) :: ld_rstr |
---|
582 | INTEGER :: ji |
---|
583 | #if defined key_iomput |
---|
584 | TYPE(xios_domaingroup) :: domaingroup_hdl |
---|
585 | TYPE(xios_domain) :: domain_hdl |
---|
586 | TYPE(xios_axisgroup) :: axisgroup_hdl |
---|
587 | TYPE(xios_axis) :: axis_hdl |
---|
588 | TYPE(xios_scalar) :: scalar_hdl |
---|
589 | TYPE(xios_scalargroup) :: scalargroup_hdl |
---|
590 | |
---|
591 | CALL xios_get_handle("domain_definition",domaingroup_hdl) |
---|
592 | CALL xios_add_child(domaingroup_hdl, domain_hdl, "grid_N") |
---|
593 | CALL set_grid("N", glamt, gphit, .TRUE., ld_rstr) |
---|
594 | |
---|
595 | CALL xios_get_handle("axis_definition",axisgroup_hdl) |
---|
596 | CALL xios_add_child(axisgroup_hdl, axis_hdl, "nav_lev") |
---|
597 | !AGRIF fails to compile when unit= is in call to xios_set_axis_attr |
---|
598 | ! CALL xios_set_axis_attr( "nav_lev", long_name="Vertical levels", unit="m", positive="down") |
---|
599 | CALL xios_set_axis_attr( "nav_lev", long_name="Vertical levels in meters", positive="down") |
---|
600 | CALL iom_set_axis_attr( "nav_lev", paxis = gdept_1d ) |
---|
601 | #if defined key_si3 |
---|
602 | CALL xios_add_child(axisgroup_hdl, axis_hdl, "numcat") |
---|
603 | CALL iom_set_axis_attr( "numcat", (/ (REAL(ji,wp), ji=1,jpl) /) ) |
---|
604 | #endif |
---|
605 | |
---|
606 | CALL xios_get_handle("scalar_definition", scalargroup_hdl) |
---|
607 | CALL xios_add_child(scalargroup_hdl, scalar_hdl, "grid_scalar") |
---|
608 | #endif |
---|
609 | END SUBROUTINE iom_set_rst_context |
---|
610 | |
---|
611 | SUBROUTINE iom_swap( cdname ) |
---|
612 | !!--------------------------------------------------------------------- |
---|
613 | !! *** SUBROUTINE iom_swap *** |
---|
614 | !! |
---|
615 | !! ** Purpose : swap context between different agrif grid for xmlio_server |
---|
616 | !!--------------------------------------------------------------------- |
---|
617 | CHARACTER(len=*), INTENT(in) :: cdname |
---|
618 | #if defined key_iomput |
---|
619 | TYPE(xios_context) :: nemo_hdl |
---|
620 | IF( TRIM(Agrif_CFixed()) == '0' ) THEN |
---|
621 | CALL xios_get_handle(TRIM(cdname),nemo_hdl) |
---|
622 | ELSE |
---|
623 | CALL xios_get_handle(TRIM(Agrif_CFixed())//"_"//TRIM(cdname),nemo_hdl) |
---|
624 | ENDIF |
---|
625 | ! |
---|
626 | CALL xios_set_current_context(nemo_hdl) |
---|
627 | #endif |
---|
628 | ! |
---|
629 | END SUBROUTINE iom_swap |
---|
630 | |
---|
631 | |
---|
632 | SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, ldstop, ldiof, kdlev, cdcomp ) |
---|
633 | !!--------------------------------------------------------------------- |
---|
634 | !! *** SUBROUTINE iom_open *** |
---|
635 | !! |
---|
636 | !! ** Purpose : open an input file (return 0 if not found) |
---|
637 | !!--------------------------------------------------------------------- |
---|
638 | CHARACTER(len=*), INTENT(in ) :: cdname ! File name |
---|
639 | INTEGER , INTENT( out) :: kiomid ! iom identifier of the opened file |
---|
640 | LOGICAL , INTENT(in ), OPTIONAL :: ldwrt ! open in write modeb (default = .FALSE.) |
---|
641 | INTEGER , INTENT(in ), OPTIONAL :: kdom ! Type of domain to be written (default = jpdom_local_noovlap) |
---|
642 | LOGICAL , INTENT(in ), OPTIONAL :: ldstop ! stop if open to read a non-existing file (default = .TRUE.) |
---|
643 | LOGICAL , INTENT(in ), OPTIONAL :: ldiof ! Interp On the Fly, needed for AGRIF (default = .FALSE.) |
---|
644 | INTEGER , INTENT(in ), OPTIONAL :: kdlev ! number of vertical levels |
---|
645 | CHARACTER(len=3), INTENT(in ), OPTIONAL :: cdcomp ! name of component calling iom_nf90_open |
---|
646 | ! |
---|
647 | CHARACTER(LEN=256) :: clname ! the name of the file based on cdname [[+clcpu]+clcpu] |
---|
648 | CHARACTER(LEN=256) :: cltmpn ! tempory name to store clname (in writting mode) |
---|
649 | CHARACTER(LEN=10) :: clsuffix ! ".nc" |
---|
650 | CHARACTER(LEN=15) :: clcpu ! the cpu number (max jpmax_digits digits) |
---|
651 | CHARACTER(LEN=256) :: clinfo ! info character |
---|
652 | LOGICAL :: llok ! check the existence |
---|
653 | LOGICAL :: llwrt ! local definition of ldwrt |
---|
654 | LOGICAL :: llnoov ! local definition to read overlap |
---|
655 | LOGICAL :: llstop ! local definition of ldstop |
---|
656 | LOGICAL :: lliof ! local definition of ldiof |
---|
657 | INTEGER :: icnt ! counter for digits in clcpu (max = jpmax_digits) |
---|
658 | INTEGER :: iln, ils ! lengths of character |
---|
659 | INTEGER :: idom ! type of domain |
---|
660 | INTEGER :: istop ! |
---|
661 | INTEGER, DIMENSION(2,5) :: idompar ! domain parameters: |
---|
662 | ! local number of points for x,y dimensions |
---|
663 | ! position of first local point for x,y dimensions |
---|
664 | ! position of last local point for x,y dimensions |
---|
665 | ! start halo size for x,y dimensions |
---|
666 | ! end halo size for x,y dimensions |
---|
667 | !--------------------------------------------------------------------- |
---|
668 | ! Initializations and control |
---|
669 | ! ============= |
---|
670 | kiomid = -1 |
---|
671 | clinfo = ' iom_open ~~~ ' |
---|
672 | istop = nstop |
---|
673 | ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0 |
---|
674 | ! (could be done when defining iom_file in f95 but not in f90) |
---|
675 | IF( Agrif_Root() ) THEN |
---|
676 | IF( iom_open_init == 0 ) THEN |
---|
677 | iom_file(:)%nfid = 0 |
---|
678 | iom_open_init = 1 |
---|
679 | ENDIF |
---|
680 | ENDIF |
---|
681 | ! do we read or write the file? |
---|
682 | IF( PRESENT(ldwrt) ) THEN ; llwrt = ldwrt |
---|
683 | ELSE ; llwrt = .FALSE. |
---|
684 | ENDIF |
---|
685 | ! do we call ctl_stop if we try to open a non-existing file in read mode? |
---|
686 | IF( PRESENT(ldstop) ) THEN ; llstop = ldstop |
---|
687 | ELSE ; llstop = .TRUE. |
---|
688 | ENDIF |
---|
689 | ! are we using interpolation on the fly? |
---|
690 | IF( PRESENT(ldiof) ) THEN ; lliof = ldiof |
---|
691 | ELSE ; lliof = .FALSE. |
---|
692 | ENDIF |
---|
693 | ! do we read the overlap |
---|
694 | ! ugly patch SM+JMM+RB to overwrite global definition in some cases |
---|
695 | llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif |
---|
696 | ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix) |
---|
697 | ! ============= |
---|
698 | clname = trim(cdname) |
---|
699 | IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN |
---|
700 | iln = INDEX(clname,'/') |
---|
701 | cltmpn = clname(1:iln) |
---|
702 | clname = clname(iln+1:LEN_TRIM(clname)) |
---|
703 | clname=TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname) |
---|
704 | ENDIF |
---|
705 | ! which suffix should we use? |
---|
706 | clsuffix = '.nc' |
---|
707 | ! Add the suffix if needed |
---|
708 | iln = LEN_TRIM(clname) |
---|
709 | ils = LEN_TRIM(clsuffix) |
---|
710 | IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 ) & |
---|
711 | & clname = TRIM(clname)//TRIM(clsuffix) |
---|
712 | cltmpn = clname ! store this name |
---|
713 | ! try to find if the file to be opened already exist |
---|
714 | ! ============= |
---|
715 | INQUIRE( FILE = clname, EXIST = llok ) |
---|
716 | IF( .NOT.llok ) THEN |
---|
717 | ! we try to add the cpu number to the name |
---|
718 | WRITE(clcpu,*) narea-1 |
---|
719 | |
---|
720 | clcpu = TRIM(ADJUSTL(clcpu)) |
---|
721 | iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.) |
---|
722 | clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix) |
---|
723 | icnt = 0 |
---|
724 | INQUIRE( FILE = clname, EXIST = llok ) |
---|
725 | ! we try different formats for the cpu number by adding 0 |
---|
726 | DO WHILE( .NOT.llok .AND. icnt < jpmax_digits ) |
---|
727 | clcpu = "0"//trim(clcpu) |
---|
728 | clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix) |
---|
729 | INQUIRE( FILE = clname, EXIST = llok ) |
---|
730 | icnt = icnt + 1 |
---|
731 | END DO |
---|
732 | ELSE |
---|
733 | lxios_sini = .TRUE. |
---|
734 | ENDIF |
---|
735 | IF( llwrt ) THEN |
---|
736 | ! check the domain definition |
---|
737 | ! JMM + SM: ugly patch before getting the new version of lib_mpp) |
---|
738 | ! idom = jpdom_local_noovlap ! default definition |
---|
739 | IF( llnoov ) THEN ; idom = jpdom_local_noovlap ! default definition |
---|
740 | ELSE ; idom = jpdom_local_full ! default definition |
---|
741 | ENDIF |
---|
742 | IF( PRESENT(kdom) ) idom = kdom |
---|
743 | ! create the domain informations |
---|
744 | ! ============= |
---|
745 | SELECT CASE (idom) |
---|
746 | CASE (jpdom_local_full) |
---|
747 | idompar(:,1) = (/ jpi , jpj /) |
---|
748 | idompar(:,2) = (/ nimpp , njmpp /) |
---|
749 | idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1 /) |
---|
750 | idompar(:,4) = (/ nldi - 1 , nldj - 1 /) |
---|
751 | idompar(:,5) = (/ jpi - nlei , jpj - nlej /) |
---|
752 | CASE (jpdom_local_noextra) |
---|
753 | idompar(:,1) = (/ nlci , nlcj /) |
---|
754 | idompar(:,2) = (/ nimpp , njmpp /) |
---|
755 | idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /) |
---|
756 | idompar(:,4) = (/ nldi - 1 , nldj - 1 /) |
---|
757 | idompar(:,5) = (/ nlci - nlei , nlcj - nlej /) |
---|
758 | CASE (jpdom_local_noovlap) |
---|
759 | idompar(:,1) = (/ nlei - nldi + 1, nlej - nldj + 1 /) |
---|
760 | idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /) |
---|
761 | idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /) |
---|
762 | idompar(:,4) = (/ 0 , 0 /) |
---|
763 | idompar(:,5) = (/ 0 , 0 /) |
---|
764 | CASE DEFAULT |
---|
765 | CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' ) |
---|
766 | END SELECT |
---|
767 | ENDIF |
---|
768 | ! Open the NetCDF file |
---|
769 | ! ============= |
---|
770 | ! do we have some free file identifier? |
---|
771 | IF( MINVAL(iom_file(:)%nfid) /= 0 ) & |
---|
772 | & CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' ) |
---|
773 | ! if no file was found... |
---|
774 | IF( .NOT. llok ) THEN |
---|
775 | IF( .NOT. llwrt ) THEN ! we are in read mode |
---|
776 | IF( llstop ) THEN ; CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' ) |
---|
777 | ELSE ; istop = nstop + 1 ! make sure that istop /= nstop so we don't open the file |
---|
778 | ENDIF |
---|
779 | ELSE ! we are in write mode so we |
---|
780 | clname = cltmpn ! get back the file name without the cpu number |
---|
781 | ENDIF |
---|
782 | ELSE |
---|
783 | IF( llwrt .AND. .NOT. ln_clobber ) THEN ! we stop as we want to write in a new file |
---|
784 | CALL ctl_stop( TRIM(clinfo), 'We want to write in a new file but '//TRIM(clname)//' already exists...' ) |
---|
785 | istop = nstop + 1 ! make sure that istop /= nstop so we don't open the file |
---|
786 | ELSEIF( llwrt ) THEN ! the file exists and we are in write mode with permission to |
---|
787 | clname = cltmpn ! overwrite so get back the file name without the cpu number |
---|
788 | ENDIF |
---|
789 | ENDIF |
---|
790 | IF( istop == nstop ) THEN ! no error within this routine |
---|
791 | CALL iom_nf90_open( clname, kiomid, llwrt, llok, idompar, kdlev = kdlev, cdcomp = cdcomp ) |
---|
792 | ENDIF |
---|
793 | ! |
---|
794 | END SUBROUTINE iom_open |
---|
795 | |
---|
796 | |
---|
797 | SUBROUTINE iom_close( kiomid ) |
---|
798 | !!-------------------------------------------------------------------- |
---|
799 | !! *** SUBROUTINE iom_close *** |
---|
800 | !! |
---|
801 | !! ** Purpose : close an input file, or all files opened by iom |
---|
802 | !!-------------------------------------------------------------------- |
---|
803 | INTEGER, INTENT(inout), OPTIONAL :: kiomid ! iom identifier of the file to be closed |
---|
804 | ! ! return 0 when file is properly closed |
---|
805 | ! ! No argument: all files opened by iom are closed |
---|
806 | |
---|
807 | INTEGER :: jf ! dummy loop indices |
---|
808 | INTEGER :: i_s, i_e ! temporary integer |
---|
809 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
810 | !--------------------------------------------------------------------- |
---|
811 | ! |
---|
812 | IF( iom_open_init == 0 ) RETURN ! avoid to use iom_file(jf)%nfid that us not yet initialized |
---|
813 | ! |
---|
814 | clinfo = ' iom_close ~~~ ' |
---|
815 | IF( PRESENT(kiomid) ) THEN |
---|
816 | i_s = kiomid |
---|
817 | i_e = kiomid |
---|
818 | ELSE |
---|
819 | i_s = 1 |
---|
820 | i_e = jpmax_files |
---|
821 | ENDIF |
---|
822 | |
---|
823 | IF( i_s > 0 ) THEN |
---|
824 | DO jf = i_s, i_e |
---|
825 | IF( iom_file(jf)%nfid > 0 ) THEN |
---|
826 | CALL iom_nf90_close( jf ) |
---|
827 | iom_file(jf)%nfid = 0 ! free the id |
---|
828 | IF( PRESENT(kiomid) ) kiomid = 0 ! return 0 as id to specify that the file was closed |
---|
829 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok' |
---|
830 | ELSEIF( PRESENT(kiomid) ) THEN |
---|
831 | WRITE(ctmp1,*) '--->', kiomid |
---|
832 | CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 ) |
---|
833 | ENDIF |
---|
834 | END DO |
---|
835 | ENDIF |
---|
836 | ! |
---|
837 | END SUBROUTINE iom_close |
---|
838 | |
---|
839 | |
---|
840 | FUNCTION iom_varid ( kiomid, cdvar, kdimsz, kndims, lduld, ldstop ) |
---|
841 | !!----------------------------------------------------------------------- |
---|
842 | !! *** FUNCTION iom_varid *** |
---|
843 | !! |
---|
844 | !! ** Purpose : get the id of a variable in a file (return 0 if not found) |
---|
845 | !!----------------------------------------------------------------------- |
---|
846 | INTEGER , INTENT(in ) :: kiomid ! file Identifier |
---|
847 | CHARACTER(len=*) , INTENT(in ) :: cdvar ! name of the variable |
---|
848 | INTEGER, DIMENSION(:), INTENT( out), OPTIONAL :: kdimsz ! size of each dimension |
---|
849 | INTEGER , INTENT( out), OPTIONAL :: kndims ! number of dimensions |
---|
850 | LOGICAL , INTENT( out), OPTIONAL :: lduld ! true if the last dimension is unlimited (time) |
---|
851 | LOGICAL , INTENT(in ), OPTIONAL :: ldstop ! stop if looking for non-existing variable (default = .TRUE.) |
---|
852 | ! |
---|
853 | INTEGER :: iom_varid, iiv, i_nvd |
---|
854 | LOGICAL :: ll_fnd |
---|
855 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
856 | LOGICAL :: llstop ! local definition of ldstop |
---|
857 | !!----------------------------------------------------------------------- |
---|
858 | iom_varid = 0 ! default definition |
---|
859 | ! do we call ctl_stop if we look for non-existing variable? |
---|
860 | IF( PRESENT(ldstop) ) THEN ; llstop = ldstop |
---|
861 | ELSE ; llstop = .TRUE. |
---|
862 | ENDIF |
---|
863 | ! |
---|
864 | IF( kiomid > 0 ) THEN |
---|
865 | clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar) |
---|
866 | IF( iom_file(kiomid)%nfid == 0 ) THEN |
---|
867 | CALL ctl_stop( trim(clinfo), 'the file is not open' ) |
---|
868 | ELSE |
---|
869 | ll_fnd = .FALSE. |
---|
870 | iiv = 0 |
---|
871 | ! |
---|
872 | DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars ) |
---|
873 | iiv = iiv + 1 |
---|
874 | ll_fnd = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) ) |
---|
875 | END DO |
---|
876 | ! |
---|
877 | IF( .NOT.ll_fnd ) THEN |
---|
878 | iiv = iiv + 1 |
---|
879 | IF( iiv <= jpmax_vars ) THEN |
---|
880 | iom_varid = iom_nf90_varid( kiomid, cdvar, iiv, kdimsz, kndims, lduld ) |
---|
881 | ELSE |
---|
882 | CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name, & |
---|
883 | & 'increase the parameter jpmax_vars') |
---|
884 | ENDIF |
---|
885 | IF( llstop .AND. iom_varid == -1 ) CALL ctl_stop( TRIM(clinfo)//' not found' ) |
---|
886 | ELSE |
---|
887 | iom_varid = iiv |
---|
888 | IF( PRESENT(kdimsz) ) THEN |
---|
889 | i_nvd = iom_file(kiomid)%ndims(iiv) |
---|
890 | IF( i_nvd <= size(kdimsz) ) THEN |
---|
891 | kdimsz(1:i_nvd) = iom_file(kiomid)%dimsz(1:i_nvd,iiv) |
---|
892 | ELSE |
---|
893 | WRITE(ctmp1,*) i_nvd, size(kdimsz) |
---|
894 | CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) ) |
---|
895 | ENDIF |
---|
896 | ENDIF |
---|
897 | IF( PRESENT(kndims) ) kndims = iom_file(kiomid)%ndims(iiv) |
---|
898 | IF( PRESENT( lduld) ) lduld = iom_file(kiomid)%luld( iiv) |
---|
899 | ENDIF |
---|
900 | ENDIF |
---|
901 | ENDIF |
---|
902 | ! |
---|
903 | END FUNCTION iom_varid |
---|
904 | |
---|
905 | |
---|
906 | !!---------------------------------------------------------------------- |
---|
907 | !! INTERFACE iom_get |
---|
908 | !!---------------------------------------------------------------------- |
---|
909 | SUBROUTINE iom_g0d( kiomid, cdvar, pvar, ktime, ldxios ) |
---|
910 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
911 | CHARACTER(len=*), INTENT(in ) :: cdvar ! Name of the variable |
---|
912 | REAL(wp) , INTENT( out) :: pvar ! read field |
---|
913 | INTEGER , INTENT(in ), OPTIONAL :: ktime ! record number |
---|
914 | LOGICAL , INTENT(in ), OPTIONAL :: ldxios ! use xios to read restart |
---|
915 | ! |
---|
916 | INTEGER :: idvar ! variable id |
---|
917 | INTEGER :: idmspc ! number of spatial dimensions |
---|
918 | INTEGER , DIMENSION(1) :: itime ! record number |
---|
919 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
920 | CHARACTER(LEN=100) :: clname ! file name |
---|
921 | CHARACTER(LEN=1) :: cldmspc ! |
---|
922 | LOGICAL :: llxios |
---|
923 | ! |
---|
924 | llxios = .FALSE. |
---|
925 | IF( PRESENT(ldxios) ) llxios = ldxios |
---|
926 | |
---|
927 | IF(.NOT.llxios) THEN ! read data using default library |
---|
928 | itime = 1 |
---|
929 | IF( PRESENT(ktime) ) itime = ktime |
---|
930 | ! |
---|
931 | clname = iom_file(kiomid)%name |
---|
932 | clinfo = ' iom_g0d, file: '//trim(clname)//', var: '//trim(cdvar) |
---|
933 | ! |
---|
934 | IF( kiomid > 0 ) THEN |
---|
935 | idvar = iom_varid( kiomid, cdvar ) |
---|
936 | IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN |
---|
937 | idmspc = iom_file ( kiomid )%ndims( idvar ) |
---|
938 | IF( iom_file(kiomid)%luld(idvar) ) idmspc = idmspc - 1 |
---|
939 | WRITE(cldmspc , fmt='(i1)') idmspc |
---|
940 | IF( idmspc > 0 ) CALL ctl_stop( TRIM(clinfo), 'When reading to a 0D array, we do not accept data', & |
---|
941 | & 'with 1 or more spatial dimensions: '//cldmspc//' were found.' , & |
---|
942 | & 'Use ncwa -a to suppress the unnecessary dimensions' ) |
---|
943 | CALL iom_nf90_get( kiomid, idvar, pvar, itime ) |
---|
944 | ENDIF |
---|
945 | ENDIF |
---|
946 | ELSE |
---|
947 | #if defined key_iomput |
---|
948 | IF(lwp) WRITE(numout,*) 'XIOS RST READ (0D): ', trim(cdvar) |
---|
949 | CALL xios_recv_field( trim(cdvar), pvar) |
---|
950 | #else |
---|
951 | WRITE(ctmp1,*) 'Can not use XIOS in iom_g0d, file: '//trim(clname)//', var:'//trim(cdvar) |
---|
952 | CALL ctl_stop( 'iom_g0d', ctmp1 ) |
---|
953 | #endif |
---|
954 | ENDIF |
---|
955 | END SUBROUTINE iom_g0d |
---|
956 | |
---|
957 | SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, ldxios ) |
---|
958 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
959 | INTEGER , INTENT(in ) :: kdom ! Type of domain to be read |
---|
960 | CHARACTER(len=*), INTENT(in ) :: cdvar ! Name of the variable |
---|
961 | REAL(wp) , INTENT( out), DIMENSION(:) :: pvar ! read field |
---|
962 | INTEGER , INTENT(in ) , OPTIONAL :: ktime ! record number |
---|
963 | INTEGER , INTENT(in ), DIMENSION(1), OPTIONAL :: kstart ! start axis position of the reading |
---|
964 | INTEGER , INTENT(in ), DIMENSION(1), OPTIONAL :: kcount ! number of points in each axis |
---|
965 | LOGICAL , INTENT(in ), OPTIONAL :: ldxios ! read data using XIOS |
---|
966 | ! |
---|
967 | IF( kiomid > 0 ) THEN |
---|
968 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom , cdvar , pv_r1d=pvar, & |
---|
969 | & ktime=ktime, kstart=kstart, kcount=kcount, & |
---|
970 | & ldxios=ldxios ) |
---|
971 | ENDIF |
---|
972 | END SUBROUTINE iom_g1d |
---|
973 | |
---|
974 | SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios) |
---|
975 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
976 | INTEGER , INTENT(in ) :: kdom ! Type of domain to be read |
---|
977 | CHARACTER(len=*), INTENT(in ) :: cdvar ! Name of the variable |
---|
978 | REAL(wp) , INTENT( out), DIMENSION(:,:) :: pvar ! read field |
---|
979 | INTEGER , INTENT(in ) , OPTIONAL :: ktime ! record number |
---|
980 | INTEGER , INTENT(in ), DIMENSION(2) , OPTIONAL :: kstart ! start axis position of the reading |
---|
981 | INTEGER , INTENT(in ), DIMENSION(2) , OPTIONAL :: kcount ! number of points in each axis |
---|
982 | LOGICAL , INTENT(in ) , OPTIONAL :: lrowattr ! logical flag telling iom_get to |
---|
983 | ! look for and use a file attribute |
---|
984 | ! called open_ocean_jstart to set the start |
---|
985 | ! value for the 2nd dimension (netcdf only) |
---|
986 | LOGICAL , INTENT(in ), OPTIONAL :: ldxios ! read data using XIOS |
---|
987 | ! |
---|
988 | IF( kiomid > 0 ) THEN |
---|
989 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom , cdvar , pv_r2d=pvar, & |
---|
990 | & ktime=ktime, kstart=kstart, kcount=kcount, & |
---|
991 | & lrowattr=lrowattr, ldxios=ldxios) |
---|
992 | ENDIF |
---|
993 | END SUBROUTINE iom_g2d |
---|
994 | |
---|
995 | SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios ) |
---|
996 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
997 | INTEGER , INTENT(in ) :: kdom ! Type of domain to be read |
---|
998 | CHARACTER(len=*), INTENT(in ) :: cdvar ! Name of the variable |
---|
999 | REAL(wp) , INTENT( out), DIMENSION(:,:,:) :: pvar ! read field |
---|
1000 | INTEGER , INTENT(in ) , OPTIONAL :: ktime ! record number |
---|
1001 | INTEGER , INTENT(in ), DIMENSION(3) , OPTIONAL :: kstart ! start axis position of the reading |
---|
1002 | INTEGER , INTENT(in ), DIMENSION(3) , OPTIONAL :: kcount ! number of points in each axis |
---|
1003 | LOGICAL , INTENT(in ) , OPTIONAL :: lrowattr ! logical flag telling iom_get to |
---|
1004 | ! look for and use a file attribute |
---|
1005 | ! called open_ocean_jstart to set the start |
---|
1006 | ! value for the 2nd dimension (netcdf only) |
---|
1007 | LOGICAL , INTENT(in ), OPTIONAL :: ldxios ! read data using XIOS |
---|
1008 | ! |
---|
1009 | IF( kiomid > 0 ) THEN |
---|
1010 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom , cdvar , pv_r3d=pvar, & |
---|
1011 | & ktime=ktime, kstart=kstart, kcount=kcount, & |
---|
1012 | & lrowattr=lrowattr, ldxios=ldxios ) |
---|
1013 | ENDIF |
---|
1014 | END SUBROUTINE iom_g3d |
---|
1015 | !!---------------------------------------------------------------------- |
---|
1016 | |
---|
1017 | SUBROUTINE iom_get_123d( kiomid, kdom , cdvar , & |
---|
1018 | & pv_r1d, pv_r2d, pv_r3d, & |
---|
1019 | & ktime , kstart, kcount, & |
---|
1020 | & lrowattr, ldxios ) |
---|
1021 | !!----------------------------------------------------------------------- |
---|
1022 | !! *** ROUTINE iom_get_123d *** |
---|
1023 | !! |
---|
1024 | !! ** Purpose : read a 1D/2D/3D variable |
---|
1025 | !! |
---|
1026 | !! ** Method : read ONE record at each CALL |
---|
1027 | !!----------------------------------------------------------------------- |
---|
1028 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1029 | INTEGER , INTENT(in ) :: kdom ! Type of domain to be read |
---|
1030 | CHARACTER(len=*) , INTENT(in ) :: cdvar ! Name of the variable |
---|
1031 | REAL(wp), DIMENSION(:) , INTENT( out), OPTIONAL :: pv_r1d ! read field (1D case) |
---|
1032 | REAL(wp), DIMENSION(:,:) , INTENT( out), OPTIONAL :: pv_r2d ! read field (2D case) |
---|
1033 | REAL(wp), DIMENSION(:,:,:) , INTENT( out), OPTIONAL :: pv_r3d ! read field (3D case) |
---|
1034 | INTEGER , INTENT(in ), OPTIONAL :: ktime ! record number |
---|
1035 | INTEGER , DIMENSION(:) , INTENT(in ), OPTIONAL :: kstart ! start position of the reading in each axis |
---|
1036 | INTEGER , DIMENSION(:) , INTENT(in ), OPTIONAL :: kcount ! number of points to be read in each axis |
---|
1037 | LOGICAL , INTENT(in ), OPTIONAL :: lrowattr ! logical flag telling iom_get to |
---|
1038 | ! look for and use a file attribute |
---|
1039 | ! called open_ocean_jstart to set the start |
---|
1040 | ! value for the 2nd dimension (netcdf only) |
---|
1041 | LOGICAL , INTENT(in ), OPTIONAL :: ldxios ! use XIOS to read restart |
---|
1042 | ! |
---|
1043 | LOGICAL :: llxios ! local definition for XIOS read |
---|
1044 | LOGICAL :: llnoov ! local definition to read overlap |
---|
1045 | LOGICAL :: luse_jattr ! local definition to read open_ocean_jstart file attribute |
---|
1046 | INTEGER :: jstartrow ! start point for 2nd dimension optionally set by file attribute |
---|
1047 | INTEGER :: jl ! loop on number of dimension |
---|
1048 | INTEGER :: idom ! type of domain |
---|
1049 | INTEGER :: idvar ! id of the variable |
---|
1050 | INTEGER :: inbdim ! number of dimensions of the variable |
---|
1051 | INTEGER :: idmspc ! number of spatial dimensions |
---|
1052 | INTEGER :: itime ! record number |
---|
1053 | INTEGER :: istop ! temporary value of nstop |
---|
1054 | INTEGER :: ix1, ix2, iy1, iy2 ! subdomain indexes |
---|
1055 | INTEGER :: ji, jj ! loop counters |
---|
1056 | INTEGER :: irankpv ! |
---|
1057 | INTEGER :: ind1, ind2 ! substring index |
---|
1058 | INTEGER, DIMENSION(jpmax_dims) :: istart ! starting point to read for each axis |
---|
1059 | INTEGER, DIMENSION(jpmax_dims) :: icnt ! number of value to read along each axis |
---|
1060 | INTEGER, DIMENSION(jpmax_dims) :: idimsz ! size of the dimensions of the variable |
---|
1061 | INTEGER, DIMENSION(jpmax_dims) :: ishape ! size of the dimensions of the variable |
---|
1062 | REAL(wp) :: zscf, zofs ! sacle_factor and add_offset |
---|
1063 | INTEGER :: itmp ! temporary integer |
---|
1064 | CHARACTER(LEN=256) :: clinfo ! info character |
---|
1065 | CHARACTER(LEN=256) :: clname ! file name |
---|
1066 | CHARACTER(LEN=1) :: clrankpv, cldmspc ! |
---|
1067 | LOGICAL :: ll_depth_spec ! T => if kstart, kcount present then *only* use values for 3rd spatial dimension. |
---|
1068 | INTEGER :: inlev ! number of levels for 3D data |
---|
1069 | REAL(wp) :: gma, gmi |
---|
1070 | !--------------------------------------------------------------------- |
---|
1071 | ! |
---|
1072 | inlev = -1 |
---|
1073 | IF( PRESENT(pv_r3d) ) inlev = SIZE(pv_r3d, 3) |
---|
1074 | ! |
---|
1075 | llxios = .FALSE. |
---|
1076 | if(PRESENT(ldxios)) llxios = ldxios |
---|
1077 | idvar = iom_varid( kiomid, cdvar ) |
---|
1078 | idom = kdom |
---|
1079 | ! |
---|
1080 | IF(.NOT.llxios) THEN |
---|
1081 | clname = iom_file(kiomid)%name ! esier to read |
---|
1082 | clinfo = ' iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar) |
---|
1083 | ! local definition of the domain ? |
---|
1084 | ! do we read the overlap |
---|
1085 | ! ugly patch SM+JMM+RB to overwrite global definition in some cases |
---|
1086 | llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif |
---|
1087 | ! check kcount and kstart optionals parameters... |
---|
1088 | IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present') |
---|
1089 | IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present') |
---|
1090 | IF( PRESENT(kstart) .AND. idom /= jpdom_unknown .AND. idom /= jpdom_autoglo_xy ) & |
---|
1091 | & CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown or kdom = jpdom_autoglo_xy') |
---|
1092 | |
---|
1093 | luse_jattr = .false. |
---|
1094 | IF( PRESENT(lrowattr) ) THEN |
---|
1095 | IF( lrowattr .AND. idom /= jpdom_data ) CALL ctl_stop(trim(clinfo), 'lrowattr present and true needs kdom = jpdom_data') |
---|
1096 | IF( lrowattr .AND. idom == jpdom_data ) luse_jattr = .true. |
---|
1097 | ENDIF |
---|
1098 | |
---|
1099 | ! Search for the variable in the data base (eventually actualize data) |
---|
1100 | istop = nstop |
---|
1101 | ! |
---|
1102 | IF( idvar > 0 ) THEN |
---|
1103 | ! to write iom_file(kiomid)%dimsz in a shorter way ! |
---|
1104 | idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) |
---|
1105 | inbdim = iom_file(kiomid)%ndims(idvar) ! number of dimensions in the file |
---|
1106 | idmspc = inbdim ! number of spatial dimensions in the file |
---|
1107 | IF( iom_file(kiomid)%luld(idvar) ) idmspc = inbdim - 1 |
---|
1108 | IF( idmspc > 3 ) CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') |
---|
1109 | ! |
---|
1110 | ! update idom definition... |
---|
1111 | ! Identify the domain in case of jpdom_auto(glo/dta) definition |
---|
1112 | IF( idom == jpdom_autoglo_xy ) THEN |
---|
1113 | ll_depth_spec = .TRUE. |
---|
1114 | idom = jpdom_autoglo |
---|
1115 | ELSE |
---|
1116 | ll_depth_spec = .FALSE. |
---|
1117 | ENDIF |
---|
1118 | IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN |
---|
1119 | IF( idom == jpdom_autoglo ) THEN ; idom = jpdom_global |
---|
1120 | ELSE ; idom = jpdom_data |
---|
1121 | ENDIF |
---|
1122 | ind1 = INDEX( clname, '_', back = .TRUE. ) + 1 |
---|
1123 | ind2 = INDEX( clname, '.', back = .TRUE. ) - 1 |
---|
1124 | IF( ind2 > ind1 ) THEN ; IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 ) idom = jpdom_local ; ENDIF |
---|
1125 | ENDIF |
---|
1126 | ! Identify the domain in case of jpdom_local definition |
---|
1127 | IF( idom == jpdom_local ) THEN |
---|
1128 | IF( idimsz(1) == jpi .AND. idimsz(2) == jpj ) THEN ; idom = jpdom_local_full |
---|
1129 | ELSEIF( idimsz(1) == nlci .AND. idimsz(2) == nlcj ) THEN ; idom = jpdom_local_noextra |
---|
1130 | ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN ; idom = jpdom_local_noovlap |
---|
1131 | ELSE ; CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' ) |
---|
1132 | ENDIF |
---|
1133 | ENDIF |
---|
1134 | ! |
---|
1135 | ! check the consistency between input array and data rank in the file |
---|
1136 | ! |
---|
1137 | ! initializations |
---|
1138 | itime = 1 |
---|
1139 | IF( PRESENT(ktime) ) itime = ktime |
---|
1140 | ! |
---|
1141 | irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) ) |
---|
1142 | WRITE(clrankpv, fmt='(i1)') irankpv |
---|
1143 | WRITE(cldmspc , fmt='(i1)') idmspc |
---|
1144 | ! |
---|
1145 | !!GS: we consider 2D data as 3D data with vertical dim size = 1 |
---|
1146 | !IF( idmspc < irankpv ) THEN |
---|
1147 | ! CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension', & |
---|
1148 | ! & 'it is impossible to read a '//clrankpv//'D array from this file...' ) |
---|
1149 | !ELSEIF( idmspc == irankpv ) THEN |
---|
1150 | IF( idmspc == irankpv ) THEN |
---|
1151 | IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown ) & |
---|
1152 | & CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' ) |
---|
1153 | ELSEIF( idmspc > irankpv ) THEN |
---|
1154 | IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN |
---|
1155 | CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...' , & |
---|
1156 | & 'As the size of the z dimension is 1 and as we try to read the first record, ', & |
---|
1157 | & 'we accept this case, even if there is a possible mix-up between z and time dimension' ) |
---|
1158 | idmspc = idmspc - 1 |
---|
1159 | ELSE |
---|
1160 | CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,' , & |
---|
1161 | & 'we do not accept data with '//cldmspc//' spatial dimensions', & |
---|
1162 | & 'Use ncwa -a to suppress the unnecessary dimensions' ) |
---|
1163 | ENDIF |
---|
1164 | ENDIF |
---|
1165 | ! |
---|
1166 | ! definition of istart and icnt |
---|
1167 | ! |
---|
1168 | icnt (:) = 1 |
---|
1169 | istart(:) = 1 |
---|
1170 | istart(idmspc+1) = itime |
---|
1171 | |
---|
1172 | IF( PRESENT(kstart) .AND. .NOT. ll_depth_spec ) THEN |
---|
1173 | istart(1:idmspc) = kstart(1:idmspc) |
---|
1174 | icnt (1:idmspc) = kcount(1:idmspc) |
---|
1175 | ELSE |
---|
1176 | IF(idom == jpdom_unknown ) THEN |
---|
1177 | icnt(1:idmspc) = idimsz(1:idmspc) |
---|
1178 | ELSE |
---|
1179 | IF( .NOT. PRESENT(pv_r1d) ) THEN ! not a 1D array |
---|
1180 | IF( idom == jpdom_data ) THEN |
---|
1181 | jstartrow = 1 |
---|
1182 | IF( luse_jattr ) THEN |
---|
1183 | CALL iom_getatt(kiomid, 'open_ocean_jstart', jstartrow ) ! -999 is returned if the attribute is not found |
---|
1184 | jstartrow = MAX(1,jstartrow) |
---|
1185 | ENDIF |
---|
1186 | istart(1:2) = (/ mig(1), mjg(1) + jstartrow - 1 /) ! icnt(1:2) done below |
---|
1187 | ELSEIF( idom == jpdom_global ) THEN ; istart(1:2) = (/ nimpp , njmpp /) ! icnt(1:2) done below |
---|
1188 | ENDIF |
---|
1189 | ! we do not read the overlap -> we start to read at nldi, nldj |
---|
1190 | ! JMM + SM: ugly patch before getting the new version of lib_mpp) |
---|
1191 | ! IF( idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /) |
---|
1192 | IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /) |
---|
1193 | ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej |
---|
1194 | ! JMM + SM: ugly patch before getting the new version of lib_mpp) |
---|
1195 | ! icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /) |
---|
1196 | IF( llnoov ) THEN ; icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /) |
---|
1197 | ELSE ; icnt(1:2) = (/ nlci , nlcj /) |
---|
1198 | ENDIF |
---|
1199 | IF( PRESENT(pv_r3d) ) THEN |
---|
1200 | IF( idom == jpdom_data ) THEN ; icnt(3) = inlev |
---|
1201 | ELSEIF( ll_depth_spec .AND. PRESENT(kstart) ) THEN ; istart(3) = kstart(3) ; icnt(3) = kcount(3) |
---|
1202 | ELSE ; icnt(3) = inlev |
---|
1203 | ENDIF |
---|
1204 | ENDIF |
---|
1205 | ENDIF |
---|
1206 | ENDIF |
---|
1207 | ENDIF |
---|
1208 | |
---|
1209 | ! check that istart and icnt can be used with this file |
---|
1210 | !- |
---|
1211 | DO jl = 1, jpmax_dims |
---|
1212 | itmp = istart(jl)+icnt(jl)-1 |
---|
1213 | IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN |
---|
1214 | WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp |
---|
1215 | WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)" ) jl, idimsz(jl) |
---|
1216 | CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 ) |
---|
1217 | ENDIF |
---|
1218 | END DO |
---|
1219 | |
---|
1220 | ! check that icnt matches the input array |
---|
1221 | !- |
---|
1222 | IF( idom == jpdom_unknown ) THEN |
---|
1223 | IF( irankpv == 1 ) ishape(1:1) = SHAPE(pv_r1d) |
---|
1224 | IF( irankpv == 2 ) ishape(1:2) = SHAPE(pv_r2d) |
---|
1225 | IF( irankpv == 3 ) ishape(1:3) = SHAPE(pv_r3d) |
---|
1226 | ctmp1 = 'd' |
---|
1227 | ELSE |
---|
1228 | IF( irankpv == 2 ) THEN |
---|
1229 | ! JMM + SM: ugly patch before getting the new version of lib_mpp) |
---|
1230 | ! ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej )) ; ctmp1 = 'd(nldi:nlei,nldj:nlej)' |
---|
1231 | IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej )) ; ctmp1='d(nldi:nlei,nldj:nlej)' |
---|
1232 | ELSE ; ishape(1:2)=SHAPE(pv_r2d(1 :nlci,1 :nlcj )) ; ctmp1='d(1:nlci,1:nlcj)' |
---|
1233 | ENDIF |
---|
1234 | ENDIF |
---|
1235 | IF( irankpv == 3 ) THEN |
---|
1236 | ! JMM + SM: ugly patch before getting the new version of lib_mpp) |
---|
1237 | ! ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1 = 'd(nldi:nlei,nldj:nlej,:)' |
---|
1238 | IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)' |
---|
1239 | ELSE ; ishape(1:3)=SHAPE(pv_r3d(1 :nlci,1 :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)' |
---|
1240 | ENDIF |
---|
1241 | ENDIF |
---|
1242 | ENDIF |
---|
1243 | |
---|
1244 | DO jl = 1, irankpv |
---|
1245 | WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl) |
---|
1246 | IF( ishape(jl) /= icnt(jl) ) CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) ) |
---|
1247 | END DO |
---|
1248 | |
---|
1249 | ENDIF |
---|
1250 | |
---|
1251 | ! read the data |
---|
1252 | !- |
---|
1253 | IF( idvar > 0 .AND. istop == nstop ) THEN ! no additional errors until this point... |
---|
1254 | ! |
---|
1255 | ! find the right index of the array to be read |
---|
1256 | ! JMM + SM: ugly patch before getting the new version of lib_mpp) |
---|
1257 | ! IF( idom /= jpdom_unknown ) THEN ; ix1 = nldi ; ix2 = nlei ; iy1 = nldj ; iy2 = nlej |
---|
1258 | ! ELSE ; ix1 = 1 ; ix2 = icnt(1) ; iy1 = 1 ; iy2 = icnt(2) |
---|
1259 | ! ENDIF |
---|
1260 | IF( llnoov ) THEN |
---|
1261 | IF( idom /= jpdom_unknown ) THEN ; ix1 = nldi ; ix2 = nlei ; iy1 = nldj ; iy2 = nlej |
---|
1262 | ELSE ; ix1 = 1 ; ix2 = icnt(1) ; iy1 = 1 ; iy2 = icnt(2) |
---|
1263 | ENDIF |
---|
1264 | ELSE |
---|
1265 | IF( idom /= jpdom_unknown ) THEN ; ix1 = 1 ; ix2 = nlci ; iy1 = 1 ; iy2 = nlcj |
---|
1266 | ELSE ; ix1 = 1 ; ix2 = icnt(1) ; iy1 = 1 ; iy2 = icnt(2) |
---|
1267 | ENDIF |
---|
1268 | ENDIF |
---|
1269 | |
---|
1270 | CALL iom_nf90_get( kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2, pv_r1d, pv_r2d, pv_r3d ) |
---|
1271 | |
---|
1272 | IF( istop == nstop ) THEN ! no additional errors until this point... |
---|
1273 | IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i6,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name) |
---|
1274 | |
---|
1275 | !--- overlap areas and extra hallows (mpp) |
---|
1276 | IF( PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN |
---|
1277 | CALL lbc_lnk( 'iom', pv_r2d,'Z', -999., kfillmode = jpfillnothing ) |
---|
1278 | ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN |
---|
1279 | ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension |
---|
1280 | IF( icnt(3) == inlev ) THEN |
---|
1281 | CALL lbc_lnk( 'iom', pv_r3d,'Z', -999., kfillmode = jpfillnothing ) |
---|
1282 | ELSE ! put some arbitrary value (a call to lbc_lnk will be done later...) |
---|
1283 | DO jj = nlcj+1, jpj ; pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :) ; END DO |
---|
1284 | DO ji = nlci+1, jpi ; pv_r3d(ji , : , :) = pv_r3d(nlei , : , :) ; END DO |
---|
1285 | ENDIF |
---|
1286 | ENDIF |
---|
1287 | ! |
---|
1288 | ELSE |
---|
1289 | ! return if istop == nstop is false |
---|
1290 | RETURN |
---|
1291 | ENDIF |
---|
1292 | ELSE |
---|
1293 | ! return if statment idvar > 0 .AND. istop == nstop is false |
---|
1294 | RETURN |
---|
1295 | ENDIF |
---|
1296 | ! |
---|
1297 | ELSE ! read using XIOS. Only if KEY_IOMPUT is defined |
---|
1298 | #if defined key_iomput |
---|
1299 | !would be good to be able to check which context is active and swap only if current is not restart |
---|
1300 | IF( PRESENT(pv_r3d) ) THEN |
---|
1301 | pv_r3d(:, :, :) = 0. |
---|
1302 | if(lwp) write(numout,*) 'XIOS RST READ (3D): ',trim(cdvar) |
---|
1303 | CALL xios_recv_field( trim(cdvar), pv_r3d) |
---|
1304 | IF(idom /= jpdom_unknown ) then |
---|
1305 | CALL lbc_lnk( 'iom', pv_r3d,'Z', -999., kfillmode = jpfillnothing) |
---|
1306 | ENDIF |
---|
1307 | ELSEIF( PRESENT(pv_r2d) ) THEN |
---|
1308 | pv_r2d(:, :) = 0. |
---|
1309 | if(lwp) write(numout,*) 'XIOS RST READ (2D): ', trim(cdvar) |
---|
1310 | CALL xios_recv_field( trim(cdvar), pv_r2d) |
---|
1311 | IF(idom /= jpdom_unknown ) THEN |
---|
1312 | CALL lbc_lnk('iom', pv_r2d,'Z',-999., kfillmode = jpfillnothing) |
---|
1313 | ENDIF |
---|
1314 | ELSEIF( PRESENT(pv_r1d) ) THEN |
---|
1315 | pv_r1d(:) = 0. |
---|
1316 | if(lwp) write(numout,*) 'XIOS RST READ (1D): ', trim(cdvar) |
---|
1317 | CALL xios_recv_field( trim(cdvar), pv_r1d) |
---|
1318 | ENDIF |
---|
1319 | #else |
---|
1320 | istop = istop + 1 |
---|
1321 | clinfo = 'Can not use XIOS in iom_get_123d, file: '//trim(clname)//', var:'//trim(cdvar) |
---|
1322 | #endif |
---|
1323 | ENDIF |
---|
1324 | !some final adjustments |
---|
1325 | ! C1D case : always call lbc_lnk to replicate the central value over the whole 3X3 domain |
---|
1326 | IF( lk_c1d .AND. PRESENT(pv_r2d) ) CALL lbc_lnk( 'iom', pv_r2d,'Z',1. ) |
---|
1327 | IF( lk_c1d .AND. PRESENT(pv_r3d) ) CALL lbc_lnk( 'iom', pv_r3d,'Z',1. ) |
---|
1328 | |
---|
1329 | !--- Apply scale_factor and offset |
---|
1330 | zscf = iom_file(kiomid)%scf(idvar) ! scale factor |
---|
1331 | zofs = iom_file(kiomid)%ofs(idvar) ! offset |
---|
1332 | IF( PRESENT(pv_r1d) ) THEN |
---|
1333 | IF( zscf /= 1. ) pv_r1d(:) = pv_r1d(:) * zscf |
---|
1334 | IF( zofs /= 0. ) pv_r1d(:) = pv_r1d(:) + zofs |
---|
1335 | ELSEIF( PRESENT(pv_r2d) ) THEN |
---|
1336 | IF( zscf /= 1.) pv_r2d(:,:) = pv_r2d(:,:) * zscf |
---|
1337 | IF( zofs /= 0.) pv_r2d(:,:) = pv_r2d(:,:) + zofs |
---|
1338 | ELSEIF( PRESENT(pv_r3d) ) THEN |
---|
1339 | IF( zscf /= 1.) pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf |
---|
1340 | IF( zofs /= 0.) pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs |
---|
1341 | ENDIF |
---|
1342 | ! |
---|
1343 | END SUBROUTINE iom_get_123d |
---|
1344 | |
---|
1345 | SUBROUTINE iom_get_var( cdname, z2d) |
---|
1346 | CHARACTER(LEN=*), INTENT(in ) :: cdname |
---|
1347 | REAL(wp), DIMENSION(jpi,jpj) :: z2d |
---|
1348 | #if defined key_iomput |
---|
1349 | IF( xios_field_is_active( cdname, at_current_timestep_arg = .TRUE. ) ) THEN |
---|
1350 | z2d(:,:) = 0._wp |
---|
1351 | CALL xios_recv_field( cdname, z2d) |
---|
1352 | ENDIF |
---|
1353 | #else |
---|
1354 | IF( .FALSE. ) WRITE(numout,*) cdname, z2d ! useless test to avoid compilation warnings |
---|
1355 | #endif |
---|
1356 | END SUBROUTINE iom_get_var |
---|
1357 | |
---|
1358 | |
---|
1359 | FUNCTION iom_getszuld ( kiomid ) |
---|
1360 | !!----------------------------------------------------------------------- |
---|
1361 | !! *** FUNCTION iom_getszuld *** |
---|
1362 | !! |
---|
1363 | !! ** Purpose : get the size of the unlimited dimension in a file |
---|
1364 | !! (return -1 if not found) |
---|
1365 | !!----------------------------------------------------------------------- |
---|
1366 | INTEGER, INTENT(in ) :: kiomid ! file Identifier |
---|
1367 | ! |
---|
1368 | INTEGER :: iom_getszuld |
---|
1369 | !!----------------------------------------------------------------------- |
---|
1370 | iom_getszuld = -1 |
---|
1371 | IF( kiomid > 0 ) THEN |
---|
1372 | IF( iom_file(kiomid)%iduld > 0 ) iom_getszuld = iom_file(kiomid)%lenuld |
---|
1373 | ENDIF |
---|
1374 | END FUNCTION iom_getszuld |
---|
1375 | |
---|
1376 | |
---|
1377 | !!---------------------------------------------------------------------- |
---|
1378 | !! INTERFACE iom_chkatt |
---|
1379 | !!---------------------------------------------------------------------- |
---|
1380 | SUBROUTINE iom_chkatt( kiomid, cdatt, llok, ksize, cdvar ) |
---|
1381 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1382 | CHARACTER(len=*), INTENT(in ) :: cdatt ! Name of the attribute |
---|
1383 | LOGICAL , INTENT( out) :: llok ! Error code |
---|
1384 | INTEGER , INTENT( out), OPTIONAL :: ksize ! Size of the attribute array |
---|
1385 | CHARACTER(len=*), INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1386 | ! |
---|
1387 | IF( kiomid > 0 ) THEN |
---|
1388 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_chkatt( kiomid, cdatt, llok, ksize=ksize, cdvar=cdvar ) |
---|
1389 | ENDIF |
---|
1390 | ! |
---|
1391 | END SUBROUTINE iom_chkatt |
---|
1392 | |
---|
1393 | !!---------------------------------------------------------------------- |
---|
1394 | !! INTERFACE iom_getatt |
---|
1395 | !!---------------------------------------------------------------------- |
---|
1396 | SUBROUTINE iom_g0d_iatt( kiomid, cdatt, katt0d, cdvar ) |
---|
1397 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1398 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1399 | INTEGER , INTENT( out) :: katt0d ! read field |
---|
1400 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1401 | ! |
---|
1402 | IF( kiomid > 0 ) THEN |
---|
1403 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_getatt( kiomid, cdatt, katt0d = katt0d, cdvar=cdvar ) |
---|
1404 | ENDIF |
---|
1405 | END SUBROUTINE iom_g0d_iatt |
---|
1406 | |
---|
1407 | SUBROUTINE iom_g1d_iatt( kiomid, cdatt, katt1d, cdvar ) |
---|
1408 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1409 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1410 | INTEGER, DIMENSION(:) , INTENT( out) :: katt1d ! read field |
---|
1411 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1412 | ! |
---|
1413 | IF( kiomid > 0 ) THEN |
---|
1414 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_getatt( kiomid, cdatt, katt1d = katt1d, cdvar=cdvar ) |
---|
1415 | ENDIF |
---|
1416 | END SUBROUTINE iom_g1d_iatt |
---|
1417 | |
---|
1418 | SUBROUTINE iom_g0d_ratt( kiomid, cdatt, patt0d, cdvar ) |
---|
1419 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1420 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1421 | REAL(wp) , INTENT( out) :: patt0d ! read field |
---|
1422 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1423 | ! |
---|
1424 | IF( kiomid > 0 ) THEN |
---|
1425 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_getatt( kiomid, cdatt, patt0d = patt0d, cdvar=cdvar ) |
---|
1426 | ENDIF |
---|
1427 | END SUBROUTINE iom_g0d_ratt |
---|
1428 | |
---|
1429 | SUBROUTINE iom_g1d_ratt( kiomid, cdatt, patt1d, cdvar ) |
---|
1430 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1431 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1432 | REAL(wp), DIMENSION(:), INTENT( out) :: patt1d ! read field |
---|
1433 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1434 | ! |
---|
1435 | IF( kiomid > 0 ) THEN |
---|
1436 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_getatt( kiomid, cdatt, patt1d = patt1d, cdvar=cdvar ) |
---|
1437 | ENDIF |
---|
1438 | END SUBROUTINE iom_g1d_ratt |
---|
1439 | |
---|
1440 | SUBROUTINE iom_g0d_catt( kiomid, cdatt, cdatt0d, cdvar ) |
---|
1441 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1442 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1443 | CHARACTER(len=*) , INTENT( out) :: cdatt0d ! read field |
---|
1444 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1445 | ! |
---|
1446 | IF( kiomid > 0 ) THEN |
---|
1447 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_getatt( kiomid, cdatt, cdatt0d = cdatt0d, cdvar=cdvar ) |
---|
1448 | ENDIF |
---|
1449 | END SUBROUTINE iom_g0d_catt |
---|
1450 | |
---|
1451 | |
---|
1452 | !!---------------------------------------------------------------------- |
---|
1453 | !! INTERFACE iom_putatt |
---|
1454 | !!---------------------------------------------------------------------- |
---|
1455 | SUBROUTINE iom_p0d_iatt( kiomid, cdatt, katt0d, cdvar ) |
---|
1456 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1457 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1458 | INTEGER , INTENT(in ) :: katt0d ! written field |
---|
1459 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1460 | ! |
---|
1461 | IF( kiomid > 0 ) THEN |
---|
1462 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_putatt( kiomid, cdatt, katt0d = katt0d, cdvar=cdvar ) |
---|
1463 | ENDIF |
---|
1464 | END SUBROUTINE iom_p0d_iatt |
---|
1465 | |
---|
1466 | SUBROUTINE iom_p1d_iatt( kiomid, cdatt, katt1d, cdvar ) |
---|
1467 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1468 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1469 | INTEGER, DIMENSION(:) , INTENT(in ) :: katt1d ! written field |
---|
1470 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1471 | ! |
---|
1472 | IF( kiomid > 0 ) THEN |
---|
1473 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_putatt( kiomid, cdatt, katt1d = katt1d, cdvar=cdvar ) |
---|
1474 | ENDIF |
---|
1475 | END SUBROUTINE iom_p1d_iatt |
---|
1476 | |
---|
1477 | SUBROUTINE iom_p0d_ratt( kiomid, cdatt, patt0d, cdvar ) |
---|
1478 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1479 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1480 | REAL(wp) , INTENT(in ) :: patt0d ! written field |
---|
1481 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1482 | ! |
---|
1483 | IF( kiomid > 0 ) THEN |
---|
1484 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_putatt( kiomid, cdatt, patt0d = patt0d, cdvar=cdvar ) |
---|
1485 | ENDIF |
---|
1486 | END SUBROUTINE iom_p0d_ratt |
---|
1487 | |
---|
1488 | SUBROUTINE iom_p1d_ratt( kiomid, cdatt, patt1d, cdvar ) |
---|
1489 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1490 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1491 | REAL(wp), DIMENSION(:), INTENT(in ) :: patt1d ! written field |
---|
1492 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1493 | ! |
---|
1494 | IF( kiomid > 0 ) THEN |
---|
1495 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_putatt( kiomid, cdatt, patt1d = patt1d, cdvar=cdvar ) |
---|
1496 | ENDIF |
---|
1497 | END SUBROUTINE iom_p1d_ratt |
---|
1498 | |
---|
1499 | SUBROUTINE iom_p0d_catt( kiomid, cdatt, cdatt0d, cdvar ) |
---|
1500 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
1501 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! Name of the attribute |
---|
1502 | CHARACTER(len=*) , INTENT(in ) :: cdatt0d ! written field |
---|
1503 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! Name of the variable |
---|
1504 | ! |
---|
1505 | IF( kiomid > 0 ) THEN |
---|
1506 | IF( iom_file(kiomid)%nfid > 0 ) CALL iom_nf90_putatt( kiomid, cdatt, cdatt0d = cdatt0d, cdvar=cdvar ) |
---|
1507 | ENDIF |
---|
1508 | END SUBROUTINE iom_p0d_catt |
---|
1509 | |
---|
1510 | |
---|
1511 | !!---------------------------------------------------------------------- |
---|
1512 | !! INTERFACE iom_rstput |
---|
1513 | !!---------------------------------------------------------------------- |
---|
1514 | SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios ) |
---|
1515 | INTEGER , INTENT(in) :: kt ! ocean time-step |
---|
1516 | INTEGER , INTENT(in) :: kwrite ! writing time-step |
---|
1517 | INTEGER , INTENT(in) :: kiomid ! Identifier of the file |
---|
1518 | CHARACTER(len=*), INTENT(in) :: cdvar ! time axis name |
---|
1519 | REAL(wp) , INTENT(in) :: pvar ! written field |
---|
1520 | INTEGER , INTENT(in), OPTIONAL :: ktype ! variable external type |
---|
1521 | LOGICAL, OPTIONAL :: ldxios ! xios write flag |
---|
1522 | LOGICAL :: llx ! local xios write flag |
---|
1523 | INTEGER :: ivid ! variable id |
---|
1524 | |
---|
1525 | llx = .FALSE. |
---|
1526 | IF(PRESENT(ldxios)) llx = ldxios |
---|
1527 | IF( llx ) THEN |
---|
1528 | #ifdef key_iomput |
---|
1529 | IF( kt == kwrite ) THEN |
---|
1530 | IF(lwp) write(numout,*) 'RESTART: write (XIOS 0D) ',trim(cdvar) |
---|
1531 | CALL xios_send_field(trim(cdvar), pvar) |
---|
1532 | ELSE |
---|
1533 | IF(lwp) write(numout,*) 'RESTART: define (XIOS 0D) ',trim(cdvar) |
---|
1534 | CALL iom_set_rstw_active( trim(cdvar), rd0 = pvar ) |
---|
1535 | ENDIF |
---|
1536 | #endif |
---|
1537 | ELSE |
---|
1538 | IF( kiomid > 0 ) THEN |
---|
1539 | IF( iom_file(kiomid)%nfid > 0 ) THEN |
---|
1540 | ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. ) |
---|
1541 | CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar ) |
---|
1542 | ENDIF |
---|
1543 | ENDIF |
---|
1544 | ENDIF |
---|
1545 | END SUBROUTINE iom_rp0d |
---|
1546 | |
---|
1547 | SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios ) |
---|
1548 | INTEGER , INTENT(in) :: kt ! ocean time-step |
---|
1549 | INTEGER , INTENT(in) :: kwrite ! writing time-step |
---|
1550 | INTEGER , INTENT(in) :: kiomid ! Identifier of the file |
---|
1551 | CHARACTER(len=*), INTENT(in) :: cdvar ! time axis name |
---|
1552 | REAL(wp) , INTENT(in), DIMENSION( :) :: pvar ! written field |
---|
1553 | INTEGER , INTENT(in), OPTIONAL :: ktype ! variable external type |
---|
1554 | LOGICAL, OPTIONAL :: ldxios ! xios write flag |
---|
1555 | LOGICAL :: llx ! local xios write flag |
---|
1556 | INTEGER :: ivid ! variable id |
---|
1557 | |
---|
1558 | llx = .FALSE. |
---|
1559 | IF(PRESENT(ldxios)) llx = ldxios |
---|
1560 | IF( llx ) THEN |
---|
1561 | #ifdef key_iomput |
---|
1562 | IF( kt == kwrite ) THEN |
---|
1563 | IF(lwp) write(numout,*) 'RESTART: write (XIOS 1D) ',trim(cdvar) |
---|
1564 | CALL xios_send_field(trim(cdvar), pvar) |
---|
1565 | ELSE |
---|
1566 | IF(lwp) write(numout,*) 'RESTART: define (XIOS 1D) ',trim(cdvar) |
---|
1567 | CALL iom_set_rstw_active( trim(cdvar), rd1 = pvar ) |
---|
1568 | ENDIF |
---|
1569 | #endif |
---|
1570 | ELSE |
---|
1571 | IF( kiomid > 0 ) THEN |
---|
1572 | IF( iom_file(kiomid)%nfid > 0 ) THEN |
---|
1573 | ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. ) |
---|
1574 | CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar ) |
---|
1575 | ENDIF |
---|
1576 | ENDIF |
---|
1577 | ENDIF |
---|
1578 | END SUBROUTINE iom_rp1d |
---|
1579 | |
---|
1580 | SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios ) |
---|
1581 | INTEGER , INTENT(in) :: kt ! ocean time-step |
---|
1582 | INTEGER , INTENT(in) :: kwrite ! writing time-step |
---|
1583 | INTEGER , INTENT(in) :: kiomid ! Identifier of the file |
---|
1584 | CHARACTER(len=*), INTENT(in) :: cdvar ! time axis name |
---|
1585 | REAL(wp) , INTENT(in), DIMENSION(:, : ) :: pvar ! written field |
---|
1586 | INTEGER , INTENT(in), OPTIONAL :: ktype ! variable external type |
---|
1587 | LOGICAL, OPTIONAL :: ldxios ! xios write flag |
---|
1588 | LOGICAL :: llx |
---|
1589 | INTEGER :: ivid ! variable id |
---|
1590 | |
---|
1591 | llx = .FALSE. |
---|
1592 | IF(PRESENT(ldxios)) llx = ldxios |
---|
1593 | IF( llx ) THEN |
---|
1594 | #ifdef key_iomput |
---|
1595 | IF( kt == kwrite ) THEN |
---|
1596 | IF(lwp) write(numout,*) 'RESTART: write (XIOS 2D) ',trim(cdvar) |
---|
1597 | CALL xios_send_field(trim(cdvar), pvar) |
---|
1598 | ELSE |
---|
1599 | IF(lwp) write(numout,*) 'RESTART: define (XIOS 2D) ',trim(cdvar) |
---|
1600 | CALL iom_set_rstw_active( trim(cdvar), rd2 = pvar ) |
---|
1601 | ENDIF |
---|
1602 | #endif |
---|
1603 | ELSE |
---|
1604 | IF( kiomid > 0 ) THEN |
---|
1605 | IF( iom_file(kiomid)%nfid > 0 ) THEN |
---|
1606 | ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. ) |
---|
1607 | CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar ) |
---|
1608 | ENDIF |
---|
1609 | ENDIF |
---|
1610 | ENDIF |
---|
1611 | END SUBROUTINE iom_rp2d |
---|
1612 | |
---|
1613 | SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios ) |
---|
1614 | INTEGER , INTENT(in) :: kt ! ocean time-step |
---|
1615 | INTEGER , INTENT(in) :: kwrite ! writing time-step |
---|
1616 | INTEGER , INTENT(in) :: kiomid ! Identifier of the file |
---|
1617 | CHARACTER(len=*), INTENT(in) :: cdvar ! time axis name |
---|
1618 | REAL(wp) , INTENT(in), DIMENSION(:,:,:) :: pvar ! written field |
---|
1619 | INTEGER , INTENT(in), OPTIONAL :: ktype ! variable external type |
---|
1620 | LOGICAL, OPTIONAL :: ldxios ! xios write flag |
---|
1621 | LOGICAL :: llx ! local xios write flag |
---|
1622 | INTEGER :: ivid ! variable id |
---|
1623 | |
---|
1624 | llx = .FALSE. |
---|
1625 | IF(PRESENT(ldxios)) llx = ldxios |
---|
1626 | IF( llx ) THEN |
---|
1627 | #ifdef key_iomput |
---|
1628 | IF( kt == kwrite ) THEN |
---|
1629 | IF(lwp) write(numout,*) 'RESTART: write (XIOS 3D) ',trim(cdvar) |
---|
1630 | CALL xios_send_field(trim(cdvar), pvar) |
---|
1631 | ELSE |
---|
1632 | IF(lwp) write(numout,*) 'RESTART: define (XIOS 3D) ',trim(cdvar) |
---|
1633 | CALL iom_set_rstw_active( trim(cdvar), rd3 = pvar ) |
---|
1634 | ENDIF |
---|
1635 | #endif |
---|
1636 | ELSE |
---|
1637 | IF( kiomid > 0 ) THEN |
---|
1638 | IF( iom_file(kiomid)%nfid > 0 ) THEN |
---|
1639 | ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. ) |
---|
1640 | CALL iom_nf90_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar ) |
---|
1641 | ENDIF |
---|
1642 | ENDIF |
---|
1643 | ENDIF |
---|
1644 | END SUBROUTINE iom_rp3d |
---|
1645 | |
---|
1646 | |
---|
1647 | SUBROUTINE iom_delay_rst( cdaction, cdcpnt, kncid ) |
---|
1648 | !!--------------------------------------------------------------------- |
---|
1649 | !! Routine iom_delay_rst: used read/write restart related to mpp_delay |
---|
1650 | !! |
---|
1651 | !!--------------------------------------------------------------------- |
---|
1652 | CHARACTER(len=*), INTENT(in ) :: cdaction ! |
---|
1653 | CHARACTER(len=*), INTENT(in ) :: cdcpnt |
---|
1654 | INTEGER , INTENT(in ) :: kncid |
---|
1655 | ! |
---|
1656 | INTEGER :: ji |
---|
1657 | INTEGER :: indim |
---|
1658 | LOGICAL :: llattexist |
---|
1659 | REAL(wp), ALLOCATABLE, DIMENSION(:) :: zreal1d |
---|
1660 | !!--------------------------------------------------------------------- |
---|
1661 | ! |
---|
1662 | ! =================================== |
---|
1663 | IF( TRIM(cdaction) == 'READ' ) THEN ! read restart related to mpp_delay ! |
---|
1664 | ! =================================== |
---|
1665 | DO ji = 1, nbdelay |
---|
1666 | IF ( c_delaycpnt(ji) == cdcpnt ) THEN |
---|
1667 | CALL iom_chkatt( kncid, 'DELAY_'//c_delaylist(ji), llattexist, indim ) |
---|
1668 | IF( llattexist ) THEN |
---|
1669 | ALLOCATE( todelay(ji)%z1d(indim) ) |
---|
1670 | CALL iom_getatt( kncid, 'DELAY_'//c_delaylist(ji), todelay(ji)%z1d(:) ) |
---|
1671 | ndelayid(ji) = 0 ! set to 0 to specify that the value was read in the restart |
---|
1672 | ENDIF |
---|
1673 | ENDIF |
---|
1674 | END DO |
---|
1675 | ! ==================================== |
---|
1676 | ELSE ! write restart related to mpp_delay ! |
---|
1677 | ! ==================================== |
---|
1678 | DO ji = 1, nbdelay ! save only ocean delayed global communication variables |
---|
1679 | IF ( c_delaycpnt(ji) == cdcpnt ) THEN |
---|
1680 | IF( ASSOCIATED(todelay(ji)%z1d) ) THEN |
---|
1681 | CALL mpp_delay_rcv(ji) ! make sure %z1d is received |
---|
1682 | CALL iom_putatt( kncid, 'DELAY_'//c_delaylist(ji), todelay(ji)%z1d(:) ) |
---|
1683 | ENDIF |
---|
1684 | ENDIF |
---|
1685 | END DO |
---|
1686 | ! |
---|
1687 | ENDIF |
---|
1688 | |
---|
1689 | END SUBROUTINE iom_delay_rst |
---|
1690 | |
---|
1691 | |
---|
1692 | |
---|
1693 | !!---------------------------------------------------------------------- |
---|
1694 | !! INTERFACE iom_put |
---|
1695 | !!---------------------------------------------------------------------- |
---|
1696 | SUBROUTINE iom_p0d( cdname, pfield0d ) |
---|
1697 | CHARACTER(LEN=*), INTENT(in) :: cdname |
---|
1698 | REAL(wp) , INTENT(in) :: pfield0d |
---|
1699 | !! REAL(wp) , DIMENSION(jpi,jpj) :: zz ! masson |
---|
1700 | #if defined key_iomput |
---|
1701 | !!clem zz(:,:)=pfield0d |
---|
1702 | !!clem CALL xios_send_field(cdname, zz) |
---|
1703 | CALL xios_send_field(cdname, (/pfield0d/)) |
---|
1704 | #else |
---|
1705 | IF( .FALSE. ) WRITE(numout,*) cdname, pfield0d ! useless test to avoid compilation warnings |
---|
1706 | #endif |
---|
1707 | END SUBROUTINE iom_p0d |
---|
1708 | |
---|
1709 | SUBROUTINE iom_p1d( cdname, pfield1d ) |
---|
1710 | CHARACTER(LEN=*) , INTENT(in) :: cdname |
---|
1711 | REAL(wp), DIMENSION(:), INTENT(in) :: pfield1d |
---|
1712 | #if defined key_iomput |
---|
1713 | CALL xios_send_field( cdname, RESHAPE( (/pfield1d/), (/1,1,SIZE(pfield1d)/) ) ) |
---|
1714 | #else |
---|
1715 | IF( .FALSE. ) WRITE(numout,*) cdname, pfield1d ! useless test to avoid compilation warnings |
---|
1716 | #endif |
---|
1717 | END SUBROUTINE iom_p1d |
---|
1718 | |
---|
1719 | SUBROUTINE iom_p2d( cdname, pfield2d ) |
---|
1720 | CHARACTER(LEN=*) , INTENT(in) :: cdname |
---|
1721 | REAL(wp), DIMENSION(:,:), INTENT(in) :: pfield2d |
---|
1722 | #if defined key_iomput |
---|
1723 | CALL xios_send_field(cdname, pfield2d) |
---|
1724 | #else |
---|
1725 | IF( .FALSE. ) WRITE(numout,*) cdname, pfield2d ! useless test to avoid compilation warnings |
---|
1726 | #endif |
---|
1727 | END SUBROUTINE iom_p2d |
---|
1728 | |
---|
1729 | SUBROUTINE iom_p3d( cdname, pfield3d ) |
---|
1730 | CHARACTER(LEN=*) , INTENT(in) :: cdname |
---|
1731 | REAL(wp), DIMENSION(:,:,:), INTENT(in) :: pfield3d |
---|
1732 | #if defined key_iomput |
---|
1733 | CALL xios_send_field( cdname, pfield3d ) |
---|
1734 | #else |
---|
1735 | IF( .FALSE. ) WRITE(numout,*) cdname, pfield3d ! useless test to avoid compilation warnings |
---|
1736 | #endif |
---|
1737 | END SUBROUTINE iom_p3d |
---|
1738 | |
---|
1739 | SUBROUTINE iom_p4d( cdname, pfield4d ) |
---|
1740 | CHARACTER(LEN=*) , INTENT(in) :: cdname |
---|
1741 | REAL(wp), DIMENSION(:,:,:,:), INTENT(in) :: pfield4d |
---|
1742 | #if defined key_iomput |
---|
1743 | CALL xios_send_field(cdname, pfield4d) |
---|
1744 | #else |
---|
1745 | IF( .FALSE. ) WRITE(numout,*) cdname, pfield4d ! useless test to avoid compilation warnings |
---|
1746 | #endif |
---|
1747 | END SUBROUTINE iom_p4d |
---|
1748 | |
---|
1749 | |
---|
1750 | #if defined key_iomput |
---|
1751 | !!---------------------------------------------------------------------- |
---|
1752 | !! 'key_iomput' XIOS interface |
---|
1753 | !!---------------------------------------------------------------------- |
---|
1754 | |
---|
1755 | SUBROUTINE iom_set_domain_attr( cdid, ni_glo, nj_glo, ibegin, jbegin, ni, nj, & |
---|
1756 | & data_dim, data_ibegin, data_ni, data_jbegin, data_nj, lonvalue, latvalue, mask, & |
---|
1757 | & nvertex, bounds_lon, bounds_lat, area ) |
---|
1758 | !!---------------------------------------------------------------------- |
---|
1759 | !!---------------------------------------------------------------------- |
---|
1760 | CHARACTER(LEN=*) , INTENT(in) :: cdid |
---|
1761 | INTEGER , OPTIONAL, INTENT(in) :: ni_glo, nj_glo, ibegin, jbegin, ni, nj |
---|
1762 | INTEGER , OPTIONAL, INTENT(in) :: data_dim, data_ibegin, data_ni, data_jbegin, data_nj |
---|
1763 | INTEGER , OPTIONAL, INTENT(in) :: nvertex |
---|
1764 | REAL(wp), DIMENSION(:) , OPTIONAL, INTENT(in) :: lonvalue, latvalue |
---|
1765 | REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(in) :: bounds_lon, bounds_lat, area |
---|
1766 | LOGICAL , DIMENSION(:) , OPTIONAL, INTENT(in) :: mask |
---|
1767 | !!---------------------------------------------------------------------- |
---|
1768 | ! |
---|
1769 | IF( xios_is_valid_domain (cdid) ) THEN |
---|
1770 | CALL xios_set_domain_attr ( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj, & |
---|
1771 | & data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj , & |
---|
1772 | & lonvalue_1D=lonvalue, latvalue_1D=latvalue, mask_1D=mask, nvertex=nvertex, bounds_lon_1D=bounds_lon, & |
---|
1773 | & bounds_lat_1D=bounds_lat, area=area, type='curvilinear') |
---|
1774 | ENDIF |
---|
1775 | IF( xios_is_valid_domaingroup(cdid) ) THEN |
---|
1776 | CALL xios_set_domaingroup_attr( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj, & |
---|
1777 | & data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj , & |
---|
1778 | & lonvalue_1D=lonvalue, latvalue_1D=latvalue, mask_1D=mask, nvertex=nvertex, bounds_lon_1D=bounds_lon, & |
---|
1779 | & bounds_lat_1D=bounds_lat, area=area, type='curvilinear' ) |
---|
1780 | ENDIF |
---|
1781 | ! |
---|
1782 | CALL xios_solve_inheritance() |
---|
1783 | ! |
---|
1784 | END SUBROUTINE iom_set_domain_attr |
---|
1785 | |
---|
1786 | |
---|
1787 | SUBROUTINE iom_set_zoom_domain_attr( cdid, ibegin, jbegin, ni, nj ) |
---|
1788 | !!---------------------------------------------------------------------- |
---|
1789 | !!---------------------------------------------------------------------- |
---|
1790 | CHARACTER(LEN=*), INTENT(in) :: cdid |
---|
1791 | INTEGER , INTENT(in) :: ibegin, jbegin, ni, nj |
---|
1792 | ! |
---|
1793 | TYPE(xios_gridgroup) :: gridgroup_hdl |
---|
1794 | TYPE(xios_grid) :: grid_hdl |
---|
1795 | TYPE(xios_domain) :: domain_hdl |
---|
1796 | TYPE(xios_axis) :: axis_hdl |
---|
1797 | CHARACTER(LEN=64) :: cldomrefid ! domain_ref name |
---|
1798 | CHARACTER(len=1) :: cl1 ! last character of this name |
---|
1799 | !!---------------------------------------------------------------------- |
---|
1800 | ! |
---|
1801 | IF( xios_is_valid_zoom_domain(cdid) ) THEN |
---|
1802 | ! define the zoom_domain attributs |
---|
1803 | CALL xios_set_zoom_domain_attr( cdid, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj ) |
---|
1804 | ! define a new 2D grid with this new domain |
---|
1805 | CALL xios_get_handle("grid_definition", gridgroup_hdl ) |
---|
1806 | CALL xios_add_child(gridgroup_hdl, grid_hdl, TRIM(cdid)//'_2D' ) ! add a new 2D grid to grid_definition |
---|
1807 | CALL xios_add_child(grid_hdl, domain_hdl, TRIM(cdid) ) ! add its domain |
---|
1808 | ! define a new 3D grid with this new domain |
---|
1809 | CALL xios_add_child(gridgroup_hdl, grid_hdl, TRIM(cdid)//'_3D' ) ! add a new 3D grid to grid_definition |
---|
1810 | CALL xios_add_child(grid_hdl, domain_hdl, TRIM(cdid) ) ! add its domain |
---|
1811 | ! vertical axis |
---|
1812 | cl1 = cdid(LEN_TRIM(cdid):) ! last letter of cdid |
---|
1813 | cl1 = CHAR(ICHAR(cl1)+32) ! from upper to lower case |
---|
1814 | CALL xios_add_child(grid_hdl, axis_hdl, 'depth'//cl1) ! add its axis |
---|
1815 | ENDIF |
---|
1816 | ! |
---|
1817 | END SUBROUTINE iom_set_zoom_domain_attr |
---|
1818 | |
---|
1819 | |
---|
1820 | SUBROUTINE iom_set_axis_attr( cdid, paxis, bounds ) |
---|
1821 | !!---------------------------------------------------------------------- |
---|
1822 | !!---------------------------------------------------------------------- |
---|
1823 | CHARACTER(LEN=*) , INTENT(in) :: cdid |
---|
1824 | REAL(wp), DIMENSION(:) , OPTIONAL, INTENT(in) :: paxis |
---|
1825 | REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(in) :: bounds |
---|
1826 | !!---------------------------------------------------------------------- |
---|
1827 | IF( PRESENT(paxis) ) THEN |
---|
1828 | IF( xios_is_valid_axis (cdid) ) CALL xios_set_axis_attr ( cdid, n_glo=SIZE(paxis), value=paxis ) |
---|
1829 | IF( xios_is_valid_axisgroup(cdid) ) CALL xios_set_axisgroup_attr( cdid, n_glo=SIZE(paxis), value=paxis ) |
---|
1830 | ENDIF |
---|
1831 | IF( xios_is_valid_axis (cdid) ) CALL xios_set_axis_attr ( cdid, bounds=bounds ) |
---|
1832 | IF( xios_is_valid_axisgroup(cdid) ) CALL xios_set_axisgroup_attr( cdid, bounds=bounds ) |
---|
1833 | CALL xios_solve_inheritance() |
---|
1834 | END SUBROUTINE iom_set_axis_attr |
---|
1835 | |
---|
1836 | |
---|
1837 | SUBROUTINE iom_set_field_attr( cdid, freq_op, freq_offset ) |
---|
1838 | !!---------------------------------------------------------------------- |
---|
1839 | !!---------------------------------------------------------------------- |
---|
1840 | CHARACTER(LEN=*) , INTENT(in) :: cdid |
---|
1841 | TYPE(xios_duration), OPTIONAL, INTENT(in) :: freq_op |
---|
1842 | TYPE(xios_duration), OPTIONAL, INTENT(in) :: freq_offset |
---|
1843 | !!---------------------------------------------------------------------- |
---|
1844 | IF( xios_is_valid_field (cdid) ) CALL xios_set_field_attr ( cdid, freq_op=freq_op, freq_offset=freq_offset ) |
---|
1845 | IF( xios_is_valid_fieldgroup(cdid) ) CALL xios_set_fieldgroup_attr( cdid, freq_op=freq_op, freq_offset=freq_offset ) |
---|
1846 | CALL xios_solve_inheritance() |
---|
1847 | END SUBROUTINE iom_set_field_attr |
---|
1848 | |
---|
1849 | |
---|
1850 | SUBROUTINE iom_set_file_attr( cdid, name, name_suffix ) |
---|
1851 | !!---------------------------------------------------------------------- |
---|
1852 | !!---------------------------------------------------------------------- |
---|
1853 | CHARACTER(LEN=*) , INTENT(in) :: cdid |
---|
1854 | CHARACTER(LEN=*),OPTIONAL , INTENT(in) :: name, name_suffix |
---|
1855 | !!---------------------------------------------------------------------- |
---|
1856 | IF( xios_is_valid_file (cdid) ) CALL xios_set_file_attr ( cdid, name=name, name_suffix=name_suffix ) |
---|
1857 | IF( xios_is_valid_filegroup(cdid) ) CALL xios_set_filegroup_attr( cdid, name=name, name_suffix=name_suffix ) |
---|
1858 | CALL xios_solve_inheritance() |
---|
1859 | END SUBROUTINE iom_set_file_attr |
---|
1860 | |
---|
1861 | |
---|
1862 | SUBROUTINE iom_get_file_attr( cdid, name, name_suffix, output_freq ) |
---|
1863 | !!---------------------------------------------------------------------- |
---|
1864 | !!---------------------------------------------------------------------- |
---|
1865 | CHARACTER(LEN=*) , INTENT(in ) :: cdid |
---|
1866 | CHARACTER(LEN=*),OPTIONAL , INTENT(out) :: name, name_suffix |
---|
1867 | TYPE(xios_duration), OPTIONAL , INTENT(out) :: output_freq |
---|
1868 | LOGICAL :: llexist1,llexist2,llexist3 |
---|
1869 | !--------------------------------------------------------------------- |
---|
1870 | IF( PRESENT( name ) ) name = '' ! default values |
---|
1871 | IF( PRESENT( name_suffix ) ) name_suffix = '' |
---|
1872 | IF( PRESENT( output_freq ) ) output_freq = xios_duration(0,0,0,0,0,0) |
---|
1873 | IF( xios_is_valid_file (cdid) ) THEN |
---|
1874 | CALL xios_solve_inheritance() |
---|
1875 | CALL xios_is_defined_file_attr ( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3) |
---|
1876 | IF(llexist1) CALL xios_get_file_attr ( cdid, name = name ) |
---|
1877 | IF(llexist2) CALL xios_get_file_attr ( cdid, name_suffix = name_suffix ) |
---|
1878 | IF(llexist3) CALL xios_get_file_attr ( cdid, output_freq = output_freq ) |
---|
1879 | ENDIF |
---|
1880 | IF( xios_is_valid_filegroup(cdid) ) THEN |
---|
1881 | CALL xios_solve_inheritance() |
---|
1882 | CALL xios_is_defined_filegroup_attr( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3) |
---|
1883 | IF(llexist1) CALL xios_get_filegroup_attr( cdid, name = name ) |
---|
1884 | IF(llexist2) CALL xios_get_filegroup_attr( cdid, name_suffix = name_suffix ) |
---|
1885 | IF(llexist3) CALL xios_get_filegroup_attr( cdid, output_freq = output_freq ) |
---|
1886 | ENDIF |
---|
1887 | END SUBROUTINE iom_get_file_attr |
---|
1888 | |
---|
1889 | |
---|
1890 | SUBROUTINE iom_set_grid_attr( cdid, mask ) |
---|
1891 | !!---------------------------------------------------------------------- |
---|
1892 | !!---------------------------------------------------------------------- |
---|
1893 | CHARACTER(LEN=*) , INTENT(in) :: cdid |
---|
1894 | LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(in) :: mask |
---|
1895 | !!---------------------------------------------------------------------- |
---|
1896 | IF( xios_is_valid_grid (cdid) ) CALL xios_set_grid_attr ( cdid, mask_3D=mask ) |
---|
1897 | IF( xios_is_valid_gridgroup(cdid) ) CALL xios_set_gridgroup_attr( cdid, mask_3D=mask ) |
---|
1898 | CALL xios_solve_inheritance() |
---|
1899 | END SUBROUTINE iom_set_grid_attr |
---|
1900 | |
---|
1901 | SUBROUTINE iom_setkt( kt, cdname ) |
---|
1902 | !!---------------------------------------------------------------------- |
---|
1903 | !!---------------------------------------------------------------------- |
---|
1904 | INTEGER , INTENT(in) :: kt |
---|
1905 | CHARACTER(LEN=*), INTENT(in) :: cdname |
---|
1906 | !!---------------------------------------------------------------------- |
---|
1907 | CALL iom_swap( cdname ) ! swap to cdname context |
---|
1908 | CALL xios_update_calendar(kt) |
---|
1909 | IF( cdname /= TRIM(cxios_context) ) CALL iom_swap( TRIM(cxios_context) ) ! return back to nemo context |
---|
1910 | END SUBROUTINE iom_setkt |
---|
1911 | |
---|
1912 | SUBROUTINE iom_context_finalize( cdname ) |
---|
1913 | !!---------------------------------------------------------------------- |
---|
1914 | !!---------------------------------------------------------------------- |
---|
1915 | CHARACTER(LEN=*), INTENT(in) :: cdname |
---|
1916 | CHARACTER(LEN=120) :: clname |
---|
1917 | !!---------------------------------------------------------------------- |
---|
1918 | clname = cdname |
---|
1919 | IF(lwp) write(numout, *) 'Finalize: ', TRIM(cdname) |
---|
1920 | IF( TRIM(Agrif_CFixed()) .NE. '0' ) clname = TRIM(Agrif_CFixed())//"_"//clname |
---|
1921 | IF( xios_is_valid_context(clname) ) THEN |
---|
1922 | CALL iom_swap( cdname ) ! swap to cdname context |
---|
1923 | CALL xios_context_finalize() ! finalize the context |
---|
1924 | IF( cdname /= TRIM(cxios_context) ) CALL iom_swap( TRIM(cxios_context) ) ! return back to nemo context |
---|
1925 | ENDIF |
---|
1926 | ! |
---|
1927 | END SUBROUTINE iom_context_finalize |
---|
1928 | |
---|
1929 | |
---|
1930 | SUBROUTINE set_grid( cdgrd, plon, plat, ldxios, ldrxios ) |
---|
1931 | !!---------------------------------------------------------------------- |
---|
1932 | !! *** ROUTINE set_grid *** |
---|
1933 | !! |
---|
1934 | !! ** Purpose : define horizontal grids |
---|
1935 | !!---------------------------------------------------------------------- |
---|
1936 | CHARACTER(LEN=1) , INTENT(in) :: cdgrd |
---|
1937 | REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: plon |
---|
1938 | REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: plat |
---|
1939 | ! |
---|
1940 | INTEGER :: ni, nj |
---|
1941 | REAL(wp), DIMENSION(jpi,jpj,jpk) :: zmask |
---|
1942 | LOGICAL, INTENT(IN) :: ldxios, ldrxios |
---|
1943 | !!---------------------------------------------------------------------- |
---|
1944 | ! |
---|
1945 | ni = nlei-nldi+1 |
---|
1946 | nj = nlej-nldj+1 |
---|
1947 | ! |
---|
1948 | CALL iom_set_domain_attr("grid_"//cdgrd, ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj) |
---|
1949 | CALL iom_set_domain_attr("grid_"//cdgrd, data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj) |
---|
1950 | !don't define lon and lat for restart reading context. |
---|
1951 | IF ( .NOT.ldrxios ) & |
---|
1952 | CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = RESHAPE(plon(nldi:nlei, nldj:nlej),(/ ni*nj /)), & |
---|
1953 | & latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /))) |
---|
1954 | ! |
---|
1955 | IF ( ln_mskland .AND. (.NOT.ldxios) ) THEN |
---|
1956 | ! mask land points, keep values on coast line -> specific mask for U, V and W points |
---|
1957 | SELECT CASE ( cdgrd ) |
---|
1958 | CASE('T') ; zmask(:,:,:) = tmask(:,:,:) |
---|
1959 | CASE('U') ; zmask(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:) ; CALL lbc_lnk( 'iom', zmask, 'U', 1. ) |
---|
1960 | CASE('V') ; zmask(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:) ; CALL lbc_lnk( 'iom', zmask, 'V', 1. ) |
---|
1961 | CASE('W') ; zmask(:,:,2:jpk ) = tmask(:,:,1:jpkm1) + tmask(:,:,2:jpk) ; zmask(:,:,1) = tmask(:,:,1) |
---|
1962 | END SELECT |
---|
1963 | ! |
---|
1964 | CALL iom_set_domain_attr( "grid_"//cdgrd , mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,1),(/ni*nj /)) /= 0. ) |
---|
1965 | CALL iom_set_grid_attr ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,:),(/ni,nj,jpk/)) /= 0. ) |
---|
1966 | ENDIF |
---|
1967 | ! |
---|
1968 | END SUBROUTINE set_grid |
---|
1969 | |
---|
1970 | |
---|
1971 | SUBROUTINE set_grid_bounds( cdgrd, plon_cnr, plat_cnr, plon_pnt, plat_pnt ) |
---|
1972 | !!---------------------------------------------------------------------- |
---|
1973 | !! *** ROUTINE set_grid_bounds *** |
---|
1974 | !! |
---|
1975 | !! ** Purpose : define horizontal grid corners |
---|
1976 | !! |
---|
1977 | !!---------------------------------------------------------------------- |
---|
1978 | CHARACTER(LEN=1) , INTENT(in) :: cdgrd |
---|
1979 | REAL(wp), DIMENSION(jpi,jpj) , INTENT(in) :: plon_cnr, plat_cnr ! Lat/lon coord. of a contiguous vertex of cell (i,j) |
---|
1980 | REAL(wp), DIMENSION(jpi,jpj), OPTIONAL, INTENT(in) :: plon_pnt, plat_pnt ! Lat/lon coord. of the point of cell (i,j) |
---|
1981 | ! |
---|
1982 | INTEGER :: ji, jj, jn, ni, nj |
---|
1983 | INTEGER :: icnr, jcnr ! Offset such that the vertex coordinate (i+icnr,j+jcnr) |
---|
1984 | ! ! represents the bottom-left corner of cell (i,j) |
---|
1985 | REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: z_bnds ! Lat/lon coordinates of the vertices of cell (i,j) |
---|
1986 | REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_fld ! Working array to determine where to rotate cells |
---|
1987 | REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_rot ! Lat/lon working array for rotation of cells |
---|
1988 | !!---------------------------------------------------------------------- |
---|
1989 | ! |
---|
1990 | ALLOCATE( z_bnds(4,jpi,jpj,2), z_fld(jpi,jpj), z_rot(4,2) ) |
---|
1991 | ! |
---|
1992 | ! Offset of coordinate representing bottom-left corner |
---|
1993 | SELECT CASE ( TRIM(cdgrd) ) |
---|
1994 | CASE ('T', 'W') ; icnr = -1 ; jcnr = -1 |
---|
1995 | CASE ('U') ; icnr = 0 ; jcnr = -1 |
---|
1996 | CASE ('V') ; icnr = -1 ; jcnr = 0 |
---|
1997 | END SELECT |
---|
1998 | ! |
---|
1999 | ni = nlei-nldi+1 ! Dimensions of subdomain interior |
---|
2000 | nj = nlej-nldj+1 |
---|
2001 | ! |
---|
2002 | z_fld(:,:) = 1._wp |
---|
2003 | CALL lbc_lnk( 'iom', z_fld, cdgrd, -1. ) ! Working array for location of northfold |
---|
2004 | ! |
---|
2005 | ! Cell vertices that can be defined |
---|
2006 | DO jj = 2, jpjm1 |
---|
2007 | DO ji = 2, jpim1 |
---|
2008 | z_bnds(1,ji,jj,1) = plat_cnr(ji+icnr, jj+jcnr ) ! Bottom-left |
---|
2009 | z_bnds(2,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr ) ! Bottom-right |
---|
2010 | z_bnds(3,ji,jj,1) = plat_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right |
---|
2011 | z_bnds(4,ji,jj,1) = plat_cnr(ji+icnr, jj+jcnr+1) ! Top-left |
---|
2012 | z_bnds(1,ji,jj,2) = plon_cnr(ji+icnr, jj+jcnr ) ! Bottom-left |
---|
2013 | z_bnds(2,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr ) ! Bottom-right |
---|
2014 | z_bnds(3,ji,jj,2) = plon_cnr(ji+icnr+1,jj+jcnr+1) ! Top-right |
---|
2015 | z_bnds(4,ji,jj,2) = plon_cnr(ji+icnr, jj+jcnr+1) ! Top-left |
---|
2016 | END DO |
---|
2017 | END DO |
---|
2018 | ! |
---|
2019 | ! Cell vertices on boundries |
---|
2020 | DO jn = 1, 4 |
---|
2021 | CALL lbc_lnk( 'iom', z_bnds(jn,:,:,1), cdgrd, 1., pfillval=999._wp ) |
---|
2022 | CALL lbc_lnk( 'iom', z_bnds(jn,:,:,2), cdgrd, 1., pfillval=999._wp ) |
---|
2023 | END DO |
---|
2024 | ! |
---|
2025 | ! Zero-size cells at closed boundaries if cell points provided, |
---|
2026 | ! otherwise they are closed cells with unrealistic bounds |
---|
2027 | IF( PRESENT(plon_pnt) .AND. PRESENT(plat_pnt) ) THEN |
---|
2028 | IF( (nbondi == -1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN |
---|
2029 | DO jn = 1, 4 ! (West or jpni = 1), closed E-W |
---|
2030 | z_bnds(jn,1,:,1) = plat_pnt(1,:) ; z_bnds(jn,1,:,2) = plon_pnt(1,:) |
---|
2031 | END DO |
---|
2032 | ENDIF |
---|
2033 | IF( (nbondi == 1 .OR. nbondi == 2) .AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6) ) THEN |
---|
2034 | DO jn = 1, 4 ! (East or jpni = 1), closed E-W |
---|
2035 | z_bnds(jn,nlci,:,1) = plat_pnt(nlci,:) ; z_bnds(jn,nlci,:,2) = plon_pnt(nlci,:) |
---|
2036 | END DO |
---|
2037 | ENDIF |
---|
2038 | IF( nbondj == -1 .OR. (nbondj == 2 .AND. jperio /= 2) ) THEN |
---|
2039 | DO jn = 1, 4 ! South or (jpnj = 1, not symmetric) |
---|
2040 | z_bnds(jn,:,1,1) = plat_pnt(:,1) ; z_bnds(jn,:,1,2) = plon_pnt(:,1) |
---|
2041 | END DO |
---|
2042 | ENDIF |
---|
2043 | IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio < 3 ) THEN |
---|
2044 | DO jn = 1, 4 ! (North or jpnj = 1), no north fold |
---|
2045 | z_bnds(jn,:,nlcj,1) = plat_pnt(:,nlcj) ; z_bnds(jn,:,nlcj,2) = plon_pnt(:,nlcj) |
---|
2046 | END DO |
---|
2047 | ENDIF |
---|
2048 | ENDIF |
---|
2049 | ! |
---|
2050 | IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio >= 3 ) THEN ! Rotate cells at the north fold |
---|
2051 | DO jj = 1, jpj |
---|
2052 | DO ji = 1, jpi |
---|
2053 | IF( z_fld(ji,jj) == -1. ) THEN |
---|
2054 | z_rot(1,:) = z_bnds(3,ji,jj,:) ; z_rot(2,:) = z_bnds(4,ji,jj,:) |
---|
2055 | z_rot(3,:) = z_bnds(1,ji,jj,:) ; z_rot(4,:) = z_bnds(2,ji,jj,:) |
---|
2056 | z_bnds(:,ji,jj,:) = z_rot(:,:) |
---|
2057 | ENDIF |
---|
2058 | END DO |
---|
2059 | END DO |
---|
2060 | ELSE IF( nbondj == 2 .AND. jperio == 2 ) THEN ! Invert cells at the symmetric equator |
---|
2061 | DO ji = 1, jpi |
---|
2062 | z_rot(1:2,:) = z_bnds(3:4,ji,1,:) |
---|
2063 | z_rot(3:4,:) = z_bnds(1:2,ji,1,:) |
---|
2064 | z_bnds(:,ji,1,:) = z_rot(:,:) |
---|
2065 | END DO |
---|
2066 | ENDIF |
---|
2067 | ! |
---|
2068 | CALL iom_set_domain_attr("grid_"//cdgrd, bounds_lat = RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,1),(/ 4,ni*nj /)), & |
---|
2069 | & bounds_lon = RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,2),(/ 4,ni*nj /)), nvertex=4 ) |
---|
2070 | ! |
---|
2071 | DEALLOCATE( z_bnds, z_fld, z_rot ) |
---|
2072 | ! |
---|
2073 | END SUBROUTINE set_grid_bounds |
---|
2074 | |
---|
2075 | |
---|
2076 | SUBROUTINE set_grid_znl( plat ) |
---|
2077 | !!---------------------------------------------------------------------- |
---|
2078 | !! *** ROUTINE set_grid_znl *** |
---|
2079 | !! |
---|
2080 | !! ** Purpose : define grids for zonal mean |
---|
2081 | !! |
---|
2082 | !!---------------------------------------------------------------------- |
---|
2083 | REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: plat |
---|
2084 | ! |
---|
2085 | INTEGER :: ni, nj, ix, iy |
---|
2086 | REAL(wp), DIMENSION(:), ALLOCATABLE :: zlon |
---|
2087 | !!---------------------------------------------------------------------- |
---|
2088 | ! |
---|
2089 | ni=nlei-nldi+1 ! define zonal mean domain (jpj*jpk) |
---|
2090 | nj=nlej-nldj+1 |
---|
2091 | ALLOCATE( zlon(ni*nj) ) ; zlon(:) = 0._wp |
---|
2092 | ! |
---|
2093 | ! CALL dom_ngb( -168.53, 65.03, ix, iy, 'T' ) ! i-line that passes through Bering Strait: Reference latitude (used in plots) |
---|
2094 | CALL dom_ngb( 180., 90., ix, iy, 'T' ) ! i-line that passes near the North Pole : Reference latitude (used in plots) |
---|
2095 | CALL iom_set_domain_attr("gznl", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj) |
---|
2096 | CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj) |
---|
2097 | CALL iom_set_domain_attr("gznl", lonvalue = zlon, & |
---|
2098 | & latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /))) |
---|
2099 | CALL iom_set_zoom_domain_attr("ptr", ibegin=ix-1, jbegin=0, ni=1, nj=jpjglo) |
---|
2100 | ! |
---|
2101 | CALL iom_update_file_name('ptr') |
---|
2102 | ! |
---|
2103 | END SUBROUTINE set_grid_znl |
---|
2104 | |
---|
2105 | |
---|
2106 | SUBROUTINE set_scalar |
---|
2107 | !!---------------------------------------------------------------------- |
---|
2108 | !! *** ROUTINE set_scalar *** |
---|
2109 | !! |
---|
2110 | !! ** Purpose : define fake grids for scalar point |
---|
2111 | !! |
---|
2112 | !!---------------------------------------------------------------------- |
---|
2113 | REAL(wp), DIMENSION(1) :: zz = 1. |
---|
2114 | !!---------------------------------------------------------------------- |
---|
2115 | ! |
---|
2116 | CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea-1, jbegin=0, ni=1, nj=1) |
---|
2117 | CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 1, data_ni = 1, data_jbegin = 1, data_nj = 1) |
---|
2118 | ! |
---|
2119 | zz = REAL( narea, wp ) |
---|
2120 | CALL iom_set_domain_attr('scalarpoint', lonvalue=zz, latvalue=zz) |
---|
2121 | ! |
---|
2122 | END SUBROUTINE set_scalar |
---|
2123 | |
---|
2124 | |
---|
2125 | SUBROUTINE set_xmlatt |
---|
2126 | !!---------------------------------------------------------------------- |
---|
2127 | !! *** ROUTINE set_xmlatt *** |
---|
2128 | !! |
---|
2129 | !! ** Purpose : automatic definitions of some of the xml attributs... |
---|
2130 | !! |
---|
2131 | !!---------------------------------------------------------------------- |
---|
2132 | CHARACTER(len=1),DIMENSION( 3) :: clgrd ! suffix name |
---|
2133 | CHARACTER(len=256) :: clsuff ! suffix name |
---|
2134 | CHARACTER(len=1) :: cl1 ! 1 character |
---|
2135 | CHARACTER(len=2) :: cl2 ! 2 characters |
---|
2136 | CHARACTER(len=3) :: cl3 ! 3 characters |
---|
2137 | INTEGER :: ji, jg ! loop counters |
---|
2138 | INTEGER :: ix, iy ! i-,j- index |
---|
2139 | REAL(wp) ,DIMENSION(11) :: zlontao ! longitudes of tao moorings |
---|
2140 | REAL(wp) ,DIMENSION( 7) :: zlattao ! latitudes of tao moorings |
---|
2141 | REAL(wp) ,DIMENSION( 4) :: zlonrama ! longitudes of rama moorings |
---|
2142 | REAL(wp) ,DIMENSION(11) :: zlatrama ! latitudes of rama moorings |
---|
2143 | REAL(wp) ,DIMENSION( 3) :: zlonpira ! longitudes of pirata moorings |
---|
2144 | REAL(wp) ,DIMENSION( 9) :: zlatpira ! latitudes of pirata moorings |
---|
2145 | TYPE(xios_duration) :: f_op, f_of |
---|
2146 | !!---------------------------------------------------------------------- |
---|
2147 | ! |
---|
2148 | ! frequency of the call of iom_put (attribut: freq_op) |
---|
2149 | f_op%timestep = 1 ; f_of%timestep = 0 ; CALL iom_set_field_attr('field_definition', freq_op=f_op, freq_offset=f_of) |
---|
2150 | f_op%timestep = 2 ; f_of%timestep = 0 ; CALL iom_set_field_attr('trendT_even' , freq_op=f_op, freq_offset=f_of) |
---|
2151 | f_op%timestep = 2 ; f_of%timestep = -1 ; CALL iom_set_field_attr('trendT_odd' , freq_op=f_op, freq_offset=f_of) |
---|
2152 | f_op%timestep = nn_fsbc ; f_of%timestep = 0 ; CALL iom_set_field_attr('SBC' , freq_op=f_op, freq_offset=f_of) |
---|
2153 | f_op%timestep = nn_fsbc ; f_of%timestep = 0 ; CALL iom_set_field_attr('SBC_scalar' , freq_op=f_op, freq_offset=f_of) |
---|
2154 | f_op%timestep = nn_fsbc ; f_of%timestep = 0 ; CALL iom_set_field_attr('ABL' , freq_op=f_op, freq_offset=f_of) |
---|
2155 | |
---|
2156 | ! output file names (attribut: name) |
---|
2157 | DO ji = 1, 9 |
---|
2158 | WRITE(cl1,'(i1)') ji |
---|
2159 | CALL iom_update_file_name('file'//cl1) |
---|
2160 | END DO |
---|
2161 | DO ji = 1, 99 |
---|
2162 | WRITE(cl2,'(i2.2)') ji |
---|
2163 | CALL iom_update_file_name('file'//cl2) |
---|
2164 | END DO |
---|
2165 | DO ji = 1, 999 |
---|
2166 | WRITE(cl3,'(i3.3)') ji |
---|
2167 | CALL iom_update_file_name('file'//cl3) |
---|
2168 | END DO |
---|
2169 | |
---|
2170 | ! Zooms... |
---|
2171 | clgrd = (/ 'T', 'U', 'W' /) |
---|
2172 | DO jg = 1, SIZE(clgrd) ! grid type |
---|
2173 | cl1 = clgrd(jg) |
---|
2174 | ! Equatorial section (attributs: jbegin, ni, name_suffix) |
---|
2175 | CALL dom_ngb( 0., 0., ix, iy, cl1 ) |
---|
2176 | CALL iom_set_zoom_domain_attr('Eq'//cl1, ibegin=0, jbegin=iy-1, ni=jpiglo, nj=1 ) |
---|
2177 | CALL iom_get_file_attr ('Eq'//cl1, name_suffix = clsuff ) |
---|
2178 | CALL iom_set_file_attr ('Eq'//cl1, name_suffix = TRIM(clsuff)//'_Eq') |
---|
2179 | CALL iom_update_file_name('Eq'//cl1) |
---|
2180 | END DO |
---|
2181 | ! TAO moorings (attributs: ibegin, jbegin, name_suffix) |
---|
2182 | zlontao = (/ 137.0, 147.0, 156.0, 165.0, -180.0, -170.0, -155.0, -140.0, -125.0, -110.0, -95.0 /) |
---|
2183 | zlattao = (/ -8.0, -5.0, -2.0, 0.0, 2.0, 5.0, 8.0 /) |
---|
2184 | CALL set_mooring( zlontao, zlattao ) |
---|
2185 | ! RAMA moorings (attributs: ibegin, jbegin, name_suffix) |
---|
2186 | zlonrama = (/ 55.0, 67.0, 80.5, 90.0 /) |
---|
2187 | zlatrama = (/ -16.0, -12.0, -8.0, -4.0, -1.5, 0.0, 1.5, 4.0, 8.0, 12.0, 15.0 /) |
---|
2188 | CALL set_mooring( zlonrama, zlatrama ) |
---|
2189 | ! PIRATA moorings (attributs: ibegin, jbegin, name_suffix) |
---|
2190 | zlonpira = (/ -38.0, -23.0, -10.0 /) |
---|
2191 | zlatpira = (/ -19.0, -14.0, -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /) |
---|
2192 | CALL set_mooring( zlonpira, zlatpira ) |
---|
2193 | ! |
---|
2194 | END SUBROUTINE set_xmlatt |
---|
2195 | |
---|
2196 | |
---|
2197 | SUBROUTINE set_mooring( plon, plat ) |
---|
2198 | !!---------------------------------------------------------------------- |
---|
2199 | !! *** ROUTINE set_mooring *** |
---|
2200 | !! |
---|
2201 | !! ** Purpose : automatic definitions of moorings xml attributs... |
---|
2202 | !! |
---|
2203 | !!---------------------------------------------------------------------- |
---|
2204 | REAL(wp), DIMENSION(:), INTENT(in) :: plon, plat ! longitudes/latitudes oft the mooring |
---|
2205 | ! |
---|
2206 | !!$ CHARACTER(len=1),DIMENSION(4) :: clgrd = (/ 'T', 'U', 'V', 'W' /) ! suffix name |
---|
2207 | CHARACTER(len=1),DIMENSION(1) :: clgrd = (/ 'T' /) ! suffix name |
---|
2208 | CHARACTER(len=256) :: clname ! file name |
---|
2209 | CHARACTER(len=256) :: clsuff ! suffix name |
---|
2210 | CHARACTER(len=1) :: cl1 ! 1 character |
---|
2211 | CHARACTER(len=6) :: clon,clat ! name of longitude, latitude |
---|
2212 | INTEGER :: ji, jj, jg ! loop counters |
---|
2213 | INTEGER :: ix, iy ! i-,j- index |
---|
2214 | REAL(wp) :: zlon, zlat |
---|
2215 | !!---------------------------------------------------------------------- |
---|
2216 | DO jg = 1, SIZE(clgrd) |
---|
2217 | cl1 = clgrd(jg) |
---|
2218 | DO ji = 1, SIZE(plon) |
---|
2219 | DO jj = 1, SIZE(plat) |
---|
2220 | zlon = plon(ji) |
---|
2221 | zlat = plat(jj) |
---|
2222 | ! modifications for RAMA moorings |
---|
2223 | IF( zlon == 67. .AND. zlat == 15. ) zlon = 65. |
---|
2224 | IF( zlon == 90. .AND. zlat <= -4. ) zlon = 95. |
---|
2225 | IF( zlon == 95. .AND. zlat == -4. ) zlat = -5. |
---|
2226 | ! modifications for PIRATA moorings |
---|
2227 | IF( zlon == -38. .AND. zlat == -19. ) zlon = -34. |
---|
2228 | IF( zlon == -38. .AND. zlat == -14. ) zlon = -32. |
---|
2229 | IF( zlon == -38. .AND. zlat == -8. ) zlon = -30. |
---|
2230 | IF( zlon == -38. .AND. zlat == 0. ) zlon = -35. |
---|
2231 | IF( zlon == -23. .AND. zlat == 20. ) zlat = 21. |
---|
2232 | IF( zlon == -10. .AND. zlat == -14. ) zlat = -10. |
---|
2233 | IF( zlon == -10. .AND. zlat == -8. ) zlat = -6. |
---|
2234 | IF( zlon == -10. .AND. zlat == 4. ) THEN ; zlon = 0. ; zlat = 0. ; ENDIF |
---|
2235 | CALL dom_ngb( zlon, zlat, ix, iy, cl1 ) |
---|
2236 | IF( zlon >= 0. ) THEN |
---|
2237 | IF( zlon == REAL(NINT(zlon), wp) ) THEN ; WRITE(clon, '(i3, a)') NINT( zlon), 'e' |
---|
2238 | ELSE ; WRITE(clon, '(f5.1,a)') zlon , 'e' |
---|
2239 | ENDIF |
---|
2240 | ELSE |
---|
2241 | IF( zlon == REAL(NINT(zlon), wp) ) THEN ; WRITE(clon, '(i3, a)') NINT(-zlon), 'w' |
---|
2242 | ELSE ; WRITE(clon, '(f5.1,a)') -zlon , 'w' |
---|
2243 | ENDIF |
---|
2244 | ENDIF |
---|
2245 | IF( zlat >= 0. ) THEN |
---|
2246 | IF( zlat == REAL(NINT(zlat), wp) ) THEN ; WRITE(clat, '(i2, a)') NINT( zlat), 'n' |
---|
2247 | ELSE ; WRITE(clat, '(f4.1,a)') zlat , 'n' |
---|
2248 | ENDIF |
---|
2249 | ELSE |
---|
2250 | IF( zlat == REAL(NINT(zlat), wp) ) THEN ; WRITE(clat, '(i2, a)') NINT(-zlat), 's' |
---|
2251 | ELSE ; WRITE(clat, '(f4.1,a)') -zlat , 's' |
---|
2252 | ENDIF |
---|
2253 | ENDIF |
---|
2254 | clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon)) |
---|
2255 | CALL iom_set_zoom_domain_attr(TRIM(clname)//cl1, ibegin= ix-1, jbegin= iy-1, ni=1, nj=1) |
---|
2256 | |
---|
2257 | CALL iom_get_file_attr (TRIM(clname)//cl1, name_suffix = clsuff ) |
---|
2258 | CALL iom_set_file_attr (TRIM(clname)//cl1, name_suffix = TRIM(clsuff)//'_'//TRIM(clname)) |
---|
2259 | CALL iom_update_file_name(TRIM(clname)//cl1) |
---|
2260 | END DO |
---|
2261 | END DO |
---|
2262 | END DO |
---|
2263 | |
---|
2264 | END SUBROUTINE set_mooring |
---|
2265 | |
---|
2266 | |
---|
2267 | SUBROUTINE iom_update_file_name( cdid ) |
---|
2268 | !!---------------------------------------------------------------------- |
---|
2269 | !! *** ROUTINE iom_update_file_name *** |
---|
2270 | !! |
---|
2271 | !! ** Purpose : |
---|
2272 | !! |
---|
2273 | !!---------------------------------------------------------------------- |
---|
2274 | CHARACTER(LEN=*) , INTENT(in) :: cdid |
---|
2275 | ! |
---|
2276 | CHARACTER(LEN=256) :: clname |
---|
2277 | CHARACTER(LEN=20) :: clfreq |
---|
2278 | CHARACTER(LEN=20) :: cldate |
---|
2279 | INTEGER :: idx |
---|
2280 | INTEGER :: jn |
---|
2281 | INTEGER :: itrlen |
---|
2282 | INTEGER :: iyear, imonth, iday, isec |
---|
2283 | REAL(wp) :: zsec |
---|
2284 | LOGICAL :: llexist |
---|
2285 | TYPE(xios_duration) :: output_freq |
---|
2286 | !!---------------------------------------------------------------------- |
---|
2287 | ! |
---|
2288 | DO jn = 1, 2 |
---|
2289 | ! |
---|
2290 | output_freq = xios_duration(0,0,0,0,0,0) |
---|
2291 | IF( jn == 1 ) CALL iom_get_file_attr( cdid, name = clname, output_freq = output_freq ) |
---|
2292 | IF( jn == 2 ) CALL iom_get_file_attr( cdid, name_suffix = clname ) |
---|
2293 | ! |
---|
2294 | IF ( TRIM(clname) /= '' ) THEN |
---|
2295 | ! |
---|
2296 | idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@') |
---|
2297 | DO WHILE ( idx /= 0 ) |
---|
2298 | clname = clname(1:idx-1)//TRIM(cexper)//clname(idx+9:LEN_TRIM(clname)) |
---|
2299 | idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@') |
---|
2300 | END DO |
---|
2301 | ! |
---|
2302 | idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@') |
---|
2303 | DO WHILE ( idx /= 0 ) |
---|
2304 | IF ( output_freq%timestep /= 0) THEN |
---|
2305 | WRITE(clfreq,'(I18,A2)')INT(output_freq%timestep),'ts' |
---|
2306 | itrlen = LEN_TRIM(ADJUSTL(clfreq)) |
---|
2307 | ELSE IF ( output_freq%second /= 0 ) THEN |
---|
2308 | WRITE(clfreq,'(I19,A1)')INT(output_freq%second),'s' |
---|
2309 | itrlen = LEN_TRIM(ADJUSTL(clfreq)) |
---|
2310 | ELSE IF ( output_freq%minute /= 0 ) THEN |
---|
2311 | WRITE(clfreq,'(I18,A2)')INT(output_freq%minute),'mi' |
---|
2312 | itrlen = LEN_TRIM(ADJUSTL(clfreq)) |
---|
2313 | ELSE IF ( output_freq%hour /= 0 ) THEN |
---|
2314 | WRITE(clfreq,'(I19,A1)')INT(output_freq%hour),'h' |
---|
2315 | itrlen = LEN_TRIM(ADJUSTL(clfreq)) |
---|
2316 | ELSE IF ( output_freq%day /= 0 ) THEN |
---|
2317 | WRITE(clfreq,'(I19,A1)')INT(output_freq%day),'d' |
---|
2318 | itrlen = LEN_TRIM(ADJUSTL(clfreq)) |
---|
2319 | ELSE IF ( output_freq%month /= 0 ) THEN |
---|
2320 | WRITE(clfreq,'(I19,A1)')INT(output_freq%month),'m' |
---|
2321 | itrlen = LEN_TRIM(ADJUSTL(clfreq)) |
---|
2322 | ELSE IF ( output_freq%year /= 0 ) THEN |
---|
2323 | WRITE(clfreq,'(I19,A1)')INT(output_freq%year),'y' |
---|
2324 | itrlen = LEN_TRIM(ADJUSTL(clfreq)) |
---|
2325 | ELSE |
---|
2326 | CALL ctl_stop('error in the name of file id '//TRIM(cdid), & |
---|
2327 | & ' attribute output_freq is undefined -> cannot replace @freq@ in '//TRIM(clname) ) |
---|
2328 | ENDIF |
---|
2329 | clname = clname(1:idx-1)//TRIM(ADJUSTL(clfreq))//clname(idx+6:LEN_TRIM(clname)) |
---|
2330 | idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@') |
---|
2331 | END DO |
---|
2332 | ! |
---|
2333 | idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@') |
---|
2334 | DO WHILE ( idx /= 0 ) |
---|
2335 | cldate = iom_sdate( fjulday - rn_Dt / rday ) |
---|
2336 | clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+11:LEN_TRIM(clname)) |
---|
2337 | idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@') |
---|
2338 | END DO |
---|
2339 | ! |
---|
2340 | idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@') |
---|
2341 | DO WHILE ( idx /= 0 ) |
---|
2342 | cldate = iom_sdate( fjulday - rn_Dt / rday, ldfull = .TRUE. ) |
---|
2343 | clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+15:LEN_TRIM(clname)) |
---|
2344 | idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@') |
---|
2345 | END DO |
---|
2346 | ! |
---|
2347 | idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@') |
---|
2348 | DO WHILE ( idx /= 0 ) |
---|
2349 | cldate = iom_sdate( fjulday + rn_Dt / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE. ) |
---|
2350 | clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+9:LEN_TRIM(clname)) |
---|
2351 | idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@') |
---|
2352 | END DO |
---|
2353 | ! |
---|
2354 | idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@') |
---|
2355 | DO WHILE ( idx /= 0 ) |
---|
2356 | cldate = iom_sdate( fjulday + rn_Dt / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE., ldfull = .TRUE. ) |
---|
2357 | clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+13:LEN_TRIM(clname)) |
---|
2358 | idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@') |
---|
2359 | END DO |
---|
2360 | ! |
---|
2361 | IF( jn == 1 .AND. TRIM(Agrif_CFixed()) /= '0' ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname) |
---|
2362 | IF( jn == 1 ) CALL iom_set_file_attr( cdid, name = clname ) |
---|
2363 | IF( jn == 2 ) CALL iom_set_file_attr( cdid, name_suffix = clname ) |
---|
2364 | ! |
---|
2365 | ENDIF |
---|
2366 | ! |
---|
2367 | END DO |
---|
2368 | ! |
---|
2369 | END SUBROUTINE iom_update_file_name |
---|
2370 | |
---|
2371 | |
---|
2372 | FUNCTION iom_sdate( pjday, ld24, ldfull ) |
---|
2373 | !!---------------------------------------------------------------------- |
---|
2374 | !! *** ROUTINE iom_sdate *** |
---|
2375 | !! |
---|
2376 | !! ** Purpose : send back the date corresponding to the given julian day |
---|
2377 | !!---------------------------------------------------------------------- |
---|
2378 | REAL(wp), INTENT(in ) :: pjday ! julian day |
---|
2379 | LOGICAL , INTENT(in ), OPTIONAL :: ld24 ! true to force 24:00 instead of 00:00 |
---|
2380 | LOGICAL , INTENT(in ), OPTIONAL :: ldfull ! true to get the compleate date: yyyymmdd_hh:mm:ss |
---|
2381 | ! |
---|
2382 | CHARACTER(LEN=20) :: iom_sdate |
---|
2383 | CHARACTER(LEN=50) :: clfmt ! format used to write the date |
---|
2384 | INTEGER :: iyear, imonth, iday, ihour, iminute, isec |
---|
2385 | REAL(wp) :: zsec |
---|
2386 | LOGICAL :: ll24, llfull |
---|
2387 | !!---------------------------------------------------------------------- |
---|
2388 | ! |
---|
2389 | IF( PRESENT(ld24) ) THEN ; ll24 = ld24 |
---|
2390 | ELSE ; ll24 = .FALSE. |
---|
2391 | ENDIF |
---|
2392 | ! |
---|
2393 | IF( PRESENT(ldfull) ) THEN ; llfull = ldfull |
---|
2394 | ELSE ; llfull = .FALSE. |
---|
2395 | ENDIF |
---|
2396 | ! |
---|
2397 | CALL ju2ymds( pjday, iyear, imonth, iday, zsec ) |
---|
2398 | isec = NINT(zsec) |
---|
2399 | ! |
---|
2400 | IF ( ll24 .AND. isec == 0 ) THEN ! 00:00 of the next day -> move to 24:00 of the current day |
---|
2401 | CALL ju2ymds( pjday - 1., iyear, imonth, iday, zsec ) |
---|
2402 | isec = 86400 |
---|
2403 | ENDIF |
---|
2404 | ! |
---|
2405 | IF( iyear < 10000 ) THEN ; clfmt = "i4.4,2i2.2" ! format used to write the date |
---|
2406 | ELSE ; WRITE(clfmt, "('i',i1,',2i2.2')") INT(LOG10(REAL(iyear,wp))) + 1 |
---|
2407 | ENDIF |
---|
2408 | ! |
---|
2409 | !$AGRIF_DO_NOT_TREAT |
---|
2410 | ! needed in the conv |
---|
2411 | IF( llfull ) THEN |
---|
2412 | clfmt = TRIM(clfmt)//",'_',i2.2,':',i2.2,':',i2.2" |
---|
2413 | ihour = isec / 3600 |
---|
2414 | isec = MOD(isec, 3600) |
---|
2415 | iminute = isec / 60 |
---|
2416 | isec = MOD(isec, 60) |
---|
2417 | WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday, ihour, iminute, isec ! date of the end of run |
---|
2418 | ELSE |
---|
2419 | WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday ! date of the end of run |
---|
2420 | ENDIF |
---|
2421 | !$AGRIF_END_DO_NOT_TREAT |
---|
2422 | ! |
---|
2423 | END FUNCTION iom_sdate |
---|
2424 | |
---|
2425 | #else |
---|
2426 | !!---------------------------------------------------------------------- |
---|
2427 | !! NOT 'key_iomput' a few dummy routines |
---|
2428 | !!---------------------------------------------------------------------- |
---|
2429 | SUBROUTINE iom_setkt( kt, cdname ) |
---|
2430 | INTEGER , INTENT(in):: kt |
---|
2431 | CHARACTER(LEN=*), INTENT(in) :: cdname |
---|
2432 | IF( .FALSE. ) WRITE(numout,*) kt, cdname ! useless test to avoid compilation warnings |
---|
2433 | END SUBROUTINE iom_setkt |
---|
2434 | |
---|
2435 | SUBROUTINE iom_context_finalize( cdname ) |
---|
2436 | CHARACTER(LEN=*), INTENT(in) :: cdname |
---|
2437 | IF( .FALSE. ) WRITE(numout,*) cdname ! useless test to avoid compilation warnings |
---|
2438 | END SUBROUTINE iom_context_finalize |
---|
2439 | |
---|
2440 | SUBROUTINE iom_update_file_name( cdid ) |
---|
2441 | CHARACTER(LEN=*), INTENT(in) :: cdid |
---|
2442 | IF( .FALSE. ) WRITE(numout,*) cdid ! useless test to avoid compilation warnings |
---|
2443 | END SUBROUTINE iom_update_file_name |
---|
2444 | |
---|
2445 | #endif |
---|
2446 | |
---|
2447 | LOGICAL FUNCTION iom_use( cdname ) |
---|
2448 | CHARACTER(LEN=*), INTENT(in) :: cdname |
---|
2449 | #if defined key_iomput |
---|
2450 | iom_use = xios_field_is_active( cdname ) |
---|
2451 | #else |
---|
2452 | iom_use = .FALSE. |
---|
2453 | #endif |
---|
2454 | END FUNCTION iom_use |
---|
2455 | |
---|
2456 | SUBROUTINE iom_miss_val( cdname, pmiss_val ) |
---|
2457 | CHARACTER(LEN=*), INTENT(in ) :: cdname |
---|
2458 | REAL(wp) , INTENT(out) :: pmiss_val |
---|
2459 | #if defined key_iomput |
---|
2460 | ! get missing value |
---|
2461 | CALL xios_get_field_attr( cdname, default_value = pmiss_val ) |
---|
2462 | #else |
---|
2463 | IF( .FALSE. ) WRITE(numout,*) cdname, pmiss_val ! useless test to avoid compilation warnings |
---|
2464 | IF( .FALSE. ) pmiss_val = 0._wp ! useless assignment to avoid compilation warnings |
---|
2465 | #endif |
---|
2466 | END SUBROUTINE iom_miss_val |
---|
2467 | |
---|
2468 | !!====================================================================== |
---|
2469 | END MODULE iom |
---|