Created a tag for the 2012 HWRF baseline tests.
[WPS-merge.git] / hwrf-baseline-20120103-1354 / ungrib / src / ngl / w3 / getgbmh.f
blob6d7f78e865d58176170cac506a4c1ddbc8f86cd7
1 C-----------------------------------------------------------------------
2 SUBROUTINE GETGBMH(LUGB,LUGI,J,JPDS,JGDS,
3 & MBUF,CBUF,NLEN,NNUM,MNUM,
4 & KG,KF,K,KPDS,KGDS,IRET)
5 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
7 C SUBPROGRAM: GETGBMH 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 ITS MESSAGE NUMBER IS
18 C RETURNED ALONG WITH THE UNPACKED PDS AND GDS PARAMETERS. IF THE
19 C GRIB MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
21 C PROGRAM HISTORY LOG:
22 C 94-04-01 IREDELL
23 C 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
24 C AND ALLOWED FOR UNSPECIFIED INDEX FILE
26 C USAGE: CALL GETGBMH(LUGB,LUGI,J,JPDS,JGDS,
27 C & MBUF,CBUF,NLEN,NNUM,MNUM,
28 C & KG,KF,K,KPDS,KGDS,IRET)
29 C INPUT ARGUMENTS:
30 C LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
31 C (ONLY USED IF LUGI=0)
32 C LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
33 C (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
34 C J INTEGER NUMBER OF MESSAGES TO SKIP
35 C (=0 TO SEARCH FROM BEGINNING)
36 C (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
37 C JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
38 C (=-1 FOR WILDCARD)
39 C (1) - ID OF CENTER
40 C (2) - GENERATING PROCESS ID NUMBER
41 C (3) - GRID DEFINITION
42 C (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
43 C (5) - INDICATOR OF PARAMETER
44 C (6) - TYPE OF LEVEL
45 C (7) - HEIGHT/PRESSURE , ETC OF LEVEL
46 C (8) - YEAR INCLUDING (CENTURY-1)
47 C (9) - MONTH OF YEAR
48 C (10) - DAY OF MONTH
49 C (11) - HOUR OF DAY
50 C (12) - MINUTE OF HOUR
51 C (13) - INDICATOR OF FORECAST TIME UNIT
52 C (14) - TIME RANGE 1
53 C (15) - TIME RANGE 2
54 C (16) - TIME RANGE FLAG
55 C (17) - NUMBER INCLUDED IN AVERAGE
56 C (18) - VERSION NR OF GRIB SPECIFICATION
57 C (19) - VERSION NR OF PARAMETER TABLE
58 C (20) - NR MISSING FROM AVERAGE/ACCUMULATION
59 C (21) - CENTURY OF REFERENCE TIME OF DATA
60 C (22) - UNITS DECIMAL SCALE FACTOR
61 C (23) - SUBCENTER NUMBER
62 C (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
63 C 128 IF FORECAST FIELD ERROR
64 C 64 IF BIAS CORRECTED FCST FIELD
65 C 32 IF SMOOTHED FIELD
66 C WARNING: CAN BE COMBINATION OF MORE THAN 1
67 C (25) - PDS BYTE 30, NOT USED
68 C JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
69 C (ONLY SEARCHED IF JPDS(3)=255)
70 C (=-1 FOR WILDCARD)
71 C (1) - DATA REPRESENTATION TYPE
72 C (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
73 C (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
74 C PARAMETERS
75 C OR
76 C OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
77 C IN EACH ROW
78 C OR
79 C 255 IF NEITHER ARE PRESENT
80 C (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
81 C (22) - NUMBER OF WORDS IN EACH ROW
82 C LATITUDE/LONGITUDE GRIDS
83 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
84 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
85 C (4) - LA(1) LATITUDE OF ORIGIN
86 C (5) - LO(1) LONGITUDE OF ORIGIN
87 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
88 C (7) - LA(2) LATITUDE OF EXTREME POINT
89 C (8) - LO(2) LONGITUDE OF EXTREME POINT
90 C (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
91 C (10) - DJ LATITUDINAL DIRECTION INCREMENT
92 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
93 C GAUSSIAN GRIDS
94 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
95 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
96 C (4) - LA(1) LATITUDE OF ORIGIN
97 C (5) - LO(1) LONGITUDE OF ORIGIN
98 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
99 C (7) - LA(2) LATITUDE OF EXTREME POINT
100 C (8) - LO(2) LONGITUDE OF EXTREME POINT
101 C (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
102 C (10) - N - NR OF CIRCLES POLE TO EQUATOR
103 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
104 C (12) - NV - NR OF VERT COORD PARAMETERS
105 C (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
106 C OR
107 C PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
108 C EACH ROW (IF NO VERT COORD PARAMETERS
109 C ARE PRESENT
110 C OR
111 C 255 IF NEITHER ARE PRESENT
112 C POLAR STEREOGRAPHIC GRIDS
113 C (2) - N(I) NR POINTS ALONG LAT CIRCLE
114 C (3) - N(J) NR POINTS ALONG LON CIRCLE
115 C (4) - LA(1) LATITUDE OF ORIGIN
116 C (5) - LO(1) LONGITUDE OF ORIGIN
117 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
118 C (7) - LOV GRID ORIENTATION
119 C (8) - DX - X DIRECTION INCREMENT
120 C (9) - DY - Y DIRECTION INCREMENT
121 C (10) - PROJECTION CENTER FLAG
122 C (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
123 C SPHERICAL HARMONIC COEFFICIENTS
124 C (2) - J PENTAGONAL RESOLUTION PARAMETER
125 C (3) - K " " "
126 C (4) - M " " "
127 C (5) - REPRESENTATION TYPE
128 C (6) - COEFFICIENT STORAGE MODE
129 C MERCATOR GRIDS
130 C (2) - N(I) NR POINTS ON LATITUDE CIRCLE
131 C (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
132 C (4) - LA(1) LATITUDE OF ORIGIN
133 C (5) - LO(1) LONGITUDE OF ORIGIN
134 C (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
135 C (7) - LA(2) LATITUDE OF LAST GRID POINT
136 C (8) - LO(2) LONGITUDE OF LAST GRID POINT
137 C (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
138 C (10) - RESERVED
139 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
140 C (12) - LONGITUDINAL DIR GRID LENGTH
141 C (13) - LATITUDINAL DIR GRID LENGTH
142 C LAMBERT CONFORMAL GRIDS
143 C (2) - NX NR POINTS ALONG X-AXIS
144 C (3) - NY NR POINTS ALONG Y-AXIS
145 C (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
146 C (5) - LO1 LON OF ORIGIN (LOWER LEFT)
147 C (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
148 C (7) - LOV - ORIENTATION OF GRID
149 C (8) - DX - X-DIR INCREMENT
150 C (9) - DY - Y-DIR INCREMENT
151 C (10) - PROJECTION CENTER FLAG
152 C (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
153 C (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
154 C (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
155 C MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
156 C CBUF CHARACTER*1 (MBUF) INDEX BUFFER
157 C (INITIALIZE BY SETTING J=-1)
158 C NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
159 C (INITIALIZE BY SETTING J=-1)
160 C NNUM INTEGER NUMBER OF INDEX RECORDS
161 C (INITIALIZE BY SETTING J=-1)
162 C MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
163 C (INITIALIZE BY SETTING J=-1)
164 C OUTPUT ARGUMENTS:
165 C CBUF CHARACTER*1 (MBUF) INDEX BUFFER
166 C NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
167 C NNUM INTEGER NUMBER OF INDEX RECORDS
168 C MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
169 C KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
170 C KF INTEGER NUMBER OF DATA POINTS IN THE 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 IRET INTEGER RETURN CODE
177 C 0 ALL OK
178 C 96 ERROR READING INDEX FILE
179 C 99 REQUEST NOT FOUND
181 C SUBPROGRAMS CALLED:
182 C GETGI READ INDEX FILE
183 C GETGIR READ INDEX BUFFER FROM GRIB FILE
184 C GETGB1S SEARCH INDEX RECORDS
185 C LENGDS RETURN THE LENGTH OF A GRID
187 C REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
188 C SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
189 C DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
191 C ATTRIBUTES:
192 C LANGUAGE: FORTRAN 77
193 C MACHINE: CRAY, WORKSTATIONS
195 C$$$
196 INTEGER JPDS(200),JGDS(200)
197 INTEGER KPDS(200),KGDS(200)
198 CHARACTER CBUF(MBUF)
199 PARAMETER(MSK1=32000,MSK2=4000)
200 INTEGER JENS(200),KENS(200)
201 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
202 C SEARCH PREVIOUS INDEX BUFFER IF POSSIBLE
203 JENS=-1
204 IF(J.GE.0) THEN
205 IF(MNUM.GE.0) THEN
206 IRGI=0
207 ELSE
208 MNUM=-1-MNUM
209 IRGI=1
210 ENDIF
211 JR=J-MNUM
212 IF(JR.GE.0.AND.(JR.LT.NNUM.OR.IRGI.EQ.0)) THEN
213 CALL GETGB1S(CBUF,NLEN,NNUM,JR,JPDS,JGDS,JENS,
214 & KR,KPDS,KGDS,KENS,LSKIP,LGRIB,IRGS)
215 IF(IRGS.EQ.0) K=KR+MNUM
216 IF(IRGI.EQ.1.AND.IRGS.EQ.0) MNUM=-1-MNUM
217 IF(IRGI.EQ.1.AND.IRGS.GT.0) MNUM=MNUM+NNUM
218 ELSE
219 MNUM=J
220 IRGI=1
221 IRGS=1
222 ENDIF
223 ELSE
224 MNUM=-1-J
225 IRGI=1
226 IRGS=1
227 ENDIF
228 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 C READ AND SEARCH NEXT INDEX BUFFER
230 JR=0
231 DOWHILE(IRGI.EQ.1.AND.IRGS.EQ.1)
232 IF(LUGI.GT.0) THEN
233 CALL GETGI(LUGI,MNUM,MBUF,CBUF,NLEN,NNUM,IRGI)
234 ELSE
235 CALL GETGIR(LUGB,MSK1,MSK2,MNUM,MBUF,CBUF,NLEN,NNUM,IRGI)
236 ENDIF
237 IF(IRGI.LE.1) THEN
238 CALL GETGB1S(CBUF,NLEN,NNUM,JR,JPDS,JGDS,JENS,
239 & KR,KPDS,KGDS,KENS,LSKIP,LGRIB,IRGS)
240 IF(IRGS.EQ.0) K=KR+MNUM
241 IF(IRGI.EQ.1.AND.IRGS.EQ.0) MNUM=-1-MNUM
242 IF(IRGI.EQ.1.AND.IRGS.GT.0) MNUM=MNUM+NNUM
243 ENDIF
244 ENDDO
245 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
246 C READ GRIB RECORD
247 IF(IRGI.GT.1) THEN
248 IRET=96
249 ELSEIF(IRGS.NE.0) THEN
250 IRET=99
251 ELSE
252 KG=LGRIB
253 KF=LENGDS(KGDS)
254 IRET=0
255 ENDIF
256 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
257 RETURN