NCEPLIBS-w3emc  2.11.0
getgi.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read a grib index file and return its contents.
3 C> @author Mark Iredell @date 1995-10-31
4 
5 C> Read a grib index file and return its contents.
6 C> Version 1 of the index file has the following format:
7 C> 81-byte s.lord header with 'gb1ix1' in columns 42-47 followed by
8 C> 81-byte header with number of bytes to skip before index records,
9 C> number of bytes in each index record, number of index records,
10 C> and grib file basename written in format ('ix1form:',3i10,2x,a40).
11 C> Each following index record corresponds to a grib message
12 C> and has the internal format:
13 C> - byte 001-004: bytes to skip in data file before grib message.
14 C> - byte 005-008: bytes to skip in message before pds.
15 C> - byte 009-012: bytes to skip in message before gds (0 if no gds).
16 C> - byte 013-016: bytes to skip in message before bms (0 if no bms).
17 C> - byte 017-020: bytes to skip in message before bds.
18 C> - byte 021-024: bytes total in the message.
19 C> - byte 025-025: grib version number.
20 C> - byte 026-053: product definition section (pds).
21 C> - byte 054-095: grid definition section (gds) (or nulls).
22 C> - byte 096-101: first part of the bit map section (bms) (or nulls).
23 C> - byte 102-112: first part of the binary data section (bds).
24 C> - byte 113-172: (optional) bytes 41-100 of the pds.
25 C> - byte 173-184: (optional) bytes 29-40 of the pds.
26 C> - byte 185-320: (optional) bytes 43-178 of the gds.
27 C>
28 C> Program history log:
29 C> - Mark Iredell 1995-10-31
30 C> - Mark Iredell 1996-10-31 Augmented optional definitions to byte 320.
31 C>
32 C> @param[in] lugi integer unit of the unblocked grib index file.
33 C> @param[in] mnum integer number of index records to skip (usually 0).
34 C> @param[in] mbuf integer length of cbuf in bytes.
35 C> @param[out] cbuf character*1 (mbuf) buffer to receive index data.
36 C> @param[out] nlen integer length of each index record in bytes.
37 C> @param[out] nnum integer number of index records.
38 C> @param[out] iret integer return code.
39 C> - 0: all ok.
40 C> - 1: cbuf too small to hold index buffer.
41 C> - 2: error reading index file buffer.
42 C> - 3: error reading index file header.
43 C>
44 C> @note Subprogram can be called from a multiprocessing environment.
45 C> Do not engage the same logical unit from more than one processor.
46 C>
47 C> @author Mark Iredell @date 1995-10-31
48 C-----------------------------------------------------------------------
49  SUBROUTINE getgi(LUGI,MNUM,MBUF,CBUF,NLEN,NNUM,IRET)
50  CHARACTER CBUF(MBUF)
51  CHARACTER CHEAD*162
52 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53  nlen=0
54  nnum=0
55  iret=3
56  CALL baread(lugi,0,162,lhead,chead)
57  IF(lhead.EQ.162.AND.chead(42:47).EQ.'GB1IX1') THEN
58  READ(chead(82:162),'(8X,3I10,2X,A40)',iostat=ios) nskp,nlen,nnum
59  IF(ios.EQ.0) THEN
60  nskp=nskp+mnum*nlen
61  nnum=nnum-mnum
62  nbuf=nnum*nlen
63  iret=0
64  IF(nbuf.GT.mbuf) THEN
65  nnum=mbuf/nlen
66  nbuf=nnum*nlen
67  iret=1
68  ENDIF
69  IF(nbuf.GT.0) THEN
70  CALL baread(lugi,nskp,nbuf,lbuf,cbuf)
71  IF(lbuf.NE.nbuf) iret=2
72  ENDIF
73  ENDIF
74  ENDIF
75 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76  RETURN
77  END
subroutine getgi(LUGI, MNUM, MBUF, CBUF, NLEN, NNUM, IRET)
Read a grib index file and return its contents.
Definition: getgi.f:50