NCEPLIBS-w3emc  2.11.0
getgbex.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> (The index buffer is saved for use by future prospective calls.)
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> - Y. Zhu 1997-02-11 Included probability and cluster arguments.
23 C>
24 C> @param[in] lugb integer unit of the unblocked grib data file.
25 C> @param[in] lugi integer unit of the unblocked grib index file
26 C> (=0 to get index buffer from the grib file).
27 C> @param[in] jf integer maximum number of data points to unpack.
28 C> @param[in] j integer number of messages to skip
29 C> (=0 to search from beginning)
30 C> (<0 to read index buffer and skip -1-j messages).
31 C> @param[in] jpds integer (200) pds parameters for which to search
32 C> (=-1 for wildcard).
33 C> - 1: id of center.
34 C> - 2: generating process id number.
35 C> - 3: grid definition.
36 C> - 4: gds/bms flag (right adj copy of octet 8).
37 C> - 5: indicator of parameter.
38 C> - 6: type of level.
39 C> - 7: height/pressure , etc of level.
40 C> - 8: year including (century-1).
41 C> - 9: month of year.
42 C> - 10: day of month.
43 C> - 11: hour of day.
44 C> - 12: minute of hour.
45 C> - 13: indicator of forecast time unit.
46 C> - 14: time range 1.
47 C> - 15: time range 2.
48 C> - 16: time range flag.
49 C> - 17: number included in average.
50 C> - 18: version nr of grib specification.
51 C> - 19: version nr of parameter table.
52 C> - 20: nr missing from average/accumulation.
53 C> - 21: century of reference time of data.
54 C> - 22: units decimal scale factor.
55 C> - 23: subcenter number.
56 C> - 24: pds byte 29, for nmc ensemble products.
57 C> - 128 if forecast field error.
58 C> - 64 if bias corrected fcst field.
59 C> - 32 if smoothed field.
60 C> - warning: can be combination of more than 1.
61 C> - 25: pds byte 30, not used.
62 C> @param[in] jgds integer (200) gds parameters for which to search
63 C> (only searched if jpds(3)=255)
64 C> (=-1 for wildcard).
65 C> - 1: data representation type.
66 C> - 19: number of vertical coordinate parameters.
67 C> - 20: octet number of the list of vertical coordinate parameters or
68 C> octet number of the list of numbers of points in each row or
69 C> 255 if neither are present.
70 C> - 21: for grids with pl, number of points in grid.
71 C> - 22: number of words in each row.
72 C> - Latitude/longitude grids.
73 C> - 2: n(i) nr points on latitude circle.
74 C> - 3: n(j) nr points on longitude meridian.
75 C> - 4: la(1) latitude of origin.
76 C> - 5: lo(1) longitude of origin.
77 C> - 6: resolution flag (right adj copy of octet 17).
78 C> - 7: la(2) latitude of extreme point.
79 C> - 8: lo(2) longitude of extreme point.
80 C> - 9: di longitudinal direction of increment.
81 C> - 10: dj latitudinal direction increment.
82 C> - 11: scanning mode flag (right adj copy of octet 28).
83 C> - Gaussian grids.
84 C> - 2: n(i) nr points on latitude circle.
85 C> - 3: n(j) nr points on longitude meridian.
86 C> - 4: la(1) latitude of origin.
87 C> - 5: lo(1) longitude of origin.
88 C> - 6: resolution flag (right adj copy of octet 17).
89 C> - 7: la(2) latitude of extreme point.
90 C> - 8: lo(2) longitude of extreme point.
91 C> - 9: di longitudinal direction of increment.
92 C> - 10: n - nr of circles pole to equator.
93 C> - 11: scanning mode flag (right adj copy of octet 28).
94 C> - 12: nv - nr of vert coord parameters.
95 C> - 13:
96 C> - 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.
99 C> - 255 if neither are present.
100 C> - Polar stereographic grids.
101 C> - 2: n(i) nr points along lat circle.
102 C> - 3: n(j) nr points along lon circle.
103 C> - 4: la(1) latitude of origin.
104 C> - 5: lo(1) longitude of origin.
105 C> - 6: resolution flag (right adj copy of octet 17).
106 C> - 7: lov grid orientation.
107 C> - 8: dx - x direction increment.
108 C> - 9: dy - y direction increment.
109 C> - 10: projection center flag.
110 C> - 11: scanning mode (right adj copy of octet 28).
111 C> - Spherical harmonic coefficients.
112 C> - 2: j pentagonal resolution parameter.
113 C> - 3: k pentagonal resolution parameter.
114 C> - 4: m pentagonal resolution parameter.
115 C> - 5: representation type.
116 C> - 6: coefficient storage mode.
117 C> - Mercator grids.
118 C> - 2: n(i) nr points on latitude circle.
119 C> - 3: n(j) nr points on longitude meridian.
120 C> - 4: la(1) latitude of origin.
121 C> - 5: lo(1) longitude of origin.
122 C> - 6: resolution flag (right adj copy of octet 17).
123 C> - 7: la(2) latitude of last grid point.
124 C> - 8: lo(2) longitude of last grid point.
125 C> - 9: latit - latitude of projection intersection.
126 C> - 10: reserved.
127 C> - 11: scanning mode flag (right adj copy of octet 28).
128 C> - 12: longitudinal dir grid length.
129 C> - 13: latitudinal dir grid length.
130 C> - Lambert conformal grids.
131 C> - 2: nx nr points along x-axis.
132 C> - 3: ny nr points along y-axis.
133 C> - 4: la1 lat of origin (lower left).
134 C> - 5: lo1 lon of origin (lower left).
135 C> - 6: resolution (right adj copy of octet 17).
136 C> - 7: lov - orientation of grid.
137 C> - 8: dx - x-dir increment.
138 C> - 9: dy - y-dir increment.
139 C> - 10: projection center flag.
140 C> - 11: scanning mode flag (right adj copy of octet 28).
141 C> - 12: latin 1 - first lat from pole of secant cone inter.
142 C> - 13: latin 2 - second lat from pole of secant cone inter.
143 C> @param[in] jens integer (200) ensemble pds parms for which to search
144 C> (only searched if jpds(23)=2)
145 C> (=-1 for wildcard).
146 C> - 1: application identifier.
147 C> - 2: ensemble type.
148 C> - 3: ensemble identifier.
149 C> - 4: product identifier.
150 C> - 5: smoothing flag.
151 C>
152 C> @param[out] kf integer number of data points unpacked.
153 C> @param[out] k integer message number unpacked
154 C> (can be same as j in calling program
155 C> in order to facilitate multiple searches).
156 C> @param[out] kpds integer (200) unpacked pds parameters.
157 C> @param[out] kgds integer (200) unpacked gds parameters.
158 C> @param[out] kens integer (200) unpacked ensemble pds parms.
159 C> @param[out] kprob integer (2) probability ensemble parms.
160 C> @param[out] xprob real (2) probability ensemble parms.
161 C> @param[out] kclust integer (16) cluster ensemble parms.
162 C> @param[out] kmembr integer (8) cluster ensemble parms.
163 C> @param[out] lb logical*1 (kf) unpacked bitmap if present.
164 C> @param[out] f real (kf) unpacked data.
165 C> @param[out] iret integer return code.
166 C> - 0: all ok.
167 C> - 96: error reading index file.
168 C> - 97: error reading grib file.
169 C> - 98: number of data points greater than jf.
170 C> - 99: request not found.
171 C> - other w3fi63 grib unpacker return code.
172 C>
173 C> @note In order to unpack grib from a multiprocessing environment
174 C> where each processor is attempting to read from its own pair of
175 C> logical units, one must directly call subprogram getgbexm as below,
176 C> allocating a private copy of cbuf, nlen and nnum to each processor.
177 C> Do not engage the same logical unit from more than one processor.
178 C>
179 C> @author Mark Iredell @date 1994-04-01
180 C-----------------------------------------------------------------------
181  SUBROUTINE getgbex(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,
182  & KF,K,KPDS,KGDS,KENS,KPROB,XPROB,KCLUST,KMEMBR,
183  & LB,F,IRET)
184  INTEGER JPDS(200),JGDS(200),JENS(200)
185  INTEGER KPDS(200),KGDS(200),KENS(200)
186  INTEGER KPROB(2),KCLUST(16),KMEMBR(80)
187  REAL XPROB(2)
188  LOGICAL*1 LB(JF)
189  REAL F(JF)
190  parameter(mbuf=256*1024)
191  CHARACTER CBUF(MBUF)
192  SAVE cbuf,nlen,nnum,mnum
193  DATA lux/0/
194 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
195 C DETERMINE WHETHER INDEX BUFFER NEEDS TO BE INITIALIZED
196  IF(lugi.GT.0.AND.(j.LT.0.OR.lugi.NE.lux)) THEN
197  lux=lugi
198  jj=min(j,-1-j)
199  ELSEIF(lugi.LE.0.AND.(j.LT.0.OR.lugb.NE.lux)) THEN
200  lux=lugb
201  jj=min(j,-1-j)
202  ELSE
203  jj=j
204  ENDIF
205 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206 C FIND AND UNPACK GRIB MESSAGE
207  CALL getgbexm(lugb,lugi,jf,jj,jpds,jgds,jens,
208  & mbuf,cbuf,nlen,nnum,mnum,
209  & kf,k,kpds,kgds,kens,kprob,xprob,kclust,kmembr,
210  & lb,f,iret)
211  IF(iret.EQ.96) lux=0
212 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
213  RETURN
214  END
subroutine getgbex(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, 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: getgbex.f:184
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