NCEPLIBS-w3emc  2.11.0
getgbh.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> (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 its message number is
13 C> returned along with the unpacked pds and gds parameters. If the
14 C> grib message is not found, then the return code will be nonzero.
15 C>
16 C> Program history log:
17 C> - Mark Iredell 1994-04-01
18 C> - Mark Iredell 1995-10-31 Modularized portions of code into subprograms
19 C> and allowed for unspecified index file.
20 C>
21 C> @param[in] lugb integer unit of the unblocked grib data file
22 C> (only used if lugi=0).
23 C> @param[in] lugi integer unit of the unblocked grib index file
24 C> (=0 to get index buffer from the grib file).
25 C> @param[in] j integer number of messages to skip
26 C> (=0 to search from beginning)
27 C> (<0 to read index buffer and skip -1-j messages)
28 C> @param[in] jpds integer (200) pds parameters for which to search
29 C> (=-1 for wildcard).
30 C> - 1: id of center.
31 C> - 2: generating process id number.
32 C> - 3: grid definition.
33 C> - 4: gds/bms flag (right adj copy of octet 8).
34 C> - 5: indicator of parameter.
35 C> - 6: type of level.
36 C> - 7: height/pressure , etc of level.
37 C> - 8: year including (century-1).
38 C> - 9: month of year.
39 C> - 10: day of month.
40 C> - 11: hour of day.
41 C> - 12: minute of hour.
42 C> - 13: indicator of forecast time unit.
43 C> - 14: time range 1.
44 C> - 15: time range 2.
45 C> - 16: time range flag.
46 C> - 17: number included in average.
47 C> - 18: version nr of grib specification.
48 C> - 19: version nr of parameter table.
49 C> - 20: nr missing from average/accumulation.
50 C> - 21: century of reference time of data.
51 C> - 22: units decimal scale factor.
52 C> - 23: subcenter number.
53 C> - 24: pds byte 29, for nmc ensemble products.
54 C> - 128 if forecast field error.
55 C> - 64 if bias corrected fcst field.
56 C> - 32 if smoothed field.
57 C> - warning: can be combination of more than 1.
58 C> - 25: pds byte 30, not used
59 C> @param[in] jgds integer (200) gds parameters for which to search
60 C> (only searched if jpds(3)=255)
61 C> (=-1 for wildcard).
62 C> - 1: data representation type.
63 C> - 19: number of vertical coordinate parameters.
64 C> - 20: octet number of the list of vertical coordinate parameters or
65 C> octet number of the list of numbers of points in each row or
66 C> 255 if neither are present.
67 C> - 21: for grids with pl, number of points in grid.
68 C> - 22: number of words in each row.
69 C> - tu: ngitude grids.
70 C> - 2: n(i) nr points on latitude circle.
71 C> - 3: n(j) nr points on longitude meridian.
72 C> - 4: la(1) latitude of origin.
73 C> - 5: lo(1) longitude of origin.
74 C> - 6: resolution flag (right adj copy of octet 17).
75 C> - 7: la(2) latitude of extreme point.
76 C> - 8: lo(2) longitude of extreme point.
77 C> - 9: di longitudinal direction of increment.
78 C> - 10: dj latitudinal direction increment.
79 C> - 11: scanning mode flag (right adj copy of octet 28).
80 C> - Gaussian grids.
81 C> - 2: n(i) nr points on latitude circle.
82 C> - 3: n(j) nr points on longitude meridian.
83 C> - 4: la(1) latitude of origin.
84 C> - 5: lo(1) longitude of origin.
85 C> - 6: resolution flag (right adj copy of octet 17).
86 C> - 7: la(2) latitude of extreme point.
87 C> - 8: lo(2) longitude of extreme point.
88 C> - 9: di longitudinal direction of increment.
89 C> - 10: n - nr of circles pole to equator.
90 C> - 11: scanning mode flag (right adj copy of octet 28).
91 C> - 12: nv - nr of vert coord parameters.
92 C> - 13: 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[out] kg integer number of bytes in the grib message.
140 C> @param[out] kf integer number of data points in the message.
141 C> @param[out] k integer message number unpacked
142 C> (can be same as j in calling program in order to facilitate multiple searches).
143 C> @param[out] kpds integer (200) unpacked pds parameters.
144 C> @param[out] kgds integer (200) unpacked gds parameters.
145 C> @param[out] iret integer return code.
146 C> - 0: all ok.
147 C> - 96: error reading index file.
148 C> - 99: request not found.
149 C>
150 C> @note In order to unpack grib from a multiprocessing environment
151 C> where each processor is attempting to read from its own pair of
152 C> logical units, one must directly call subprogram getgbmh as below,
153 C> allocating a private copy of cbuf, nlen and nnum to each processor.
154 C> Do not engage the same logical unit from more than one processor.
155 C>
156 C> @author Mark Iredell @date 1994-04-01
157 C-----------------------------------------------------------------------
158  SUBROUTINE getgbh(LUGB,LUGI,J,JPDS,JGDS,
159  & KG,KF,K,KPDS,KGDS,IRET)
160  INTEGER JPDS(200),JGDS(200)
161  INTEGER KPDS(200),KGDS(200)
162  parameter(mbuf=256*1024)
163  CHARACTER CBUF(MBUF)
164  SAVE cbuf,nlen,nnum,mnum
165  DATA lux/0/
166 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
167 C DETERMINE WHETHER INDEX BUFFER NEEDS TO BE INITIALIZED
168  IF(lugi.GT.0.AND.(j.LT.0.OR.lugi.NE.lux)) THEN
169  lux=lugi
170  jj=min(j,-1-j)
171  ELSEIF(lugi.LE.0.AND.(j.LT.0.OR.lugb.NE.lux)) THEN
172  lux=lugb
173  jj=min(j,-1-j)
174  ELSE
175  jj=j
176  ENDIF
177 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
178 C FIND AND UNPACK GRIB MESSAGE
179  CALL getgbmh(lugb,lugi,jj,jpds,jgds,
180  & mbuf,cbuf,nlen,nnum,mnum,
181  & kg,kf,k,kpds,kgds,iret)
182  IF(iret.EQ.96) lux=0
183 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184  RETURN
185  END
subroutine getgbh(LUGB, LUGI, J, JPDS, JGDS, KG, KF, K, KPDS, KGDS, IRET)
Read a grib index file (or optionally the grib file itself) to get the index buffer (i....
Definition: getgbh.f:160
subroutine getgbmh(LUGB, LUGI, J, JPDS, JGDS, MBUF, CBUF, NLEN, NNUM, MNUM, KG, KF, K, KPDS, KGDS, IRET)
Read a grib index file (or optionally the grib file itself) to get the index buffer (i....
Definition: getgbmh.f:167