1 | MODULE iom_nf90 |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE iom_nf90 *** |
---|
4 | !! Input/Output manager : Library to read input files with NF90 (only fliocom module) |
---|
5 | !!====================================================================== |
---|
6 | !! History : 9.0 ! 05 12 (J. Belier) Original code |
---|
7 | !! 9.0 ! 06 02 (S. Masson) Adaptation to NEMO |
---|
8 | !! " ! 07 07 (D. Storkey) Changes to iom_nf90_gettime |
---|
9 | !! 3.6 ! 2015-15 (J. Harle) Added procedure to read REAL attributes |
---|
10 | !! 4.0 ! 2017-11 (M. Andrejczuk) Extend IOM interface to write any 3D fields |
---|
11 | !!---------------------------------------------------------------------- |
---|
12 | |
---|
13 | !!---------------------------------------------------------------------- |
---|
14 | !! iom_open : open a file read only |
---|
15 | !! iom_close : close a file or all files opened by iom |
---|
16 | !! iom_get : read a field (interfaced to several routines) |
---|
17 | !! iom_varid : get the id of a variable in a file |
---|
18 | !! iom_rstput : write a field in a restart file (interfaced to several routines) |
---|
19 | !!---------------------------------------------------------------------- |
---|
20 | USE dom_oce ! ocean space and time domain |
---|
21 | USE lbclnk ! lateal boundary condition / mpp exchanges |
---|
22 | USE iom_def ! iom variables definitions |
---|
23 | USE netcdf ! NetCDF library |
---|
24 | USE in_out_manager ! I/O manager |
---|
25 | USE lib_mpp ! MPP library |
---|
26 | |
---|
27 | IMPLICIT NONE |
---|
28 | PRIVATE |
---|
29 | |
---|
30 | PUBLIC iom_nf90_open , iom_nf90_close, iom_nf90_varid, iom_nf90_get, iom_nf90_rstput |
---|
31 | PUBLIC iom_nf90_chkatt, iom_nf90_getatt, iom_nf90_putatt |
---|
32 | |
---|
33 | INTERFACE iom_nf90_get |
---|
34 | MODULE PROCEDURE iom_nf90_g0d, iom_nf90_g123d |
---|
35 | END INTERFACE |
---|
36 | INTERFACE iom_nf90_rstput |
---|
37 | MODULE PROCEDURE iom_nf90_rp0123d |
---|
38 | END INTERFACE |
---|
39 | |
---|
40 | !!---------------------------------------------------------------------- |
---|
41 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
42 | !! $Id$ |
---|
43 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
44 | !!---------------------------------------------------------------------- |
---|
45 | CONTAINS |
---|
46 | |
---|
47 | SUBROUTINE iom_nf90_open( cdname, kiomid, ldwrt, ldok, kdompar, kdlev ) |
---|
48 | !!--------------------------------------------------------------------- |
---|
49 | !! *** SUBROUTINE iom_open *** |
---|
50 | !! |
---|
51 | !! ** Purpose : open an input file with NF90 |
---|
52 | !!--------------------------------------------------------------------- |
---|
53 | CHARACTER(len=*) , INTENT(inout) :: cdname ! File name |
---|
54 | INTEGER , INTENT( out) :: kiomid ! nf90 identifier of the opened file |
---|
55 | LOGICAL , INTENT(in ) :: ldwrt ! read or write the file? |
---|
56 | LOGICAL , INTENT(in ) :: ldok ! check the existence |
---|
57 | INTEGER, DIMENSION(2,5), INTENT(in ), OPTIONAL :: kdompar ! domain parameters: |
---|
58 | INTEGER , INTENT(in ), OPTIONAL :: kdlev ! size of the third dimension |
---|
59 | |
---|
60 | CHARACTER(LEN=256) :: clinfo ! info character |
---|
61 | CHARACTER(LEN=256) :: cltmp ! temporary character |
---|
62 | INTEGER :: iln ! lengths of character |
---|
63 | INTEGER :: istop ! temporary storage of nstop |
---|
64 | INTEGER :: if90id ! nf90 identifier of the opened file |
---|
65 | INTEGER :: idmy ! dummy variable |
---|
66 | INTEGER :: jl ! loop variable |
---|
67 | INTEGER :: ichunk ! temporary storage of nn_chunksz |
---|
68 | INTEGER :: imode ! creation mode flag: NF90_CLOBBER or NF90_NOCLOBBER or NF90_HDF5 |
---|
69 | INTEGER :: ihdf5 ! local variable for retrieval of value for NF90_HDF5 |
---|
70 | LOGICAL :: llclobber ! local definition of ln_clobber |
---|
71 | INTEGER :: ilevels ! vertical levels |
---|
72 | !--------------------------------------------------------------------- |
---|
73 | ! |
---|
74 | clinfo = ' iom_nf90_open ~~~ ' |
---|
75 | istop = nstop ! store the actual value of nstop |
---|
76 | ! |
---|
77 | ! !number of vertical levels |
---|
78 | IF( PRESENT(kdlev) ) THEN ; ilevels = kdlev ! use input value (useful for sea-ice) |
---|
79 | ELSE ; ilevels = jpk ! by default jpk |
---|
80 | ENDIF |
---|
81 | ! |
---|
82 | IF( nn_chunksz > 0 ) THEN ; ichunk = nn_chunksz |
---|
83 | ELSE ; ichunk = NF90_SIZEHINT_DEFAULT |
---|
84 | ENDIF |
---|
85 | ! |
---|
86 | llclobber = ldwrt .AND. ln_clobber |
---|
87 | IF( ldok .AND. .NOT. llclobber ) THEN !== Open existing file ==! |
---|
88 | ! !=========================! |
---|
89 | IF( ldwrt ) THEN ! ... in write mode |
---|
90 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode' |
---|
91 | IF( snc4set%luse ) THEN |
---|
92 | CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_WRITE , if90id ), clinfo) |
---|
93 | ELSE |
---|
94 | CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_WRITE , if90id, chunksize = ichunk ), clinfo) |
---|
95 | ENDIF |
---|
96 | CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy ), clinfo) |
---|
97 | ELSE ! ... in read mode |
---|
98 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode' |
---|
99 | CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_NOWRITE, if90id, chunksize = ichunk ), clinfo) |
---|
100 | ENDIF |
---|
101 | ELSE !== the file doesn't exist ==! (or we overwrite it) |
---|
102 | ! !============================! |
---|
103 | iln = INDEX( cdname, '.nc' ) |
---|
104 | IF( ldwrt ) THEN !* the file should be open in write mode so we create it... |
---|
105 | IF( jpnij > 1 ) THEN |
---|
106 | WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea-1, '.nc' |
---|
107 | cdname = TRIM(cltmp) |
---|
108 | ENDIF |
---|
109 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in WRITE mode' |
---|
110 | |
---|
111 | IF( llclobber ) THEN ; imode = IOR( NF90_64BIT_OFFSET, NF90_CLOBBER ) |
---|
112 | ELSE ; imode = IOR( NF90_64BIT_OFFSET, NF90_NOCLOBBER ) |
---|
113 | ENDIF |
---|
114 | IF( snc4set%luse ) THEN |
---|
115 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' creating file: '//TRIM(cdname)//' in hdf5 (netcdf4) mode' |
---|
116 | CALL GET_NF90_SYMBOL("NF90_HDF5", ihdf5) |
---|
117 | IF( llclobber ) THEN ; imode = IOR(ihdf5, NF90_CLOBBER) |
---|
118 | ELSE ; imode = IOR(ihdf5, NF90_NOCLOBBER) |
---|
119 | ENDIF |
---|
120 | CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), imode, if90id ), clinfo) |
---|
121 | ELSE |
---|
122 | CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), imode, if90id, chunksize = ichunk ), clinfo) |
---|
123 | ENDIF |
---|
124 | CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy ), clinfo) |
---|
125 | ! define dimensions |
---|
126 | CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'x', kdompar(1,1), idmy ), clinfo) |
---|
127 | CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'y', kdompar(2,1), idmy ), clinfo) |
---|
128 | CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'nav_lev', jpk, idmy ), clinfo) |
---|
129 | CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'time_counter', NF90_UNLIMITED, idmy ), clinfo) |
---|
130 | IF( PRESENT(kdlev) ) & |
---|
131 | CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'numcat', kdlev, idmy ), clinfo) |
---|
132 | ! global attributes |
---|
133 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number_total' , jpnij ), clinfo) |
---|
134 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number' , narea-1 ), clinfo) |
---|
135 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/1 , 2 /) ), clinfo) |
---|
136 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_size_global' , (/jpiglo, jpjglo/) ), clinfo) |
---|
137 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_size_local' , kdompar(:,1) ), clinfo) |
---|
138 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_position_first' , kdompar(:,2) ), clinfo) |
---|
139 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_position_last' , kdompar(:,3) ), clinfo) |
---|
140 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_start', kdompar(:,4) ), clinfo) |
---|
141 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_end' , kdompar(:,5) ), clinfo) |
---|
142 | CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_type' , 'BOX' ), clinfo) |
---|
143 | ELSE !* the file should be open for read mode so it must exist... |
---|
144 | CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' ) |
---|
145 | ENDIF |
---|
146 | ENDIF |
---|
147 | ! |
---|
148 | ! start to fill file informations |
---|
149 | ! ============= |
---|
150 | IF( istop == nstop ) THEN ! no error within this routine |
---|
151 | !does not work with some compilers kiomid = MINLOC(iom_file(:)%nfid, dim = 1) |
---|
152 | kiomid = 0 |
---|
153 | DO jl = jpmax_files, 1, -1 |
---|
154 | IF( iom_file(jl)%nfid == 0 ) kiomid = jl |
---|
155 | ENDDO |
---|
156 | iom_file(kiomid)%name = TRIM(cdname) |
---|
157 | iom_file(kiomid)%nfid = if90id |
---|
158 | iom_file(kiomid)%nvars = 0 |
---|
159 | iom_file(kiomid)%irec = -1 ! useless for NetCDF files, used to know if the file is in define mode |
---|
160 | iom_file(kiomid)%nlev = ilevels |
---|
161 | CALL iom_nf90_check(NF90_Inquire(if90id, unlimitedDimId = iom_file(kiomid)%iduld), clinfo) |
---|
162 | IF( iom_file(kiomid)%iduld .GE. 0 ) THEN |
---|
163 | CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, iom_file(kiomid)%iduld, & |
---|
164 | & name = iom_file(kiomid)%uldname, & |
---|
165 | & len = iom_file(kiomid)%lenuld ), clinfo ) |
---|
166 | ENDIF |
---|
167 | IF(lwp) WRITE(numout,*) ' ---> '//TRIM(cdname)//' OK' |
---|
168 | ELSE |
---|
169 | kiomid = 0 ! return error flag |
---|
170 | ENDIF |
---|
171 | ! |
---|
172 | END SUBROUTINE iom_nf90_open |
---|
173 | |
---|
174 | |
---|
175 | SUBROUTINE iom_nf90_close( kiomid ) |
---|
176 | !!-------------------------------------------------------------------- |
---|
177 | !! *** SUBROUTINE iom_nf90_close *** |
---|
178 | !! |
---|
179 | !! ** Purpose : close an input file with NF90 |
---|
180 | !!-------------------------------------------------------------------- |
---|
181 | INTEGER, INTENT(in) :: kiomid ! iom identifier of the file to be closed |
---|
182 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
183 | !--------------------------------------------------------------------- |
---|
184 | clinfo = ' iom_nf90_close , file: '//TRIM(iom_file(kiomid)%name) |
---|
185 | CALL iom_nf90_check(NF90_CLOSE(iom_file(kiomid)%nfid), clinfo) |
---|
186 | END SUBROUTINE iom_nf90_close |
---|
187 | |
---|
188 | |
---|
189 | FUNCTION iom_nf90_varid ( kiomid, cdvar, kiv, kdimsz, kndims, lduld ) |
---|
190 | !!----------------------------------------------------------------------- |
---|
191 | !! *** FUNCTION iom_varid *** |
---|
192 | !! |
---|
193 | !! ** Purpose : get the id of a variable in a file with NF90 |
---|
194 | !!----------------------------------------------------------------------- |
---|
195 | INTEGER , INTENT(in ) :: kiomid ! file Identifier |
---|
196 | CHARACTER(len=*) , INTENT(in ) :: cdvar ! name of the variable |
---|
197 | INTEGER , INTENT(in ) :: kiv ! |
---|
198 | INTEGER, DIMENSION(:), INTENT( out), OPTIONAL :: kdimsz ! size of each dimension |
---|
199 | INTEGER , INTENT( out), OPTIONAL :: kndims ! number of dimensions |
---|
200 | LOGICAL , INTENT( out), OPTIONAL :: lduld ! true if the last dimension is unlimited (time) |
---|
201 | ! |
---|
202 | INTEGER :: iom_nf90_varid ! iom variable Id |
---|
203 | INTEGER :: if90id ! nf90 file identifier |
---|
204 | INTEGER :: ji ! dummy loop index |
---|
205 | INTEGER :: ivarid ! NetCDF variable Id |
---|
206 | INTEGER :: i_nvd ! number of dimension of the variable |
---|
207 | INTEGER, DIMENSION(jpmax_dims) :: idimid ! dimension ids of the variable |
---|
208 | LOGICAL :: llok ! ok test |
---|
209 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
210 | !!----------------------------------------------------------------------- |
---|
211 | clinfo = ' iom_nf90_varid, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar) |
---|
212 | iom_nf90_varid = 0 ! default definition |
---|
213 | IF( PRESENT(kdimsz) ) kdimsz(:) = 0 ! default definition |
---|
214 | if90id = iom_file(kiomid)%nfid ! get back NetCDF file id |
---|
215 | ! |
---|
216 | llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr ! does the variable exist in the file |
---|
217 | IF( llok ) THEN |
---|
218 | iom_nf90_varid = kiv |
---|
219 | iom_file(kiomid)%nvars = kiv |
---|
220 | iom_file(kiomid)%nvid(kiv) = ivarid |
---|
221 | iom_file(kiomid)%cn_var(kiv) = TRIM(cdvar) |
---|
222 | CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, ndims = i_nvd), clinfo) ! number of dimensions |
---|
223 | iom_file(kiomid)%ndims(kiv) = i_nvd |
---|
224 | CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, dimids = idimid(1:i_nvd)), clinfo) ! dimensions ids |
---|
225 | iom_file(kiomid)%luld(kiv) = .FALSE. ! default value |
---|
226 | iom_file(kiomid)%dimsz(:,kiv) = 0 ! reset dimsz in case previously used |
---|
227 | DO ji = 1, i_nvd ! dimensions size |
---|
228 | CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, idimid(ji), len = iom_file(kiomid)%dimsz(ji,kiv)), clinfo) |
---|
229 | IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE. ! unlimited dimension? |
---|
230 | END DO |
---|
231 | !---------- Deal with scale_factor and add_offset |
---|
232 | llok = NF90_Inquire_attribute(if90id, ivarid, 'scale_factor') == nf90_noerr |
---|
233 | IF( llok) THEN |
---|
234 | CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'scale_factor', iom_file(kiomid)%scf(kiv)), clinfo) |
---|
235 | ELSE |
---|
236 | iom_file(kiomid)%scf(kiv) = 1. |
---|
237 | END IF |
---|
238 | llok = NF90_Inquire_attribute(if90id, ivarid, 'add_offset') == nf90_noerr |
---|
239 | IF( llok ) THEN |
---|
240 | CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'add_offset', iom_file(kiomid)%ofs(kiv)), clinfo) |
---|
241 | ELSE |
---|
242 | iom_file(kiomid)%ofs(kiv) = 0. |
---|
243 | END IF |
---|
244 | ! return the simension size |
---|
245 | IF( PRESENT(kdimsz) ) THEN |
---|
246 | IF( i_nvd <= SIZE(kdimsz) ) THEN |
---|
247 | kdimsz(1:i_nvd) = iom_file(kiomid)%dimsz(1:i_nvd,kiv) |
---|
248 | ELSE |
---|
249 | WRITE(ctmp1,*) i_nvd, SIZE(kdimsz) |
---|
250 | CALL ctl_stop( TRIM(clinfo), 'error in kdimsz size'//TRIM(ctmp1) ) |
---|
251 | ENDIF |
---|
252 | ENDIF |
---|
253 | IF( PRESENT(kndims) ) kndims = iom_file(kiomid)%ndims(kiv) |
---|
254 | IF( PRESENT( lduld) ) lduld = iom_file(kiomid)%luld(kiv) |
---|
255 | ELSE |
---|
256 | iom_nf90_varid = -1 ! variable not found, return error code: -1 |
---|
257 | ENDIF |
---|
258 | ! |
---|
259 | END FUNCTION iom_nf90_varid |
---|
260 | |
---|
261 | !!---------------------------------------------------------------------- |
---|
262 | !! INTERFACE iom_nf90_get |
---|
263 | !!---------------------------------------------------------------------- |
---|
264 | |
---|
265 | SUBROUTINE iom_nf90_g0d( kiomid, kvid, pvar, kstart ) |
---|
266 | !!----------------------------------------------------------------------- |
---|
267 | !! *** ROUTINE iom_nf90_g0d *** |
---|
268 | !! |
---|
269 | !! ** Purpose : read a scalar with NF90 |
---|
270 | !!----------------------------------------------------------------------- |
---|
271 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
272 | INTEGER , INTENT(in ) :: kvid ! variable id |
---|
273 | REAL(wp), INTENT( out) :: pvar ! read field |
---|
274 | INTEGER , DIMENSION(1), INTENT(in ), OPTIONAL :: kstart ! start position of the reading in each axis |
---|
275 | ! |
---|
276 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
277 | !--------------------------------------------------------------------- |
---|
278 | clinfo = 'iom_nf90_g0d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid)) |
---|
279 | CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), pvar, start = kstart), clinfo ) |
---|
280 | END SUBROUTINE iom_nf90_g0d |
---|
281 | |
---|
282 | |
---|
283 | SUBROUTINE iom_nf90_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2, & |
---|
284 | & pv_r1d, pv_r2d, pv_r3d ) |
---|
285 | !!----------------------------------------------------------------------- |
---|
286 | !! *** ROUTINE iom_nf90_g123d *** |
---|
287 | !! |
---|
288 | !! ** Purpose : read a 1D/2D/3D variable with NF90 |
---|
289 | !! |
---|
290 | !! ** Method : read ONE record at each CALL |
---|
291 | !!----------------------------------------------------------------------- |
---|
292 | INTEGER , INTENT(in ) :: kiomid ! iom identifier of the file |
---|
293 | INTEGER , INTENT(in ) :: kvid ! Name of the variable |
---|
294 | INTEGER , INTENT(in ) :: knbdim ! number of dimensions of the variable |
---|
295 | INTEGER , DIMENSION(:) , INTENT(in ) :: kstart ! start position of the reading in each axis |
---|
296 | INTEGER , DIMENSION(:) , INTENT(in ) :: kcount ! number of points to be read in each axis |
---|
297 | INTEGER , INTENT(in ) :: kx1, kx2, ky1, ky2 ! subdomain indexes |
---|
298 | REAL(wp), DIMENSION(:) , INTENT( out), OPTIONAL :: pv_r1d ! read field (1D case) |
---|
299 | REAL(wp), DIMENSION(:,:) , INTENT( out), OPTIONAL :: pv_r2d ! read field (2D case) |
---|
300 | REAL(wp), DIMENSION(:,:,:) , INTENT( out), OPTIONAL :: pv_r3d ! read field (3D case) |
---|
301 | ! |
---|
302 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
303 | INTEGER :: if90id ! nf90 identifier of the opened file |
---|
304 | INTEGER :: ivid ! nf90 variable id |
---|
305 | !--------------------------------------------------------------------- |
---|
306 | clinfo = 'iom_nf90_g123d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid)) |
---|
307 | if90id = iom_file(kiomid)%nfid ! get back NetCDF file id |
---|
308 | ivid = iom_file(kiomid)%nvid(kvid) ! get back NetCDF var id |
---|
309 | ! |
---|
310 | IF( PRESENT(pv_r1d) ) THEN |
---|
311 | CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r1d(: ), start = kstart(1:knbdim), & |
---|
312 | & count = kcount(1:knbdim)), clinfo ) |
---|
313 | ELSEIF( PRESENT(pv_r2d) ) THEN |
---|
314 | CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r2d(kx1:kx2,ky1:ky2 ), start = kstart(1:knbdim), & |
---|
315 | & count = kcount(1:knbdim)), clinfo ) |
---|
316 | ELSEIF( PRESENT(pv_r3d) ) THEN |
---|
317 | CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim), & |
---|
318 | & count = kcount(1:knbdim)), clinfo ) |
---|
319 | ENDIF |
---|
320 | ! |
---|
321 | END SUBROUTINE iom_nf90_g123d |
---|
322 | |
---|
323 | |
---|
324 | SUBROUTINE iom_nf90_chkatt( kiomid, cdatt, llok, ksize, cdvar ) |
---|
325 | !!----------------------------------------------------------------------- |
---|
326 | !! *** ROUTINE iom_nf90_chkatt *** |
---|
327 | !! |
---|
328 | !! ** Purpose : check existence of attribute with NF90 |
---|
329 | !! (either a global attribute (default) or a variable |
---|
330 | !! attribute if optional variable name is supplied (cdvar)) |
---|
331 | !!----------------------------------------------------------------------- |
---|
332 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
333 | CHARACTER(len=*), INTENT(in ) :: cdatt ! attribute name |
---|
334 | LOGICAL , INTENT( out) :: llok ! error code |
---|
335 | INTEGER , INTENT( out), OPTIONAL & |
---|
336 | & :: ksize ! attribute size |
---|
337 | CHARACTER(len=*), INTENT(in ), OPTIONAL & |
---|
338 | & :: cdvar ! name of the variable |
---|
339 | ! |
---|
340 | INTEGER :: if90id ! temporary integer |
---|
341 | INTEGER :: isize ! temporary integer |
---|
342 | INTEGER :: ivarid ! NetCDF variable Id |
---|
343 | !--------------------------------------------------------------------- |
---|
344 | ! |
---|
345 | if90id = iom_file(kiomid)%nfid |
---|
346 | IF( PRESENT(cdvar) ) THEN |
---|
347 | ! check the variable exists in the file |
---|
348 | llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr |
---|
349 | IF( llok ) & |
---|
350 | ! check the variable has the attribute required |
---|
351 | llok = NF90_Inquire_attribute(if90id, ivarid, cdatt, len=isize ) == nf90_noerr |
---|
352 | ELSE |
---|
353 | llok = NF90_Inquire_attribute(if90id, NF90_GLOBAL, cdatt, len=isize ) == nf90_noerr |
---|
354 | ENDIF |
---|
355 | ! |
---|
356 | IF( PRESENT(ksize) ) ksize = isize |
---|
357 | ! |
---|
358 | IF( .not. llok) & |
---|
359 | CALL ctl_warn('iom_nf90_chkatt: no attribute '//cdatt//' found') |
---|
360 | ! |
---|
361 | END SUBROUTINE iom_nf90_chkatt |
---|
362 | |
---|
363 | |
---|
364 | !!---------------------------------------------------------------------- |
---|
365 | !! INTERFACE iom_nf90_getatt |
---|
366 | !!---------------------------------------------------------------------- |
---|
367 | |
---|
368 | SUBROUTINE iom_nf90_getatt( kiomid, cdatt, katt0d, katt1d, patt0d, patt1d, cdatt0d, cdvar) |
---|
369 | !!----------------------------------------------------------------------- |
---|
370 | !! *** ROUTINE iom_nf90_getatt *** |
---|
371 | !! |
---|
372 | !! ** Purpose : read an attribute with NF90 |
---|
373 | !! (either a global attribute (default) or a variable |
---|
374 | !! attribute if optional variable name is supplied (cdvar)) |
---|
375 | !!----------------------------------------------------------------------- |
---|
376 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
377 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! attribute name |
---|
378 | INTEGER , INTENT( out), OPTIONAL :: katt0d ! read scalar integer |
---|
379 | INTEGER, DIMENSION(:) , INTENT( out), OPTIONAL :: katt1d ! read 1d array integer |
---|
380 | REAL(wp) , INTENT( out), OPTIONAL :: patt0d ! read scalar real |
---|
381 | REAL(wp), DIMENSION(:), INTENT( out), OPTIONAL :: patt1d ! read 1d array real |
---|
382 | CHARACTER(len=*) , INTENT( out), OPTIONAL :: cdatt0d ! read character |
---|
383 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! name of the variable |
---|
384 | ! |
---|
385 | INTEGER :: if90id ! temporary integer |
---|
386 | INTEGER :: ivarid ! NetCDF variable Id |
---|
387 | LOGICAL :: llok ! temporary logical |
---|
388 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
389 | !--------------------------------------------------------------------- |
---|
390 | ! |
---|
391 | if90id = iom_file(kiomid)%nfid |
---|
392 | IF( PRESENT(cdvar) ) THEN |
---|
393 | ! check the variable exists in the file |
---|
394 | llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr |
---|
395 | IF( llok ) THEN |
---|
396 | ! check the variable has the attribute required |
---|
397 | llok = NF90_Inquire_attribute(if90id, ivarid, cdatt) == nf90_noerr |
---|
398 | ELSE |
---|
399 | CALL ctl_warn('iom_nf90_getatt: no variable '//TRIM(cdvar)//' found') |
---|
400 | ENDIF |
---|
401 | ELSE |
---|
402 | llok = NF90_Inquire_attribute(if90id, NF90_GLOBAL, cdatt) == nf90_noerr |
---|
403 | ivarid = NF90_GLOBAL |
---|
404 | ENDIF |
---|
405 | ! |
---|
406 | IF( llok) THEN |
---|
407 | clinfo = 'iom_nf90_getatt, file: '//TRIM(iom_file(kiomid)%name)//', att: '//TRIM(cdatt) |
---|
408 | IF(PRESENT( katt0d)) CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values = katt0d), clinfo) |
---|
409 | IF(PRESENT( katt1d)) CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values = katt1d), clinfo) |
---|
410 | IF(PRESENT( patt0d)) CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values = patt0d), clinfo) |
---|
411 | IF(PRESENT( patt1d)) CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values = patt1d), clinfo) |
---|
412 | IF(PRESENT(cdatt0d)) CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values = cdatt0d), clinfo) |
---|
413 | ELSE |
---|
414 | CALL ctl_warn('iom_nf90_getatt: no attribute '//TRIM(cdatt)//' found') |
---|
415 | IF(PRESENT( katt0d)) katt0d = -999 |
---|
416 | IF(PRESENT( katt1d)) katt1d(:) = -999 |
---|
417 | IF(PRESENT( patt0d)) patt0d = -999._wp |
---|
418 | IF(PRESENT( patt1d)) patt1d(:) = -999._wp |
---|
419 | IF(PRESENT(cdatt0d)) cdatt0d = '!' |
---|
420 | ENDIF |
---|
421 | ! |
---|
422 | END SUBROUTINE iom_nf90_getatt |
---|
423 | |
---|
424 | |
---|
425 | SUBROUTINE iom_nf90_putatt( kiomid, cdatt, katt0d, katt1d, patt0d, patt1d, cdatt0d, cdvar) |
---|
426 | !!----------------------------------------------------------------------- |
---|
427 | !! *** ROUTINE iom_nf90_putatt *** |
---|
428 | !! |
---|
429 | !! ** Purpose : write an attribute with NF90 |
---|
430 | !! (either a global attribute (default) or a variable |
---|
431 | !! attribute if optional variable name is supplied (cdvar)) |
---|
432 | !!----------------------------------------------------------------------- |
---|
433 | INTEGER , INTENT(in ) :: kiomid ! Identifier of the file |
---|
434 | CHARACTER(len=*) , INTENT(in ) :: cdatt ! attribute name |
---|
435 | INTEGER , INTENT(in ), OPTIONAL :: katt0d ! read scalar integer |
---|
436 | INTEGER, DIMENSION(:) , INTENT(in ), OPTIONAL :: katt1d ! read 1d array integer |
---|
437 | REAL(wp) , INTENT(in ), OPTIONAL :: patt0d ! read scalar real |
---|
438 | REAL(wp), DIMENSION(:), INTENT(in ), OPTIONAL :: patt1d ! read 1d array real |
---|
439 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdatt0d ! read character |
---|
440 | CHARACTER(len=*) , INTENT(in ), OPTIONAL :: cdvar ! name of the variable |
---|
441 | ! |
---|
442 | INTEGER :: if90id ! temporary integer |
---|
443 | INTEGER :: ivarid ! NetCDF variable Id |
---|
444 | INTEGER :: isize ! Attribute size |
---|
445 | INTEGER :: itype ! Attribute type |
---|
446 | LOGICAL :: llok ! temporary logical |
---|
447 | LOGICAL :: llatt ! temporary logical |
---|
448 | LOGICAL :: lldata ! temporary logical |
---|
449 | CHARACTER(LEN=100) :: clinfo ! info character |
---|
450 | !--------------------------------------------------------------------- |
---|
451 | ! |
---|
452 | if90id = iom_file(kiomid)%nfid |
---|
453 | IF( PRESENT(cdvar) ) THEN |
---|
454 | llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr ! is the variable in the file? |
---|
455 | IF( .NOT. llok ) THEN |
---|
456 | CALL ctl_warn('iom_nf90_putatt: no variable '//TRIM(cdvar)//' found' & |
---|
457 | & , ' no attribute '//cdatt//' written' ) |
---|
458 | RETURN |
---|
459 | ENDIF |
---|
460 | ELSE |
---|
461 | ivarid = NF90_GLOBAL |
---|
462 | ENDIF |
---|
463 | llatt = NF90_Inquire_attribute(if90id, ivarid, cdatt, len = isize, xtype = itype ) == nf90_noerr |
---|
464 | ! |
---|
465 | ! trick: irec used to know if the file is in define mode or not |
---|
466 | lldata = iom_file(kiomid)%irec /= -1 ! default: go back in define mode if in data mode |
---|
467 | IF( lldata .AND. llatt ) THEN ! attribute already there. Do we really need to go back in define mode? |
---|
468 | ! do we have the appropriate type? |
---|
469 | IF(PRESENT( katt0d) .OR. PRESENT( katt1d)) llok = itype == NF90_INT |
---|
470 | IF(PRESENT( patt0d) .OR. PRESENT( patt1d)) llok = itype == NF90_DOUBLE |
---|
471 | IF(PRESENT(cdatt0d) ) llok = itype == NF90_CHAR |
---|
472 | ! and do we have the appropriate size? |
---|
473 | IF(PRESENT( katt0d)) llok = llok .AND. isize == 1 |
---|
474 | IF(PRESENT( katt1d)) llok = llok .AND. isize == SIZE(katt1d) |
---|
475 | IF(PRESENT( patt0d)) llok = llok .AND. isize == 1 |
---|
476 | IF(PRESENT( patt1d)) llok = llok .AND. isize == SIZE(patt1d) |
---|
477 | IF(PRESENT(cdatt0d)) llok = llok .AND. isize == LEN_TRIM(cdatt0d) |
---|
478 | ! |
---|
479 | lldata = .NOT. llok |
---|
480 | ENDIF |
---|
481 | ! |
---|
482 | clinfo = 'iom_nf90_putatt, file: '//TRIM(iom_file(kiomid)%name)//', att: '//TRIM(cdatt) |
---|
483 | IF(lldata) CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo) ! leave data mode to define mode |
---|
484 | ! |
---|
485 | IF(PRESENT( katt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = katt0d) , clinfo) |
---|
486 | IF(PRESENT( katt1d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = katt1d) , clinfo) |
---|
487 | IF(PRESENT( patt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = patt0d) , clinfo) |
---|
488 | IF(PRESENT( patt1d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = patt1d) , clinfo) |
---|
489 | IF(PRESENT(cdatt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = trim(cdatt0d)), clinfo) |
---|
490 | ! |
---|
491 | IF(lldata) CALL iom_nf90_check(NF90_ENDDEF( if90id ), clinfo) ! leave define mode to data mode |
---|
492 | ! |
---|
493 | END SUBROUTINE iom_nf90_putatt |
---|
494 | |
---|
495 | |
---|
496 | SUBROUTINE iom_nf90_rp0123d( kt, kwrite, kiomid, cdvar , kvid , ktype, & |
---|
497 | & pv_r0d, pv_r1d, pv_r2d, pv_r3d ) |
---|
498 | !!-------------------------------------------------------------------- |
---|
499 | !! *** SUBROUTINE iom_nf90_rstput *** |
---|
500 | !! |
---|
501 | !! ** Purpose : read the time axis cdvar in the file |
---|
502 | !!-------------------------------------------------------------------- |
---|
503 | INTEGER , INTENT(in) :: kt ! ocean time-step |
---|
504 | INTEGER , INTENT(in) :: kwrite ! writing time-step |
---|
505 | INTEGER , INTENT(in) :: kiomid ! Identifier of the file |
---|
506 | CHARACTER(len=*) , INTENT(in) :: cdvar ! variable name |
---|
507 | INTEGER , INTENT(in) :: kvid ! variable id |
---|
508 | INTEGER , INTENT(in), OPTIONAL :: ktype ! variable type (default R8) |
---|
509 | REAL(wp) , INTENT(in), OPTIONAL :: pv_r0d ! written Od field |
---|
510 | REAL(wp), DIMENSION( :), INTENT(in), OPTIONAL :: pv_r1d ! written 1d field |
---|
511 | REAL(wp), DIMENSION(:, : ), INTENT(in), OPTIONAL :: pv_r2d ! written 2d field |
---|
512 | REAL(wp), DIMENSION(:, :, :), INTENT(in), OPTIONAL :: pv_r3d ! written 3d field |
---|
513 | ! |
---|
514 | INTEGER :: idims ! number of dimension |
---|
515 | INTEGER :: idvar ! variable id |
---|
516 | INTEGER :: jd ! dimension loop counter |
---|
517 | INTEGER :: ix1, ix2, iy1, iy2 ! subdomain indexes |
---|
518 | INTEGER, DIMENSION(4) :: idimsz ! dimensions size |
---|
519 | INTEGER, DIMENSION(4) :: idimid ! dimensions id |
---|
520 | CHARACTER(LEN=256) :: clinfo ! info character |
---|
521 | CHARACTER(LEN= 12), DIMENSION(5) :: cltmp ! temporary character |
---|
522 | INTEGER :: if90id ! nf90 file identifier |
---|
523 | INTEGER :: idmy ! dummy variable |
---|
524 | INTEGER :: itype ! variable type |
---|
525 | INTEGER, DIMENSION(4) :: ichunksz ! NetCDF4 chunk sizes. Will be computed using |
---|
526 | ! ! nn_nchunks_[i,j,k,t] namelist parameters |
---|
527 | INTEGER :: ichunkalg, ishuffle, ideflate, ideflate_level |
---|
528 | ! ! NetCDF4 internally fixed parameters |
---|
529 | LOGICAL :: lchunk ! logical switch to activate chunking and compression |
---|
530 | ! ! when appropriate (currently chunking is applied to 4d fields only) |
---|
531 | INTEGER :: idlv ! local variable |
---|
532 | INTEGER :: idim3 ! id of the third dimension |
---|
533 | !--------------------------------------------------------------------- |
---|
534 | ! |
---|
535 | clinfo = ' iom_nf90_rp0123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar) |
---|
536 | if90id = iom_file(kiomid)%nfid |
---|
537 | ! |
---|
538 | ! define dimension variables if it is not already done |
---|
539 | ! ========================== |
---|
540 | IF( iom_file(kiomid)%nvars == 0 ) THEN |
---|
541 | ! are we in define mode? |
---|
542 | IF( iom_file(kiomid)%irec /= -1 ) THEN ! trick: irec used to know if the file is in define mode or not |
---|
543 | CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo) ; iom_file(kiomid)%irec = -1 |
---|
544 | ENDIF |
---|
545 | ! define the dimension variables if it is not already done |
---|
546 | ! Warning: we must use the same character length in an array constructor (at least for gcc compiler) |
---|
547 | cltmp = (/ 'nav_lon ', 'nav_lat ', 'nav_lev ', 'time_counter', 'numcat ' /) |
---|
548 | CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(1)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(1) ), clinfo) |
---|
549 | CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(2)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(2) ), clinfo) |
---|
550 | CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(3)), NF90_FLOAT , (/ 3 /), iom_file(kiomid)%nvid(3) ), clinfo) |
---|
551 | CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(4)), NF90_DOUBLE, (/ 4 /), iom_file(kiomid)%nvid(4) ), clinfo) |
---|
552 | ! update informations structure related the dimension variable we just added... |
---|
553 | iom_file(kiomid)%nvars = 4 |
---|
554 | iom_file(kiomid)%luld(1:4) = (/ .FALSE., .FALSE., .FALSE., .TRUE. /) |
---|
555 | iom_file(kiomid)%cn_var(1:4) = cltmp(1:4) |
---|
556 | iom_file(kiomid)%ndims(1:4) = (/ 2, 2, 1, 1 /) |
---|
557 | IF( NF90_INQ_DIMID( if90id, 'numcat', idmy ) == nf90_noerr ) THEN ! add a 5th variable corresponding to the 5th dimension |
---|
558 | CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(5)), NF90_FLOAT , (/ 5 /), iom_file(kiomid)%nvid(5) ), clinfo) |
---|
559 | iom_file(kiomid)%nvars = 5 |
---|
560 | iom_file(kiomid)%luld(5) = .FALSE. |
---|
561 | iom_file(kiomid)%cn_var(5) = cltmp(5) |
---|
562 | iom_file(kiomid)%ndims(5) = 1 |
---|
563 | ENDIF |
---|
564 | ! trick: defined to 0 to say that dimension variables are defined but not yet written |
---|
565 | iom_file(kiomid)%dimsz(1, 1) = 0 |
---|
566 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done' |
---|
567 | ENDIF |
---|
568 | ! define the data if it is not already done |
---|
569 | ! =============== |
---|
570 | IF( kvid <= 0 ) THEN |
---|
571 | ! |
---|
572 | ! NetCDF4 chunking and compression fixed settings |
---|
573 | ichunkalg = 0 |
---|
574 | ishuffle = 1 |
---|
575 | ideflate = 1 |
---|
576 | ideflate_level = 1 |
---|
577 | ! |
---|
578 | idvar = iom_file(kiomid)%nvars + 1 |
---|
579 | ! are we in define mode? |
---|
580 | IF( iom_file(kiomid)%irec /= -1 ) THEN ! trick: irec used to know if the file is in define mode or not |
---|
581 | CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo) ; iom_file(kiomid)%irec = -1 |
---|
582 | ENDIF |
---|
583 | ! variable definition |
---|
584 | IF( PRESENT(pv_r0d) ) THEN ; idims = 0 |
---|
585 | ELSEIF( PRESENT(pv_r1d) ) THEN |
---|
586 | IF( SIZE(pv_r1d,1) == jpk ) THEN ; idim3 = 3 |
---|
587 | ELSE ; idim3 = 5 |
---|
588 | ENDIF |
---|
589 | idims = 2 ; idimid(1:idims) = (/idim3,4/) |
---|
590 | ELSEIF( PRESENT(pv_r2d) ) THEN ; idims = 3 ; idimid(1:idims) = (/1,2 ,4/) |
---|
591 | ELSEIF( PRESENT(pv_r3d) ) THEN |
---|
592 | IF( SIZE(pv_r3d,3) == jpk ) THEN ; idim3 = 3 |
---|
593 | ELSE ; idim3 = 5 |
---|
594 | ENDIF |
---|
595 | idims = 4 ; idimid(1:idims) = (/1,2,idim3,4/) |
---|
596 | ENDIF |
---|
597 | IF( PRESENT(ktype) ) THEN ! variable external type |
---|
598 | SELECT CASE (ktype) |
---|
599 | CASE (jp_r8) ; itype = NF90_DOUBLE |
---|
600 | CASE (jp_r4) ; itype = NF90_FLOAT |
---|
601 | CASE (jp_i4) ; itype = NF90_INT |
---|
602 | CASE (jp_i2) ; itype = NF90_SHORT |
---|
603 | CASE (jp_i1) ; itype = NF90_BYTE |
---|
604 | CASE DEFAULT ; CALL ctl_stop( TRIM(clinfo)//' unknown variable type' ) |
---|
605 | END SELECT |
---|
606 | ELSE |
---|
607 | itype = NF90_DOUBLE |
---|
608 | ENDIF |
---|
609 | IF( PRESENT(pv_r0d) ) THEN |
---|
610 | CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype, & |
---|
611 | & iom_file(kiomid)%nvid(idvar) ), clinfo ) |
---|
612 | ELSE |
---|
613 | CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype, idimid(1:idims), & |
---|
614 | & iom_file(kiomid)%nvid(idvar) ), clinfo ) |
---|
615 | ENDIF |
---|
616 | lchunk = .false. |
---|
617 | IF( snc4set%luse .AND. idims == 4 ) lchunk = .true. |
---|
618 | ! update informations structure related the new variable we want to add... |
---|
619 | iom_file(kiomid)%nvars = idvar |
---|
620 | iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar) |
---|
621 | iom_file(kiomid)%scf(idvar) = 1. |
---|
622 | iom_file(kiomid)%ofs(idvar) = 0. |
---|
623 | iom_file(kiomid)%ndims(idvar) = idims |
---|
624 | IF( .NOT. PRESENT(pv_r0d) ) THEN ; iom_file(kiomid)%luld(idvar) = .TRUE. |
---|
625 | ELSE ; iom_file(kiomid)%luld(idvar) = .FALSE. |
---|
626 | ENDIF |
---|
627 | DO jd = 1, idims |
---|
628 | CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, idimid(jd), len = iom_file(kiomid)%dimsz(jd,idvar) ), clinfo) |
---|
629 | IF ( lchunk ) ichunksz(jd) = iom_file(kiomid)%dimsz(jd,idvar) |
---|
630 | END DO |
---|
631 | IF ( lchunk ) THEN |
---|
632 | ! Calculate chunk sizes by partitioning each dimension as requested in namnc4 namelist |
---|
633 | ! Disallow very small chunk sizes and prevent chunk sizes larger than each individual dimension |
---|
634 | ichunksz(1) = MIN( ichunksz(1),MAX( (ichunksz(1)-1)/snc4set%ni + 1 ,16 ) ) ! Suggested default nc4set%ni=4 |
---|
635 | ichunksz(2) = MIN( ichunksz(2),MAX( (ichunksz(2)-1)/snc4set%nj + 1 ,16 ) ) ! Suggested default nc4set%nj=2 |
---|
636 | ichunksz(3) = MIN( ichunksz(3),MAX( (ichunksz(3)-1)/snc4set%nk + 1 , 1 ) ) ! Suggested default nc4set%nk=6 |
---|
637 | ichunksz(4) = 1 ! Do not allow chunks to span the |
---|
638 | ! ! unlimited dimension |
---|
639 | CALL iom_nf90_check(SET_NF90_DEF_VAR_CHUNKING(if90id, idvar, ichunkalg, ichunksz), clinfo) |
---|
640 | CALL iom_nf90_check(SET_NF90_DEF_VAR_DEFLATE(if90id, idvar, ishuffle, ideflate, ideflate_level), clinfo) |
---|
641 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' chunked ok. Chunks sizes: ', ichunksz |
---|
642 | ENDIF |
---|
643 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok' |
---|
644 | ELSE |
---|
645 | idvar = kvid |
---|
646 | ENDIF |
---|
647 | ! |
---|
648 | ! time step kwrite : write the variable |
---|
649 | IF( kt == kwrite ) THEN |
---|
650 | ! are we in write mode? |
---|
651 | IF( iom_file(kiomid)%irec == -1 ) THEN ! trick: irec used to know if the file is in define mode or not |
---|
652 | CALL iom_nf90_check(NF90_ENDDEF( if90id ), clinfo) ; iom_file(kiomid)%irec = 0 |
---|
653 | ENDIF |
---|
654 | ! on what kind of domain must the data be written? |
---|
655 | IF( PRESENT(pv_r2d) .OR. PRESENT(pv_r3d) ) THEN |
---|
656 | idimsz(1:2) = iom_file(kiomid)%dimsz(1:2,idvar) |
---|
657 | IF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN |
---|
658 | ix1 = nldi ; ix2 = nlei ; iy1 = nldj ; iy2 = nlej |
---|
659 | ELSEIF( idimsz(1) == nlci .AND. idimsz(2) == nlcj ) THEN |
---|
660 | ix1 = 1 ; ix2 = nlci ; iy1 = 1 ; iy2 = nlcj |
---|
661 | ELSEIF( idimsz(1) == jpi .AND. idimsz(2) == jpj ) THEN |
---|
662 | ix1 = 1 ; ix2 = jpi ; iy1 = 1 ; iy2 = jpj |
---|
663 | ELSE |
---|
664 | CALL ctl_stop( 'iom_nf90_rp0123d: should have been an impossible case...' ) |
---|
665 | ENDIF |
---|
666 | |
---|
667 | ! write dimension variables if it is not already done |
---|
668 | ! ============= |
---|
669 | ! trick: is defined to 0 => dimension variable are defined but not yet written |
---|
670 | IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN |
---|
671 | CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'nav_lon' , idmy ) , clinfo ) |
---|
672 | CALL iom_nf90_check( NF90_PUT_VAR ( if90id, idmy, glamt(ix1:ix2, iy1:iy2) ), clinfo ) |
---|
673 | CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'nav_lat' , idmy ) , clinfo ) |
---|
674 | CALL iom_nf90_check( NF90_PUT_VAR ( if90id, idmy, gphit(ix1:ix2, iy1:iy2) ), clinfo ) |
---|
675 | CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'nav_lev' , idmy ), clinfo ) |
---|
676 | CALL iom_nf90_check( NF90_PUT_VAR ( if90id, idmy, gdept_1d ), clinfo ) |
---|
677 | IF( NF90_INQ_VARID( if90id, 'numcat', idmy ) == nf90_noerr ) THEN |
---|
678 | CALL iom_nf90_check( NF90_PUT_VAR ( if90id, idmy, (/ (idlv, idlv = 1,iom_file(kiomid)%nlev) /)), clinfo ) |
---|
679 | ENDIF |
---|
680 | ! +++ WRONG VALUE: to be improved but not really useful... |
---|
681 | CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'time_counter', idmy ), clinfo ) |
---|
682 | CALL iom_nf90_check( NF90_PUT_VAR( if90id, idmy, kt ), clinfo ) |
---|
683 | ! update the values of the variables dimensions size |
---|
684 | CALL iom_nf90_check( NF90_INQUIRE_DIMENSION( if90id, 1, len = iom_file(kiomid)%dimsz(1,1) ), clinfo ) |
---|
685 | CALL iom_nf90_check( NF90_INQUIRE_DIMENSION( if90id, 2, len = iom_file(kiomid)%dimsz(2,1) ), clinfo ) |
---|
686 | iom_file(kiomid)%dimsz(1:2, 2) = iom_file(kiomid)%dimsz(1:2, 1) |
---|
687 | CALL iom_nf90_check( NF90_INQUIRE_DIMENSION( if90id, 3, len = iom_file(kiomid)%dimsz(1,3) ), clinfo ) |
---|
688 | iom_file(kiomid)%dimsz(1 , 4) = 1 ! unlimited dimension |
---|
689 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done' |
---|
690 | ENDIF |
---|
691 | ENDIF |
---|
692 | |
---|
693 | ! write the data |
---|
694 | ! ============= |
---|
695 | IF( PRESENT(pv_r0d) ) THEN |
---|
696 | CALL iom_nf90_check( NF90_PUT_VAR( if90id, idvar, pv_r0d ), clinfo ) |
---|
697 | ELSEIF( PRESENT(pv_r1d) ) THEN |
---|
698 | CALL iom_nf90_check( NF90_PUT_VAR( if90id, idvar, pv_r1d(:) ), clinfo ) |
---|
699 | ELSEIF( PRESENT(pv_r2d) ) THEN |
---|
700 | CALL iom_nf90_check( NF90_PUT_VAR( if90id, idvar, pv_r2d(ix1:ix2,iy1:iy2) ), clinfo ) |
---|
701 | ELSEIF( PRESENT(pv_r3d) ) THEN |
---|
702 | CALL iom_nf90_check( NF90_PUT_VAR( if90id, idvar, pv_r3d(ix1:ix2,iy1:iy2,:) ), clinfo ) |
---|
703 | ENDIF |
---|
704 | ! add 1 to the size of the temporal dimension (not really useful...) |
---|
705 | IF( iom_file(kiomid)%luld(idvar) ) iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) & |
---|
706 | & = iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) + 1 |
---|
707 | IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok' |
---|
708 | ENDIF |
---|
709 | ! |
---|
710 | END SUBROUTINE iom_nf90_rp0123d |
---|
711 | |
---|
712 | |
---|
713 | SUBROUTINE iom_nf90_check( kstatus, cdinfo ) |
---|
714 | !!-------------------------------------------------------------------- |
---|
715 | !! *** SUBROUTINE iom_nf90_check *** |
---|
716 | !! |
---|
717 | !! ** Purpose : check nf90 errors |
---|
718 | !!-------------------------------------------------------------------- |
---|
719 | INTEGER, INTENT(in) :: kstatus |
---|
720 | CHARACTER(LEN=*), INTENT(in) :: cdinfo |
---|
721 | !--------------------------------------------------------------------- |
---|
722 | IF(kstatus /= nf90_noerr) CALL ctl_stop( 'iom_nf90_check : '//TRIM(nf90_strerror(kstatus)), TRIM(cdinfo) ) |
---|
723 | END SUBROUTINE iom_nf90_check |
---|
724 | |
---|
725 | !!====================================================================== |
---|
726 | END MODULE iom_nf90 |
---|