NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
getgb1s.f
Go to the documentation of this file.
1C> @file
2C> @brief Find a grib message.
3C> @author Mark Iredell @date 1995-10-31
4
5C> Find a grib message.
6C> Find in the index file a reference to the grib message requested.
7C> The grib message request specifies the number of messages to skip
8c> and the unpacked pds and gds parameters. (A requested parameter
9c> of -1 means to allow any value of this parameter to be found.)
10C>
11C> Program history log:
12C> - Mark Iredell 1995-10-31
13C> - Mark Iredell 2001-06-05 Apply linux port by ebisuzaki.
14C>
15C> @param[in] CBUF Character*1 (nlen*nnum) buffer containing index data.
16C> @param[in] NLEN Integer length of each index record in bytes.
17C> @param[in] NNUM Integer number of index records.
18C> @param[in] J Integer number of messages to skip
19c> (=0 to search from beginning).
20C> @param[in] JPDS Integer (200) pds parameters for which to search
21c> (=-1 for wildcard).
22C> @param[in] JGDS Integer (200) gds parameters for which to search
23c> (only searched if jpds(3)=255) (=-1 for wildcard).
24C> @param[in] JENS Integer (200) ensemble pds parms for which to search
25c> (only searched if jpds(23)=2) (=-1 for wildcard).
26C> @param[out] K Integer message number found
27c> (can be same as j in calling program in order to facilitate multiple searches).
28C> @param[out] KPDS Integer (200) unpacked pds parameters.
29C> @param[out] KGDS Integer (200) unpacked gds parameters.
30C> @param[out] KENS Integer (200) unpacked ensemble pds parms.
31C> @param[out] LSKIP Integer number of bytes to skip.
32C> @param[out] LGRIB Integer number of bytes to read.
33C> @param[out] IRET Integer return code.
34C> - 0 All ok.
35C> - 1 Request not found.
36C>
37C> @note Subprogram can be called from a multiprocessing environment.
38C> This subprogram is intended for private use by getgb routines only.
39C>
40C> @author Mark Iredell @date 1995-10-31
41C-----------------------------------------------------------------------
42 SUBROUTINE getgb1s(CBUF,NLEN,NNUM,J,JPDS,JGDS,JENS,
43 & K,KPDS,KGDS,KENS,LSKIP,LGRIB,IRET)
44 CHARACTER CBUF(NLEN*NNUM)
45 INTEGER JPDS(200),JGDS(200),JENS(200)
46 INTEGER KPDS(200),KGDS(200),KENS(200)
47 parameter(lpds=23,lgds=22,lens=5) ! ACTUAL SEARCH RANGES
48 CHARACTER CPDS(400)*1,CGDS(400)*1
49 INTEGER KPTR(200)
50 INTEGER IPDSP(LPDS),JPDSP(LPDS)
51 INTEGER IGDSP(LGDS),JGDSP(LGDS)
52 INTEGER IENSP(LENS),JENSP(LENS)
53C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54C COMPRESS REQUEST LISTS
55 k=j
56 lskip=0
57 lgrib=0
58 iret=1
59C COMPRESS PDS REQUEST
60 lpdsp=0
61 DO i=1,lpds
62 IF(jpds(i).NE.-1) THEN
63 lpdsp=lpdsp+1
64 ipdsp(lpdsp)=i
65 jpdsp(lpdsp)=jpds(i)
66 ENDIF
67 ENDDO
68C COMPRESS GDS REQUEST
69 lgdsp=0
70 IF(jpds(3).EQ.255) THEN
71 DO i=1,lgds
72 IF(jgds(i).NE.-1) THEN
73 lgdsp=lgdsp+1
74 igdsp(lgdsp)=i
75 jgdsp(lgdsp)=jgds(i)
76 ENDIF
77 ENDDO
78 ENDIF
79C COMPRESS ENS REQUEST
80 lensp=0
81 IF(jpds(23).EQ.2) THEN
82 DO i=1,lens
83 IF(jens(i).NE.-1) THEN
84 lensp=lensp+1
85 iensp(lensp)=i
86 jensp(lensp)=jens(i)
87 ENDIF
88 ENDDO
89 ENDIF
90C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91C SEARCH FOR REQUEST
92 dowhile(iret.NE.0.AND.k.LT.nnum)
93 k=k+1
94 lt=0
95C SEARCH FOR PDS REQUEST
96 IF(lpdsp.GT.0) THEN
97 cpds=char(0)
98 cpds(1:28)=cbuf((k-1)*nlen+26:(k-1)*nlen+53)
99 nless=max(184-nlen,0)
100 cpds(29:40-nless)=cbuf((k-1)*nlen+173:(k-1)*nlen+184-nless)
101 kptr=0
102 CALL gbytec(cbuf,kptr(3),(k-1)*nlen*8+25*8,3*8)
103 kpds(18)=1
104 CALL gbytec(cpds,kpds(4),7*8,8)
105 CALL fi632(cpds,kptr,kpds,kret)
106 DO i=1,lpdsp
107 ip=ipdsp(i)
108 lt=lt+abs(jpds(ip)-kpds(ip))
109 ENDDO
110 ENDIF
111C SEARCH FOR GDS REQUEST
112 IF(lt.EQ.0.AND.lgdsp.GT.0) THEN
113 cgds=char(0)
114 cgds(1:42)=cbuf((k-1)*nlen+54:(k-1)*nlen+95)
115 nless=max(320-nlen,0)
116 cgds(43:178-nless)=cbuf((k-1)*nlen+185:(k-1)*nlen+320-nless)
117 kptr=0
118 CALL fi633(cgds,kptr,kgds,kret)
119 DO i=1,lgdsp
120 ip=igdsp(i)
121 lt=lt+abs(jgds(ip)-kgds(ip))
122 ENDDO
123 ENDIF
124C SEARCH FOR ENS REQUEST
125 IF(lt.EQ.0.AND.lensp.GT.0) THEN
126 nless=max(172-nlen,0)
127 cpds(41:100-nless)=cbuf((k-1)*nlen+113:(k-1)*nlen+172-nless)
128 CALL pdseup(kens,kprob,xprob,kclust,kmembr,45,cpds)
129 DO i=1,lensp
130 ip=iensp(i)
131 lt=lt+abs(jens(ip)-kens(ip))
132 ENDDO
133 ENDIF
134C RETURN IF REQUEST IS FOUND
135 IF(lt.EQ.0) THEN
136 CALL gbytec(cbuf,lskip,(k-1)*nlen*8,4*8)
137 CALL gbytec(cbuf,lgrib,(k-1)*nlen*8+20*8,4*8)
138 IF(lpdsp.EQ.0) THEN
139 cpds=char(0)
140 cpds(1:28)=cbuf((k-1)*nlen+26:(k-1)*nlen+53)
141 nless=max(184-nlen,0)
142 cpds(29:40-nless)=cbuf((k-1)*nlen+173:(k-1)*nlen+184-nless)
143 kptr=0
144 CALL gbytec(cbuf,kptr(3),(k-1)*nlen*8+25*8,3*8)
145 kpds(18)=1
146 CALL gbytec(cpds,kpds(4),7*8,8)
147 CALL fi632(cpds,kptr,kpds,kret)
148 ENDIF
149 IF(lgdsp.EQ.0) THEN
150 cgds=char(0)
151 cgds(1:42)=cbuf((k-1)*nlen+54:(k-1)*nlen+95)
152 nless=max(320-nlen,0)
153 cgds(43:178-nless)=cbuf((k-1)*nlen+185:(k-1)*nlen+320-nless)
154 kptr=0
155 CALL fi633(cgds,kptr,kgds,kret)
156 ENDIF
157 IF(kpds(23).EQ.2.AND.lensp.EQ.0) THEN
158 nless=max(172-nlen,0)
159 cpds(41:100-nless)=cbuf((k-1)*nlen+113:(k-1)*nlen+172-nless)
160 CALL pdseup(kens,kprob,xprob,kclust,kmembr,45,cpds)
161 ENDIF
162 iret=0
163 ENDIF
164 ENDDO
165C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
166 RETURN
167 END
subroutine gbytec(in, iout, iskip, nbyte)
Wrapper for gbytesc() limiting NSKIP and N to 0 and 1.
Definition gbytec.f:14
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 pdseup(kens, kprob, xprob, kclust, kmembr, ilast, msga)
Unpacks grib pds extension starting on byte 41 for ensemble forecast products.
Definition pdseup.f:28
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