NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
skgb.f
Go to the documentation of this file.
1C> @file
2C> @brief Search for next grib message.
3C> @author Mark Iredell @date 1993-11-22
4
5C> This subprogram searches a file for the next grib 1 message.
6C> A grib 1 message is identified by its indicator section, i.e.
7C> an 8-byte sequence with 'grib' in bytes 1-4 and 1 in byte 8.
8C> If found, the length of the message is decoded from bytes 5-7.
9C> The search is done over a given section of the file.
10C> The search is terminated if an eof or i/o error is encountered.
11C>
12C> Program history log:
13C> - Mark Iredell 1993-11-22
14C> - Mark Iredell 1995-10-31 Add call to baread.
15C> - Mark Iredell 1997-03-14 Check for '7777'.
16C> - Stephen Gilbert 2001-12-05 Modified to also look for grib2 messages.
17C>
18C> @param[in] LUGB Integer logical unit of input grib file.
19C> @param[in] ISEEK Integer number of bytes to skip before search.
20C> @param[in] MSEEK Integer maximum number of bytes to search.
21C> @param[out] LSKIP Integer number of bytes to skip before message.
22C> @param[out] LGRIB Integer number of bytes in message (0 if not found).
23C>
24C> @author Mark Iredell @date 1993-11-22
25C-----------------------------------------------------------------------
26 SUBROUTINE skgb(LUGB,ISEEK,MSEEK,LSKIP,LGRIB)
27 parameter(lseek=128)
28 CHARACTER Z(LSEEK)
29 CHARACTER Z4(4)
30C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 lgrib=0
32 ks=iseek
33 kn=min(lseek,mseek)
34 kz=lseek
35C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36C LOOP UNTIL GRIB MESSAGE IS FOUND
37 dowhile(lgrib.EQ.0.AND.kn.GE.8.AND.kz.EQ.lseek)
38C READ PARTIAL SECTION
39 CALL baread(lugb,ks,kn,kz,z)
40 km=kz-8+1
41 k=0
42C LOOK FOR 'GRIB...1' IN PARTIAL SECTION
43 dowhile(lgrib.EQ.0.AND.k.LT.km)
44 CALL gbytec(z,i4,(k+0)*8,4*8)
45 CALL gbytec(z,i1,(k+7)*8,1*8)
46 IF(i4.EQ.1196575042.AND.(i1.EQ.1.OR.i1.EQ.2)) THEN
47C LOOK FOR '7777' AT END OF GRIB MESSAGE
48 IF (i1.EQ.1) CALL gbytec(z,kg,(k+4)*8,3*8)
49 IF (i1.EQ.2) CALL gbytec(z,kg,(k+12)*8,4*8)
50 CALL baread(lugb,ks+k+kg-4,4,k4,z4)
51 IF(k4.EQ.4) THEN
52 CALL gbytec(z4,i4,0,4*8)
53 IF(i4.EQ.926365495) THEN
54C GRIB MESSAGE FOUND
55 lskip=ks+k
56 lgrib=kg
57 ENDIF
58 ENDIF
59 ENDIF
60 k=k+1
61 ENDDO
62 ks=ks+km
63 kn=min(lseek,iseek+mseek-ks)
64 ENDDO
65C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66 RETURN
67 END
subroutine gbytec(in, iout, iskip, nbyte)
Wrapper for gbytesc() limiting NSKIP and N to 0 and 1.
Definition gbytec.f:14
subroutine skgb(lugb, iseek, mseek, lskip, lgrib)
This subprogram searches a file for the next grib 1 message.
Definition skgb.f:27