NCEPLIBS-w3emc  2.11.0
getgir.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read a grib index file and return its index contents.
3 C> @author Mark Iredell @date 1995-10-31
4 
5 C> Read a grib file and return its index contents.
6 C> The index buffer returned contains index records with the internal format:
7 C> - byte 001-004: bytes to skip in data file before grib message.
8 C> - byte 005-008: bytes to skip in message before pds.
9 C> - byte 009-012: bytes to skip in message before gds (0 if no gds).
10 C> - byte 013-016: bytes to skip in message before bms (0 if no bms).
11 C> - byte 017-020: bytes to skip in message before bds.
12 C> - byte 021-024: bytes total in the message.
13 C> - byte 025-025: grib version number.
14 C> - byte 026-053: product definition section (pds).
15 C> - byte 054-095: grid definition section (gds) (or nulls).
16 C> - byte 096-101: first part of the bit map section (bms) (or nulls).
17 C> - byte 102-112: first part of the binary data section (bds).
18 C> - byte 113-172: (optional) bytes 41-100 of the pds.
19 C> - byte 173-184: (optional) bytes 29-40 of the pds.
20 C> - byte 185-320: (optional) bytes 43-178 of the gds.
21 C>
22 C> Program history log:
23 C> - Mark Iredell 1995-10-31
24 C> - Mark Iredell 1996-10-31 Augmented optional definitions to byte 320.
25 C>
26 C> @param[in] lugb integer unit of the unblocked grib file.
27 C> @param[in] msk1 integer number of bytes to search for first message.
28 C> @param[in] msk2 integer number of bytes to search for other messages.
29 C> @param[in] mnum integer number of index records to skip (usually 0).
30 C> @param[in] mbuf integer length of cbuf in bytes.
31 C> @param[out] cbuf character*1 (mbuf) buffer to receive index data.
32 C> @param[out] nlen integer length of each index record in bytes.
33 C> @param[out] nnum integer number of index records
34 C> (=0 if no grib messages are found).
35 C> @param[out] iret integer return code.
36 C> - 0: all ok.
37 C> - 1: cbuf too small to hold index data.
38 C>
39 C> @note Subprogram can be called from a multiprocessing environment.
40 C> Do not engage the same logical unit from more than one processor.
41 C>
42 C> @author Mark Iredell @date 1995-10-31
43 C-----------------------------------------------------------------------
44  SUBROUTINE getgir(LUGB,MSK1,MSK2,MNUM,MBUF,CBUF,NLEN,NNUM,IRET)
45  CHARACTER CBUF(MBUF)
46  parameter(mindex=320)
47 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 C SEARCH FOR FIRST GRIB MESSAGE
49  iseek=0
50  CALL skgb(lugb,iseek,msk1,lskip,lgrib)
51  IF(lgrib.GT.0.AND.mindex.LE.mbuf) THEN
52  CALL ixgb(lugb,lskip,lgrib,mindex,1,nlen,cbuf)
53  ELSE
54  nlen=mindex
55  ENDIF
56  DO m=1,mnum
57  IF(lgrib.GT.0) THEN
58  iseek=lskip+lgrib
59  CALL skgb(lugb,iseek,msk2,lskip,lgrib)
60  ENDIF
61  ENDDO
62 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 C MAKE AN INDEX RECORD FOR EVERY GRIB RECORD FOUND
64  nnum=0
65  iret=0
66  dowhile(iret.EQ.0.AND.lgrib.GT.0)
67  IF(nlen*(nnum+1).LE.mbuf) THEN
68  nnum=nnum+1
69  CALL ixgb(lugb,lskip,lgrib,nlen,nnum,mlen,cbuf)
70  iseek=lskip+lgrib
71  CALL skgb(lugb,iseek,msk2,lskip,lgrib)
72  ELSE
73  iret=1
74  ENDIF
75  ENDDO
76 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77  RETURN
78  END
subroutine getgir(LUGB, MSK1, MSK2, MNUM, MBUF, CBUF, NLEN, NNUM, IRET)
Read a grib file and return its index contents.
Definition: getgir.f:45
subroutine ixgb(LUGB, LSKIP, LGRIB, NLEN, NNUM, MLEN, CBUF)
Byte 001-004: Bytes to skip in data file before grib message.
Definition: ixgb.f:36
subroutine skgb(LUGB, ISEEK, MSEEK, LSKIP, LGRIB)
This subprogram searches a file for the next grib 1 message.
Definition: skgb.f:27