106 subroutine getfield(cgrib, lcgrib, ifldnum, igds, igdstmpl, &
107 igdslen, ideflist, idefnum, ipdsnum, ipdstmpl, ipdslen, &
108 coordlist, numcoord, ndpts, idrsnum, idrstmpl, idrslen, &
109 ibmap, bmap, fld, ierr)
113 character(len = 1),
intent(in) :: cgrib(lcgrib)
114 integer,
intent(in) :: lcgrib, ifldnum
115 integer,
intent(out) :: igds(*), igdstmpl(*), ideflist(*)
116 integer,
intent(out) :: ipdsnum, ipdstmpl(*)
117 integer,
intent(out) :: idrsnum, idrstmpl(*)
118 integer,
intent(out) :: ndpts, ibmap, idefnum, numcoord
119 integer,
intent(out) :: ierr
120 logical*1,
intent(out) :: bmap(*)
121 real,
intent(out) :: fld(*), coordlist(*)
123 character(len = 4),
parameter :: grib =
'GRIB', c7777 =
'7777'
124 character(len = 4) :: ctemp
125 integer :: listsec0(2)
126 integer :: iofst, istart
128 logical :: have3, have4, have5, have6, have7
131 integer,
intent(out) :: igdslen, ipdslen, idrslen
132 integer :: numfld, j, lengrib, lensec0, ipos
133 integer :: lensec, isecnum, jerr, ier, numlocal
145 if (ifldnum .le. 0)
then
146 print *,
'getfield: Request for field number ' &
155 ctemp = cgrib(j) // cgrib(j + 1) // cgrib(j + 2) // cgrib(j + 3)
156 if (ctemp .eq. grib)
then
161 if (istart .eq. 0)
then
162 print *,
'getfield: Beginning characters GRIB not found.'
168 iofst = 8 * (istart + 5)
169 call g2_gbytec(cgrib, listsec0(1), iofst, 8)
171 call g2_gbytec(cgrib, listsec0(2), iofst, 8)
174 call g2_gbytec(cgrib, lengrib, iofst, 32)
177 ipos = istart + lensec0
180 if (listsec0(2) .ne. 2)
then
181 print *,
'getfield: can only decode GRIB edition 2.'
191 ctemp = cgrib(ipos) // cgrib(ipos + 1) // cgrib(ipos + 2) // &
193 if (ctemp .eq. c7777)
then
196 if (ipos.ne.(istart + lengrib))
then
197 print *,
'getfield: "7777" found, but not ' &
205 iofst = (ipos - 1) * 8
214 if (isecnum .eq. 3)
then
216 call unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
217 igdslen, ideflist, idefnum, jerr)
218 if (jerr .eq. 0)
then
228 if (isecnum .eq. 4)
then
230 if (numfld .eq. ifldnum)
then
232 call unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, &
233 ipdslen, coordlist, numcoord, jerr)
234 if (jerr .eq. 0)
then
245 if ((isecnum .eq. 5) .and. (numfld .eq. ifldnum))
then
247 call unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, &
248 idrstmpl, idrslen, jerr)
249 if (jerr .eq. 0)
then
259 if (isecnum .eq. 6)
then
261 call unpack6(cgrib, lcgrib, iofst, igds(2), ibmap, bmap, &
263 if (jerr .eq. 0)
then
273 if ((isecnum .eq. 7) .and. (numfld .eq. ifldnum))
then
274 if (idrsnum .eq. 0)
then
275 call simunpack(cgrib(ipos + 5), lensec - 6, idrstmpl, &
278 elseif (idrsnum .eq. 2 .or. idrsnum .eq. 3)
then
279 call comunpack(cgrib(ipos + 5), lensec - 6, lensec, &
280 idrsnum,idrstmpl, ndpts, fld, ier)
286 elseif (idrsnum .eq. 50)
then
287 call simunpack(cgrib(ipos + 5), lensec - 6, idrstmpl, &
290 call rdieee(ieee, fld(1), 1)
292 elseif (idrsnum .eq. 40 .or. idrsnum .eq. 40000)
then
293 call jpcunpack(cgrib(ipos + 5), lensec - 5, idrstmpl, &
296 elseif (idrsnum .eq. 41 .or. idrsnum .eq. 40010)
then
297 call pngunpack(cgrib(ipos + 5), lensec - 5, idrstmpl, &
301 print *,
'getfield: Data Representation Template ', &
302 idrsnum,
' not yet implemented.'
311 if (ipos .gt. (istart + lengrib))
then
312 print *,
'getfield: "7777" not found at end' &
318 if (have3 .and. have4 .and. have5 .and. have6 .and. have7) &
325 print *,
'getfield: GRIB message contained ', numlocal, &
327 print *,
'getfield: The request was for the ', ifldnum, &
374 subroutine unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
375 mapgridlen, ideflist, idefnum, ierr)
380 character(len = 1),
intent(in) :: cgrib(lcgrib)
381 integer,
intent(in) :: lcgrib
382 integer,
intent(inout) :: iofst
383 integer,
intent(out) :: igds(*), igdstmpl(*), ideflist(*)
384 integer,
intent(out) :: ierr, idefnum
386 integer,
allocatable :: mapgrid(:)
387 integer :: mapgridlen, ibyttem
391 integer :: lensec, iret, i, nbits, isign, newmapgridlen
401 call g2_gbytec(cgrib, igds(2), iofst, 32)
407 call g2_gbytec(cgrib, igds(5), iofst, 16)
409 if (igds(1) .eq. 0)
then
411 allocate(mapgrid(lensec))
415 if (iret .ne. 0)
then
430 nbits = iabs(mapgrid(i)) * 8
431 if (mapgrid(i) .ge. 0)
then
432 call g2_gbytec(cgrib, igdstmpl(i), iofst, nbits)
435 call g2_gbytec(cgrib, igdstmpl(i), iofst + 1, nbits-1)
436 if (isign .eq. 1) igdstmpl(i) = -igdstmpl(i)
438 iofst = iofst + nbits
439 ibyttem = ibyttem + iabs(mapgrid(i))
449 do i = mapgridlen + 1, newmapgridlen
450 nbits = iabs(mapgrid(i)) * 8
451 if (mapgrid(i) .ge. 0)
then
452 call g2_gbytec(cgrib, igdstmpl(i), iofst, nbits)
455 call g2_gbytec(cgrib, igdstmpl(i), iofst + 1, nbits - &
457 if (isign .eq. 1) igdstmpl(i) = -igdstmpl(i)
459 iofst = iofst + nbits
460 ibyttem = ibyttem + iabs(mapgrid(i))
462 mapgridlen = newmapgridlen
467 if (igds(3) .ne. 0)
then
469 idefnum = (lensec - 14 - ibyttem) / igds(3)
470 call g2_gbytesc(cgrib, ideflist, iofst, nbits, 0, idefnum)
471 iofst = iofst + (nbits * idefnum)
475 if (
allocated(mapgrid))
deallocate(mapgrid)
504 subroutine unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, &
505 mappdslen, coordlist, numcoord, ierr)
510 character(len = 1),
intent(in) :: cgrib(lcgrib)
511 integer,
intent(in) :: lcgrib
512 integer,
intent(inout) :: iofst
513 real,
intent(out) :: coordlist(*)
514 integer,
intent(out) :: ipdsnum, ipdstmpl(*)
515 integer,
intent(out) :: ierr, numcoord
517 real(4),
allocatable :: coordieee(:)
518 integer,
allocatable :: mappds(:)
523 integer :: lensec, iret, i, nbits, isign, newmappdslen
530 allocate(mappds(lensec))
532 call g2_gbytec(cgrib, numcoord, iofst, 16)
534 call g2_gbytec(cgrib, ipdsnum, iofst, 16)
547 nbits = iabs(mappds(i))*8
548 if (mappds(i).ge.0)
then
549 call g2_gbytec(cgrib, ipdstmpl(i), iofst, nbits)
552 call g2_gbytec(cgrib, ipdstmpl(i), iofst + 1, nbits-1)
553 if (isign.eq.1) ipdstmpl(i) = -ipdstmpl(i)
555 iofst = iofst + nbits
565 do i = mappdslen + 1, newmappdslen
566 nbits = iabs(mappds(i))*8
567 if (mappds(i).ge.0)
then
568 call g2_gbytec(cgrib, ipdstmpl(i), iofst, nbits)
571 call g2_gbytec(cgrib, ipdstmpl(i), iofst + 1, nbits-1)
572 if (isign.eq.1) ipdstmpl(i) = -ipdstmpl(i)
574 iofst = iofst + nbits
576 mappdslen = newmappdslen
581 if (numcoord .ne. 0)
then
582 allocate (coordieee(numcoord))
583 call g2_gbytesc(cgrib, coordieee, iofst, 32, 0, numcoord)
584 call rdieee(coordieee, coordlist, numcoord)
585 deallocate (coordieee)
586 iofst = iofst + (32*numcoord)
588 if (
allocated(mappds))
deallocate(mappds)
613 subroutine unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, &
614 idrstmpl, mapdrslen, ierr)
619 character(len = 1),
intent(in) :: cgrib(lcgrib)
620 integer,
intent(in) :: lcgrib
621 integer,
intent(inout) :: iofst
622 integer,
intent(out) :: ndpts, idrsnum, idrstmpl(*)
623 integer,
intent(out) :: ierr
626 integer,
allocatable :: mapdrs(:)
631 integer :: lensec, i, nbits, isign, newmapdrslen, iret
638 allocate(mapdrs(lensec))
642 call g2_gbytec(cgrib, idrsnum, iofst, 16)
655 nbits = iabs(mapdrs(i))*8
656 if (mapdrs(i).ge.0)
then
657 call g2_gbytec(cgrib, idrstmpl(i), iofst, nbits)
660 call g2_gbytec(cgrib, idrstmpl(i), iofst + 1, nbits-1)
661 if (isign.eq.1) idrstmpl(i) = -idrstmpl(i)
663 iofst = iofst + nbits
672 do i = mapdrslen + 1, newmapdrslen
673 nbits = iabs(mapdrs(i))*8
674 if (mapdrs(i).ge.0)
then
675 call g2_gbytec(cgrib, idrstmpl(i), iofst, nbits)
678 call g2_gbytec(cgrib, idrstmpl(i), iofst + 1, nbits - 1)
679 if (isign.eq.1) idrstmpl(i) = -idrstmpl(i)
681 iofst = iofst + nbits
683 mapdrslen = newmapdrslen
685 if (
allocated(mapdrs))
deallocate(mapdrs)
709 subroutine unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, ierr)
712 character(len = 1),
intent(in) :: cgrib(lcgrib)
713 integer,
intent(in) :: lcgrib, ngpts
714 integer,
intent(inout) :: iofst
715 integer,
intent(out) :: ibmap
716 integer,
intent(out) :: ierr
717 logical*1,
intent(out) :: bmap(ngpts)
719 integer :: intbmap(ngpts)
733 call g2_gbytesc(cgrib, intbmap, iofst, 1, 0, ngpts)
734 iofst = iofst + ngpts
737 if (intbmap(j).eq.0) bmap(j) = .false.
739 elseif (ibmap.eq.254)
then
741 elseif (ibmap.eq.255)
then
742 bmap(1:ngpts) = .true.
744 print *,
'unpack6: Predefined bitmap ', ibmap, &
subroutine comunpack(cpack, len, lensec, idrsnum, idrstmpl, ndpts, fld, ier)
Unpack a data field that was packed using a complex packing algorithm as defined in the GRIB2 documen...
subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked a...
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 getfield(cgrib, lcgrib, ifldnum, igds, igdstmpl, igdslen, ideflist, idefnum, ipdsnum, ipdstmpl, ipdslen, coordlist, numcoord, ndpts, idrsnum, idrstmpl, idrslen, ibmap, bmap, fld, ierr)
This subroutine returns the Grid Definition, Product Definition, Bit-map (if applicable),...
subroutine unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, ierr)
This subroutine unpacks Section 6 (Bit-Map Section) starting at octet 6 of that Section.
subroutine unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, mappdslen, coordlist, numcoord, ierr)
This subroutine unpacks Section 4 (Product Definition Section) starting at octet 6 of that Section.
subroutine unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, mapgridlen, ideflist, idefnum, ierr)
This subroutine unpacks Section 3 (Grid Definition Section) starting at octet 6 of that Section.
subroutine unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, idrstmpl, mapdrslen, ierr)
This subroutine unpacks Section 5 (Data Representation Section) starting at octet 6 of that Section.
subroutine jpcunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field from a JPEG2000 code stream.
Handles Data Representation Templates used in Section 5.
subroutine getdrstemplate(number, nummap, map, needext, iret)
Return DRS template information for a specified Data Representation Template.
subroutine extdrstemplate(number, list, nummap, map)
Generate the remaining octet map for a given Data Representation Template, if required.
This Fortran module contains info on all the available GRIB2 Grid Definition Templates used in [Secti...
subroutine getgridtemplate(number, nummap, map, needext, iret)
Get the grid template information for a specified Grid Definition Template.
subroutine extgridtemplate(number, list, nummap, map)
Generate the remaining octet map for a given Grid Definition Template, if required.
Information on all GRIB2 Product Definition Templates used in Section 4 - the Product Definition Sect...
subroutine extpdstemplate(number, list, nummap, map)
This subroutine generates the remaining octet map for a given Product Definition Template,...
subroutine getpdstemplate(number, nummap, map, needext, iret)
This subroutine returns PDS template information for a specified Product Definition Template.
subroutine pngunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field packed into a PNG image format.
subroutine rdieee(rieee, a, num)
Copy array of 32-bit IEEE floating point values to local floating point representation.
subroutine simunpack(cpack, len, idrstmpl, ndpts, fld)
This subroutine unpacks a data field that was packed using a simple packing algorithm as defined in t...