NCEPLIBS-g2  3.4.8
specunpack.F90
Go to the documentation of this file.
1 
4 
22 subroutine specunpack(cpack,len,idrstmpl,ndpts,JJ,KK,MM,fld)
23 
24  character(len=1),intent(in) :: cpack(len)
25  integer,intent(in) :: ndpts,len,JJ,KK,MM
26  integer,intent(in) :: idrstmpl(*)
27  real,intent(out) :: fld(ndpts)
28 
29  integer :: ifld(ndpts),Ts
30  integer(4) :: ieee
31  real :: ref,bscale,dscale,unpk(ndpts)
32  real,allocatable :: pscale(:)
33 
34  ieee = idrstmpl(1)
35  call rdieee(ieee,ref,1)
36  bscale = 2.0**real(idrstmpl(2))
37  dscale = 10.0**real(-idrstmpl(3))
38  nbits = idrstmpl(4)
39  js=idrstmpl(6)
40  ks=idrstmpl(7)
41  ms=idrstmpl(8)
42  ts=idrstmpl(9)
43 
44  if (idrstmpl(10).eq.1) then ! unpacked floats are 32-bit IEEE
45  call rdieee(cpack,unpk,ts) ! read IEEE unpacked floats
46  iofst=32*ts
47  call g2_gbytesc(cpack,ifld,iofst,nbits,0,ndpts-ts) ! unpack scaled data
48 
49  ! Calculate Laplacian scaling factors for each possible wave number.
50  allocate(pscale(jj+mm))
51  tscale=real(idrstmpl(5))*1e-6
52  do n=js,jj+mm
53  pscale(n)=real(n*(n+1))**(-tscale)
54  enddo
55 
56  ! Assemble spectral coeffs back to original order.
57  inc=1
58  incu=1
59  incp=1
60  do m=0,mm
61  nm=jj ! triangular or trapezoidal
62  if (kk .eq. jj+mm) nm=jj+m ! rhombodial
63  ns=js ! triangular or trapezoidal
64  if (ks .eq. js+ms) ns=js+m ! rhombodial
65  do n=m,nm
66  if (n.le.ns .AND. m.le.ms) then ! grab unpacked value
67  fld(inc)=unpk(incu) ! real part
68  fld(inc+1)=unpk(incu+1) ! imaginary part
69  inc=inc+2
70  incu=incu+2
71  else ! Calc coeff from packed value
72  fld(inc)=((real(ifld(incp))*bscale)+ref)*dscale*pscale(n) ! real part
73  fld(inc+1)=((real(ifld(incp+1))*bscale)+ref)*dscale*pscale(n) ! imaginary part
74  inc=inc+2
75  incp=incp+2
76  endif
77  enddo
78  enddo
79  deallocate(pscale)
80  else
81  print *,'specunpack: Cannot handle 64 or 128-bit floats.'
82  fld=0.0
83  endif
84 end subroutine specunpack
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...
Definition: g2_gbytesc.F90:63
subroutine rdieee(rieee, a, num)
Copy array of 32-bit IEEE floating point values to local floating point representation.
Definition: rdieee.F90:16
subroutine specunpack(cpack, len, idrstmpl, ndpts, JJ, KK, MM, fld)
This subroutine unpacks a spectral data field that was packed using the complex packing algorithm for...
Definition: specunpack.F90:23