OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
ipar.c
Go to the documentation of this file.
1 /*---------------------------------------------------------------------*/
2 /* ipar.c - functions to compute instantaneous PAR */
3 /*---------------------------------------------------------------------*/
4 
5 #include "l12_proto.h"
6 #include "l2prod.h"
7 
8 static float unitc = 119.625e8; /* conversion to einsteins/m^2/s */
9 
10 #define PARW1 400
11 #define PARW2 700
12 #define PARWN (PARW2-PARW1)+1
13 
14 /*---------------------------------------------------------------------*/
15 /* get_ipar - computes ipar for each pixel in L2 record */
16 
17 /*---------------------------------------------------------------------*/
18 void get_ipar(l2str *l2rec, float ipar[]) {
19  static float badval = BAD_FLT;
20  static int firstCall = 1;
21  static int32_t nwave;
22  static float *wave;
23  static float F0vis[PARWN];
24  static float *ta;
25 
26  float Ed0p;
27  int32_t ip, ipb, iw, ib;
28 
29  l1str *l1rec = l2rec->l1rec;
30  filehandle *l1file = l1rec->l1file;
31 
32  if (firstCall) {
33 
34  firstCall = 0;
35  if ((wave = (float *) calloc(l1file->nbands, sizeof (float))) == NULL) {
36  printf("-E- %s line %d : error allocating memory for ipar:get_ipar.\n",
37  __FILE__, __LINE__);
38  exit(1);
39  }
40  for (iw = 0; iw < l1file->nbands; iw++) {
41  wave[iw] = l1file->fwave[iw];
42  }
43 
44  // instantaneous solar irradiance at 1-nm intervals
45  for (iw = PARW1; iw <= PARW2; iw++) {
46  ib = iw - PARW1;
47  get_f0_thuillier_ext(iw, 1, &F0vis[ib]);
48  F0vis[ib] *= l1rec->fsol;
49  }
50 
51  nwave = MIN(windex(PARW2, wave, l1file->nbands) + 1, l1file->nbands);
52 
53  if ((ta = (float *) calloc(nwave, sizeof (float))) == NULL) {
54  printf("-E- %s line %d : error allocating memory for ipar:get_ipar.\n",
55  __FILE__, __LINE__);
56  exit(1);
57  }
58 
59  }
60 
61  for (ip = 0; ip < l1rec->npix; ip++) {
62 
63  ipar[ip] = 0.;
64 
65  if (!l1rec->mask[ip]) {
66 
67  for (iw = 0; iw < nwave; iw++) {
68 
69  ipb = ip * l1file->nbands + iw;
70 
71  // atmospheric transmittance (sun to surface)
72  ta[iw] = l1rec->tg_sol[ipb] * l1rec->t_sol[ipb];
73  }
74 
75  for (iw = PARW1; iw <= PARW2; iw++) {
76  ib = iw - PARW1;
77  Ed0p = F0vis[ib] * l1rec->csolz[ip] * linterp(wave, ta, nwave, (float) iw);
78  ipar[ip] += ((float) iw) * Ed0p / unitc;
79  }
80 
81  if (!isfinite(ipar[ip])) {
82  ipar[ip] = badval;
83  l1rec->flags[ip] |= PRODFAIL;
84  }
85 
86  } else {
87  ipar[ip] = badval;
88  l1rec->flags[ip] |= PRODFAIL;
89  }
90  }
91 }
92 
93 /*
94  Energy of one photon = hc/lamda.
95  So the number of photons generating Ed (watts/m2/nm) is
96 
97  Ed / (hc/lamba) = Ed*lamda /(hc)
98 
99  = Ed*lamda/ (6.626e-34 J Sec. x 2.998e8 m/Sec()
100  = Ed*lamda/ (1.9865e-25 J m)
101 
102  So using lamda in nm
103 
104  (J/Sec/m2/nm) * nm * 1m/1e9nm / (1.9865e-25 J m x 6.022e23 photons / Ein)
105 
106  = (Ein/Sec/m2/nm) / 1.19625e8.
107  */
int32 l1file(int32 sdfid, int32 *nsamp, int32 *nscans, int16 *dtynum)
Definition: l1stat_chk.c:586
#define MIN(x, y)
Definition: rice.h:169
#define PARWN
Definition: ipar.c:12
#define NULL
Definition: decode_rs.h:63
#define PARW2
Definition: ipar.c:11
read l1rec
#define PRODFAIL
Definition: l2_flags.h:41
float linterp(float xin[], float yin[], int32_t nin, float xout)
Definition: lspline.c:59
#define BAD_FLT
Definition: jplaeriallib.h:19
void get_ipar(l2str *l2rec, float ipar[])
Definition: ipar.c:18
int windex(float wave, float twave[], int ntwave)
Definition: windex.c:73
#define PARW1
Definition: ipar.c:10
void get_f0_thuillier_ext(int32_t wl, int32_t width, float *f0)
Definition: get_f0.c:137