File: igsetup.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 (628 lines) | stat: -rwxr-xr-x 16,625 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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
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 IGSETUP( KSEC1, KSEC2, KSEC4)
C
C---->
C**** IGSETUP
C
C     Purpose
C     -------
C
C     Setup GRIB sections 1, 2 and 4 for the new interpolation product.
C
C
C     Interface
C     ---------
C
C     IRET IGSETUP( KSEC1, KSEC2, KSEC4)
C
C     Input
C     -----
C
C     KSEC1   - Section 1 values (for GRIBEX)
C     KSEC2   - Section 2 values (for GRIBEX)
C     KSEC3   - Section 4 values (for GRIBEX)
C
C     Output
C     ------
C
C     KSEC1   - Modified section 1 values (for GRIBEX)
C     KSEC2   - Modified section 2 values (for GRIBEX)
C     KSEC3   - Modified section 4 values (for GRIBEX)
C
C     Method
C     ------
C
C     Use common block values and existing values from the original GRIB
C     product used for interpolation.
C
C
C     Externals
C     ---------
C
C     INTLOG   - Logs messages.
C
C
C     Author
C     ------
C
C     J.D.Chambers     ECMWF     Aug 1994
C
C----<
C
      IMPLICIT NONE
C
#include "parim.h"
#include "nifld.common"
#include "nofld.common"
C
C     Parameter(s)
C
      INTEGER JPROUTINE
      PARAMETER ( JPROUTINE = 19100 )
C
C     Function arguments
C
      INTEGER KSEC1, KSEC2, KSEC4
      DIMENSION KSEC1(*), KSEC2(*), KSEC4(*)
C
C     Local variables
C
      LOGICAL LIROTAT, LOROTAT
      INTEGER ILOOP, ITEMP
C
C***********************************************************************
C     Section 1.   Startup.
C***********************************************************************
C
 100  CONTINUE
C
      IGSETUP = 0
C
C     Check a recognized data representation type is being processed
C
      IF ( (NOREPR .NE.JPREGULAR  ) .AND.
     X     (NOREPR .NE.JPREGROT   ) .AND.
     X     (NOREPR .NE.JPGAUSSIAN ) .AND.
     X     (NOREPR .NE.JPFGGROT   ) .AND.
     X     (NOREPR .NE.JPQUASI    ) .AND.
     X     (NOREPR .NE.JPQGGROT   ) .AND.
     X     (NOREPR .NE.JPSPHROT   ) .AND.
     X     (NOREPR .NE.JPSPHERE   ) ) GOTO 910
C
C     Set flags if input is rotated or if a rotation angle has been given
C
      LIROTAT = (NIREPR.EQ.JPSPHROT).OR.
     X          (NIREPR.EQ.JPREGROT).OR.
     X          (NIREPR.EQ.JPFGGROT).OR.
     X          (NIREPR.EQ.JPQGGROT)
C
      LOROTAT = ((NOROTA(1).NE.-9000000).AND.(NOROTA(1).NE.0)).OR.
     X          (NOROTA(2).NE.0)
C
C***********************************************************************
C     Section 2.   Setup output product section 1.
C***********************************************************************
C
 200  CONTINUE
C
C     Setup output if not given by input GRIB message
C     (ie input is 'unpacked').
C
      IF ( NIFORM .NE. 1 ) THEN
C
C       Code table ( same as input )
C
        KSEC1(1) = NOTABLE
C
C       Originating centre = ECMWF
C
        KSEC1(2) = 98
C
C       Generating process ID = 255
C       Grid definition       = 255
C
        KSEC1(3) = 255
        KSEC1(4) = 255
C
C       Parameter
C
        KSEC1(6) = NOPARAM
C
C       Level
C
        KSEC1(7) = NOLEVT
        KSEC1(8) = NOLEVEL
        KSEC1(9) = 0
C
C       Dummy date and time ( 1 Jan 1990, 1200 )
C
        KSEC1(10) = 90
        KSEC1(11) = 1
        KSEC1(12) = 1
        KSEC1(13) = 12
        KSEC1(14) = 0
