File: iaogdef.F

package info (click to toggle)
emoslib 000380%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 47,712 kB
  • ctags: 11,551
  • sloc: fortran: 89,643; ansic: 24,200; makefile: 370; sh: 355
file content (419 lines) | stat: -rwxr-xr-x 11,628 bytes parent folder | download | duplicates (2)
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
C Copyright 1981-2007 ECMWF
C 
C Licensed under the GNU Lesser General Public License which
C incorporates the terms and conditions of version 3 of the GNU
C General Public License.
C See LICENSE and gpl-3.0.txt for details.
C

      INTEGER FUNCTION IAOGDEF (PWEST, PEAST, PNORTH, PSOUTH,
     1   KGAUSS, KAREA, OCHNG, OIWEGLOBE, OINPOLE, OISPOLE,
     2   KIAREA, KPR, KERR)
C
C---->
C**** *IAOGDEF*
C
C     PURPOSE
C     _______
C
C     Set the output field definition variables.
C
C     INTERFACE
C     _________
C
C     IERR = IAOGDEF (PWEST, PEAST, PNORTH, PSOUTH, KGAUSS, KAREA,
C    1   OCHNG, OIWEGLOBE, OINPOLE, OISPOLE, KIAREA, KPR, KERR)
C
C     Input parameters
C     ________________
C
C     PWEST      - The Western limit of the output field area.
C
C     PEAST      - The Eastern limit of the output field area.
C
C     PNORTH     - The Northern limit of the output field area.
C
C     PSOUTH     - The Southern limit of the output field area.
C
C     KGAUSS     - The Gaussian truncation for the output field.
C
C     KAREA      - The previous output field area used for checking
C                  for definition changes.
C
C     OIWEGLOBE  - Flag indicating whether the INPUT field spans the
C                  globe in the West-East direction.
C
C     OINPOLE    - Flag indicating whether the INPUT field includes
C                  the North polar line of latitude.
C
C     OISPOLE    - Flag indicating whether the INPUT field includes
C                  the South polar line of latitude.
C
C     KIAREA     - The input field area which will be used for an
C                  uninitialised output field area when the input
C                  field is not global.
C
C     KPR        - The debug print switch.
C                  0  , No debugging output.
C                  1  , Produce debugging output.
C
C     KERR       - The error control flag.
C                  -ve, No error message. Return error code.
C                  0  , Hard failure with error message.
C                  +ve, Print error message. Return error code.
C
C     Output parameters
C     ________________
C
C     KAREA      - The output field area if the definition has changed.
C
C     OCHNG      - A flag variable indicating whether the definition
C                  has changed.
C
C     Return value
C     ____________
C
C     The error indicator (INTEGER).
C
C     Error and Warning Return Values
C     _______________________________
C
C     21601 An illegal Gaussian truncation was requested.
C     21602 The default West-East output limits for a non-global
C           input field did not match the increment.
C     21603 Default North-South limits were specified for a
C           non-global input field. This is not allowed for a
C           Gaussian output field.
C
C     Common block usage
C     __________________
C
C     nofld.common - This file contains all the output field
C                    definition variables.
C
C     NOGAUSS      - Output field Gaussian truncation is set.
C     NOREPR       - Output field representation is set.
C     NOSCNM       - Output field scanning mode is set.
C
C     EXTERNALS
C     _________
C
C     INTLOG     - Logs messages.
C
C     METHOD
C     ______
C
C     Check the output definition against the previous definition and
C     update appropriate definition variables.
C
C     REFERENCE
C     _________
C
C     None
C
C     COMMENTS
C     ________
C
C     Program contains sections 0 to 3 and 9
C
C     AUTHOR
C     ______
C
C     K. Fielding      *ECMWF*      Apr 1994
C
C     MODIFICATIONS
C     _____________
C
C     None
C
C----<
C     _______________________________________________________
C
C
C*    Section 0. Definition of variables.
C     _______________________________________________________
C
C*    Prefix conventions for variable names
C
C     Logical      L (but not LP), global or common.
C                  O, dummy argument
C                  G, local variable
C                  LP, parameter.
C     Character    C, global or common.
C                  H, dummy argument
C                  Y (but not YP), local variable
C                  YP, parameter.
C     Integer      M and N, global or common.
C                  K, dummy argument
C                  I, local variable
C                  J (but not JP), loop control
C                  JP, parameter.
C     REAL         A to F and Q to X, global or common.
C                  P (but not PP), dummy argument
C                  Z, local variable
C                  PP, parameter.
C
C     Implicit statement to force declarations
C
      IMPLICIT NONE
