OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
geom_per_band.c
Go to the documentation of this file.
1 /*
2  * file geom_per_band.c - generic operations needed for the
3  * band-dependent geometry capability
4  */
5 #include "l1.h"
6 
8 /*-----------------------------------------------------------------------
9  init_geom_per_band
10 
11  purpose: set up the band-dependent geometry storage
12 
13  Returns 0 if all checks are OK
14  Parameters: (in calling order)
15  Type Name I/O Description
16  ---- ---- --- -----------
17  l1str * l1rec I record containing the band-
18  dependent geometry fields and
19  the sizes in pixels, bands
20 
21  Modification history:
22  Programmer Date Description of change
23  ---------- ---- ---------------------
24  Wayne Robinson 2 Dec 2016 Original development
25 
26  -----------------------------------------------------------------------*/ {
27  int32_t nbands, npix;
28 
29  nbands = l1rec->l1file->nbands;
30  npix = l1rec->npix;
31  l1rec->geom_per_band = (geom_struc *) malloc(sizeof (geom_struc));
32  l1rec->geom_per_band->senz =
33  (float *) malloc(npix * nbands * sizeof (float));
34  l1rec->geom_per_band->sena =
35  (float *) malloc(npix * nbands * sizeof (float));
36  l1rec->geom_per_band->csenz =
37  (float *) malloc(npix * nbands * sizeof (float));
38  l1rec->geom_per_band->solz =
39  (float *) malloc(npix * nbands * sizeof (float));
40  l1rec->geom_per_band->sola =
41  (float *) malloc(npix * nbands * sizeof (float));
42  l1rec->geom_per_band->csolz =
43  (float *) malloc(npix * nbands * sizeof (float));
44  l1rec->geom_per_band->delphi =
45  (float *) malloc(npix * nbands * sizeof (float));
46  l1rec->geom_per_band->scattang =
47  (float *) malloc(npix * nbands * sizeof (float));
48  return 0;
49 }
50 
52 /*-----------------------------------------------------------------------
53  geom_per_band_deriv
54 
55  purpose: derive the other band-dependent geometry quantities
56 
57  Returns 0 if all checks are OK
58  Parameters: (in calling order)
59  Type Name I/O Description
60  ---- ---- --- -----------
61  l1str * l1rec I record containing the band-
62  dependent geometry fields and
63  the sizes in pixels, bands
64 
65  Modification history:
66  Programmer Date Description of change
67  ---------- ---- ---------------------
68  Wayne Robinson 10 Jan 2017 Original development
69 
70  -----------------------------------------------------------------------*/ {
71  static double radeg = RADEG;
72  double temp;
73  int32_t nbands, npix, ip, ib, ipb;
74  geom_struc *geom = l1rec->geom_per_band;
75 
76  nbands = l1rec->l1file->nbands;
77  npix = l1rec->npix;
78  /* This just creates the csolz, csola, delphi, and scattang for the
79  band-dependent geometry values */
80  for (ib = 0; ib < nbands; ib++) {
81  for (ip = 0; ip < npix; ip++) {
82  ipb = ip * nbands + ib;
83 
84  /* relative azimuth */
85  geom->delphi[ipb] = geom->sena[ipb] - 180.0 - geom->sola[ipb];
86  if (geom->delphi[ipb] < -180.) geom->delphi[ipb] += 360.0;
87  else if (geom->delphi[ipb] > 180.0)
88  geom->delphi[ipb] -= 360.0;
89 
90  /* frequently used trig relations */
91  geom->csolz[ipb] = cos(geom->solz[ipb] / radeg);
92  geom->csenz[ipb] = cos(geom->senz[ipb] / radeg);
93 
94  /* Scattering angle */
95  temp = sqrt((1.0 - geom->csenz[ipb] * geom->csenz[ipb])*
96  (1.0 - geom->csolz[ipb] * geom->csolz[ipb]))
97  * cos(geom->delphi[ipb] / radeg);
98  geom->scattang[ipb] = acos(MAX(-geom->csenz[ipb] * geom->csolz[ipb] +
99  temp, -1.0)) * radeg;
100  }
101  }
102  return 0;
103 }
#define MAX(A, B)
Definition: swl0_utils.h:26
int init_geom_per_band(l1str *l1rec)
Definition: geom_per_band.c:7
read l1rec
int geom_per_band_deriv(l1str *l1rec)
Definition: geom_per_band.c:51
geom_str geom
Definition: aerosol.c:206
#define RADEG
Definition: czcs_ctl_pt.c:5
int32_t nbands
int npix
Definition: get_cmp.c:27