OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_rhos.c
Go to the documentation of this file.
1 /* ================================================================ */
2 /* get_rhos() - computes surface reflectance. */
3 /* */
4 /* Note to users: This surface reflectance is used */
5 /* by some derived product algorithms which may not require */
6 /* full atmospheric correction. The same calculations are */
7 /* repeated for standard atmospheric correction over ocean. */
8 /* */
9 /* Written By: B. A. Franz, SAIC GSC, NASA/SIMBIOS, April 2000 */
10 /* Based on code provided by Jacques Descloitres */
11 /* W. Robinson, SAIC, 7 Nov 2012, for radiance < 0, return */
12 /* reflectance of BAD_FLT */
13 /* */
14 /* ================================================================ */
15 
16 #include <math.h>
17 #include "l12_proto.h"
18 
19 double fintexp3(float taur);
20 double fintexp1(float taur);
21 float csalbr(float taur);
22 
23 int get_rhos(l1str *l1rec, int32_t ip) {
24  static float pi = 3.141592654;
25  static float radeg = 180. / 3.141592654;
26  static float p0 = 1013.25;
27  static int firstCall = TRUE;
28  static float sphalb[5000];
29 
30  float mu0 = cos(l1rec->solz[ip] / radeg);
31 
32  float Ka = 0.8;
33  float Taur;
34  int32_t i, ib, ipb;
35  int32_t cirrus_opt = input->cirrus_opt;
36 
37  /* */
38  /* Derive spherical albedo correction table */
39  /* */
40  if (firstCall) {
41  firstCall = FALSE;
42  sphalb[0] = 0.0;
43  for (i = 1; i < 5000; i++)
44  sphalb[i] = csalbr(i / 10000.);
45  }
46  /* */
47  /* Loop through bands and compute transmittance and reflectance */
48  /* */
49  for (ib = 0; ib < l1rec->l1file->nbands; ib++) {
50 
51  ipb = ip * l1rec->l1file->nbands + ib;
52 
53  /* Compute surface reflectance */
54  if (l1rec->Lt[ipb] > 0.) {
55  if (cirrus_opt)
56  l1rec->rhos[ipb] = pi / l1rec->Fo[ib] / mu0
57  * ((l1rec->Lt[ipb] / l1rec->tg_sol[ipb] / l1rec->tg_sen[ipb]
58  - l1rec->Lr[ipb]) - l1rec->rho_cirrus[ip] / Ka)
59  / l1rec->t_sol[ipb] / l1rec->t_sen[ipb] / l1rec->t_o2[ipb] / l1rec->t_h2o[ipb];
60  else
61  l1rec->rhos[ipb] = pi / l1rec->Fo[ib] / mu0
62  * (l1rec->Lt[ipb] / l1rec->tg_sol[ipb] / l1rec->tg_sen[ipb]
63  - l1rec->Lr[ipb])
64  / l1rec->t_sol[ipb] / l1rec->t_sen[ipb] / l1rec->t_o2[ipb] / l1rec->t_h2o[ipb];
65 
66  /* Correct for spherical albedo (atmosphere-surface interaction).*/
67  /* Note that for Ocean processing, these effects are already */
68  /* included in the Rayleigh radiances, based on a priori */
69  /* knowledge of the ocean surface reflectance as fn of windspeed.*/
70  if (l1rec->land[ip]) {
71  Taur = l1rec->l1file->Tau_r[ib] * l1rec->pr[ip] / p0;
72  l1rec->rhos[ipb] /=
73  (1 + sphalb[(int) (Taur * 10000 + 0.5)] * l1rec->rhos[ipb]);
74  }
75  } else
76  l1rec->rhos[ipb] = BAD_FLT;
77  }
78  return (0);
79 }
80 
81 
82 /* ------------------------------------------------------------------------ */
83 /* Code below was provided by Jacques Descloitres, March 2000 */
84 /* */
85 /* changed expf, logf to exp, log, to fix problems with 64-bit solaris */
86 /* BAF, 8/2002. */
87 
88 /* ------------------------------------------------------------------------ */
89 
90 float csalbr(float xtau) {
91  return (3 * xtau - fintexp3(xtau)*(4 + 2 * xtau) + 2 * exp(-xtau)) / (4 + 3 * xtau);
92 }
93 
94 double fintexp3(float xtau) {
95  return (exp(-xtau)*(1. - xtau) + xtau * xtau * fintexp1(xtau)) / 2.;
96 }
97 
98 double fintexp1(float xtau) {
99  double xx, xftau;
100  int i;
101  const float a[6] = {-.57721566, 0.99999193, -0.24991055,
102  0.05519968, -0.00976004, 0.00107857};
103  xx = a[0];
104  xftau = 1.;
105  for (i = 1; i < 6; i++) {
106  xftau *= xtau;
107  xx += a[i] * xftau;
108  }
109  return xx - log(xtau);
110 }
111 
#define FALSE
Definition: rice.h:164
read l1rec
const double pi
#define TRUE
Definition: rice.h:165
instr * input
character(len=1000) if
Definition: names.f90:13
float csalbr(float taur)
Definition: get_rhos.c:90
int get_rhos(l1str *l1rec, int32_t ip)
Definition: get_rhos.c:23
double fintexp3(float taur)
Definition: get_rhos.c:94
#define BAD_FLT
Definition: jplaeriallib.h:19
float mu0
int i
Definition: decode_rs.h:71
PGE01 indicating that PGE02 PGE01 V6 for and PGE01 V2 for MOD03 were used to produce the granule By convention adopted in all MODIS Terra PGE02 code versions are The fourth digit of the PGE02 version denotes the LUT version used to produce the granule The source of the metadata environment variable ProcessingCenter was changed from a QA LUT value to the Process Configuration A sign used in error in the second order term was changed to a
Definition: HISTORY.txt:424
double fintexp1(float taur)
Definition: get_rhos.c:98