NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
getgbmh.f
Go to the documentation of this file.
1C> @file
2C> @brief Finds a grib message.
3C> @author Mark Iredell @date 1994-04-01
4
5C> Read a grib index file (or optionally the grib file itself)
6C> to get the index buffer (i.e. table of contents) for the grib file.
7C> Find in the index buffer a reference to the grib message requested.
8C> The grib message request specifies the number of messages to skip
9C> and the unpacked pds and gds parameters. (A requested parameter
10C> of -1 means to allow any value of this parameter to be found.)
11C> If the requested grib message is found, then its message number is
12C> returned along with the unpacked pds and gds parameters. If the
13C> grib message is not found, then the return code will be nonzero.
14C>
15C> Program history log:
16C> - Mark Iredell 1994-04-01
17C> - Mark Iredell 1995-10-31 Modularized portions of code into subprograms
18C> and allowed for unspecified index file.
19C>
20C> @param[in] lugb integer unit of the unblocked grib data file
21C> (only used if lugi=0).
22C> @param[in] lugi integer unit of the unblocked grib index file
23C> (=0 to get index buffer from the grib file).
24C> @param[in] j integer number of messages to skip
25C> (=0 to search from beginning)
26C> (<0 to read index buffer and skip -1-j messages).
27C> @param[in] jpds integer (200) pds parameters for which to search
28C> (=-1 for wildcard).
29C> - 1: id of center.
30C> - 2: generating process id number.
31C> - 3: grid definition.
32C> - 4: gds/bms flag (right adj copy of octet 8).
33C> - 5: indicator of parameter.
34C> - 6: type of level.
35C> - 7: height/pressure , etc of level.
36C> - 8: year including (century-1).
37C> - 9: month of year.
38C> - 10: day of month.
39C> - 11: hour of day.
40C> - 12: minute of hour.
41C> - 13: indicator of forecast time unit.
42C> - 14: time range 1.
43C> - 15: time range 2.
44C> - 16: time range flag.
45C> - 17: number included in average.
46C> - 18: version nr of grib specification.
47C> - 19: version nr of parameter table.
48C> - 20: nr missing from average/accumulation.
49C> - 21: century of reference time of data.
50C> - 22: units decimal scale factor.
51C> - 23: subcenter number.
52C> - 24: pds byte 29, for nmc ensemble products.
53C> - 128 if forecast field error.
54C> - 64 if bias corrected fcst field.
55C> - 32 if smoothed field.
56C> - warning: can be combination of more than 1.
57C> - 25: pds byte 30, not used.
58C> @param[in] jgds integer (200) gds parameters for which to search
59C> (only searched if jpds(3)=255)
60C> (=-1 for wildcard).
61C> - 1: data representation type.
62C> - 19: number of vertical coordinate parameters.
63C> - 20: octet number of the list of vertical coordinate parameters or
64C> octet number of the list of numbers of points in each row or
65C> 255 if neither are present.
66C> - 21: for grids with pl, number of points in grid.
67C> - 22: number of words in each row.
68C> - Latitude/longitude grids.
69C> - 2: n(i) nr points on latitude circle.
70C> - 3: n(j) nr points on longitude meridian.
71C> - 4: la(1) latitude of origin.
72C> - 5: lo(1) longitude of origin.
73C> - 6: resolution flag (right adj copy of octet 17).
74C> - 7: la(2) latitude of extreme point.
75C> - 8: lo(2) longitude of extreme point.
76C> - 9: di longitudinal direction of increment.
77C> - 10: dj latitudinal direction increment.
78C> - 11: scanning mode flag (right adj copy of octet 28).
79C> - Gaussian grids.
80C> - 2: n(i) nr points on latitude circle.
81C> - 3: n(j) nr points on longitude meridian.
82C> - 4: la(1) latitude of origin.
83C> - 5: lo(1) longitude of origin.
84C> - 6: resolution flag (right adj copy of octet 17).
85C> - 7: la(2) latitude of extreme point.
86C> - 8: lo(2) longitude of extreme point.
87C> - 9: di longitudinal direction of increment.
88C> - 10: n - nr of circles pole to equator.
89C> - 11: scanning mode flag (right adj copy of octet 28).
90C> - 12: nv - nr of vert coord parameters.
91C> - 13: pv - octet nr of list of vert coord parameters or
92C> pl - location of the list of numbers of points in each row
93C> (if no vert coord parameters are present or
94C> 255 if neither are present
95C> - Polar stereographic grids.
96C> - 2: n(i) nr points along lat circle.
97C> - 3: n(j) nr points along lon circle.
98C> - 4: la(1) latitude of origin.
99C> - 5: lo(1) longitude of origin.
100C> - 6: resolution flag (right adj copy of octet 17).
101C> - 7: lov grid orientation.
102C> - 8: dx - x direction increment.
103C> - 9: dy - y direction increment.
104C> - 10: projection center flag.
105C> - 11: scanning mode (right adj copy of octet 28).
106C> - Spherical harmonic coefficients.
107C> - 2): j pentagonal resolution parameter.
108C> - 3): k pentagonal resolution parameter.
109C> - 4): m pentagonal resolution parameter.
110C> - 5): representation type.
111C> - 6): coefficient storage mode.
112C> - Mercator grids.
113C> - 2: n(i) nr points on latitude circle.
114C> - 3: n(j) nr points on longitude meridian.
115C> - 4: la(1) latitude of origin.
116C> - 5: lo(1) longitude of origin.
117C> - 6: resolution flag (right adj copy of octet 17).
118C> - 7: la(2) latitude of last grid point.
119C> - 8: lo(2) longitude of last grid point.
120C> - 9: latit - latitude of projection intersection.
121C> - 10: reserved.
122C> - 11: scanning mode flag (right adj copy of octet 28).
123C> - 12: longitudinal dir grid length.
124C> - 13: latitudinal dir grid length.
125C> - Lambert conformal grids.
126C> - 2: nx nr points along x-axis.
127C> - 3: ny nr points along y-axis.
128C> - 4: la1 lat of origin (lower left).
129C> - 5: lo1 lon of origin (lower left).
130C> - 6: resolution (right adj copy of octet 17).
131C> - 7: lov - orientation of grid.
132C> - 8: dx - x-dir increment.
133C> - 9: dy - y-dir increment.
134C> - 10: projection center flag.
135C> - 11: scanning mode flag (right adj copy of octet 28).
136C> - 12: latin 1 - first lat from pole of secant cone inter.
137C> - 13: latin 2 - second lat from pole of secant cone inter.
138C> @param[in] mbuf integer length of index buffer in bytes.
139C> @param[inout] cbuf character*1 (mbuf) index buffer
140C> (initialize by setting j=-1).
141C> @param[inout] nlen integer length of each index record in bytes
142C> (initialize by setting j=-1).
143C> @param[inout] nnum integer number of index records
144C> (initialize by setting j=-1).
145C> @param[inout] mnum integer number of index records skipped
146C> (initialize by setting j=-1).
147C> @param[out] kg integer number of bytes in the grib message.
148C> @param[out] kf integer number of data points in the message.
149C> @param[out] k integer message number unpacked
150C> (can be same as j in calling program in order to facilitate multiple searches).
151C> @param[out] kpds integer (200) unpacked pds parameters.
152C> @param[out] kgds integer (200) unpacked gds parameters.
153C> @param[out] iret integer return code.
154C> - 0: all ok.
155C> - 96: error reading index file.
156C> - 99: request not found.
157C>
158C> @note Specify an index file if feasible to increase speed.
159C> Subprogram can be called from a multiprocessing environment.
160C> Do not engage the same logical unit from more than one processor.
161C>
162C> @author Mark Iredell @date 1994-04-01
163C-----------------------------------------------------------------------
164 SUBROUTINE getgbmh(LUGB,LUGI,J,JPDS,JGDS,
165 & MBUF,CBUF,NLEN,NNUM,MNUM,
166 & KG,KF,K,KPDS,KGDS,IRET)
167 INTEGER JPDS(200),JGDS(200)
168 INTEGER KPDS(200),KGDS(200)
169 CHARACTER CBUF(MBUF)
170 parameter(msk1=32000,msk2=4000)
171 INTEGER JENS(200),KENS(200)
172C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
173C SEARCH PREVIOUS INDEX BUFFER IF POSSIBLE
174 jens=-1
175 IF(j.GE.0) THEN
176 IF(mnum.GE.0) THEN
177 irgi=0
178 ELSE
179 mnum=-1-mnum
180 irgi=1
181 ENDIF
182 jr=j-mnum
183 IF(jr.GE.0.AND.(jr.LT.nnum.OR.irgi.EQ.0)) THEN
184 CALL getgb1s(cbuf,nlen,nnum,jr,jpds,jgds,jens,
185 & kr,kpds,kgds,kens,lskip,lgrib,irgs)
186 IF(irgs.EQ.0) k=kr+mnum
187 IF(irgi.EQ.1.AND.irgs.EQ.0) mnum=-1-mnum
188 IF(irgi.EQ.1.AND.irgs.GT.0) mnum=mnum+nnum
189 ELSE
190 mnum=j
191 irgi=1
192 irgs=1
193 ENDIF
194 ELSE
195 mnum=-1-j
196 irgi=1
197 irgs=1
198 ENDIF
199C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
200C READ AND SEARCH NEXT INDEX BUFFER
201 jr=0
202 dowhile(irgi.EQ.1.AND.irgs.EQ.1)
203 IF(lugi.GT.0) THEN
204 CALL getgi(lugi,mnum,mbuf,cbuf,nlen,nnum,irgi)
205 ELSE
206 CALL getgir(lugb,msk1,msk2,mnum,mbuf,cbuf,nlen,nnum,irgi)
207 ENDIF
208 IF(irgi.LE.1) THEN
209 CALL getgb1s(cbuf,nlen,nnum,jr,jpds,jgds,jens,
210 & kr,kpds,kgds,kens,lskip,lgrib,irgs)
211 IF(irgs.EQ.0) k=kr+mnum
212 IF(irgi.EQ.1.AND.irgs.EQ.0) mnum=-1-mnum
213 IF(irgi.EQ.1.AND.irgs.GT.0) mnum=mnum+nnum
214 ENDIF
215 ENDDO
216C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
217C READ GRIB RECORD
218 IF(irgi.GT.1) THEN
219 iret=96
220 ELSEIF(irgs.NE.0) THEN
221 iret=99
222 ELSE
223 kg=lgrib
224 kf=lengds(kgds)
225 iret=0
226 ENDIF
227C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
228 RETURN
229 END
subroutine getgb1s(cbuf, nlen, nnum, j, jpds, jgds, jens, k, kpds, kgds, kens, lskip, lgrib, iret)
Find a grib message.
Definition getgb1s.f:44
subroutine getgbmh(lugb, lugi, j, jpds, jgds, mbuf, cbuf, nlen, nnum, mnum, kg, kf, k, kpds, kgds, iret)
Read a grib index file (or optionally the grib file itself) to get the index buffer (i....
Definition getgbmh.f:167
subroutine getgi(lugi, mnum, mbuf, cbuf, nlen, nnum, iret)
Read a grib index file and return its contents.
Definition getgi.f:50
subroutine getgir(lugb, msk1, msk2, mnum, mbuf, cbuf, nlen, nnum, iret)
Read a grib file and return its index contents.
Definition getgir.f:45
function lengds(kgds)
Program history log:
Definition lengds.f:15