C
C       Dummy verifying time (initialised analysis)
C
        KSEC1(15) = 1
        KSEC1(16) = 0
        KSEC1(17) = 0
        KSEC1(18) = 1
        KSEC1(19) = 0
        KSEC1(20) = 0
C
C       Century ( = 20 )
C
        KSEC1(21) = 20
C
C       Lots of zeroes
C
        DO 210 ILOOP = 22, 36
          KSEC1(ILOOP) = 0
  210   CONTINUE
C
C     Allow for user specified output field values when input is packed
C
      ELSE
C
C       Code table
C
        KSEC1(1) = NOTABLE
C
C       Parameter
C
        IF( LNOPARA ) KSEC1(6) = NOPARAM
C
C       Level
C
        IF( LNOLEVT ) KSEC1(7) = NOLEVT
        IF( LNOLEVL ) THEN
          KSEC1(8) = NOLEVEL
          KSEC1(9) = 0
        ENDIF
      ENDIF
C
C     Section 2 included, section 3 omitted
C
      KSEC1(5) = 128
C
C     Rest of section 1 kept unchanged from input product
C
C***********************************************************************
C     Section 3.   Setup output product section 2.
C***********************************************************************
C
 300  CONTINUE
C
C     Data representation type
C
C     Adjust output representation type if field is rotated
C
      IF( LIROTAT.OR.LOROTAT ) THEN
        KSEC2(1) = NOREPR
        IF(NOREPR.EQ.JPREGULAR )  KSEC2(1) = JPREGROT
        IF(NOREPR.EQ.JPSPHERE )   KSEC2(1) = JPSPHROT
        IF(NOREPR.EQ.JPQUASI )    KSEC2(1) = JPFGGROT
        IF(NOREPR.EQ.JPQGGROT )   KSEC2(1) = JPFGGROT
        IF(NOREPR.EQ.JPGAUSSIAN ) KSEC2(1) = JPFGGROT
C
      ELSE
C
        IF( (NOREPR.EQ.JPQUASI).OR.(NOREPR.EQ.JPQGGROT) ) THEN
          KSEC2(1) = JPGAUSSIAN
        ELSE
          KSEC2(1) = NOREPR
        ENDIF
      ENDIF
C
C***********************************************************************
C     Section 3.1. Setup section 2 for lat/long, equidistant
C                  cylindrical or plate carre grids.
C***********************************************************************
C
 310  CONTINUE
C
      IF ( (NOREPR.EQ.JPREGULAR).OR.(NOREPR.EQ.JPREGROT) ) THEN
C
C       For south to north grids, only global area allowed (eg KWBC SST)
C
cs        IF( KSEC2(4).LT.KSEC2(7) ) THEN
cs          IF((NOAREA(1).NE.(-NOAREA(3))).AND.(NOAREA(3).NE.JP90)) THEN
cs            CALL INTLOG(JP_ERROR,
cs     X        'IGSETUP: Subareas not allowed interpolating',JPQUIET)
cs            CALL INTLOG(JP_ERROR,
cs     X        'IGSETUP: grids running from south to north',JPQUIET)
cs            IGSETUP = JPROUTINE + 2
cs            GOTO 900
cs          ENDIF
cs        ENDIF

C
C       Number of points along a parallel
C
        KSEC2(2) = NOWE
C
C       Number of points along a meridian
C
        KSEC2(3) = NONS
