OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rd_sim_init.c
Go to the documentation of this file.
1 #include "viirs_sim_sdr.h"
2 #include "l12_parms.h"
3 
4 int rd_sim_init(ctl_struc *ctl, sdr_info_struc *sdr_info,
5  in_rec_struc *in_rec)
6 /*-----------------------------------------------------------------------------
7  Routine: rd_sim_init
8 
9  Description: prepare the simulator input files for use
10  It will prepare the input files, including the geolocation
11  file and the level-2 file containing the TOA radiances
12 
13  Arguments:
14  Type Name I/O Description
15  ---- ---- --- -----------
16  ctl_struc * ctl I program argument controls
17  sdr_info_struc * sdr_info I/O general SDR information
18  in_rec_struc * in_rec I/O input file information
19 
20  Modification history:
21 
22  W. Robinson, SAIC 20 Nov 2008 Original development
23  W. Robinson, SAIC 16 Nov 2009 if reflectance file is used, set up to
24  read extra atmospheric parameters from
25  the L2 file
26 
27 ----------------------------------------------------------------------------*/ {
28  char parm_list[2000];
29  char *atm_prm_root[] = {"Lr_", "tg_sol_", "tg_sen_", "t_sol_", "t_sen_",
30  "t_h2o_", "t_o2_"};
31  int iprm, ibnd, nchr, sptr;
32  /*
33  * set up the geolocation file
34  */
35  if (rd_geo_init(ctl, sdr_info, in_rec)
36  != 0) return 1;
37  /*
38  * make space for the half angle mirror side array with the # of scans
39  */
40  if ((sdr_info->ham_side = (unsigned char *)
41  malloc(in_rec->nscan * sizeof ( unsigned char))) == NULL) {
42  printf("%s, %d: Error, failed to allocate ham_side storage\n",
43  __FILE__, __LINE__);
44  return 1;
45  }
46  /*
47  * the # bands to use is determined by the make_m
48  */
49  in_rec->nbnd = (ctl->make_m == 0) ? N_VNIR_BND : MAX_BND;
50  /*
51  * Also, set up the input L2
52  */
53  if (ctl->l2_use == 1) {
54  /*
55  * set the parm list to be the VIIRS bands and if rhos_use is set,
56  * also get required extra atmospheric parameters
57  */
58  sptr = 0;
59  for (ibnd = 0; ibnd < N_VNIR_BND; ibnd++) {
60  nchr = sprintf((parm_list + sptr), "vLt_%d:",
61  *(in_rec->lam_band + ibnd));
62  sptr += nchr;
63  }
64  if (ctl->rhos_use == 1) {
65  for (iprm = 0; iprm < 7; iprm++) {
66  for (ibnd = 0; ibnd < N_VNIR_BND; ibnd++) {
67  nchr = sprintf((parm_list + sptr), "%s%d:",
68  *(atm_prm_root + iprm), *(in_rec->lam_band + ibnd));
69  sptr += nchr;
70  }
71  }
72  }
73  *(parm_list + sptr - 1) = 0;
74 
75  printf("%s: initializing input from L2 file: %s\n", __FILE__,
76  ctl->l2_file);
77  if (openL2(ctl->l2_file, parm_list, &in_rec->l2_str) != 0) {
78  printf("%s, %d: Failure to open L2 TOA dataset: %s\n", __FILE__,
79  __LINE__, ctl->l2_file);
80  return 1;
81  }
82  } else {
83  printf("%s, %d: Dummy L2 data initialization (none currently)\n",
84  __FILE__, __LINE__);
85  /* call blnk_l2_init if ever needed or do in line */
86  }
87  return 0;
88  /*
89  * and exit
90  */
91 }
int32_t openL2(const char *fname, char *plist, l2_prod *l2_str)
Definition: readL2scan.c:296
#define NULL
Definition: decode_rs.h:63
#define MAX_BND
Definition: viirs_sim_sdr.h:34
int rd_sim_init(ctl_struc *ctl, sdr_info_struc *sdr_info, in_rec_struc *in_rec)
Definition: rd_sim_init.c:4
int rd_geo_init(ctl_struc *ctl, sdr_info_struc *sdr_info, in_rec_struc *in_rec)
Definition: rd_geo_init.c:9
#define N_VNIR_BND
Definition: viirs_sim_sdr.h:31