OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
vcal.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <math.h>
3 #include "l12_proto.h"
4 
5 static int32_t npix = -1;
6 static int32_t nbands = -1;
7 static vcstr vrec;
8 
9 int alloc_vcal(int32_t npix, int32_t nbands, vcstr *rec);
10 
11 void vgain(l2str *l2rec, int band, float vgain[]) {
12  int32_t ip, ipb;
13 
14  for (ip = 0; ip < npix; ip++) {
15  ipb = ip * nbands + band;
16  if (vrec.vLt[ipb] > 0.0 && l2rec->l1rec->Lt[ipb] > 0.0) {
17  vgain[ip] = vrec.vLt[ipb] / (l2rec->l1rec->Lt[ipb] / l1_input->gain[band]);
18  } else
19  vgain[ip] = -1.0;
20  }
21 
22  return;
23 }
24 
25 void vcal(l2str *l2rec, l2prodstr *p, float prod[]) {
26  static int firstCall = 1;
27  static int32_t lastScan = -1;
28 
29  int32_t ip, ipb;
30  int32_t band = p->prod_ix;
31 
32  if (firstCall) {
33  npix = l2rec->l1rec->npix;
34  nbands = l2rec->l1rec->l1file->nbands;
35  if (alloc_vcal(npix, nbands, &vrec) == 0) {
36  printf("-E- %s: Unable to allocate vcal record.\n", __FILE__);
37  exit(1);
38  }
39  firstCall = 0;
40  }
41 
42  if (l2rec->l1rec->iscan != lastScan) {
43  convl21(l2rec, l2rec->tgrec, 0, npix - 1, vrec.vLt, &vrec);
44  lastScan = l2rec->l1rec->iscan;
45  }
46 
47  switch (p->cat_ix) {
48  case CAT_vgain:
49  vgain(l2rec, band, prod);
50  break;
51  case CAT_vLt:
52  for (ip = 0; ip < npix; ip++) {
53  ipb = ip * nbands + band;
54  prod[ip] = vrec.vLt[ipb];
55  }
56  break;
57  case CAT_vtLw:
58  for (ip = 0; ip < npix; ip++) {
59  ipb = ip * nbands + band;
60  prod[ip] = vrec.tLw[ipb];
61  }
62  break;
63  case CAT_vLw:
64  for (ip = 0; ip < npix; ip++) {
65  ipb = ip * nbands + band;
66  prod[ip] = vrec.Lw[ipb];
67  }
68  break;
69  case CAT_vnLw:
70  for (ip = 0; ip < npix; ip++) {
71  ipb = ip * nbands + band;
72  prod[ip] = vrec.nLw[ipb];
73  }
74  break;
75  case CAT_vbsat:
76  for (ip = 0; ip < npix; ip++) {
77  ipb = ip * nbands + band;
78  prod[ip] = vrec.brdfsat[ipb];
79  }
80  break;
81  case CAT_vbtgt:
82  for (ip = 0; ip < npix; ip++) {
83  ipb = ip * nbands + band;
84  prod[ip] = vrec.brdftgt[ipb];
85  }
86  break;
87  }
88 
89  return;
90 }
int alloc_vcal(int32_t npix, int32_t nbands, vcstr *rec)
Definition: alloc_vcal.c:12
void vcal(l2str *l2rec, l2prodstr *p, float prod[])
Definition: vcal.c:25
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
#define CAT_vLw
Definition: l2prod.h:154
void vgain(l2str *l2rec, int band, float vgain[])
Definition: vcal.c:11
#define CAT_vnLw
Definition: l2prod.h:155
#define CAT_vgain
Definition: l2prod.h:151
#define CAT_vbtgt
Definition: l2prod.h:157
l1_input_t * l1_input
Definition: l1_options.c:9
#define CAT_vbsat
Definition: l2prod.h:156
int32_t nbands
#define CAT_vtLw
Definition: l2prod.h:153
int convl21(l2str *l2rec, tgstr *tgrec, int32_t spix, int32_t epix, float *vLt, vcstr *vrec)
Definition: convl21.c:15
#define CAT_vLt
Definition: l2prod.h:152
int npix
Definition: get_cmp.c:27
float p[MODELMAX]
Definition: atrem_corl1.h:131