NCEPLIBS-g2  3.4.5
getgb2l.f
Go to the documentation of this file.
1 C> @file
2 C> @brief This subroutine read and unpack a local use section from a
3 C> grib2 message.
4 C> @author Stephen Gilbert @date 2002-05-07
5 C>
6 
7 C> This subroutine read and unpack a local use section from a grib2
8 C> message. It decoded information for the selected grib field and
9 C> returned it in a derived type variable, gfld. gfld is of type
10 C> gribfield, which is defined in module grib_mod, so users of this
11 C> routine will need to include the line "use grib_mod" in their
12 C> calling routine. Each component of the gribfield type is described
13 C> in the output argument list section below.
14 C>
15 C> @param[in] LUGB integer unit of the unblocked grib data file.
16 C> @param[in] CINDEX index record of the grib field (see docblock of
17 C> subroutine ixgb2 for description of an index record.)
18 C> @param[out] GFLD derived type gribfield (defined in module grib_mod)
19 C> (NOTE: See Remarks Section)
20 C> - gfld\%version GRIB edition number (currently 2)
21 C> - gfld\%discipline Message Discipline (see Code Table 0.0)
22 C> - gfld\%idsect Contains the entries in the Identification Section
23 C> (Section 1) This element is actually a pointer to an array
24 C> that holds the data.
25 C> - gfld\%idsect(1) Identification of originating Centre
26 C> (see Common Code Table C-1) 7 US National Weather Service
27 C> - gfld\%idsect(2) Identification of originating Sub-centre
28 C> - gfld\%idsect(3) GRIB Master Tables Version Number
29 C> (see Code Table 1.0) 0 Experimental; 1 Initial operational version number
30 C> - gfld\%idsect(4) GRIB Local Tables Version Number (see Code Table 1.1)
31 C> 0 Local tables not used; 1-254 Number of local tables version used
32 C> - gfld\%idsect(5) Significance of Reference Time (Code Table 1.2)
33 C> 0 Analysis; 1 Start of forecast; 2 Verifying time of forecast;
34 C> 3 Observation time.
35 C> - gfld\%idsect(6) Year (4 digits)
36 C> - gfld\%idsect(7) Month
37 C> - gfld\%idsect(8) Day
38 C> - gfld\%idsect(9) Hour
39 C> - gfld\%idsect(10) Minute
40 C> - gfld\%idsect(11) Second
41 C> - gfld\%idsect(12) Production status of processed data (see Code
42 C> Table 1.3)
43 C> 0 Operational products; 1 Operational test products;
44 C> 2 Research products; 3 Re-analysis products.
45 C> - gfld\%idsect(13) Type of processed data (see Code Table 1.4)
46 C> 0 Analysis products
47 C> 1 Forecast products
48 C> 2 Analysis and forecast products
49 C> 3 Control forecast products
50 C> 4 Perturbed forecast products
51 C> 5 Control and perturbed forecast products
52 C> 6 Processed satellite observations
53 C> 7 Processed radar observations
54 C> - gfld\%idsectlen Number of elements in gfld\%idsect
55 C> - gfld\%local Pointer to character array containing contents
56 C> of Local Section 2, if included
57 C> - gfld\%locallen length of array gfld\%local
58 C> - gfld\%ifldnum field number within GRIB message
59 C> - gfld\%griddef Source of grid definition (see Code Table 3.0)
60 C> 0 Specified in Code table 3.1
61 C> 1 Predetermined grid Defined by originating centre
62 C> - gfld\%ngrdpts Number of grid points in the defined grid.
63 C> Note that the number of actual data values returned from getgb2
64 C> (in gfld\%ndpts) may be less than this value if a logical bitmap
65 C> is in use with grid points that are being masked out.
66 C> - gfld\%numoct_opt Number of octets needed for each additional grid
67 C> points definition. Used to define number of points in each row (or
68 C> column) for non-regular grids. = 0, if using regular grid.
69 C> - gfld\%interp_opt Interpretation of list for optional points
70 C> definition.(Code Table 3.11)
71 C> - gfld\%igdtnum Grid Definition Template Number (Code Table 3.1)
72 C> - gfld\%igdtmpl Contains the data values for the specified Grid
73 C> Definition Template (NN=gfld\%igdtnum). Each element of this
74 C> integer array contains an entry (in the order specified) of Grid
75 C> Defintion Template 3.NN This element is actually a pointer to an
76 C> array that holds the data.
77 C> - gfld\%igdtlen Number of elements in gfld\%igdtmpl. i.e. number
78 C> of entries in Grid Defintion Template 3.NN (NN=gfld\%igdtnum).
79 C> - gfld\%list_opt (Used if gfld\%numoct_opt .ne. 0) This array
80 C> contains the number of grid points contained in each row (or
81 C> column). (part of Section 3) This element is actually a pointer
82 C> to an array that holds the data. This pointer is nullified
83 C> if gfld\%numoct_opt=0.
84 C> - gfld\%num_opt (Used if gfld\%numoct_opt .ne. 0) The number of
85 C> entries in array ideflist. i.e. number of rows (or columns) for which
86 C> optional grid points are defined. This value is set to zero,
87 C> if gfld\%numoct_opt=0.
88 C> - gfdl\%ipdtnum Product Definition Template Number (Code Table 4.0)
89 C> - gfld\%ipdtmpl Contains the data values for the specified Product
90 C> Definition Template (N=gfdl\%ipdtnum). Each element of this integer
91 C> array contains an entry (in the order specified) of Product Defintion
92 C> Template 4.N. This element is actually a pointer to an array
93 C> that holds the data.
94 C> - gfld\%ipdtlen Number of elements in gfld\%ipdtmpl. i.e. number of
95 C> entries in Product Defintion Template 4.N (N=gfdl\%ipdtnum).
96 C> - gfld\%coord_list Real array containing floating point values
97 C> intended to document the vertical discretisation associated to
98 C> model data on hybrid coordinate vertical levels.(part of Section 4)
99 C> This element is actually a pointer to an array
100 C> that holds the data.
101 C> - gfld\%num_coord number of values in array gfld\%coord_list.
102 C> - gfld\%ndpts Number of data points unpacked and returned.
103 C> Note that this number may be different from the value of
104 C> - gfld\%ngrdpts if a logical bitmap is in use with grid points
105 C> that are being masked out.
106 C> - gfld\%idrtnum Data Representation Template Number (Code Table 5.0)
107 C> - gfld\%idrtmpl Contains the data values for the specified Data
108 C> Representation Template (N=gfld\%idrtnum). Each element of this
109 C> integer array contains an entry (in the order specified) of
110 C> Product Defintion Template 5.N. This element is actually a
111 C> pointer to an array that holds the data.
112 C> - gfld\%idrtlen Number of elements in gfld\%idrtmpl. i.e. number
113 C> of entries in Data Representation Template 5.N (N=gfld\%idrtnum).
114 C> - gfld\%unpacked logical value indicating whether the bitmap and
115 C> data values were unpacked. If false, gfld\%bmap and gfld\%fld
116 C> pointers are nullified.
117 C> - gfld\%expanded Logical value indicating whether the data field
118 C> was expanded to the grid in the case where a bit-map is present.
119 C> If true, the data points in gfld\%fld match the grid points and
120 C> zeros were inserted at grid points where data was bit-mapped out.
121 C> If false, the data values in gfld\%fld were not expanded to the
122 C> grid and are just a consecutive array of data points corresponding
123 C> to each value of "1" in gfld\%bmap.
124 C> - gfld\%ibmap Bitmap indicator (see Code Table 6.0)
125 C> 0 bitmap applies and is included in Section 6.
126 C> 1-253 Predefined bitmap applies
127 C> 254 Previously defined bitmap applies to this field
128 C> 255 Bit map does not apply to this product.
129 C> - gfld\%bmap Logical*1 array containing decoded bitmap, if ibmap=0
130 C> or ibap=254. Otherwise nullified. This element is actually a
131 C> pointer to an array that holds the data.
132 C> - gfld\%fld Array of gfld\%ndpts unpacked data points. This element
133 C> is actually a pointer to an array that holds the data.
134 C> @param[out] IRET integer return code
135 C> - 0 all ok
136 C> - 97 error reading grib file
137 C> - other gf_getfld grib2 unpacker return code
138 C>
139 C> @note do not engage the same logical unit from more than one
140 C> processor. This subprogram is intended for private use by getgb2
141 C> routines only. Note that derived type gribfield contains pointers
142 C> to many arrays of data. The memory for these arrays is allocated
143 C> when the values in the arrays are set, to help minimize problems
144 C> with array overloading. Because of this users are encouraged to
145 C> free up this memory, when it is no longer needed, by an explicit
146 C> call to subroutine gf_free.
147 C>
148 C> @author Stephen Gilbert @date 2002-05-07
149 
150 C>
151 
152 
153 
154 
155 
156  SUBROUTINE getgb2l(LUGB,CINDEX,GFLD,IRET)
157 
158  USE grib_mod
159 
160  INTEGER,INTENT(IN) :: LUGB
161  CHARACTER(LEN=1),INTENT(IN) :: CINDEX(*)
162  INTEGER,INTENT(OUT) :: IRET
163  TYPE(gribfield) :: GFLD
164 
165  INTEGER :: LSKIP,SKIP2
166  CHARACTER(LEN=1):: CSIZE(4)
167  CHARACTER(LEN=1),ALLOCATABLE :: CTEMP(:)
168 
169  interface
170  subroutine gf_unpack2(cgrib,lcgrib,iofst,lencsec2,csec2,ierr)
171  character(len=1),intent(in) :: cgrib(lcgrib)
172  integer,intent(in) :: lcgrib
173  integer,intent(inout) :: iofst
174  integer,intent(out) :: lencsec2
175  integer,intent(out) :: ierr
176  character(len=1),pointer,dimension(:) :: csec2
177  end subroutine gf_unpack2
178  end interface
179 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
180 C GET INFO
181  NULLIFY(gfld%local)
182  iret=0
183  CALL g2_gbytec(cindex,lskip,4*8,4*8)
184  CALL g2_gbytec(cindex,skip2,8*8,4*8)
185 
186 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
187 C READ AND UNPACK LOCAL USE SECTION, IF PRESENT
188  IF ( skip2.NE.0 ) THEN
189  iskip=lskip+skip2
190  CALL baread(lugb,iskip,4,lread,csize) ! GET LENGTH OF SECTION
191  CALL g2_gbytec(csize,ilen,0,32)
192  ALLOCATE(ctemp(ilen))
193  CALL baread(lugb,iskip,ilen,lread,ctemp) ! READ IN SECTION
194  IF (ilen.NE.lread) THEN
195  iret=97
196  DEALLOCATE(ctemp)
197  RETURN
198  ENDIF
199  iofst=0
200  CALL gf_unpack2(ctemp,ilen,iofst,gfld%locallen,
201  & gfld%local,ierr)
202  IF (ierr.NE.0) THEN
203  iret=98
204  DEALLOCATE(ctemp)
205  RETURN
206  ENDIF
207  DEALLOCATE(ctemp)
208  ELSE
209  gfld%locallen=0
210  ENDIF
211 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
212  RETURN
213  END
grib_mod::gribfield
Definition: gribmod.f:155
grib_mod
PROGRAM HISTORY LOG:
Definition: gribmod.f:151
g2_gbytec
subroutine g2_gbytec(IN, IOUT, ISKIP, NBYTE)
This subrountine is to extract arbitrary size values from a packed bit string, right justifying each ...
Definition: g2_gbytesc.f:20
gf_unpack2
subroutine gf_unpack2(cgrib, lcgrib, iofst, lencsec2, csec2, ierr)
This subroutine unpacks Section 2 (Local Use Section) as defined in GRIB Edition 2.
Definition: gf_unpack2.f:22
getgb2l
subroutine getgb2l(LUGB, CINDEX, GFLD, IRET)
This subroutine read and unpack a local use section from a grib2 message.
Definition: getgb2l.f:157