1 C-----------------------------------------------------------------------
2 SUBROUTINE GETGBEM
(LUGB
,LUGI
,JF
,J
,JPDS
,JGDS
,JENS
,
3 & MBUF
,CBUF
,NLEN
,NNUM
,MNUM
,
4 & KF
,K
,KPDS
,KGDS
,KENS
,LB
,F
,IRET
)
5 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
7 C SUBPROGRAM: GETGBEM 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 FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
14 C THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
15 C AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
16 C OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
17 C IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
18 C GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
19 C THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
20 C AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
21 C RETURN CODE WILL BE NONZERO.
23 C PROGRAM HISTORY LOG:
25 C 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
26 C AND ALLOWED FOR UNSPECIFIED INDEX FILE
28 C USAGE: CALL GETGBEM(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,
29 C & MBUF,CBUF,NLEN,NNUM,MNUM,
30 C & KF,K,KPDS,KGDS,KENS,LB,F,IRET)
32 C LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
33 C LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
34 C (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
35 C JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
36 C J INTEGER NUMBER OF MESSAGES TO SKIP
37 C (=0 TO SEARCH FROM BEGINNING)
38 C (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
39 C JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
42 C (2) - GENERATING PROCESS ID NUMBER
43 C (3) - GRID DEFINITION
44 C (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
45 C (5) - INDICATOR OF PARAMETER
47 C (7) - HEIGHT/PRESSURE , ETC OF LEVEL
48 C (8) - YEAR INCLUDING (CENTURY-1)
52 C (12) - MINUTE OF HOUR
53 C (13) - INDICATOR OF FORECAST TIME UNIT
56 C (16) - TIME RANGE FLAG
57 C (17) - NUMBER INCLUDED IN AVERAGE
58 C (18) - VERSION NR OF GRIB SPECIFICATION
59 C (19) - VERSION NR OF PARAMETER TABLE
60 C (20) - NR MISSING FROM AVERAGE/ACCUMULATION
61 C (21) - CENTURY OF REFERENCE TIME OF DATA
62 C (22) - UNITS DECIMAL SCALE FACTOR
63 C (23) - SUBCENTER NUMBER
64 C (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
65 C 128 IF FORECAST FIELD ERROR
66 C 64 IF BIAS CORRECTED FCST FIELD
67 C 32 IF SMOOTHED FIELD
68 C WARNING: CAN BE COMBINATION OF MORE THAN 1
69 C (25) - PDS BYTE 30, NOT USED
70 C JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
71 C (ONLY SEARCHED IF JPDS(3)=255)
73 C (1) - DATA REPRESENTATION TYPE
74 C (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
75 C (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
78 C OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
81 C 255 IF NEITHER ARE PRESENT
82 C (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
83 C (22) - NUMBER OF WORDS IN EACH ROW
84 C LATITUDE/LONGITUDE GRIDS
85 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
86 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
87 C (4) - LA(1) LATITUDE OF ORIGIN
88 C (5) - LO(1) LONGITUDE OF ORIGIN
89 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
90 C (7) - LA(2) LATITUDE OF EXTREME POINT
91 C (8) - LO(2) LONGITUDE OF EXTREME POINT
92 C (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
93 C (10) - DJ LATITUDINAL DIRECTION INCREMENT
94 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
96 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
97 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
98 C (4) - LA(1) LATITUDE OF ORIGIN
99 C (5) - LO(1) LONGITUDE OF ORIGIN
100 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
101 C (7) - LA(2) LATITUDE OF EXTREME POINT
102 C (8) - LO(2) LONGITUDE OF EXTREME POINT
103 C (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
104 C (10) - N - NR OF CIRCLES POLE TO EQUATOR
105 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
106 C (12) - NV - NR OF VERT COORD PARAMETERS
107 C (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
109 C PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
110 C EACH ROW (IF NO VERT COORD PARAMETERS
113 C 255 IF NEITHER ARE PRESENT
114 C POLAR STEREOGRAPHIC GRIDS
115 C (2) - N(I) NR POINTS ALONG LAT CIRCLE
116 C (3) - N(J) NR POINTS ALONG LON CIRCLE
117 C (4) - LA(1) LATITUDE OF ORIGIN
118 C (5) - LO(1) LONGITUDE OF ORIGIN
119 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
120 C (7) - LOV GRID ORIENTATION
121 C (8) - DX - X DIRECTION INCREMENT
122 C (9) - DY - Y DIRECTION INCREMENT
123 C (10) - PROJECTION CENTER FLAG
124 C (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
125 C SPHERICAL HARMONIC COEFFICIENTS
126 C (2) - J PENTAGONAL RESOLUTION PARAMETER
129 C (5) - REPRESENTATION TYPE
130 C (6) - COEFFICIENT STORAGE MODE
132 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
133 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
134 C (4) - LA(1) LATITUDE OF ORIGIN
135 C (5) - LO(1) LONGITUDE OF ORIGIN
136 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
137 C (7) - LA(2) LATITUDE OF LAST GRID POINT
138 C (8) - LO(2) LONGITUDE OF LAST GRID POINT
139 C (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
141 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
142 C (12) - LONGITUDINAL DIR GRID LENGTH
143 C (13) - LATITUDINAL DIR GRID LENGTH
144 C LAMBERT CONFORMAL GRIDS
145 C (2) - NX NR POINTS ALONG X-AXIS
146 C (3) - NY NR POINTS ALONG Y-AXIS
147 C (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
148 C (5) - LO1 LON OF ORIGIN (LOWER LEFT)
149 C (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
150 C (7) - LOV - ORIENTATION OF GRID
151 C (8) - DX - X-DIR INCREMENT
152 C (9) - DY - Y-DIR INCREMENT
153 C (10) - PROJECTION CENTER FLAG
154 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
155 C (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
156 C (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
157 C JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
158 C (ONLY SEARCHED IF JPDS(23)=2)
160 C (1) - APPLICATION IDENTIFIER
161 C (2) - ENSEMBLE TYPE
162 C (3) - ENSEMBLE IDENTIFIER
163 C (4) - PRODUCT IDENTIFIER
164 C (5) - SMOOTHING FLAG
165 C MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
166 C CBUF CHARACTER*1 (MBUF) INDEX BUFFER
167 C (INITIALIZE BY SETTING J=-1)
168 C NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
169 C (INITIALIZE BY SETTING J=-1)
170 C NNUM INTEGER NUMBER OF INDEX RECORDS
171 C (INITIALIZE BY SETTING J=-1)
172 C MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
173 C (INITIALIZE BY SETTING J=-1)
175 C CBUF CHARACTER*1 (MBUF) INDEX BUFFER
176 C NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
177 C NNUM INTEGER NUMBER OF INDEX RECORDS
178 C MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
179 C KF INTEGER NUMBER OF DATA POINTS UNPACKED
180 C K INTEGER MESSAGE NUMBER UNPACKED
181 C (CAN BE SAME AS J IN CALLING PROGRAM
182 C IN ORDER TO FACILITATE MULTIPLE SEARCHES)
183 C KPDS INTEGER (200) UNPACKED PDS PARAMETERS
184 C KGDS INTEGER (200) UNPACKED GDS PARAMETERS
185 C KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
186 C LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
187 C F REAL (KF) UNPACKED DATA
188 C IRET INTEGER RETURN CODE
190 C 96 ERROR READING INDEX FILE
191 C 97 ERROR READING GRIB FILE
192 C 98 NUMBER OF DATA POINTS GREATER THAN JF
193 C 99 REQUEST NOT FOUND
194 C OTHER W3FI63 GRIB UNPACKER RETURN CODE
196 C SUBPROGRAMS CALLED:
197 C GETGI READ INDEX FILE
198 C GETGIR READ INDEX BUFFER FROM GRIB FILE
199 C GETGB1S SEARCH INDEX RECORDS
200 C GETGB1R READ AND UNPACK GRIB RECORD
201 C LENGDS RETURN THE LENGTH OF A GRID
203 C REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
204 C SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
205 C DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
208 C LANGUAGE: FORTRAN 77
209 C MACHINE: CRAY, WORKSTATIONS
212 INTEGER JPDS
(200),JGDS
(200),JENS
(200)
213 INTEGER KPDS
(200),KGDS
(200),KENS
(200)
217 PARAMETER(MSK1
=32000,MSK2
=4000)
218 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219 C SEARCH PREVIOUS INDEX BUFFER IF POSSIBLE
228 IF(JR
.GE
.0.AND
.(JR
.LT
.NNUM
.OR
.IRGI
.EQ
.0)) THEN
229 CALL GETGB1S
(CBUF
,NLEN
,NNUM
,JR
,JPDS
,JGDS
,JENS
,
230 & KR
,KPDS
,KGDS
,KENS
,LSKIP
,LGRIB
,IRGS
)
231 IF(IRGS
.EQ
.0) K
=KR
+MNUM
232 IF(IRGI
.EQ
.1.AND
.IRGS
.EQ
.0) MNUM
=-1-MNUM
233 IF(IRGI
.EQ
.1.AND
.IRGS
.GT
.0) MNUM
=MNUM
+NNUM
244 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
245 C READ AND SEARCH NEXT INDEX BUFFER
247 DOWHILE
(IRGI
.EQ
.1.AND
.IRGS
.EQ
.1)
249 CALL GETGI
(LUGI
,MNUM
,MBUF
,CBUF
,NLEN
,NNUM
,IRGI
)
251 CALL GETGIR
(LUGB
,MSK1
,MSK2
,MNUM
,MBUF
,CBUF
,NLEN
,NNUM
,IRGI
)
254 CALL GETGB1S
(CBUF
,NLEN
,NNUM
,JR
,JPDS
,JGDS
,JENS
,
255 & KR
,KPDS
,KGDS
,KENS
,LSKIP
,LGRIB
,IRGS
)
256 IF(IRGS
.EQ
.0) K
=KR
+MNUM
257 IF(IRGI
.EQ
.1.AND
.IRGS
.EQ
.0) MNUM
=-1-MNUM
258 IF(IRGI
.EQ
.1.AND
.IRGS
.GT
.0) MNUM
=MNUM
+NNUM
261 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
262 C READ AND UNPACK GRIB RECORD
265 ELSEIF
(IRGS
.NE
.0) THEN
267 ELSEIF
(LENGDS
(KGDS
).GT
.JF
) THEN
270 CALL GETGB1R
(LUGB
,LSKIP
,LGRIB
,KF
,KPDS
,KGDS
,KENS
,LB
,F
,NBITSS
273 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -