67 subroutine gf_getfld(cgrib, lcgrib, ifldnum, unpack, expand, gfld, ierr)
72 character(len = 1),
intent(in) :: cgrib(lcgrib)
73 integer,
intent(in) :: lcgrib, ifldnum
74 logical,
intent(in) :: unpack, expand
76 integer,
intent(out) :: ierr
78 character(len = 4),
parameter :: grib =
'GRIB', c7777 =
'7777'
79 character(len = 4) :: ctemp
80 real,
pointer,
dimension(:) :: newfld
81 integer:: listsec0(2), igds(5)
83 logical*1,
pointer,
dimension(:) :: bmpsave
84 logical have3, have4, have5, have6, have7
87 integer :: numfld, j, lengrib, ipos, lensec0, lensec
88 integer :: isecnum, jerr, n, numlocal
91 subroutine gf_unpack1(cgrib, lcgrib, iofst, ids, idslen, ierr)
92 character(len = 1),
intent(in) :: cgrib(lcgrib)
93 integer,
intent(in) :: lcgrib
94 integer,
intent(inout) :: iofst
95 integer,
pointer,
dimension(:) :: ids
96 integer,
intent(out) :: ierr, idslen
98 subroutine gf_unpack2(cgrib, lcgrib, iofst, lencsec2, csec2, ierr)
99 character(len = 1),
intent(in) :: cgrib(lcgrib)
100 integer,
intent(in) :: lcgrib
101 integer,
intent(inout) :: iofst
102 integer,
intent(out) :: lencsec2
103 integer,
intent(out) :: ierr
104 character(len = 1),
pointer,
dimension(:) :: csec2
106 subroutine gf_unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
107 mapgridlen, ideflist, idefnum, ierr)
108 character(len = 1),
intent(in) :: cgrib(lcgrib)
109 integer,
intent(in) :: lcgrib
110 integer,
intent(inout) :: iofst
111 integer,
pointer,
dimension(:) :: igdstmpl, ideflist
112 integer,
intent(out) :: igds(5)
113 integer,
intent(out) :: mapgridlen
114 integer,
intent(out) :: ierr, idefnum
116 subroutine gf_unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, &
117 mappdslen, coordlist, numcoord, ierr)
118 character(len = 1),
intent(in) :: cgrib(lcgrib)
119 integer,
intent(in) :: lcgrib
120 integer,
intent(inout) :: iofst
121 real,
pointer,
dimension(:) :: coordlist
122 integer,
pointer,
dimension(:) :: ipdstmpl
123 integer,
intent(out) :: ipdsnum
124 integer,
intent(out) :: mappdslen
125 integer,
intent(out) :: ierr, numcoord
127 subroutine gf_unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, &
128 idrstmpl, mapdrslen, ierr)
129 character(len = 1),
intent(in) :: cgrib(lcgrib)
130 integer,
intent(in) :: lcgrib
131 integer,
intent(inout) :: iofst
132 integer,
intent(out) :: ndpts, idrsnum
133 integer,
pointer,
dimension(:) :: idrstmpl
134 integer,
intent(out) :: mapdrslen
135 integer,
intent(out) :: ierr
137 subroutine gf_unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, &
139 character(len = 1),
intent(in) :: cgrib(lcgrib)
140 integer,
intent(in) :: lcgrib, ngpts
141 integer,
intent(inout) :: iofst
142 integer,
intent(out) :: ibmap
143 integer,
intent(out) :: ierr
144 logical*1,
pointer,
dimension(:) :: bmap
146 subroutine gf_unpack7(cgrib, lcgrib, iofst, igdsnum, igdstmpl, &
147 idrsnum, idrstmpl, ndpts, fld, ierr)
148 character(len = 1),
intent(in) :: cgrib(lcgrib)
149 integer,
intent(in) :: lcgrib, ndpts, idrsnum, igdsnum
150 integer,
intent(inout) :: iofst
151 integer,
pointer,
dimension(:) :: idrstmpl, igdstmpl
152 integer,
intent(out) :: ierr
153 real,
pointer,
dimension(:) :: fld
165 nullify(gfld%list_opt, gfld%igdtmpl, gfld%ipdtmpl)
166 nullify(gfld%coord_list, gfld%idrtmpl, gfld%bmap, gfld%fld)
169 if (ifldnum .le. 0)
then
170 print *,
'gf_getfld: Request for field number ' &
179 ctemp = cgrib(j) // cgrib(j + 1) // cgrib(j + 2) // cgrib(j + 3)
180 if (ctemp .eq. grib)
then
185 if (istart .eq. 0)
then
186 print *,
'gf_getfld: Beginning characters GRIB not found.'
192 iofst = 8 * (istart + 5)
193 call g2_gbytec(cgrib, listsec0(1), iofst, 8)
195 call g2_gbytec(cgrib, listsec0(2), iofst, 8)
198 call g2_gbytec(cgrib, lengrib, iofst, 32)
201 ipos = istart + lensec0
204 if (listsec0(2) .ne. 2)
then
205 print *,
'gf_getfld: can only decode GRIB edition 2.'
215 ctemp = cgrib(ipos) // cgrib(ipos + 1) // cgrib(ipos + 2) // &
217 if (ctemp .eq. c7777)
then
220 if (ipos.ne.(istart + lengrib))
then
221 print *,
'gf_getfld: "7777" found, but not ' &
230 iofst = (ipos - 1) * 8
237 if ((isecnum .lt. 1) .or. (isecnum .gt. 7))
then
238 print *,
'gf_getfld: Unrecognized Section Encountered = ', &
245 if (isecnum .eq. 1)
then
247 call gf_unpack1(cgrib, lcgrib, iofst, gfld%idsect, &
248 gfld%idsectlen, jerr)
249 if (jerr .ne. 0)
then
257 if (isecnum .eq. 2)
then
259 if (
associated(gfld%local))
deallocate(gfld%local)
260 call gf_unpack2(cgrib, lcgrib, iofst, gfld%locallen, &
262 if (jerr .ne. 0)
then
272 if (isecnum .eq. 3)
then
274 if (
associated(gfld%igdtmpl))
deallocate(gfld%igdtmpl)
275 if (
associated(gfld%list_opt))
deallocate(gfld%list_opt)
276 call gf_unpack3(cgrib, lcgrib, iofst, igds, gfld%igdtmpl, &
277 gfld%igdtlen, gfld%list_opt, gfld%num_opt, jerr)
278 if (jerr .ne. 0)
then
284 gfld%griddef = igds(1)
285 gfld%ngrdpts = igds(2)
286 gfld%numoct_opt = igds(3)
287 gfld%interp_opt = igds(4)
288 gfld%igdtnum = igds(5)
293 if (isecnum .eq. 4)
then
295 if (numfld .eq. ifldnum)
then
296 gfld%discipline = listsec0(1)
297 gfld%version = listsec0(2)
298 gfld%ifldnum = ifldnum
299 gfld%unpacked = unpack
300 gfld%expanded = .false.
302 call gf_unpack4(cgrib, lcgrib, iofst, gfld%ipdtnum, &
303 gfld%ipdtmpl, gfld%ipdtlen, gfld%coord_list, &
304 gfld%num_coord, jerr)
305 if (jerr .ne. 0)
then
316 if ((isecnum .eq. 5).and.(numfld .eq. ifldnum))
then
318 call gf_unpack5(cgrib, lcgrib, iofst, gfld%ndpts, &
319 gfld%idrtnum, gfld%idrtmpl, gfld%idrtlen, jerr)
320 if (jerr .ne. 0)
then
330 if (isecnum .eq. 6)
then
334 call gf_unpack6(cgrib, lcgrib, iofst, gfld%ngrdpts, &
335 gfld%ibmap, gfld%bmap, jerr)
336 if (jerr .ne. 0)
then
342 if (gfld%ibmap .eq. 254)
then
343 if (
associated(bmpsave))
then
346 print *,
'gf_getfld: Previous bit-map ' &
347 ,
'specified, but none exists, '
353 if (
associated(bmpsave))
deallocate(bmpsave)
356 call g2_gbytec(cgrib, gfld%ibmap, iofst, 8)
363 if ((isecnum .eq. 7) .and. (numfld .eq. ifldnum) .and. unpack) &
366 call gf_unpack7(cgrib, lcgrib, iofst, gfld%igdtnum, &
367 gfld%igdtmpl, gfld%idrtnum, &
368 gfld%idrtmpl, gfld%ndpts, &
370 if (jerr .ne. 0)
then
372 print *,
'gf_getfld: return from gf_unpack7 = ', jerr
380 if (gfld%ibmap .ne. 255 .AND.
associated(gfld%bmap))
then
382 allocate(newfld(gfld%ngrdpts))
384 do j = 1, gfld%ngrdpts
385 if (gfld%bmap(j))
then
386 newfld(j) = gfld%fld(n)
392 deallocate(gfld%fld);
394 gfld%expanded = .true.
396 gfld%expanded = .false.
399 gfld%expanded = .true.
406 if (ipos .gt. (istart + lengrib))
then
407 print *,
'gf_getfld: "7777" not found at end ' &
416 if (unpack .and. have3 .and. have4 .and. have5 .and. have6 &
421 if ((.not. unpack) .and. have3 .and. have4 .and. have5 .and. &
427 print *,
'gf_getfld: GRIB message contained ', numlocal, &
429 print *,
'gf_getfld: The request was for the ', ifldnum, &
subroutine g2_gbytec(in, iout, iskip, nbits)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked a...
subroutine gf_free(gfld)
Free memory that was used to store array values in derived type grib_mod::gribfield.
subroutine gf_getfld(cgrib, lcgrib, ifldnum, unpack, expand, gfld, ierr)
This subroutine returns the Grid Definition, Product Definition, Bit-map (if applicable),...
subroutine gf_unpack1(cgrib, lcgrib, iofst, ids, idslen, ierr)
Unpack Section 1 (Identification Section) of a GRIB2 message, starting at octet 6 of that Section.
subroutine gf_unpack2(cgrib, lcgrib, iofst, lencsec2, csec2, ierr)
Unpack Section 2 (Local Use Section) of a GRIB2 message.
subroutine gf_unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, mapgridlen, ideflist, idefnum, ierr)
Unpack Section 3 (Grid Definition Section) of a GRIB2 message, starting at octet 6 of that Section.
subroutine gf_unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, mappdslen, coordlist, numcoord, ierr)
Unpack Section 4 (Product Definition Section) of a GRIB2 message, starting at octet 6 of that Section...
subroutine gf_unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, idrstmpl, mapdrslen, ierr)
Unpack Section 5 (Data Representation Section) of a GRIB2 message, starting at octet 6 of that Sectio...
subroutine gf_unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, ierr)
Unpack Section 6 (Bit-Map Section) of a GRIB2 message, starting at octet 6 of that Section.
subroutine gf_unpack7(cgrib, lcgrib, iofst, igdsnum, igdstmpl, idrsnum, idrstmpl, ndpts, fld, ierr)
Unpack Section 7 (Data Section) of a GRIB2 message.
This Fortran module contains the declaration of derived type gribfield.