41 subroutine gf_unpack1(cgrib, lcgrib, iofst, ids, idslen, ierr)
44 character(len=1),
intent(in) :: cgrib(lcgrib)
45 integer,
intent(in) :: lcgrib
46 integer,
intent(inout) :: iofst
47 integer,
pointer,
dimension(:) :: ids
48 integer,
intent(out) :: ierr, idslen
49 integer,
dimension(:) :: mapid(13)
50 integer :: i, istat, lensec, nbits
52 data mapid /2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1/
66 allocate(ids(idslen), stat = istat)
67 if (istat .ne. 0)
then
75 call g2_gbytec(cgrib, ids(i), iofst, nbits)
99 subroutine gf_unpack2(cgrib, lcgrib, iofst, lencsec2, csec2, ierr)
102 character(len = 1),
intent(in) :: cgrib(lcgrib)
103 integer,
intent(in) :: lcgrib
104 integer,
intent(inout) :: iofst
105 integer,
intent(out) :: lencsec2
106 integer,
intent(out) :: ierr
107 character(len = 1),
pointer,
dimension(:) :: csec2
108 integer :: lensec, istat, isecnum, ipos
119 ipos = (iofst / 8) + 1
121 if (isecnum .ne. 2)
then
123 print *,
'gf_unpack2: Not Section 2 data. '
127 allocate(csec2(lencsec2), stat = istat)
128 if (istat .ne. 0)
then
134 csec2(1:lencsec2) = cgrib(ipos:ipos + lencsec2 - 1)
135 iofst = iofst + (lencsec2 * 8)
182 subroutine gf_unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
183 mapgridlen, ideflist, idefnum, ierr)
189 character(len = 1),
intent(in) :: cgrib(lcgrib)
190 integer,
intent(in) :: lcgrib
191 integer,
intent(inout) :: iofst
192 integer,
pointer,
dimension(:) :: igdstmpl, ideflist
193 integer,
intent(out) :: igds(5)
194 integer,
intent(out) :: ierr, idefnum
196 integer,
allocatable :: mapgrid(:)
197 integer,
intent(out) :: mapgridlen
200 integer :: lensec, istat, i, nbits, isign, newmapgridlen, iret
203 nullify(igdstmpl, ideflist)
211 call g2_gbytec(cgrib, igds(2), iofst, 32)
217 call g2_gbytec(cgrib, igds(5), iofst, 16)
220 if (igds(1) .eq. 0 .OR. igds(1) .eq. 255)
then
221 allocate(mapgrid(lensec))
225 if (iret .ne. 0)
then
227 if (
allocated(mapgrid))
deallocate(mapgrid)
239 if (mapgridlen .gt. 0)
allocate(igdstmpl(mapgridlen), stat = istat)
240 if (istat .ne. 0)
then
243 if (
allocated(mapgrid))
deallocate(mapgrid)
248 nbits = iabs(mapgrid(i)) * 8
249 if (mapgrid(i) .ge. 0)
then
250 call g2_gbytec(cgrib, igdstmpl(i), iofst, nbits)
253 call g2_gbytec(cgrib, igdstmpl(i), iofst + 1, nbits - 1)
254 if (isign .eq. 1) igdstmpl(i) = -igdstmpl(i)
256 iofst = iofst + nbits
257 ibyttem = ibyttem + iabs(mapgrid(i))
268 call realloc(igdstmpl, mapgridlen, newmapgridlen, istat)
269 do i = mapgridlen + 1, newmapgridlen
270 nbits = iabs(mapgrid(i)) * 8
271 if (mapgrid(i) .ge. 0)
then
272 call g2_gbytec(cgrib, igdstmpl(i), iofst, nbits)
275 call g2_gbytec(cgrib, igdstmpl(i), iofst + 1, nbits - 1)
276 if (isign.eq.1) igdstmpl(i) = -igdstmpl(i)
278 iofst = iofst + nbits
279 ibyttem = ibyttem + iabs(mapgrid(i))
281 mapgridlen = newmapgridlen
283 if (
allocated(mapgrid))
deallocate(mapgrid)
287 if (igds(3) .ne. 0)
then
289 idefnum = (lensec - 14 - ibyttem) / igds(3)
291 if (idefnum .gt. 0)
allocate(ideflist(idefnum), stat = istat)
292 if (istat .ne. 0)
then
297 call g2_gbytesc(cgrib, ideflist, iofst, nbits, 0, idefnum)
298 iofst = iofst + (nbits * idefnum)
332 subroutine gf_unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, &
333 mappdslen, coordlist, numcoord, ierr)
338 character(len = 1),
intent(in) :: cgrib(lcgrib)
339 integer,
intent(in) :: lcgrib
340 integer,
intent(inout) :: iofst
341 real,
pointer,
dimension(:) :: coordlist
342 integer,
pointer,
dimension(:) :: ipdstmpl
343 integer,
intent(out) :: ipdsnum
344 integer,
intent(out) :: ierr, numcoord
346 real(4),
allocatable :: coordieee(:)
347 integer,
allocatable :: mappds(:)
350 integer :: lensec, nbits, newmappdslen
351 integer :: istat1, istat, isign, iret, i
354 nullify(ipdstmpl, coordlist)
360 allocate(mappds(lensec))
363 call g2_gbytec(cgrib, numcoord, iofst, 16)
366 call g2_gbytec(cgrib, ipdsnum, iofst, 16)
372 if (
allocated(mappds))
deallocate(mappds)
380 if (mappdslen.gt.0)
allocate(ipdstmpl(mappdslen), stat = istat)
384 if (
allocated(mappds))
deallocate(mappds)
388 nbits = iabs(mappds(i))*8
389 if (mappds(i).ge.0)
then
390 call g2_gbytec(cgrib, ipdstmpl(i), iofst, nbits)
393 call g2_gbytec(cgrib, ipdstmpl(i), iofst + 1, nbits-1)
394 if (isign.eq.1) ipdstmpl(i) = -ipdstmpl(i)
396 iofst = iofst + nbits
404 call realloc(ipdstmpl, mappdslen, newmappdslen, istat)
406 do i = mappdslen + 1, newmappdslen
407 nbits = iabs(mappds(i))*8
408 if (mappds(i).ge.0)
then
409 call g2_gbytec(cgrib, ipdstmpl(i), iofst, nbits)
412 call g2_gbytec(cgrib, ipdstmpl(i), iofst + 1, nbits-1)
413 if (isign.eq.1) ipdstmpl(i) = -ipdstmpl(i)
415 iofst = iofst + nbits
417 mappdslen = newmappdslen
419 if (
allocated(mappds))
deallocate(mappds)
424 if (numcoord .ne. 0)
then
425 allocate (coordieee(numcoord), stat = istat1)
426 allocate(coordlist(numcoord), stat = istat)
427 if ((istat1 + istat).ne.0)
then
430 if (
allocated(coordieee))
deallocate(coordieee)
433 call g2_gbytescr(cgrib, coordieee, iofst, 32, 0, numcoord)
434 call rdieee(coordieee, coordlist, numcoord)
435 deallocate (coordieee)
436 iofst = iofst + (32 * numcoord)
465 subroutine gf_unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, idrstmpl, &
471 character(len = 1),
intent(in) :: cgrib(lcgrib)
472 integer,
intent(in) :: lcgrib
473 integer,
intent(inout) :: iofst
474 integer,
intent(out) :: ndpts, idrsnum
475 integer,
pointer,
dimension(:) :: idrstmpl
476 integer,
intent(out) :: ierr
478 integer,
allocatable :: mapdrs(:)
481 integer :: newmapdrslen, nbits, istat, isign, lensec, iret, i
489 allocate(mapdrs(lensec))
495 call g2_gbytec(cgrib, idrsnum, iofst, 16)
499 if (iret .ne. 0)
then
501 if (
allocated(mapdrs))
deallocate(mapdrs)
509 if (mapdrslen .gt. 0)
allocate(idrstmpl(mapdrslen), stat = istat)
510 if (istat .ne. 0)
then
513 if (
allocated(mapdrs))
deallocate(mapdrs)
517 nbits = iabs(mapdrs(i)) * 8
518 if (mapdrs(i) .ge. 0)
then
519 call g2_gbytec(cgrib, idrstmpl(i), iofst, nbits)
522 call g2_gbytec(cgrib, idrstmpl(i), iofst + 1, nbits-1)
523 if (isign .eq. 1) idrstmpl(i) = -idrstmpl(i)
525 iofst = iofst + nbits
533 call realloc(idrstmpl, mapdrslen, newmapdrslen, istat)
536 do i = mapdrslen + 1, newmapdrslen
537 nbits = iabs(mapdrs(i)) * 8
538 if (mapdrs(i) .ge. 0)
then
539 call g2_gbytec(cgrib, idrstmpl(i), iofst, nbits)
542 call g2_gbytec(cgrib, idrstmpl(i), iofst + 1, nbits - 1)
543 if (isign.eq.1) idrstmpl(i) = -idrstmpl(i)
545 iofst = iofst + nbits
547 mapdrslen = newmapdrslen
549 if (
allocated(mapdrs))
deallocate(mapdrs)
575 subroutine gf_unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, ierr)
578 character(len = 1),
intent(in) :: cgrib(lcgrib)
579 integer,
intent(in) :: lcgrib, ngpts
580 integer,
intent(inout) :: iofst
581 integer,
intent(out) :: ibmap
582 integer,
intent(out) :: ierr
584 logical*1,
pointer,
dimension(:) :: bmap
585 integer :: intbmap(ngpts)
597 if (ibmap .eq. 0)
then
599 if (ngpts .gt. 0)
allocate(bmap(ngpts), stat = istat)
600 if (istat .ne. 0)
then
605 call g2_gbytesc(cgrib, intbmap, iofst, 1, 0, ngpts)
606 iofst = iofst + ngpts
609 if (intbmap(j) .eq. 0) bmap(j) = .false.
648 subroutine gf_unpack7(cgrib, lcgrib, iofst, igdsnum, igdstmpl, &
649 idrsnum, idrstmpl, ndpts, fld, ierr)
652 character(len = 1),
intent(in) :: cgrib(lcgrib)
653 integer,
intent(in) :: lcgrib, ndpts, igdsnum, idrsnum
654 integer,
intent(inout) :: iofst
655 integer,
pointer,
dimension(:) :: igdstmpl, idrstmpl
656 integer,
intent(out) :: ierr
657 real,
pointer,
dimension(:) :: fld
658 integer :: ier, ipos, istat, lensec
659 real (kind = 4) :: ieee(1)
671 allocate(fld(ndpts), stat = istat)
677 if (idrsnum .eq. 0)
then
678 call simunpack(cgrib(ipos), lensec-5, idrstmpl, ndpts, fld)
679 elseif (idrsnum.eq.2.or.idrsnum.eq.3)
then
680 call comunpack(cgrib(ipos), lensec-5, lensec, idrsnum, idrstmpl, ndpts, fld, ier)
685 elseif (idrsnum .eq. 50)
then
686 call simunpack(cgrib(ipos), lensec-5, idrstmpl, ndpts-1, fld(2))
687 ieee = transfer(idrstmpl(5), ieee, 1)
688 call rdieee(ieee, tmpfld, 1)
690 elseif (idrsnum .eq. 51)
then
691 if (igdsnum.ge.50.AND.igdsnum.le.53)
then
692 call specunpack(cgrib(ipos), lensec-5, idrstmpl, ndpts, &
693 igdstmpl(1), igdstmpl(2), igdstmpl(3), fld)
695 print *,
'gf_unpack7: Cannot use GDT 3.', igdsnum,
' to unpack Data Section 5.51.'
700 elseif (idrsnum .eq. 40 .OR. idrsnum .eq. 40000)
then
701 call jpcunpack(cgrib(ipos), lensec-5, idrstmpl, ndpts, fld)
702 elseif (idrsnum .eq. 41 .OR. idrsnum .eq. 40010)
then
703 call pngunpack(cgrib(ipos), lensec-5, idrstmpl, ndpts, fld)
705 print *,
'gf_unpack7: Data Representation Template ', idrsnum,
' not yet implemented.'
711 iofst = iofst + (8 * lensec)
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 big-endian integer values (up to 32 bits each) from a packed bit string.
subroutine rdieee(rieee, a, num)
Copy array of 32-bit IEEE floating point values to local floating point representation.
subroutine g2_gbytec(in, iout, iskip, nbits)
Extract one arbitrary size big-endian value (up to 32 bits) from a packed bit string into one element...
subroutine g2_gbytescr(in, rout, iskip, nbits, nskip, n)
Extract big-endian floating-point values (32 bits each) from a packed bit string.
subroutine jpcunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field from a JPEG2000 code stream as defined in Data Representation Template 5....
subroutine pngunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field with PNG, defined in [Data Representation Template 5.40](https://www....
subroutine simunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field that was packed using a simple packing, [Data Representation Template 5....
subroutine specunpack(cpack, len, idrstmpl, ndpts, JJ, KK, MM, fld)
Unpack a spectral data field using the complex packing algorithm for spherical harmonic data,...
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_unpack7(cgrib, lcgrib, iofst, igdsnum, igdstmpl, idrsnum, idrstmpl, ndpts, fld, ierr)
Unpack Section 7 (Data Section) of a GRIB2 message.
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_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_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_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.
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.
Reallocate memory, preserving contents.