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