-
Notifications
You must be signed in to change notification settings - Fork 1
/
inv_trans.F90
394 lines (258 loc) · 8 KB
/
inv_trans.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
MODULE FIELD_MODULE
IMPLICIT NONE
TYPE FIELD_1RB
REAL, POINTER :: P (:)
END TYPE
TYPE FIELD_2RB
REAL, POINTER :: P (:,:)
END TYPE
TYPE FIELD_3RB
REAL, POINTER :: P (:,:,:)
END TYPE
TYPE FIELD_1RB_VIEW
REAL, POINTER :: V (:)
END TYPE
TYPE FIELD_2RB_VIEW
REAL, POINTER :: V (:,:)
END TYPE
INTERFACE LG_
MODULE PROCEDURE :: LG2RB, LG3RB
END INTERFACE
INTERFACE LS_
MODULE PROCEDURE :: LS1RB, LS2RB, LS3RB
END INTERFACE
INTERFACE FIELD_NEW
MODULE PROCEDURE :: FIELD_NEW_1RB, FIELD_NEW_2RB, FIELD_NEW_3RB
END INTERFACE
CONTAINS
SUBROUTINE FIELD_NEW_1RB (YLF, UBOUNDS)
CLASS (FIELD_1RB), POINTER :: YLF
INTEGER :: UBOUNDS (1)
ALLOCATE (YLF)
ALLOCATE (YLF%P (UBOUNDS (1)))
END SUBROUTINE
SUBROUTINE FIELD_NEW_2RB (YLF, UBOUNDS)
CLASS (FIELD_2RB), POINTER :: YLF
INTEGER :: UBOUNDS (2)
ALLOCATE (YLF)
ALLOCATE (YLF%P (UBOUNDS (1), UBOUNDS (2)))
END SUBROUTINE
SUBROUTINE FIELD_NEW_3RB (YLF, UBOUNDS)
CLASS (FIELD_3RB), POINTER :: YLF
INTEGER :: UBOUNDS (3)
ALLOCATE (YLF)
ALLOCATE (YLF%P (UBOUNDS (1), UBOUNDS (2), UBOUNDS (3)))
END SUBROUTINE
FUNCTION LG2RB (YLF, LDACC)
CLASS (FIELD_2RB), POINTER :: YLF
LOGICAL, INTENT (IN) :: LDACC
TYPE (FIELD_2RB_VIEW), ALLOCATABLE :: LG2RB (:)
REAL, POINTER :: ZZ2 (:,:)
INTEGER :: I2, I3, J
ZZ2 => YLF%P
ALLOCATE (LG2RB (1))
LG2RB (1)%V => ZZ2
END FUNCTION
FUNCTION LG3RB (YLF, LDACC)
CLASS (FIELD_3RB), POINTER :: YLF
LOGICAL, INTENT (IN) :: LDACC
TYPE (FIELD_2RB_VIEW), ALLOCATABLE :: LG3RB (:)
REAL, POINTER :: ZZ3 (:,:,:)
INTEGER :: I2, J
ZZ3 => YLF%P
ALLOCATE (LG3RB (SIZE (ZZ3, 2)))
J = 1
DO I2 = LBOUND (ZZ3, 2), UBOUND (ZZ3, 2)
LG3RB (J)%V => ZZ3 (:, I2, :)
J = J + 1
ENDDO
END FUNCTION
FUNCTION LS1RB (YLF, LDACC)
CLASS (FIELD_1RB), POINTER :: YLF
LOGICAL, INTENT (IN) :: LDACC
TYPE (FIELD_1RB_VIEW), ALLOCATABLE :: LS1RB (:)
REAL, POINTER :: ZZ1 (:)
ZZ1 => YLF%P
ALLOCATE (LS1RB (1))
LS1RB (1)%V => ZZ1
END FUNCTION
FUNCTION LS2RB (YLF, LDACC)
CLASS (FIELD_2RB), POINTER :: YLF
LOGICAL, INTENT (IN) :: LDACC
TYPE (FIELD_1RB_VIEW), ALLOCATABLE :: LS2RB (:)
REAL, POINTER :: ZZ2 (:,:)
INTEGER :: I2, I3, J
ZZ2 => YLF%P
ALLOCATE (LS2RB (SIZE (ZZ2, 2)))
J = 1
DO I2 = LBOUND (ZZ2, 2), UBOUND (ZZ2, 2)
LS2RB (J)%V => ZZ2 (:, I2)
J = J + 1
ENDDO
END FUNCTION
FUNCTION LS3RB (YLF, LDACC)
CLASS (FIELD_3RB), POINTER :: YLF
LOGICAL, INTENT (IN) :: LDACC
TYPE (FIELD_1RB_VIEW), ALLOCATABLE :: LS3RB (:)
REAL, POINTER :: ZZ3 (:,:,:)
INTEGER :: I2, I3, J
ZZ3 => YLF%P
ALLOCATE (LS3RB (SIZE (ZZ3, 2) * SIZE (ZZ3, 3)))
J = 1
DO I3 = LBOUND (ZZ3, 3), UBOUND (ZZ3, 3)
DO I2 = LBOUND (ZZ3, 2), UBOUND (ZZ3, 2)
LS3RB (J)%V => ZZ3 (:, I2, I3)
J = J + 1
ENDDO
ENDDO
END FUNCTION
END MODULE
MODULE INV_TRANS_MODULE
USE FIELD_MODULE
CONTAINS
SUBROUTINE INV_TRANS (U, V, VOR, DIV, VSETUV, GRID, SPEC, VSET)
TYPE (FIELD_2RB_VIEW), OPTIONAL :: U (:), V (:), GRID (:)
TYPE (FIELD_1RB_VIEW), OPTIONAL :: VOR (:), DIV (:), SPEC (:)
INTEGER, OPTIONAL :: VSETUV (:), VSET (:)
REAL, ALLOCATABLE :: ZGPUV (:,:,:,:), ZSPVOR (:,:), ZSPDIV (:,:), ZGP (:,:,:), ZSPSCALAR (:,:)
INTEGER :: IPROMA, IGPBLKS, IFLDGUV, ISPEC2, IFLDSUV
IF (PRESENT (U) .NEQV. PRESENT (V)) STOP "U/V"
IF (PRESENT (U) .NEQV. PRESENT (VOR)) STOP "U/VOR"
IF (PRESENT (U) .NEQV. PRESENT (DIV)) STOP "U/DIV"
IF (PRESENT (U) .NEQV. PRESENT (VSETUV)) STOP "U/VSETUV"
IF (PRESENT (U)) THEN
IF ((SIZE (U) /= SIZE (V)) .OR. (SIZE (VOR) /= SIZE (DIV)) .OR. (SIZE (VSETUV) /= SIZE (U))) THEN
PRINT *, " U = ", SIZE (U)
PRINT *, " V = ", SIZE (V)
PRINT *, " VOR = ", SIZE (VOR)
PRINT *, " DIV = ", SIZE (DIV)
PRINT *, " VSETUV = ", SIZE (VSETUV)
STOP 1
ENDIF
IPROMA = SIZE (U (1)%V, 1)
IGPBLKS = SIZE (U (1)%V, 2)
IFLDGUV = SIZE (U)
ISPEC2 = SIZE (VOR (1)%V, 1)
IFLDSUV = SIZE (VOR)
ALLOCATE (ZGPUV (IPROMA, IFLDGUV, 2, IGPBLKS), ZSPVOR (ISPEC2, IFLDSUV), ZSPDIV (ISPEC2, IFLDSUV))
DO JFLD = 1, IFLDSUV
ZSPVOR (:, JFLD) = VOR (JFLD)%V (:)
ZSPDIV (:, JFLD) = DIV (JFLD)%V (:)
ENDDO
ELSE
IFLDSUV = 0
ALLOCATE (ZGPUV (0, IFLDSUV, 2, 0), ZSPVOR (0, 0), ZSPDIV (0, 0))
ENDIF
IF (PRESENT (GRID) .NEQV. PRESENT (SPEC)) STOP "GRID/SPEC"
IF (PRESENT (GRID) .NEQV. PRESENT (VSET)) STOP "GRID/VSET"
IF (PRESENT (GRID)) THEN
IF ((SIZE (GRID) /= SIZE (SPEC)) .AND. (SIZE (GRID) /= SIZE (VSET))) THEN
PRINT *, " SIZE (GRID) = ", SIZE (GRID)
PRINT *, " SIZE (SPEC) = ", SIZE (SPEC)
PRINT *, " SIZE (VSET) = ", SIZE (VSET)
STOP 1
ENDIF
IPROMA = SIZE (GRID (1)%V, 1)
IGPBLKS = SIZE (GRID (1)%V, 2)
IFLDG = SIZE (GRID)
ISPEC2 = SIZE (SPEC (1)%V, 1)
IFLDS = SIZE (SPEC)
ALLOCATE (ZGP (IPROMA, IFLDG, IGPBLKS), ZSPSCALAR (ISPEC2, IFLDS))
DO JFLD = 1, IFLDS
ZSPSCALAR (:,JFLD) = SPEC (JFLD)%V (:)
ENDDO
ELSE
IFLDG = 0
ALLOCATE (ZGP (0, IFLDG, 0), ZSPSCALAR (0, 0))
ENDIF
#ifdef UNDEF
CALL INV_TRANS (PSPVOR=ZSPVOR, PSPDIV=ZSPVIV, PGPUV=ZGPUV, KVSETUV=VSETUV, &
& PSPSCALAR=ZSPSCALAR, PGP=ZGP, KVSETSC=VSET, KPROMA=IPROMA)
#endif
DO JFLD = 1, IFLDGUV
U (JFLD)%V (:,:) = ZGPUV (:,JFLD,1,:)
V (JFLD)%V (:,:) = ZGPUV (:,JFLD,2,:)
ENDDO
DO JFLD = 1, IFLDG
GRID (JFLD)%V (:,:) = ZGP (:, JFLD, :)
ENDDO
END SUBROUTINE
END MODULE
PROGRAM MAIN
#include "ll.h"
USE FIELD_MODULE
USE INV_TRANS_MODULE
INTEGER, PARAMETER :: NPRTRW = 5, NPRTRV = 3, MYSETW = 1, MYSETV = 1
INTEGER, PARAMETER :: NPROMA = 100, NFLEVG = 15, NGPBLKS = 10, NSPEC2 = 600
INTEGER :: NFLEVL
CLASS (FIELD_3RB), POINTER :: GU, GV, GT, GQ
CLASS (FIELD_2RB), POINTER :: SVOR, SDIV, ST, SQ
CLASS (FIELD_2RB), POINTER :: GU1, GV1, GT1, GQ1
CLASS (FIELD_1RB), POINTER :: SVOR1, SDIV1, ST1, SQ1
TYPE (FIELD_2RB_VIEW), ALLOCATABLE :: U (:), V (:), GRID (:)
TYPE (FIELD_1RB_VIEW), ALLOCATABLE :: VOR (:), DIV (:), SPEC (:)
INTEGER :: NBSETP
INTEGER, ALLOCATABLE :: NBSETLEV (:)
INTEGER, ALLOCATABLE :: VSETUV (:), VSET (:)
LOGICAL :: LLACC
INTEGER :: JLEV
NBSETSP = 1
ALLOCATE (NBSETLEV (NFLEVG))
DO JLEV = 1, NFLEVG
NBSETLEV (JLEV) = 1 + ((JLEV-1) * (NPRTRV)) / NFLEVG
ENDDO
NFLEVL = COUNT (NBSETLEV == MYSETV)
CALL FIELD_NEW (GU, UBOUNDS=[NPROMA, NFLEVG, NGPBLKS])
CALL FIELD_NEW (GV, UBOUNDS=[NPROMA, NFLEVG, NGPBLKS])
CALL FIELD_NEW (GT, UBOUNDS=[NPROMA, NFLEVG, NGPBLKS])
CALL FIELD_NEW (GQ, UBOUNDS=[NPROMA, NFLEVG, NGPBLKS])
CALL FIELD_NEW (SVOR, UBOUNDS=[NSPEC2, NFLEVL])
CALL FIELD_NEW (SDIV, UBOUNDS=[NSPEC2, NFLEVL])
CALL FIELD_NEW (ST, UBOUNDS=[NSPEC2, NFLEVL])
CALL FIELD_NEW (SQ, UBOUNDS=[NSPEC2, NFLEVL])
CALL FIELD_NEW (GU1, UBOUNDS=[NPROMA, NGPBLKS])
CALL FIELD_NEW (GV1, UBOUNDS=[NPROMA, NGPBLKS])
CALL FIELD_NEW (GT1, UBOUNDS=[NPROMA, NGPBLKS])
CALL FIELD_NEW (GQ1, UBOUNDS=[NPROMA, NGPBLKS])
CALL FIELD_NEW (SVOR1, UBOUNDS=[NSPEC2])
CALL FIELD_NEW (SDIV1, UBOUNDS=[NSPEC2])
CALL FIELD_NEW (ST1, UBOUNDS=[NSPEC2, NFLEVL])
CALL FIELD_NEW (SQ1, UBOUNDS=[NSPEC2, NFLEVL])
! Create list arguments
CALL INV_TRANS (U=[LG (GU), LG (GU1)], VOR=[LS (SVOR), LS (SVOR1)], &
& V=[LG (GV), LG (GV1)], DIV=[LS (SDIV), LS (SDIV1)], &
& VSETUV=[NBSETLEV, NBSETSP], &
& GRID=[LG (GT), LG (GQ), LG (GT1), LG (GQ1)], &
& SPEC=[LS (ST), LS (SQ), LS (ST1), LS (SQ1)], &
& VSET=[NBSETLEV, NBSETLEV, NBSETSP, NBSETSP])
! Build list
U = [LG (GU), LG (GU1)]
V = [LG (GV), LG (GV1)]
VOR = [LS (SVOR), LS (SVOR1)]
DIV = [LS (SDIV), LS (SDIV1)]
VSETUV = [NBSETLEV, NBSETSP]
GRID = [LG (GT), LG (GQ), LG (GT1), LG (GQ1)]
SPEC = [LS (ST), LS (SQ), LS (ST1), LS (SQ1)]
VSET = [NBSETLEV, NBSETLEV, NBSETSP, NBSETSP]
CALL INV_TRANS (U=U, V=V, VOR=VOR, DIV=DIV, VSETUV=VSETUV, &
& GRID=GRID, SPEC=SPEC, VSET=VSET)
! Build list in two steps
! First step : 3D fields
U = [LG (GU)]
V = [LG (GV)]
VOR = [LS (SVOR)]
DIV = [LS (SDIV)]
VSETUV = [NBSETLEV]
GRID = [LG (GT), LG (GQ)]
SPEC = [LS (ST), LS (SQ)]
! Append surface fields
U = [U, LG (GU1)]
V = [V, LG (GV1)]
VOR = [VOR, LS (SVOR1)]
DIV = [DIV, LS (SDIV1)]
VSETUV = [VSETUV, NBSETSP]
GRID = [GRID, LG (GT1), LG (GQ1)]
SPEC = [SPEC, LS (ST1), LS (SQ1)]
CALL INV_TRANS (U=U, V=V, VOR=VOR, DIV=DIV, VSETUV=VSETUV, &
& GRID=GRID, SPEC=SPEC, VSET=VSET)
END