OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
polcor_hawkeye.cpp
Go to the documentation of this file.
1 /*
2  * Implement the polarization correction for Hawkeye
3  */
4 
5 #include <netcdf>
6 #include "polcor_hawkeye.h"
7 
8 #include <math.h>
9 
10 #include <allocate2d.h>
11 
12 #include "l12_proto.h"
13 
14 using namespace std;
15 using namespace netCDF;
16 using namespace netCDF::exceptions;
17 
18 // global variables
19 static bool firstRun = true;
20 static float** m12;
21 static float** m13;
22 
23 
24 extern "C" void polcor_hawkeye(l1str *l1rec, int32_t ip) {
25  int numBands = l1rec->l1file->nbands;
26 
27  if(firstRun) {
28  firstRun = false;
29 
30  int numPixels = l1rec->npix;
31  try {
32  NcFile ncFile(input->polfile, NcFile::read);
33  NcVar ncVar = ncFile.getVar("m12");
34  int lutNumBands = ncVar.getDim(0).getSize();
35  if(lutNumBands != numBands) {
36  printf("-E- %s:%d - Problem reading polfile %s\n", __FILE__, __LINE__, input->polfile);
37  printf(" L1 file #bands=%d, LUT m12 #bands=%d\n", numBands, lutNumBands);
38  exit(EXIT_FAILURE);
39  }
40  int lutNumPixels = ncVar.getDim(1).getSize();
41  if(lutNumPixels != numPixels) {
42  printf("-E- %s:%d - Problem reading polfile %s\n", __FILE__, __LINE__, input->polfile);
43  printf(" L1 file #pix=%d, LUT m12 #pix=%d\n", numPixels, lutNumPixels);
44  exit(EXIT_FAILURE);
45  }
46  m12 = allocate2d_float(numBands, numPixels);
47  ncVar.getVar(m12[0]);
48 
49  ncVar = ncFile.getVar("m13");
50  lutNumBands = ncVar.getDim(0).getSize();
51  if(lutNumBands != numBands) {
52  printf("-E- %s:%d - Problem reading polfile %s\n", __FILE__, __LINE__, input->polfile);
53  printf(" L1 file #bands=%d, LUT m13 #bands=%d\n", numBands, lutNumBands);
54  exit(EXIT_FAILURE);
55  }
56  lutNumPixels = ncVar.getDim(1).getSize();
57  if(lutNumPixels != numPixels) {
58  printf("-E- %s:%d - Problem reading polfile %s\n", __FILE__, __LINE__, input->polfile);
59  printf(" L1 file #pix=%d, LUT m13 #pix=%d\n", numPixels, lutNumPixels);
60  exit(EXIT_FAILURE);
61  }
62  m13 = allocate2d_float(numBands, numPixels);
63  ncVar.getVar(m13[0]);
64 
65  } catch (NcException& e) {
66  printf("-E- %s:%d - Problem reading polfile %s\n", __FILE__, __LINE__, input->polfile);
67  printf(" %s\n", e.what());
68  exit(EXIT_FAILURE);
69  }
70  } // firstRun
71 
72  for(int band=0; band<numBands; band++) {
73  int ipb = ip * numBands + band;
74 
75  double alpha = l1rec->alpha[ip] / RADEG;
76  double L_x = l1rec->Lt[ipb] / l1rec->tg_sol[ipb] / l1rec->tg_sen[ipb];
77  double L_qp = l1rec->L_q[ipb] * cos(2 * alpha) + l1rec->L_u[ipb] * sin(2 * alpha);
78  double L_up = l1rec->L_u[ipb] * cos(2 * alpha) - l1rec->L_q[ipb] * sin(2 * alpha);
79 
80  l1rec->polcor[ipb] = 1.0 / (1.0 - m12[band][ip] * L_qp / L_x - m13[band][ip] * L_up / L_x);
81  l1rec->dpol[ipb] = sqrt(pow(l1rec->L_q[ipb], 2.0) + pow(l1rec->L_u[ipb], 2.0)) / L_x;
82  } //for bands
83 
84 
85 }
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
instr * input
NcFile * ncFile
void polcor_hawkeye(l1str *l1rec, int32_t ip)
#define RADEG
Definition: czcs_ctl_pt.c:5
Utility functions for allocating and freeing two-dimensional arrays of various types.
float ** allocate2d_float(size_t h, size_t w)
Allocate a two-dimensional array of type float of a given size.
Definition: allocate2d.c:125