OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
atmocor1_land.c
Go to the documentation of this file.
1 /* ================================================================ */
2 /* atmocor1_land - computes atmospheric components over land. */
3 /* */
4 /* Written By: B. A. Franz, SAIC GSC, NASA/SIMBIOS, April 2000 */
5 /* Based on code provided by Jacques Descloitres */
6 /* */
7 /* ================================================================ */
8 
9 #include <math.h>
10 #include "l12_proto.h"
11 
12 
13 void chand(float xphi, float xmuv, float xmus, float *xtau,
14  float *rhoray, double *trup, double *trdown, int nbands);
15 
16 int atmocor1_land(l1str *l1rec, int32_t ip) {
17  static float pi = 3.141592654;
18  static float radeg = 180. / 3.141592654;
19  static float p0 = 1013.25;
20 
21  float delphi = l1rec->delphi[ip] + 180.0;
22  float mu0 = cos(l1rec->solz[ip] / radeg);
23  float mu = cos(l1rec->senz[ip] / radeg);
24  float airmass = 1.0 / mu0 + 1.0 / mu;
25  int nbands = l1rec->l1file->nbands;
26 
27  float *Taur;
28  float *rhor;
29  double *trup;
30  double *trdown;
31 
32  float Tauoz;
33 
34  int32_t ib, ipb;
35 
36  if ((Taur = (float *) calloc(nbands, sizeof (float))) == NULL) {
37  printf("-E- : Error allocating memory to Taur\n");
38  exit(FATAL_ERROR);
39  }
40  if ((rhor = (float *) calloc(nbands, sizeof (float))) == NULL) {
41  printf("-E- : Error allocating memory to rhor\n");
42  exit(FATAL_ERROR);
43  }
44  if ((trup = (double *) calloc(nbands, sizeof (double))) == NULL) {
45  printf("-E- : Error allocating memory to trup\n");
46  exit(FATAL_ERROR);
47  }
48  if ((trdown = (double *) calloc(nbands, sizeof (double))) == NULL) {
49  printf("-E- : Error allocating memory to trdown\n");
50  exit(FATAL_ERROR);
51  }
52 
53  /* */
54  /* First, correct Rayleigh optical thickness for pressure. */
55  /* */
56  for (ib = 0; ib < nbands; ib++) {
57  Taur[ib] = l1rec->l1file->Tau_r[ib] * l1rec->pr[ip] / p0;
58  }
59 
60  /* */
61  /* Compute Rayleigh path reflectances, also total diff. trans. */
62  /* */
63  chand(delphi, mu, mu0, Taur, rhor, trup, trdown, nbands);
64 
65  /* */
66  /* Loop through bands and compute transmittance and reflectance */
67  /* */
68  for (ib = 0; ib < l1rec->l1file->nbands; ib++) {
69 
70  ipb = ip * l1rec->l1file->nbands + ib;
71 
72  /* Compute and store Rayleigh radiance and diff trans */
73  l1rec->Lr[ipb] = rhor[ib] * l1rec->Fo[ib] * mu0 / pi;
74  l1rec->t_sol[ipb] =
75  ((2.0 / 3.0 + mu0) + (2.0 / 3.0 - mu0) * trdown[ib])
76  / (4.0 / 3.0 + Taur[ib]);
77  l1rec->t_sen[ipb] =
78  ((2.0 / 3.0 + mu) + (2.0 / 3.0 - mu) * trup [ib])
79  / (4.0 / 3.0 + Taur[ib]);
80 
81  /* no way to comput polarization correction over land */
82  l1rec->polcor[ipb] = 1.0;
83 
84  /* Compute gaseous transmittance functions */
85  Tauoz = l1rec->l1file->k_oz[ib] * l1rec->oz[ip];
86  l1rec->tg_sol[ipb] = exp(-Tauoz / mu0);
87  l1rec->tg_sen[ipb] = exp(-Tauoz / mu);
88 
89  if (l1rec->l1file->sensorID == SEAWIFS)
90  l1rec->t_h2o[ipb] = water_vapor(ib, l1rec->wv[ip], airmass);
91  else
92  l1rec->t_h2o[ipb] = 1.0;
93 
94  l1rec->t_o2[ipb] = 1.0;
95 
96  }
97 
98  free(Taur);
99  free(rhor);
100  free(trup);
101  free(trdown);
102 
103  return (0);
104 }
105 
106 
107 /* ------------------------------------------------------------------------ */
108 /* Code below was provided by Jacques Descloitres, March 2000 */
109 /* ------------------------------------------------------------------------ */
110 
111 #define fac 0.0174532925199 /* PI/180 */
112 
113 void chand(float xphi, float xmuv, float xmus, float *xtau, float *rhoray, double *trup, double *trdown, int nbands) {
114  /*
115  input parameters: xphi,xmus,xmuv,xtau
116  xphi: azimuthal difference between sun and observation (xphi=0,
117  in backscattering) and expressed in degree (0.:360.)
118  xmus: cosine of the sun zenith angle
119  xmuv: cosine of the observation zenith angle
120  xtau: molecular optical depth
121  output parameter: xrray : molecular reflectance (0.:1.)
122  constant : xdep: depolarization factor (0.0279)
123  xfd = (1-xdep/(2-xdep)) / (1 + 2*xdep/(2-xdep)) = 2 * (1 - xdep) / (2 + xdep) = 0.958725775
124 
125  chAnged all instances of expf, logf, and cosf to exp, log, cos, to fix problems
126  with 64-bit solaris systems. BAF, 8/2002.
127  */
128  const double xfd = 0.958725775;
129  const float xbeta2 = 0.5;
130  float pl[5];
131  double fs01, fs02, fs0, fs1, fs2;
132  const float as0[10] = {0.33243832, 0.16285370, -0.30924818, -0.10324388, 0.11493334,
133  -6.777104e-02, 1.577425e-03, -1.240906e-02, 3.241678e-02, -3.503695e-02};
134  const float as1[2] = {.19666292, -5.439061e-02};
135  const float as2[2] = {.14545937, -2.910845e-02};
136  float phios, xcosf1, xcosf2, xcosf3;
137  float xph1, xph2, xph3, xitm1, xitm2;
138  float xlntau, xitot1, xitot2, xitot3;
139  int i, ib;
140 
141  phios = 180 - xphi;
142  xcosf1 = 1.;
143  xcosf2 = cos(phios * fac);
144  xcosf3 = cos(2 * phios * fac);
145  xph1 = 1 + (3 * xmus * xmus - 1) * (3 * xmuv * xmuv - 1) * xfd / 8.;
146  xph2 = -xfd * xbeta2 * 1.5 * xmus * xmuv * sqrt(1 - xmus * xmus) * sqrt(1 - xmuv * xmuv);
147  xph3 = xfd * xbeta2 * 0.375 * (1 - xmus * xmus) * (1 - xmuv * xmuv);
148  pl[0] = 1.;
149  pl[1] = xmus + xmuv;
150  pl[2] = xmus * xmuv;
151  pl[3] = xmus * xmus + xmuv * xmuv;
152  pl[4] = xmus * xmus * xmuv * xmuv;
153  fs01 = fs02 = 0;
154  for (i = 0; i < 5; i++) fs01 += pl[i] * as0[i];
155  for (i = 0; i < 5; i++) fs02 += pl[i] * as0[5 + i];
156  for (ib = 0; ib < nbands; ib++) {
157  xlntau = log(xtau[ib]);
158  fs0 = fs01 + fs02 * xlntau;
159  fs1 = as1[0] + xlntau * as1[1];
160  fs2 = as2[0] + xlntau * as2[1];
161  trdown[ib] = exp(-xtau[ib] / xmus);
162  trup[ib] = exp(-xtau[ib] / xmuv);
163  xitm1 = (1 - trdown[ib] * trup[ib]) / 4. / (xmus + xmuv);
164  xitm2 = (1 - trdown[ib]) * (1 - trup[ib]);
165  xitot1 = xph1 * (xitm1 + xitm2 * fs0);
166  xitot2 = xph2 * (xitm1 + xitm2 * fs1);
167  xitot3 = xph3 * (xitm1 + xitm2 * fs2);
168  rhoray[ib] = xitot1 * xcosf1 + xitot2 * xcosf2 * 2 + xitot3 * xcosf3 * 2;
169  }
170 
171 }
void chand(float xphi, float xmuv, float xmus, float *xtau, float *rhoray, double *trup, double *trdown, int nbands)
#define NULL
Definition: decode_rs.h:63
read l1rec
const double pi
float mu
#define fac
float water_vapor
Definition: atrem_corl1.h:226
#define FATAL_ERROR
Definition: swl0_parms.h:5
int atmocor1_land(l1str *l1rec, int32_t ip)
Definition: atmocor1_land.c:16
int32_t nbands
float mu0
#define SEAWIFS
Definition: sensorDefs.h:12
int i
Definition: decode_rs.h:71