source: trunk/WRF.COMMON/WRFV3/external/io_grib2/g2lib/getgb2p.F @ 2759

Last change on this file since 2759 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: 9.7 KB
Line 
1C-----------------------------------------------------------------------
2      SUBROUTINE GETGB2P(LUGB,LUGI,J,JDISC,JIDS,JPDTN,JPDT,JGDTN,JGDT,
3     &                   EXTRACT,K,GRIBM,LENG,IRET)
4C$$$  SUBPROGRAM DOCUMENTATION BLOCK
5C
6C SUBPROGRAM: GETGB2P        FINDS AND EXTRACTS A GRIB MESSAGE
7C   PRGMMR: IREDELL          ORG: W/NMC23     DATE: 94-04-01
8C
9C ABSTRACT: FIND AND EXTRACTS A GRIB MESSAGE FROM A FILE.
10C   READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
11C   TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
12C   FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB FIELD REQUESTED.
13C   THE GRIB FIELD REQUEST SPECIFIES THE NUMBER OF FIELDS TO SKIP
14C   AND THE UNPACKED IDENTIFICATION SECTION, GRID DEFINITION TEMPLATE AND
15C   PRODUCT DEFINTION SECTION PARAMETERS.  (A REQUESTED PARAMETER
16C   OF -9999 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
17C   IF THE REQUESTED GRIB FIELD IS FOUND, THEN IT IS READ FROM THE
18C   GRIB FILE AND RETURNED.
19C   IF THE GRIB FIELD IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
20C
21C PROGRAM HISTORY LOG:
22C   94-04-01  IREDELL
23C   95-10-31  IREDELL     MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
24C                         AND ALLOWED FOR UNSPECIFIED INDEX FILE
25C 2002-01-11  GILBERT     MODIFIED FROM GETGB AND GETGBM TO WORK WITH GRIB2
26C 2003-12-17  GILBERT     MODIFIED FROM GETGB2 TO RETURN PACKED GRIB2 MESSAGE.
27C
28C USAGE:    CALL GETGB2P(LUGB,LUGI,J,JDISC,JIDS,JPDTN,JPDT,JGDTN,JGDT,
29C    &                  EXTRACT,K,GRIBM,LENG,IRET)
30C   INPUT ARGUMENTS:
31C     LUGB         INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE.
32C                  FILE MUST BE OPENED WITH BAOPEN OR BAOPENR BEFORE CALLING
33C                  THIS ROUTINE.
34C     LUGI         INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE.
35C                  IF NONZERO, FILE MUST BE OPENED WITH BAOPEN BAOPENR BEFORE
36C                  CALLING THIS ROUTINE.
37C                  (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
38C     J            INTEGER NUMBER OF FIELDS TO SKIP
39C                  (=0 TO SEARCH FROM BEGINNING)
40C     JDISC        GRIB2 DISCIPLINE NUMBER OF REQUESTED FIELD
41C                  ( IF = -1, ACCEPT ANY DISCIPLINE)
42C                  ( SEE CODE TABLE 0.0 )
43C                  0 - Meteorological products
44C                  1 - Hydrological products
45C                  2 - Land surface products
46C                  3 - Space products
47C                  10 - Oceanographic products
48C     JIDS()       INTEGER ARRAY OF VALUES IN THE IDENTIFICATION SECTION
49C                  (=-9999 FOR WILDCARD)
50C            JIDS(1)   = IDENTIFICATION OF ORIGINATING CENTRE
51C                         ( SEE COMMON CODE TABLE C-1 )
52C            JIDS(2)   = IDENTIFICATION OF ORIGINATING SUB-CENTRE
53C            JIDS(3)   = GRIB MASTER TABLES VERSION NUMBER
54C                         ( SEE CODE TABLE 1.0 )
55C                       0 - Experimental
56C                       1 - Initial operational version number
57C            JIDS(4)   = GRIB LOCAL TABLES VERSION NUMBER
58C                         ( SEE CODE TABLE 1.1 )
59C                       0     - Local tables not used
60C                       1-254 - Number of local tables version used
61C            JIDS(5)   = SIGNIFICANCE OF REFERENCE TIME (CODE TABLE 1.2)
62C                       0 - Analysis
63C                       1 - Start of forecast
64C                       2 - Verifying time of forecast
65C                       3 - Observation time
66C            JIDS(6)   = YEAR ( 4 DIGITS )
67C            JIDS(7)   = MONTH
68C            JIDS(8)   = DAY
69C            JIDS(9)   = HOUR
70C            JIDS(10)  = MINUTE
71C            JIDS(11)  = SECOND
72C            JIDS(12)  = PRODUCTION STATUS OF PROCESSED DATA
73C                         ( SEE CODE TABLE 1.3 )
74C                       0 - Operational products
75C                       1 - Operational test products
76C                       2 - Research products
77C                       3 - Re-analysis products
78C            JIDS(13)  = TYPE OF PROCESSED DATA ( SEE CODE TABLE 1.4 )
79C                       0  - Analysis products
80C                       1  - Forecast products
81C                       2  - Analysis and forecast products
82C                       3  - Control forecast products
83C                       4  - Perturbed forecast products
84C                       5  - Control and perturbed forecast products
85C                       6  - Processed satellite observations
86C                       7  - Processed radar observations
87C     JPDTN        INTEGER PRODUCT DEFINITION TEMPLATE NUMBER (N)
88C                  ( IF = -1, DON'T BOTHER MATCHING PDT - ACCEPT ANY )
89C     JPDT()       INTEGER ARRAY OF VALUES DEFINING THE PRODUCT DEFINITION
90C                  TEMPLATE 4.N OF THE FIELD FOR WHICH TO SEARCH
91C                  (=-9999 FOR WILDCARD)
92C     JGDTN        INTEGER GRID DEFINITION TEMPLATE NUMBER (M)
93C                  ( IF = -1, DON'T BOTHER MATCHING GDT - ACCEPT ANY )
94C     JGDT()       INTEGER ARRAY OF VALUES DEFINING THE GRID DEFINITION
95C                  TEMPLATE 3.M OF THE FIELD FOR WHICH TO SEARCH
96C                  (=-9999 FOR WILDCARD)
97C     EXTRACT       LOGICAL VALUE INDICATING WHETHER TO RETURN A GRIB2
98C                   MESSAGE WITH JUST THE REQUESTED FIELD, OR THE ENTIRE
99C                   GRIB2 MESSAGE CONTAINING THE REQUESTED FIELD.
100C                  .TRUE. = RETURN GRIB2 MESSAGE CONTAINING ONLY THE REQUESTED
101C                           FIELD.
102C                  .FALSE. = RETURN ENTIRE GRIB2 MESSAGE CONTAINING THE
103C                            REQUESTED FIELD.
104C
105C   OUTPUT ARGUMENTS:
106C     K            INTEGER FIELD NUMBER RETURNED.
107C     GRIBM         RETURNED GRIB MESSAGE.
108C     LENG         LENGTH OF RETURNED GRIB MESSAGE IN BYTES.
109C     IRET         INTEGER RETURN CODE
110C                    0      ALL OK
111C                    96     ERROR READING INDEX FILE
112C                    97     ERROR READING GRIB FILE
113C                    99     REQUEST NOT FOUND
114C
115C SUBPROGRAMS CALLED:
116C   GETG2I          READ INDEX FILE
117C   GETG2IR         READ INDEX BUFFER FROM GRIB FILE
118C   GETGB2S        SEARCH INDEX RECORDS
119C   GETGB2RP        READ A PACKED GRIB RECORD
120C   GF_FREE        FREES MEMORY USED BY GFLD  ( SEE REMARKS )
121C
122C REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
123C   DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
124C
125C   Note that derived type gribfield contains pointers to many
126C   arrays of data.  The memory for these arrays is allocated
127C   when the values in the arrays are set, to help minimize
128C   problems with array overloading.  Because of this users
129C   are encouraged to free up this memory, when it is no longer
130C   needed, by an explicit call to subroutine gf_free.
131C   ( i.e.   CALL GF_FREE(GFLD) )
132C
133C ATTRIBUTES:
134C   LANGUAGE: FORTRAN 90
135C
136C$$$
137      USE GRIB_MOD
138
139      INTEGER,INTENT(IN) :: LUGB,LUGI,J,JDISC,JPDTN,JGDTN
140      INTEGER,DIMENSION(:) :: JIDS(*),JPDT(*),JGDT(*)
141      LOGICAL,INTENT(IN) :: EXTRACT
142      INTEGER,INTENT(OUT) :: K,IRET,LENG
143      CHARACTER(LEN=1),POINTER,DIMENSION(:) :: GRIBM
144
145      TYPE(GRIBFIELD) :: GFLD
146
147      CHARACTER(LEN=1),POINTER,DIMENSION(:) :: CBUF
148      PARAMETER(MSK1=32000,MSK2=4000)
149
150      SAVE CBUF,NLEN,NNUM
151      DATA LUX/0/
152C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153C  DECLARE INTERFACES (REQUIRED FOR CBUF POINTER)
154      INTERFACE
155         SUBROUTINE GETG2I(LUGI,CBUF,NLEN,NNUM,IRET)
156            CHARACTER(LEN=1),POINTER,DIMENSION(:) :: CBUF
157            INTEGER,INTENT(IN) :: LUGI
158            INTEGER,INTENT(OUT) :: NLEN,NNUM,IRET
159         END SUBROUTINE GETG2I
160         SUBROUTINE GETG2IR(LUGB,MSK1,MSK2,MNUM,CBUF,NLEN,NNUM,
161     &                      NMESS,IRET)
162            CHARACTER(LEN=1),POINTER,DIMENSION(:) :: CBUF
163            INTEGER,INTENT(IN) :: LUGB,MSK1,MSK2,MNUM
164            INTEGER,INTENT(OUT) :: NLEN,NNUM,NMESS,IRET
165         END SUBROUTINE GETG2IR
166         SUBROUTINE GETGB2RP(LUGB,CINDEX,EXTRACT,GRIBM,LENG,IRET)
167            INTEGER,INTENT(IN) :: LUGB
168            CHARACTER(LEN=1),INTENT(IN) :: CINDEX(*)
169            LOGICAL,INTENT(IN) :: EXTRACT
170            INTEGER,INTENT(OUT) :: LENG,IRET
171            CHARACTER(LEN=1),POINTER,DIMENSION(:) :: GRIBM
172         END SUBROUTINE GETGB2RP
173      END INTERFACE
174
175C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
176C  DETERMINE WHETHER INDEX BUFFER NEEDS TO BE INITIALIZED
177      IRGI=0
178      IF(LUGI.GT.0.AND.LUGI.NE.LUX) THEN
179        CALL GETG2I(LUGI,CBUF,NLEN,NNUM,IRGI)
180        LUX=LUGI
181      ELSEIF(LUGI.LE.0.AND.LUGB.NE.LUX) THEN
182        MSKP=0
183        CALL GETG2IR(LUGB,MSK1,MSK2,MSKP,CBUF,NLEN,NNUM,NMESS,IRGI)
184        LUX=LUGB
185      ENDIF
186      IF(IRGI.GT.1) THEN
187        IRET=96
188        LUX=0
189        RETURN
190      ENDIF
191C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
192C  SEARCH INDEX BUFFER
193      CALL GETGB2S(CBUF,NLEN,NNUM,J,-1,JDISC,JIDS,JPDTN,JPDT,JGDTN,JGDT,
194     &             JK,GFLD,LPOS,IRGS)
195      IF(IRGS.NE.0) THEN
196        IRET=99
197        CALL GF_FREE(GFLD)
198        RETURN
199      ENDIF
200C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201C  EXTRACT GRIB MESSAGE FROM FILE
202      CALL GETGB2RP(LUGB,CBUF(LPOS:),EXTRACT,GRIBM,LENG,IRET)
203!      IF ( EXTRACT ) THEN
204!         PRINT *,'NOT SUPPOSED TO BE HERE.'
205!      ELSE
206!         IPOS=(LPOS+3)*8
207!         CALL G2LIB_GBYTE(CBUF,ISKIP,IPOS,32)     ! BYTES TO SKIP IN FILE
208!         IPOS=IPOS+(32*8)
209!         CALL G2LIB_GBYTE(CBUF,LENG,IPOS,32)      ! LENGTH OF GRIB MESSAGE
210!         IF (.NOT. ASSOCIATED(GRIBM)) ALLOCATE(GRIBM(LENG))
211!         CALL BAREAD(LUGB,ISKIP,LENG,LREAD,GRIBM)
212!         IF ( LENG .NE. LREAD ) THEN
213!            IRET=97
214!            CALL GF_FREE(GFLD)
215!            RETURN
216!         ENDIF
217!      ENDIF
218C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219      K=JK
220      CALL GF_FREE(GFLD)
221C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
222      RETURN
223      END
Note: See TracBrowser for help on using the repository browser.