NCEPLIBS-w3emc  2.11.0
getgbexm.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> Read a grib index file (or optionally the grib file itself)
6 C> to get the index buffer (i.e. table of contents) for the grib file.
7 C> Find in the index buffer a reference to the grib message requested.
8 C> The grib message request specifies the number of messages to skip
9 C> and the unpacked pds and gds parameters. (A requested parameter
10 C> of -1 means to allow any value of this parameter to be found.)
11 C> If the requested grib message is found, then it is read from the
12 C> grib file and unpacked. Its message number is returned along with
13 C> the unpacked pds and gds parameters, the unpacked bitmap (if any),
14 C> and the unpacked data. If the grib message is not found, then the
15 C> return code will be nonzero.
16 C>
17 C> Program history log:
18 C> - Mark Iredell 1994-04-01
19 C> - Mark Iredell 1995-10-31 Modularized portions of code into subprograms
20 C> and allowed for unspecified index file.
21 C> - Y. Zhu 1997-02-11 Included probability and cluster arguments.
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 or.
67 C> 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 each row
96 C> (if no vert coord parameters are present) or 255 if neither are present.
97 C> - Polar stereographic grids.
98 C> - 2: n(i) nr points along lat circle.
99 C> - 3: n(j) nr points along lon circle.
100 C> - 4: la(1) latitude of origin.
101 C> - 5: lo(1) longitude of origin.
102 C> - 6: resolution flag (right adj copy of octet 17).
103 C> - 7: lov grid orientation.
104 C> - 8: dx - x direction increment.
105 C> - 9: dy - y direction increment.
106 C> - 10: projection center flag.
107 C> - 11: scanning mode (right adj copy of octet 28).
108 C> - Spherical harmonic coefficients.
109 C> - 2: j pentagonal resolution parameter.
110 C> - 3: k pentagonal resolution parameter.
111 C> - 4: m pentagonal resolution parameter.
112 C> - 5: representation type.
113 C> - 6: coefficient storage mode.
114 C> - Mercator grids.
115 C> - 2: n(i) nr points on latitude circle.
116 C> - 3: n(j) nr points on longitude meridian.
117 C> - 4: la(1) latitude of origin.
118 C> - 5: lo(1) longitude of origin.
119 C> - 6: resolution flag (right adj copy of octet 17).
120 C> - 7: la(2) latitude of last grid point.
121 C> - 8: lo(2) longitude of last grid point.
122 C> - 9: latit - latitude of projection intersection.
123 C> - 10: reserved.
124 C> - 11: scanning mode flag (right adj copy of octet 28).
125 C> - 12: longitudinal dir grid length.
126 C> - 13: latitudinal dir grid length.
127 C> - Lambert conformal grids.
128 C> - 2: nx nr points along x-axis.
129 C> - 3: ny nr points along y-axis.
130 C> - 4: la1 lat of origin (lower left).
131 C> - 5: lo1 lon of origin (lower left).
132 C> - 6: resolution (right adj copy of octet 17).
133 C> - 7: lov - orientation of grid.
134 C> - 8: dx - x-dir increment.
135 C> - 9: dy - y-dir increment.
136 C> - 10: projection center flag.
137 C> - 11: scanning mode flag (right adj copy of octet 28).
138 C> - 12: latin 1 - first lat from pole of secant cone inter.
139 C> - 13: latin 2 - second lat from pole of secant cone inter.
140 C> @param[in] jens integer (200) ensemble pds parms for which to search
141 C> (only searched if jpds(23)=2)
142 C> (=-1 for wildcard).
143 C> - 1: application identifier.
144 C> - 2: ensemble type.
145 C> - 3: ensemble identifier.
146 C> - 4: product identifier.
147 C> - 5: smoothing flag.
148 C> @param[in] mbuf integer length of index buffer in bytes.
149 C> @param[inout] cbuf character*1 (mbuf) index buffer
150 C> (initialize by setting j=-1).
151 C> @param[inout] nlen integer length of each index record in bytes
152 C> (initialize by setting j=-1).
153 C> @param[inout] nnum integer number of index records
154 C> (initialize by setting j=-1).
155 C> @param[inout] mnum integer number of index records skipped
156 C> (initialize by setting j=-1).
157 C> @param[out] kf integer number of data points unpacked.
158 C> @param[out] k integer message number unpacked
159 C> (can be same as j in calling program
160 C> in order to facilitate multiple searches).
161 C> @param[out] kpds integer (200) unpacked pds parameters.
162 C> @param[out] kgds integer (200) unpacked gds parameters.
163 C> @param[out] kens integer (200) unpacked ensemble pds parms.
164 C> @param[out] kprob integer (2) probability ensemble parms.
165 C> @param[out] xprob real (2) probability ensemble parms.
166 C> @param[out] kclust integer (16) cluster ensemble parms.
167 C> @param[out] kmembr integer (8) cluster ensemble parms.
168 C> @param[out] lb logical*1 (kf) unpacked bitmap if present.
169 C> @param[out] f real (kf) unpacked data.
170 C> @param[out] iret integer return code.
171 C> - 0 all ok.
172 C> - 96 error reading index file.
173 C> - 97 error reading grib file.
174 C> - 98 number of data points greater than jf.
175 C> - 99 request not found.
176 C> - other w3fi63 grib unpacker return code.
177 C>
178 C> @note Specify an index file if feasible to increase speed.
179 C> Subprogram can be called from a multiprocessing environment.
180 C> Do not engage the same logical unit from more than one processor.
181 C>
182 C> @author Mark Iredell @date 1994-04-01
183 C-----------------------------------------------------------------------
184  SUBROUTINE getgbexm(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,
185  & MBUF,CBUF,NLEN,NNUM,MNUM,
186  & KF,K,KPDS,KGDS,KENS,KPROB,XPROB,KCLUST,KMEMBR,
187  & LB,F,IRET)
188  INTEGER JPDS(200),JGDS(200),JENS(200)
189  INTEGER KPDS(200),KGDS(200),KENS(200)
190  INTEGER KPROB(2),KCLUST(16),KMEMBR(80)
191  REAL XPROB(2)
192  CHARACTER CBUF(MBUF)
193  LOGICAL*1 LB(JF)
194  REAL F(JF)
195  parameter(msk1=32000,msk2=4000)
196 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
197 C SEARCH PREVIOUS INDEX BUFFER IF POSSIBLE
198  IF(j.GE.0) THEN
199  IF(mnum.GE.0) THEN
200  irgi=0
201  ELSE
202  mnum=-1-mnum
203  irgi=1
204  ENDIF
205  jr=j-mnum
206  IF(jr.GE.0.AND.(jr.LT.nnum.OR.irgi.EQ.0)) THEN
207  CALL getgb1s(cbuf,nlen,nnum,jr,jpds,jgds,jens,
208  & kr,kpds,kgds,kens,lskip,lgrib,irgs)
209  IF(irgs.EQ.0) k=kr+mnum
210  IF(irgi.EQ.1.AND.irgs.EQ.0) mnum=-1-mnum
211  IF(irgi.EQ.1.AND.irgs.GT.0) mnum=mnum+nnum
212  ELSE
213  mnum=j
214  irgi=1
215  irgs=1
216  ENDIF
217  ELSE
218  mnum=-1-j
219  irgi=1
220  irgs=1
221  ENDIF
222 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223 C READ AND SEARCH NEXT INDEX BUFFER
224  jr=0
225  dowhile(irgi.EQ.1.AND.irgs.EQ.1)
226  IF(lugi.GT.0) THEN
227  CALL getgi(lugi,mnum,mbuf,cbuf,nlen,nnum,irgi)
228  ELSE
229  CALL getgir(lugb,msk1,msk2,mnum,mbuf,cbuf,nlen,nnum,irgi)
230  ENDIF
231  IF(irgi.LE.1) THEN
232  CALL getgb1s(cbuf,nlen,nnum,jr,jpds,jgds,jens,
233  & kr,kpds,kgds,kens,lskip,lgrib,irgs)
234  IF(irgs.EQ.0) k=kr+mnum
235  IF(irgi.EQ.1.AND.irgs.EQ.0) mnum=-1-mnum
236  IF(irgi.EQ.1.AND.irgs.GT.0) mnum=mnum+nnum
237  ENDIF
238  ENDDO
239 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
240 C READ AND UNPACK GRIB RECORD
241  IF(irgi.GT.1) THEN
242  iret=96
243  ELSEIF(irgs.NE.0) THEN
244  iret=99
245  ELSEIF(lengds(kgds).GT.jf) THEN
246  iret=98
247  ELSE
248  CALL getgb1re(lugb,lskip,lgrib,kf,kpds,kgds,kens,
249  & kprob,xprob,kclust,kmembr,lb,f,iret)
250  ENDIF
251 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
252  RETURN
253  END
subroutine getgb1re(LUGB, LSKIP, LGRIB, KF, KPDS, KGDS, KENS, KPROB, XPROB, KCLUST, KMEMBR, LB, F, IRET)
Reads and unpacks a grib message.
Definition: getgb1re.f:38
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 getgbexm(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, MBUF, CBUF, NLEN, NNUM, MNUM, KF, K, KPDS, KGDS, KENS, KPROB, XPROB, KCLUST, KMEMBR, LB, F, IRET)
Read a grib index file (or optionally the grib file itself) to get the index buffer (i....
Definition: getgbexm.f:188
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