35 subroutine comunpack(cpack,len,lensec,idrsnum,idrstmpl,ndpts,
38 character(len=1),
intent(in) :: cpack(len)
39 integer,
intent(in) :: ndpts,len
40 integer,
intent(in) :: idrstmpl(*)
41 real,
intent(out) :: fld(ndpts)
43 integer,
allocatable :: ifld(:),ifldmiss(:)
45 integer,
allocatable :: gref(:),gwidth(:),glen(:)
46 real :: ref,bscale,dscale,rmiss1,rmiss2
48 integer :: totBit, totLen
54 bscale = 2.0**real(idrstmpl(2))
55 dscale = 10.0**real(-idrstmpl(3))
56 nbitsgref = idrstmpl(4)
58 ngroups = idrstmpl(10)
59 nbitsgwidth = idrstmpl(12)
60 nbitsglen = idrstmpl(16)
61 if (idrsnum.eq.3)
then
67 if (ngroups.eq.0)
then
75 allocate(ifld(ndpts),stat=is)
77 allocate(gref(ngroups),stat=is)
79 allocate(gwidth(ngroups),stat=is)
84 if ( idrstmpl(7).eq.1 )
then
86 call rdieee(idrstmpl(8),rmiss1,1)
88 rmiss1=real(idrstmpl(8))
90 elseif ( idrstmpl(7).eq.2 )
then
92 call rdieee(idrstmpl(8),rmiss1,1)
93 call rdieee(idrstmpl(9),rmiss2,1)
95 rmiss1=real(idrstmpl(8))
96 rmiss2=real(idrstmpl(9))
103 if (idrsnum.eq.3)
then
104 if (nbitsd.ne.0)
then
107 if (idrstmpl(17).eq.2)
then
113 call g2_gbytec(cpack,minsd,iofst,nbitsd-1)
115 if (isign.eq.1) minsd=-minsd
127 if (nbitsgref.ne.0)
then
128 call g2_gbytesc(cpack,gref,iofst,nbitsgref,0,ngroups)
129 itemp=nbitsgref*ngroups
131 if (mod(itemp,8).ne.0) iofst=iofst+(8-mod(itemp,8))
140 if (nbitsgwidth.ne.0)
then
141 call g2_gbytesc(cpack,gwidth,iofst,nbitsgwidth,0,ngroups)
142 itemp=nbitsgwidth*ngroups
144 if (mod(itemp,8).ne.0) iofst=iofst+(8-mod(itemp,8))
149 gwidth(j)=gwidth(j)+idrstmpl(11)
155 allocate(glen(ngroups),stat=is)
158 if (nbitsglen.ne.0)
then
159 call g2_gbytesc(cpack,glen,iofst,nbitsglen,0,ngroups)
160 itemp=nbitsglen*ngroups
162 if (mod(itemp,8).ne.0) iofst=iofst+(8-mod(itemp,8))
167 glen(j)=(glen(j)*idrstmpl(14))+idrstmpl(13)
169 glen(ngroups)=idrstmpl(15)
179 totbit = totbit + (gwidth(j)*glen(j));
180 totlen = totlen + glen(j);
182 if (totlen .NE. ndpts)
then
186 if ( (totbit/8) .GT. lensec)
then
193 if ( idrstmpl(7).eq.0 )
then
197 if (gwidth(j).ne.0)
then
198 call g2_gbytesc(cpack,ifld(n),iofst,gwidth(j),0,glen(j))
200 ifld(n)=ifld(n)+gref(j)
204 ifld(n:n+glen(j)-1)=gref(j)
207 iofst=iofst+(gwidth(j)*glen(j))
209 elseif ( idrstmpl(7).eq.1.OR.idrstmpl(7).eq.2 )
then
211 allocate(ifldmiss(ndpts))
217 if (gwidth(j).ne.0)
then
218 msng1=(2**gwidth(j))-1
220 call g2_gbytesc(cpack,ifld(n),iofst,gwidth(j),0,glen(j))
221 iofst=iofst+(gwidth(j)*glen(j))
223 if (ifld(n).eq.msng1)
then
225 elseif (idrstmpl(7).eq.2.AND.ifld(n).eq.msng2)
then
229 ifld(non)=ifld(n)+gref(j)
235 msng1=(2**nbitsgref)-1
237 if (gref(j).eq.msng1)
then
238 ifldmiss(n:n+glen(j)-1)=1
240 elseif (idrstmpl(7).eq.2.AND.gref(j).eq.msng2)
then
241 ifldmiss(n:n+glen(j)-1)=2
244 ifldmiss(n:n+glen(j)-1)=0
245 ifld(non:non+glen(j)-1)=gref(j)
254 if (
allocated(gref) )
deallocate(gref)
255 if (
allocated(gwidth) )
deallocate(gwidth)
256 if (
allocated(glen) )
deallocate(glen)
261 if (idrsnum.eq.3)
then
262 if (idrstmpl(17).eq.1)
then
264 if ( idrstmpl(7).eq.0 )
then
270 ifld(n)=ifld(n)+minsd
271 ifld(n)=ifld(n)+ifld(n-1)
273 elseif (idrstmpl(17).eq.2)
then
276 if ( idrstmpl(7).eq.0 )
then
282 ifld(n)=ifld(n)+minsd
283 ifld(n)=ifld(n)+(2*ifld(n-1))-ifld(n-2)
292 if ( idrstmpl(7).eq.0 )
then
294 fld(n)=((real(ifld(n))*bscale)+ref)*dscale
297 elseif ( idrstmpl(7).eq.1.OR.idrstmpl(7).eq.2 )
then
301 if ( ifldmiss(n).eq.0 )
then
302 fld(n)=((real(ifld(non))*bscale)+ref)*dscale
305 elseif ( ifldmiss(n).eq.1 )
then
307 elseif ( ifldmiss(n).eq.2 )
then
311 if (
allocated(ifldmiss) )
deallocate(ifldmiss)
314 if (
allocated(ifld) )
deallocate(ifld)