OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rhos_to_lt.c
Go to the documentation of this file.
1 #include "viirs_sim_sdr.h"
2 #include "l12_parms.h"
3 
4 /*#include "l12_proto.h" - Again, if we get the make more like ocssw
5  and maybe also need to move formally to that area */
6 
7 int rhos_to_lt(int rhos_opt, float **rhos, in_rec_struc *in_rec, int idet,
8  sdr_info_struc *sdr_info)
9 /*-----------------------------------------------------------------------------
10  Program: rhos_to_lt
11 
12  Description: convert the reflectance into Lt value and replace
13  the Lt conditionally for a line in a scan of lines
14 
15  Arguments:
16  Type Name I/O Description
17  ---- ---- --- -----------
18  int rhos_opt I reflectance use option: 0 - replace
19  where Lt from ocean color is missing
20  1 - replace everywhere
21  float ** rhos I a scan's worth of reflectance
22  in_rec_struc * in_rec I/O input record structure with input values
23  of atmospheric values and output of
24  final lt for simulated scan
25  int idet I line in scan to process
26  sdr_info_struc * sdr_info I general SDR information
27 
28  Modification history:
29 
30  W. Robinson, SAIC 18 Nov 2009 Original development
31  W. Robinson, SAIC 12 Apr 2011 for a reflectance that is missing -999.
32  or just < 0., set the bnd_q = 2
33 
34 ----------------------------------------------------------------------------*/ {
35  int ipx, npix, ibnd, repl, loc;
36  float lt[N_VNIR_BND], solz, mu0;
37  float tg_sol, tg_sen, t_sol, t_sen, t_o2, lr, refl;
38  /* positions of parameter fields in the l2 record, see rd_sim_init */
39  int loc_tg_sol = N_VNIR_BND * 2, loc_tg_sen = N_VNIR_BND * 3;
40  int loc_t_sol = N_VNIR_BND * 4, loc_t_sen = N_VNIR_BND * 5;
41  int loc_t_o2 = N_VNIR_BND * 7;
42  int loc_lr = N_VNIR_BND;
43 
44  npix = in_rec->npix;
45  /*
46  * get lt from rhos for all pixels and lines in the scan
47  */
48  for (ipx = 0; ipx < npix; ipx++) {
49  loc = ipx + idet * npix;
50  solz = *(in_rec->solz + loc);
51  mu0 = cos(solz / RADEG);
52 
53  /*
54  * derive the Lt for each band
55  */
56  for (ibnd = 0; ibnd < N_VNIR_BND; ibnd++) {
57  refl = *(*rhos + ipx + (idet + ibnd * in_rec->ndet_scan) * npix);
58  if (refl < 0.)
59  lt[ibnd] = -999.;
60  else {
61  lr = in_rec->l2_str.l2_data[loc_lr + ibnd][ipx];
62  t_sen = in_rec->l2_str.l2_data[loc_t_sen + ibnd][ipx];
63  t_sol = in_rec->l2_str.l2_data[loc_t_sol + ibnd][ipx];
64  t_o2 = in_rec->l2_str.l2_data[loc_t_o2 + ibnd][ipx];
65  tg_sen = in_rec->l2_str.l2_data[loc_tg_sen + ibnd][ipx];
66  tg_sol = in_rec->l2_str.l2_data[loc_tg_sol + ibnd][ipx];
67 
68  lt[ibnd] = tg_sol * tg_sen *
69  (refl * in_rec->f0[ibnd] * mu0 * t_sol * t_sen * t_o2 / PI +
70  RAD_CGS_2_MKS * lr);
71  }
72  }
73  /*
74  * examine all the ocean lt and decide on replacing it with the lt(rhos)
75  * Options are to replace if Lt < 0 or a bad value (rhos_opt=0)
76  * or replace al points (rhos_opt=1)
77  */
78  if (rhos_opt == 1)
79  repl = 1;
80  else {
81  repl = 0;
82  for (ibnd = 0; ibnd < N_VNIR_BND; ibnd++) {
83  if ((*(in_rec->bnd_lt[ibnd] + loc) < 0.) ||
84  (*(in_rec->bnd_q[ibnd] + loc) == 2)) {
85  repl = 1;
86  break;
87  }
88  }
89  /*
90  * now, assume all reflectance is good and fill
91  */
92  if (repl == 1)
93  for (ibnd = 0; ibnd < N_VNIR_BND; ibnd++) {
94  if (lt[ibnd] < -0.5) {
95  *(in_rec->bnd_lt[ibnd] + loc) = 0.;
96  *(in_rec->bnd_q[ibnd] + loc) = 2;
97  } else {
98  *(in_rec->bnd_lt[ibnd] + loc) = lt[ibnd];
99  *(in_rec->bnd_q[ibnd] + loc) = 0;
100  }
101  }
102  }
103  }
104  return 0;
105 }
float tg_sen[NBANDS]
Definition: atrem_corl1.h:127
int rhos_to_lt(int rhos_opt, float **rhos, in_rec_struc *in_rec, int idet, sdr_info_struc *sdr_info)
Definition: rhos_to_lt.c:7
#define PI
Definition: l3_get_org.c:6
float tg_sol[NBANDS]
Definition: atrem_corl1.h:127
#define RAD_CGS_2_MKS
Definition: viirs_sim_sdr.h:36
#define RADEG
Definition: czcs_ctl_pt.c:5
data_t loc[NROOTS]
Definition: decode_rs.h:78
float mu0
#define N_VNIR_BND
Definition: viirs_sim_sdr.h:31
int npix
Definition: get_cmp.c:27