Due to the lapse in federal government funding, NASA is not updating this website. We sincerely regret this inconvenience.
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 "l1_misr.h"
6 #include "geo_region.h"
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  // setting the georegion
47  if(input->georegionfile[0]){
48  float lat = l1rec->lat[ip];
49  float lon = l1rec->lon[ip];
50  if(get_georegion(lat, lon))
51  l2rec->l1rec->flags[ip] |=GEOREGION;
52  }
53  /* ------------------------------------------------ */
54  /* Ocean processing */
55  /* ------------------------------------------------ */
56  if ((input->proc_ocean != 0) &&
57  !l1rec->mask[ip] &&
58  l1rec->solz[ip] < SOLZNIGHT) {
59  if (l1rec->is_l2){
60  /* Lt values are reflectances: skip atmocor, but calc chl */
61  int nbands = l1rec->l1file->nbands;
62  for (int ib = 0; ib < nbands; ib++) {
63  int ipb = ip*nbands+ib;
64  l2rec->Rrs[ipb] = l1rec->Lt[ipb];
65  l2rec->nLw[ipb] = l2rec->Rrs[ipb]*l1rec->l1file->Fobar[ib];
66  }
67 
68  // l2rec->chl[ip] = get_default_chl(l2rec, &l2rec->Rrs[ip * nbands]);
69  l2rec->chl[ip] = get_default_chl(l2rec, l2rec->Rrs);
70  } else if (input->atmocor) {
71  /* set aerosol values from input rec, if supplied */
72 // if (input->aer_opt == AERSOA || input->aer_opt == AERSMA)
73 // status = run_soa_sma(l2rec, ip);
74 // else
75  status = atmocor2(l2rec, aerec, ip);
76 
77  /* */
78  /* If the atmospheric correction failed, flag and mask. Else,*/
79  /* set flags which depend on complete atmospheric correction.*/
80  /* */
81  if (status != 0) {
82  l2rec->l1rec->flags[ip] |= ATMFAIL;
83  l2rec->l1rec->mask[ip] = 1;
84  } else {
85  setflagbits_l2(l2rec, ip);
86  }
87 
88  }
89 
90  } // if ocean
91 
92  } // for ip
93 
94 
95  /* Load L2 rec with inherent optical properties */
96  if (l1rec->is_l2 || (input->iop_opt > 0 && (input->proc_ocean != 0) && input->atmocor)){
97  get_iops(l2rec, input->iop_opt);
98  }
99 
100  return (0);
101 }
102 
103 
104 
105 /* --------------------------------------------------------------- */
106 /* get_iops.c - load IOP (a & bb) fields in L2 rec. */
107 /* */
108 /* Inputs: */
109 /* l2rec - level-2 structure containing one complete scan */
110 /* after atmospheric correction. */
111 /* Outputs: */
112 /* iop_opt - algorithm selector */
113 /* */
114 /* Written By: B. Franz, NASA/OBPG/SAIC, 25 Feb 2005 */
115 /* */
116 
117 /* --------------------------------------------------------------- */
118 void get_iops(l2str *l2rec, int32_t iop_opt) {
119  switch (iop_opt) {
120  case IOPCARDER:
121  iops_carder(l2rec);
122  break;
123  case IOPGSM:
124  iops_gsm(l2rec);
125  break;
126  case IOPQAA:
127  iops_qaa(l2rec);
128  break;
129  case IOPPML:
130  iops_pml(l2rec);
131  break;
132  case IOPLAS:
133  iops_las(l2rec);
134  break;
135  case IOPNIWA:
136  iops_niwa(l2rec);
137  break;
138  case IOPGIOP:
139  iops_giop(l2rec);
140  break;
141  case IOPSWIM:
142  iops_swim(l2rec);
143  break;
144  default:
145  break;
146  }
147 
148  return;
149 }
#define IOPLAS
Definition: l12_parms.h:73
int get_georegion(float lat, float lon)
Definition: geo_region.cpp:51
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:321
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)
Get the sst for SST.
Definition: sst.c:219
void get_iops(l2str *l2rec, int32_t iop_opt)
Definition: convl12.c:118
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:58
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:679
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
#define GEOREGION
Definition: geo_region.h:4
void iops_giop(l2str *l2rec)
Definition: giop.c:3741
#define IOPSWIM
Definition: l12_parms.h:75
void setflagbits_l2(l2str *l2rec, int32_t ipix)
Definition: setflags_l2.c:14