NCEPLIBS-g2  3.4.5
gf_unpack4.f
Go to the documentation of this file.
1 
6 
40 
41  subroutine gf_unpack4(cgrib,lcgrib,iofst,ipdsnum,ipdstmpl,
42  & mappdslen,coordlist,numcoord,ierr)
43 
44  use pdstemplates
45  use re_alloc ! needed for subroutine realloc
46 
47  character(len=1),intent(in) :: cgrib(lcgrib)
48  integer,intent(in) :: lcgrib
49  integer,intent(inout) :: iofst
50  real,pointer,dimension(:) :: coordlist
51  integer,pointer,dimension(:) :: ipdstmpl
52  integer,intent(out) :: ipdsnum
53  integer,intent(out) :: ierr,numcoord
54 
55  real(4),allocatable :: coordieee(:)
56  integer,allocatable :: mappds(:)
57  integer :: mappdslen
58  logical needext
59 
60  ierr=0
61  nullify(ipdstmpl,coordlist)
62 
63  call g2_gbytec(cgrib,lensec,iofst,32) ! Get Length of Section
64  iofst=iofst+32
65  iofst=iofst+8 ! skip section number
66  allocate(mappds(lensec))
67 
68  call g2_gbytec(cgrib,numcoord,iofst,16) ! Get num of coordinate values
69  iofst=iofst+16
70  call g2_gbytec(cgrib,ipdsnum,iofst,16) ! Get Prod. Def Template num.
71  iofst=iofst+16
72  ! Get Product Definition Template
73  call getpdstemplate(ipdsnum,mappdslen,mappds,needext,iret)
74  if (iret.ne.0) then
75  ierr=5
76  if( allocated(mappds) ) deallocate(mappds)
77  return
78  endif
79  !
80  ! Unpack each value into array ipdstmpl from the
81  ! the appropriate number of octets, which are specified in
82  ! corresponding entries in array mappds.
83  !
84  istat=0
85  if (mappdslen.gt.0) allocate(ipdstmpl(mappdslen),stat=istat)
86  if (istat.ne.0) then
87  ierr=6
88  nullify(ipdstmpl)
89  if( allocated(mappds) ) deallocate(mappds)
90  return
91  endif
92  do i=1,mappdslen
93  nbits=iabs(mappds(i))*8
94  if ( mappds(i).ge.0 ) then
95  call g2_gbytec(cgrib,ipdstmpl(i),iofst,nbits)
96  else
97  call g2_gbytec(cgrib,isign,iofst,1)
98  call g2_gbytec(cgrib,ipdstmpl(i),iofst+1,nbits-1)
99  if (isign.eq.1) ipdstmpl(i)=-ipdstmpl(i)
100  endif
101  iofst=iofst+nbits
102  enddo
103  !
104  ! Check to see if the Product Definition Template needs to be
105  ! extended.
106  ! The number of values in a specific template may vary
107  ! depending on data specified in the "static" part of the
108  ! template.
109  !
110  if ( needext ) then
111  call extpdstemplate(ipdsnum,ipdstmpl,newmappdslen,mappds)
112  call realloc(ipdstmpl,mappdslen,newmappdslen,istat)
113  ! Unpack the rest of the Product Definition Template
114  do i=mappdslen+1,newmappdslen
115  nbits=iabs(mappds(i))*8
116  if ( mappds(i).ge.0 ) then
117  call g2_gbytec(cgrib,ipdstmpl(i),iofst,nbits)
118  else
119  call g2_gbytec(cgrib,isign,iofst,1)
120  call g2_gbytec(cgrib,ipdstmpl(i),iofst+1,nbits-1)
121  if (isign.eq.1) ipdstmpl(i)=-ipdstmpl(i)
122  endif
123  iofst=iofst+nbits
124  enddo
125  mappdslen=newmappdslen
126  endif
127  if( allocated(mappds) ) deallocate(mappds)
128  !
129  ! Get Optional list of vertical coordinate values
130  ! after the Product Definition Template, if necessary.
131  !
132  nullify(coordlist)
133  if ( numcoord .ne. 0 ) then
134  allocate (coordieee(numcoord),stat=istat1)
135  allocate(coordlist(numcoord),stat=istat)
136  if ((istat1+istat).ne.0) then
137  ierr=6
138  nullify(coordlist)
139  if( allocated(coordieee) ) deallocate(coordieee)
140  return
141  endif
142  call g2_gbytesc(cgrib,coordieee,iofst,32,0,numcoord)
143  call rdieee(coordieee,coordlist,numcoord)
144  deallocate (coordieee)
145  iofst=iofst+(32*numcoord)
146  endif
147 
148  return ! End of Section 4 processing
149  end
150 
pdstemplates::extpdstemplate
subroutine extpdstemplate(number, list, nummap, map)
This subroutine generates the remaining octet map for a given Product Definition Template,...
Definition: pdstemplates.f:459
gf_unpack4
subroutine gf_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.
Definition: gf_unpack4.f:43
pdstemplates::getpdstemplate
subroutine getpdstemplate(number, nummap, map, needext, iret)
This subroutine returns PDS template information for a specified Product Definition Template 4....
Definition: pdstemplates.f:412
rdieee
subroutine rdieee(rieee, a, num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.
Definition: rdieee.f:16
re_alloc
This module contains three subroutines to reorganize the integer, real and character data in memory i...
Definition: realloc.f:14
re_alloc::realloc
Definition: realloc.f:16
pdstemplates
This Fortran Module contains info on all the available GRIB2 Product Definition Templates used in Sec...
Definition: pdstemplates.f:54
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
g2_gbytesc
subroutine g2_gbytesc(IN, IOUT, ISKIP, NBYTE, NSKIP, N)
This subrountine is to extract arbitrary size values from a packed bit string, right justifying each ...
Definition: g2_gbytesc.f:60