I am trying to create an hdf5 file that is extendable, has attributes, and
is  compressed. Along with this my hdf5 has a Compound datatype that
includes members. All of this is simple to create when you have static
members:



    #include <vector>

    #include <string>

    #include <iostream>

    #include <H5Cpp.h>

    using namespace H5;

    using namespace std;


    const double NULL_VALUE = -999.99;


    const int ATTR_DIM = 1;

    const int ATTR_RANK = 1;

    const int CHUNK_RANK = 1;

    const hsize_t CHUNK_DIM[2] = {1, 365};

    const int STRTYPE_LENGTH = 20;

    const int COMPRESS_RATE = 6;


    const H5std_string STATIONID("stationID");

    const H5std_string STARTUP("startup");

    const H5std_string SAMPLERATE("samplerate");


    int main(void)

    {

      string filename = "NEALL01_60.h5";

      vector<string> sensors;

      string datasetName = "60";

      int dimSize = 1000;

      string stationID = "NEALL01";

      string startup = "1988-05-10 05:00:00";

      int samplerate = 60;

      hsize_t attrdim[] = {ATTR_DIM};

      DataSpace attrspace(ATTR_RANK, attrdim);

      StrType strdatatype(H5::PredType::C_S1, STRTYPE_LENGTH);

      const H5std_string stationIDBuff (stationID);

      const H5std_string startupBuff (startup);

      const H5std_string samplerateBuff (std::to_string(samplerate));

      hsize_t maxdim[] = {H5S_UNLIMITED, H5S_UNLIMITED};



      sensors.push_back("ml2_10cm");

      sensors.push_back("ml2_20cm");

      int rank = 1;


      typedef struct s1_t {

        double a;

        double b;

      } s1_t;



      int  i;

      s1_t s1[dimSize];

      for (i = 0; i< dimSize; i++)

      {

        s1[i].a = NULL_VALUE;

        s1[i].b = NULL_VALUE;

      }



      hsize_t dim[] = {dimSize};

      DataSpace space(rank, dim, maxdim);



      H5File *file = new H5File(filename, H5F_ACC_TRUNC);



      CompType mtype1(sizeof(s1_t));



      int count = 0;

      for (auto a = sensors.cbegin(); a < sensors.cend(); ++a)

      {

        mtype1.insertMember(*a, sizeof(double)*count,
PredType::NATIVE_DOUBLE);

        count++;

      }



      DSetCreatPropList creatplist;

      creatplist.setChunk(CHUNK_RANK, CHUNK_DIM);

      creatplist.setDeflate(COMPRESS_RATE);



      DataSet *dataset;

      dataset = new DataSet(file->createDataSet(datasetName, mtype1, space,
creatplist));



      dataset->write(s1, mtype1);



      Attribute myatt1 = dataset->createAttribute(STATIONID, strdatatype,
attrspace);

      Attribute myatt2 = dataset->createAttribute(STARTUP, strdatatype,
attrspace);

      Attribute myatt3 = dataset->createAttribute(SAMPLERATE, strdatatype,
attrspace);

      myatt1.write(strdatatype, stationIDBuff);

      myatt2.write(strdatatype, startupBuff);

      myatt3.write(strdatatype, samplerateBuff);



      delete dataset;

      delete file;

    }


But, I dont know the amount of members to be added to the dataset until
run-time. In this case a struct will not due since it cant be added to.
Whats left is C++ containers such as vector or map. My question is how do I
implement the below code using a vector or map?
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to