source: trunk/WRF.COMMON/WRFV3/external/io_grib2/g2lib/getg2i.F @ 3567

Last change on this file since 3567 was 2759, checked in by aslmd, 2 years ago

adding unmodified code from WRFV3.0.1.1, expurged from useless data +1M size

File size: 3.9 KB
Line 
1C-----------------------------------------------------------------------
2      SUBROUTINE GETG2I(LUGI,CBUF,NLEN,NNUM,IRET)
3C$$$  SUBPROGRAM DOCUMENTATION BLOCK
4C
5C SUBPROGRAM: GETG2I          READS A GRIB2 INDEX FILE
6C   PRGMMR: IREDELL          ORG: W/NMC23     DATE: 95-10-31
7C
8C ABSTRACT: READ A GRIB2 INDEX FILE AND RETURN ITS CONTENTS.
9C   VERSION 1 OF THE INDEX FILE HAS THE FOLLOWING FORMAT:
10C     81-BYTE S.LORD HEADER WITH 'GB2IX1' IN COLUMNS 42-47 FOLLOWED BY
11C     81-BYTE HEADER WITH NUMBER OF BYTES TO SKIP BEFORE INDEX RECORDS,
12C     TOTAL LENGTH IN BYTES OF THE INDEX RECORDS, NUMBER OF INDEX RECORDS,
13C     AND GRIB FILE BASENAME WRITTEN IN FORMAT ('IX1FORM:',3I10,2X,A40).
14C     EACH FOLLOWING INDEX RECORD CORRESPONDS TO A GRIB MESSAGE
15C     AND HAS THE INTERNAL FORMAT:
16C       BYTE 001 - 004: LENGTH OF INDEX RECORD
17C       BYTE 005 - 008: BYTES TO SKIP IN DATA FILE BEFORE GRIB MESSAGE
18C       BYTE 009 - 012: BYTES TO SKIP IN MESSAGE BEFORE LUS (LOCAL USE)
19C                       SET = 0, IF NO LOCAL USE SECTION IN GRIB2 MESSAGE.
20C       BYTE 013 - 016: BYTES TO SKIP IN MESSAGE BEFORE GDS
21C       BYTE 017 - 020: BYTES TO SKIP IN MESSAGE BEFORE PDS
22C       BYTE 021 - 024: BYTES TO SKIP IN MESSAGE BEFORE DRS
23C       BYTE 025 - 028: BYTES TO SKIP IN MESSAGE BEFORE BMS
24C       BYTE 029 - 032: BYTES TO SKIP IN MESSAGE BEFORE DATA SECTION
25C       BYTE 033 - 040: BYTES TOTAL IN THE MESSAGE
26C       BYTE 041 - 041: GRIB VERSION NUMBER ( CURRENTLY 2 )
27C       BYTE 042 - 042: MESSAGE DISCIPLINE
28C       BYTE 043 - 044: FIELD NUMBER WITHIN GRIB2 MESSAGE
29C       BYTE 045 -  II: IDENTIFICATION SECTION (IDS)
30C       BYTE II+1-  JJ: GRID DEFINITION SECTION (GDS)
31C       BYTE JJ+1-  KK: PRODUCT DEFINITION SECTION (PDS)
32C       BYTE KK+1-  LL: THE DATA REPRESENTATION SECTION (DRS)
33C       BYTE LL+1-LL+6: FIRST 6 BYTES OF THE BIT MAP SECTION (BMS)
34C
35C PROGRAM HISTORY LOG:
36C   95-10-31  IREDELL
37C   96-10-31  IREDELL   AUGMENTED OPTIONAL DEFINITIONS TO BYTE 320
38C 2002-01-03  GILBERT   MODIFIED FROM GETGI TO WORK WITH GRIB2
39C
40C USAGE:    CALL GETG2I(LUGI,CBUF,NLEN,NNUM,IRET)
41C   INPUT ARGUMENTS:
42C     LUGI         INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
43C   OUTPUT ARGUMENTS:
44C     CBUF         CHARACTER*1 POINTER TO A BUFFER THAT CONTAINS INDEX RECORDS.
45C                  USERS SHOULD FREE MEMORY THAT CBUF POINTS TO
46C                  USING DEALLOCATE(CBUF) WHEN CBUF IS NO LONGER NEEDED.
47C     NLEN         INTEGER TOTAL LENGTH OF ALL INDEX RECORDS
48C     NNUM         INTEGER NUMBER OF INDEX RECORDS
49C     IRET         INTEGER RETURN CODE
50C                    0      ALL OK
51C                    2      NOT ENOUGH MEMORY TO HOLD INDEX BUFFER
52C                    3      ERROR READING INDEX FILE BUFFER
53C                    4      ERROR READING INDEX FILE HEADER
54C
55C SUBPROGRAMS CALLED:
56C   BAREAD         BYTE-ADDRESSABLE READ
57C
58C REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
59C   DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
60C
61C ATTRIBUTES:
62C   LANGUAGE: FORTRAN 90
63C
64C$$$
65      CHARACTER(LEN=1),POINTER,DIMENSION(:) :: CBUF
66      INTEGER,INTENT(IN) :: LUGI
67      INTEGER,INTENT(OUT) :: NLEN,NNUM,IRET
68      CHARACTER CHEAD*162
69C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70      IF (ASSOCIATED(CBUF)) NULLIFY(CBUF)
71C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72      NLEN=0
73      NNUM=0
74      IRET=4
75      CALL BAREAD(LUGI,0,162,LHEAD,CHEAD)
76      IF(LHEAD.EQ.162.AND.CHEAD(42:47).EQ.'GB2IX1') THEN
77        READ(CHEAD(82:162),'(8X,3I10,2X,A40)',IOSTAT=IOS) NSKP,NLEN,NNUM
78        IF(IOS.EQ.0) THEN
79         
80          ALLOCATE(CBUF(NLEN),STAT=ISTAT)    ! ALLOCATE SPACE FOR CBUF
81          IF (ISTAT.NE.0) THEN
82             IRET=2
83             RETURN
84          ENDIF
85          IRET=0
86          CALL BAREAD(LUGI,NSKP,NLEN,LBUF,CBUF)
87          IF(LBUF.NE.NLEN) IRET=3
88
89        ENDIF
90      ENDIF
91C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92      RETURN
93      END
Note: See TracBrowser for help on using the repository browser.