OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
cdom_mannino.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <math.h>
3 #include "l12_proto.h"
4 
5 static float badval = BAD_FLT;
6 
7 void cdom_mannino(l2str *l2rec, int prodnum, float prod[]) {
8  static int firstCall = 1;
9  static int ib1 = -1;
10  static int ib2 = -1;
11 
12  static float b_ag412[] = {-2.784, -1.146, 1.008};
13  static float b_sg275[] = {-3.325, 0.3, -0.252};
14  static float b_sg300[] = {-3.679, 0.168, -0.134};
15 
16  l1str *l1rec = l2rec->l1rec;
17  int32_t nbands = l1rec->l1file->nbands;
18 
19  float *wave = l1rec->l1file->fwave;
20  float *b;
21  float *Rrs, Rrs1, Rrs2;
22  float x1, x2;
23  int32_t ip;
24 
25  if (firstCall) {
26  firstCall = 0;
27  ib1 = bindex_get(443);
28  ib2 = bindex_get(545);
29  if (ib2 < 0) ib2 = bindex_get(550);
30  if (ib2 < 0) ib2 = bindex_get(555);
31  if (ib2 < 0) ib2 = bindex_get(560);
32  if (ib2 < 0) ib2 = bindex_get(565);
33  if (ib1 < 0 || ib2 < 0) {
34  printf("-E- %s line %d: required bands not available for Stramski POC\n",
35  __FILE__, __LINE__);
36  exit(1);
37  }
38  }
39 
40  switch (prodnum) {
41  case CAT_ag_412_mlrc:
42  b = b_ag412;
43  break;
45  b = b_sg275;
46  break;
48  b = b_sg300;
49  break;
50  default:
51  printf("Error: %s : Unknown product specifier: %d\n", __FILE__, prodnum);
52  exit(1);
53  break;
54  }
55 
56  for (ip = 0; ip < l1rec->npix; ip++) {
57 
58  prod[ip] = badval;
59 
60  Rrs = &l2rec->Rrs[ip * nbands];
61  Rrs1 = Rrs[ib1];
62  Rrs2 = Rrs[ib2];
63 
64  if (Rrs1 > 0.0 && Rrs2 > 0.0) {
65 
66  Rrs2 = conv_rrs_to_555(Rrs2, wave[ib2]);
67 
68  x1 = log(Rrs1);
69  x2 = log(Rrs2);
70 
71  prod[ip] = exp(b[0] + b[1] * x1 + b[2] * x2);
72 
73  } else {
74  l1rec->flags[ip] |= PRODFAIL;
75  }
76 
77  }
78 
79  return;
80 }
81 
82 
#define CAT_Sg_300_600_mlrc
Definition: l2prod.h:314
read l1rec
#define CAT_ag_412_mlrc
Definition: l2prod.h:312
#define PRODFAIL
Definition: l2_flags.h:41
int bindex_get(int32_t wave)
Definition: windex.c:45
#define CAT_Sg_275_295_mlrc
Definition: l2prod.h:313
data_t b[NROOTS+1]
Definition: decode_rs.h:77
#define BAD_FLT
Definition: jplaeriallib.h:19
int32_t nbands
void cdom_mannino(l2str *l2rec, int prodnum, float prod[])
Definition: cdom_mannino.c:7
float conv_rrs_to_555(float Rrs, float wave)
Definition: convert_band.c:17