icedb  version 0.5.1
Snow particle scattering database API
Functions | Variables
shapes-main.cpp File Reference
#include <icedb/defs.h>
#include <boost/program_options.hpp>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <icedb/shape.hpp>
#include <icedb/Database.hpp>
#include <icedb/fs_backend.hpp>
#include "shape.hpp"
#include "shapeIOtext.hpp"
Include dependency graph for shapes-main.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

const std::map< std::string, std::set< sfs::path > > file_formats
 3d_structures_example program - Shows you how to write a shape More...
 
float resolution_um = 0
 The resolution of each shape lattice, in micrometers. More...
 
icedb::Groups::Group::Group_ptr basegrp
 Shapes get written to this location in the output database. More...
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 36 of file shapes-main.cpp.

References basegrp, icedb::Examples::Shapes::ShapeRequiredData::particle_id, icedb::Examples::Shapes::readTextFile(), icedb::Examples::Shapes::ShapeDataBasic::required, and resolution_um.

36  {
37  try {
38  using namespace std;
39  // Read program options
40 
41  namespace po = boost::program_options;
42  po::options_description desc("Allowed options");
43  desc.add_options()
44  ("help,h", "produce help message")
45  ("from", po::value<string>(), "The path where a shape is read from")
46  ("to", po::value<string>(), "The path where the shape is written to")
47  ("db-path", po::value<string>()->default_value("shape"), "The path within the database to write to")
48  ("create", "Create the output database if it does not exist")
49  ("resolution", po::value<float>(), "Lattice spacing for the shape, in um")
50  ("truncate", "Instead of opening existing output files in read-write mode, truncate them.")
51  ;
52  po::variables_map vm;
53  po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
54  po::notify(vm);
55 
56  auto doHelp = [&](const string& s)->void
57  {
58  cout << s << endl;
59  cout << desc << endl;
60  exit(1);
61  };
62  if (vm.count("help")) doHelp("");
63  if (!vm.count("from") || !vm.count("to")) doHelp("Need to specify to/from locations.");
64 
65  using namespace icedb;
66 
67  // namespace sfs defined for compatability. See <icedb/fs_backend.hpp>
68  string sFromRaw = vm["from"].as<string>();
69  string sToRaw = vm["to"].as<string>();
70  sfs::path pFromRaw(sFromRaw);
71  sfs::path pToRaw(sToRaw);
72  string dbpath = vm["db-path"].as<string>();
73  if (vm.count("resolution")) resolution_um = vm["resolution"].as<float>();
74 
75  // Create the output database if it does not exist
76  auto iof = fs::IOopenFlags::READ_WRITE;
77  if (vm.count("create")) iof = fs::IOopenFlags::CREATE;
78  if (vm.count("truncate")) iof = fs::IOopenFlags::TRUNCATE;
79  if (!sfs::exists(pToRaw)) iof = fs::IOopenFlags::CREATE;
80  Databases::Database::Database_ptr db = Databases::Database::openDatabase(pToRaw.string(), iof);
81 
82  // Reading the shape from the text file
83  auto data = icedb::Examples::Shapes::readTextFile(pFromRaw.string());
84  // Set a basic particle id. This id is used when writing the shape to the output file.
85  // In this example, objects in the output file are named according to their ids.
86  data.required.particle_id = pFromRaw.filename().string();
87  if (resolution_um)
88  data.optional.particle_scattering_element_spacing = resolution_um / 1.e6f;
89 
90  // Writing the shape to the HDF5/netCDF file
91 
92  basegrp = db->createGroupStructure(dbpath);
93  auto shp = data.toShape(data.required.particle_id, basegrp->getHDF5Group());
94  }
95  // Ensure that unhandled errors are displayed before the application terminates.
96  catch (const std::exception &e) {
97  std::cerr << e.what() << std::endl;
98  return 1;
99  }
100  catch (...) {
101  std::cerr << "Unknown exception caught." << std::endl;
102  return 1;
103  }
104  return 0;
105 }
STL namespace.
float resolution_um
The resolution of each shape lattice, in micrometers.
Definition: shapes-main.cpp:76
ShapeDataBasic readTextFile(const std::string &filename)
std::unique_ptr< Database > Database_ptr
Definition: Database.hpp:20
icedb::Groups::Group::Group_ptr basegrp
Shapes get written to this location in the output database.
Definition: shapes-main.cpp:79
Here is the call graph for this function:

Variable Documentation

◆ basegrp

Shapes get written to this location in the output database.

Definition at line 34 of file shapes-main.cpp.

◆ file_formats

const std::map<std::string, std::set<sfs::path> > file_formats
Initial value:
= {
{"text", {".dat", ".shp", ".txt", ".shape"} },
{"icedb", {".hdf5", ".nc", ".h5", ".cdf", ".hdf"} }
}

3d_structures_example program - Shows you how to write a shape

This program reads shape files (in ADDA or DDSCAT formats) and writes an HDF5/netCDF file as an output. The program demonstrates how to create shapes using the library's C++ interface.

Here's how the program works:

  1. Read the user options.
  2. Read the shape.
  3. Write the shape.

Definition at line 26 of file shapes-main.cpp.

◆ resolution_um

float resolution_um = 0

The resolution of each shape lattice, in micrometers.

Definition at line 32 of file shapes-main.cpp.