Skip to content

Instantly share code, notes, and snippets.

@gicmo
Created March 4, 2014 17:35
Show Gist options
  • Save gicmo/9351530 to your computer and use it in GitHub Desktop.
Save gicmo/9351530 to your computer and use it in GitHub Desktop.
[hack] Test for time information in HDF5's H5O_info_t obtained via H5Oget_info
#include <hdf5.h>
#include <H5Cpp.h>
#include <vector>
#include <ctime>
#include <string>
#include <iostream>
#include <thread>
using namespace H5;
const int NX = 5; // dataset dimensions
const int NY = 6;
static void
dump_info(hid_t objid, const std::string &name)
{
H5O_info_t info;
H5Oget_info(objid, &info);
std::cout << "--- " << name << std::endl;
std::cout << "atime: " << info.atime << " " << std::ctime(&info.atime);
std::cout << "mtime: " << info.mtime << " " << std::ctime(&info.mtime);
std::cout << "ctime: " << info.ctime << " " << std::ctime(&info.ctime);
std::cout << "btime: " << info.btime << " " << std::ctime(&info.btime);
std::cout << "---" << std::endl;
}
int main(int argc, char **argv)
{
hbool_t htrue = true;
int i, j;
int data[NX][NY]; // buffer for data to write
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++)
data[j][i] = i + j;
}
FileCreatPropList fplist;
H5Pset_obj_track_times(fplist.getId(), true);
H5File* file = new H5File("test.h5", H5F_ACC_TRUNC, fplist);
hsize_t fdim[] = {NX, NY}; // dim sizes of ds (on disk)
DataSpace fspace( 2, fdim);
int fillvalue = 0; /* Fill value for the dataset */
DSetCreatPropList plist;
plist.setFillValue(PredType::NATIVE_INT, &fillvalue);
H5Pset_obj_track_times(plist.getId(), true);
hid_t gPlist = H5Pcreate(H5P_GROUP_CREATE);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
hid_t gapl = H5Pcreate(H5P_GROUP_ACCESS);
H5Pset_obj_track_times(gPlist, true);
hid_t gid = H5Gcreate2(file->getId(), "group", lcpl, gPlist, gapl);
dump_info(gid, "group");
file->createDataSet("ds", PredType::NATIVE_INT, fspace, plist);
DataSet* dataset = new DataSet(file->openDataSet("ds"));
std::chrono::milliseconds dura(200);
std::this_thread::sleep_for(dura);
dataset->write(data, PredType::NATIVE_INT);
dump_info(dataset->getId(), "dataset");
dump_info(file->getId(), "file");
delete dataset;
delete file;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment