NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
getgb1.f
Go to the documentation of this file.
1C> @file
2C> @brief Find and unpacks a grib message.
3C> @author Mark Iredell @date 1994-04-01
4
5C> Find and unpack a grib message.
6C> Read an associated grib index file (unless it already was read).
7C> Find in the index file a reference to the grib message requested.
8C> The grib message request specifies the number of messages to skip
9C> and the unpacked pds and gds parameters. (A requested parameter
10C> of -1 means to allow any value of this parameter to be found.)
11C> If the requested grib message is found, then it is read from the
12C> grib file and unpacked. Its message number is returned along with
13C> the unpacked pds and gds parameters, the unpacked bitmap (if any),
14C> and the unpacked data. If the grib message is not found, then the
15C> return code will be nonzero.
16C>
17C> Program history log:
18C> - Mark Iredell 1994-04-01
19C> - Ralph Jones 1995-05-10 Add one more parameter to getgb and
20C> change name to getgb1.
21C>
22C> @param[in] lugb logical unit of the unblocked grib data file.
23C> @param[in] lugi logical unit of the unblocked grib index file.
24C> @param[in] jf integer maximum number of data points to unpack.
25C> @param[in] j integer number of messages to skip (=0 to search from beginning)
26C> (<0 to reopen index file and search from beginning).
27C> @param[in] jpds integer (25) pds parameters for which to search
28C> (=-1 for wildcard) look in doc block of w3fi63 for array kpds
29C> for list of order of unpacked pds values.
30C> In most cases you only need to set 4 or 5 values to pick up record.
31C> @param[in] jgds integer (22) gds parameters for which to search
32C> (only searched if jpds(3)=255) (=-1 for wildcard).
33C> @param[out] grib Grib data array before it is unpacked.
34C> @param[out] kf Integer number of data points unpacked.
35C> @param[out] k Integer message number unpacked
36C> (can be same as j in calling program
37C> in order to facilitate multiple searches).
38C> @param[out] kpds Integer (25) unpacked pds parameters.
39C> @param[out] kgds Integer (22) unpacked gds parameters.
40C> @param[out] lb Logical (kf) unpacked bitmap if present.
41C> @param[out] f Real (kf) unpacked data.
42C> @param[out] iret Integer return code.
43C> - 0 All ok.
44C> - 96 Error reading index file.
45C> - 97 Error reading grib file.
46C> - 98 Number of data points greater than jf.
47C> - 99 Request not found.
48C> - other w3fi63 grib unpacker return code.
49C>
50C> @author Mark Iredell @date 1994-04-01
51 SUBROUTINE getgb1(LUGB,LUGI,JF,J,JPDS,JGDS,
52 & GRIB,KF,K,KPDS,KGDS,LB,F,IRET)
53C
54 parameter(mbuf=8192*128)
55 parameter(lpds=23,lgds=22)
56C
57 INTEGER JPDS(25),JGDS(*),KPDS(25),KGDS(*)
58 INTEGER IPDSP(LPDS),JPDSP(LPDS),IGDSP(LGDS)
59 INTEGER JGDSP(LGDS)
60 INTEGER KPTR(20)
61C
62 LOGICAL LB(*)
63C
64 REAL F(*)
65C
66 CHARACTER CBUF(MBUF)
67 CHARACTER*81 CHEAD(2)
68 CHARACTER*1 CPDS(28)
69 CHARACTER*1 CGDS(42)
70 CHARACTER*1 GRIB(*)
71C
72C SAVE LUX,NSKP,NLEN,NNUM,CBUF
73 SAVE
74C
75 DATA lux/0/
76C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77C READ INDEX FILE
78 IF(j.LT.0.OR.lugi.NE.lux) THEN
79C REWIND LUGI
80C READ(LUGI,fmt='(2A81)',IOSTAT=IOS) CHEAD
81 CALL baread(lugi,0,162,ios,chead)
82 IF(ios.EQ.162.AND.chead(1)(42:47).EQ.'GB1IX1') THEN
83 lux=0
84 READ(chead(2),'(8X,3I10,2X,A40)',iostat=ios) nskp,nlen,nnum
85 IF(ios.EQ.0) THEN
86 nbuf=nnum*nlen
87 IF(nbuf.GT.mbuf) THEN
88 print *,'GETGB1: INCREASE BUFFER FROM ',mbuf,' TO ',nbuf
89 nnum=mbuf/nlen
90 nbuf=nnum*nlen
91 ENDIF
92 CALL baread(lugi,nskp,nbuf,lbuf,cbuf)
93 IF(lbuf.EQ.nbuf) THEN
94 lux=lugi
95 j=max(j,0)
96 ENDIF
97 ENDIF
98 ENDIF
99 ENDIF
100C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101C SEARCH FOR REQUEST
102 lgrib=0
103 kj=j
104 k=j
105 kf=0
106 IF(j.GE.0.AND.lugi.EQ.lux) THEN
107 lpdsp=0
108 DO i=1,lpds
109 IF(jpds(i).NE.-1) THEN
110 lpdsp=lpdsp+1
111 ipdsp(lpdsp)=i
112 jpdsp(lpdsp)=jpds(i)
113 ENDIF
114 ENDDO
115 lgdsp=0
116 IF(jpds(3).EQ.255) THEN
117 DO i=1,lgds
118 IF(jgds(i).NE.-1) THEN
119 lgdsp=lgdsp+1
120 igdsp(lgdsp)=i
121 jgdsp(lgdsp)=jgds(i)
122 ENDIF
123 ENDDO
124 ENDIF
125 iret=99
126 dowhile(lgrib.EQ.0.AND.kj.LT.nnum)
127 kj=kj+1
128 lt=0
129 IF(lpdsp.GT.0) THEN
130 cpds=cbuf((kj-1)*nlen+26:(kj-1)*nlen+53)
131 kptr=0
132 CALL gbyte(cbuf,kptr(3),(kj-1)*nlen*8+25*8,3*8)
133 CALL fi632(cpds,kptr,kpds,iret)
134 DO i=1,lpdsp
135 ip=ipdsp(i)
136 lt=lt+abs(jpds(ip)-kpds(ip))
137 ENDDO
138 ENDIF
139 IF(lt.EQ.0.AND.lgdsp.GT.0) THEN
140 cgds=cbuf((kj-1)*nlen+54:(kj-1)*nlen+95)
141 kptr=0
142 CALL fi633(cgds,kptr,kgds,iret)
143 DO i=1,lgdsp
144 ip=igdsp(i)
145 lt=lt+abs(jgds(ip)-kgds(ip))
146 ENDDO
147 ENDIF
148C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
149C READ AND UNPACK GRIB DATA
150 IF(lt.EQ.0) THEN
151 CALL gbyte(cbuf,lskip,(kj-1)*nlen*8,4*8)
152 CALL gbyte(cbuf,lgrib,(kj-1)*nlen*8+20*8,4*8)
153 cgds=cbuf((kj-1)*nlen+54:(kj-1)*nlen+95)
154 kptr=0
155 CALL fi633(cgds,kptr,kgds,iret)
156C BSM IF(LGRIB.LE.200+17*JF/8.AND.KGDS(2)*KGDS(3).LE.JF) THEN
157C Change number of bits that can be handled to 25
158 IF(lgrib.LE.200+25*jf/8.AND.kgds(2)*kgds(3).LE.jf) THEN
159 CALL baread(lugb,lskip,lgrib,lread,grib)
160 IF(lread.EQ.lgrib) THEN
161 CALL w3fi63(grib,kpds,kgds,lb,f,kptr,iret)
162 IF(iret.EQ.0) THEN
163 k=kj
164 kf=kptr(10)
165 ENDIF
166 ELSE
167 iret=97
168 ENDIF
169 ELSE
170 iret=98
171 ENDIF
172 ENDIF
173 ENDDO
174 ELSE
175 iret=96
176 ENDIF
177C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
178 RETURN
179 END
subroutine gbyte(ipackd, iunpkd, noff, nbits)
This is the fortran version of gbyte.
Definition gbyte.f:27
subroutine getgb1(lugb, lugi, jf, j, jpds, jgds, grib, kf, k, kpds, kgds, lb, f, iret)
Find and unpack a grib message.
Definition getgb1.f:53
subroutine w3fi63(msga, kpds, kgds, kbms, data, kptr, kret)
Unpack a GRIB (edition 1) field to the exact grid specified in the GRIB message, isolate the bit map,...
Definition w3fi63.f:243
subroutine fi632(msga, kptr, kpds, kret)
Gather info from product definition sec.
Definition w3fi63.f:635
subroutine fi633(msga, kptr, kgds, kret)
Extract info from grib-gds.
Definition w3fi63.f:981