PlasCom2  1.0
XPACC Multi-physics simluation application
PCPPHDF5.C
Go to the documentation of this file.
1 // #include "PCPPTypes.H"
2 // #include "PCPPIO.H"
3 #include "PCPPHDF5.H"
4 
5 namespace pcpp
6 {
7  namespace io
8  {
9  namespace xdmf
10  {
11 
12  void OpenFileTag(std::ostream &outStream)
13  {
14  outStream << "<?xml version=\"1.0\" ?>" << std::endl
15  << "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" []>" << std::endl
16  << "<Xdmf Version=\"2.0\">"
17  << " <Domain>" << std::endl;
18  }
19 
20  void CloseFileTag(std::ostream &outStream)
21  {
22  outStream << " </Domain>" << std::endl
23  << "</Xdmf>" << std::endl;
24  }
25 
26  void OpenGridTag(const std::string &gridName,const std::string &gridType,double inTime,std::ostream &outStream)
27  {
28  outStream << " <Grid Name=\"" << gridName << "\" GridType=\"" << gridType << "\">" << std::endl;
29  if(inTime >= 0)
30  outStream << " <Time Value=\"" << inTime << "\" />" << std::endl;
31  }
32  void CloseGridTag(std::ostream &outStream)
33  {
34  outStream << " </Grid>" << std::endl;
35  }
36 
38  int WriteGridSection(const std::string &topoType,const std::string &geomType,
39  const std::string &fileName,const std::string &gridPath,
40  const std::vector<size_t> &gridSize,std::ostream &outStream)
41  {
42 
43  unsigned int nDim = gridSize.size();
44  if(nDim > 3 || nDim < 2)
45  return(1);
46  std::ostringstream Ostr;
47  std::vector<size_t>::const_iterator gsIt = gridSize.begin();
48  while(gsIt != gridSize.end()){
49  Ostr << *gsIt++;
50  if(gsIt != gridSize.end())
51  Ostr << " ";
52  }
53 
54  outStream << " <Topology TopologyType=\"" << topoType << "\" Dimensions=\""
55  << Ostr.str() << "\" />" << std::endl
56  << " <Geometry GeometryType=\"" << (nDim == 2 ? "X_Y" : "X_Y_Z")
57  << "\">" << std::endl;
58 
59  outStream << " <DataItem Dimensions=\"" << Ostr.str() << "\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">" << std::endl
60  << " " << fileName << ":/" << gridPath << "/X" << std::endl
61  << " </DataItem>" << std::endl
62  << " <DataItem Dimensions=\"" << Ostr.str() << "\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">" << std::endl
63  << " " << fileName << ":/" << gridPath << "/Y" << std::endl
64  << " </DataItem>" << std::endl;
65 
66  if(nDim == 3){
67  outStream << " <DataItem Dimensions=\"" << Ostr.str() << "\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">" << std::endl
68  << " " << fileName << ":/" << gridPath << "/Z" << std::endl
69  << " </DataItem>" << std::endl;
70  }
71 
72  outStream << " </Geometry>" << std::endl;
73 
74  return(0);
75  }
76 
77  int WriteGridSection(const std::string &topoType,
78  const std::string &fileName,
79  const std::string &gridPath,
80  const std::vector<size_t> &gridSize,
81  std::ostream &outStream)
82  {
83 
84  unsigned int nDim = gridSize.size();
85  if(nDim > 3 || nDim < 2)
86  return(1);
87  std::ostringstream Ostr;
88  std::vector<size_t>::const_iterator gsIt = gridSize.begin();
89  while(gsIt != gridSize.end()){
90  Ostr << *gsIt++;
91  if(gsIt != gridSize.end())
92  Ostr << " ";
93  }
94 
95  outStream << " <Topology TopologyType=\"" << topoType << "\" Dimensions=\""
96  << Ostr.str() << "\" />" << std::endl
97  << " <Geometry GeometryType=\"" << (nDim == 2 ? "X_Y" : "X_Y_Z")
98  << "\">" << std::endl;
99 
100  outStream << " <DataItem Dimensions=\"" << Ostr.str() << "\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">" << std::endl
101  << " " << fileName << ":/" << gridPath << "/X" << std::endl
102  << " </DataItem>" << std::endl
103  << " <DataItem Dimensions=\"" << Ostr.str() << "\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">" << std::endl
104  << " " << fileName << ":/" << gridPath << "/Y" << std::endl
105  << " </DataItem>" << std::endl;
106 
107  if(nDim == 3){
108  outStream << " <DataItem Dimensions=\"" << Ostr.str() << "\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">" << std::endl
109  << " " << fileName << ":/" << gridPath << "/Z" << std::endl
110  << " </DataItem>" << std::endl;
111  }
112 
113  outStream << " </Geometry>" << std::endl;
114 
115  return(0);
116  }
117 
118  int WriteGridData(const std::string &fileName,const std::string &dataName,unsigned int dataSize,
119  const std::string &dataPath,const std::vector<size_t> &gridSize,std::ostream &outStream)
120  {
121  unsigned int nDim = gridSize.size();
122  if(nDim > 3 || nDim < 2)
123  return(1);
124  std::ostringstream Ostr;
125  std::vector<size_t>::const_iterator gsIt = gridSize.begin();
126  while(gsIt != gridSize.end()){
127  Ostr << *gsIt++;
128  if(gsIt != gridSize.end())
129  Ostr << " ";
130  }
131  outStream << " <Attribute Name=\"" << dataName << "\" AttributeType=\"Scalar\" Center=\"Node\">"
132  << " <DataItem Dimensions=\"" << Ostr.str() << "\" NumberType=\"" << (dataSize == 1 ? "Char" :
133  (dataSize == 4 ? "Int" :
134  (dataSize == 8 ? "Float" : "")))
135  << "\" Precision=\"" << dataSize << "\" Format=\"HDF\">" << std::endl
136  << " " << fileName << ":/" << dataPath << std::endl
137  << " </DataItem>" << std::endl
138  << " </Attribute>" << std::endl;
139  return(0);
140  }
141 
142  }
143 
144  namespace hdf5
145  {
146 
147  int LegacyFileInfo(hid_t rootGroupID,simfileinfo &fileInfo,std::ostream &messageStream)
148  {
149  const std::string &hdfFileName(fileInfo.fileName);
150 
151  hid_t h5attID = H5Aopen(rootGroupID,"numberOfGrids",H5P_DEFAULT);
152  std::ostringstream Ostr;
153  int numGrids = 0;
154  if(h5attID < 0){
155  h5attID = H5Aopen(rootGroupID,"numGrids",H5P_DEFAULT);
156  }
157  if(h5attID > 0){
158 
159  if(H5Aread(h5attID,H5T_NATIVE_INT,&numGrids) < 0){
160  Ostr << "Unable to read number of grids from legacy HDF5 file." << std::endl;
161  messageStream << Ostr.str();
162  return(1);
163  } else {
164  Ostr << hdfFileName << " has " << numGrids << " grids." << std::endl;
165  messageStream << Ostr.str();
166  fileInfo.numGrids = numGrids;
167  if(numGrids > 0)
168  fileInfo.formatBits.set(HASGRID);
169  }
170  H5Aclose(h5attID);
171 
172  std::vector<std::string> &gridNames(fileInfo.gridNames);
173  // Try to get the grid names
174  if(H5Aexists(rootGroupID,"gridNames") > 0){
175  h5attID = H5Aopen(rootGroupID,"gridNames",H5P_DEFAULT);
176  // std::vector<int> gridNameSizes(numGrids,0);
177  // hid_t gridNameDataSpace = H5Aget_space(h5attID);
178  } else {
179 
180  Ostr << "No grid names in HDF file, going with names specified in input."
181  << std::endl;
182  messageStream << Ostr.str();
183 
184  for(int i = 0;i < numGrids;i++){
185  std::ostringstream gridOut;
186  int gridNum = i+1;
187  gridOut << "Group" << (gridNum < 10 ? "00" :
188  (gridNum < 100 ? "0" :
189  "")) << gridNum;
190  gridNames.push_back(gridOut.str());
191  }
192 
193  }
194  // H5Gclose(h5groupID);
195  // struct pcpp::geometry::domaininfo domainInfo(plascomDomain.Info());
196  // std::vector<std::string> &gridsInFile(domainInfo.gridsInFile[hdfFileName]);
197  // if(gridsInFile.size() != numGrids){
198  // ErrOut(std::string("Number of grids in file ")+hdfFileName+
199  // std::string(" does not match those given in configuration.\n"));
200  // return(1);
201  // }
202  // pcpp::io::RenewStream(Ostr);
203 
204  Ostr << "Grid sizes:" << std::endl;
205 
206  std::vector<int> &gridNumDimensions(fileInfo.gridNumDimensions);
207  std::vector<std::vector<size_t> > &gridSizes(fileInfo.gridSizes);
208  gridNumDimensions.resize(numGrids);
209  gridSizes.resize(numGrids);
210 
211  for(int iGrid = 0;iGrid < numGrids;iGrid++){
212  hsize_t gridDimensions = 0;
213  hsize_t maxGridDimensions = 0;
214  // pcpp::geometry::grid &currentGrid(plascomDomain.Grid(gridsInFile[i]));
215  // pcpp::geometry::gridinfo &gridInfo(currentGrid.Info());
216  // currentGrid.SetName(gridNames[i]); // reset grid name to one from file
217  // Ostr << gridNames[i] << " (" << gridsInFile[i] << ") : (";
218  Ostr << gridNames[iGrid] << " : (";
219  // h5groupID = H5Gopen(h5fileID,gridNames[iGrid].c_str(),H5P_DEFAULT);
220  hid_t gridGroupID = H5Gopen(rootGroupID,gridNames[iGrid].c_str(),H5P_DEFAULT);
221  if(H5Lexists(gridGroupID,"IBLANK",0) > 0){
222  fileInfo.formatBits.set(HASIBLANK);
223  }
224  if(H5Lexists(gridGroupID,"State",0) > 0){
225  fileInfo.formatBits.set(HASSTATE);
226  }
227  if(H5Lexists(gridGroupID,"cv01",0) > 0) {
228  fileInfo.formatBits.set(HASSTATE);
229  fileInfo.formatBits.set(ISLEGACY);
230  }
231  if(H5Lexists(gridGroupID,"cvt01",0) > 0) {
232  fileInfo.formatBits.set(HASTARGDATA);
233  fileInfo.formatBits.set(ISLEGACY);
234  }
235  if(H5Lexists(gridGroupID,"aux01",0) > 0) {
236  fileInfo.formatBits.set(HASAUXDATA);
237  fileInfo.formatBits.set(ISLEGACY);
238  }
239  if(H5Lexists(gridGroupID,"numberOfAuxVars",0) > 0){
240  h5attID = H5Aopen(gridGroupID,"numberOfAuxVars",H5P_DEFAULT);
241  int numAux = 0;
242  if(H5Aread(h5attID,H5T_NATIVE_INT,&numAux) < 0){
243  messageStream << "pcpp::io:hdf5::FileInfo:Error: Unable to"
244  << " read number of Aux vars." << std::endl;
245  return(1);
246  }
247  fileInfo.numAuxVars = numAux;
248  }
249 
250  h5attID = H5Aopen(gridGroupID,"gridSize",H5P_DEFAULT);
251  hid_t h5spaceID = H5Aget_space(h5attID);
252  H5Sget_simple_extent_dims(h5spaceID,&gridDimensions,&maxGridDimensions);
253  gridNumDimensions[iGrid] = gridDimensions;
254  std::vector<int> gridGlobalSize(gridDimensions,1);
255  // gridInfo.globalSize.resize(3,1);
256  H5Aread(h5attID,H5T_NATIVE_INT,&(gridGlobalSize[0]));
257  for(int iDim = 0;iDim < gridDimensions;iDim++){
258  Ostr << gridGlobalSize[iDim];
259  if(iDim < (gridDimensions - 1))
260  Ostr << ",";
261  }
262  Ostr << ")" << std::endl;
263  gridSizes[iGrid].resize(gridDimensions,0);
264  for(int iDim = 0;iDim < gridDimensions;iDim++)
265  gridSizes[iGrid][iDim] = gridGlobalSize[iDim];
266  H5Aclose(h5attID);
267  H5Gclose(gridGroupID);
268  }
269  }
270  messageStream << Ostr.str();
271  return(0);
272  }
273 
274 
275 
276  int PlasCom2FileInfo(pcpp::io::hdf5::base &hdf5File,simfileinfo &fileInfo,std::ostream &messageStream)
277  {
278 
279  std::ostringstream Ostr;
280  const std::string fileName(hdf5File.Name());
281  fileInfo.fileName = fileName;
282 
283  if(!hdf5File.Exists("PlasCom2")){
284  messageStream << "pcpp::io::hdf5::FileInfo:Error: Unable to open PlasCom2 group in "
285  << fileName << "." << std::endl;
286  return(1);
287  }
288 
289  if(hdf5File.Exists("Global"))
290  fileInfo.formatBits.set(HASGLOBAL);
291  if(hdf5File.Exists("/PlasCom2/Configuration"))
292  fileInfo.formatBits.set(HASCONFIG);
293  if(hdf5File.Exists("/PlasCom2/Geometry")){
294  fileInfo.formatBits.set(HASGEOMETRY);
295  fileInfo.formatBits.set(HASGRID);
296  }
297  if(hdf5File.Exists("/PlasCom2/Simulation"))
298  fileInfo.formatBits.set(HASSIMULATION);
299  // if(H5Lexists(plasCom2GroupID,"Provenance",0) > 0){
300  // fileInfo.formatBits.set(HASPROVENANCE);
301  // }
302  // if(H5Lexists(rootGroupID,"DataDictionary",0) > 0){
303  // fileInfo.formatBits.set(HASDATADICT);
304  // }
305 
306  if(fileInfo.formatBits.test(HASGEOMETRY)){
307 
308  int totalNumGrids = 0;
309  std::vector<std::string> &allGeometryGridNames(fileInfo.gridNames);
310  std::vector<std::vector<size_t> > &allGridSizes(fileInfo.gridSizes);
311  std::vector<int> &allGridDimensions(fileInfo.gridNumDimensions);
312  allGeometryGridNames.resize(0);
313  allGridSizes.resize(0);
314  allGridDimensions.resize(0);
315 
316  std::string allGeometryNames;
317  hdf5File.ReadAttribute("/PlasCom2/Geometry/numGeometries",&(fileInfo.numGeometries));
318  hdf5File.ReadAttribute("/PlasCom2/Geometry/geometryNames",allGeometryNames);
319  pcpp::io::TokenizeString(fileInfo.geometryNames,allGeometryNames);
320  assert(fileInfo.geometryNames.size() == fileInfo.numGeometries);
321 
322  fileInfo.geometryGridNames.resize(fileInfo.numGeometries);
323  fileInfo.geometryGridSizes.resize(fileInfo.numGeometries);
324 
325  std::vector<std::vector<std::string> >::iterator
326  geomGridNameIt(fileInfo.geometryGridNames.begin());
327  std::vector<std::vector<std::vector<size_t> > >::iterator
328  geomGridSizeIt(fileInfo.geometryGridSizes.begin());
329  std::vector<std::string>::iterator geomNameIt = fileInfo.geometryNames.begin();
330  while(geomNameIt != fileInfo.geometryNames.end()){
331 
332  std::vector<std::string> &gridNames(*geomGridNameIt++);
333  std::vector<std::vector<size_t> > &gridIntervals(*geomGridSizeIt++);
334  gridNames.resize(0);
335 
336  std::string &geometryName(*geomNameIt++);
337  std::string geometryGroupName(std::string("/PlasCom2/Geometry/")+geometryName);
338  int numGrids = 0;
339  hdf5File.ReadAttribute(geometryGroupName+"/numGrids",&numGrids);
340  totalNumGrids += numGrids;
341  std::string allGridNames;
342  hdf5File.ReadAttribute(geometryGroupName+"/gridNames",allGridNames);
343  pcpp::io::TokenizeString(gridNames,allGridNames);
344  std::vector<std::string>::iterator gridNameIt = gridNames.begin();
345  while(gridNameIt != gridNames.end()){
346  const std::string &gridName(*gridNameIt++);
347  allGeometryGridNames.push_back(geometryName+":"+gridName);
348  const std::string gridGroupName(geometryGroupName+std::string("/")+
349  gridName);
350  int numDim = 0;
351  hdf5File.ReadAttribute(gridGroupName+"/numDim",&numDim);
352  allGridDimensions.push_back(numDim);
353  std::vector<size_t> reverseGridSizes(numDim,0);
354  hdf5File.ReadAttribute(gridGroupName+"/gridSize",&reverseGridSizes[0]);
355  std::vector<size_t> gridSizes(reverseGridSizes);
356  std::reverse(gridSizes.begin(),gridSizes.end());
357  // pcpp::IndexIntervalType gridInterval;
358  // gridInterval.InitSimple(gridSizes);
359  gridIntervals.push_back(gridSizes);
360  allGridSizes.push_back(gridSizes);
361  }
362  }
363  fileInfo.numGrids = totalNumGrids;
364  }
365 
366  if(fileInfo.formatBits.test(HASSIMULATION)){
367 
368  int numDomains = 0;
369 
370  pcpp::field::metadataset &simulationParamDictionary(fileInfo.simulationParamDictionary);
371  pcpp::field::metadataset &simulationStateDictionary(fileInfo.simulationStateDictionary);
372 
373  hdf5File.ReadAttribute("/PlasCom2/Simulation/numDomains",&numDomains);
374  if(hdf5File.AttributeExists("/PlasCom2/Simulation/stepNumber")){
375  hdf5File.ReadAttribute("/PlasCom2/Simulation/stepNumber",&fileInfo.simStep);
376  }
377 
378  if(hdf5File.AttributeExists("/PlasCom2/Simulation/paramDictionary")){
379  std::string paramDictionaryString;
380  hdf5File.ReadAttribute("/PlasCom2/Simulation/paramDictionary",paramDictionaryString);
381  std::istringstream Istr(paramDictionaryString);
382  Istr >> simulationParamDictionary;
383  }
384 
385  if(hdf5File.AttributeExists("/PlasCom2/Simulation/stateDictionary")){
386  std::string stateDictionaryString;
387  hdf5File.ReadAttribute("/PlasCom2/Simulation/stateDictionary",stateDictionaryString);
388  std::istringstream Istr(stateDictionaryString);
389  Istr >> simulationStateDictionary;
390  }
391 
392  if(numDomains > 0){
393 
394  fileInfo.formatBits.set(HASSTATE);
395 
396  fileInfo.domainGridNames.resize(numDomains);
397  fileInfo.domainParamDictionaries.resize(numDomains);
398  fileInfo.domainStateDictionaries.resize(numDomains);
399  fileInfo.domainGridPaths.resize(numDomains);
400 
401  std::string allDomainNames;
402  hdf5File.ReadAttribute("/PlasCom2/Simulation/domainNames",allDomainNames);
403  pcpp::io::TokenizeString(fileInfo.domainNames,allDomainNames);
404  fileInfo.numDomains = fileInfo.domainNames.size();
405 
406  const std::vector<std::string> &domainNames(fileInfo.domainNames);
407 
408  std::vector<std::vector<std::string> >::iterator domainGridNameIt =
409  fileInfo.domainGridNames.begin();
410  std::vector<std::vector<std::string> >::iterator domainFullGridNamesIt =
411  fileInfo.domainGridPaths.begin();
412  std::vector<pcpp::field::metadataset>::iterator domainParamDictIt =
413  fileInfo.domainParamDictionaries.begin();
414  std::vector<pcpp::field::metadataset>::iterator domainStateDictIt =
415  fileInfo.domainStateDictionaries.begin();
416  std::vector<std::string>::const_iterator domainNameIt = domainNames.begin();
417 
418  while(domainNameIt != domainNames.end()){
419 
420  pcpp::field::metadataset &domainParamDictionary(*domainParamDictIt++);
421  pcpp::field::metadataset &domainStateDictionary(*domainStateDictIt++);
422 
423  const std::string &domainName(*domainNameIt++);
424  std::string domainGroupName("/PlasCom2/Simulation/"+domainName);
425  int numDomainGrids = 0;
426  hdf5File.ReadAttribute(domainGroupName+"/numGrids",&numDomainGrids);
427 
428  if(hdf5File.AttributeExists(domainGroupName+"/simTime")){
429  hdf5File.ReadAttribute(domainGroupName+"/simTime",&fileInfo.simTime);
430  }
431 
432  if(hdf5File.AttributeExists(domainGroupName+"/paramDictionary")){
433  std::string paramDictionaryString;
434  hdf5File.ReadAttribute(domainGroupName+"/paramDictionary",paramDictionaryString);
435  std::istringstream Istr(paramDictionaryString);
436  Istr >> domainParamDictionary;
437  }
438 
439  if(hdf5File.AttributeExists(domainGroupName+"/stateDictionary")){
440  std::string stateDictionaryString;
441  hdf5File.ReadAttribute(domainGroupName+"/stateDictionary",stateDictionaryString);
442  std::istringstream Istr(stateDictionaryString);
443  Istr >> domainStateDictionary;
444  }
445 
446  if(numDomainGrids > 0){
447 
448  std::vector<std::string> &domainGridNames(*domainGridNameIt++);
449  std::vector<std::string> &domainFullGridNames(*domainFullGridNamesIt++);
450  domainFullGridNames.resize(numDomainGrids);
451  std::string allGridNames;
452 
453  std::string attName(domainGroupName+"/gridNames");
454  hdf5File.ReadAttribute(domainGroupName+"/gridNames",allGridNames);
455  pcpp::io::TokenizeString(domainGridNames,allGridNames);
456 
457  for(int iGrid = 0;iGrid < numDomainGrids;iGrid++){
458  const std::string &gridName(domainGridNames[iGrid]);
459  const std::string gridGroupName(domainGroupName+"/"+gridName);
460  hdf5File.ReadAttribute(gridGroupName+"/gridPath",domainFullGridNames[iGrid]);
461  }
462  }
463  }
464  }
465  }
466  return(0);
467  }
468 
469  int LegacyFileInfo(pcpp::io::hdf5::base &hdf5File,simfileinfo &fileInfo,std::ostream &messageStream)
470  {
471 
472  std::ostringstream Ostr;
473  const std::string fileName(hdf5File.Name());
474  fileInfo.fileName = fileName;
475  const std::string &hdfFileName(fileInfo.fileName);
476  pcpp::field::metadataset &paramDictionary(fileInfo.simulationParamDictionary);
477  pcpp::field::metadataset &stateDictionary(fileInfo.simulationStateDictionary);
478 
479  int &numGrids(fileInfo.numGrids);
480  double dStep = 0;
481  hdf5File.ReadAttribute("HEADER",&dStep);
482  fileInfo.simStep = int(dStep);
483  stateDictionary.AddField("simStep",'d',1,4,"");
484  stateDictionary.AddField("simTime",'d',1,8,"time");
485  paramDictionary.AddField("refRe",'d',1,8,"ReynoldsNo");
486  paramDictionary.AddField("refPr",'d',1,8,"PrandtlNo");
487  paramDictionary.AddField("refSc",'d',1,8,"SchmidtNo");
488  hdf5File.ReadAttribute("numberOfGrids",&numGrids);
489  if(numGrids > 0){
490  paramDictionary.AddField("numberOfGrids",'d',1,4,"");
491  }
492  if(numGrids <= 0){
493  hdf5File.ReadAttribute("numGrids",&numGrids);
494  if(numGrids > 0){
495  paramDictionary.AddField("numGrids",'d',1,4,"");
496  }
497  }
498  if(numGrids <= 0){
499  messageStream << "pcpp::hdf5::LegacyFileInfo: Could not read number of grids." << std::endl;
500  return(1);
501  }
502 
503  Ostr << hdfFileName << " has " << numGrids << " grids." << std::endl;
504  messageStream << Ostr.str();
505 
506  std::vector<std::string> &gridNames(fileInfo.gridNames);
507  Ostr << "No grid names in HDF file, going with names specified in input."
508  << std::endl;
509  messageStream << Ostr.str();
510  pcpp::io::RenewStream(Ostr);
511 
512  for(int i = 0;i < numGrids;i++){
513  std::ostringstream gridOut;
514  int gridNum = i+1;
515  gridOut << "Group" << (gridNum < 10 ? "00" :
516  (gridNum < 100 ? "0" :
517  "")) << gridNum;
518  gridNames.push_back(gridOut.str());
519  Ostr << "Setting grid name " << gridOut.str() << std::endl;
520  }
521  messageStream << Ostr.str();
522  pcpp::io::RenewStream(Ostr);
523 
524  Ostr << "Grid sizes:" << std::endl;
525  std::vector<int> &gridNumDimensions(fileInfo.gridNumDimensions);
526  std::vector<std::vector<size_t> > &gridSizes(fileInfo.gridSizes);
527  gridNumDimensions.resize(numGrids);
528  gridSizes.resize(numGrids);
529 
530  for(int iGrid = 0;iGrid < numGrids;iGrid++){
531 
532  const std::string &gridName(gridNames[iGrid]);
533  std::vector<size_t> &gridSize(gridSizes[iGrid]);
534  std::vector<size_t> reverseGridSize;
535 
536  hdf5File.ReadAttribute(gridName+"/gridSize",reverseGridSize);
537  // std::reverse(reverseGridSize.begin(),reverseGridSize.end());
538  gridSize = reverseGridSize;
539  gridNumDimensions[iGrid] = gridSize.size();
540  int numDim = gridNumDimensions[iGrid];
541  // void AddField(const std::string &name,char loc,unsigned int ncomp,
542  // unsigned int dsize,const std::string &unit)
543 
544  if(hdf5File.Exists(gridName+"/X")){
545  fileInfo.formatBits.set(HASGRID);
546  }
547  if(hdf5File.Exists(gridName+"/IBLANK")){
548  fileInfo.formatBits.set(HASIBLANK);
549  if(iGrid == 0){
550  stateDictionary.AddField("IBLANK",'n',1,4,"");
551  }
552  }
553  if(hdf5File.Exists(gridName+"/cv01")){
554  fileInfo.formatBits.set(HASSTATE);
555  if(iGrid == 0){
556  stateDictionary.AddField("cv01",'n',1,8,"rho");
557  for(int iDim = 0;iDim < numDim;iDim++){
558  std::ostringstream attNameStream;
559  attNameStream << "cv0" << iDim+2;
560  std::ostringstream unitStream;
561  unitStream << "rhoV-" << iDim+1;
562  if(iGrid == 0)
563  stateDictionary.AddField(attNameStream.str(),'n',1,8,unitStream.str());
564  }
565  std::ostringstream attNameStream;
566  attNameStream << "cv0" << numDim+2;
567  stateDictionary.AddField(attNameStream.str(),'n',1,8,"rhoE");
568  }
569  }
570  if(hdf5File.Exists(gridName+"/cvt01")){
571  fileInfo.formatBits.set(HASTARGDATA);
572  if(iGrid == 0){
573  stateDictionary.AddField("cvt01",'n',1,8,"rhoTarget");
574  for(int iDim = 0;iDim < numDim;iDim++){
575  std::ostringstream attNameStream;
576  attNameStream << "cvt0" << iDim+2;
577  std::ostringstream unitStream;
578  unitStream << "rhoVTarget-" << iDim+1;
579  stateDictionary.AddField(attNameStream.str(),'n',1,8,unitStream.str());
580  }
581  std::ostringstream attNameStream;
582  attNameStream << "cvt0" << numDim+2;
583  stateDictionary.AddField(attNameStream.str(),'n',1,8,"rhoETarget");
584  }
585  }
586  if(hdf5File.Exists(gridName+"/numberOfAuxVars")){
587  hdf5File.ReadAttribute(gridName+"/numberOfAuxVars",&fileInfo.numAuxVars);
588  if(fileInfo.numAuxVars > 0){
589  fileInfo.formatBits.set(HASAUXDATA);
590  if(iGrid == 0){
591  for(int iAux = 0;iAux < fileInfo.numAuxVars;iAux++){
592  std::ostringstream Ostr;
593  Ostr << std::setfill('0') << std::setw(2) << iAux;
594  const std::string auxId(Ostr.str());
595  const std::string auxName("aux"+auxId);
596  stateDictionary.AddField(auxName,'n',1,8,"");
597  if(fileInfo.formatBits.test(HASTARGDATA)){
598  const std::string auxTarg("auxt"+auxId);
599  stateDictionary.AddField(auxTarg,'n',1,8,"");
600  }
601  }
602  }
603  }
604  }
605  std::vector<double> gridHeader;
606  hdf5File.ReadAttribute(gridName+"/HEADER",gridHeader);
607  size_t numHeader = gridHeader.size();
608  if(numHeader >= 4)
609  fileInfo.simTime = gridHeader[3];
610  fileInfo.legacyHeader = gridHeader;
611  Ostr << gridName << " : (";
612  pcpp::io::DumpContents(Ostr,gridSize,",");
613  Ostr << ")" << std::endl;
614  }
615  messageStream << Ostr.str();
616  pcpp::io::RenewStream(Ostr);
617 
618  return(0);
619  }
620 
621  int FileInfo(const std::string &hdfFileName,simfileinfo &fileInfo,std::ostream &messageStream)
622  {
623 
624  fileInfo.fileName = hdfFileName;
625 
626  hid_t h5fileID = H5Fopen(hdfFileName.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
627  // std::vector<std::string> gridNames;
628  if(h5fileID < 0){
629  messageStream << "Unable to open " << hdfFileName << "." << std::endl;
630  return(1);
631  }
632  hid_t rootGroupID = H5Gopen(h5fileID,"/",H5P_DEFAULT);
633  if(rootGroupID < 0){
634  messageStream << "pcpp::io::hdf5::FileInfo::Error: Unable to open root group in "
635  << hdfFileName << "." << std::endl;
636  return(1);
637  }
638  if(H5Lexists(rootGroupID,"PlasCom2",0) > 0){
639  fileInfo.formatBits.set(ISPLASCOM2);
640  fileInfo.formatBits.reset(ISLEGACY);
641  } else {
642  fileInfo.formatBits.set(ISLEGACY);
643  fileInfo.formatBits.reset(ISPLASCOM2);
644  }
645  H5Gclose(rootGroupID);
646  H5Fclose(h5fileID);
647 
648  pcpp::io::hdf5::base hdf5File(hdfFileName);
649  if(fileInfo.formatBits.test(ISLEGACY)){
650  if(LegacyFileInfo(hdf5File,fileInfo,messageStream)){
651  messageStream << "pcpp::io::hdf5::FileInfo::Error: Processing of Legacy HDF5 file "
652  << hdfFileName << " failed." << std::endl;
653  return(1);
654  }
655  } else {
656  if(PlasCom2FileInfo(hdf5File,fileInfo,messageStream)){
657  messageStream << "pcpp::io::hdf5::FileInfo::Error: Processing of PlasCom2 HDF5 file "
658  << hdfFileName << " failed." << std::endl;
659  return(1);
660  }
661  }
662 
663  return(0);
664  };
665 
666  int FileInfo(const std::string &hdfFileName,simfileinfo &fileInfo,
667  fixtures::CommunicatorType &inComm,std::ostream &messageStream)
668  {
669  int myRank = inComm.Rank();
670  if(myRank == 0){
671  if(FileInfo(hdfFileName,fileInfo,messageStream)){
672  inComm.SetErr(1);
673  }
674  }
675  if(inComm.Check()){
676  return(1);
677  }
678  inComm.StreamBroadCast(fileInfo);
679  return(0);
680  };
681 
682 
683  int base::Create(const std::string &inFileName,bool force)
684  {
685 
686  std::ostream &messageStream(*messageStreamPtr);
687  Close();
688  unsigned createFlag = H5F_ACC_EXCL;
689  if(force)
690  createFlag = H5F_ACC_TRUNC;
691  hid_t fileProperties = H5P_DEFAULT;
692  // messageStream << "pcpp::io::hdf5::base: "
693  // << (force ? "Forcing creation of " : "Creating ")
694  // << inFileName;
695 
696  if(commPtr){
697  int numProc = commPtr->NProc();
698  // messageStream << " on " << numProc << " processors";
699  fileProperties = H5Pcreate(H5P_FILE_ACCESS);
700  H5Pset_fapl_mpio(fileProperties, commPtr->Comm(),MPI_INFO_NULL);
701  collectiveMode = true;
702  }
703  // messageStream << "." << std::endl;
704  hid_t fileID = H5Fcreate(inFileName.c_str(),createFlag,H5P_DEFAULT,fileProperties);
705  if(fileID < 0){
706  messageStream << "pcpp::io::hdf5::base:ERROR: Unable to create "
707  << inFileName << "." << std::endl;
708  return(1);
709  }
710  hdfScope.push_back(fileID);
711  H5Pclose(fileProperties);
712  dataTransferProperties = H5Pcreate(H5P_DATASET_XFER);
713  // hdfAPL.push_back(fileProperties);
714  return(0);
715  };
716 
717 
718  int base::Open(const std::string &inFileName,bool readOnly)
719  {
720 
721  std::ostream &messageStream(*messageStreamPtr);
722  Close();
723  unsigned openFlags = H5F_ACC_RDWR;
724  if(readOnly){
725  messageStream << "pcpp::io::hdf5::base: Opening READONLY file, " << inFileName
726  << "." << std::endl;
727  openFlags = H5F_ACC_RDONLY;
728  }
729  hid_t hdfFileID = -1;
730  if(!commPtr){
731 
732  messageStream << "pcpp::io::hdf5::base: Opening " << inFileName
733  << " with " << (readOnly ? "readonly" :
734  "read/write") << " access." << std::endl;
735  hdfFileID = H5Fopen(inFileName.c_str(),openFlags,H5P_DEFAULT);
736  if(hdfFileID < 0){
737  messageStream << "pcpp::io::hdf5::base:ERROR: Unable to open "
738  << inFileName << "." << std::endl;
739  return(1);
740  }
741  hdfScope.push_back(hdfFileID);
742  // hdfAPL.push_back(H5P_DEFAULT);
743  } else {
744 
745  fixtures::CommunicatorType &hdfComm(*commPtr);
746  int nProc = commPtr->NProc();
747  collectiveMode = true;
748  messageStream << "pcpp::io::hdf5::base: Opening " << inFileName
749  << " on " << nProc << " processors with "
750  << (readOnly ? "readonly" :
751  "read/write") << " access." << std::endl;
752  hid_t propertyListID = H5Pcreate(H5P_FILE_ACCESS);
753  if(propertyListID < 0){
754  messageStream << "pcpp::io::hdf5::base:ERROR: H5Pcreate failed." << std::endl;
755  return(1);
756  }
757  if(H5Pset_fapl_mpio(propertyListID,hdfComm.Comm(),MPI_INFO_NULL) < 0){
758  messageStream << "pcpp::io::hdf5::base:ERROR: H5Pset_fapl_mpio failed."
759  << std::endl;
760  return(1);
761  }
762  hdfFileID = H5Fopen(inFileName.c_str(),openFlags,propertyListID);
763  if(hdfFileID < 0){
764  std::ostringstream Ostr;
765  messageStream << "pcpp::io::hdf5::base:ERROR: Could not open HDF5 file: "
766  << inFileName << std::endl;
767  return(1);
768  }
769  hdfScope.push_back(hdfFileID);
770  H5Pclose(propertyListID);
771  // hdfAPL.push_back(propertyListID);
772  }
773  // hid_t rootGroupID = H5Gopen(hdfFileID,"/",H5P_DEFAULT);
774  // if(rootGroupID < 0){
775  // messageStream << "pcpp::io::hdf5::FileInfo::Error: Unable to open root group in "
776  // << inFileName << "." << std::endl;
777  // return(1);
778  // }
779  messageStream << "Opened file on scope(" << hdfFileID << ")"
780  << std::endl;
781  // messageStream << "Opened group / on scope(" << rootGroupID
782  // << ")" << std::endl;
783  // hdfScope.push_back(rootGroupID);
784  // hdfAPL.push_back(H5P_DEFAULT);
785  fileName = inFileName;
786  dataTransferProperties = H5Pcreate(H5P_DATASET_XFER);
787  return(0);
788  };
789 
790  int base::Close()
791  {
792  std::vector<hid_t>::iterator plistIt = hdfAPL.begin();
793  while(plistIt != hdfAPL.end()){
794  if(*plistIt != H5P_DEFAULT)
795  H5Pclose(*plistIt);
796  plistIt++;
797  }
798  hdfAPL.resize(0);
799  if(dataTransferProperties > 0){
800  H5Pclose(dataTransferProperties);
801  dataTransferProperties = -1;
802  }
803  // if(dataSpace > 0){
804  // H5Sclose(dataSpace);
805  // dataSpace = -1;
806  // }
807  // if(dataSet > 0){
808  // H5Dclose(dataSet);
809  // dataSet = -1;
810  // }
811  if(localSlab > 0){
812  H5Sclose(localSlab);
813  localSlab = -1;
814  }
815  if(globalSlab > 0){
816  H5Sclose(globalSlab);
817  globalSlab = -1;
818  }
819  int numScope = hdfScope.size();
820  for(int iScope = numScope-1;iScope > 0;iScope--){
821  H5Gclose(hdfScope[iScope]);
822  }
823  if(numScope > 0){
824  // H5Fflush(hdfScope[0],H5F_SCOPE_GLOBAL);
825  H5Fclose(hdfScope[0]);
826  hdfScope.resize(0);
827  }
828  return(0);
829  };
830 
831  int base::OpenGroup(const std::string &groupName)
832  {
833  std::ostream &messageStream(*messageStreamPtr);
834  hid_t parentID = hdfScope.back();
835  if(H5Lexists(parentID,groupName.c_str(),H5P_DEFAULT) <= 0){
836  messageStream << "pcpp::io::hdf5::base:ERROR: Group "
837  << groupName << " does not exist in "
838  << fileName << "." << std::endl;
839  return(1);
840  }
841  hid_t hdfGroupID = H5Gopen(parentID,groupName.c_str(),H5P_DEFAULT);
842  if(hdfGroupID < 0){
843  messageStream << "pcpp::io::hdf5::base:ERROR: "
844  << "Unable to open group: "
845  << groupName << std::endl;
846  return(1);
847  }
848  hdfScope.push_back(hdfGroupID);
849  return(0);
850  };
851 
852  bool base::AttributeExists(const std::string &inName)
853  {
854  *messageStreamPtr << "LOCATING ATTRIBUTE: " << inName << std::endl;
855  std::string attributeName(inName);
856  std::string locationName(".");
857  hid_t parentId = hdfScope.back();
858  if(ResolveName(inName,locationName,attributeName,parentId))
859  return(false);
860  *messageStreamPtr << "Checking for existence of attribute ("
861  << attributeName << ") located at (" << locationName
862  << ") in scope ("
863  << parentId << ")" << std::endl;
864  if(H5Aexists_by_name(parentId,locationName.c_str(),attributeName.c_str(),H5P_DEFAULT) <= 0){
865  *messageStreamPtr << "Not found." << std::endl;
866  return(false);
867  }
868  *messageStreamPtr << "Found." << std::endl;
869  return(true);
870  }
871 
872  bool base::Exists(const std::string &linkName)
873  {
874  hid_t parentId = hdfScope.back();
875  if(linkName[0] == '/')
876  parentId = hdfScope[0];
877  *messageStreamPtr << "Checking for existence of "
878  << linkName << " in scope ("
879  << parentId << ")" << std::endl;
880  if(H5Lexists(parentId,linkName.c_str(),H5P_DEFAULT) <= 0){
881  *messageStreamPtr << "Not found." << std::endl;
882  return(false);
883  }
884  *messageStreamPtr << "Found." << std::endl;
885  return(true);
886  };
887 
888  int base::ResolveName(const std::string &inName,std::string &attLocation,
889  std::string &attName,hid_t &parentId)
890  {
891  // *messageStreamPtr << "Resolving name (" << inName
892  // << ")" << std::endl;
893  attName = inName;
894  attLocation = ".";
895  parentId = hdfScope.back();
896  if(attName[0] == '/'){
897  attName = attName.substr(1);
898  parentId = hdfScope[0];
899  }
900  std::string::size_type x = attName.find_last_of("/");
901  if(x != std::string::npos){
902  attLocation = attName.substr(0,x);
903  attName = attName.substr(x+1);
904  if(attLocation.empty())
905  attLocation = ".";
906  }
907  if(attLocation.empty() ||
908  attLocation.empty() ||
909  (parentId <= 0))
910  return(1);
911  *messageStreamPtr << "Resolved(" << inName
912  << ") = (" << attName << ","
913  << attLocation << ")"
914  << std::endl;
915 
916  return(0);
917  };
918 
919  hid_t base::OpenDataSet(const std::string &inName)
920  {
921  if(!Exists(inName))
922  return(-1);
923  std::string dataLocation;
924  std::string dataSetName;
925  hid_t parentID;
926  if(ResolveName(inName,dataLocation,dataSetName,parentID))
927  return(-1);
928  std::ostream &messageStream(*messageStreamPtr);
929  messageStream << "Opening dataset (" << dataSetName
930  << ") at (" << dataLocation << ") in scope"
931  << "(" << parentID << ")." << std::endl;
932  hid_t dataSetID = H5Dopen(parentID,inName.c_str(),H5P_DEFAULT);
933  if(dataSetID <= 0){
934  messageStream << "pcpp::io::hdf5::base: ERROR: Dataset not found ("
935  << dataSetName << ")" << std::endl;
936  return(-1);
937  }
938  return(dataSetID);
939  };
940 
941  hid_t base::OpenAttribute(const std::string &inName)
942  {
943 
944  if(!AttributeExists(inName))
945  return(-1);
946  std::string attributeName;
947  std::string attLocation;
948  hid_t parentID = hdfScope.back();
949  if(ResolveName(inName,attLocation,attributeName,parentID))
950  return(-1);
951  std::ostream &messageStream(*messageStreamPtr);
952  messageStream << "Opening attribute (" << attributeName << ") located"
953  << " at (" << attLocation << ") in scope (" << parentID
954  << ")." << std::endl;
955  hid_t h5attID = H5Aopen_by_name(parentID,attLocation.c_str(),attributeName.c_str(),
956  H5P_DEFAULT,H5P_DEFAULT);
957  if(h5attID < 0){
958  messageStream << "pcpp::io::hdf5::base: ERROR: Attribute not found ("
959  << attributeName << ")" << std::endl;
960  return(-1);
961  }
962  return(h5attID);
963  };
964 
965  int base::ReadDataSet(const std::string &inName,int *inBuf)
966  {
967  std::ostream &messageStream(*messageStreamPtr);
968  hid_t dataSetID = OpenDataSet(inName);
969  if(dataSetID < 0)
970  return(-1);
971  if(H5Dread(dataSetID,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,inBuf) < 0){
972  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
973  << "attribute (" << inName << ")" << std::endl;
974  H5Dclose(dataSetID);
975  return(1);
976  }
977  H5Dclose(dataSetID);
978  return(0);
979  };
980 
981  int base::ReadDataSet(const std::string &inName,size_t *inBuf)
982  {
983  std::ostream &messageStream(*messageStreamPtr);
984  hid_t dataSetID = OpenDataSet(inName);
985  if(dataSetID < 0)
986  return(-1);
987  if(H5Dread(dataSetID,H5T_NATIVE_HSIZE,H5S_ALL,H5S_ALL,H5P_DEFAULT,inBuf) < 0){
988  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
989  << "attribute (" << inName << ")" << std::endl;
990  H5Dclose(dataSetID);
991  return(1);
992  }
993  H5Dclose(dataSetID);
994  return(0);
995  };
996 
997  int base::ReadDataSet(const std::string &inName,double *inBuf)
998  {
999  std::ostream &messageStream(*messageStreamPtr);
1000  hid_t dataSetID = OpenDataSet(inName);
1001  if(dataSetID < 0)
1002  return(-1);
1003  if(H5Dread(dataSetID,H5T_NATIVE_DOUBLE,H5S_ALL,H5S_ALL,H5P_DEFAULT,inBuf) < 0){
1004  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
1005  << "attribute (" << inName << ")" << std::endl;
1006  H5Dclose(dataSetID);
1007  return(1);
1008  }
1009  H5Dclose(dataSetID);
1010  return(0);
1011  };
1012 
1013  int base::ReadDataSet(const std::string &inName,char *inBuf)
1014  {
1015  std::ostream &messageStream(*messageStreamPtr);
1016  hid_t dataSetID = OpenDataSet(inName);
1017  if(dataSetID < 0)
1018  return(-1);
1019  if(H5Dread(dataSetID,H5T_NATIVE_CHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,inBuf) < 0){
1020  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
1021  << "attribute (" << inName << ")" << std::endl;
1022  H5Dclose(dataSetID);
1023  return(1);
1024  }
1025  H5Dclose(dataSetID);
1026  return(0);
1027  };
1028 
1029  int base::ReadAttribute(const std::string &inName,int *inBuf)
1030  {
1031  std::ostream &messageStream(*messageStreamPtr);
1032  hid_t h5attID = OpenAttribute(inName);
1033  if(h5attID < 0){
1034  return(-1);
1035  } else {
1036  if(H5Aread(h5attID,H5T_NATIVE_INT,inBuf) < 0){
1037  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
1038  << "attribute (" << inName << ")" << std::endl;
1039  H5Aclose(h5attID);
1040  return(1);
1041  }
1042  }
1043  H5Aclose(h5attID);
1044  return(0);
1045  };
1046 
1047 
1048  int base::ReadAttribute(const std::string &inName,size_t *inBuf)
1049  {
1050  std::ostream &messageStream(*messageStreamPtr);
1051  hid_t h5attID = OpenAttribute(inName);
1052  if(h5attID < 0){
1053  return(-1);
1054  } else {
1055  if(H5Aread(h5attID,H5T_NATIVE_HSIZE,inBuf) < 0){
1056  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
1057  << "attribute (" << inName << ")" << std::endl;
1058  H5Aclose(h5attID);
1059  return(1);
1060  }
1061  }
1062  H5Aclose(h5attID);
1063  return(0);
1064  };
1065 
1066  int base::ReadAttribute(const std::string &inName,double *inBuf)
1067  {
1068  std::ostream &messageStream(*messageStreamPtr);
1069  hid_t h5attID = OpenAttribute(inName);
1070  if(h5attID < 0){
1071  return(-1);
1072  } else {
1073  if(H5Aread(h5attID,H5T_NATIVE_DOUBLE,inBuf) < 0){
1074  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
1075  << "attribute (" << inName << ")" << std::endl;
1076  H5Aclose(h5attID);
1077  return(1);
1078  }
1079  }
1080  H5Aclose(h5attID);
1081  return(0);
1082  };
1083 
1084  int base::ReadAttribute(const std::string &inName,char *inBuf)
1085  {
1086  std::ostream &messageStream(*messageStreamPtr);
1087  hid_t h5attID = OpenAttribute(inName);
1088  if(h5attID < 0){
1089  return(-1);
1090  } else {
1091  if(H5Aread(h5attID,H5T_NATIVE_CHAR,inBuf) < 0){
1092  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
1093  << "attribute (" << inName << ")" << std::endl;
1094  H5Aclose(h5attID);
1095  return(1);
1096  }
1097  }
1098  H5Aclose(h5attID);
1099  return(0);
1100  };
1101 
1102  int base::ReadAttribute(const std::string &inName,std::string &inBuf)
1103  {
1104  std::ostream &messageStream(*messageStreamPtr);
1105  hid_t h5attID = OpenAttribute(inName);
1106  if(h5attID < 0){
1107  return(-1);
1108  } else {
1109  hsize_t stringSize = H5Aget_storage_size(h5attID);
1110  hid_t typeID = H5Tcopy(H5T_C_S1);
1111  H5Tset_size(typeID,stringSize);
1112  char *stringBuf = new char [stringSize];
1113  if(H5Aread(h5attID,typeID,stringBuf) < 0){
1114  messageStream << "pcpp::io::hdf5::base: ERROR: Unable to read "
1115  << "attribute (" << inName << ")" << std::endl;
1116  H5Aclose(h5attID);
1117  H5Tclose(typeID);
1118  delete [] stringBuf;
1119  return(1);
1120  }
1121  H5Aclose(h5attID);
1122  H5Tclose(typeID);
1123  inBuf.assign(stringBuf);
1124  delete [] stringBuf;
1125  }
1126  return(0);
1127  };
1128 
1129  hid_t base::DataSpace(const std::string &inName)
1130  {
1131  hid_t returnValue = -1;
1132  return(returnValue);
1133  };
1134 
1135  std::vector<size_t> base::DataDimensions(const std::string &inName)
1136  {
1137 
1138  std::vector<size_t> dataDimensions;
1139  std::ostream &messageStream(*messageStreamPtr);
1140  hid_t dataID = OpenDataSet(inName);
1141  if(dataID < 0)
1142  return(dataDimensions);
1143  hid_t dataSpace = H5Dget_space(dataID);
1144  if(dataSpace < 0){
1145  H5Dclose(dataID);
1146  return(dataDimensions);
1147  }
1148  int numSpaceDim = H5Sget_simple_extent_ndims(dataSpace);
1149  if(numSpaceDim <= 0){
1150  H5Sclose(dataSpace);
1151  H5Dclose(dataID);
1152  return(dataDimensions);
1153  }
1154  std::vector<hsize_t> spaceDims(numSpaceDim,0);
1155  dataDimensions.resize(numSpaceDim,0);
1156  herr_t h5Status = H5Sget_simple_extent_dims(dataSpace,&spaceDims[0],NULL);
1157  if(h5Status < 0){
1158  H5Sclose(dataSpace);
1159  H5Dclose(dataID);
1160  return(dataDimensions);
1161  }
1162  for(size_t iDim = 0;iDim < numSpaceDim;iDim++)
1163  dataDimensions[iDim] = spaceDims[iDim];
1164 
1165  H5Sclose(dataSpace);
1166  H5Dclose(dataID);
1167  return(dataDimensions);
1168  };
1169 
1170  std::vector<size_t> base::AttributeDimensions(const std::string &inName)
1171  {
1172 
1173  std::vector<size_t> attDimensions;
1174  std::ostream &messageStream(*messageStreamPtr);
1175  hid_t attID = OpenAttribute(inName);
1176  if(attID < 0)
1177  return(attDimensions);
1178  hid_t attSpace = H5Aget_space(attID);
1179  if(attSpace < 0){
1180  H5Dclose(attID);
1181  return(attDimensions);
1182  }
1183  int numSpaceDim = H5Sget_simple_extent_ndims(attSpace);
1184  if(numSpaceDim <= 0){
1185  H5Sclose(attSpace);
1186  H5Dclose(attID);
1187  return(attDimensions);
1188  }
1189  std::vector<hsize_t> spaceDims(numSpaceDim,0);
1190  attDimensions.resize(numSpaceDim,0);
1191  herr_t h5Status = H5Sget_simple_extent_dims(attSpace,&spaceDims[0],NULL);
1192  if(h5Status < 0){
1193  H5Sclose(attSpace);
1194  H5Dclose(attID);
1195  return(attDimensions);
1196  }
1197  for(size_t iDim = 0;iDim < numSpaceDim;iDim++)
1198  attDimensions[iDim] = spaceDims[iDim];
1199  H5Sclose(attSpace);
1200  H5Dclose(attID);
1201  return(attDimensions);
1202  };
1203 
1204  int base::InitializeHyperSlab(std::vector<size_t> &inGlobalSize,
1205  std::vector<size_t> &inLocalSize,
1206  std::vector<size_t> &inLocalStart)
1207  {
1208 
1209  hsize_t numPoints = 1;
1210  hsize_t numDim = inGlobalSize.size();
1211 
1212  std::vector<hsize_t> globalSize(numDim,1);
1213  std::vector<hsize_t> localSize(numDim,1);
1214  std::vector<hsize_t> localStart(numDim,0);
1215 
1216  for(int i = 0;i < numDim;i++){
1217  numPoints *= inLocalSize[i];
1218  globalSize[i] = inGlobalSize[i];
1219  localSize[i] = inLocalSize[i];
1220  localStart[i] = inLocalStart[i];
1221  }
1222 
1223  if(globalSlab > 0){
1224  H5Sclose(globalSlab);
1225  }
1226  globalSlab = H5Screate_simple(numDim,&globalSize[0],NULL);
1227  if(globalSlab < 0){
1228  *messageStreamPtr << "Unable to create space for the HDF global grid."
1229  << std::endl;
1230  return(1);
1231  }
1232 
1233  if(localSlab > 0){
1234  H5Sclose(localSlab);
1235  }
1236  localSlab = H5Screate_simple(numDim,&localSize[0],NULL);
1237 
1238  if(localSlab < 0){
1239  *messageStreamPtr << "Unable to create space for the HDF local grid."
1240  << std::endl;
1241  return(1);
1242  }
1243 
1244  if(H5Sselect_hyperslab(globalSlab,H5S_SELECT_SET,
1245  &localStart[0],NULL,&localSize[0],NULL) < 0){
1246  *messageStreamPtr << "Unable to select local hyperslab." << std::endl;
1247  return(1);
1248  }
1249 
1250  return(0);
1251  };
1252 
1253  int base::WriteHyperSlab(const std::string &inName,
1254  const std::vector<size_t> &globalSize,
1255  const std::vector<size_t> &localStart,
1256  const std::vector<size_t> &localSize,
1257  std::vector<double> &inDataVec)
1258  {
1259  std::ostream &messageStream(*messageStreamPtr);
1260 
1261  hid_t dataID = -1;
1262  hid_t fileSpace = -1;
1263  if(!Exists(inName)){ // create it
1264  std::string locationName;
1265  std::string dataSetName;
1266  hid_t parentId;
1267  if(ResolveName(inName,locationName,dataSetName,parentId)){
1268  return(-1);
1269  }
1270  hid_t dataType = H5T_NATIVE_DOUBLE;
1271  fileSpace = CreateDataSpace(globalSize);
1272  if(fileSpace < 0)
1273  return(-1);
1274  dataID = H5Dcreate(parentId,inName.c_str(),dataType,fileSpace,
1275  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1276  if(dataID < 0){
1277  H5Sclose(fileSpace);
1278  return(-1);
1279  }
1280  } else {
1281  dataID = OpenDataSet(inName);
1282  if(dataID < 0)
1283  return(-1);
1284  fileSpace = H5Dget_space(dataID);
1285  if(fileSpace < 0){
1286  H5Dclose(dataID);
1287  return(-1);
1288  }
1289  }
1290 
1291  size_t numDim = localStart.size();
1292  if(localSize.size() != numDim){
1293  H5Dclose(dataID);
1294  H5Sclose(fileSpace);
1295  return(-1);
1296  }
1297 
1298 
1299  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
1300  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
1301  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
1302  NULL,&h5LocalSize[0],NULL);
1303  if(h5Status < 0){
1304  H5Sclose(fileSpace);
1305  H5Dclose(dataID);
1306  return(-1);
1307  }
1308 
1309  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
1310  if(localSpace < 0){
1311  H5Sclose(fileSpace);
1312  H5Dclose(dataID);
1313  return(-1);
1314  }
1315 
1316  size_t numLocalPoints = 1;
1317  for(size_t iDim = 0;iDim < numDim;iDim++)
1318  numLocalPoints *= localSize[iDim];
1319 
1320  if(inDataVec.size() != numLocalPoints){
1321  H5Sclose(fileSpace);
1322  H5Sclose(localSpace);
1323  H5Dclose(dataID);
1324  return(-1);
1325  }
1326 
1327  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
1328  if(collectiveMode && (commPtr != NULL)){
1329  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
1330  }
1331 
1332  h5Status = H5Dwrite(dataID,H5T_NATIVE_DOUBLE,localSpace,
1333  fileSpace,xferProperties,&inDataVec[0]);
1334 
1335  H5Sclose(fileSpace);
1336  H5Sclose(localSpace);
1337  H5Pclose(xferProperties);
1338  H5Dclose(dataID);
1339 
1340  if(h5Status < 0)
1341  return(-1);
1342 
1343  return(0);
1344  };
1345 
1346 
1347  int base::WriteHyperSlab(const std::string &inName,
1348  const std::vector<size_t> &globalSize,
1349  const std::vector<size_t> &localStart,
1350  const std::vector<size_t> &localSize,
1351  const double *inDataPtr)
1352  {
1353  std::ostream &messageStream(*messageStreamPtr);
1354 
1355  hid_t dataID = -1;
1356  hid_t fileSpace = -1;
1357  if(!Exists(inName)){ // create it
1358  std::string locationName;
1359  std::string dataSetName;
1360  hid_t parentId;
1361  if(ResolveName(inName,locationName,dataSetName,parentId)){
1362  return(-1);
1363  }
1364  hid_t dataType = H5T_NATIVE_DOUBLE;
1365  fileSpace = CreateDataSpace(globalSize);
1366  if(fileSpace < 0)
1367  return(-1);
1368  dataID = H5Dcreate(parentId,inName.c_str(),dataType,fileSpace,
1369  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1370  if(dataID < 0){
1371  H5Sclose(fileSpace);
1372  return(-1);
1373  }
1374  } else {
1375  dataID = OpenDataSet(inName);
1376  if(dataID < 0)
1377  return(-1);
1378  fileSpace = H5Dget_space(dataID);
1379  if(fileSpace < 0){
1380  H5Dclose(dataID);
1381  return(-1);
1382  }
1383  }
1384 
1385  size_t numDim = localStart.size();
1386  if(localSize.size() != numDim){
1387  H5Dclose(dataID);
1388  H5Sclose(fileSpace);
1389  return(-1);
1390  }
1391 
1392 
1393  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
1394  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
1395  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
1396  NULL,&h5LocalSize[0],NULL);
1397  if(h5Status < 0){
1398  H5Sclose(fileSpace);
1399  H5Dclose(dataID);
1400  return(-1);
1401  }
1402 
1403  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
1404  if(localSpace < 0){
1405  H5Sclose(fileSpace);
1406  H5Dclose(dataID);
1407  return(-1);
1408  }
1409 
1410  size_t numLocalPoints = 1;
1411  for(size_t iDim = 0;iDim < numDim;iDim++)
1412  numLocalPoints *= localSize[iDim];
1413 
1414  // if(inDataVec.size() != numLocalPoints){
1415  // H5Sclose(fileSpace);
1416  // H5Sclose(localSpace);
1417  // H5Dclose(dataID);
1418  // return(-1);
1419  // }
1420 
1421  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
1422  if(collectiveMode && (commPtr != NULL)){
1423  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
1424  }
1425 
1426  h5Status = H5Dwrite(dataID,H5T_NATIVE_DOUBLE,localSpace,
1427  fileSpace,xferProperties,inDataPtr);
1428 
1429  H5Sclose(fileSpace);
1430  H5Sclose(localSpace);
1431  H5Pclose(xferProperties);
1432  H5Dclose(dataID);
1433 
1434  if(h5Status < 0)
1435  return(-1);
1436 
1437  return(0);
1438  };
1439 
1440  int base::WriteHyperSlab(const std::string &inName,
1441  const std::vector<size_t> &globalSize,
1442  const std::vector<size_t> &localStart,
1443  const std::vector<size_t> &localSize,
1444  const std::vector<size_t> &bufferStart,
1445  const std::vector<size_t> &bufferSize,
1446  const double *inDataPtr)
1447  {
1448  std::ostream &messageStream(*messageStreamPtr);
1449 
1450  hid_t dataID = -1;
1451  hid_t fileSpace = -1;
1452  if(!Exists(inName)){ // create it
1453  std::string locationName;
1454  std::string dataSetName;
1455  hid_t parentId;
1456  if(ResolveName(inName,locationName,dataSetName,parentId)){
1457  return(-1);
1458  }
1459  hid_t dataType = H5T_NATIVE_DOUBLE;
1460  fileSpace = CreateDataSpace(globalSize);
1461  if(fileSpace < 0)
1462  return(-1);
1463  dataID = H5Dcreate(parentId,inName.c_str(),dataType,fileSpace,
1464  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1465  if(dataID < 0){
1466  H5Sclose(fileSpace);
1467  return(-1);
1468  }
1469  } else {
1470  dataID = OpenDataSet(inName);
1471  if(dataID < 0)
1472  return(-1);
1473  fileSpace = H5Dget_space(dataID);
1474  if(fileSpace < 0){
1475  H5Dclose(dataID);
1476  return(-1);
1477  }
1478  }
1479 
1480  size_t numDim = localStart.size();
1481  if(localSize.size() != numDim){
1482  H5Dclose(dataID);
1483  H5Sclose(fileSpace);
1484  return(-1);
1485  }
1486 
1487 
1488  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
1489  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
1490  std::vector<hsize_t> h5BufferStart(bufferStart.begin(),bufferStart.end());
1491  std::vector<hsize_t> h5BufferSize(bufferSize.begin(),bufferSize.end());
1492 
1493  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
1494  NULL,&h5LocalSize[0],NULL);
1495  if(h5Status < 0){
1496  H5Sclose(fileSpace);
1497  H5Dclose(dataID);
1498  return(-1);
1499  }
1500 
1501  hid_t localSpace = CreateDataSpace(bufferSize);
1502  // hid_t localSpace = H5Screate_simple(numDim,&h5BufferSize[0],NULL);
1503  if(localSpace < 0){
1504  H5Sclose(fileSpace);
1505  H5Dclose(dataID);
1506  return(-1);
1507  }
1508 
1509 
1510  h5Status = H5Sselect_hyperslab(localSpace,H5S_SELECT_SET,&h5BufferStart[0],
1511  NULL,&h5LocalSize[0],NULL);
1512  if(h5Status < 0){
1513  H5Sclose(fileSpace);
1514  H5Sclose(localSpace);
1515  H5Dclose(dataID);
1516  return(-1);
1517  }
1518 
1519  size_t numLocalPoints = 1;
1520  for(size_t iDim = 0;iDim < numDim;iDim++)
1521  numLocalPoints *= localSize[iDim];
1522 
1523  // if(inDataVec.size() != numLocalPoints){
1524  // H5Sclose(fileSpace);
1525  // H5Sclose(localSpace);
1526  // H5Dclose(dataID);
1527  // return(-1);
1528  // }
1529 
1530  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
1531  if(collectiveMode && (commPtr != NULL)){
1532  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
1533  }
1534 
1535 
1536  h5Status = H5Dwrite(dataID,H5T_NATIVE_DOUBLE,localSpace,
1537  fileSpace,xferProperties,inDataPtr);
1538 
1539  H5Sclose(fileSpace);
1540  H5Sclose(localSpace);
1541  H5Pclose(xferProperties);
1542  H5Dclose(dataID);
1543 
1544  if(h5Status < 0)
1545  return(-1);
1546 
1547  return(0);
1548  };
1549 
1550  int base::WriteHyperSlab(const std::string &inName,
1551  const std::vector<size_t> &globalSize,
1552  const std::vector<size_t> &localStart,
1553  const std::vector<size_t> &localSize,
1554  const std::vector<size_t> &bufferStart,
1555  const std::vector<size_t> &bufferSize,
1556  const int *inDataPtr)
1557  {
1558  std::ostream &messageStream(*messageStreamPtr);
1559 
1560  hid_t dataID = -1;
1561  hid_t fileSpace = -1;
1562  hid_t dataType = H5T_NATIVE_INT;
1563 
1564  if(!Exists(inName)){ // create it
1565  std::string locationName;
1566  std::string dataSetName;
1567  hid_t parentId;
1568  if(ResolveName(inName,locationName,dataSetName,parentId)){
1569  return(-1);
1570  }
1571  fileSpace = CreateDataSpace(globalSize);
1572  if(fileSpace < 0)
1573  return(-1);
1574  dataID = H5Dcreate(parentId,inName.c_str(),dataType,fileSpace,
1575  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1576  if(dataID < 0){
1577  H5Sclose(fileSpace);
1578  return(-1);
1579  }
1580  } else {
1581  dataID = OpenDataSet(inName);
1582  if(dataID < 0)
1583  return(-1);
1584  fileSpace = H5Dget_space(dataID);
1585  if(fileSpace < 0){
1586  H5Dclose(dataID);
1587  return(-1);
1588  }
1589  }
1590 
1591  size_t numDim = localStart.size();
1592  if(localSize.size() != numDim){
1593  H5Dclose(dataID);
1594  H5Sclose(fileSpace);
1595  return(-1);
1596  }
1597 
1598 
1599  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
1600  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
1601  std::vector<hsize_t> h5BufferStart(bufferStart.begin(),bufferStart.end());
1602  std::vector<hsize_t> h5BufferSize(bufferSize.begin(),bufferSize.end());
1603 
1604  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
1605  NULL,&h5LocalSize[0],NULL);
1606  if(h5Status < 0){
1607  H5Sclose(fileSpace);
1608  H5Dclose(dataID);
1609  return(-1);
1610  }
1611 
1612  hid_t localSpace = CreateDataSpace(bufferSize);
1613  // hid_t localSpace = H5Screate_simple(numDim,&h5BufferSize[0],NULL);
1614  if(localSpace < 0){
1615  H5Sclose(fileSpace);
1616  H5Dclose(dataID);
1617  return(-1);
1618  }
1619 
1620 
1621  h5Status = H5Sselect_hyperslab(localSpace,H5S_SELECT_SET,&h5BufferStart[0],
1622  NULL,&h5LocalSize[0],NULL);
1623  if(h5Status < 0){
1624  H5Sclose(fileSpace);
1625  H5Sclose(localSpace);
1626  H5Dclose(dataID);
1627  return(-1);
1628  }
1629 
1630  size_t numLocalPoints = 1;
1631  for(size_t iDim = 0;iDim < numDim;iDim++)
1632  numLocalPoints *= localSize[iDim];
1633 
1634  // if(inDataVec.size() != numLocalPoints){
1635  // H5Sclose(fileSpace);
1636  // H5Sclose(localSpace);
1637  // H5Dclose(dataID);
1638  // return(-1);
1639  // }
1640 
1641  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
1642  if(collectiveMode && (commPtr != NULL)){
1643  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
1644  }
1645 
1646 
1647  h5Status = H5Dwrite(dataID,dataType,localSpace,
1648  fileSpace,xferProperties,inDataPtr);
1649 
1650  H5Sclose(fileSpace);
1651  H5Sclose(localSpace);
1652  H5Pclose(xferProperties);
1653  H5Dclose(dataID);
1654 
1655  if(h5Status < 0)
1656  return(-1);
1657 
1658  return(0);
1659  };
1660 
1661  int base::WriteHyperSlab(const std::string &inName,
1662  const std::vector<size_t> &globalSize,
1663  const std::vector<size_t> &localStart,
1664  const std::vector<size_t> &localSize,
1665  const std::vector<size_t> &bufferStart,
1666  const std::vector<size_t> &bufferSize,
1667  const char *inDataPtr)
1668  {
1669  std::ostream &messageStream(*messageStreamPtr);
1670 
1671  hid_t dataID = -1;
1672  hid_t fileSpace = -1;
1673  hid_t dataType = H5T_NATIVE_CHAR;
1674 
1675  if(!Exists(inName)){ // create it
1676  std::string locationName;
1677  std::string dataSetName;
1678  hid_t parentId;
1679  if(ResolveName(inName,locationName,dataSetName,parentId)){
1680  return(-1);
1681  }
1682  fileSpace = CreateDataSpace(globalSize);
1683  if(fileSpace < 0)
1684  return(-1);
1685  dataID = H5Dcreate(parentId,inName.c_str(),dataType,fileSpace,
1686  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1687  if(dataID < 0){
1688  H5Sclose(fileSpace);
1689  return(-1);
1690  }
1691  } else {
1692  dataID = OpenDataSet(inName);
1693  if(dataID < 0)
1694  return(-1);
1695  fileSpace = H5Dget_space(dataID);
1696  if(fileSpace < 0){
1697  H5Dclose(dataID);
1698  return(-1);
1699  }
1700  }
1701 
1702  size_t numDim = localStart.size();
1703  if(localSize.size() != numDim){
1704  H5Dclose(dataID);
1705  H5Sclose(fileSpace);
1706  return(-1);
1707  }
1708 
1709 
1710  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
1711  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
1712  std::vector<hsize_t> h5BufferStart(bufferStart.begin(),bufferStart.end());
1713  std::vector<hsize_t> h5BufferSize(bufferSize.begin(),bufferSize.end());
1714 
1715  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
1716  NULL,&h5LocalSize[0],NULL);
1717  if(h5Status < 0){
1718  H5Sclose(fileSpace);
1719  H5Dclose(dataID);
1720  return(-1);
1721  }
1722 
1723  hid_t localSpace = CreateDataSpace(bufferSize);
1724  // hid_t localSpace = H5Screate_simple(numDim,&h5BufferSize[0],NULL);
1725  if(localSpace < 0){
1726  H5Sclose(fileSpace);
1727  H5Dclose(dataID);
1728  return(-1);
1729  }
1730 
1731 
1732  h5Status = H5Sselect_hyperslab(localSpace,H5S_SELECT_SET,&h5BufferStart[0],
1733  NULL,&h5LocalSize[0],NULL);
1734  if(h5Status < 0){
1735  H5Sclose(fileSpace);
1736  H5Sclose(localSpace);
1737  H5Dclose(dataID);
1738  return(-1);
1739  }
1740 
1741  size_t numLocalPoints = 1;
1742  for(size_t iDim = 0;iDim < numDim;iDim++)
1743  numLocalPoints *= localSize[iDim];
1744 
1745  // if(inDataVec.size() != numLocalPoints){
1746  // H5Sclose(fileSpace);
1747  // H5Sclose(localSpace);
1748  // H5Dclose(dataID);
1749  // return(-1);
1750  // }
1751 
1752  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
1753  if(collectiveMode && (commPtr != NULL)){
1754  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
1755  }
1756 
1757 
1758  h5Status = H5Dwrite(dataID,dataType,localSpace,
1759  fileSpace,xferProperties,inDataPtr);
1760 
1761  H5Sclose(fileSpace);
1762  H5Sclose(localSpace);
1763  H5Pclose(xferProperties);
1764  H5Dclose(dataID);
1765 
1766  if(h5Status < 0)
1767  return(-1);
1768 
1769  return(0);
1770  };
1771 
1772  int base::WriteHyperSlab(const std::string &inName,
1773  const std::vector<size_t> &globalSize,
1774  const std::vector<size_t> &localStart,
1775  const std::vector<size_t> &localSize,
1776  std::vector<int> &inDataVec)
1777  {
1778  std::ostream &messageStream(*messageStreamPtr);
1779 
1780  hid_t dataID = -1;
1781  hid_t fileSpace = -1;
1782  if(!Exists(inName)){ // create it
1783  std::string locationName;
1784  std::string dataSetName;
1785  hid_t parentId;
1786  if(ResolveName(inName,locationName,dataSetName,parentId)){
1787  return(-1);
1788  }
1789  hid_t dataType = H5T_NATIVE_INT;
1790  fileSpace = CreateDataSpace(globalSize);
1791  if(fileSpace < 0)
1792  return(-1);
1793  dataID = H5Dcreate(parentId,inName.c_str(),dataType,fileSpace,
1794  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1795  if(dataID < 0){
1796  H5Sclose(fileSpace);
1797  return(-1);
1798  }
1799  } else {
1800  dataID = OpenDataSet(inName);
1801  if(dataID < 0)
1802  return(-1);
1803  fileSpace = H5Dget_space(dataID);
1804  if(fileSpace < 0){
1805  H5Dclose(dataID);
1806  return(-1);
1807  }
1808  }
1809 
1810  size_t numDim = localStart.size();
1811  if(localSize.size() != numDim){
1812  H5Dclose(dataID);
1813  H5Sclose(fileSpace);
1814  return(-1);
1815  }
1816 
1817 
1818  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
1819  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
1820  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
1821  NULL,&h5LocalSize[0],NULL);
1822  if(h5Status < 0){
1823  H5Sclose(fileSpace);
1824  H5Dclose(dataID);
1825  return(-1);
1826  }
1827 
1828  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
1829  if(localSpace < 0){
1830  H5Sclose(fileSpace);
1831  H5Dclose(dataID);
1832  return(-1);
1833  }
1834 
1835  size_t numLocalPoints = 1;
1836  for(size_t iDim = 0;iDim < numDim;iDim++)
1837  numLocalPoints *= localSize[iDim];
1838 
1839  if(inDataVec.size() != numLocalPoints){
1840  H5Sclose(fileSpace);
1841  H5Sclose(localSpace);
1842  H5Dclose(dataID);
1843  return(-1);
1844  }
1845 
1846  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
1847  if(collectiveMode && (commPtr != NULL)){
1848  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
1849  }
1850 
1851  h5Status = H5Dwrite(dataID,H5T_NATIVE_INT,localSpace,
1852  fileSpace,xferProperties,&inDataVec[0]);
1853 
1854  H5Sclose(fileSpace);
1855  H5Sclose(localSpace);
1856  H5Pclose(xferProperties);
1857  H5Dclose(dataID);
1858 
1859  if(h5Status < 0)
1860  return(-1);
1861 
1862  return(0);
1863  };
1864 
1865 
1866  int base::WriteHyperSlab(const std::string &inName,
1867  const std::vector<size_t> &globalSize,
1868  const std::vector<size_t> &localStart,
1869  const std::vector<size_t> &localSize,
1870  std::vector<size_t> &inDataVec)
1871  {
1872  std::ostream &messageStream(*messageStreamPtr);
1873 
1874  hid_t dataID = -1;
1875  hid_t fileSpace = -1;
1876  if(!Exists(inName)){ // create it
1877  std::string locationName;
1878  std::string dataSetName;
1879  hid_t parentId;
1880  if(ResolveName(inName,locationName,dataSetName,parentId)){
1881  return(-1);
1882  }
1883  hid_t dataType = H5T_NATIVE_HSIZE;
1884  fileSpace = CreateDataSpace(globalSize);
1885  if(fileSpace < 0)
1886  return(-1);
1887  dataID = H5Dcreate(parentId,inName.c_str(),dataType,fileSpace,
1888  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1889  if(dataID < 0){
1890  H5Sclose(fileSpace);
1891  return(-1);
1892  }
1893  } else {
1894  dataID = OpenDataSet(inName);
1895  if(dataID < 0)
1896  return(-1);
1897  fileSpace = H5Dget_space(dataID);
1898  if(fileSpace < 0){
1899  H5Dclose(dataID);
1900  return(-1);
1901  }
1902  }
1903 
1904  size_t numDim = localStart.size();
1905  if(localSize.size() != numDim){
1906  H5Dclose(dataID);
1907  H5Sclose(fileSpace);
1908  return(-1);
1909  }
1910 
1911 
1912  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
1913  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
1914  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
1915  NULL,&h5LocalSize[0],NULL);
1916  if(h5Status < 0){
1917  H5Sclose(fileSpace);
1918  H5Dclose(dataID);
1919  return(-1);
1920  }
1921 
1922  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
1923  if(localSpace < 0){
1924  H5Sclose(fileSpace);
1925  H5Dclose(dataID);
1926  return(-1);
1927  }
1928 
1929  size_t numLocalPoints = 1;
1930  for(size_t iDim = 0;iDim < numDim;iDim++)
1931  numLocalPoints *= localSize[iDim];
1932 
1933  if(inDataVec.size() != numLocalPoints){
1934  H5Sclose(fileSpace);
1935  H5Sclose(localSpace);
1936  H5Dclose(dataID);
1937  return(-1);
1938  }
1939 
1940  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
1941  if(collectiveMode && (commPtr != NULL)){
1942  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
1943  }
1944 
1945  h5Status = H5Dwrite(dataID,H5T_NATIVE_HSIZE,localSpace,
1946  fileSpace,xferProperties,&inDataVec[0]);
1947 
1948  H5Sclose(fileSpace);
1949  H5Sclose(localSpace);
1950  H5Pclose(xferProperties);
1951  H5Dclose(dataID);
1952 
1953  if(h5Status < 0)
1954  return(-1);
1955 
1956  return(0);
1957  };
1958 
1959  int base::WriteHyperSlab(const std::string &inName,
1960  const std::vector<size_t> &globalSize,
1961  const std::vector<size_t> &localStart,
1962  const std::vector<size_t> &localSize,
1963  std::vector<char> &inDataVec)
1964  {
1965  std::ostream &messageStream(*messageStreamPtr);
1966 
1967  hid_t dataID = -1;
1968  hid_t fileSpace = -1;
1969  if(!Exists(inName)){ // create it
1970  std::string locationName;
1971  std::string dataSetName;
1972  hid_t parentId;
1973  if(ResolveName(inName,locationName,dataSetName,parentId)){
1974  return(-1);
1975  }
1976  hid_t dataType = H5T_NATIVE_CHAR;
1977  fileSpace = CreateDataSpace(globalSize);
1978  if(fileSpace < 0)
1979  return(-1);
1980  dataID = H5Dcreate(parentId,inName.c_str(),dataType,fileSpace,
1981  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1982  if(dataID < 0){
1983  H5Sclose(fileSpace);
1984  return(-1);
1985  }
1986  } else {
1987  dataID = OpenDataSet(inName);
1988  if(dataID < 0)
1989  return(-1);
1990  fileSpace = H5Dget_space(dataID);
1991  if(fileSpace < 0){
1992  H5Dclose(dataID);
1993  return(-1);
1994  }
1995  }
1996 
1997  size_t numDim = localStart.size();
1998  if(localSize.size() != numDim){
1999  H5Dclose(dataID);
2000  H5Sclose(fileSpace);
2001  return(-1);
2002  }
2003 
2004 
2005  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
2006  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
2007  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
2008  NULL,&h5LocalSize[0],NULL);
2009  if(h5Status < 0){
2010  H5Sclose(fileSpace);
2011  H5Dclose(dataID);
2012  return(-1);
2013  }
2014 
2015  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
2016  if(localSpace < 0){
2017  H5Sclose(fileSpace);
2018  H5Dclose(dataID);
2019  return(-1);
2020  }
2021 
2022  size_t numLocalPoints = 1;
2023  for(size_t iDim = 0;iDim < numDim;iDim++)
2024  numLocalPoints *= localSize[iDim];
2025 
2026  if(inDataVec.size() != numLocalPoints){
2027  H5Sclose(fileSpace);
2028  H5Sclose(localSpace);
2029  H5Dclose(dataID);
2030  return(-1);
2031  }
2032 
2033  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
2034  if(collectiveMode && (commPtr != NULL)){
2035  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
2036  }
2037 
2038  h5Status = H5Dwrite(dataID,H5T_NATIVE_CHAR,localSpace,
2039  fileSpace,xferProperties,&inDataVec[0]);
2040 
2041  H5Sclose(fileSpace);
2042  H5Sclose(localSpace);
2043  H5Pclose(xferProperties);
2044  H5Dclose(dataID);
2045 
2046  if(h5Status < 0)
2047  return(-1);
2048 
2049  return(0);
2050  };
2051 
2052  int base::WriteHyperSlab(const std::string &inName,
2053  const std::vector<size_t> &localStart,
2054  const std::vector<size_t> &localSize,
2055  std::vector<double> &inDataVec)
2056  {
2057  std::ostream &messageStream(*messageStreamPtr);
2058 
2059  hid_t dataID = -1;
2060  hid_t fileSpace = -1;
2061  if(!Exists(inName))
2062  return(-1);
2063  dataID = OpenDataSet(inName);
2064  if(dataID < 0)
2065  return(-1);
2066  fileSpace = H5Dget_space(dataID);
2067  if(fileSpace < 0){
2068  H5Dclose(dataID);
2069  return(-1);
2070  }
2071 
2072  size_t numDim = localStart.size();
2073  if(localSize.size() != numDim){
2074  H5Dclose(dataID);
2075  H5Sclose(fileSpace);
2076  return(-1);
2077  }
2078 
2079 
2080  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
2081  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
2082  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
2083  NULL,&h5LocalSize[0],NULL);
2084  if(h5Status < 0){
2085  H5Sclose(fileSpace);
2086  H5Dclose(dataID);
2087  return(-1);
2088  }
2089 
2090  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
2091  if(localSpace < 0){
2092  H5Sclose(fileSpace);
2093  H5Dclose(dataID);
2094  return(-1);
2095  }
2096 
2097  size_t numLocalPoints = 1;
2098  for(size_t iDim = 0;iDim < numDim;iDim++)
2099  numLocalPoints *= localSize[iDim];
2100 
2101  if(inDataVec.size() != numLocalPoints){
2102  H5Sclose(fileSpace);
2103  H5Sclose(localSpace);
2104  H5Dclose(dataID);
2105  return(-1);
2106  }
2107 
2108  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
2109  if(collectiveMode && (commPtr != NULL)){
2110  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
2111  }
2112 
2113  h5Status = H5Dwrite(dataID,H5T_NATIVE_DOUBLE,localSpace,
2114  fileSpace,xferProperties,&inDataVec[0]);
2115 
2116  H5Sclose(fileSpace);
2117  H5Sclose(localSpace);
2118  H5Pclose(xferProperties);
2119  H5Dclose(dataID);
2120 
2121  if(h5Status < 0)
2122  return(-1);
2123 
2124  return(0);
2125  };
2126 
2127  int base::WriteHyperSlab(const std::string &inName,
2128  const std::vector<size_t> &localStart,
2129  const std::vector<size_t> &localSize,
2130  std::vector<int> &inDataVec)
2131  {
2132  std::ostream &messageStream(*messageStreamPtr);
2133 
2134  hid_t dataID = -1;
2135  hid_t fileSpace = -1;
2136  if(!Exists(inName))
2137  return(-1);
2138  dataID = OpenDataSet(inName);
2139  if(dataID < 0)
2140  return(-1);
2141  fileSpace = H5Dget_space(dataID);
2142  if(fileSpace < 0){
2143  H5Dclose(dataID);
2144  return(-1);
2145  }
2146 
2147  size_t numDim = localStart.size();
2148  if(localSize.size() != numDim){
2149  H5Dclose(dataID);
2150  H5Sclose(fileSpace);
2151  return(-1);
2152  }
2153 
2154 
2155  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
2156  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
2157  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
2158  NULL,&h5LocalSize[0],NULL);
2159  if(h5Status < 0){
2160  H5Sclose(fileSpace);
2161  H5Dclose(dataID);
2162  return(-1);
2163  }
2164 
2165  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
2166  if(localSpace < 0){
2167  H5Sclose(fileSpace);
2168  H5Dclose(dataID);
2169  return(-1);
2170  }
2171 
2172  size_t numLocalPoints = 1;
2173  for(size_t iDim = 0;iDim < numDim;iDim++)
2174  numLocalPoints *= localSize[iDim];
2175 
2176  if(inDataVec.size() != numLocalPoints){
2177  H5Sclose(fileSpace);
2178  H5Sclose(localSpace);
2179  H5Dclose(dataID);
2180  return(-1);
2181  }
2182 
2183  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
2184  if(collectiveMode && (commPtr != NULL)){
2185  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
2186  }
2187 
2188  h5Status = H5Dwrite(dataID,H5T_NATIVE_INT,localSpace,
2189  fileSpace,xferProperties,&inDataVec[0]);
2190 
2191  H5Sclose(fileSpace);
2192  H5Sclose(localSpace);
2193  H5Pclose(xferProperties);
2194  H5Dclose(dataID);
2195 
2196  if(h5Status < 0)
2197  return(-1);
2198 
2199  return(0);
2200  };
2201 
2202  int base::WriteHyperSlab(const std::string &inName,
2203  const std::vector<size_t> &localStart,
2204  const std::vector<size_t> &localSize,
2205  std::vector<char> &inDataVec)
2206  {
2207  std::ostream &messageStream(*messageStreamPtr);
2208 
2209  hid_t dataID = -1;
2210  hid_t fileSpace = -1;
2211  if(!Exists(inName))
2212  return(-1);
2213  dataID = OpenDataSet(inName);
2214  if(dataID < 0)
2215  return(-1);
2216  fileSpace = H5Dget_space(dataID);
2217  if(fileSpace < 0){
2218  H5Dclose(dataID);
2219  return(-1);
2220  }
2221 
2222  size_t numDim = localStart.size();
2223  if(localSize.size() != numDim){
2224  H5Dclose(dataID);
2225  H5Sclose(fileSpace);
2226  return(-1);
2227  }
2228 
2229 
2230  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
2231  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
2232  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
2233  NULL,&h5LocalSize[0],NULL);
2234  if(h5Status < 0){
2235  H5Sclose(fileSpace);
2236  H5Dclose(dataID);
2237  return(-1);
2238  }
2239 
2240  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
2241  if(localSpace < 0){
2242  H5Sclose(fileSpace);
2243  H5Dclose(dataID);
2244  return(-1);
2245  }
2246 
2247  size_t numLocalPoints = 1;
2248  for(size_t iDim = 0;iDim < numDim;iDim++)
2249  numLocalPoints *= localSize[iDim];
2250 
2251  if(inDataVec.size() != numLocalPoints){
2252  H5Sclose(fileSpace);
2253  H5Sclose(localSpace);
2254  H5Dclose(dataID);
2255  return(-1);
2256  }
2257 
2258  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
2259  if(collectiveMode && (commPtr != NULL)){
2260  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
2261  }
2262 
2263  h5Status = H5Dwrite(dataID,H5T_NATIVE_CHAR,localSpace,
2264  fileSpace,xferProperties,&inDataVec[0]);
2265 
2266  H5Sclose(fileSpace);
2267  H5Sclose(localSpace);
2268  H5Pclose(xferProperties);
2269  H5Dclose(dataID);
2270 
2271  if(h5Status < 0)
2272  return(-1);
2273 
2274  return(0);
2275  };
2276 
2277  int base::WriteHyperSlab(const std::string &inName,
2278  const std::vector<size_t> &localStart,
2279  const std::vector<size_t> &localSize,
2280  std::vector<size_t> &inDataVec)
2281  {
2282  std::ostream &messageStream(*messageStreamPtr);
2283 
2284  hid_t dataID = -1;
2285  hid_t fileSpace = -1;
2286  if(!Exists(inName))
2287  return(-1);
2288  dataID = OpenDataSet(inName);
2289  if(dataID < 0)
2290  return(-1);
2291  fileSpace = H5Dget_space(dataID);
2292  if(fileSpace < 0){
2293  H5Dclose(dataID);
2294  return(-1);
2295  }
2296 
2297  size_t numDim = localStart.size();
2298  if(localSize.size() != numDim){
2299  H5Dclose(dataID);
2300  H5Sclose(fileSpace);
2301  return(-1);
2302  }
2303 
2304 
2305  std::vector<hsize_t> h5LocalStart(localStart.begin(),localStart.end());
2306  std::vector<hsize_t> h5LocalSize(localSize.begin(),localSize.end());
2307  herr_t h5Status = H5Sselect_hyperslab(fileSpace,H5S_SELECT_SET,&h5LocalStart[0],
2308  NULL,&h5LocalSize[0],NULL);
2309  if(h5Status < 0){
2310  H5Sclose(fileSpace);
2311  H5Dclose(dataID);
2312  return(-1);
2313  }
2314 
2315  hid_t localSpace = H5Screate_simple(numDim,&h5LocalSize[0],NULL);
2316  if(localSpace < 0){
2317  H5Sclose(fileSpace);
2318  H5Dclose(dataID);
2319  return(-1);
2320  }
2321 
2322  size_t numLocalPoints = 1;
2323  for(size_t iDim = 0;iDim < numDim;iDim++)
2324  numLocalPoints *= localSize[iDim];
2325 
2326  if(inDataVec.size() != numLocalPoints){
2327  H5Sclose(fileSpace);
2328  H5Sclose(localSpace);
2329  H5Dclose(dataID);
2330  return(-1);
2331  }
2332 
2333  hid_t xferProperties = H5Pcreate(H5P_DATASET_XFER);
2334  if(collectiveMode && (commPtr != NULL)){
2335  H5Pset_dxpl_mpio(xferProperties,H5FD_MPIO_COLLECTIVE);
2336  }
2337 
2338  h5Status = H5Dwrite(dataID,H5T_NATIVE_HSIZE,localSpace,
2339  fileSpace,xferProperties,&inDataVec[0]);
2340 
2341  H5Sclose(fileSpace);
2342  H5Sclose(localSpace);
2343  H5Pclose(xferProperties);
2344  H5Dclose(dataID);
2345 
2346  if(h5Status < 0)
2347  return(-1);
2348 
2349  return(0);
2350  };
2351 
2352 
2353  int base::CreateGroup(const std::string &inName)
2354  {
2355  std::string groupName;
2356  std::string locationName;
2357  hid_t parentId;
2358  if(ResolveName(inName,locationName,groupName,parentId))
2359  return(-1);
2360  hid_t groupId = H5Gcreate(parentId,inName.c_str(),H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2361  // hdfScope.push_back(groupId);
2362  H5Gclose(groupId);
2363  return(0);
2364  };
2365 
2366  hid_t base::CreateDataSpace(const std::vector<size_t> &dataSpaceDims)
2367  {
2368  hsize_t numDim = dataSpaceDims.size();
2369  if(numDim == 0)
2370  return(-1);
2371  // if(dataSpace > 0){
2372  // H5Sclose(dataSpace);
2373  // }
2374  std::vector<hsize_t> hdf5SpaceDimensions(dataSpaceDims.begin(),dataSpaceDims.end());
2375  hid_t dataSpace = H5Screate_simple(numDim,&hdf5SpaceDimensions[0],NULL);
2376  return(dataSpace);
2377  };
2378 
2379 
2380  int base::CreateDataSet(const std::string &inName,
2381  const std::vector<size_t> &dataSpaceDims,
2382  size_t elementSize)
2383  {
2384  std::string locationName;
2385  std::string dataSetName;
2386  hid_t parentId;
2387  if(ResolveName(inName,locationName,dataSetName,parentId)){
2388  return(-1);
2389  }
2390  hid_t dataType = H5T_NATIVE_INT;
2391  switch(elementSize){
2392  case 1:
2393  dataType = H5T_NATIVE_CHAR;
2394  break;
2395  case 4:
2396  dataType = H5T_NATIVE_INT;
2397  break;
2398  case 8:
2399  default:
2400  dataType = H5T_NATIVE_DOUBLE;
2401  }
2402  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2403  if(dataSpace < 0)
2404  return(-1);
2405  // if(dataSet > 0)
2406  // H5Dclose(dataSet);
2407  hid_t dataSet = H5Dcreate(parentId,inName.c_str(),dataType,dataSpace,
2408  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2409  H5Sclose(dataSpace);
2410  H5Dclose(dataSet);
2411 
2412  return(0);
2413  };
2414 
2415  int base::CreateDataSet(const std::string &inName,
2416  const std::vector<size_t> &dataSpaceDims,
2417  std::vector<double> &inData)
2418  {
2419  std::string locationName;
2420  std::string dataSetName;
2421  hid_t parentId;
2422  if(ResolveName(inName,locationName,dataSetName,parentId)){
2423  return(-1);
2424  }
2425  hid_t dataType = H5T_NATIVE_DOUBLE;
2426  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2427  if(dataSpace < 0)
2428  return(-1);
2429  // if(dataSet > 0)
2430  // H5Dclose(dataSet);
2431  hid_t dataSet = H5Dcreate(parentId,inName.c_str(),dataType,dataSpace,
2432  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2433  if(dataSet < 0) {
2434  H5Sclose(dataSpace);
2435  return(-1);
2436  }
2437 
2438 
2439  herr_t status = H5Dwrite(dataSet,dataType,H5S_ALL,H5S_ALL,
2440  H5P_DEFAULT,&inData[0]);
2441  H5Sclose(dataSpace);
2442  H5Dclose(dataSet);
2443 
2444  return(status);
2445 
2446  };
2447 
2448  int base::CreateDataSet(const std::string &inName,
2449  const std::vector<size_t> &dataSpaceDims,
2450  std::vector<int> &inData)
2451  {
2452  std::string locationName;
2453  std::string dataSetName;
2454  hid_t parentId;
2455  if(ResolveName(inName,locationName,dataSetName,parentId)){
2456  return(-1);
2457  }
2458  hid_t dataType = H5T_NATIVE_INT;
2459  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2460  if(dataSpace < 0)
2461  return(-1);
2462  // if(dataSet > 0)
2463  // H5Dclose(dataSet);
2464  hid_t dataSet = H5Dcreate(parentId,inName.c_str(),dataType,dataSpace,
2465  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2466  if(dataSet < 0){
2467  H5Sclose(dataSpace);
2468  return(-1);
2469  }
2470 
2471  herr_t status = H5Dwrite(dataSet,dataType,H5S_ALL,H5S_ALL,
2472  H5P_DEFAULT,&inData[0]);
2473 // if(status < 0)
2474 // return(status);
2475  H5Sclose(dataSpace);
2476  H5Dclose(dataSet);
2477  // dataSet = -1;
2478  // dataSpace = -1;
2479  return(status);
2480  };
2481 
2482  int base::CreateAttribute(const std::string &inName,
2483  const std::vector<size_t> &dataSpaceDims,
2484  size_t elementSize)
2485  {
2486  std::string locationName;
2487  std::string attName;
2488  hid_t parentId;
2489  if(ResolveName(inName,locationName,attName,parentId)){
2490  return(-1);
2491  }
2492  hid_t dataType = H5T_NATIVE_INT;
2493  switch(elementSize){
2494  case 1:
2495  dataType = H5T_NATIVE_CHAR;
2496  break;
2497  case 4:
2498  dataType = H5T_NATIVE_INT;
2499  break;
2500  case 8:
2501  default:
2502  dataType = H5T_NATIVE_DOUBLE;
2503  }
2504  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2505  if(dataSpace < 0)
2506  return(-1);
2507  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2508  attName.c_str(),dataType,dataSpace,
2509  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2510  if(attributeId <= 0){
2511  H5Sclose(dataSpace);
2512  return(1);
2513  }
2514 
2515  H5Sclose(dataSpace);
2516  dataSpace = -1;
2517  H5Aclose(attributeId);
2518 
2519  return(0);
2520  };
2521 
2522 
2523  int base::CreateAttribute(const std::string &inName,
2524  const std::vector<size_t> &dataSpaceDims,
2525  const int *inBuf)
2526  {
2527  std::string locationName;
2528  std::string attName;
2529  hid_t parentId;
2530  if(ResolveName(inName,locationName,attName,parentId)){
2531  return(-1);
2532  }
2533  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2534  if(dataSpace < 0)
2535  return(-1);
2536  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2537  attName.c_str(),H5T_NATIVE_INT,dataSpace,
2538  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2539  if(attributeId <= 0){
2540  H5Sclose(dataSpace);
2541  return(1);
2542  }
2543  herr_t retVal = H5Awrite(attributeId,H5T_NATIVE_INT,inBuf);
2544 
2545  H5Sclose(dataSpace);
2546  H5Aclose(attributeId);
2547  dataSpace = -1;
2548  if(retVal < 0){
2549  return(1);
2550  }
2551  return(0);
2552 
2553  };
2554 
2555  int base::CreateAttribute(const std::string &inName,const std::vector<size_t> &dataSpaceDims,
2556  const std::vector<int> &inData)
2557  {
2558  std::string locationName;
2559  std::string attName;
2560  hid_t parentId;
2561  if(ResolveName(inName,locationName,attName,parentId)){
2562  return(-1);
2563  }
2564  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2565  if(dataSpace < 0)
2566  return(-1);
2567  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2568  attName.c_str(),H5T_NATIVE_INT,dataSpace,
2569  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2570  if(attributeId <= 0){
2571  H5Sclose(dataSpace);
2572  return(1);
2573  }
2574  herr_t retVal = H5Awrite(attributeId,H5T_NATIVE_INT,&inData[0]);
2575 
2576  H5Sclose(dataSpace);
2577  H5Aclose(attributeId);
2578  dataSpace = -1;
2579  if(retVal < 0){
2580  return(1);
2581  }
2582  return(0);
2583  };
2584 
2585  int base::CreateAttribute(const std::string &inName,
2586  const std::vector<size_t> &dataSpaceDims,
2587  const double *inBuf)
2588  {
2589  std::string locationName;
2590  std::string attName;
2591  hid_t parentId;
2592  if(ResolveName(inName,locationName,attName,parentId)){
2593  return(-1);
2594  }
2595  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2596  if(dataSpace < 0)
2597  return(-1);
2598  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2599  attName.c_str(),H5T_NATIVE_DOUBLE,dataSpace,
2600  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2601  if(attributeId <= 0){
2602  H5Sclose(dataSpace);
2603  return(1);
2604  }
2605 
2606  herr_t retVal = H5Awrite(attributeId,H5T_NATIVE_DOUBLE,inBuf);
2607 
2608  H5Sclose(dataSpace);
2609  H5Aclose(attributeId);
2610  dataSpace = -1;
2611  if(retVal < 0){
2612  return(1);
2613  }
2614  return(0);
2615  };
2616 
2617  int base::CreateAttribute(const std::string &inName,
2618  const std::vector<size_t> &dataSpaceDims,
2619  const std::vector<double> &inData)
2620  {
2621  std::string locationName;
2622  std::string attName;
2623  hid_t parentId;
2624  if(ResolveName(inName,locationName,attName,parentId)){
2625  return(-1);
2626  }
2627  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2628  if(dataSpace < 0)
2629  return(-1);
2630  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2631  attName.c_str(),H5T_NATIVE_DOUBLE,dataSpace,
2632  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2633  if(attributeId <= 0){
2634  H5Sclose(dataSpace);
2635  return(1);
2636  }
2637 
2638  herr_t retVal = H5Awrite(attributeId,H5T_NATIVE_DOUBLE,&inData[0]);
2639 
2640  H5Sclose(dataSpace);
2641  H5Aclose(attributeId);
2642  dataSpace = -1;
2643  if(retVal < 0){
2644  return(1);
2645  }
2646  return(0);
2647  };
2648 
2649  int base::CreateAttribute(const std::string &inName,
2650  const std::vector<size_t> &dataSpaceDims,
2651  const size_t *inBuf)
2652  {
2653  std::string locationName;
2654  std::string attName;
2655  hid_t parentId;
2656  if(ResolveName(inName,locationName,attName,parentId)){
2657  return(-1);
2658  }
2659  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2660  if(dataSpace < 0)
2661  return(-1);
2662  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2663  attName.c_str(),H5T_NATIVE_HSIZE,dataSpace,
2664  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2665  if(attributeId <= 0){
2666  H5Sclose(dataSpace);
2667  return(1);
2668  }
2669 
2670  herr_t retVal = H5Awrite(attributeId,H5T_NATIVE_HSIZE,inBuf);
2671 
2672  H5Sclose(dataSpace);
2673  H5Aclose(attributeId);
2674  dataSpace = -1;
2675  if(retVal < 0){
2676  return(1);
2677  }
2678  return(0);
2679  };
2680 
2681  int base::CreateAttribute(const std::string &inName,
2682  const std::vector<size_t> &dataSpaceDims,
2683  const std::vector<size_t> &inData)
2684  {
2685  std::string locationName;
2686  std::string attName;
2687  hid_t parentId;
2688  if(ResolveName(inName,locationName,attName,parentId)){
2689  return(-1);
2690  }
2691  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2692  if(dataSpace < 0)
2693  return(-1);
2694 
2695  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2696  attName.c_str(),H5T_NATIVE_HSIZE,dataSpace,
2697  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2698  if(attributeId <= 0){
2699  H5Sclose(dataSpace);
2700  return(1);
2701  }
2702 
2703  herr_t retVal = H5Awrite(attributeId,H5T_NATIVE_HSIZE,&inData[0]);
2704 
2705  H5Sclose(dataSpace);
2706  H5Aclose(attributeId);
2707  dataSpace = -1;
2708  if(retVal < 0){
2709  return(1);
2710  }
2711  return(0);
2712  };
2713 
2714  int base::CreateAttribute(const std::string &inName,
2715  const std::vector<size_t> &dataSpaceDims,
2716  const char *inBuf)
2717  {
2718  std::string locationName;
2719  std::string attName;
2720  hid_t parentId;
2721  if(ResolveName(inName,locationName,attName,parentId)){
2722  return(-1);
2723  }
2724  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2725  if(dataSpace < 0)
2726  return(-1);
2727  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2728  attName.c_str(),H5T_NATIVE_CHAR,dataSpace,
2729  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2730  if(attributeId <= 0){
2731  H5Sclose(dataSpace);
2732  return(1);
2733  }
2734 
2735  herr_t retVal = H5Awrite(attributeId,H5T_NATIVE_CHAR,inBuf);
2736 
2737  H5Sclose(dataSpace);
2738  H5Aclose(attributeId);
2739  dataSpace = -1;
2740  if(retVal < 0){
2741  return(1);
2742  }
2743  return(0);
2744  };
2745 
2746  int base::CreateAttribute(const std::string &inName,
2747  const std::string &inData)
2748  {
2749  std::string locationName;
2750  std::string attName;
2751  hid_t parentId;
2752  if(ResolveName(inName,locationName,attName,parentId)){
2753  return(-1);
2754  }
2755 
2756  std::vector<size_t> dataSpaceDims(1,1);
2757  hid_t dataSpace = CreateDataSpace(dataSpaceDims);
2758  if(dataSpace < 0)
2759  return(-1);
2760 
2761  size_t attributeSize = inData.size() + 1;
2762  hid_t typeID = H5Tcopy(H5T_C_S1);
2763  H5Tset_size(typeID,inData.size()+1);
2764  const char *stringToWrite = inData.c_str();
2765  // size_t stringLen = std::strlen(stringToWrite);
2766 
2767  hid_t attributeId = H5Acreate_by_name(parentId,locationName.c_str(),
2768  attName.c_str(),typeID,dataSpace,
2769  H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
2770  if(attributeId <= 0){
2771  H5Sclose(dataSpace);
2772  H5Tclose(typeID);
2773  return(1);
2774  }
2775 
2776  herr_t retVal = H5Awrite(attributeId,typeID,stringToWrite);
2777 
2778  H5Tclose(typeID);
2779  H5Sclose(dataSpace);
2780  H5Aclose(attributeId);
2781  dataSpace = -1;
2782 
2783  if(retVal < 0)
2784  return(1);
2785 
2786  return(0);
2787  };
2788  }
2789  }
2790 }
std::vector< pcpp::field::metadataset > domainStateDictionaries
Definition: PCPPIO.H:74
void OpenFileTag(std::ostream &outStream)
Definition: PCPPHDF5.C:12
void size_t int size_t int size_t int int int int double int int double double *void size_t int size_t int int int int int double int size_t size_t size_t double double *void size_t int size_t int size_t size_t int double int double double *void size_t size_t * bufferSize
void CloseFileTag(std::ostream &outStream)
Definition: PCPPHDF5.C:20
void const size_t * numPoints
Definition: EulerKernels.H:10
int ReadAttribute(const std::string &inName, int *inBuf)
Definition: PCPPHDF5.C:1029
void AddField(const std::string &name, char loc, unsigned int ncomp, unsigned int dsize, const std::string &unit)
std::vector< std::vector< std::string > > geometryGridNames
Grid names for each geometry.
Definition: PCPPIO.H:58
void CloseGridTag(std::ostream &outStream)
Definition: PCPPHDF5.C:32
pcpp::field::metadataset simulationParamDictionary
Dictionaries summarizing the attribute and datatsets in the file.
Definition: PCPPIO.H:71
void const size_t const size_t * gridSizes
Definition: EulerKernels.H:10
int FileInfo(const std::string &hdfFileName, pcpp::io::simfileinfo &fileInfo, std::ostream &messageStream)
Definition: PCPPHDF5.C:621
void RenewStream(std::ostringstream &outStream)
int LegacyFileInfo(pcpp::io::hdf5::base &hdf5File, simfileinfo &fileInfo, std::ostream &messageStream)
Definition: PCPPHDF5.C:469
bool Exists(const std::string &linkName)
Definition: PCPPHDF5.C:872
void const size_t const size_t const size_t const int const int * gridType
Definition: EulerKernels.H:10
std::vector< std::vector< std::string > > domainGridPaths
Path to grid data (including file name, geometry and grid names)
Definition: PCPPIO.H:67
int SetErr(int errin)
Definition: COMM.H:110
std::string Name()
Definition: PCPPHDF5.H:231
std::vector< int > gridNumDimensions
Definition: PCPPIO.H:51
std::bitset< NUMFORMATBITS > formatBits
Definition: PCPPIO.H:42
int WriteGridData(const std::string &fileName, const std::string &dataName, unsigned int dataSize, const std::string &dataPath, const std::vector< size_t > &gridSize, std::ostream &outStream)
Definition: PCPPHDF5.C:118
void const size_t const size_t const size_t const double const double * x
void OpenGridTag(const std::string &gridName, const std::string &gridType, double inTime, std::ostream &outStream)
Definition: PCPPHDF5.C:26
bool AttributeExists(const std::string &inName)
Definition: PCPPHDF5.C:852
int PlasCom2FileInfo(pcpp::io::hdf5::base &hdf5File, simfileinfo &fileInfo, std::ostream &messageStream)
Definition: PCPPHDF5.C:276
int Check(comm::Ops op=comm::MAXOP)
Definition: COMM.C:355
std::string fileName
Definition: PCPPIO.H:41
std::vector< std::vector< size_t > > gridSizes
Definition: PCPPIO.H:52
Main encapsulation of MPI.
Definition: COMM.H:62
void TokenizeString(std::vector< std::string > &tokens, const std::string &source)
Tokenize string.
Definition: AppTools.H:132
pcpp::field::metadataset simulationStateDictionary
Definition: PCPPIO.H:72
void DumpContents(std::ostream &Ostr, const ContainerType &c, std::string del="\)
Dump container contents.
Definition: AppTools.H:117
std::vector< double > legacyHeader
Time Re Pr from PlasComCM.
Definition: PCPPIO.H:46
int WriteGridSection(const std::string &topoType, const std::string &geomType, const std::string &fileName, const std::string &gridPath, const std::vector< size_t > &gridSize, std::ostream &outStream)
Definition: PCPPHDF5.C:38
std::vector< std::vector< std::string > > domainGridNames
Domain-specific grid names for which there is data.
Definition: PCPPIO.H:65
std::vector< std::string > geometryNames
Names of all geometries in file.
Definition: PCPPIO.H:56
std::vector< std::string > gridNames
Full grid names (geometryName:gridName)
Definition: PCPPIO.H:50
std::vector< std::vector< std::vector< size_t > > > geometryGridSizes
Sizes for each geometry grid.
Definition: PCPPIO.H:60
int StreamBroadCast(DataType &inData, int root_rank=0)
Definition: COMM.H:225
std::vector< pcpp::field::metadataset > domainParamDictionaries
Definition: PCPPIO.H:73
std::vector< std::string > domainNames
Definition: PCPPIO.H:63