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