Ejemplo n.º 1
0
TEST(H5Handle_Test, WriteReadTest) {
  float data[12];
  for (size_t i = 0; i < ArraySize(data); i++) {
    data[i] = i;
  }
  {
    H5File file;
    file.SetFile("tmp.h5");
    file.Open(true);
    hsize_t dims[] = {3,4};
    hsize_t chunking[] = {3,4};
    H5DataSet *ds =  file.CreateDataSet("/tmp/here/testdata", 2, dims, chunking, 2, H5T_NATIVE_FLOAT);

    size_t starts[] = {0,0};
    size_t ends[] = {3,4};
    //ds->WriteRangeData(starts, ends, ArraySize(data), data);
	ds->WriteRangeData(starts, ends, data);
    ds->Close();
  }
  { 
    H5File file;
    file.SetFile("tmp.h5");
    file.Open();
    H5DataSet *ds = file.OpenDataSet("/tmp/here/testdata");
    float query[12];
    size_t starts[] = {0,0};
    size_t ends[] = {3,4};
    ds->ReadRangeData(starts, ends, ArraySize(query), query);
    for (size_t i = 0; i < ArraySize(data); i++) {
      if (data[i] != query[i]) {
        EXPECT_EQ(query[i], data[i]);
      }
    }
    
    {
      float update[4];
      size_t starts[] = {1,2};
      size_t ends[] = {3,4};
      size_t count = 0;
      for (size_t i = 11; i >= 8; i--) {
        update[count++] = i;
      }
      //ds->WriteRangeData(starts, ends, ArraySize(update), update);
	  ds->WriteRangeData(starts, ends, update);
      float query[12];
      size_t rstarts[] = {0,0};
      size_t rends[] = {3,4};
      float gold[12] = {0,1,2,3,4,5,11,10,8,9,9,8};
      ds->ReadRangeData(rstarts, rends, ArraySize(query), query);
      for (size_t i = 0; i < 1; i++) {
        EXPECT_EQ(gold[i], query[i]);
      }

    }
    //    ds->Close();
    ds = file.OpenDataSet("shouldbenull");
    EXPECT_EQ(NULL,ds);

  }
}
Ejemplo n.º 2
0
TEST(H5Handle_Test, MatrixTest) {
  Mat<float> mymat = ones<Mat<float> >(5,3);
  Mat<float>::iterator i;
  int count = 0;
  for (i = mymat.begin(); i != mymat.end(); i++) {
    *i = count++;
  }
  //  mymat.raw_print(cout);
  {
    H5File file;
    file.SetFile("tmp.h5");
    file.Open(true);
    H5DataSet *ds = file.CreateDataSet("/tmp/fun/mat", mymat, 0);
    //H5DataSet *ds = file.CreateDataSet("mat", mymat, 0);
    ds->WriteMatrix(mymat);
    ds->Close();
  }
  {
    H5File file;
    file.SetFile("tmp.h5");
    file.Open();
    H5DataSet *ds = file.OpenDataSet("/tmp/fun/mat");
    //    H5DataSet *ds = file.OpenDataSet("mat");
    Mat<float> m;
    ds->ReadMatrix(m);
    //    m.raw_print(cout);
    Mat<float>::iterator gold, test;
    for (gold = mymat.begin(), test = m.begin(); gold != mymat.end(); gold++, test++) {
      float g = *gold;
      float t = *test;
      EXPECT_EQ(t, g);
    }    
    ds->Close();
  }

 }
