NCEPLIBS-w3emc  2.11.0
getgbem.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Find and unpack a grib message.
3 C> @author Mark Iredell @date 1994-04-01
4 
5 C> Find and unpack a grib message.
6 C> Read a grib index file (or optionally the grib file itself)
7 C> to get the index buffer (i.e. table of contents) for the grib file.
8 C> Find in the index buffer a reference to the grib message requested.
9 C> The grib message request specifies the number of messages to skip
10 C> and the unpacked pds and gds parameters. (A requested parameter
11 C> of -1 means to allow any value of this parameter to be found.)
12 C> If the requested grib message is found, then it is read from the
13 C> grib file and unpacked. Its message number is returned along with
14 C> the unpacked pds and gds parameters, the unpacked bitmap (if any),
15 C> and the unpacked data. if the grib message is not found, then the
16 C> return code will be nonzero.
17 C>
18 C> Program history log:
19 C> - Mark Iredell 1994-04-01
20 C> - Mark Iredell 1995-10-31 Modularized portions of code into subprograms
21 C> and allowed for unspecified index file.
22 C>
23 C> @param[in] LUGB Integer unit of the unblocked grib data file.
24 C> @param[in] LUGI Integer unit of the unblocked grib index file
25 C> (=0 to get index buffer from the grib file).
26 C> @param[in] JF Integer maximum number of data points to unpack.
27 C> @param[in] J integer number of messages to skip
28 C> (=0 to search from beginning)
29 C> (<0 to read index buffer and skip -1-j messages)
30 C> @param[in] jpds integer (200) pds parameters for which to search
31 C> (=-1 for wildcard)
32 C> - 1 id of center.
33 C> - 2 generating process id number.
34 C> - 3 grid definition.
35 C> - 4 gds/bms flag (right adj copy of octet 8).
36 C> - 5 indicator of parameter.
37 C> - 6 type of level.
38 C> - 7 height/pressure , etc of level.
39 C> - 8 year including (century-1).
40 C> - 9 month of year.
41 C> - 10 day of month.
42 C> - 11 hour of day.
43 C> - 12 minute of hour.
44 C> - 13 indicator of forecast time unit.
45 C> - 14 time range 1.
46 C> - 15 time range 2.
47 C> - 16 time range flag.
48 C> - 17 number included in average.
49 C> - 18 version nr of grib specification.
50 C> - 19 version nr of parameter table.
51 C> - 20 nr missing from average/accumulation.
52 C> - 21 century of reference time of data.
53 C> - 22 units decimal scale factor.
54 C> - 23 subcenter number.
55 C> - 24 pds byte 29, for nmc ensemble products.
56 C> - 128 if forecast field error.
57 C> - 64 if bias corrected fcst field.
58 C> - 32 if smoothed field.
59 C> - warning: can be combination of more than 1.
60 C> - (25) - pds byte 30, not used.
61 C> @param[in] jgds integer (200) gds parameters for which to search
62 C> (only searched if jpds(3)=255)
63 C> (=-1 for wildcard).
64 C> - 1 data representation type.
65 C> - 19 number of vertical coordinate parameters.
66 C> - 20 octet number of the list of vertical coordinate parameters
67 C> or octet number of the list of numbers of points in each row or
68 C> 255 if neither are present.
69 C> - 21 for grids with pl, number of points in grid.
70 C> - 22 number of words in each row.
71 C> - Latitude/longitude grids.
72 C> - 2 n(i) nr points on latitude circle.
73 C> - 3 n(j) nr points on longitude meridian.
74 C> - 4 la(1) latitude of origin.
75 C> - 5 lo(1) longitude of origin.
76 C> - 6 resolution flag (right adj copy of octet 17).
77 C> - 7 la(2) latitude of extreme point.
78 C> - 8 lo(2) longitude of extreme point.
79 C> - 9 di longitudinal direction of increment.
80 C> - 10 dj latitudinal direction increment.
81 C> - 11 scanning mode flag (right adj copy of octet 28).
82 C> - Gaussian 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 n: nr of circles pole to equator.
92 C> - 11 scanning mode flag (right adj copy of octet 28).
93 C> - 12 nv: nr of vert coord parameters.
94 C> - 13 pv: octet nr of list of vert coord parameters or
95 C> - pl: location of the list of numbers of points in
96 C> each row (if no vert coord parameters are present or
97 C> - 255 if neither are present.
98 C> - Polar stereographic grids.
99 C> - 2 n(i) nr points along lat circle.
100 C> - 3 n(j) nr points along lon circle.
101 C> - 4 la(1) latitude of origin.
102 C> - 5 lo(1) longitude of origin.
103 C> - 6 resolution flag (right adj copy of octet 17).
104 C> - 7 lov grid orientation.
105 C> - 8 dx - x direction increment.
106 C> - 9 dy - y direction increment.
107 C> - 10 projection center flag.
108 C> - 11 scanning mode (right adj copy of octet 28).
109 C> - Spherical harmonic coefficients.
110 C> - 2 j pentagonal resolution parameter.
111 C> - 3 k pentagonal resolution parameter.
112 C> - 4 m pentagonal resolution parameter.
113 C> - 5 representation type.
114 C> - 6 coefficient storage mode.
115 C> - Mercator grids.
116 C> - 2 n(i) nr points on latitude circle.
117 C> - 3 n(j) nr points on longitude meridian.
118 C> - 4 la(1) latitude of origin.
119 C> - 5 lo(1) longitude of origin.
120 C> - 6 resolution flag (right adj copy of octet 17).
121 C> - 7 la(2) latitude of last grid point.
122 C> - 8 lo(2) longitude of last grid point.
123 C> - 9 latit - latitude of projection intersection.
124 C> - 10 reserved.
125 C> - 11 scanning mode flag (right adj copy of octet 28).
126 C> - 12 longitudinal dir grid length.
127 C> - 13 latitudinal dir grid length.
128 C> - Lambert conformal grids.
129 C> - 2 nx nr points along x-axis.
130 C> - 3 ny nr points along y-axis.
131 C> - 4 la1 lat of origin (lower left).
132 C> - 5 lo1 lon of origin (lower left).
133 C> - 6 resolution (right adj copy of octet 17).
134 C> - 7 lov - orientation of grid.
135 C> - 8 dx - x-dir increment.
136 C> - 9 dy - y-dir increment.
137 C> - 10 projection center flag.
138 C> - 11 scanning mode flag (right adj copy of octet 28).
139 C> - 12 latin 1 - first lat from pole of secant cone inter.
140 C> - 13 latin 2 - second lat from pole of secant cone inter.
141 C> @param[in] jens integer (200) ensemble pds parms for which to search
142 C> (only searched if jpds(23)=2)
143 C> (=-1 for wildcard).
144 C> - 1 application identifier.
145 C> - 2 ensemble type.
146 C> - 3 ensemble identifier.
147 C> - 4 product identifier.
148 C> - 5 smoothing flag.
149 C> @param[in] mbuf integer length of index buffer in bytes.
150 C> @param[inout] nnum integer number of index records
151 C> (initialize by setting j=-1).
152 C> @param[inout] mnum integer number of index records skipped
153 C> (initialize by setting j=-1).
154 C> @param[inout] cbuf character*1 (mbuf) index buffer
155 C> (initialize by setting j=-1).
156 C> @param[inout] nlen integer length of each index record in bytes.
157 C> (initialize by setting j=-1).
158 C> @param[out] kf integer number of data points unpacked.
159 C> @param[out] k integer message number unpacked
160 C> (can be same as j in calling program
161 C> in order to facilitate multiple searches).
162 C> @param[out] kpds integer (200) unpacked pds parameters.
163 C> @param[out] kgds integer (200) unpacked gds parameters.
164 C> @param[out] kens integer (200) unpacked ensemble pds parms.
165 C> @param[out] lb logical*1 (kf) unpacked bitmap if present.
166 C> @param[out] f real (kf) unpacked data.
167 C> @param[out] iret integer return code.
168 C> - 0 all ok.
169 C> - 96 error reading index file.
170 C> - 97 error reading grib file.
171 C> - 98 number of data points greater than jf.
172 C> - 99 request not found.
173 C> - other w3fi63 grib unpacker return code.
174 C>
175 C> @note Specify an index file if feasible to increase speed.
176 C> Subprogram can be called from a multiprocessing environment.
177 C> Do not engage the same logical unit from more than one processor.
178 C>
179 C-----------------------------------------------------------------------
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)
189 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
190 C 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
215 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
216 C 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
232 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
233 C 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
244 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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