OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1_imgscale.c
Go to the documentation of this file.
1 #include "l12_proto.h"
2 #include "input_struc.h"
3 #define INT32 int32_t
4 #define FLOAT32 float
5 #define BYTE unsigned char
6 
7 /* -------------------------------------------------------------- */
8 float toa_reflect(l1str *l1rec, int32_t ip, int32_t ib) {
9  int32_t ipb;
10  float mu0;
11  static float pi = 3.141592654;
12  float rho;
13 
14  mu0 = cos(l1rec->solz[ip] * pi / 180.);
15  ipb = ip * l1rec->l1file->nbands + ib;
16  rho = l1rec->Lt[ipb] * pi / l1rec->Fo[ib] / mu0;
17  return (rho);
18 }
19 
20 
21 /* -------------------------------------------------------------- */
22 /* linscale() - linear reflectance scaling */
23 
24 /* -------------------------------------------------------------- */
25 BYTE linscale(FLOAT32 x, FLOAT32 minrad, FLOAT32 maxrad) {
26 
27  if (x >= maxrad || x <= 0)
28  return (255);
29 
30  if (x <= minrad)
31  return (0);
32 
33  return (BYTE) ((x - minrad)*255.0 / maxrad);
34 }
35 
36 
37 /* -------------------------------------------------------------- */
38 /* linscale() - linear scaling */
39 
40 /* -------------------------------------------------------------- */
42  float maxrad = 15.0;
43  float minrad = 0.0;
44 
45  switch (band) {
46  case 0: minrad = 0;
47  maxrad = 15;
48  break;
49  case 4: minrad = 0;
50  maxrad = 12;
51  break;
52  case 5: minrad = 0;
53  maxrad = 10;
54  break;
55  /*
56  case 2: minrad=0; maxrad=30; break;
57  case 4: minrad=0; maxrad=24; break;
58  case 5: minrad=0; maxrad=20; break;
59  */
60  default: break;
61  }
62 
63  if (x >= maxrad || x <= 0)
64  return (250);
65 
66  if (x <= minrad)
67  return (0);
68 
69  return (BYTE) ((x - minrad)*250.0 / maxrad);
70 }
71 
72 /* -------------------------------------------------------------- */
73 /* scale() - log scaling of reflectance */
74 
75 /* -------------------------------------------------------------- */
77  int32_t scaleval;
78  /* Save a few calls to the log function. */
79  static double logmaxmin = 1, lastmin = 0, lastmax = 0;
80 
81  if (min != lastmin || max != lastmax) {
82 
83  logmaxmin = log(max / min);
84  lastmin = min;
85  lastmax = max;
86  }
87 
88  if (val > min)
89  /*scaleval = ((log10(val) + 2.0)/(2.0/255));*/
90  scaleval = rint(255 * log(val / min) / logmaxmin);
91  else
92  scaleval = 0;
93  if (scaleval < 0) return ( 0);
94  if (scaleval > 255) return (255);
95  return ((BYTE) scaleval);
96 }
These are used to scale the SD before writing it to the HDF4 file The default is and which means the product is not scaled at all Since the product is usually stored as a float inside of this is a way to write the float out as a integer l2prod min
read l1rec
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second band
const double pi
float toa_reflect(l1str *l1rec, int32_t ip, int32_t ib)
Definition: l1_imgscale.c:8
BYTE logscale(FLOAT32 val, FLOAT32 min, FLOAT32 max)
Definition: l1_imgscale.c:76
unsigned char BYTE
Definition: elements.h:4
BYTE linscale(FLOAT32 x, FLOAT32 minrad, FLOAT32 maxrad)
Definition: l1_imgscale.c:25
float FLOAT32
Definition: elements.h:7
float mu0
BYTE linscale_old(FLOAT32 x, int band)
Definition: l1_imgscale.c:41
double rint(double)
msiBandIdx val
Definition: l1c_msi.cpp:34
l2prod max