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