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