NCEPLIBS-g2c  1.6.4
jpcunpack.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "grib2.h"
9 
10 int dec_jpeg2000(char *, g2int, g2int *);
11 
30 g2int
31 jpcunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts,
32  g2float *fld)
33 {
34  g2int *ifld;
35  g2int j, nbits;
36  g2float ref, bscale, dscale;
37 
38  rdieee(idrstmpl, &ref, 1);
39  bscale = int_power(2.0, idrstmpl[1]);
40  dscale = int_power(10.0, -idrstmpl[2]);
41  nbits = idrstmpl[3];
42 
43  /* If nbits equals 0, we have a constant field where the reference
44  * value is the data value at each gridpoint. */
45  if (nbits != 0)
46  {
47  ifld = calloc(ndpts, sizeof(g2int));
48  if (ifld == 0)
49  {
50  fprintf(stderr, "Could not allocate space in jpcunpack.\n Data field NOT upacked.\n");
51  return(1);
52  }
53  dec_jpeg2000(cpack, len, ifld);
54  for (j = 0; j < ndpts; j++)
55  fld[j] = (((g2float)ifld[j] * bscale) + ref) * dscale;
56  free(ifld);
57  }
58  else
59  {
60  for (j = 0; j < ndpts; j++)
61  fld[j] = ref;
62  }
63 
64  return(0);
65 }
Header file for NCEPLIBS-g2c library.
float g2float
Float type.
Definition: grib2.h:22
int64_t g2int
Long integer type.
Definition: grib2.h:20
double int_power(double x, g2int y)
Function similar to C pow() power function.
Definition: int_power.c:17
int dec_jpeg2000(char *, g2int, g2int *)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
Definition: dec_jpeg2000.c:42
g2int jpcunpack(unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, g2float *fld)
This subroutine unpacks a data field that was packed into a JPEG2000 code stream using info from the ...
Definition: jpcunpack.c:31
void rdieee(g2int *rieee, g2float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.
Definition: rdieee.c:20