NCEPLIBS-g2  3.4.5
skgb.f
Go to the documentation of this file.
1 C> @file
2 C> @brief This subroutine generates an index record for each field in
3 C> a grib2 message.
4 C> @author Mark Iredell @date 1995-10-31
5 C>
6 
7 C> This subroutine searches a file for the next grib 1 message. A grib
8 C> 1 message is identified by its indicator section, i.e. an 8-byte
9 C> sequence with 'grib' in bytes 1-4 and 1 in byte 8. If found, the
10 C> length of the message is decoded from bytes 5-7. The search is
11 C> done over a given section of the file. The search is terminated if
12 C> an eof or i/o error is encountered.
13 C> PROGRAM HISTORY LOG:
14 C> - 1993-11-22 Mark Iredell
15 C> - 1995-10-31 Mark Iredell add call to baread.
16 C> - 1997-03-14 Mark Iredell check for '7777'.
17 C> - 2001-12-05 Stephen Gilbert modified to also look for grib2
18 C> messages.
19 C> - 2009-12-14 Boi Vuong modified to increase length of seek (512).
20 C>
21 C> @param[in] LUGB integer unit of the unblocked grib file.
22 C> @param[in] ISEEK integer number of bytes to skip before search.
23 C> @param[in] MSEEK integer maximum number of bytes to search.
24 C> @param[out] LSKIP integer number of bytes to skip before message.
25 C> @param[out] LGRIB integer number of bytes in message (0 if not
26 C> found)
27 C>
28 C> @author Mark Iredell @date 1995-10-31
29 C>
30 
31 C-----------------------------------------------------------------------
32  SUBROUTINE skgb(LUGB,ISEEK,MSEEK,LSKIP,LGRIB)
33 
34  parameter(lseek=512)
35  CHARACTER Z(LSEEK)
36  CHARACTER Z4(4)
37 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38  lgrib=0
39  ks=iseek
40  kn=min(lseek,mseek)
41  kz=lseek
42 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 C LOOP UNTIL GRIB MESSAGE IS FOUND
44  dowhile(lgrib.EQ.0.AND.kn.GE.8.AND.kz.EQ.lseek)
45 C READ PARTIAL SECTION
46  CALL baread(lugb,ks,kn,kz,z)
47  km=kz-8+1
48  k=0
49 C LOOK FOR 'GRIB...1' IN PARTIAL SECTION
50  dowhile(lgrib.EQ.0.AND.k.LT.km)
51  CALL g2_gbytec(z,i4,(k+0)*8,4*8)
52  CALL g2_gbytec(z,i1,(k+7)*8,1*8)
53  IF(i4.EQ.1196575042.AND.(i1.EQ.1.OR.i1.EQ.2)) THEN
54 C LOOK FOR '7777' AT END OF GRIB MESSAGE
55  IF (i1.EQ.1) CALL g2_gbytec(z,kg,(k+4)*8,3*8)
56  IF (i1.EQ.2) CALL g2_gbytec(z,kg,(k+12)*8,4*8)
57  CALL baread(lugb,ks+k+kg-4,4,k4,z4)
58  IF(k4.EQ.4) THEN
59  CALL g2_gbytec(z4,i4,0,4*8)
60  IF(i4.EQ.926365495) THEN
61 C GRIB MESSAGE FOUND
62  lskip=ks+k
63  lgrib=kg
64  ENDIF
65  ENDIF
66  ENDIF
67  k=k+1
68  ENDDO
69  ks=ks+km
70  kn=min(lseek,iseek+mseek-ks)
71  ENDDO
72 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73  RETURN
74  END
skgb
subroutine skgb(LUGB, ISEEK, MSEEK, LSKIP, LGRIB)
This subroutine searches a file for the next grib 1 message.
Definition: skgb.f:33
g2_gbytec
subroutine g2_gbytec(IN, IOUT, ISKIP, NBYTE)
This subrountine is to extract arbitrary size values from a packed bit string, right justifying each ...
Definition: g2_gbytesc.f:20