source: trunk/WRF.COMMON/WRFV3/external/io_grib2/g2lib/getidx.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: 5.2 KB
Line 
1C-----------------------------------------------------------------------
2      SUBROUTINE GETIDX(LUGB,LUGI,CINDEX,NLEN,NNUM,IRET)
3C$$$  SUBPROGRAM DOCUMENTATION BLOCK
4C
5C SUBPROGRAM: GETIDX         FINDS, READS OR GENERATES A GRIB2 INDEX
6C   PRGMMR: GILBERT          ORG: W/NP11     DATE: 2005-03-15
7C
8C ABSTRACT: FINDS, READS OR GENERATES A GRIB2 INDEX FOR THE GRIB2 FILE
9C  ASSOCIATED WITH UNIT LUGB.  IF THE INDEX ALREADY EXISTS, IT IS RETURNED.
10C  OTHERWISE, THE INDEX IS (1) READ FROM AN EXISTING INDEXFILE ASSOCIATED WITH
11C  UNIT LUGI. OR (2) GENERATED FROM THE GRIB2FILE LUGB ( IF LUGI=0 ).
12C  USERS CAN FORCE A REGENERATION OF AN INDEX.  IF LUGI EQUALS LUGB, THE INDEX
13C  WILL BE REGENERATED FROM THE DATA IN FILE LUGB.  IF LUGI IS LESS THAN
14C  ZERO, THEN THE INDEX IS RE READ FROM INDEX FILE ABS(LUGI). 
15C
16C PROGRAM HISTORY LOG:
17C 2005-03-15  GILBERT
18C
19C USAGE:    CALL GETIDX(LUGB,LUGI,CINDEX,NLEN,NNUM,IRET)
20C
21C   INPUT ARGUMENTS:
22C     LUGB         INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE.
23C                  FILE MUST BE OPENED WITH BAOPEN OR BAOPENR BEFORE CALLING
24C                  THIS ROUTINE.
25C     LUGI         INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE.
26C                  IF NONZERO, FILE MUST BE OPENED WITH BAOPEN BAOPENR BEFORE
27C                  CALLING THIS ROUTINE.
28C                  >0 - READ INDEX FROM INDEX FILE LUGI, IF INDEX DOESN"T
29C                       ALREADY EXIST.
30C                  =0 - TO GET INDEX BUFFER FROM THE GRIB FILE, IF INDEX
31C                       DOESN"T ALREADY EXIST.
32C                  <0 - FORCE REREAD OF INDEX FROM INDEX FILE ABS(LUGI).
33C                  =LUGB - FORCE REGENERATION OF INDEX FROM GRIB2 FILE LUGB.
34C
35C   OUTPUT ARGUMENTS:
36C     CINDEX       CHARACTER*1 POINTER TO A BUFFER THAT CONTAINS INDEX RECORDS.
37C     NLEN         INTEGER TOTAL LENGTH OF ALL INDEX RECORDS
38C     NNUM         INTEGER NUMBER OF INDEX RECORDS
39C     IRET         INTEGER RETURN CODE
40C                    0      ALL OK
41C                    90     UNIT NUMBER OUT OF RANGE
42C                    96     ERROR READING/CREATING INDEX FILE
43C
44C SUBPROGRAMS CALLED:
45C   GETG2I          READ INDEX FILE
46C   GETG2IR         READ INDEX BUFFER FROM GRIB FILE
47C
48C REMARKS:
49C
50C
51C ATTRIBUTES:
52C   LANGUAGE: FORTRAN 90
53C
54C$$$
55
56      INTEGER,INTENT(IN) :: LUGB,LUGI
57      INTEGER,INTENT(OUT) :: NLEN,NNUM,IRET
58      CHARACTER(LEN=1),POINTER,DIMENSION(:) :: CINDEX
59
60      INTEGER,PARAMETER :: MAXIDX=100
61      INTEGER,PARAMETER :: MSK1=32000,MSK2=4000
62 
63      TYPE GINDEX
64         integer :: nlen
65         integer :: nnum
66         character(len=1),pointer,dimension(:) :: cbuf
67      END TYPE GINDEX
68     
69      TYPE(GINDEX),SAVE :: IDXLIST(100)
70
71      DATA LUX/0/
72C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73C  DECLARE INTERFACES (REQUIRED FOR CBUF POINTER)
74      INTERFACE
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
79         END SUBROUTINE GETG2I
80         SUBROUTINE GETG2IR(LUGB,MSK1,MSK2,MNUM,CBUF,NLEN,NNUM,
81     &                      NMESS,IRET)
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
86      END INTERFACE
87
88C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89C  DETERMINE WHETHER INDEX BUFFER NEEDS TO BE INITIALIZED
90      LUX=0
91      IRET=0
92      IF ( LUGB.LE.0 .AND. LUGB.GT.100 ) THEN
93         IRET=90
94         RETURN
95      ENDIF
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)
100         IDXLIST(LUGB)%NLEN=0
101         IDXLIST(LUGB)%NNUM=0
102         LUX=0
103      ENDIF
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)
109         IDXLIST(LUGB)%NLEN=0
110         IDXLIST(LUGB)%NNUM=0
111         LUX=ABS(LUGI)
112      ENDIF
113C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114C  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
119         RETURN
120      ENDIF
121C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
122      IRGI=0
123      IF(LUX.GT.0) THEN
124        CALL GETG2I(LUX,IDXLIST(LUGB)%CBUF,NLEN,NNUM,IRGI)
125      ELSEIF(LUX.LE.0) THEN
126        MSKP=0
127        CALL GETG2IR(LUGB,MSK1,MSK2,MSKP,IDXLIST(LUGB)%CBUF,
128     &               NLEN,NNUM,NMESS,IRGI)
129      ENDIF
130      IF(IRGI.EQ.0) THEN
131         CINDEX => IDXLIST(LUGB)%CBUF
132         IDXLIST(LUGB)%NLEN = NLEN
133         IDXLIST(LUGB)%NNUM = NNUM
134      ELSE
135         NLEN = 0
136         NNUM = 0
137         IRET=96
138         RETURN
139      ENDIF
140C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
142      RETURN
143      END
Note: See TracBrowser for help on using the repository browser.