1 C-----------------------------------------------------------------------
2 SUBROUTINE GETIDX(LUGB,LUGI,CINDEX,NLEN,NNUM,IRET)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
5 C SUBPROGRAM: GETIDX FINDS, READS OR GENERATES A GRIB2 INDEX
6 C PRGMMR: GILBERT ORG: W/NP11 DATE: 2005-03-15
8 C ABSTRACT: FINDS, READS OR GENERATES A GRIB2 INDEX FOR THE GRIB2 FILE
9 C ASSOCIATED WITH UNIT LUGB. IF THE INDEX ALREADY EXISTS, IT IS RETURNED.
10 C OTHERWISE, THE INDEX IS (1) READ FROM AN EXISTING INDEXFILE ASSOCIATED WITH
11 C UNIT LUGI. OR (2) GENERATED FROM THE GRIB2FILE LUGB ( IF LUGI=0 ).
12 C USERS CAN FORCE A REGENERATION OF AN INDEX. IF LUGI EQUALS LUGB, THE INDEX
13 C WILL BE REGENERATED FROM THE DATA IN FILE LUGB. IF LUGI IS LESS THAN
14 C ZERO, THEN THE INDEX IS RE READ FROM INDEX FILE ABS(LUGI).
16 C PROGRAM HISTORY LOG:
19 C USAGE: CALL GETIDX(LUGB,LUGI,CINDEX,NLEN,NNUM,IRET)
22 C LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE.
23 C FILE MUST BE OPENED WITH BAOPEN OR BAOPENR BEFORE CALLING
25 C LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE.
26 C IF NONZERO, FILE MUST BE OPENED WITH BAOPEN BAOPENR BEFORE
27 C CALLING THIS ROUTINE.
28 C >0 - READ INDEX FROM INDEX FILE LUGI, IF INDEX DOESN"T
30 C =0 - TO GET INDEX BUFFER FROM THE GRIB FILE, IF INDEX
31 C DOESN"T ALREADY EXIST.
32 C <0 - FORCE REREAD OF INDEX FROM INDEX FILE ABS(LUGI).
33 C =LUGB - FORCE REGENERATION OF INDEX FROM GRIB2 FILE LUGB.
36 C CINDEX CHARACTER*1 POINTER TO A BUFFER THAT CONTAINS INDEX RECORDS.
37 C NLEN INTEGER TOTAL LENGTH OF ALL INDEX RECORDS
38 C NNUM INTEGER NUMBER OF INDEX RECORDS
39 C IRET INTEGER RETURN CODE
41 C 90 UNIT NUMBER OUT OF RANGE
42 C 96 ERROR READING/CREATING INDEX FILE
45 C GETG2I READ INDEX FILE
46 C GETG2IR READ INDEX BUFFER FROM GRIB FILE
52 C LANGUAGE: FORTRAN 90
56 INTEGER,INTENT(IN) :: LUGB,LUGI
57 INTEGER,INTENT(OUT) :: NLEN,NNUM,IRET
58 CHARACTER(LEN=1),POINTER,DIMENSION(:) :: CINDEX
60 INTEGER,PARAMETER :: MAXIDX=100
61 INTEGER,PARAMETER :: MSK1=32000,MSK2=4000
66 character(len=1),pointer,dimension(:) :: cbuf
69 TYPE(GINDEX),SAVE :: IDXLIST(100)
72 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73 C DECLARE INTERFACES (REQUIRED FOR CBUF POINTER)
75 SUBROUTINE GETG2I(LUGI,CBUF,NLEN,NNUM,IRET)
76 CHARACTER(LEN=1),POINTER,DIMENSION(:) :: CBUF
77 INTEGER,INTENT(IN) :: LUGI
78 INTEGER,INTENT(OUT) :: NLEN,NNUM,IRET
80 SUBROUTINE GETG2IR(LUGB,MSK1,MSK2,MNUM,CBUF,NLEN,NNUM,
82 CHARACTER(LEN=1),POINTER,DIMENSION(:) :: CBUF
83 INTEGER,INTENT(IN) :: LUGB,MSK1,MSK2,MNUM
84 INTEGER,INTENT(OUT) :: NLEN,NNUM,NMESS,IRET
85 END SUBROUTINE GETG2IR
88 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89 C DETERMINE WHETHER INDEX BUFFER NEEDS TO BE INITIALIZED
92 IF ( LUGB.LE.0 .AND. LUGB.GT.100 ) THEN
96 IF (LUGI.EQ.LUGB) THEN ! Force regeneration of index from GRIB2 File
97 IF ( ASSOCIATED( IDXLIST(LUGB)%CBUF ) )
98 & DEALLOCATE(IDXLIST(LUGB)%CBUF)
99 NULLIFY(IDXLIST(LUGB)%CBUF)
104 IF (LUGI.LT.0) THEN ! Force re-read of index from indexfile
105 ! associated with unit abs(lugi)
106 IF ( ASSOCIATED( IDXLIST(LUGB)%CBUF ) )
107 & DEALLOCATE(IDXLIST(LUGB)%CBUF)
108 NULLIFY(IDXLIST(LUGB)%CBUF)
113 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114 C Check if index already exists in memory
115 IF ( ASSOCIATED( IDXLIST(LUGB)%CBUF ) ) THEN
116 CINDEX => IDXLIST(LUGB)%CBUF
117 NLEN = IDXLIST(LUGB)%NLEN
118 NNUM = IDXLIST(LUGB)%NNUM
121 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124 CALL GETG2I(LUX,IDXLIST(LUGB)%CBUF,NLEN,NNUM,IRGI)
125 ELSEIF(LUX.LE.0) THEN
127 CALL GETG2IR(LUGB,MSK1,MSK2,MSKP,IDXLIST(LUGB)%CBUF,
128 & NLEN,NNUM,NMESS,IRGI)
131 CINDEX => IDXLIST(LUGB)%CBUF
132 IDXLIST(LUGB)%NLEN = NLEN
133 IDXLIST(LUGB)%NNUM = NNUM
140 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -