NASA Logo
Ocean Color Science Software

ocssw V2022
l2extract_3d_wv.cpp
Go to the documentation of this file.
1 #include "l2extract_3d_wv.h"
2 
3 #include <expand3D.hpp>
4 
5 
15 void get_wv3_indexes(const char *inp_file, const char *wv_list,
16  int **wv_vals_out, int **wv_indexes_out,
17  int *wv_num_to_pass, const char *prod_list) {
18  try {
19  netCDF::NcFile l2_file(inp_file, netCDF::NcFile::read);
20  auto grp = l2_file.getGroup("sensor_band_parameters");
21  {
22  if (grp.getVar("wavelength_3d").isNull()) {
23  if (std::string(wv_list).length() > 0) {
24  std::cerr << "No wavelength 3D are found in the L2 file "
25  << inp_file << " but the user supplied it";
26  exit(EXIT_FAILURE);
27  }
28  return;
29  }
30  if (std::string(wv_list).length() == 0) {
31  std::cout << "No wavelength_3d list is supplied by the user. "
32  "All wavelength 3D will be in output "
33  << std::endl;
34  return;
35  }
36  }
37  auto dims_wv_3d = grp.getVar("wavelength_3d").getDims();
38  size_t wv_3d_len = 1;
39  std::for_each(
40  dims_wv_3d.begin(), dims_wv_3d.end(),
41  [&](const netCDF::NcDim &dim) { wv_3d_len *= dim.getSize(); });
42  std::vector<int> wv_3d_vals(wv_3d_len, 0);
43  grp.getVar("wavelength_3d").getVar(wv_3d_vals.data());
44  std::unordered_map<int, int> wv_3d_vals_lut;
45  int count = 0;
46  std::for_each(wv_3d_vals.begin(), wv_3d_vals.end(),
47  [&](const int &val) {
48  wv_3d_vals_lut.insert({val, count});
49  count++;
50  });
51  static std::vector<int> wv_requested_vals,wv_requested_indexes;
52  parse_wv_list(wv_list, wv_3d_vals_lut,wv_requested_vals,wv_requested_indexes);
53  l2_file.close();
54  *wv_vals_out = wv_requested_vals.data();
55  *wv_indexes_out = wv_requested_indexes.data();
56  *wv_num_to_pass = (int)wv_requested_vals.size();
57  } catch (netCDF::exceptions::NcException const &e) {
58  e.what();
59  exit(EXIT_FAILURE);
60  } catch (std::exception const &e) {
61  std::cerr << "Error opening file for reading: " << e.what()
62  << std::endl;
63  exit(EXIT_FAILURE);
64  }
65 }
@ string
void get_wv3_indexes(const char *inp_file, const char *wv_list, int **wv_vals_out, int **wv_indexes_out, int *wv_num_to_pass, const char *prod_list)
Get the wv3 indexes object.
void parse_wv_list(const std::string &wv_list, const std::unordered_map< int, int > &wv3d_list, std::vector< int > &wv_requested_vals, std::vector< int > &wv_requested_indexes, bool exit_on_not_found)
Definition: expand3D.cpp:70
int count
Definition: decode_rs.h:79