19 #include <boost/program_options.hpp> 28 int main(
int argc,
char** argv) {
34 namespace po = boost::program_options;
35 po::options_description desc(
"Allowed options");
39 (
"help,h",
"produce help message")
43 (
"dbpath,p", po::value<string>()->default_value(
"testdataset"),
"Database path")
45 (
"create",
"Create a sample database at this location")
46 (
"rw",
"Specifies that the database should be opened in read-write mode")
47 (
"ro",
"Specifies that the database should be opened in read-only mode")
53 po::store(po::command_line_parser(argc, argv).
54 options(desc).run(), vm);
60 auto doHelp = [&](
const std::string& s)->
void 62 std::cout << s << endl;
63 std::cout << desc << endl;
71 if (vm.count(
"help")) doHelp(
"");
72 if (!vm.count(
"create") && !vm.count(
"rw") && !vm.count(
"ro"))
73 doHelp(
"Must specify if the database is being created, or " 74 "opened in read-write or read-only mode.");
78 string dbpath = vm[
"dbpath"].as<
string>();
88 std::unique_ptr<icedb::Databases::Database> db;
91 if (vm.count(
"create")) {
92 std::cout <<
"Trying to create a sample database at " << dbpath << std::endl;
106 std::cout <<
"Trying to open the database at " << dbpath << std::endl;
107 std::cout <<
"Note: This will fail if the database does not exist. " 108 "If this is the case, either run with --create as an option, " 109 "or check that the database path (--dbpath) is correct." << std::endl;
111 if (vm.count(
"ro")) {
113 std::cerr <<
"You have stated that you want to open the database in " 114 "read-only mode. While this is a perfectly valid option for most " 115 "scenarios, this example program will fail with various errors. " 116 "Viewing these error messages is rather instructive, as it can help " 117 "you to become accustomed to debugging icedb." 133 std::unique_ptr<icedb::Groups::Group> grpMain = db->openGroup(
"Testing");
143 auto grpScratch = grpMain->
openGroup(
"scratch.hdf5");
146 auto grpTest1 = grpScratch->createGroup(
"Obj_1");
155 "TestDouble1", { 1 }, { 2.0 });
160 grpTest1->writeAttribute(attrDouble1);
168 { 1.0f, 2.0f, 2.5f, 3.0f });
169 grpTest1->writeAttribute(attrFloat2);
175 { 1.0f, 2.0f, 3.1f, 4.2f, 5.3f, 6.0f });
188 { 4.2f, 5.3f, 6.0f });
209 std::cout <<
"We just read TestString6 = " << readTS6.
data[0] << std::endl;
220 auto tblTest = grpTest1->createTable<int64_t>(
"Test_table_1", { 2, 3 }, { -2, -1, 0, 1, 2, 3 });
236 tblTest->writeAttribute<int64_t>(icedb::Attributes::Attribute<int64_t>(
"TestInt8", { 4 }, { 1, -1, 2, -2 }));
241 auto tblDims1 = grpTest1->createTable<int64_t>(
"X_axis", { 3 }, { 9, 10, 11 });
242 auto tblDims2 = grpTest1->createTable<int64_t>(
"Y_axis", { 2 }, { 4, 6 });
243 tblDims1->setDimensionScale(
"X_axis");
244 tblDims2->setDimensionScale(
"Y_axis");
245 tblTest->attachDimensionScale(0, tblDims2.get());
246 tblTest->attachDimensionScale(1, tblDims1.get());
259 auto grpTest2 = grpScratch->createGroup(
"Obj_Shape_2");
264 constexpr uint64_t numPoints = 8;
265 constexpr uint64_t numSubstances = 1;
266 constexpr uint64_t numAxes = 3;
269 constexpr std::array<float, numPoints * numAxes> points = {
294 shpCommonOptional.
isValid(&shpRequired, &cerr);
297 *(grpTest2.get()),
"Test_shape", shpRequired.
particle_id,
298 &shpRequired, &shpCommonOptional);
static void indexDatabase(const std::string &location)
static Shape_Type createShape(Groups::Group &grpshp, const std::string &uid, gsl::not_null< const NewShapeRequiredProperties *> required, const NewShapeCommonOptionalProperties *optional=nullptr)
Create a new shape.
Strucure containing a list of all of the required data needed to create a new shape in the database...
std::string particle_id
ATTRIBUTE: Unique Particle Identifier.
static Database_ptr createSampleDatabase(const std::string &location)
int main(int argc, char **argv)
This is an example application that illustrates how to manipulate the most basic features of an icedb...
float particle_scattering_element_spacing
OPTIONAL ATTRIBUTE: Physical spacing between adjacent grid points (in meters). Used in DDA...
std::vector< DataType > data
virtual Group_ptr openGroup(const std::string &groupName) const =0
Opens a group.
uint8_t number_of_particle_constituents
uint64_t number_of_particle_scattering_elements
Structure containing a list of all of the common optional data for creating a new shape in the databa...
gsl::span< const float > particle_scattering_element_coordinates
bool isValid(gsl::not_null< const NewShapeRequiredProperties *> required, std::ostream *errout=nullptr) const
This class defines an attribute.
static Database_ptr openDatabase(const std::string &location, fs::IOopenFlags flags=fs::IOopenFlags::READ_ONLY)
bool isValid(std::ostream *errout=nullptr) const