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