NCEPLIBS-g2  3.4.5
specpack.f
Go to the documentation of this file.
1 
5 
21 
22  subroutine specpack(fld,ndpts,JJ,KK,MM,idrstmpl,cpack,lcpack)
23 
24  real,intent(in) :: fld(ndpts)
25  integer,intent(in) :: ndpts,JJ,KK,MM
26  integer,intent(inout) :: idrstmpl(*)
27  character(len=1),intent(out) :: cpack(*)
28  integer,intent(out) :: lcpack
29 
30  integer :: ifld(ndpts),Ts,tmplsim(5)
31  real :: bscale,dscale,unpk(ndpts),tfld(ndpts)
32  real,allocatable :: pscale(:)
33 
34  bscale = 2.0**real(-idrstmpl(2))
35  dscale = 10.0**real(idrstmpl(3))
36  nbits = idrstmpl(4)
37  js=idrstmpl(6)
38  ks=idrstmpl(7)
39  ms=idrstmpl(8)
40  ts=idrstmpl(9)
41 
42 !
43 ! Calculate Laplacian scaling factors for each possible wave number.
44 !
45  allocate(pscale(jj+mm))
46  tscale=real(idrstmpl(5))*1e-6
47  do n=js,jj+mm
48  pscale(n)=real(n*(n+1))**(tscale)
49  enddo
50 !
51 ! Separate spectral coeffs into two lists; one to contain unpacked
52 ! values within the sub-spectrum Js, Ks, Ms, and the other with values
53 ! outside of the sub-spectrum to be packed.
54 !
55  inc=1
56  incu=1
57  incp=1
58  do m=0,mm
59  nm=jj ! triangular or trapezoidal
60  if ( kk .eq. jj+mm ) nm=jj+m ! rhombodial
61  ns=js ! triangular or trapezoidal
62  if ( ks .eq. js+ms ) ns=js+m ! rhombodial
63  do n=m,nm
64  if (n.le.ns .AND. m.le.ms) then ! save unpacked value
65  unpk(incu)=fld(inc) ! real part
66  unpk(incu+1)=fld(inc+1) ! imaginary part
67  inc=inc+2
68  incu=incu+2
69  else ! Save value to be packed and scale
70  ! Laplacian scale factor
71  tfld(incp)=fld(inc)*pscale(n) ! real part
72  tfld(incp+1)=fld(inc+1)*pscale(n) ! imaginary part
73  inc=inc+2
74  incp=incp+2
75  endif
76  enddo
77  enddo
78 
79  deallocate(pscale)
80 
81  incu=incu-1
82  if (incu .ne. ts) then
83  print *,'specpack: Incorrect number of unpacked values ',
84  & 'given:',ts
85  print *,'specpack: Resetting idrstmpl(9) to ',incu
86  ts=incu
87  endif
88 !
89 ! Add unpacked values to the packed data array in 32-bit IEEE format
90 !
91  call mkieee(unpk,cpack,ts)
92  ipos=4*ts
93 !
94 ! Scale and pack the rest of the coefficients
95 !
96  tmplsim(2)=idrstmpl(2)
97  tmplsim(3)=idrstmpl(3)
98  tmplsim(4)=idrstmpl(4)
99  call simpack(tfld,ndpts-ts,tmplsim,cpack(ipos+1),lcpack)
100  lcpack=lcpack+ipos
101 !
102 ! Fill in Template 5.51
103 !
104  idrstmpl(1)=tmplsim(1)
105  idrstmpl(2)=tmplsim(2)
106  idrstmpl(3)=tmplsim(3)
107  idrstmpl(4)=tmplsim(4)
108  idrstmpl(9)=ts
109  idrstmpl(10)=1 ! Unpacked spectral data is 32-bit IEEE
110 
111  return
112  end
specpack
subroutine specpack(fld, ndpts, JJ, KK, MM, idrstmpl, cpack, lcpack)
This subroutine packs a spectral data field using the complex packing algorithm for spherical harmoni...
Definition: specpack.f:23
simpack
subroutine simpack(fld, ndpts, idrstmpl, cpack, lcpack)
This subroutine packs up a data field using a simple packing algorithm as defined in the GRIB2 docume...
Definition: simpack.f:34
mkieee
subroutine mkieee(a, rieee, num)
This subroutine stores a list of real values in 32-bit IEEE floating point format.
Definition: mkieee.f:17