Update the GFSENS Vtable to account for the soil temperature changes
[WPS-merge.git] / ungrib / src / ngl / g2 / jpcunpack.F
blobb088994879c9965bd06055d0da4730a5098af7d9
1       subroutine jpcunpack(cpack,len,idrstmpl,ndpts,fld)
2 !$$$  SUBPROGRAM DOCUMENTATION BLOCK
3 !                .      .    .                                       .
4 ! SUBPROGRAM:    jpcunpack
5 !   PRGMMR: Gilbert          ORG: W/NP11    DATE: 2002-12-17
7 ! ABSTRACT: This subroutine unpacks a data field that was packed into a 
8 !   JPEG2000 code stream
9 !   using info from the GRIB2 Data Representation Template 5.40 or 5.40000.
11 ! PROGRAM HISTORY LOG:
12 ! 2002-12-17  Gilbert
14 ! USAGE:    CALL jpcunpack(cpack,len,idrstmpl,ndpts,fld)
15 !   INPUT ARGUMENT LIST:
16 !     cpack    - The packed data field (character*1 array)
17 !     len      - length of packed field cpack().
18 !     idrstmpl - Contains the array of values for Data Representation
19 !                Template 5.40 or 5.40000
20 !     ndpts    - The number of data values to unpack
22 !   OUTPUT ARGUMENT LIST:
23 !     fld()    - Contains the unpacked data values
25 ! REMARKS: None
27 ! ATTRIBUTES:
28 !   LANGUAGE: XL Fortran 90
29 !   MACHINE:  IBM SP
31 !$$$
33       character(len=1),intent(in) :: cpack(len)
34       integer,intent(in) :: ndpts,len
35       integer,intent(in) :: idrstmpl(*)
36       real,intent(out) :: fld(ndpts)
38       integer :: ifld(ndpts)
39       integer(4) :: ieee
40       real :: ref,bscale,dscale
41       integer :: dec_jpeg2000
42 #ifdef USE_JPEG2000
44       ieee = idrstmpl(1)
45       call rdieee(ieee,ref,1)
46       bscale = 2.0**real(idrstmpl(2))
47       dscale = 10.0**real(-idrstmpl(3))
48       nbits = idrstmpl(4)
50 !  if nbits equals 0, we have a constant field where the reference value
51 !  is the data value at each gridpoint
53       if (nbits.ne.0) then
54 !         call gbytes(cpack,ifld,0,nbits,0,ndpts)
55          iret=dec_jpeg2000(cpack,len,ifld)
56          do j=1,ndpts
57            fld(j)=((real(ifld(j))*bscale)+ref)*dscale
58          enddo
59       else
60          do j=1,ndpts
61            fld(j)=ref
62          enddo
63       endif
66 #endif /* USE_JPEG2000 */
67       return
68       end