14 #include <boost/program_options.hpp> 28 {
"text", {
".dat",
".shp",
".txt",
".shape"} },
29 {
"icedb", {
".hdf5",
".nc",
".h5",
".cdf",
".hdf"} },
38 int main(
int argc,
char** argv) {
43 namespace po = boost::program_options;
44 po::options_description desc(
"Allowed options");
46 (
"help,h",
"produce help message")
47 (
"from", po::value<vector<string> >()->multitoken(),
"The paths where shapes are read from")
48 (
"to", po::value<string>(),
"The path where the shape is written to")
49 (
"db-path", po::value<string>()->default_value(
"shape"),
"The path within the database to write to")
50 (
"create",
"Create the output database if it does not exist")
51 (
"resolution", po::value<float>(),
"Lattice spacing for the shape, in um")
52 (
"truncate",
"Instead of opening existing output files in read-write mode, truncate them.")
53 (
"from-format", po::value<string>()->default_value(
"text"),
"The format of the input files. Options: text, psu.")
56 po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
59 auto doHelp = [&](
const string& s)->
void 65 if (vm.count(
"help")) doHelp(
"");
66 if (!vm.count(
"from") || !vm.count(
"to")) doHelp(
"Need to specify to/from locations.");
68 using namespace icedb;
71 vector<string> vsFromRaw = vm[
"from"].as<vector<string> >();
72 string sToRaw = vm[
"to"].as<
string>();
74 sfs::path pToRaw(sToRaw);
75 string dbpath = vm[
"db-path"].as<
string>();
76 if (vm.count(
"resolution"))
resolution_um = vm[
"resolution"].as<float>();
77 string informat = vm[
"from-format"].as<
string>();
80 auto iof = fs::IOopenFlags::READ_WRITE;
81 if (vm.count(
"create")) iof = fs::IOopenFlags::CREATE;
82 if (vm.count(
"truncate")) iof = fs::IOopenFlags::TRUNCATE;
83 if (!sfs::exists(pToRaw)) iof = fs::IOopenFlags::CREATE;
87 for (
const auto &sFromRaw : vsFromRaw)
89 sfs::path pFromRaw(sFromRaw);
91 for (
const auto &f : files)
95 if (informat ==
"text")
97 else if (informat ==
"psu")
100 .add(
"Description",
"Unknown input file format. See program help for a list of valid formats.")
101 .add(
"Current-format", informat);
111 basegrp = db->createGroupStructure(dbpath);
118 catch (
const std::exception &e) {
119 std::cerr << e.what() << std::endl;
123 std::cerr <<
"Unknown exception caught." << std::endl;
CollectedFilesRet_Type collectDatasetFiles(const sfs::path &base, const ExtensionsMatching_Type &valid_extensions)
float resolution_um
The resolution of each shape lattice, in micrometers.
const std::map< std::string, std::set< sfs::path > > file_formats
ShapeDataBasic readTextFile(const std::string &filename)
std::unique_ptr< Database > Database_ptr
float particle_scattering_element_spacing
icedb::Groups::Group::Group_ptr basegrp
Shapes get written to this location in the output database.
icedb::Shapes::Shape::Shape_Type toShape(const std::string &name, std::shared_ptr< H5::Group >) const
Make a new shape under the group.
std::unique_ptr< Groups::Group > Group_ptr
ShapeDataBasic readPSUfile(const std::string &filename)
Reads a Penn State-style geometry file.
ShapeCommonOptionalData optional
int main(int argc, char **argv)
The main body of the program.
ShapeRequiredData required