C
C       Latitude and longitude of first grid point
C
        IF( NOAREA(1).GE.0 ) THEN
          KSEC2(4) = (NOAREA(1)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(4) = (NOAREA(1)-(JPMICRO/2)) / JPMICRO
        ENDIF
        IF( NOAREA(2).GE.0 ) THEN
          KSEC2(5) = (NOAREA(2)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(5) = (NOAREA(2)-(JPMICRO/2)) / JPMICRO
        ENDIF
C
C       Resolution flag, increments are given
C
        KSEC2(6) = 128
C
C       Latitude and longitude of last grid point
C
        IF( NOAREA(3).GE.0 ) THEN
          KSEC2(7) = (NOAREA(3)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(7) = (NOAREA(3)-(JPMICRO/2)) / JPMICRO
        ENDIF
        IF( NOAREA(4).GE.0 ) THEN
          KSEC2(8) = (NOAREA(4)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(8) = (NOAREA(4)-(JPMICRO/2)) / JPMICRO
        ENDIF
C
C       Flip latitudes if they run from south to north
C       Set scanning mode flags
C
        IF( KSEC2(4).LT.KSEC2(7) ) THEN
          IF( LNOGRID ) THEN
            ITEMP = KSEC2(7)
            KSEC2(7) = KSEC2(4)
            KSEC2(4) = ITEMP
            KSEC2(11) = 0
          ELSE
            KSEC2(11) = 64
          ENDIF
        ELSE
          KSEC2(11) = NOSCNM
        ENDIF
C
C       i and j  direction increments
C
        KSEC2(9)  = (NOGRID(1) + (JPMICRO/2)) / JPMICRO
        KSEC2(10) = (NOGRID(2) + (JPMICRO/2)) / JPMICRO
C
C       Following left same as for input product
C       - no.of vertical coordinate parameters,
C       - lat/long of southern pole of rotation
C       - lat/long of pole of stretching
C
C       If rotated, put in new lat/long of southern pole of rotation
C
        IF( LIROTAT.OR.LOROTAT ) THEN
          IF( NOROTA(1).GE.0 ) THEN
            KSEC2(13) = (NOROTA(1) + (JPMICRO/2)) / JPMICRO
          ELSE
            KSEC2(13) = (NOROTA(1) - (JPMICRO/2)) / JPMICRO
          ENDIF
          IF( NOROTA(2).GE.0 ) THEN
            KSEC2(14) = (NOROTA(2) + (JPMICRO/2)) / JPMICRO
          ELSE
            KSEC2(14) = (NOROTA(2) - (JPMICRO/2)) / JPMICRO
          ENDIF
        ENDIF
C
C       Regular grid flag
C
        KSEC2(17) = 0
C
C       Following left same as for input product
C       - earth flag
C       - components flag
C       - reserved fields
C
      ENDIF
C
C***********************************************************************
C     Section 3.2. Setup section 2 for gaussian grids.
C***********************************************************************
C
 320  CONTINUE
C
      IF ( (NOREPR.EQ.JPGAUSSIAN).OR.
     X     (NOREPR.EQ.JPFGGROT).OR.
     X     (NOREPR.EQ.JPQUASI).OR.
     X     (NOREPR.EQ.JPQGGROT) ) THEN
C
C       Number of points along a parallel
C
C       For a regular gaussian grid only
        IF( (NOREPR.EQ.JPGAUSSIAN).OR.(NOREPR.EQ.JPFGGROT) ) THEN
          KSEC2(2) = NOWE
        ELSE
          KSEC2(2) = 0
        ENDIF
C
C       Number of points along a meridian
C
        KSEC2(3) = NONS
C
C       Latitude and longitude of first grid point
C
        IF( NOAREA(1).GE.0 ) THEN
          KSEC2(4) = (NOAREA(1)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(4) = (NOAREA(1)-(JPMICRO/2)) / JPMICRO
        ENDIF
        IF( NOAREA(2).GE.0 ) THEN
          KSEC2(5) = (NOAREA(2)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(5) = (NOAREA(2)-(JPMICRO/2)) / JPMICRO
        ENDIF
C
C       Resolution flag
C
C       For a regular gaussian grid only, increments are given
C
        IF( (NOREPR.EQ.JPGAUSSIAN).OR.(NOREPR.EQ.JPFGGROT) ) THEN
          KSEC2(6) = 128
        ELSE
          KSEC2(6) = 0
        ENDIF
C
C       Latitude and longitude of last grid point
C
        IF( NOAREA(3).GE.0 ) THEN
          KSEC2(7) = (NOAREA(3)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(7) = (NOAREA(3)-(JPMICRO/2)) / JPMICRO
        ENDIF
        IF( NOAREA(4).GE.0 ) THEN
          KSEC2(8) = (NOAREA(4)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(8) = (NOAREA(4)-(JPMICRO/2)) / JPMICRO
        ENDIF
C
C       i direction increment
C
C       For a regular gaussian grid, only 
C
        IF( (NOREPR.EQ.JPGAUSSIAN).OR.(NOREPR.EQ.JPFGGROT) ) THEN
          KSEC2(9) = (((JP90)/NOGAUSS)+(JPMICRO/2)) / JPMICRO
        ELSE
          KSEC2(9) = 0
        ENDIF
C
C       Number of parallels between a pole and the Equator
C
        KSEC2(10) = NOGAUSS
C
C       Scanning mode flags
C
        KSEC2(11) = NOSCNM
C
C       Following left same as for input product
C       - no.of vertical coordinate parameters,
C       - lat/long of southern pole of rotation
C       - lat/long of pole of stretching
C
C       If rotated, put in new lat/long of southern pole of rotation
C
        IF( LIROTAT.OR.LOROTAT ) THEN
          IF( NOROTA(1).GE.0 ) THEN
            KSEC2(13) = (NOROTA(1) + (JPMICRO/2)) / JPMICRO
          ELSE
            KSEC2(13) = (NOROTA(1) - (JPMICRO/2)) / JPMICRO
          ENDIF
          IF( NOROTA(2).GE.0 ) THEN
            KSEC2(14) = (NOROTA(2) + (JPMICRO/2)) / JPMICRO
          ELSE
            KSEC2(14) = (NOROTA(2) - (JPMICRO/2)) / JPMICRO
          ENDIF
        ENDIF
C
C       Regular grid flag
C
        IF( (NOREPR.EQ.JPGAUSSIAN).OR.(NOREPR.EQ.JPFGGROT) ) THEN
          KSEC2(17) = 0
        ELSE
          KSEC2(17) = 1
        ENDIF
C
C       Following left same as for input product
C       - earth flag
C       - components flag
C       - reserved fields
C
C       For reduced grid, move in number of points along each parallel
C
          IF( (NOREPR.EQ.JPQUASI) .OR.
     X        (NOREPR.EQ.JPQGGROT) ) THEN
          DO 325 ILOOP = 1, KSEC2(3)
            KSEC2(22+ILOOP) = NOLPTS(ILOOP+NO1NS-1)
 325      CONTINUE
        ENDIF
C
      ENDIF
C
C***********************************************************************
C     Section 3.3. Setup section 2 for spherical harmonic coefficients.
C***********************************************************************
C
 330  CONTINUE
C
      IF ( (NOREPR.EQ.JPSPHERE).OR.(NOREPR.EQ.JPSPHROT) ) THEN
C
C       I, K, M pentagonal resolution parameters
C
        KSEC2(2) = NORESO
        KSEC2(3) = NORESO
        KSEC2(4) = NORESO
C
C       Representation type, associated legendre functions of the
C                            first kind
        KSEC2(5) = 1
C
C       Representation mode, complex packing
C
        KSEC2(6) = 2
C
C       Following left same as for input product
C       - reserved words 7-11
C       - no.of vertical coordinate parameters,
C       - lat/long of southern pole of rotation
C       - lat/long of pole of stretching
C       - reserved words 17-22
C
C       If rotated, put in new lat/long of southern pole of rotation
C
        IF( LIROTAT.OR.LOROTAT ) THEN
          IF( NOROTA(1).GE.0 ) THEN
            KSEC2(13) = (NOROTA(1) + (JPMICRO/2)) / JPMICRO
          ELSE
            KSEC2(13) = (NOROTA(1) - (JPMICRO/2)) / JPMICRO
          ENDIF
          IF( NOROTA(2).GE.0 ) THEN
            KSEC2(14) = (NOROTA(2) + (JPMICRO/2)) / JPMICRO
          ELSE
            KSEC2(14) = (NOROTA(2) - (JPMICRO/2)) / JPMICRO
          ENDIF
        ENDIF
      ENDIF
C
C***********************************************************************
C     Section 4.   Setup output product section 4.
C***********************************************************************
C
 400  CONTINUE
C
C     Number of values to be packed
C
      IF ( (NOREPR.EQ.JPSPHERE).OR.(NOREPR.EQ.JPSPHROT) ) THEN
        KSEC4(1) = (NORESO + 1) * (NORESO + 2)
      ELSE IF( (NOREPR.EQ.JPQUASI).OR.(NOREPR.EQ.JPQGGROT) ) THEN
        KSEC4(1) = NOPCNT
      ELSE
        KSEC4(1) = NOWE * NONS
      ENDIF
C
C     If all the values are missing, set the count of values negative
C
      IF(NOMISS.NE.0) THEN
        KSEC4(1) = -KSEC4(1)
      ENDIF
C
C     Number of bits used for each packed value
C
      KSEC4(2) = NOACC
C
C     Type of data, spherical harmonic = 128, grid point = 0
C
      IF ( (NOREPR.EQ.JPSPHERE).OR.(NOREPR.EQ.JPSPHROT) ) THEN
        KSEC4(3) = 128
      ELSE
        KSEC4(3) = 0
      ENDIF
C
C     Type of packing, spherical harmonic = complex
C
      IF ( (NOREPR.EQ.JPSPHERE).OR.(NOREPR.EQ.JPSPHROT) ) THEN
        KSEC4(4) = 64
      ELSE
        KSEC4(4) = 0
      ENDIF
C
C     Type of data = floating point
C
      KSEC4(5) = 0
C
C     Additional flags indicator = none
C
      KSEC4(6) = 0
C
C     Reserved word, set to 0
C
      KSEC4(7) = 0
C
C     Following set to simplest case
C     - no.of values indicator
C     - secondary bitmaps indicator
C     - values width indicator
C     - no.of bits for 2nd order values
C
      KSEC4(8)  = 0
      KSEC4(9)  = 0
      KSEC4(10) = 0
      KSEC4(11) = 0
C     
C     Reserved words, set to 0
C
      KSEC4(12) = 0
      KSEC4(13) = 0
      KSEC4(14) = 0
      KSEC4(15) = 0
C
C     If spherical harmonics, set following for complex packing
C
      IF ( (NOREPR.EQ.JPSPHERE).OR.(NOREPR.EQ.JPSPHROT) ) THEN
C
C       KSEC4(16), pointer to start of packed data, setup by packing
C       KSEC4(17), scaling factor P, unchanged from input
C       KSEC4(18), pentagonal resolution parameter J for packing of subset,
C                  unchanged from input
C       KSEC4(19), pentagonal resolution parameter K for packing of subset,
C                  unchanged from input
C       KSEC4(20), pentagonal resolution parameter M for packing of subset,
C                  unchanged from input
C
      ELSE
        DO 410 ILOOP = 16, 20
          KSEC4(ILOOP) = 0
 410    CONTINUE
      ENDIF
C
C     Words 21-33 reserved, set to zero.
C
      DO 420 ILOOP = 21, 33
        KSEC4(ILOOP) = 0
 420  CONTINUE
C
C***********************************************************************
C     Section 9.   Closedown
C***********************************************************************
C
 900  CONTINUE
C
      RETURN
C
C     Invalid data represntation type
C
 910  CONTINUE
      CALL INTLOG(JP_ERROR,
     X  'IGSETUP: Data representation type not recognized: ',NOREPR)
      CALL INTLOG(JP_ERROR,
     X  'IGSETUP: Only the following types are recognized:',JPQUIET)
      CALL INTLOG(JP_ERROR,'IGSETUP: Lat/long grid = ', JPREGULAR)
      CALL INTLOG(JP_ERROR,'IGSETUP: Lat/long (rotated) = ', JPREGROT)
      CALL INTLOG(JP_ERROR,'IGSETUP: regular gaussian = ', JPGAUSSIAN)
      CALL INTLOG(JP_ERROR,'IGSETUP: reg gauss rotated = ', JPFGGROT)
      CALL INTLOG(JP_ERROR,'IGSETUP: reduced gaussian = ', JPQUASI)
      CALL INTLOG(JP_ERROR,'IGSETUP: red gauss rotated = ', JPQUASI)
      CALL INTLOG(JP_ERROR,'IGSETUP: spherical harmonic = ', JPSPHERE)
      CALL INTLOG(JP_ERROR,'IGSETUP: spectral (rotated) = ', JPSPHROT)
C
      IGSETUP = JPROUTINE + 1
      RETURN
      END