ungrib build
[WPS.git] / ungrib / src / ngl / w3 / getgbex.f
blob4698b0fa48e3487d0a99063093c5733eae4c9582
1 C-----------------------------------------------------------------------
2 SUBROUTINE GETGBEX(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,
3 & KF,K,KPDS,KGDS,KENS,KPROB,XPROB,KCLUST,KMEMBR,
4 & LB,F,IRET)
5 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
7 C SUBPROGRAM: GETGBEX FINDS AND UNPACKS A GRIB MESSAGE
8 C PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
10 C ABSTRACT: FIND AND UNPACK A GRIB MESSAGE.
11 C READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
12 C TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
13 C (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
14 C FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
15 C THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
16 C AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
17 C OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
18 C IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
19 C GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
20 C THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
21 C AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
22 C RETURN CODE WILL BE NONZERO.
24 C PROGRAM HISTORY LOG:
25 C 94-04-01 IREDELL
26 C 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
27 C AND ALLOWED FOR UNSPECIFIED INDEX FILE
28 C 97-02-11 Y.ZHU INCLUDED PROBABILITY AND CLUSTER ARGUMENTS
30 C USAGE: CALL GETGBEX(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,
31 C & KF,K,KPDS,KGDS,KENS,KPROB,XPROB,KCLUST,KMEMBR,
32 C & LB,F,IRET)
33 C INPUT ARGUMENTS:
34 C LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
35 C LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
36 C (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
37 C JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
38 C J INTEGER NUMBER OF MESSAGES TO SKIP
39 C (=0 TO SEARCH FROM BEGINNING)
40 C (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
41 C JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
42 C (=-1 FOR WILDCARD)
43 C (1) - ID OF CENTER
44 C (2) - GENERATING PROCESS ID NUMBER
45 C (3) - GRID DEFINITION
46 C (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
47 C (5) - INDICATOR OF PARAMETER
48 C (6) - TYPE OF LEVEL
49 C (7) - HEIGHT/PRESSURE , ETC OF LEVEL
50 C (8) - YEAR INCLUDING (CENTURY-1)
51 C (9) - MONTH OF YEAR
52 C (10) - DAY OF MONTH
53 C (11) - HOUR OF DAY
54 C (12) - MINUTE OF HOUR
55 C (13) - INDICATOR OF FORECAST TIME UNIT
56 C (14) - TIME RANGE 1
57 C (15) - TIME RANGE 2
58 C (16) - TIME RANGE FLAG
59 C (17) - NUMBER INCLUDED IN AVERAGE
60 C (18) - VERSION NR OF GRIB SPECIFICATION
61 C (19) - VERSION NR OF PARAMETER TABLE
62 C (20) - NR MISSING FROM AVERAGE/ACCUMULATION
63 C (21) - CENTURY OF REFERENCE TIME OF DATA
64 C (22) - UNITS DECIMAL SCALE FACTOR
65 C (23) - SUBCENTER NUMBER
66 C (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
67 C 128 IF FORECAST FIELD ERROR
68 C 64 IF BIAS CORRECTED FCST FIELD
69 C 32 IF SMOOTHED FIELD
70 C WARNING: CAN BE COMBINATION OF MORE THAN 1
71 C (25) - PDS BYTE 30, NOT USED
72 C JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
73 C (ONLY SEARCHED IF JPDS(3)=255)
74 C (=-1 FOR WILDCARD)
75 C (1) - DATA REPRESENTATION TYPE
76 C (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
77 C (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
78 C PARAMETERS
79 C OR
80 C OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
81 C IN EACH ROW
82 C OR
83 C 255 IF NEITHER ARE PRESENT
84 C (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
85 C (22) - NUMBER OF WORDS IN EACH ROW
86 C LATITUDE/LONGITUDE GRIDS
87 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
88 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
89 C (4) - LA(1) LATITUDE OF ORIGIN
90 C (5) - LO(1) LONGITUDE OF ORIGIN
91 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
92 C (7) - LA(2) LATITUDE OF EXTREME POINT
93 C (8) - LO(2) LONGITUDE OF EXTREME POINT
94 C (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
95 C (10) - DJ LATITUDINAL DIRECTION INCREMENT
96 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
97 C GAUSSIAN GRIDS
98 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
99 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
100 C (4) - LA(1) LATITUDE OF ORIGIN
101 C (5) - LO(1) LONGITUDE OF ORIGIN
102 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
103 C (7) - LA(2) LATITUDE OF EXTREME POINT
104 C (8) - LO(2) LONGITUDE OF EXTREME POINT
105 C (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
106 C (10) - N - NR OF CIRCLES POLE TO EQUATOR
107 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
108 C (12) - NV - NR OF VERT COORD PARAMETERS
109 C (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
110 C OR
111 C PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
112 C EACH ROW (IF NO VERT COORD PARAMETERS
113 C ARE PRESENT
114 C OR
115 C 255 IF NEITHER ARE PRESENT
116 C POLAR STEREOGRAPHIC GRIDS
117 C (2) - N(I) NR POINTS ALONG LAT CIRCLE
118 C (3) - N(J) NR POINTS ALONG LON CIRCLE
119 C (4) - LA(1) LATITUDE OF ORIGIN
120 C (5) - LO(1) LONGITUDE OF ORIGIN
121 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
122 C (7) - LOV GRID ORIENTATION
123 C (8) - DX - X DIRECTION INCREMENT
124 C (9) - DY - Y DIRECTION INCREMENT
125 C (10) - PROJECTION CENTER FLAG
126 C (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
127 C SPHERICAL HARMONIC COEFFICIENTS
128 C (2) - J PENTAGONAL RESOLUTION PARAMETER
129 C (3) - K " " "
130 C (4) - M " " "
131 C (5) - REPRESENTATION TYPE
132 C (6) - COEFFICIENT STORAGE MODE
133 C MERCATOR GRIDS
134 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
135 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
136 C (4) - LA(1) LATITUDE OF ORIGIN
137 C (5) - LO(1) LONGITUDE OF ORIGIN
138 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
139 C (7) - LA(2) LATITUDE OF LAST GRID POINT
140 C (8) - LO(2) LONGITUDE OF LAST GRID POINT
141 C (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
142 C (10) - RESERVED
143 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
144 C (12) - LONGITUDINAL DIR GRID LENGTH
145 C (13) - LATITUDINAL DIR GRID LENGTH
146 C LAMBERT CONFORMAL GRIDS
147 C (2) - NX NR POINTS ALONG X-AXIS
148 C (3) - NY NR POINTS ALONG Y-AXIS
149 C (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
150 C (5) - LO1 LON OF ORIGIN (LOWER LEFT)
151 C (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
152 C (7) - LOV - ORIENTATION OF GRID
153 C (8) - DX - X-DIR INCREMENT
154 C (9) - DY - Y-DIR INCREMENT
155 C (10) - PROJECTION CENTER FLAG
156 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
157 C (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
158 C (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
159 C JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
160 C (ONLY SEARCHED IF JPDS(23)=2)
161 C (=-1 FOR WILDCARD)
162 C (1) - APPLICATION IDENTIFIER
163 C (2) - ENSEMBLE TYPE
164 C (3) - ENSEMBLE IDENTIFIER
165 C (4) - PRODUCT IDENTIFIER
166 C (5) - SMOOTHING FLAG
167 C OUTPUT ARGUMENTS:
168 C KF INTEGER NUMBER OF DATA POINTS UNPACKED
169 C K INTEGER MESSAGE NUMBER UNPACKED
170 C (CAN BE SAME AS J IN CALLING PROGRAM
171 C IN ORDER TO FACILITATE MULTIPLE SEARCHES)
172 C KPDS INTEGER (200) UNPACKED PDS PARAMETERS
173 C KGDS INTEGER (200) UNPACKED GDS PARAMETERS
174 C KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
175 C KPROB INTEGER (2) PROBABILITY ENSEMBLE PARMS
176 C XPROB REAL (2) PROBABILITY ENSEMBLE PARMS
177 C KCLUST INTEGER (16) CLUSTER ENSEMBLE PARMS
178 C KMEMBR INTEGER (8) CLUSTER ENSEMBLE PARMS
179 C LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
180 C F REAL (KF) UNPACKED DATA
181 C IRET INTEGER RETURN CODE
182 C 0 ALL OK
183 C 96 ERROR READING INDEX FILE
184 C 97 ERROR READING GRIB FILE
185 C 98 NUMBER OF DATA POINTS GREATER THAN JF
186 C 99 REQUEST NOT FOUND
187 C OTHER W3FI63 GRIB UNPACKER RETURN CODE
189 C SUBPROGRAMS CALLED:
190 C GETGBEXM FIND AND UNPACK GRIB MESSAGE
192 C REMARKS: IN ORDER TO UNPACK GRIB FROM A MULTIPROCESSING ENVIRONMENT
193 C WHERE EACH PROCESSOR IS ATTEMPTING TO READ FROM ITS OWN PAIR OF
194 C LOGICAL UNITS, ONE MUST DIRECTLY CALL SUBPROGRAM GETGBEXM AS BELOW,
195 C ALLOCATING A PRIVATE COPY OF CBUF, NLEN AND NNUM TO EACH PROCESSOR.
196 C DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
198 C ATTRIBUTES:
199 C LANGUAGE: FORTRAN 77
200 C MACHINE: CRAY, WORKSTATIONS
202 C$$$
203 INTEGER JPDS(200),JGDS(200),JENS(200)
204 INTEGER KPDS(200),KGDS(200),KENS(200)
205 INTEGER KPROB(2),KCLUST(16),KMEMBR(80)
206 REAL XPROB(2)
207 LOGICAL*1 LB(JF)
208 REAL F(JF)
209 PARAMETER(MBUF=256*1024)
210 CHARACTER CBUF(MBUF)
211 SAVE CBUF,NLEN,NNUM,MNUM
212 DATA LUX/0/
213 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
214 C DETERMINE WHETHER INDEX BUFFER NEEDS TO BE INITIALIZED
215 IF(LUGI.GT.0.AND.(J.LT.0.OR.LUGI.NE.LUX)) THEN
216 LUX=LUGI
217 JJ=MIN(J,-1-J)
218 ELSEIF(LUGI.LE.0.AND.(J.LT.0.OR.LUGB.NE.LUX)) THEN
219 LUX=LUGB
220 JJ=MIN(J,-1-J)
221 ELSE
222 JJ=J
223 ENDIF
224 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
225 C FIND AND UNPACK GRIB MESSAGE
226 CALL GETGBEXM(LUGB,LUGI,JF,JJ,JPDS,JGDS,JENS,
227 & MBUF,CBUF,NLEN,NNUM,MNUM,
228 & KF,K,KPDS,KGDS,KENS,KPROB,XPROB,KCLUST,KMEMBR,
229 & LB,F,IRET)
230 IF(IRET.EQ.96) LUX=0
231 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
232 RETURN