1 | !! This subroutines initialize a variable or an array |
---|
2 | !! with a variable or an array of smaller rank |
---|
3 | !! - i is for integer interface - r for real interface |
---|
4 | !! - 0 is for a scalar - 1 for a 1D array - 2 for a 2D array |
---|
5 | !! Thee right routines is automatically called depending type of input variable |
---|
6 | !! This initialisation is done only if the value of input field is egal to val_exp |
---|
7 | !! |
---|
8 | !! If a key word is provided which is not equal to "NO_KEYWORD" or "NOKEYWORD" then |
---|
9 | !! we try to find the value to fill in in the configuration file. |
---|
10 | !! |
---|
11 | !! @author Marie-Alice Foujols and Jan Polcher |
---|
12 | !! @Version : $Revision: 1540 $, $Date: 2013-10-15 18:16:19 +0200 (Tue, 15 Oct 2013) $ |
---|
13 | !! |
---|
14 | !< $HeadURL: svn://forge.ipsl.jussieu.fr/orchidee/perso/shushi.peng/ORCHIDEE/src_sechiba/sechiba_io_p.f90 $ |
---|
15 | !< $Date: 2013-10-15 18:16:19 +0200 (Tue, 15 Oct 2013) $ |
---|
16 | !< $Author: josefine.ghattas $ |
---|
17 | !< $Revision: 1540 $ |
---|
18 | !! IPSL (2006) |
---|
19 | !! This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC |
---|
20 | !! |
---|
21 | MODULE sechiba_io_p |
---|
22 | |
---|
23 | USE defprec |
---|
24 | USE constantes |
---|
25 | USE ioipsl |
---|
26 | USE ioipsl_para |
---|
27 | USE mod_orchidee_para |
---|
28 | |
---|
29 | IMPLICIT NONE |
---|
30 | |
---|
31 | INTERFACE setvar_p |
---|
32 | MODULE PROCEDURE i0setvar_p, i10setvar_p, i20setvar_p, i11setvar_p, i21setvar_p, i22setvar_p |
---|
33 | MODULE PROCEDURE r0setvar_p, r10setvar_p, r20setvar_p, r11setvar_p, r21setvar_p, r22setvar_p, r30setvar_p |
---|
34 | END INTERFACE |
---|
35 | |
---|
36 | ! |
---|
37 | ! mettre la l'interface des routines utilisees: |
---|
38 | ! |
---|
39 | ! restget/put/ini histbeg/def flinopen/close |
---|
40 | ! |
---|
41 | |
---|
42 | LOGICAL, SAVE :: long_print_setvar_p=.FALSE. !! change to true to have more information |
---|
43 | !$OMP THREADPRIVATE(long_print_setvar_p) |
---|
44 | |
---|
45 | CONTAINS |
---|
46 | |
---|
47 | !! Interface for integer scalar to scalar. |
---|
48 | SUBROUTINE i0setvar_p (var, val_exp, key_wd, val_put) |
---|
49 | |
---|
50 | INTEGER(i_std), INTENT(inout) :: var !! Integer scalar to modify |
---|
51 | INTEGER(i_std), INTENT(in) :: val_exp !! Exceptional value |
---|
52 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
53 | INTEGER(i_std), INTENT(in) :: val_put !! Initial value to stored |
---|
54 | |
---|
55 | INTEGER(i_std) :: val_tmp |
---|
56 | INTEGER(i_std) :: is_key |
---|
57 | |
---|
58 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
59 | |
---|
60 | IF (long_print_setvar_p) WRITE (numout,*) "i0setvar :", key_wd, val_exp, val_put |
---|
61 | |
---|
62 | val_tmp = val_put |
---|
63 | |
---|
64 | IF ( var == val_exp ) THEN |
---|
65 | IF ( is_key <= 0 ) THEN |
---|
66 | CALL getin_p(key_wd, val_tmp) |
---|
67 | ENDIF |
---|
68 | var = val_tmp |
---|
69 | END IF |
---|
70 | |
---|
71 | END SUBROUTINE i0setvar_p |
---|
72 | |
---|
73 | |
---|
74 | !! Interface for initialising an 1D integer array with a scalar integer. |
---|
75 | SUBROUTINE i10setvar_p (var, val_exp, key_wd, val_put) |
---|
76 | |
---|
77 | INTEGER(i_std), DIMENSION(:), INTENT(inout) :: var !! 1D integer array to modify |
---|
78 | INTEGER(i_std), INTENT(in) :: val_exp !! Exceptional value |
---|
79 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
80 | INTEGER(i_std), INTENT(in) :: val_put !! Scalar value to stored |
---|
81 | |
---|
82 | INTEGER(i_std) :: val_tmp |
---|
83 | INTEGER(i_std) :: is_key |
---|
84 | |
---|
85 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
86 | |
---|
87 | IF (long_print_setvar_p) WRITE (numout,*) "i10setvar :", key_wd, val_exp, val_put |
---|
88 | |
---|
89 | val_tmp = val_put |
---|
90 | |
---|
91 | IF ( ALL( var(:) == val_exp ) ) THEN |
---|
92 | IF ( is_key <= 0 ) THEN |
---|
93 | CALL getin_p(key_wd, val_tmp) |
---|
94 | ENDIF |
---|
95 | var(:) = val_tmp |
---|
96 | END IF |
---|
97 | |
---|
98 | END SUBROUTINE i10setvar_p |
---|
99 | |
---|
100 | |
---|
101 | !! Interface for initialising an 1D array integer with an other 1D array integer. |
---|
102 | SUBROUTINE i11setvar_p (var, val_exp, key_wd, val_put, is_grid) |
---|
103 | |
---|
104 | INTEGER(i_std), DIMENSION(:), INTENT(inout) :: var !! 1D integer array to modify |
---|
105 | INTEGER(i_std), INTENT(in) :: val_exp !! Exceptional value |
---|
106 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
107 | INTEGER(i_std), DIMENSION(:), INTENT(in) :: val_put !! 1D integer array to stored |
---|
108 | LOGICAL, OPTIONAL :: is_grid !! Parameter present indicates a setvar for a grid variable |
---|
109 | |
---|
110 | INTEGER(i_std), ALLOCATABLE,DIMENSION(:) :: val_tmp |
---|
111 | INTEGER(i_std), ALLOCATABLE,DIMENSION(:) :: val_tmp_g |
---|
112 | INTEGER(i_std) :: is_key |
---|
113 | |
---|
114 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
115 | |
---|
116 | IF (long_print_setvar_p) WRITE (numout,*) "i11setvar :", key_wd, val_exp, SIZE(val_put), val_put(1) |
---|
117 | |
---|
118 | ALLOCATE(val_tmp(SIZE(val_put))) |
---|
119 | val_tmp(:) = val_put(:) |
---|
120 | |
---|
121 | IF ( ALL( var(:) == val_exp ) ) THEN |
---|
122 | IF ( is_key <= 0 ) THEN |
---|
123 | IF (PRESENT(is_grid) ) THEN |
---|
124 | IF (is_root_prc) THEN |
---|
125 | ALLOCATE( val_tmp_g(nbp_glo) ) |
---|
126 | ELSE |
---|
127 | ALLOCATE( val_tmp_g(1) ) |
---|
128 | ENDIF |
---|
129 | CALL gather( val_tmp,val_tmp_g ) |
---|
130 | IF (is_root_prc) & |
---|
131 | CALL getin(key_wd, val_tmp_g) |
---|
132 | CALL scatter( val_tmp,val_tmp_g ) |
---|
133 | DEALLOCATE( val_tmp_g ) |
---|
134 | ELSE |
---|
135 | CALL getin_p(key_wd, val_tmp) |
---|
136 | ENDIF |
---|
137 | ENDIF |
---|
138 | var(:) = val_tmp (:) |
---|
139 | END IF |
---|
140 | |
---|
141 | DEALLOCATE(val_tmp) |
---|
142 | |
---|
143 | END SUBROUTINE i11setvar_p |
---|
144 | |
---|
145 | |
---|
146 | !! Interface for initialising an 2D array integer with a scalar integer. |
---|
147 | SUBROUTINE i20setvar_p (var, val_exp, key_wd, val_put) |
---|
148 | |
---|
149 | INTEGER(i_std), DIMENSION(:,:), INTENT(inout) :: var !! 2D integer array to modify |
---|
150 | INTEGER(i_std), INTENT(in) :: val_exp !! Exceptional value |
---|
151 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
152 | INTEGER(i_std), INTENT(in) :: val_put !! Scalar value to stored |
---|
153 | |
---|
154 | INTEGER(i_std) :: val_tmp |
---|
155 | INTEGER(i_std) :: is_key |
---|
156 | |
---|
157 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
158 | |
---|
159 | ! |
---|
160 | ! this subroutine set val_put value to var if var is constant |
---|
161 | ! |
---|
162 | ! |
---|
163 | IF (long_print_setvar_p) WRITE (numout,*) "i20setvar :", key_wd, val_exp, val_put |
---|
164 | |
---|
165 | val_tmp = val_put |
---|
166 | |
---|
167 | IF ( ALL( var(:,:) == val_exp ) ) THEN |
---|
168 | IF ( is_key <= 0 ) THEN |
---|
169 | CALL getin_p(key_wd, val_tmp) |
---|
170 | ENDIF |
---|
171 | var(:,:) = val_tmp |
---|
172 | END IF |
---|
173 | |
---|
174 | END SUBROUTINE i20setvar_p |
---|
175 | |
---|
176 | |
---|
177 | !! Interface for initialising an 2D array integer with an 1D array integer. |
---|
178 | !! Row or column depending size of 1D array to stored. |
---|
179 | !! |
---|
180 | !! example: 1D 1,2,3 2D is 1, 2, 3, |
---|
181 | !! 1, 2, 3 |
---|
182 | !! |
---|
183 | !! |
---|
184 | !! example: 1D 1,2,3 2D is 1, 1, |
---|
185 | !! 2, 2, |
---|
186 | !! 3, 3 |
---|
187 | !! |
---|
188 | SUBROUTINE i21setvar_p (var, val_exp, key_wd, val_put, is_grid) |
---|
189 | |
---|
190 | INTEGER(i_std), DIMENSION(:,:), INTENT(inout) :: var !! 2D integer array to modify |
---|
191 | INTEGER(i_std), INTENT(in) :: val_exp !! Exceptional value |
---|
192 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
193 | INTEGER(i_std), DIMENSION(:), INTENT(in) :: val_put !! 1D integer array to stored |
---|
194 | LOGICAL, OPTIONAL :: is_grid !! Parameter present indicates a setvar for a grid variable |
---|
195 | |
---|
196 | INTEGER(i_std), ALLOCATABLE,DIMENSION(:) :: val_tmp |
---|
197 | INTEGER(i_std) :: is_key |
---|
198 | |
---|
199 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
200 | |
---|
201 | ! test if the 1D array dimension is compatible with first or second |
---|
202 | ! dimension of the 2D array |
---|
203 | |
---|
204 | IF (long_print_setvar_p) WRITE (numout,*) "i21setvar :", key_wd, val_exp, val_put |
---|
205 | |
---|
206 | ALLOCATE(val_tmp(SIZE(val_put))) |
---|
207 | val_tmp(:) = val_put(:) |
---|
208 | |
---|
209 | IF (SIZE(val_put)==SIZE(var,1)) THEN |
---|
210 | ! |
---|
211 | ! example: 1D 1.,2.,3. 2D is 1., 2., 3., |
---|
212 | ! 1., 2., 3. |
---|
213 | ! |
---|
214 | IF ( ALL( var(:,:) == val_exp ) ) THEN |
---|
215 | IF ( is_key <= 0 ) THEN |
---|
216 | CALL getin_p(key_wd, val_tmp) |
---|
217 | ENDIF |
---|
218 | var(:,:) = SPREAD(val_tmp(:),2,SIZE(var,1)) |
---|
219 | END IF |
---|
220 | ELSEIF (SIZE(val_put)==SIZE(var,2)) THEN |
---|
221 | ! |
---|
222 | ! example: 1D 1.,2.,3. 2D is 1., 1., |
---|
223 | ! 2., 2., |
---|
224 | ! 3., 3. |
---|
225 | ! |
---|
226 | IF ( ALL( var(:,:) == val_exp ) ) THEN |
---|
227 | IF ( is_key <= 0 ) THEN |
---|
228 | CALL getin_p(key_wd, val_tmp) |
---|
229 | ENDIF |
---|
230 | var(:,:) = SPREAD(val_tmp(:),1,SIZE(var,1)) |
---|
231 | END IF |
---|
232 | ELSE |
---|
233 | WRITE (numout,*) ' incompatible dimension var and val_put' |
---|
234 | WRITE (numout,*) ' var ', SIZE(var,1), SIZE(var,2) |
---|
235 | WRITE (numout,*) ' val_put ', SIZE(val_put) |
---|
236 | STOP 'setvar' |
---|
237 | END IF |
---|
238 | |
---|
239 | DEALLOCATE(val_tmp) |
---|
240 | |
---|
241 | END SUBROUTINE i21setvar_p |
---|
242 | |
---|
243 | !! Interface for initialising an 2D array integer with an other 2D array integer. |
---|
244 | SUBROUTINE i22setvar_p (var, val_exp, key_wd, val_put, is_grid) |
---|
245 | |
---|
246 | INTEGER(i_std), DIMENSION(:,:), INTENT(inout) :: var !! 2D integer array to modify |
---|
247 | INTEGER(i_std), INTENT(in) :: val_exp !! Exceptional value |
---|
248 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
249 | INTEGER(i_std), DIMENSION(:,:), INTENT(in) :: val_put !! 2D integer array to stored |
---|
250 | LOGICAL, OPTIONAL :: is_grid !! Parameter present indicates a setvar for a grid variable |
---|
251 | |
---|
252 | INTEGER(i_std), ALLOCATABLE, DIMENSION(:,:) :: val_tmp |
---|
253 | INTEGER(i_std) :: is_key |
---|
254 | |
---|
255 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
256 | |
---|
257 | IF (long_print_setvar_p) WRITE (numout,*) "i21setvar :", key_wd, val_exp, SIZE(val_put), val_put(1,1) |
---|
258 | |
---|
259 | ALLOCATE(val_tmp(SIZE(val_put,DIM=1),SIZE(val_put,DIM=2))) |
---|
260 | val_tmp(:,:) = val_put(:,:) |
---|
261 | |
---|
262 | IF ( ALL(var(:,:) == val_exp ) ) THEN |
---|
263 | IF ( is_key <= 0 ) THEN |
---|
264 | CALL getin_p(key_wd, val_tmp) |
---|
265 | ENDIF |
---|
266 | var(:,:) = val_tmp(:,:) |
---|
267 | END IF |
---|
268 | |
---|
269 | DEALLOCATE(val_tmp) |
---|
270 | |
---|
271 | END SUBROUTINE i22setvar_p |
---|
272 | |
---|
273 | |
---|
274 | !! Interface for scalar to scalar real |
---|
275 | SUBROUTINE r0setvar_p (var, val_exp, key_wd, val_put) |
---|
276 | |
---|
277 | REAL(r_std), INTENT(inout) :: var !! Real scalar to modify |
---|
278 | REAL(r_std), INTENT(in) :: val_exp !! Exceptional value |
---|
279 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
280 | REAL(r_std), INTENT(in) :: val_put !! Initial value to stored |
---|
281 | |
---|
282 | REAL(r_std) :: val_tmp |
---|
283 | INTEGER(i_std) :: is_key |
---|
284 | |
---|
285 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
286 | |
---|
287 | IF (long_print_setvar_p) WRITE (numout,*) "r0setvar :", key_wd, val_exp, val_put |
---|
288 | |
---|
289 | val_tmp = val_put |
---|
290 | |
---|
291 | IF ( var==val_exp ) THEN |
---|
292 | IF ( is_key <= 0 ) THEN |
---|
293 | CALL getin_p(key_wd, val_tmp) |
---|
294 | ENDIF |
---|
295 | var = val_tmp |
---|
296 | END IF |
---|
297 | |
---|
298 | END SUBROUTINE r0setvar_p |
---|
299 | |
---|
300 | |
---|
301 | !! Interface for initialising an 1D real array with a scalar real. |
---|
302 | SUBROUTINE r10setvar_p (var, val_exp, key_wd, val_put) |
---|
303 | |
---|
304 | REAL(r_std), DIMENSION(:), INTENT(inout) :: var !! 1D real array to modify |
---|
305 | REAL(r_std), INTENT(in) :: val_exp !! Exceptional value |
---|
306 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
307 | REAL(r_std), INTENT(in) :: val_put !! Scalar value to stored |
---|
308 | |
---|
309 | REAL(r_std) :: val_tmp |
---|
310 | INTEGER(i_std) :: is_key |
---|
311 | |
---|
312 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
313 | |
---|
314 | IF (long_print_setvar_p) WRITE (numout,*) "r10setvar :", key_wd, val_exp, val_put |
---|
315 | |
---|
316 | val_tmp = val_put |
---|
317 | |
---|
318 | IF ( ALL( var(:) == val_exp ) ) THEN |
---|
319 | IF ( is_key <= 0 ) THEN |
---|
320 | CALL getin_p(key_wd, val_tmp) |
---|
321 | ENDIF |
---|
322 | var(:) = val_tmp |
---|
323 | END IF |
---|
324 | |
---|
325 | END SUBROUTINE r10setvar_p |
---|
326 | |
---|
327 | |
---|
328 | !! Interface for initialising an 1D array real with an other 1D array real. |
---|
329 | SUBROUTINE r11setvar_p (var, val_exp, key_wd, val_put, is_grid) |
---|
330 | |
---|
331 | REAL(r_std), DIMENSION(:), INTENT(inout) :: var !! 1D real array to modify |
---|
332 | REAL(r_std), INTENT(in) :: val_exp !! Exceptional value |
---|
333 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
334 | REAL(r_std), DIMENSION(:), INTENT(in) :: val_put !! 1D integer array to stored |
---|
335 | LOGICAL, OPTIONAL :: is_grid !! Parameter present indicates a setvar for a grid variable |
---|
336 | |
---|
337 | REAL(r_std), ALLOCATABLE,DIMENSION(:) :: val_tmp |
---|
338 | INTEGER(i_std) :: is_key |
---|
339 | |
---|
340 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
341 | |
---|
342 | IF (long_print_setvar_p) WRITE (numout,*) "r11setvar :", key_wd, val_exp, SIZE(val_put), val_put(1) |
---|
343 | |
---|
344 | ALLOCATE(val_tmp(SIZE(val_put))) |
---|
345 | val_tmp(:) = val_put(:) |
---|
346 | |
---|
347 | IF ( ALL( var(:) == val_exp ) ) THEN |
---|
348 | IF ( is_key <= 0 ) THEN |
---|
349 | CALL getin_p(key_wd, val_tmp) |
---|
350 | ENDIF |
---|
351 | var(:) = val_tmp (:) |
---|
352 | END IF |
---|
353 | |
---|
354 | DEALLOCATE(val_tmp) |
---|
355 | |
---|
356 | END SUBROUTINE r11setvar_p |
---|
357 | |
---|
358 | |
---|
359 | !! Interface for initialising an 2D array real with a scalar real. |
---|
360 | SUBROUTINE r20setvar_p (var, val_exp, key_wd, val_put) |
---|
361 | |
---|
362 | ! interface for scalar to 2D array real |
---|
363 | |
---|
364 | REAL(r_std), DIMENSION(:,:), INTENT(inout) :: var !! 2D integer array to modify |
---|
365 | REAL(r_std), INTENT(in) :: val_exp !! Exceptional value |
---|
366 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
367 | REAL(r_std), INTENT(in) :: val_put !! Scalar value to stored |
---|
368 | |
---|
369 | REAL(r_std) :: val_tmp |
---|
370 | INTEGER(i_std) :: is_key |
---|
371 | |
---|
372 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
373 | |
---|
374 | IF (long_print_setvar_p) WRITE (numout,*) "r20setvar :", key_wd, val_exp, val_put |
---|
375 | |
---|
376 | val_tmp = val_put |
---|
377 | |
---|
378 | IF ( ALL( var(:,:) == val_exp ) ) THEN |
---|
379 | IF ( is_key <= 0 ) THEN |
---|
380 | CALL getin_p(key_wd, val_tmp) |
---|
381 | ENDIF |
---|
382 | var(:,:) = val_tmp |
---|
383 | END IF |
---|
384 | |
---|
385 | END SUBROUTINE r20setvar_p |
---|
386 | |
---|
387 | |
---|
388 | !! Interface for initialising an 2D array real with an 1D array real. |
---|
389 | !! Row or column depending size of 1D array to stored. |
---|
390 | !! |
---|
391 | !! example: 1D 1.,2.,3. 2D is 1., 2., 3., |
---|
392 | !! 1., 2., 3. |
---|
393 | !! |
---|
394 | !! |
---|
395 | !! example: 1D 1.,2.,3. 2D is 1., 1., |
---|
396 | !! 2., 2., |
---|
397 | !! 3., 3. |
---|
398 | !! |
---|
399 | SUBROUTINE r21setvar_p (var, val_exp, key_wd, val_put, is_grid) |
---|
400 | |
---|
401 | ! interface for 1D array to 2D array real |
---|
402 | |
---|
403 | REAL(r_std), DIMENSION(:,:), INTENT(inout) :: var !! 2D real array to modify |
---|
404 | REAL(r_std), INTENT(in) :: val_exp !! Exceptional value |
---|
405 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
406 | REAL(r_std), DIMENSION(:), INTENT(in) :: val_put !! 1D real array to stored |
---|
407 | LOGICAL, OPTIONAL :: is_grid !! Parameter present indicates a setvar for a grid variable |
---|
408 | |
---|
409 | REAL(r_std), ALLOCATABLE,DIMENSION(:) :: val_tmp |
---|
410 | INTEGER(i_std) :: is_key |
---|
411 | |
---|
412 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
413 | |
---|
414 | ! test if the 1D array dimension is compatible with first or second |
---|
415 | ! dimension of the 2D array |
---|
416 | |
---|
417 | IF (long_print_setvar_p) WRITE (numout,*) "r21setvar :", key_wd, val_exp, SIZE(val_put), val_put(1) |
---|
418 | |
---|
419 | ALLOCATE(val_tmp(SIZE(val_put))) |
---|
420 | val_tmp(:) = val_put(:) |
---|
421 | |
---|
422 | IF (SIZE(val_put)==SIZE(var,1)) THEN |
---|
423 | ! |
---|
424 | ! example: 1D 1.,2.,3. 2D is 1., 2., 3., |
---|
425 | ! 1., 2., 3. |
---|
426 | ! |
---|
427 | IF ( ALL( var(:,:) == val_exp ) ) THEN |
---|
428 | IF ( is_key <= 0 ) THEN |
---|
429 | CALL getin_p(key_wd, val_tmp) |
---|
430 | ENDIF |
---|
431 | var(:,:) = SPREAD(val_tmp(:),2,SIZE(var,1)) |
---|
432 | END IF |
---|
433 | ELSEIF (SIZE(val_put)==SIZE(var,2)) THEN |
---|
434 | ! |
---|
435 | ! example: 1D 1.,2.,3. 2D is 1., 1., |
---|
436 | ! 2., 2., |
---|
437 | ! 3., 3. |
---|
438 | ! |
---|
439 | IF ( ALL( var(:,:) == val_exp ) ) THEN |
---|
440 | IF ( is_key <= 0 ) THEN |
---|
441 | CALL getin_p(key_wd, val_tmp) |
---|
442 | ENDIF |
---|
443 | var(:,:) = SPREAD(val_tmp(:),1,SIZE(var,1)) |
---|
444 | END IF |
---|
445 | ELSE |
---|
446 | WRITE (numout,*) ' incompatible dimension var and val_put' |
---|
447 | WRITE (numout,*) ' var ', SIZE(var,1), SIZE(var,2) |
---|
448 | WRITE (numout,*) ' val_put ', SIZE(val_put) |
---|
449 | STOP 'setvar' |
---|
450 | END IF |
---|
451 | |
---|
452 | DEALLOCATE(val_tmp) |
---|
453 | |
---|
454 | END SUBROUTINE r21setvar_p |
---|
455 | |
---|
456 | |
---|
457 | !! Interface for initialising a real 2D array with a scalar parameter from run.def or an other 2D array in argument |
---|
458 | SUBROUTINE r22setvar_p (var, val_exp, key_wd, val_put) |
---|
459 | |
---|
460 | ! interface for 2D array to 2D array real |
---|
461 | ! If a key_wd is set, it is supposed to be a scalar parameter will be read from run.def |
---|
462 | ! It is not possible to read a 2D variable from run.def |
---|
463 | |
---|
464 | REAL(r_std), DIMENSION(:,:), INTENT(inout) :: var !! 2D real array to modify |
---|
465 | REAL(r_std), INTENT(in) :: val_exp !! Exceptional value |
---|
466 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
467 | REAL(r_std), DIMENSION(:,:), INTENT(in) :: val_put !! 2D integer array to stored |
---|
468 | REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: val_tmp |
---|
469 | REAL(r_std) :: val_scal !! Temporary variable to read a scalar value from run.def |
---|
470 | INTEGER(i_std) :: is_key |
---|
471 | |
---|
472 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
473 | |
---|
474 | IF (long_print_setvar_p) WRITE (numout,*) "r22setvar :", key_wd, val_exp, SIZE(val_put), val_put(1,1) |
---|
475 | |
---|
476 | ALLOCATE(val_tmp(SIZE(val_put,DIM=1),SIZE(val_put,DIM=2))) |
---|
477 | val_tmp(:,:) = val_put(:,:) |
---|
478 | |
---|
479 | IF ( ALL( var(:,:) == val_exp ) ) THEN |
---|
480 | IF ( is_key <= 0 ) THEN |
---|
481 | ! This case only read a scalar value with getin |
---|
482 | val_scal=val_exp |
---|
483 | CALL getin_p(key_wd, val_scal) |
---|
484 | ! If a value was found in run.def, then set val_tmp to this value. |
---|
485 | IF (val_scal/=val_exp) val_tmp(:,:)=val_scal |
---|
486 | ENDIF |
---|
487 | var(:,:) = val_tmp(:,:) |
---|
488 | END IF |
---|
489 | |
---|
490 | DEALLOCATE(val_tmp) |
---|
491 | |
---|
492 | END SUBROUTINE r22setvar_p |
---|
493 | |
---|
494 | !! Interface for initialising an 3D array real with a scalar real. |
---|
495 | SUBROUTINE r30setvar_p (var, val_exp, key_wd, val_put) |
---|
496 | |
---|
497 | ! interface for scalar to 3D array real |
---|
498 | |
---|
499 | REAL(r_std), DIMENSION(:,:,:), INTENT(inout) :: var !! 3D integer array to modify |
---|
500 | REAL(r_std), INTENT(in) :: val_exp !! Exceptional value |
---|
501 | CHARACTER(LEN=*), INTENT(in) :: key_wd !! The Key word we will look for |
---|
502 | REAL(r_std), INTENT(in) :: val_put !! Scalar value to stored |
---|
503 | |
---|
504 | REAL(r_std) :: val_tmp |
---|
505 | INTEGER(i_std) :: is_key |
---|
506 | |
---|
507 | is_key = MAX(INDEX(key_wd, 'NO_KEYWORD'), INDEX(key_wd, 'NOKEYWORD')) |
---|
508 | |
---|
509 | IF (long_print_setvar_p) WRITE(numout,*) 'r30setvar',val_exp, val_put |
---|
510 | |
---|
511 | val_tmp = val_put |
---|
512 | |
---|
513 | IF ( ALL( var(:,:,:) == val_exp ) ) THEN |
---|
514 | IF ( is_key <= 0 ) THEN |
---|
515 | CALL getin_p(key_wd, val_tmp) |
---|
516 | ENDIF |
---|
517 | var(:,:,:) = val_tmp |
---|
518 | END IF |
---|
519 | |
---|
520 | END SUBROUTINE r30setvar_p |
---|
521 | |
---|
522 | END MODULE sechiba_io_p |
---|