1 subroutine gf_unpack7(cgrib,lcgrib,iofst,igdsnum,igdstmpl,
2 & idrsnum,idrstmpl,ndpts,fld,ierr)
3 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
5 ! SUBPROGRAM: gf_unpack7
6 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-01-24
8 ! ABSTRACT: This subroutine unpacks GRIB2 Section 7 (Data Section).
10 ! PROGRAM HISTORY LOG:
12 ! 2002-12-17 Gilbert - Added support for new templates using
13 ! PNG and JPEG2000 algorithms/templates.
14 ! 2004-12-29 Gilbert - Added check on comunpack return code.
16 ! USAGE: CALL gf_unpack7(cgrib,lcgrib,iofst,igdsnum,igdstmpl,
17 ! & idrsnum,idrstmpl,ndpts,fld,ierr)
18 ! INPUT ARGUMENT LIST:
19 ! cgrib - Character array that contains the GRIB2 message
20 ! lcgrib - Length (in bytes) of GRIB message array cgrib.
21 ! iofst - Bit offset of the beginning of Section 7.
22 ! igdsnum - Grid Definition Template Number ( see Code Table 3.0)
23 ! (Only required to unpack DRT 5.51)
24 ! igdstmpl - Pointer to an integer array containing the data values for
25 ! the specified Grid Definition
26 ! Template ( N=igdsnum ). Each element of this integer
27 ! array contains an entry (in the order specified) of Grid
28 ! Definition Template 3.N
29 ! (Only required to unpack DRT 5.51)
30 ! idrsnum - Data Representation Template Number ( see Code Table 5.0)
31 ! idrstmpl - Pointer to an integer array containing the data values for
32 ! the specified Data Representation
33 ! Template ( N=idrsnum ). Each element of this integer
34 ! array contains an entry (in the order specified) of Data
35 ! Representation Template 5.N
36 ! ndpts - Number of data points unpacked and returned.
38 ! OUTPUT ARGUMENT LIST:
39 ! iofst - Bit offset at the end of Section 7, returned.
40 ! fld() - Pointer to a real array containing the unpacked data field.
41 ! ierr - Error return code.
43 ! 4 = Unrecognized Data Representation Template
44 ! 5 = One of GDT 3.50 through 3.53 required to unpack DRT 5.51
45 ! 6 = memory allocation error
46 ! 7 = corrupt section 7.
51 ! LANGUAGE: Fortran 90
56 character(len=1),intent(in) :: cgrib(lcgrib)
57 integer,intent(in) :: lcgrib,ndpts,igdsnum,idrsnum
58 integer,intent(inout) :: iofst
59 integer,pointer,dimension(:) :: igdstmpl,idrstmpl
60 integer,intent(out) :: ierr
61 real,pointer,dimension(:) :: fld
67 call g2lib_gbyte(cgrib,lensec,iofst,32) ! Get Length of Section
69 iofst=iofst+8 ! skip section number
73 allocate(fld(ndpts),stat=istat)
79 if (idrsnum.eq.0) then
80 call simunpack(cgrib(ipos),lensec-5,idrstmpl,ndpts,fld)
81 elseif (idrsnum.eq.2.or.idrsnum.eq.3) then
82 call comunpack(cgrib(ipos),lensec-5,lensec,idrsnum,idrstmpl,
84 if ( ier .NE. 0 ) then
88 elseif (idrsnum.eq.50) then ! Spectral simple
89 call simunpack(cgrib(ipos),lensec-5,idrstmpl,ndpts-1,
92 call rdieee(ieee,fld(1),1)
93 elseif (idrsnum.eq.51) then ! Spectral complex
94 if (igdsnum.ge.50.AND.igdsnum.le.53) then
95 call specunpack(cgrib(ipos),lensec-5,idrstmpl,ndpts,
96 & igdstmpl(1),igdstmpl(2),igdstmpl(3),fld)
98 print *,'gf_unpack7: Cannot use GDT 3.',igdsnum,
99 & ' to unpack Data Section 5.51.'
105 elseif (idrsnum.eq.40 .OR. idrsnum.eq.40000) then
106 call jpcunpack(cgrib(ipos),lensec-5,idrstmpl,ndpts,fld)
107 #endif /* USE_JPEG2000 */
109 elseif (idrsnum.eq.41 .OR. idrsnum.eq.40010) then
110 call pngunpack(cgrib(ipos),lensec-5,idrstmpl,ndpts,fld)
113 print *,'gf_unpack7: Data Representation Template ',idrsnum,
114 & ' not yet implemented.'
120 iofst=iofst+(8*lensec)
122 return ! End of Section 7 processing