fix more stuff

This commit is contained in:
2011-08-12 07:05:54 +00:00
parent 8862acd04f
commit b1e8e15b90
6 changed files with 4403 additions and 4507 deletions
+1 -3
View File
@@ -3,7 +3,5 @@
aclocal
autoconf
automake -a -c
./configure --prefix=$HOME --with-h5part=$HOME --enable-boost
make
#make install
+3881 -3980
View File
File diff suppressed because it is too large Load Diff
+16 -16
View File
@@ -69,31 +69,31 @@ AC_LANG_PUSH(C)
[AC_MSG_ERROR(hdf5 library not found!)]
)
H5PART_PREFIX=""
H5PART_INCL_PATH=""
H5PART_LIB_PATH=""
H5HUT_PREFIX=""
H5HUT_INCL_PATH=""
H5HUT_LIB_PATH=""
AC_ARG_WITH(
[h5part],
AC_HELP_STRING([--with-h5part=PREFIX],
[prefix, parent directory, where the serial(!) h5part library and header files can be found]),
[H5PART_PREFIX=$withval
H5PART_INCL_PATH=${H5PART_PREFIX}"/include "
H5PART_LIB_PATH=${H5PART_PREFIX}"/lib "]
[h5hut],
AC_HELP_STRING([--with-h5hut=PREFIX],
[prefix, parent directory, where the serial(!) h5hut library and header files can be found]),
[H5HUT_PREFIX=$withval
H5HUT_INCL_PATH=${H5HUT_PREFIX}"/include "
H5HUT_LIB_PATH=${H5HUT_PREFIX}"/lib "]
)
if test "${H5PART_PREFIX}" != ""; then
CPPFLAGS=${CPPFLAGS}" -I"${H5PART_INCL_PATH};
LDFLAGS=${LDFLAGS}" -L"${H5PART_LIB_PATH};
if test "${H5HUT_PREFIX}" != ""; then
CPPFLAGS=${CPPFLAGS}" -I"${H5HUT_INCL_PATH};
LDFLAGS=${LDFLAGS}" -L"${H5HUT_LIB_PATH};
fi
AC_CHECK_HEADERS(
[H5Part.h],
[H5hut.h],
[],
[AC_MSG_ERROR(H5Part.h not found!)]
[AC_MSG_ERROR(H5hut.h not found!)]
)
AC_CHECK_LIB(
[H5Part],
[H5hut],
[main],
[],
[AC_MSG_ERROR(H5Part library not found!)]
[AC_MSG_ERROR(H5hut library not found!)]
)
AC_LANG_POP
AC_LANG(C++)
+171 -172
View File
@@ -1,6 +1,6 @@
/* Description
*
* This application merges and slices one, two or more H5Part files
* This application merges and slices one, two or more H5hut files
* into a single one. The range of each file which should be merged/
* sliced can be specified on the command line where each input file
* is handled similar to a python array. Negative indices are counted
@@ -18,14 +18,18 @@
*
* \bug this code is under permanent development.
*
* \todo ??
* \todo H5hut port
*/
#include <hdf5.h>
#include "H5hut.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include "H5Part.hh"
#include <cstdlib>
#include "optparse.hh"
#ifdef USE_BOOST
@@ -35,12 +39,14 @@
#define MAX_LEN 128
using namespace std;
/*
struct strCmp {
bool operator()( const char* s1, const char* s2 ) const {
return strcmp( s1, s2 ) < 0;
}
};
*/
struct StringCmp {
bool operator()( const string s1, const string s2 ) const {
return s1 < s2;
@@ -51,20 +57,23 @@ struct StringCmp {
using boost::any_cast;
typedef map<string, boost::any, StringCmp> StringAnyValueMap;
#endif
typedef map<string, int, StringCmp> StringIntMap;
typedef map<string, h5part_int64_t, StringCmp> StringInt64Map;
typedef map<string, h5_int64_t, StringCmp> StringInt64Map;
h5part_int64_t copyFileAttribute(H5PartFile* In, H5PartFile* Out, string AttrName, h5part_int64_t Type, h5part_int64_t Num);
h5part_int64_t copyFileToStepAttribute(H5PartFile* In, H5PartFile* Out, string AttrName, h5part_int64_t Type, h5part_int64_t Num);
h5_int64_t copyFileAttribute(h5_file_t* In, h5_file_t* Out, string AttrName, h5_int64_t Type, h5_int64_t Num);
h5_int64_t copyFileToStepAttribute(h5_file_t* In, h5_file_t* Out, string AttrName, h5_int64_t Type, h5_int64_t Num);
#ifdef USE_BOOST
h5part_int64_t copyFileAttribute(H5PartFile* In, H5PartFile* Out, StringAnyValueMap &FileAttributes, string AttrName, h5part_int64_t Type, h5part_int64_t Num);
h5part_int64_t copyFileToStepAttribute(H5PartFile* In, H5PartFile* Out, StringAnyValueMap &FileAttributes, string AttrName, h5part_int64_t Type, h5part_int64_t Num);
h5_int64_t copyFileAttribute(h5_file_t* In, h5_file_t* Out, StringAnyValueMap &FileAttributes, string AttrName,
h5_int64_t Type, h5_int64_t Num);
h5_int64_t copyFileToStepAttribute(h5_file_t* In, h5_file_t* Out, StringAnyValueMap &FileAttributes, string AttrName,
h5_int64_t Type, h5_int64_t Num);
#endif
h5part_int64_t copyStepAttribute(H5PartFile* In, H5PartFile* Out, string AttrName, h5part_int64_t Type, h5part_int64_t Num);
h5part_int64_t copyDataset(H5PartFile* In, H5PartFile* Out, string SetName, h5part_int64_t Type, h5part_float64_t* FloatArray, h5part_int64_t* IntArray);
h5_int64_t copyStepAttribute(h5_file_t* In, h5_file_t* Out, string AttrName, h5_int64_t Type, h5_int64_t Num);
h5_int64_t copyDataset(h5_file_t* In, h5_file_t* Out, string SetName,
h5_int64_t Type, h5_float64_t* FloatArray, h5_int64_t* IntArray);
int main(int argc, char **argv){
@@ -75,8 +84,8 @@ int main(int argc, char **argv){
using optparse::BOOL;
using optparse::INT;
using optparse::DOUBLE;
H5PartFile *H5OutFile, *H5InFile;
h5_file_t *H5OutFile, *H5InFile;
ifstream testopen;
int NumInput = 0;
@@ -119,25 +128,25 @@ int main(int argc, char **argv){
StringInt64Map::iterator itType;
StringInt64Map::iterator itNumType;
h5part_int64_t NumParticles = 0;
h5part_int64_t maxNumParticles = 0;
h5_int64_t NumParticles = 0;
h5_int64_t maxNumParticles = 0;
h5part_int64_t NumSteps;
h5part_int64_t effStep = 0;
h5_int64_t NumSteps;
h5_int64_t effStep = 0;
bool firstStepInput = true;
h5part_float64_t* FloatValues = NULL;
h5part_int64_t* IntegerValues = NULL;
h5_float64_t* FloatValues = NULL;
h5_int64_t* IntegerValues = NULL;
h5part_int64_t Type;
h5part_int64_t SetType;
h5part_int64_t NumType;
h5part_int64_t SetNum;
h5_int64_t Type;
h5_int64_t SetType;
h5_int64_t NumType;
h5_int64_t SetNum;
int verbosity = 0;
h5part_int64_t rc;
h5_int64_t rc;
string usage("H5merge\n\nmerges two or more H5Part files, but can also be used to slice a H5Part file\n\nUsage: H5merge [[options]] input1.h5[from1:to1] [input2.h5[from2:to2] ... inputN.h5[fromN:toN]] output.h5,\n where fromX and toX are the step numbers which determine the range to be merged.\n Negative values are counted from the end of the file\n\noptions:");
string usage("H5merge\n\nmerges two or more H5hut files, but can also be used to slice a H5hut file\n\nUsage: H5merge [[options]] input1.h5[from1:to1] [input2.h5[from2:to2] ... inputN.h5[fromN:toN]] output.h5,\n where fromX and toX are the step numbers which determine the range to be merged.\n Negative values are counted from the end of the file\n\noptions:");
optparse::OptionParser parser(usage);
parser.add_option("-h", "--help", "help","Show this message",STORE_TRUE, BOOL, "0");
@@ -171,7 +180,7 @@ int main(int argc, char **argv){
to = new int[NumInput];
verbosity = parser.get<int>("verbosity");
H5PartSetVerbosityLevel(verbosity);
H5SetVerbosityLevel(verbosity);
/**************************************************************\
* Parse input file names and ranges to be merged
@@ -299,12 +308,12 @@ int main(int argc, char **argv){
for (int i = 0; i < effNumInput; ++i)
{
H5InFile = H5PartOpenFile(InputFilenames[i].c_str(), H5PART_READ);
H5InFile = H5OpenFile(InputFilenames[i].c_str(), H5_O_RDONLY, NULL);
/**************************************************************\
* fix range if values are negative
\**************************************************************/
int n_steps = H5PartGetNumSteps(H5InFile);
int n_steps = H5GetNumSteps(H5InFile);
if (from[i] >= n_steps)
from[i] = n_steps - 1;
@@ -327,18 +336,15 @@ int main(int argc, char **argv){
NumSteps = to[i] - from[i] + 1;
// cout << InputFilenames[i] << "[" << from[i] << ":" << to[i] << "]" << endl;
for (int k = from[i]; k <= to[i]; ++k)
{
H5PartSetStep(H5InFile,k);
// cout << "Step set to " << k << endl;
H5SetStep(H5InFile,k);
/**************************************************************\
* determine maximum number of particles in all input files
* and all steps
\**************************************************************/
h5part_int64_t localNumParticles = H5PartGetNumParticles(H5InFile);
h5_int64_t localNumParticles = H5PartGetNumParticles(H5InFile);
if (localNumParticles > maxNumParticles)
maxNumParticles = localNumParticles;
}
@@ -366,20 +372,17 @@ int main(int argc, char **argv){
if (parser.get<bool>("intersect-file-attributes"))
{
NumFileAttr = H5PartGetNumFileAttribs(H5InFile);
// cout << NumFileAttr << " file attributes" << endl;
NumFileAttr = H5GetNumFileAttribs(H5InFile);
for (int l = 0; l < NumFileAttr; ++l)
{
H5PartGetFileAttribInfo(H5InFile, l, AttrName, MAX_LEN, &Type, &NumType);
// cout << "Found file attribute '" << AttrName << "'" << endl;
H5GetFileAttribInfo(H5InFile, l, AttrName, MAX_LEN, &Type, &NumType);
itName = FileAttribName.find(string(AttrName));
if (itName == FileAttribName.end())
{
FileAttribName.insert(make_pair(string(AttrName), 1));
FileAttribType.insert(make_pair(string(AttrName), Type));
FileAttribNumType.insert(make_pair(string(AttrName), NumType));
// cout << "Added file attribute " << AttrName << endl;
}
else
{
@@ -403,8 +406,7 @@ int main(int argc, char **argv){
}
}
}
for (int k = from[i]; k <= to[i]; ++k)
{
H5PartSetStep(H5InFile,k);
@@ -412,17 +414,15 @@ int main(int argc, char **argv){
if (parser.get<bool>("intersect-datasets"))
{
NumDataSets = H5PartGetNumDatasets(H5InFile);
for (h5part_int64_t m = 0; m < NumDataSets; ++m)
for (h5_int64_t m = 0; m < NumDataSets; ++m)
{
H5PartGetDatasetInfo(H5InFile, m, SetName, MAX_LEN, &SetType, &SetNum);
// cout << "Found dataset '" << SetName << "' " << endl;
itName = localDataSetName.find(string(SetName));
itName = localDataSetName.find(string(SetName));
if (itName == localDataSetName.end())
{
localDataSetName.insert(make_pair(string(SetName), 1));
localDataSetType.insert(make_pair(string(SetName), SetType));
// cout << "Added dataset " << SetName << endl;
}
}
else
{
if (localDataSetType[string(SetName)] == SetType)
@@ -440,11 +440,10 @@ int main(int argc, char **argv){
if (parser.get<bool>("intersect-step-attributes"))
{
NumStepAttr = H5PartGetNumStepAttribs(H5InFile);
NumStepAttr = H5GetNumStepAttribs(H5InFile);
for (int m = 0; m < NumStepAttr; ++m)
{
H5PartGetStepAttribInfo(H5InFile, m, StepAttrName, MAX_LEN, &Type, &NumType);
// cout << "Found Step Attribute '" << StepAttrName << "' " << endl;
H5GetStepAttribInfo(H5InFile, m, StepAttrName, MAX_LEN, &Type, &NumType);
itlocalName = localStepAttribName.find(string(StepAttrName));
if (itlocalName == localStepAttribName.end())
{
@@ -478,13 +477,15 @@ int main(int argc, char **argv){
if (parser.get<bool>("intersect-datasets"))
{
// exclude those datasets which do not occur in all steps in file i
for (itlocalName = localDataSetName.begin(), itlocalType = localDataSetType.begin(); itlocalName != localDataSetName.end(); itlocalName++, itlocalType++)
for (itlocalName = localDataSetName.begin(), itlocalType = localDataSetType.begin();
itlocalName != localDataSetName.end(); itlocalName++, itlocalType++)
{
if (itlocalName->second != NumSteps)
{
cerr << "WARNING: dataset '" << itlocalName->first << "' in file " << InputFilenames[i] << " only found in " << itlocalName->second << " of " << NumSteps << " steps;" << endl;
cerr << "WARNING: dataset '" << itlocalName->first << "' in file "
<< InputFilenames[i] << " only found in " << itlocalName->second
<< " of " << NumSteps << " steps;" << endl;
cerr << " Skipping this dataset;" << endl;
localDataSetName.erase(itlocalName);
}
@@ -517,14 +518,13 @@ int main(int argc, char **argv){
// exclude those step attributes which do not occur in all steps in file i
itlocalType = localStepAttribType.begin();
itlocalNumType = localStepAttribNumType.begin();
for (itlocalName = localStepAttribName.begin(); itlocalName != localStepAttribName.end(); itlocalName++, itlocalType++, itlocalNumType++)
for (itlocalName = localStepAttribName.begin(); itlocalName != localStepAttribName.end();
itlocalName++, itlocalType++, itlocalNumType++)
{
if (itlocalName->second != NumSteps){
cerr << "WARNING: step attribute '" << itlocalName->first << "' in file " << InputFilenames[i] << " only found in " << itlocalName->second << " of " << NumSteps << " steps;" << endl;
cerr << "WARNING: step attribute '" << itlocalName->first << "' in file " << InputFilenames[i]
<< " only found in " << itlocalName->second << " of " << NumSteps << " steps;" << endl;
cerr << " Skipping this step attribute;" << endl;
// localStepAttribName.erase(itlocalName);
// localStepAttribType.erase(itlocalType);
// localStepAttribNumType.erase(itlocalNumType);
}
else
{
@@ -559,7 +559,7 @@ int main(int argc, char **argv){
}
}
H5PartCloseFile(H5InFile);
H5CloseFile(H5InFile);
}
}
@@ -573,7 +573,8 @@ int main(int argc, char **argv){
{
if (itName->second != effNumInput)
{
cerr << "WARNING: file attribute '" << itName->first << "' only found in " << itName->second << " of " << effNumInput << " input files;" << endl;
cerr << "WARNING: file attribute '" << itName->first << "' only found in " << itName->second << " of "
<< effNumInput << " input files;" << endl;
cerr << " skipping this attribute!" << endl;
FileAttribName.erase(itName);
FileAttribType.erase(itType);
@@ -599,7 +600,8 @@ int main(int argc, char **argv){
{
if (itName->second != effNumInput)
{
cerr << "WARNING: dataset '" << itName->first << "' only found in " << itName->second << " of " << effNumInput << " input files;" << endl;
cerr << "WARNING: dataset '" << itName->first << "' only found in " << itName->second
<< " of " << effNumInput << " input files;" << endl;
cerr << " skipping this data set!" << endl;
DataSetName.erase(itName);
DataSetType.erase(itType);
@@ -624,7 +626,8 @@ int main(int argc, char **argv){
{
if (itName->second != effNumInput)
{
cerr << "WARNING: step attribute '" << itName->first << "' only found in " << itName->second << " of " << effNumInput << " input files;" << endl;
cerr << "WARNING: step attribute '" << itName->first << "' only found in " << itName->second
<< " of " << effNumInput << " input files;" << endl;
cerr << " skipping this attribute!" << endl;
StepAttribName.erase(itName);
StepAttribType.erase(itType);
@@ -644,23 +647,22 @@ int main(int argc, char **argv){
}
H5OutFile = H5PartOpenFile(OutputFilename.c_str(), H5PART_WRITE);
H5OutFile = H5OpenFile(OutputFilename.c_str(), H5_O_WRONLY, NULL);
if (H5OutFile == NULL)
{
cerr << "ABORT: could not open '" << OutputFilename << "' for writing!" << endl;
exit(1);
}
FloatValues = new h5part_float64_t[maxNumParticles];
IntegerValues = new h5part_int64_t[maxNumParticles];
FloatValues = new h5_float64_t[maxNumParticles];
IntegerValues = new h5_int64_t[maxNumParticles];
// cout << "ready to write data " << maxNumParticles << endl;
for (int i = 0; i < effNumInput; ++i)
{
H5InFile = H5PartOpenFile(InputFilenames[i].c_str(), H5PART_READ);
H5InFile = H5OpenFile(InputFilenames[i].c_str(), H5_O_RDONLY, NULL );
H5PartSetStep(H5InFile,from[i]);
H5PartSetStep(H5OutFile,effStep);
H5SetStep(H5InFile,from[i]);
H5SetStep(H5OutFile,effStep);
if (parser.get<bool>("intersect-file-attributes"))
{
@@ -668,8 +670,7 @@ int main(int argc, char **argv){
itNumType = FileAttribNumType.begin();
for (itName = FileAttribName.begin(); itName != FileAttribName.end(); itName++, itType++, itNumType++)
{
// cout << "writing file attribute " << itName->first << endl;
if (i == 0)
if (i == 0)
{
#ifdef USE_BOOST
rc = copyFileAttribute(H5InFile, H5OutFile, FileAttributes, itName->first, itType->second, itNumType->second);
@@ -685,20 +686,16 @@ int main(int argc, char **argv){
rc = copyFileToStepAttribute(H5InFile, H5OutFile, itName->first, itType->second, itNumType->second);
#endif
}
if (rc != H5PART_SUCCESS)
if (rc != H5_SUCCESS)
cerr << "WARNING: could not write file attribute '" << AttrName << "'" << endl;
}
// cout << "wrote file attributes" << endl;
}
else
{
h5part_int64_t NumFileAttr = H5PartGetNumFileAttribs(H5InFile);
// cout << NumFileAttr << " file attributes" << endl;
for (h5part_int64_t l = 0; l < NumFileAttr; ++l)
h5_int64_t NumFileAttr = H5GetNumFileAttribs(H5InFile);
for (h5_int64_t l = 0; l < NumFileAttr; ++l)
{
H5PartGetFileAttribInfo(H5InFile, l, AttrName, MAX_LEN, &Type, &NumType);
// cout << "Found file attribute '" << AttrName << "'" << endl;
H5PartGetFileAttribInfo(H5InFile, l, AttrName, MAX_LEN, &Type, &NumType);
if (i == 0)
{
#ifdef USE_BOOST
@@ -715,7 +712,7 @@ int main(int argc, char **argv){
rc = copyFileToStepAttribute(H5InFile, H5OutFile, string(AttrName), Type, NumType);
#endif
}
if (rc != H5PART_SUCCESS)
if (rc != H5_SUCCESS)
cerr << "WARNING: could not write file attribute '" << AttrName << "'" << endl;
}
}
@@ -725,20 +722,22 @@ int main(int argc, char **argv){
{
if(!firstStepInput)
{
rc = H5PartSetStep(H5InFile, l);
if (rc != H5PART_SUCCESS)
rc = H5SetStep(H5InFile, l);
if (rc != H5_SUCCESS)
{
cerr << "ABORT: could not change to step #" << l << " in input file '" << InputFilenames[i] << "'" << endl;
rc = H5PartCloseFile(H5InFile);
rc = H5PartCloseFile(H5OutFile);
cerr << "ABORT: could not change to step #" << l << " in input file '"
<< InputFilenames[i] << "'" << endl;
rc = H5CloseFile(H5InFile);
rc = H5CloseFile(H5OutFile);
exit(1);
}
rc = H5PartSetStep(H5OutFile, effStep);
if (rc != H5PART_SUCCESS)
rc = H5SetStep(H5OutFile, effStep);
if (rc != H5_SUCCESS)
{
cerr << "ABORT: could not change to step #" << effStep << " in output file '" << OutputFilename << "'" << endl;
rc = H5PartCloseFile(H5InFile);
rc = H5PartCloseFile(H5OutFile);
cerr << "ABORT: could not change to step #" << effStep << " in output file '"
<< OutputFilename << "'" << endl;
rc = H5CloseFile(H5InFile);
rc = H5CloseFile(H5OutFile);
exit(1);
}
}
@@ -748,11 +747,11 @@ int main(int argc, char **argv){
}
NumParticles = H5PartGetNumParticles(H5InFile);
rc = H5PartSetNumParticles(H5OutFile, NumParticles);
if (rc != H5PART_SUCCESS)
if (rc != H5_SUCCESS)
{
cerr << "ABORT: could not set the number of particles in output file '" << OutputFilename << "'" << endl;
rc = H5PartCloseFile(H5InFile);
rc = H5PartCloseFile(H5OutFile);
rc = H5CloseFile(H5InFile);
rc = H5CloseFile(H5OutFile);
exit(1);
}
if (parser.get<bool>("intersect-step-attributes"))
@@ -762,18 +761,18 @@ int main(int argc, char **argv){
for (itName = StepAttribName.begin(); itName != StepAttribName.end(); ++itName, ++itType, ++itNumType)
{
rc = copyStepAttribute(H5InFile, H5OutFile, itName->first, itType->second, itNumType->second);
if (rc != H5PART_SUCCESS)
if (rc != H5_SUCCESS)
cerr << "WARNING: could not write step attribute '" << itName->first << "'" << endl;
}
}
else
{
h5part_int64_t NumStepAttr = H5PartGetNumStepAttribs(H5InFile);
for (h5part_int64_t m = 0; m < NumStepAttr; ++m)
h5_int64_t NumStepAttr = H5GetNumStepAttribs(H5InFile);
for (h5_int64_t m = 0; m < NumStepAttr; ++m)
{
H5PartGetStepAttribInfo(H5InFile, m, StepAttrName, MAX_LEN, &Type, &NumType);
rc = copyStepAttribute(H5InFile, H5OutFile, string(StepAttrName), Type, NumType);
if (rc != H5PART_SUCCESS)
if (rc != H5_SUCCESS)
cerr << "WARNING: could not write step attribute '" << StepAttrName << "'" << endl;
}
}
@@ -784,26 +783,26 @@ int main(int argc, char **argv){
for (itType = DataSetType.begin(); itType != DataSetType.end(); ++itType)
{
rc = copyDataset(H5InFile, H5OutFile, itType->first, itType->second, FloatValues, IntegerValues);
if (rc != H5PART_SUCCESS)
cerr << "WARNING: could not write dataset '" << itType->first << "'" << endl;
if (rc != H5_SUCCESS)
cerr << "WARNING: could not write dataset '" << itType->first << "'" << endl;
}
}
else
{
h5part_int64_t NumDataSets = H5PartGetNumDatasets(H5InFile);
for (h5part_int64_t m = 0; m < NumDataSets; ++m)
h5_int64_t NumDataSets = H5PartGetNumDatasets(H5InFile);
for (h5_int64_t m = 0; m < NumDataSets; ++m)
{
H5PartGetDatasetInfo(H5InFile, m, SetName, MAX_LEN, &SetType, &SetNum);
rc = copyDataset(H5InFile, H5OutFile, string(SetName), SetType, FloatValues, IntegerValues);
if (rc != H5PART_SUCCESS)
cerr << "WARNING: could not write dataset '" << SetName << "'" << endl;
H5PartGetDatasetInfo(H5InFile, m, SetName, MAX_LEN, &SetType, &SetNum);
rc = copyDataset(H5InFile, H5OutFile, string(SetName), SetType, FloatValues, IntegerValues);
if (rc != H5_SUCCESS)
cerr << "WARNING: could not write dataset '" << SetName << "'" << endl;
}
}
}
rc = H5PartCloseFile(H5InFile);
rc = H5CloseFile(H5InFile);
}
rc = H5PartCloseFile(H5OutFile);
rc = H5CloseFile(H5OutFile);
if (isOutputInput)
{
@@ -817,14 +816,14 @@ int main(int argc, char **argv){
delete[] to;
}
h5part_int64_t copyFileAttribute(H5PartFile* In, H5PartFile* Out, string AttrName, h5part_int64_t Type, h5part_int64_t Num)
h5_int64_t copyFileAttribute(h5_file_t* In, h5_file_t* Out, string AttrName, h5_int64_t Type, h5_int64_t Num)
{
h5part_int64_t rc;
h5_int64_t rc;
if (Type == H5T_NATIVE_DOUBLE)
{
void *Attrib = (double*)malloc(sizeof(double)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (double*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteFileAttrib(Out, AttrName.c_str(), Type, (double*)Attrib, Num);
free(Attrib);
return rc;
@@ -832,37 +831,37 @@ h5part_int64_t copyFileAttribute(H5PartFile* In, H5PartFile* Out, string AttrNam
else if (Type == H5T_NATIVE_CHAR)
{
void *Attrib = (char*)malloc(sizeof(char)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (char*)Attrib);
if (rc == H5PART_SUCCESS)
rc = H5PartWriteFileAttrib(Out, AttrName.c_str(), Type, (char*)Attrib, Num);
rc = H5ReadFileAttrib(In, AttrName.c_str(), (char*)Attrib);
if (rc == H5_SUCCESS)
rc = H5WriteFileAttrib(Out, AttrName.c_str(), Type, (char*)Attrib, Num);
free(Attrib);
return rc;
}
else if (Type == H5T_NATIVE_INT64)
{
void *Attrib = (h5part_int64_t*)malloc(sizeof(h5part_int64_t)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (h5part_int64_t*)Attrib);
if (rc == H5PART_SUCCESS)
rc = H5PartWriteFileAttrib(Out, AttrName.c_str(), Type, (h5part_int64_t*)Attrib, Num);
void *Attrib = (h5_int64_t*)malloc(sizeof(h5_int64_t)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (h5_int64_t*)Attrib);
if (rc == H5_SUCCESS)
rc = H5PartWriteFileAttrib(Out, AttrName.c_str(), Type, (h5_int64_t*)Attrib, Num);
free(Attrib);
return rc;
}
else
{
cerr << "WARNING: unknown type for file attribue " << AttrName << "! Skipping it. " << endl;
return H5PART_ERR_INVAL;
return H5_ERR_INVAL;
}
}
h5part_int64_t copyFileToStepAttribute(H5PartFile* In, H5PartFile* Out, string AttrName, h5part_int64_t Type, h5part_int64_t Num)
h5_int64_t copyFileToStepAttribute(h5_file_t* In, h5_file_t* Out, string AttrName, h5_int64_t Type, h5_int64_t Num)
{
h5part_int64_t rc;
h5_int64_t rc;
if (Type == H5T_NATIVE_DOUBLE)
{
void *Attrib = (double*)malloc(sizeof(double)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (double*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (double*)Attrib, Num);
free(Attrib);
return rc;
@@ -871,35 +870,35 @@ h5part_int64_t copyFileToStepAttribute(H5PartFile* In, H5PartFile* Out, string A
{
void *Attrib = (char*)malloc(sizeof(char)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (char*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (char*)Attrib, Num);
free(Attrib);
return rc;
}
else if (Type == H5T_NATIVE_INT64)
{
void *Attrib = (h5part_int64_t*)malloc(sizeof(h5part_int64_t)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (h5part_int64_t*)Attrib);
if (rc == H5PART_SUCCESS)
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (h5part_int64_t*)Attrib, Num);
void *Attrib = (h5_int64_t*)malloc(sizeof(h5_int64_t)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (h5_int64_t*)Attrib);
if (rc == H5_SUCCESS)
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (h5_int64_t*)Attrib, Num);
free(Attrib);
return rc;
}
else
{
cerr << "WARNING: unknown type for file attribue " << AttrName << "! Skipping it. " << endl;
return H5PART_ERR_INVAL;
return H5_ERR_INVAL;
}
}
h5part_int64_t copyStepAttribute(H5PartFile* In, H5PartFile* Out, string AttrName, h5part_int64_t Type, h5part_int64_t Num)
h5_int64_t copyStepAttribute(h5_file_t* In, h5_file_t* Out, string AttrName, h5_int64_t Type, h5_int64_t Num)
{
h5part_int64_t rc;
h5_int64_t rc;
if (Type == H5T_NATIVE_DOUBLE)
{
void* Attrib = (double*)malloc(sizeof(double)*Num);;
rc = H5PartReadStepAttrib(In, AttrName.c_str(), (double*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (double*)Attrib, Num);
free(Attrib);
return rc;
@@ -908,63 +907,63 @@ h5part_int64_t copyStepAttribute(H5PartFile* In, H5PartFile* Out, string AttrNam
{
void* Attrib = (char*)malloc(sizeof(char)*Num);;
rc = H5PartReadStepAttrib(In, AttrName.c_str(), (char*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (char*)Attrib, Num);
free(Attrib);
return rc;
}
else if (Type == H5T_NATIVE_INT64)
{
void* Attrib = (h5part_int64_t*)malloc(sizeof(h5part_int64_t)*Num);
rc = H5PartReadStepAttrib(In, AttrName.c_str(), (h5part_int64_t*)Attrib);
if (rc == H5PART_SUCCESS)
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (h5part_int64_t*)Attrib, Num);
void* Attrib = (h5_int64_t*)malloc(sizeof(h5_int64_t)*Num);
rc = H5PartReadStepAttrib(In, AttrName.c_str(), (h5_int64_t*)Attrib);
if (rc == H5_SUCCESS)
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (h5_int64_t*)Attrib, Num);
free(Attrib);
return rc;
}
else
{
cerr << "WARNING: unknown type for step attribute " << AttrName << "! Skipping it." << endl;
return H5PART_ERR_INVAL;
return H5_ERR_INVAL;
}
}
h5part_int64_t copyDataset(H5PartFile* In, H5PartFile* Out, string SetName, h5part_int64_t Type, h5part_float64_t* FloatArray, h5part_int64_t* IntegerArray)
h5_int64_t copyDataset(h5_file_t* In, h5_file_t* Out, string SetName, h5_int64_t Type, h5_float64_t* FloatArray, h5_int64_t* IntegerArray)
{
h5part_int64_t rc;
h5_int64_t rc;
if (Type == H5T_NATIVE_DOUBLE)
{
rc = H5PartReadDataFloat64(In, SetName.c_str(), FloatArray);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteDataFloat64(Out, SetName.c_str(), FloatArray);
return rc;
}
else if (Type == H5T_NATIVE_INT64)
{
rc = H5PartReadDataInt64(In, SetName.c_str(), IntegerArray);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteDataInt64(Out, SetName.c_str(), IntegerArray);
return rc;
}
else
{
cerr << "WARNING: unknown type for dataset " << SetName << "! Skipping it." << endl;
return H5PART_ERR_INVAL;
return H5_ERR_INVAL;
}
}
#ifdef USE_BOOST
h5part_int64_t copyFileAttribute(H5PartFile* In, H5PartFile* Out, StringAnyValueMap &FileAttributes, string AttrName, h5part_int64_t Type, h5part_int64_t Num)
h5_int64_t copyFileAttribute(h5_file_t* In, h5_file_t* Out, StringAnyValueMap &FileAttributes, string AttrName, h5_int64_t Type, h5_int64_t Num)
{
h5part_int64_t rc;
h5_int64_t rc;
if (Type == H5T_NATIVE_DOUBLE)
{
void *Attrib = (double*)malloc(sizeof(double)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (double*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteFileAttrib(Out, AttrName.c_str(), Type, (double*)Attrib, Num);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
FileAttributes.insert(make_pair(AttrName,boost::any(*(double*)Attrib)));
free(Attrib);
return rc;
@@ -973,51 +972,51 @@ h5part_int64_t copyFileAttribute(H5PartFile* In, H5PartFile* Out, StringAnyValue
{
void *Attrib = (char*)malloc(sizeof(char)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (char*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
rc = H5PartWriteFileAttrib(Out, AttrName.c_str(), Type, (char*)Attrib, Num);
if (rc == H5PART_SUCCESS)
FileAttributes.insert(make_pair(AttrName,boost::any(string((char*)Attrib))));
if (rc == H5_SUCCESS)
FileAttributes.insert(make_pair(AttrName,boost::any(string((char*)Attrib))));
free(Attrib);
return rc;
}
else if (Type == H5T_NATIVE_INT64)
{
void *Attrib = (h5part_int64_t*)malloc(sizeof(h5part_int64_t)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (h5part_int64_t*)Attrib);
if (rc == H5PART_SUCCESS)
rc = H5PartWriteFileAttrib(Out, AttrName.c_str(), Type, (h5part_int64_t*)Attrib, Num);
if (rc == H5PART_SUCCESS)
FileAttributes.insert(make_pair(AttrName,boost::any(*(h5part_int64_t*)Attrib)));
void *Attrib = (h5_int64_t*)malloc(sizeof(h5_int64_t)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (h5_int64_t*)Attrib);
if (rc == H5_SUCCESS)
rc = H5PartWriteFileAttrib(Out, AttrName.c_str(), Type, (h5_int64_t*)Attrib, Num);
if (rc == H5_SUCCESS)
FileAttributes.insert(make_pair(AttrName,boost::any(*(h5_int64_t*)Attrib)));
free(Attrib);
return rc;
}
else
{
cerr << "WARNING: unknown type for file attribue " << AttrName << "! Skipping it. " << endl;
return H5PART_ERR_INVAL;
return H5_ERR_INVAL;
}
}
h5part_int64_t copyFileToStepAttribute(H5PartFile* In, H5PartFile* Out, StringAnyValueMap &FileAttributes, string AttrName, h5part_int64_t Type, h5part_int64_t Num)
h5_int64_t copyFileToStepAttribute(h5_file_t* In, h5_file_t* Out, StringAnyValueMap &FileAttributes, string AttrName, h5_int64_t Type, h5_int64_t Num)
{
h5part_int64_t rc;
h5_int64_t rc;
if (Type == H5T_NATIVE_DOUBLE)
{
void *Attrib = (double*)malloc(sizeof(double)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (double*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
{
if (FileAttributes.find(AttrName) == FileAttributes.end())
{
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (double*)Attrib, Num);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
FileAttributes.insert(make_pair(AttrName,boost::any(*(double*)Attrib)));
}
else if(any_cast<double>(FileAttributes[AttrName]) != *(double*)Attrib)
{
rc = H5PartWriteStepAttrib(Out, (AttrName + " changed to").c_str(), Type, (double*)Attrib, Num);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
FileAttributes[AttrName] = boost::any(*(double*)Attrib);
}
}
@@ -1028,18 +1027,18 @@ h5part_int64_t copyFileToStepAttribute(H5PartFile* In, H5PartFile* Out, StringAn
{
void *Attrib = (char*)malloc(sizeof(char)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (char*)Attrib);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
{
if (FileAttributes.find(AttrName) == FileAttributes.end())
{
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (char*)Attrib, Num);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
FileAttributes.insert(make_pair(AttrName,boost::any(string((char*)Attrib))));
}
else if(strcmp((any_cast<string>(FileAttributes[AttrName])).c_str(),(char*)Attrib) != 0)
{
rc = H5PartWriteStepAttrib(Out, (AttrName + " changed to").c_str(), Type, (char*)Attrib, Num);
if (rc == H5PART_SUCCESS)
if (rc == H5_SUCCESS)
FileAttributes[AttrName] = boost::any(string((char*)Attrib));
}
}
@@ -1048,20 +1047,20 @@ h5part_int64_t copyFileToStepAttribute(H5PartFile* In, H5PartFile* Out, StringAn
}
else if (Type == H5T_NATIVE_INT64)
{
void *Attrib = (h5part_int64_t*)malloc(sizeof(h5part_int64_t)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (h5part_int64_t*)Attrib);
if (rc == H5PART_SUCCESS)
void *Attrib = (h5_int64_t*)malloc(sizeof(h5_int64_t)*Num);
rc = H5PartReadFileAttrib(In, AttrName.c_str(), (h5_int64_t*)Attrib);
if (rc == H5_SUCCESS)
{
if (FileAttributes.find(AttrName) == FileAttributes.end())
{
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (h5part_int64_t*)Attrib, Num);
FileAttributes.insert(make_pair(AttrName,boost::any((h5part_int64_t*)Attrib)));
rc = H5PartWriteStepAttrib(Out, AttrName.c_str(), Type, (h5_int64_t*)Attrib, Num);
FileAttributes.insert(make_pair(AttrName,boost::any((h5_int64_t*)Attrib)));
}
else if(any_cast<h5part_int64_t>(FileAttributes[AttrName]) != *(h5part_int64_t*)Attrib)
else if(any_cast<h5_int64_t>(FileAttributes[AttrName]) != *(h5_int64_t*)Attrib)
{
rc = H5PartWriteStepAttrib(Out, (AttrName + " changed to").c_str(), Type, (h5part_int64_t*)Attrib, Num);
if (rc == H5PART_SUCCESS)
FileAttributes[AttrName] = boost::any((h5part_int64_t*)Attrib);
rc = H5PartWriteStepAttrib(Out, (AttrName + " changed to").c_str(), Type, (h5_int64_t*)Attrib, Num);
if (rc == H5_SUCCESS)
FileAttributes[AttrName] = boost::any((h5_int64_t*)Attrib);
}
}
free(Attrib);
@@ -1070,7 +1069,7 @@ h5part_int64_t copyFileToStepAttribute(H5PartFile* In, H5PartFile* Out, StringAn
else
{
cerr << "WARNING: unknown type for file attribue " << AttrName << "! Skipping it. " << endl;
return H5PART_ERR_INVAL;
return H5_ERR_INVAL;
}
}
#endif
+3 -1
View File
@@ -9,7 +9,7 @@ INCLUDES = -I../src/include @INCLUDES@
# What to build... make install will place these files in the $(prefix)/bin directory.
bin_PROGRAMS = @BUILD_TOOLS@
EXTRA_PROGRAMS = h5pAttrib h5PartDcToVtk
EXTRA_PROGRAMS = h5pAttrib h5PartDcToVtk h5PartSurfaceToVtk
# Listing of all programs that maybe built. (Has to know statically...)
EXTRA_SCRIPTS = h5hutcc
@@ -26,5 +26,7 @@ h5pAttrib_SOURCES = h5pAttrib.cc
h5PartDcToVtk_SOURCES = h5PartDcToVtk.cc
h5PartSurfaceToVtk_SOURCES = h5PartSurfaceToVtk.cc
clean: clean-am
+331 -335
View File
@@ -1,14 +1,17 @@
/* h5ToVtk.cc
Andreas Adelmann
/* h5PartSurfaceToVtk.cc
Andreas Adelmann & Chuan Wang
2010-2011
*/
#include <hdf5.h>
#include "H5hut.h"
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <cctype>
#include <string.h>
#include "hdf5.h"
#include "H5Part.h"
#include <set>
#include <iostream>
#include <fstream>
@@ -17,27 +20,32 @@
#include <sstream>
#include <iomanip>
#include <cassert>
//#include <string>
//#include <cstdlib>
using namespace std;
#define MAX_LEN 100
/* Function headers */
int get_option(int argc, const char **argv, const char *opts, const struct long_options *l_opts);
static void print_help();
static void variable_assign(int argc, const char *argv[]);
/* Global variables */
static char* input_name = NULL;
static char* mytemp = NULL;
static char* geo_name = NULL;
static char* output_name = NULL;
static char* geo_name = NULL;
static char* output_name = NULL;
static bool flg_alive = false;
static double z_pos = 0.0;
static int print_all = 0;
static int step_ini = 1;
static int dump_freq = 1;
/* `get_option' variables */
int opt_err = 1; /*get_option prints errors if this is on */
int opt_ind = 1; /*token pointer */
@@ -45,17 +53,17 @@ const char *opt_arg = NULL; /*flag argument (or value) */
/* indication whether the flag (option) requires an argument or not */
enum {
no_arg = 0, /* doesn't take an argument */
require_arg, /* requires an argument */
no_arg = 0, /* doesn't take an argument */
require_arg, /* requires an argument */
};
/* struct for flags (options) */
typedef struct long_options
{
const char *name; /* name of the long option */
int has_arg; /* whether we should look for an arg */
char shortval; /* the shortname equivalent of long arg
* this gets returned from get_option */
const char *name; /* name of the long option */
int has_arg; /* whether we should look for an arg */
char shortval; /* the shortname equivalent of long arg
* this gets returned from get_option */
} long_options;
/* List of options in single characters */
@@ -63,17 +71,15 @@ static const char *s_opts = "h1:2:i:g:o:f:d:";
/* List of options in full words */
static struct long_options l_opts[] =
{
{ "help", no_arg, 'h' }, // Print help page
{ "input", require_arg, 'i' }, // Takes input file name
{ "geometry", require_arg, 'g' }, // Takes input geometry file name
{ "output", require_arg, 'o' }, // Takes output file name (without this flag, the program will print to stdout)
{ "first", require_arg, 'f' }, // first step
{ "dumpfreq", require_arg, 'd' }, // dump frequency of the
{ NULL, 0, '\0' }
};
{
{ "help", no_arg, 'h' }, // Print help page
{ "input", require_arg, 'i' }, // Takes input file name
{ "geometry", require_arg, 'g' }, // Takes input geometry file name
{ "output", require_arg, 'o' }, // Takes output file name (without this flag, the program will print to stdout)
{ "first", require_arg, 'f' }, // first step
{ "dumpfreq", require_arg, 'd' }, // dump frequency of the
{ NULL, 0, '\0' }
};
/************************************************************************************
*********************************** FUNCTIONS *************************************
@@ -81,289 +87,279 @@ static struct long_options l_opts[] =
string convert2Int(int number) {
stringstream ss;
ss << setw(5) << setfill('0') << number;
return ss.str();
stringstream ss;
ss << setw(5) << setfill('0') << number;
return ss.str();
}
/* get_option is the parsing function that was majorly ported from h5dump utility */
int get_option(int argc, const char **argv, const char *opts, const struct long_options *l_opts) {
static int sp = 1; /* character index in current token */
int opt_opt = '?'; /* option character passed back to user */
static int sp = 1; /* character index in current token */
int opt_opt = '?'; /* option character passed back to user */
if (sp == 1)
if (sp == 1)
{
/* check for more flag-like tokens */
if (opt_ind >= argc || argv[opt_ind][0] != '-' || argv[opt_ind][1] == '\0')
{
/* check for more flag-like tokens */
if (opt_ind >= argc || argv[opt_ind][0] != '-' || argv[opt_ind][1] == '\0')
return EOF;
}
else if (strcmp(argv[opt_ind], "--") == 0)
{
opt_ind++;
return EOF;
}
}
if (sp == 1 && argv[opt_ind][0] == '-' && argv[opt_ind][1] == '-')
{
/* long command line option */
const char *arg = &argv[opt_ind][2];
int i;
for (i = 0; l_opts && l_opts[i].name; i++)
{
size_t len = strlen(l_opts[i].name);
if (strncmp(arg, l_opts[i].name, len) == 0)
{
/* we've found a matching long command line flag */
opt_opt = l_opts[i].shortval;
if (l_opts[i].has_arg != no_arg)
{
return EOF;
if (arg[len] == '=')
{
opt_arg = &arg[len + 1];
}
else if (opt_ind < (argc - 1) && argv[opt_ind + 1][0] != '-')
{
opt_arg = argv[++opt_ind];
}
else if (l_opts[i].has_arg == require_arg)
{
if (opt_err)
fprintf(stderr, "%s: option required for \"--%s\" flag\n", argv[0], arg);
opt_opt = '?';
}
}
else if (strcmp(argv[opt_ind], "--") == 0)
else
{
opt_ind++;
return EOF;
if (arg[len] == '=')
{
if (opt_err)
fprintf(stderr, "%s: no option required for \"%s\" flag\n", argv[0], arg);
opt_opt = '?';
}
opt_arg = NULL;
}
break;
}
}
if (sp == 1 && argv[opt_ind][0] == '-' && argv[opt_ind][1] == '-')
if (l_opts[i].name == NULL)
{
/* long command line option */
const char *arg = &argv[opt_ind][2];
int i;
/* exhausted all of the l_opts we have and still didn't match */
if (opt_err)
fprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg);
for (i = 0; l_opts && l_opts[i].name; i++)
{
size_t len = strlen(l_opts[i].name);
if (strncmp(arg, l_opts[i].name, len) == 0)
{
/* we've found a matching long command line flag */
opt_opt = l_opts[i].shortval;
if (l_opts[i].has_arg != no_arg)
{
if (arg[len] == '=')
{
opt_arg = &arg[len + 1];
}
else if (opt_ind < (argc - 1) && argv[opt_ind + 1][0] != '-')
{
opt_arg = argv[++opt_ind];
}
else if (l_opts[i].has_arg == require_arg)
{
if (opt_err)
fprintf(stderr, "%s: option required for \"--%s\" flag\n", argv[0], arg);
opt_opt = '?';
}
}
else
{
if (arg[len] == '=')
{
if (opt_err)
fprintf(stderr, "%s: no option required for \"%s\" flag\n", argv[0], arg);
opt_opt = '?';
}
opt_arg = NULL;
}
break;
}
}
if (l_opts[i].name == NULL)
{
/* exhausted all of the l_opts we have and still didn't match */
if (opt_err)
fprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg);
opt_opt = '?';
}
opt_ind++;
sp = 1;
}
else
{
register char *cp; /* pointer into current token */
/* short command line option */
opt_opt = argv[opt_ind][sp];
if (opt_opt == ':' || (cp = strchr(opts, opt_opt)) == 0)
{
if (opt_err)
fprintf(stderr, "%s: unknown option \"%c\"\n", argv[0], opt_opt);
/* if no chars left in this token, move to next token */
if (argv[opt_ind][++sp] == '\0')
{
opt_ind++;
sp = 1;
}
return '?';
}
if (*++cp == ':')
{
/* if a value is expected, get it */
if (argv[opt_ind][sp + 1] != '\0')
{
/* flag value is rest of current token */
opt_arg = &argv[opt_ind++][sp + 1];
}
else if (++opt_ind >= argc)
{
if (opt_err)
{
fprintf(stderr, "%s: value expected for option \"%c\"\n", argv[0], opt_opt);
}
opt_opt = '?';
}
else
{
/* flag value is next token */
opt_arg = argv[opt_ind++];
}
sp = 1;
}
else
{
/* set up to look at next char in token, next time */
if (argv[opt_ind][++sp] == '\0')
{
/* no more in current token, so setup next token */
opt_ind++;
sp = 1;
}
opt_arg = NULL;
}
opt_opt = '?';
}
/* return the current flag character found */
return opt_opt;
opt_ind++;
sp = 1;
}
else
{
register char *cp; /* pointer into current token */
/* short command line option */
opt_opt = argv[opt_ind][sp];
if (opt_opt == ':' || (cp = strchr(opts, opt_opt)) == 0)
{
if (opt_err)
fprintf(stderr, "%s: unknown option \"%c\"\n", argv[0], opt_opt);
/* if no chars left in this token, move to next token */
if (argv[opt_ind][++sp] == '\0')
{
opt_ind++;
sp = 1;
}
return '?';
}
if (*++cp == ':')
{
/* if a value is expected, get it */
if (argv[opt_ind][sp + 1] != '\0')
{
/* flag value is rest of current token */
opt_arg = &argv[opt_ind++][sp + 1];
}
else if (++opt_ind >= argc)
{
if (opt_err)
{
fprintf(stderr, "%s: value expected for option \"%c\"\n", argv[0], opt_opt);
}
opt_opt = '?';
}
else
{
/* flag value is next token */
opt_arg = argv[opt_ind++];
}
sp = 1;
}
else
{
/* set up to look at next char in token, next time */
if (argv[opt_ind][++sp] == '\0')
{
/* no more in current token, so setup next token */
opt_ind++;
sp = 1;
}
opt_arg = NULL;
}
}
/* return the current flag character found */
return opt_opt;
}
/* Assigns functions according to the parsed result */
static void variable_assign(int argc, const char *argv[])
{
int option;
int option;
/* set options according to the command line */
while ((option = get_option(argc, argv, s_opts, l_opts)) != EOF)
/* set options according to the command line */
while ((option = get_option(argc, argv, s_opts, l_opts)) != EOF)
{
switch ((char)option)
{
switch ((char)option)
{
case 'h': // Print help page
print_help();
exit(1);
case 'o': // Print number of steps
output_name = strdup(opt_arg);
break;
case 'i': // Print shorter version without the values
input_name = strdup(opt_arg);
break;
case 'g': //
{ geo_name = strdup(opt_arg);
case 'h': // Print help page
print_help();
exit(1);
case 'o': // Print number of steps
output_name = strdup(opt_arg);
break;
case 'i': // Print shorter version without the values
input_name = strdup(opt_arg);
break;
case 'g': //
{ geo_name = strdup(opt_arg);
}
break;
case 'f': //
{
//fflush(stdout);
//char ss* = NULL;
//ss = strdup(opt_arg);
mytemp = strdup(opt_arg);
step_ini = (int)strtod(mytemp,NULL);
fprintf(stdout,"string=%s, %s \n",opt_arg, mytemp);
fprintf(stdout,"step_ini=%i \n",step_ini);
}
break;
case 'd': //
{
//fflush(stdout);
//char df* = NULL;
//df = strdup(opt_arg);
fprintf(stdout,"string=%s \n",opt_arg);
mytemp = strdup(opt_arg);
dump_freq = (int)strtod(mytemp,NULL);
fprintf(stdout,"string=%s \n",opt_arg);
fprintf(stdout,"dump_freq=%i \n",dump_freq);
}
break;
default:
print_help();
exit(1);
}
}
break;
case 'f': //
{
mytemp = strdup(opt_arg);
step_ini = (int)strtod(mytemp,NULL);
fprintf(stdout,"string=%s, %s \n",opt_arg, mytemp);
fprintf(stdout,"step_ini=%i \n",step_ini);
}
break;
case 'd': //
{
fprintf(stdout,"string=%s \n",opt_arg);
mytemp = strdup(opt_arg);
dump_freq = (int)strtod(mytemp,NULL);
fprintf(stdout,"string=%s \n",opt_arg);
fprintf(stdout,"dump_freq=%i \n",dump_freq);
}
break;
default:
print_help();
exit(1);
}
}
}
/* For printing help page */
static void print_help()
{
fflush(stdout);
fprintf(stdout, "\nusage: h5SurfaceVtk -i INPUTFILE -g GEOMETRYFILE -o OUTPUTFILE\n");
fprintf(stdout, "\n");
fprintf(stdout, " FLAGS\n");
fprintf(stdout, " -h, --help Print help page\n");
fprintf(stdout, " -i file, --input file (REQUIRED) Takes input base file name to \"file\" (extension h5 is assumed \n");
fprintf(stdout, " -g file, --input geometry file (REQUIRED) Takes input base file name to \"file\" (extension h5 is assumed \n");
fprintf(stdout, " -o file, --output file (REQUIRED) Takes output base file name to \"file\" (extension vtk is added)\n");
fflush(stdout);
fprintf(stdout, "\nusage: h5PartSurfaceToVtk -i INPUTFILE -g GEOMETRYFILE -o OUTPUTFILE\n");
fprintf(stdout, "\n");
fprintf(stdout, " FLAGS\n");
fprintf(stdout, " -h, --help Print help page\n");
fprintf(stdout, " -i file, --input file (REQUIRED) Takes input base file name to \"file\" (extension h5 is assumed \n");
fprintf(stdout, " -g file, --input geometry file (REQUIRED) Takes input base file name to \"file\" (extension h5 is assumed \n");
fprintf(stdout, " -o file, --output file (REQUIRED) Takes output base file name to \"file\" (extension vtk is added)\n");
fprintf(stdout, "\n");
fprintf(stdout, " Examples first dump step 100 and dump frequency 100:\n");
fprintf(stdout, "\n");
fprintf(stdout, " /h5SurfaceVtk -i Cavity_Mag_Surface -g ../10 -o p- -f 100 -d 100 \n");
fprintf(stdout, "\n");
fprintf(stdout, "\n");
fprintf(stdout, " Examples first dump step 100 and dump frequency 100:\n");
fprintf(stdout, "\n");
fprintf(stdout, " /h5SurfaceVtk -i Cavity_Mag_Surface -g ../10 -o p- -f 100 -d 100 \n");
fprintf(stdout, "\n");
}
int main(int argc, const char *argv[])
{
H5PartFile *h5file = NULL;
std::ofstream of, ofalive, ofenergy, ofpnum;
h5_file_t *h5file = NULL;
std::ofstream of, ofalive, ofenergy, ofpnum;
int j;
int j;
int num_dataset;
int num_dataset;
int ntime_step = 0;
int ntime_step = 0;
variable_assign(argc, argv);
variable_assign(argc, argv);
if(input_name == NULL) {
fprintf(stdout, "missing input file name\n");
print_help();
exit(1);
}
if(input_name == NULL) {
fprintf(stdout, "missing input file name\n");
print_help();
exit(1);
}
if(output_name == NULL) {
fprintf(stdout, "missing output file name\n");
print_help();
exit(1);
}
if(output_name == NULL) {
fprintf(stdout, "missing output file name\n");
print_help();
exit(1);
}
string ifn = string(input_name) + string(".h5");
string ifn = string(input_name) + string(".h5");
h5file = H5PartOpenFile(ifn.c_str(), H5PART_READ);
if( h5file == NULL ) {
fprintf(stdout, "unable to open file %s\n", input_name);
print_help();
exit(1);
}
h5file = H5OpenFile(ifn.c_str(), H5_O_WRONLY, NULL);
if( h5file == NULL ) {
fprintf(stdout, "unable to open file %s\n", input_name);
print_help();
exit(1);
}
string gfn = string(geo_name) + string(".h5");
hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS); //Property list identifier
// H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);
// Create a new file collectively and release property list identifier.
hid_t file_id = H5Fopen(gfn.c_str(), H5F_ACC_RDONLY, plist_id);
assert(file_id >= 0);
H5Pclose(plist_id);
int numbfaces_global_m;
/////////////////////////////////////////////
string gfn = string(geo_name) + string(".h5");
hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS); //Property list identifier
// H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);
// Create a new file collectively and release property list identifier.
hid_t file_id = H5Fopen(gfn.c_str(), H5F_ACC_RDONLY, plist_id);
assert(file_id >= 0);
H5Pclose(plist_id);
int numbfaces_global_m;
/////////////////////////////////////////////
// Read dataset "surface" from .h5 file
////////////////////////////////////////////
hsize_t dimsf[2];//dataset dimensions
herr_t status;
hid_t dset_id = H5Dopen(file_id, "/surface");
hid_t dset_id = H5Dopen(file_id, "/surface",H5P_DEFAULT);
assert(dset_id >= 0);
// Create the dataspace for the dataset.
hid_t x = H5Dget_space(dset_id);
@@ -387,19 +383,19 @@ int main(int argc, const char *argv[])
for(int i = 0; i < numbfaces_global_m; i ++) {
bfaces_idx_m[i] = i;
if(allbfaces_m[4 * i] > nogeosym_flag) {
nof_sym_m += 1;
if(i < numbfaces_global_m - 1) {
for(int j = 0; j < numbfaces_global_m - i; j ++) {
allbfaces_m[4*(i+j)] = allbfaces_m[4*(i+j+1)];
allbfaces_m[4*(i+j)+1] = allbfaces_m[4*(i+j+1)+1];
allbfaces_m[4*(i+j)+2] = allbfaces_m[4*(i+j+1)+2];
allbfaces_m[4*(i+j)+3] = allbfaces_m[4*(i+j+1)+3];
}
} else
numbfaces_global_m = numbfaces_global_m - 1;
}
bfaces_idx_m[i] = i;
if(allbfaces_m[4 * i] > nogeosym_flag) {
nof_sym_m += 1;
if(i < numbfaces_global_m - 1) {
for(int j = 0; j < numbfaces_global_m - i; j ++) {
allbfaces_m[4*(i+j)] = allbfaces_m[4*(i+j+1)];
allbfaces_m[4*(i+j)+1] = allbfaces_m[4*(i+j+1)+1];
allbfaces_m[4*(i+j)+2] = allbfaces_m[4*(i+j+1)+2];
allbfaces_m[4*(i+j)+3] = allbfaces_m[4*(i+j+1)+3];
}
} else
numbfaces_global_m = numbfaces_global_m - 1;
}
}
H5Dclose(dset_id);
H5Sclose(filespace);
@@ -408,7 +404,7 @@ int main(int argc, const char *argv[])
////////////////////////////////
hsize_t dimsf_c[2];
herr_t status_c;
hid_t dset_id_c = H5Dopen(file_id, "/coords");
hid_t dset_id_c = H5Dopen(file_id, "/coords",H5P_DEFAULT);
assert(dset_id_c >= 0);
// Create the dataspace for the dataset.
@@ -429,13 +425,13 @@ int main(int argc, const char *argv[])
double **geo3Dcoords_m;//= malloc(sizeof(double)*numpoints_global_m*3);
geo3Dcoords_m = (double**)malloc(sizeof(double)*numpoints_global_m);
for (int i=0;i<numpoints_global_m;i++) {
geo3Dcoords_m[i] = (double*)malloc(sizeof(double)*3);
geo3Dcoords_m[i] = (double*)malloc(sizeof(double)*3);
}
for(int i = 0; i < numpoints_global_m; i++) {
geo3Dcoords_m[i][0] = point_coords[3*i];
geo3Dcoords_m[i][1] = point_coords[3*i+1];
geo3Dcoords_m[i][2] = point_coords[3*i+2];
geo3Dcoords_m[i][0] = point_coords[3*i];
geo3Dcoords_m[i][1] = point_coords[3*i+1];
geo3Dcoords_m[i][2] = point_coords[3*i+2];
}
@@ -445,88 +441,88 @@ int main(int argc, const char *argv[])
H5Sclose(filespace_c);
ntime_step = H5PartGetNumSteps(h5file);
ntime_step = H5GetNumSteps(h5file);
cout<<"step number: "<<ntime_step<<endl;
double sey_num;//sey total number
int remained_num;//
for (size_t j=1; j<=ntime_step; j++) {
set<h5part_int64_t> idSet;
size_t step_local = step_ini + (j-1)*dump_freq;
H5PartSetStep(h5file,step_local);
num_dataset = H5PartGetNumDatasets(h5file);
h5part_int64_t triNum = H5PartGetNumParticles(h5file);
double qi = 0.0;
H5PartReadStepAttrib ( h5file,"qi",&qi);
cout << "Working on timestep " << step_local << endl;
set<h5_int64_t> idSet;
size_t step_local = step_ini + (j-1)*dump_freq;
H5SetStep(h5file,step_local);
num_dataset = H5PartGetNumDatasets(h5file);
h5_int64_t triNum = H5PartGetNumParticles(h5file);
double qi = 0.0;
H5ReadStepAttribFloat64(h5file,"qi",&qi);
cout << "Working on timestep " << step_local << endl;
h5part_float64_t* PrimaryLoss = (h5part_float64_t*)malloc(sizeof(h5part_float64_t)*triNum);
H5PartReadDataFloat64(h5file, "PrimaryLoss", PrimaryLoss);
h5_float64_t* PrimaryLoss = (h5_float64_t*)malloc(sizeof(h5_float64_t)*triNum);
H5PartReadDataFloat64(h5file, "PrimaryLoss", PrimaryLoss);
h5part_float64_t* SecondaryLoss = (h5part_float64_t*)malloc(sizeof(h5part_float64_t)*triNum);
H5PartReadDataFloat64(h5file, "SecondaryLoss", SecondaryLoss);
h5_float64_t* SecondaryLoss = (h5_float64_t*)malloc(sizeof(h5_float64_t)*triNum);
H5PartReadDataFloat64(h5file, "SecondaryLoss", SecondaryLoss);
h5part_float64_t* FNEmissionLoss = (h5part_float64_t*)malloc(sizeof(h5part_float64_t)*triNum);
H5PartReadDataFloat64(h5file, "FNEmissionLoss", FNEmissionLoss);
h5_float64_t* FNEmissionLoss = (h5_float64_t*)malloc(sizeof(h5_float64_t)*triNum);
H5PartReadDataFloat64(h5file, "FNEmissionLoss", FNEmissionLoss);
h5part_int64_t* TriID = (h5part_int64_t*)malloc(sizeof(h5part_int64_t)*triNum);
H5PartReadDataInt64(h5file, "TriangleID", TriID);
h5_int64_t* TriID = (h5_int64_t*)malloc(sizeof(h5_int64_t)*triNum);
H5PartReadDataInt64(h5file, "TriangleID", TriID);
string ffn = string("vtk/") + string(output_name) + string("Surface-") + convert2Int(j) + string(".vtk");
string ffn = string("vtk/") + string(output_name) + string("Surface-") + convert2Int(j) + string(".vtk");
of.open(ffn.c_str());
assert(of.is_open());
of.precision(6);
of << "# vtk DataFile Version 2.0" << endl; // first line of a vtk file
of << "generated using DataSink::writeGeoToVtk" << endl; // header
of << "ASCII" << endl << endl; // file format
of << "DATASET UNSTRUCTURED_GRID" << endl; // dataset structrue
of << "POINTS " << numpoints_global_m << " float" << endl; // data num and type
for(int i = 0; i < numpoints_global_m ; i ++)
of << geo3Dcoords_m[i][0] << " " << geo3Dcoords_m[i][1] << " " << geo3Dcoords_m[i][2] << endl;
of << endl;
of.open(ffn.c_str());
assert(of.is_open());
of.precision(6);
of << "# vtk DataFile Version 2.0" << endl; // first line of a vtk file
of << "generated using DataSink::writeGeoToVtk" << endl; // header
of << "ASCII" << endl << endl; // file format
of << "DATASET UNSTRUCTURED_GRID" << endl; // dataset structrue
of << "POINTS " << numpoints_global_m << " float" << endl; // data num and type
for(int i = 0; i < numpoints_global_m ; i ++)
of << geo3Dcoords_m[i][0] << " " << geo3Dcoords_m[i][1] << " " << geo3Dcoords_m[i][2] << endl;
of << endl;
of << "CELLS " << numbfaces_global_m << " " << 4 * numbfaces_global_m << endl;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << "3 " << allbfaces_m[4*i+1] << " " << allbfaces_m[4*i+2] << " " << allbfaces_m[4*i+3] << endl;
of << "CELL_TYPES " << numbfaces_global_m << endl;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << "5" << endl;
of << "CELL_DATA " << numbfaces_global_m << endl;
of << "SCALARS " << "PrimaryLoss" << " float " << "1" << endl;
of << "LOOKUP_TABLE " << "default" << endl ;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << fabs(PrimaryLoss[i]/qi) << endl;
of << "SCALARS " << "SecondaryLoss" << " float " << "1" << endl;
of << "LOOKUP_TABLE " << "default" << endl ;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << fabs(SecondaryLoss[i]/qi) << endl;
of << "SCALARS " << "FNEmissionLoss" << " float " << "1" << endl;
of << "LOOKUP_TABLE " << "default" << endl ;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << fabs(FNEmissionLoss[i]/qi) << endl;
of << "SCALARS " << "TotalLoss" << " float " << "1" << endl;
of << "LOOKUP_TABLE " << "default" << endl ;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << fabs((FNEmissionLoss[i]+SecondaryLoss[i]+PrimaryLoss[i])/qi) << endl;
of << endl;
of << "CELLS " << numbfaces_global_m << " " << 4 * numbfaces_global_m << endl;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << "3 " << allbfaces_m[4*i+1] << " " << allbfaces_m[4*i+2] << " " << allbfaces_m[4*i+3] << endl;
of << "CELL_TYPES " << numbfaces_global_m << endl;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << "5" << endl;
of << "CELL_DATA " << numbfaces_global_m << endl;
of << "SCALARS " << "PrimaryLoss" << " float " << "1" << endl;
of << "LOOKUP_TABLE " << "default" << endl ;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << fabs(PrimaryLoss[i]/qi) << endl;
of << "SCALARS " << "SecondaryLoss" << " float " << "1" << endl;
of << "LOOKUP_TABLE " << "default" << endl ;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << fabs(SecondaryLoss[i]/qi) << endl;
of << "SCALARS " << "FNEmissionLoss" << " float " << "1" << endl;
of << "LOOKUP_TABLE " << "default" << endl ;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << fabs(FNEmissionLoss[i]/qi) << endl;
of << "SCALARS " << "TotalLoss" << " float " << "1" << endl;
of << "LOOKUP_TABLE " << "default" << endl ;
for(int i = 0; i < numbfaces_global_m ; i ++)
of << fabs((FNEmissionLoss[i]+SecondaryLoss[i]+PrimaryLoss[i])/qi) << endl;
of << endl;
of.close();
of.close();
//cout <<"ptype size = "<< sizeof(ptype) << endl;
//cout <<"ptype size = "<< sizeof(ptype) << endl;
free(PrimaryLoss);
free(SecondaryLoss);
free(FNEmissionLoss);
free(TriID);
free(PrimaryLoss);
free(SecondaryLoss);
free(FNEmissionLoss);
free(TriID);
}
free(point_coords);
for (int i=0;i<numpoints_global_m;i++) {
free(geo3Dcoords_m[i]);
free(geo3Dcoords_m[i]);
}
free(geo3Dcoords_m);
free(allbfaces_m);
free(bfaces_idx_m);
H5PartCloseFile(h5file);
H5CloseFile(h5file);
return 0;
}