C
#include "parim.h"
#include "nofld.common"
C
C     Subroutine arguments
C
      LOGICAL OCHNG, OIWEGLOBE, OINPOLE, OISPOLE
      INTEGER KGAUSS, KPR, KERR
      INTEGER KAREA (4), KIAREA (4)
      REAL PWEST, PEAST, PNORTH, PSOUTH
C
C     Local variables
      LOGICAL GLOBE, GNS
      INTEGER INORTH, ISOUTH, IWEST, IEAST, IWEINC, IWETMP, ITEMP
      INTEGER IERR
      INTEGER JPROUTINE
      PARAMETER (JPROUTINE = 21600)
C
C     External functions
C
C     Transform definition variables that must be preserved
C
C
C     _______________________________________________________
C
C*    Section 1. Initialisation
C     _______________________________________________________
C
  100 CONTINUE
C
      IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IAOGDEF: Section 1.',JPQUIET)
C
      IAOGDEF = 0
C
      IERR = 0
C
      OCHNG = .FALSE.
C
      GNS = OINPOLE .AND. OISPOLE
C
      GLOBE = OIWEGLOBE .AND. GNS
C
      IF (KPR .GE. 1) THEN
         CALL INTLOG(JP_DEBUG,'IAOGDEF: Input parameters',JPQUIET)
         CALL INTLOG(JP_DEBUG,'IAOGDEF: Gaussian truncation = ',KGAUSS)
         CALL INTLOGR(JP_DEBUG,'IAOGDEF: Area North = ',PNORTH)
         CALL INTLOGR(JP_DEBUG,'IAOGDEF: Area West = ',PWEST)
         CALL INTLOGR(JP_DEBUG,'IAOGDEF: Area South = ',PSOUTH)
         CALL INTLOGR(JP_DEBUG,'IAOGDEF: Area East = ',PEAST)
      ENDIF
C
C     _______________________________________________________
C
C
C*    Section 2. Convert parameters to integer
C     _______________________________________________________
C
  200 CONTINUE
C
      IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IAOGDEF: Section 2.',JPQUIET)
C
C     Representation
C
      IF (NOREPR .NE. JPGAUSSIAN) THEN
         NOREPR = JPGAUSSIAN
         OCHNG = .TRUE.
      ENDIF
C
      NOSCNM = 0
C
C     North, South, West and East limits
C
      INORTH = NINT (PNORTH * PPMULT)
      ISOUTH = NINT (PSOUTH * PPMULT)
      IWEST = NINT (PWEST * PPMULT)
      IEAST = NINT (PEAST * PPMULT)
C
C     Direction increments for regular grids
C
      IWEINC = JP90 / KGAUSS
C
      IF (IWEINC * KGAUSS .NE. JP90) THEN
        IAOGDEF = JPROUTINE + 1
        IF (KERR .GE. 0) THEN
          CALL INTLOG(JP_ERROR,
     X      'IAOGDEF: Illegal gaussian truncation = ',KGAUSS)
          IF (KERR .EQ. 0) CALL INTLOG(JP_FATAL,
     X      'IAOGDEF: Interpolation failing.',JPQUIET)
        ENDIF
        GO TO 900
      ENDIF
C
C
C     _______________________________________________________
C
C
C*    Section 3. Adjust grid stride and area
C     _______________________________________________________
C
  300 CONTINUE
C
      IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IAOGDEF: Section 3.',JPQUIET)
C
C     Global field if all area limits are 0
C
      IF (INORTH .EQ. 0 .AND. ISOUTH .EQ. 0 .AND.
     X  IWEST .EQ. 0 .AND. IEAST .EQ. 0) THEN
C
        INORTH = JP90
        ISOUTH = - JP90
C
        IF (GLOBE) THEN
C
          IWEST = 0
          IEAST = JP360 - IWEINC
C
        ELSE
          IF (GNS) THEN
C
            IWEST = KIAREA (JPWEST)
            IEAST = KIAREA (JPEAST)
C
            IF (MOD (IEAST - IWEST, IWEINC) .NE. 0) THEN
              IAOGDEF = JPROUTINE + 2
              IF (KERR .GE. 0) THEN
                CALL INTLOG(JP_ERROR,
     X            'IAOGDEF: West-East increment ', IWEINC)
                CALL INTLOG(JP_ERROR,
     X            'IAOGDEF: does not match the range from ',IWEST)
                CALL INTLOG(JP_ERROR,
     X            'IAOGDEF: to ',IEAST)
                IF (KERR .EQ. 0) CALL INTLOG(JP_FATAL,
     X            'IAOGDEF: Interpolation failing.',JPQUIET)
              ENDIF
              GO TO 900
            ENDIF
          ELSE
            IAOGDEF = JPROUTINE + 3
              IF (KERR .GE. 0) THEN
                CALL INTLOG(JP_ERROR,
     X            'IAOGDEF: Must specify a range if Gaussian',JPQUIET)
                CALL INTLOG(JP_ERROR,
     X            'IAOGDEF: output and non-global input.',JPQUIET)
                IF (KERR .EQ. 0) CALL INTLOG(JP_FATAL,
     X            'IAOGDEF: Interpolation failing.',JPQUIET)
              ENDIF
              GO TO 900
          ENDIF
        ENDIF
