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