NCEPLIBS-g2  3.4.8
pngunpack.F90
Go to the documentation of this file.
1 
4 
19 subroutine pngunpack(cpack, len, idrstmpl, ndpts, fld)
20  implicit none
21 
22  character(len = 1), intent(in) :: cpack(len)
23  integer, intent(in) :: ndpts, len
24  integer, intent(in) :: idrstmpl(*)
25  real, intent(out) :: fld(ndpts)
26 
27  integer :: ifld(ndpts)
28  character(len = 1), allocatable :: ctemp(:)
29  integer(4) :: ieee
30  real :: ref, bscale, dscale
31  integer :: width, height
32  integer :: iret, itype, j, nbits
33 
34  interface
35  function dec_png(pngbuf, width, height, cout) bind(c, name="dec_png")
36  use iso_c_binding
37  character(kind = c_char), intent(in) :: pngbuf(*)
38  integer(c_int), intent(in) :: width, height
39  character(kind = c_char), intent(out) :: cout(*)
40  integer(c_int) :: dec_png
41  end function dec_png
42  end interface
43 
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)
49  itype = idrstmpl(5)
50 
51  ! If nbits equals 0, we have a constant field where the reference value
52  ! is the data value at each gridpoint.
53  if (nbits .ne. 0) then
54  allocate(ctemp(ndpts * 4))
55  iret = dec_png(cpack, width, height, ctemp)
56  call g2_gbytesc(ctemp, ifld, 0, nbits, 0, ndpts)
57  deallocate(ctemp)
58  do j = 1, ndpts
59  fld(j) = ((real(ifld(j)) * bscale) + ref) * dscale
60  enddo
61  else
62  do j = 1, ndpts
63  fld(j) = ref
64  enddo
65  endif
66 end subroutine pngunpack
int dec_png(unsigned char *pngbuf, g2int *width, g2int *height, char *cout)
Decode some PNG compressed data.
Definition: dec_png.c:64
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 pngunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field packed into a PNG image format.
Definition: pngunpack.F90:20
subroutine rdieee(rieee, a, num)
Copy array of 32-bit IEEE floating point values to local floating point representation.
Definition: rdieee.F90:16