C
      ELSE
C
C     Try to produce fields representable in GRIB for 0.5625 degree
C     strides
C
        IF (IEAST .LT. IWEST) THEN
          IF (IEAST .LE. 0) THEN
            IEAST = IEAST + JP360
          ELSE
            IWEST = IWEST - JP360
          ENDIF
        ENDIF
C
        GLOBE = IEAST - IWEST + IWEINC .EQ. JP360 .OR.
     X      IEAST - IWEST + IWEINC .EQ. 0
C
        IF (MOD (IWEINC, 10) .EQ. 5 .AND. .NOT. GLOBE) THEN
          IWETMP = IWEINC * 2
        ELSE
          IWETMP = IWEINC
        ENDIF
C
        IF (MOD (IEAST - IWEST, IWETMP) .NE. 0) THEN
C
          IF (MOD (IEAST, IWETMP) .NE. 0) THEN
C
            ITEMP = ABS (IEAST) / IWETMP
C
            IF (IEAST .GT. 0) THEN
              IEAST = (ITEMP + 1) * IWETMP
              IF (IEAST .GT. JP360) IEAST = IEAST - IWETMP
            ELSE
              IEAST = - ITEMP * IWETMP
            ENDIF
          ENDIF
C
          IF (MOD (IWEST, IWETMP) .NE. 0) THEN
C
            ITEMP = ABS (IWEST) / IWETMP
C
            IF (IWEST .LT. 0) THEN
              IWEST = - (ITEMP + 1) * IWETMP
              IF (IWEST .LT. - JP360) IWEST = IWEST + IWETMP
            ELSE
              IWEST = ITEMP * IWETMP
            ENDIF
          ENDIF
        ENDIF
      ENDIF
C
      IF (NOGAUSS .NE. KGAUSS) THEN
        NOGAUSS = KGAUSS
        OCHNG = .TRUE.
      ENDIF
C
      IF (KAREA (JPNORTH) .NE. INORTH) THEN
        KAREA (JPNORTH) = INORTH
        OCHNG = .TRUE.
      ENDIF
C
      IF (KAREA (JPSOUTH) .NE. ISOUTH) THEN
        KAREA (JPSOUTH) = ISOUTH
        OCHNG = .TRUE.
      ENDIF
C
      IF (IWEST .NE. KAREA (JPWEST) ) THEN
        KAREA (JPWEST) = IWEST
        OCHNG = .TRUE.
      ENDIF
C
      IF (IEAST .NE. KAREA (JPEAST) ) THEN
        KAREA (JPEAST) = IEAST
        OCHNG = .TRUE.
      ENDIF
C
      IF (KPR .GE. 1) THEN
        CALL INTLOG(JP_DEBUG,
     X    'IAOGDEF: Output field definition parameters.',JPQUIET)
        CALL INTLOG(JP_DEBUG,
     X    'IAOGDEF: Representation is ',NOREPR)
        CALL INTLOG(JP_DEBUG,
     X    'IAOGDEF: Gaussian truncation is ',NOGAUSS)
        CALL INTLOG(JP_DEBUG,
     X    'IAOGDEF: Area North is ',KAREA(1))
        CALL INTLOG(JP_DEBUG,
     X    'IAOGDEF: Area West  is ',KAREA(2))
        CALL INTLOG(JP_DEBUG,
     X    'IAOGDEF: Area South is ',KAREA(3))
        CALL INTLOG(JP_DEBUG,
     X    'IAOGDEF: Area East  is ',KAREA(4))
        IF( OCHNG ) THEN
          CALL INTLOG(JP_DEBUG,
     X      'IAOGDEF: Output field change is TRUE.',JPQUIET)
        ELSE
          CALL INTLOG(JP_DEBUG,
     X      'IAOGDEF: Output field change is TRUE.',JPQUIET)
        ENDIF
C
      ENDIF
C
C     _______________________________________________________
C
C*    Section 9. Return to calling routine. Format statements
C     _______________________________________________________
C
  900 CONTINUE
C
      IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IAOGDEF: Section 9.',JPQUIET)
C
      RETURN
      END