OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
convl12.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "l12_proto.h"
5 #include "l1b_misr.h"
6 
7 /* ---------------------------------------------------------- */
8 /* Converts a sensor-generic level-1b record to level-2 */
9 /* */
10 /* B. A. Franz, GSC, SIMBIOS Project, March 1998 */
11 /* W. Robinson, SAIC 15 Dec 2006 fix Western, Eastern most */
12 /* long for CZCS */
13 
14 /* ---------------------------------------------------------- */
15 
16 int convl12(l1str *l1rec, l2str *l2rec, int32_t spix, int32_t epix,
17  aestr *aerec) {
18  int32_t ip; /* Pixel index */
19  int32_t status; /* 0=OK, 1=bad */
20 
21  /* */
22  /* Clear the L2 record */
23  /* */
24  init_l2(l2rec, l1rec->l1file->nbands);
25 
26  /* Point L2 rec to computed SST, if requested (before atmcor) */
27  if (input->proc_sst)
28  l2rec->sst = get_sst(l2rec);
29  else
30  l2rec->sst = NULL;
31 
32  if (l1rec->l1file->sensorID == MISR) {
33  misr_t *private_data = l1rec->l1file->private_data;
34  int32_t block = l1rec->iscan / 128;
35  if (private_data->multipleInput == 1) block /= 9;
36  if(//private_data->isOceanBlock[block] == 0 ||
37  (block+1) < private_data->startBlock ||
38  (block+1) > private_data->endBlock)
39  return 0;
40  }
41 
42  /* */
43  /* Loop through each pixel and do atmospheric correction*/
44  /* */
45  for (ip = spix; ip <= epix; ip++) {
46 
47  /* ------------------------------------------------ */
48  /* Ocean processing */
49  /* ------------------------------------------------ */
50  if ((input->proc_ocean != 0) &&
51  !l1rec->mask[ip] &&
52  l1rec->solz[ip] < SOLZNIGHT) {
53 
54  if (l1rec->is_l2){
55  /* Lt values are reflectances: skip atmocor, but calc chl */
56  int nbands = l1rec->l1file->nbands;
57  for (int ib = 0; ib < nbands; ib++) {
58  int ipb = ip*nbands+ib;
59  l2rec->Rrs[ipb] = l1rec->Lt[ipb];
60  l2rec->nLw[ipb] = l2rec->Rrs[ipb]*l1rec->l1file->Fobar[ib];
61  }
62 
63  // l2rec->chl[ip] = get_default_chl(l2rec, &l2rec->Rrs[ip * nbands]);
64  l2rec->chl[ip] = get_default_chl(l2rec, l2rec->Rrs);
65  } else if (input->atmocor) {
66  /* set aerosol values from input rec, if supplied */
67 // if (input->aer_opt == AERSOA || input->aer_opt == AERSMA)
68 // status = run_soa_sma(l2rec, ip);
69 // else
70  status = atmocor2(l2rec, aerec, ip);
71 
72  /* */
73  /* If the atmospheric correction failed, flag and mask. Else,*/
74  /* set flags which depend on complete atmospheric correction.*/
75  /* */
76  if (status != 0) {
77  l2rec->l1rec->flags[ip] |= ATMFAIL;
78  l2rec->l1rec->mask[ip] = 1;
79  } else {
80  setflagbits_l2(l2rec, ip);
81  }
82 
83  }
84 
85  } // if ocean
86 
87  } // for ip
88 
89 
90  /* Load L2 rec with inherent optical properties */
91  if (l1rec->is_l2 || (input->iop_opt > 0 && (input->proc_ocean != 0) && input->atmocor)){
92  get_iops(l2rec, input->iop_opt);
93  }
94 
95  return (0);
96 }
97 
98 
99 
100 /* --------------------------------------------------------------- */
101 /* get_iops.c - load IOP (a & bb) fields in L2 rec. */
102 /* */
103 /* Inputs: */
104 /* l2rec - level-2 structure containing one complete scan */
105 /* after atmospheric correction. */
106 /* Outputs: */
107 /* iop_opt - algorithm selector */
108 /* */
109 /* Written By: B. Franz, NASA/OBPG/SAIC, 25 Feb 2005 */
110 /* */
111 
112 /* --------------------------------------------------------------- */
113 void get_iops(l2str *l2rec, int32_t iop_opt) {
114  switch (iop_opt) {
115  case IOPCARDER:
116  iops_carder(l2rec);
117  break;
118  case IOPGSM:
119  iops_gsm(l2rec);
120  break;
121  case IOPQAA:
122  iops_qaa(l2rec);
123  break;
124  case IOPPML:
125  iops_pml(l2rec);
126  break;
127  case IOPLAS:
128  iops_las(l2rec);
129  break;
130  case IOPNIWA:
131  iops_niwa(l2rec);
132  break;
133  case IOPGIOP:
134  iops_giop(l2rec);
135  break;
136  case IOPSWIM:
137  iops_swim(l2rec);
138  break;
139  default:
140  break;
141  }
142 
143  return;
144 }
#define IOPLAS
Definition: l12_parms.h:73
int status
Definition: l1_czcs_hdf.c:32
void iops_carder(l2str *l2rec)
Definition: carder.c:1013
#define NULL
Definition: decode_rs.h:63
read l1rec
#define IOPGSM
Definition: l12_parms.h:69
int atmocor2(l2str *l2rec, aestr *aerec, int32_t ip)
Definition: atmocor2.c:11
void iops_qaa(l2str *l2rec)
Definition: get_qaa.c:335
void iops_niwa(l2str *l2rec)
Definition: get_niwa_iop.c:109
instr * input
#define IOPGIOP
Definition: l12_parms.h:74
#define IOPCARDER
Definition: l12_parms.h:68
#define IOPQAA
Definition: l12_parms.h:70
int convl12(l1str *l1rec, l2str *l2rec, int32_t spix, int32_t epix, aestr *aerec)
Definition: convl12.c:16
float * get_sst(l2str *l2rec)
Definition: sst.c:7606
void get_iops(l2str *l2rec, int32_t iop_opt)
Definition: convl12.c:113
void iops_swim(l2str *l2rec)
Definition: swim.c:799
void init_l2(l2str *l2rec, int32_t nbands)
Definition: init_l2.c:11
#define ATMFAIL
Definition: l2_flags.h:11
#define MISR
Definition: sensorDefs.h:40
#define SOLZNIGHT
Definition: l1.h:57
void iops_pml(l2str *l2rec)
Definition: get_pml.c:313
void iops_gsm(l2str *l2rec)
Definition: gsm.c:883
#define IOPPML
Definition: l12_parms.h:71
#define IOPNIWA
Definition: l12_parms.h:72
float get_default_chl(l2str *l2rec, float Rrs[])
Definition: get_chl.c:392
int32_t nbands
int32 spix
Definition: l1_czcs_hdf.c:21
int32 epix
Definition: l1_czcs_hdf.c:23
void iops_las(l2str *l2rec)
Definition: las_iop.c:581
void iops_giop(l2str *l2rec)
Definition: giop.c:2734
#define IOPSWIM
Definition: l12_parms.h:75
void setflagbits_l2(l2str *l2rec, int32_t ipix)
Definition: setflags_l2.c:14