OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rd_sdr_scan.c
Go to the documentation of this file.
1 #include "viirs_sim_sdr.h"
2 #include <stdlib.h>
3 
4 int rd_sdr_scan(int iscn, ctl_struc *ctl, sdr_info_struc *sdr_info,
5  in_rec_struc *in_rec)
6 /*-----------------------------------------------------------------------------
7  Program: rd_sdr_scan.c
8 
9  Description: get all scan oriented data from simulated data sources
10 
11  Arguments:
12  Type Name I/O Description
13  ---- ---- --- -----------
14  int iscn I scan to read
15  ctl_struc * ctl I processing controls
16  sdr_info_struc * sdr_info I general sdr information
17  in_rec_struc * in_rec I/O input record controls
18 
19  Modification history:
20 
21  W. Robinson, SAIC 21 Oct 2008 Original development
22  W. Robinson, SAIC 17 Feb 2010 update readL2 call seq for added last
23  (and undefined) parameter
24  W. Robinson, SAIC 12 Mar 2010 adapt to process whole scans
25 
26 ----------------------------------------------------------------------------*/ {
27  int ipix, ibnd, ilin, idet;
28  static float *rhos = NULL;
29  float rad;
30  /*
31  * place the ham side in the in_rec
32  */
33  in_rec->ham_side = *(sdr_info->ham_side + iscn);
34  /*
35  * read the geoloc SDR
36  */
37  if (rd_geo_scan(iscn, sdr_info, in_rec) != 0) return 1;
38  /*
39  * Proceed to reading up the band files
40  */
41  switch (ctl->l2_use) {
42  case 0:
43  /*
44  printf( "%s-temp: no Lt data file option, making constant line\n",
45  __FILE__ );
46  */
47  if (gen_const_rad_scn(sdr_info, 0, in_rec) != 0) {
48  printf("%s, %d: call to gen_const_rad_scn failed on line %d\n",
49  __FILE__, __LINE__, iscn);
50  return 1;
51  }
52  break;
53  case 1:
54  /*
55  * get a scan of reflectance if needed
56  */
57  if (ctl->rhos_use == 1)
58  if (rd_rhos_scan(ctl->rhos_file, in_rec->npix, iscn,
59  in_rec->ndet_scan, &rhos) != 0) return 1;
60  /*
61  * get the L2 line and move the radiances into the input record
62  * convert from milliwatt cm^-2... to w m^-2...
63  * (some other l2 info may also go there in the future)
64  */
65  for (idet = 0; idet < in_rec->ndet_scan; idet++) {
66  ilin = idet + iscn * in_rec->ndet_scan;
67  if (readL2(&(in_rec->l2_str), 0, ilin, -1, NULL) != 0) {
68  printf("%s, %d: call to readL2 failed on line %d\n",
69  __FILE__, __LINE__, ilin);
70  return 1;
71  }
72  for (ibnd = 0; ibnd < N_VNIR_BND; ibnd++) {
73  for (ipix = 0; ipix < in_rec->npix; ipix++) {
74  /* remember to check for a bad value and note it */
75  rad = in_rec->l2_str.l2_data[ibnd][ipix];
76  if ((rad == in_rec->l2_str.bv_unscaled[ibnd]) ||
77  (rad < -0.5)) {
78  *(in_rec->bnd_q[ibnd] + idet * in_rec->npix + ipix) = 2;
79  *(in_rec->bnd_lt[ibnd] + idet * in_rec->npix + ipix) = 0.;
80  } else {
81  *(in_rec->bnd_lt[ibnd] + idet * in_rec->npix + ipix) =
82  rad * RAD_CGS_2_MKS;
83  *(in_rec->bnd_q[ibnd] + idet * in_rec->npix + ipix) = 0;
84  }
85  }
86  }
87  /*
88  * If requested, convert reflectance to Lt using L2 fields for
89  * that line and fill in the SDR radiances
90  */
91  if (ctl->rhos_use == 1) {
92  if (rhos_to_lt(ctl->rhos_opt, &rhos, in_rec, idet, sdr_info) != 0)
93  return 1;
94  }
95  /*
96  * finally, if the rest of the bands are done, put in typical values
97  */
98  if (in_rec->nbnd > N_VNIR_BND) {
99  if (gen_const_rad_scn(sdr_info, N_VNIR_BND, in_rec) != 0) {
100  printf("%s, %d: call to gen_const_rad_scn failed on line %d\n",
101  __FILE__, __LINE__, iscn);
102  return 1;
103  }
104  }
105  }
106  break;
107  default:
108  printf("%s: Bad Lt input source, Exiting\n",
109  __FILE__);
110  return 1;
111  break;
112  }
113  return 0;
114 }
int rd_geo_scan(int iscn, sdr_info_struc *sdr_info, in_rec_struc *in_rec)
Definition: rd_geo_scan.c:3
int rhos_to_lt(int rhos_opt, float **rhos, in_rec_struc *in_rec, int idet, sdr_info_struc *sdr_info)
Definition: rhos_to_lt.c:7
#define NULL
Definition: decode_rs.h:63
int gen_const_rad_scn(sdr_info_struc *sdr_info, int st_bnd, in_rec_struc *in_rec)
int rd_rhos_scan(char *file, int npix, int iscn, int ndet, float **rhos)
Definition: rd_rhos_scan.c:8
int32_t readL2(l2_prod *l2_str, int32_t ifile, int32_t recnum, int32_t iprod, unsigned char *scan_in_rowgroup)
Definition: readL2scan.c:1250
#define RAD_CGS_2_MKS
Definition: viirs_sim_sdr.h:36
#define N_VNIR_BND
Definition: viirs_sim_sdr.h:31
int rd_sdr_scan(int iscn, ctl_struc *ctl, sdr_info_struc *sdr_info, in_rec_struc *in_rec)
Definition: rd_sdr_scan.c:4