icedb  version 0.5.1
Snow particle scattering database API
Functions
main.cpp File Reference
#include <icedb/defs.h>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include <exception>
#include <iostream>
#include <icedb/refract/refract.hpp>
#include <icedb/units/units.hpp>
#include <icedb/error.hpp>
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

std::ostream & std::operator<< (std::ostream &os, const std::vector< std::string > &vec)
 Used when listing the program options. More...
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file main.cpp.

25  {
26  using namespace std;
27  int retval = 0;
28  try {
29  using namespace icedb;
30  namespace po = boost::program_options;
31 
32  po::options_description desc("Allowed options"),
33  subst_opts("Substance options"),
34  unit_opts("Unit options"),
35  environ_opts("Environment options"),
36  scatt_matrix_opts("Scattering matrix options"),
37  scatt_provider_opts("Scattering method options"),
38  cmdline("Command-line options"),
39  config("Config options"), hidden("Hidden options"), oall("all options");
40 
41  unit_opts.add_options()
42  ("length-units", po::value<string>()->default_value("um"), "Units of length (um, mm, cm, m)")
43  ("volume-units", po::value<string>()->default_value("um^3"), "Units of volume (um^3, m^3, cm^3)")
44  ("frequency-units", po::value<string>()->default_value("GHz"), "Units of frequency (GHz, Hz)")
45  ("temperature-units", po::value<string>()->default_value("K"), "Units of temperature (K, degC)")
46  ("temp-units", po::value<string>()->default_value("K"), "Temperature units")
47  ;
48  subst_opts.add_options()
49  ("refractive-index,r", po::value<vector<string> >()->multitoken(), "Refractive indices of target (may instead specify substance and temperature)")
50  ("volume,v", po::value<vector<string> >()->multitoken(), "Volumes")
51  ("radii,a", po::value<vector<string> >()->multitoken(), "Sphere radii")
52  ("diameters,d", po::value<vector<string> >()->multitoken(), "Sphere diameters")
53 
54  ("substance,S", po::value<vector<string> >(), "Substances of interest. See icedb-refract for a list of pure substances. If not provided, you must specify refractive indices manually.")
55  ("temp,T", po::value<vector<string> >()->multitoken(), "Temperatures. Needed to calculate the refractive indices of certain substances.")
56  ;
57  environ_opts.add_options()
58  ("wavelength,w", po::value<vector<string> >()->multitoken(), "Incident wavelengths")
59  ("frequency,f", po::value<vector<string> >()->multitoken(), "Incident frequencies")
60  ("environ-refractive-index", po::value<complex<double> >()->default_value(std::complex<double>(1,0)),
61  "Refractive index of the ambient environment")
62  ;
63  scatt_matrix_opts.add_options()
64  ("angles", po::value<string>()->default_value("0:19:180:lin"), "Write the output scattering matrices at these scattering angles")
65  ;
66  scatt_provider_opts.add_options()
67  ("list-scattering-methods", "Generate a list of implemented methods for calculating scattering by spheres.")
68  ("scattering-method,M", po::value<vector<string > >()->default_value(vector<string> ({"mie"}))->multitoken(),
69  "Choose the scattering methods (mie, rayleigh, rayleigh-gans)")
70  ;
71  cmdline.add_options()
72  ("help,h", "produce help message")
73  ("help-all", "produce verbose help for all possible options")
74  ("output-cross-sections,o", po::value<string>(), "Output file for cross sections. If no output file, then these are written to stdout.")
75  ("output-short", "Write terse output. Useful when writing to screen.")
76  ("output-scatt-matrices", po::value<string>(), "Path to an HDF5 file with scattering matrix results. If unspecified, then "
77  "the scattering matrices will not be calculated.")
78  ("output-format", po::value<string>()->default_value("text"), "Output cross sections file format: text or HDF5. Must specify output-cross-sections for this to have any effect.")
79  ;
80  config.add(unit_opts).add(subst_opts).add(environ_opts).add(scatt_matrix_opts).add(scatt_provider_opts);
81  cmdline.add(config);
82 
83  desc.add(cmdline);
84  oall.add(cmdline).add(hidden);
85 
86  po::variables_map vm;
87  po::store(po::command_line_parser(argc, argv).
88  options(oall).run(), vm);
89  po::notify(vm);
90 
91  auto doHelp = [&](const std::string &m) {
92  cerr << desc << "\n" << m << endl;
93  exit(1);
94  };
95  if (vm.count("help") || argc < 2) doHelp("");
96  if (vm.count("help-all")) { cerr << oall << endl; exit(1); }
97 
98  }
99  catch (std::exception &e) {
100  cerr << "An exception has occurred: " << e.what() << endl;
101  retval = 2;
102  }
103  return retval;
104 }
STL namespace.

◆ operator<<()

std::ostream& std::operator<< ( std::ostream &  os,
const std::vector< std::string > &  vec 
)

Used when listing the program options.

Definition at line 15 of file main.cpp.

16  {
17  for (auto item : vec)
18  {
19  os << item << " ";
20  }
21  return os;
22  }