Ejemplo n.º 3
0
// col, row, and flow are zero-based in this function, info read out include both borders.
RcppExport SEXP readBeadParamR(SEXP RbeadParamFile,SEXP RminCol, SEXP RmaxCol, SEXP RminRow, SEXP RmaxRow,SEXP RminFlow, SEXP RmaxFlow) {
  SEXP ret = R_NilValue;
  char *exceptionMesg = NULL;

  try {
    //vector<string> beadParamFile = Rcpp::as< vector<string> > (RbeadParamFile);
    //RcppStringVector tBeadParamFile(RbeadParamFile);
    string beadParamFile = Rcpp::as< string > (RbeadParamFile);
    int minCol = Rcpp::as< int > (RminCol);
    int maxCol = Rcpp::as< int > (RmaxCol);
    int minRow = Rcpp::as< int > (RminRow);
    int maxRow = Rcpp::as< int > (RmaxRow);
    int minFlow = Rcpp::as< int > (RminFlow);
    int maxFlow = Rcpp::as< int > (RmaxFlow);
    // Outputs

    unsigned int nCol = maxCol - minCol+1;
    unsigned int nRow = maxRow - minRow+1;
    unsigned int nFlow = maxFlow - minFlow+1;
    vector<unsigned int> colOut,rowOut,flowOut;
    vector< double > resErr;
    
    colOut.reserve(nCol * nRow * nFlow);
    rowOut.reserve(nCol * nRow * nFlow);
    // Recast int to unsigned int
    vector<unsigned int> col, row, flow;
    col.resize(nCol);
    for(unsigned int i=0;i<col.size();++i) 
      col[i] = (unsigned int)(i+minCol);
    row.resize(nRow);
    for(unsigned int i=0;i<row.size();++i)
      row[i] = (unsigned int) (i+minRow);
    flow.resize(nFlow);
    for(unsigned int i=0;i<flow.size();++i)
      flow[i] = (unsigned int) (i+minFlow);

    H5File beadParam;
    beadParam.SetFile(beadParamFile);
    beadParam.Open();
    H5DataSet *resErrDS = beadParam.OpenDataSet("/bead/res_error");
    H5DataSet *ampMulDS = beadParam.OpenDataSet("bead/ampl_multiplier");
    H5DataSet *krateMulDS = beadParam.OpenDataSet("bead/k_rate_multiplier");
    H5DataSet *beadInitDS = beadParam.OpenDataSet("bead/bead_init_param");
    H5DataSet *beadDCDS = beadParam.OpenDataSet("bead/fg_bead_DC");
   
    //float  tresErr[nCol * nRow * nFlow];
    float *tresErr;
    float *tamplMul;
    float *tkrateMul;
    float *tbeadInit;
    float *tbeadDC;

    tresErr = (float *) malloc ( sizeof(float) * nCol * nRow * nFlow);
    tamplMul = (float *) malloc ( sizeof(float) * nCol * nRow * nFlow);
    tkrateMul = (float *) malloc ( sizeof(float) * nCol * nRow * nFlow);
    tbeadInit = (float *) malloc ( sizeof(float) * nCol * nRow * 4);
    tbeadDC = (float *) malloc ( sizeof(float) * nCol * nRow * nFlow);

    size_t starts[3];
    size_t ends[3];
    starts[0] = minCol;
    starts[1] = minRow;
    starts[2] = minFlow;
    ends[0] = maxCol;
    ends[1] = maxRow;
    ends[2] = maxFlow;
    resErrDS->ReadRangeData(starts, ends, sizeof(tresErr),tresErr);
    ampMulDS->ReadRangeData(starts, ends, sizeof(tamplMul),tamplMul);
    krateMulDS->ReadRangeData(starts, ends, sizeof(tkrateMul),tkrateMul);
    beadDCDS->ReadRangeData(starts, ends, sizeof(tbeadDC),tbeadDC);

    starts[2] = 0;
    ends[2] = 3;
    beadInitDS->ReadRangeData(starts,ends,sizeof(tbeadInit),tbeadInit);
    beadParam.Close();

    RcppMatrix< double > resErrMat(nRow*nCol,nFlow);
    RcppMatrix< double > amplMulMat(nRow*nCol,nFlow);
    RcppMatrix< double > krateMulMat(nRow*nCol,nFlow);
    RcppMatrix< double > beadInitMat(nRow*nCol,4);
    RcppMatrix< double > beadDCMat(nRow*nCol,nFlow);
    vector<int> colOutInt,rowOutInt,flowOutInt;

    int count = 0;
    for(size_t icol=0;icol<nCol;++icol)
      for(size_t irow=0;irow<nRow;++irow) {
	for(size_t iFlow=0;iFlow<nFlow;++iFlow)
	  {
	    amplMulMat(count,iFlow) = (double) tamplMul[icol * nRow * nFlow + irow * nFlow + iFlow] ;
	    krateMulMat(count,iFlow) = (double) tkrateMul[icol * nRow * nFlow + irow * nFlow + iFlow];
	    beadDCMat(count,iFlow) = (double) tbeadDC[icol * nRow *nFlow + irow * nFlow + iFlow];
	  }
	for(size_t ip=0;ip<4;++ip)
	  beadInitMat(count,ip) = (double) tbeadInit[icol * nRow * ip + irow * 4 + ip];
	colOutInt.push_back(minCol+icol);
	rowOutInt.push_back(minRow+irow);
	count++;
      }

    RcppResultSet rs;
    rs.add("beadParamFile", beadParamFile);
    rs.add("nCol", (int)nCol);
    rs.add("nRow", (int)nRow);
    rs.add("minFlow",minFlow);
    rs.add("maxFlow",maxFlow);
    rs.add("nFlow", (int)nFlow);
    rs.add("col", colOutInt);
    rs.add("row",rowOutInt);
    rs.add("res_error",resErrMat);
    rs.add("ampl_multiplier",amplMulMat);
    rs.add("krate_multiplier",krateMulMat);
    rs.add("bead_init",beadInitMat);
    rs.add("bead_dc",beadDCMat);
    ret = rs.getReturnList();
    free(tresErr);
    free(tamplMul);
    free(tkrateMul);
    free(tbeadInit);
    free(tbeadDC);
  }
  catch(exception& ex) {
    exceptionMesg = copyMessageToR(ex.what());
  } catch (...) {
    exceptionMesg = copyMessageToR("Unknown reason");
  }
  
  if ( exceptionMesg != NULL)
    Rf_error(exceptionMesg);
  
  return ret;

}