NCEPLIBS-w3emc  2.11.0
getgb1s.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Find a grib message.
3 C> @author Mark Iredell @date 1995-10-31
4 
5 C> Find a grib message.
6 C> Find in the index file a reference to the grib message requested.
7 C> The grib message request specifies the number of messages to skip
8 c> and the unpacked pds and gds parameters. (A requested parameter
9 c> of -1 means to allow any value of this parameter to be found.)
10 C>
11 C> Program history log:
12 C> - Mark Iredell 1995-10-31
13 C> - Mark Iredell 2001-06-05 Apply linux port by ebisuzaki.
14 C>
15 C> @param[in] CBUF Character*1 (nlen*nnum) buffer containing index data.
16 C> @param[in] NLEN Integer length of each index record in bytes.
17 C> @param[in] NNUM Integer number of index records.
18 C> @param[in] J Integer number of messages to skip
19 c> (=0 to search from beginning).
20 C> @param[in] JPDS Integer (200) pds parameters for which to search
21 c> (=-1 for wildcard).
22 C> @param[in] JGDS Integer (200) gds parameters for which to search
23 c> (only searched if jpds(3)=255) (=-1 for wildcard).
24 C> @param[in] JENS Integer (200) ensemble pds parms for which to search
25 c> (only searched if jpds(23)=2) (=-1 for wildcard).
26 C> @param[out] K Integer message number found
27 c> (can be same as j in calling program in order to facilitate multiple searches).
28 C> @param[out] KPDS Integer (200) unpacked pds parameters.
29 C> @param[out] KGDS Integer (200) unpacked gds parameters.
30 C> @param[out] KENS Integer (200) unpacked ensemble pds parms.
31 C> @param[out] LSKIP Integer number of bytes to skip.
32 C> @param[out] LGRIB Integer number of bytes to read.
33 C> @param[out] IRET Integer return code.
34 C> - 0 All ok.
35 C> - 1 Request not found.
36 C>
37 C> @note Subprogram can be called from a multiprocessing environment.
38 C> This subprogram is intended for private use by getgb routines only.
39 C>
40 C> @author Mark Iredell @date 1995-10-31
41 C-----------------------------------------------------------------------
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)
53 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54 C COMPRESS REQUEST LISTS
55  k=j
56  lskip=0
57  lgrib=0
58  iret=1
59 C 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
68 C 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
79 C 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
90 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91 C SEARCH FOR REQUEST
92  dowhile(iret.NE.0.AND.k.LT.nnum)
93  k=k+1
94  lt=0
95 C 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
111 C 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
124 C 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
134 C 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
165 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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