[cig-commits] r13775 - in cs/cigma/trunk: src tests/system
luis at geodynamics.org
luis at geodynamics.org
Wed Dec 17 02:33:54 PST 2008
Author: luis
Date: 2008-12-17 02:33:53 -0800 (Wed, 17 Dec 2008)
New Revision: 13775
Modified:
cs/cigma/trunk/src/cli_compare_cmd.cpp
cs/cigma/trunk/src/cli_compare_cmd.h
cs/cigma/trunk/src/cli_eval_cmd.cpp
cs/cigma/trunk/src/cli_extract_cmd.cpp
cs/cigma/trunk/src/core_compare_op.h
cs/cigma/trunk/src/core_writers.cpp
cs/cigma/trunk/src/core_writers.h
cs/cigma/trunk/src/io_file_writer.cpp
cs/cigma/trunk/src/io_file_writer.h
cs/cigma/trunk/src/io_hdf5.h
cs/cigma/trunk/src/io_hdf5_writer.cpp
cs/cigma/trunk/tests/system/100-extract.sh
cs/cigma/trunk/tests/system/200-eval.sh
cs/cigma/trunk/tests/system/300-compare.sh
cs/cigma/trunk/tests/system/301-compare.sh
Log:
Open HDF5 files in append mode, and added flag for overwriting existing data
Modified: cs/cigma/trunk/src/cli_compare_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_compare_cmd.cpp 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/cli_compare_cmd.cpp 2008-12-17 10:33:53 UTC (rev 13775)
@@ -54,6 +54,7 @@
("rule,r", po::value<string>(&rule), "Integration rule (points and weights)")
("rule-weights", po::value<string>(&qw), "...integration weights on reference cell")
("rule-points", po::value<string>(&qx), "...integration points on reference cell")
+ ("overwrite", "Overwrite existing output datasets")
("timer-frequency,f", po::value<int>(&(op.freq)), "Output frequency of timer")
("threshold", po::value<double>(&threshold), "Threshold value for global residual")
;
@@ -75,6 +76,9 @@
op.freq = 1000;
}
+ overwrite = vm.count("overwrite");
+ if (overwrite) cout << "overwriting!!" << endl;
+
if (!vm.count("first"))
{
string msg("No first field was specified (use --first option)");
@@ -176,7 +180,7 @@
cout << "Creating file " << path.filename() << endl;
}
- WriteResiduals(path, op.residuals);
+ WriteResiduals(path, op.residuals, overwrite);
return status;
}
Modified: cs/cigma/trunk/src/cli_compare_cmd.h
===================================================================
--- cs/cigma/trunk/src/cli_compare_cmd.h 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/cli_compare_cmd.h 2008-12-17 10:33:53 UTC (rev 13775)
@@ -26,8 +26,9 @@
std::string mesh, nc, eb, rule, qw, qx, cell;
std::string first, mesh1, nc1, eb1, qr1, qw1, qx1, cell1;
std::string second, mesh2, nc2, eb2, qr2, qw2, qx2, cell2;
+ double threshold;
+ bool overwrite;
std::string outputfile;
- double threshold;
CompareOp op;
Modified: cs/cigma/trunk/src/cli_eval_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_eval_cmd.cpp 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/cli_eval_cmd.cpp 2008-12-17 10:33:53 UTC (rev 13775)
@@ -43,6 +43,7 @@
("field-mesh-cell", po::value<string>(&cell), "...cell type for mesh")
("field-mesh-coords", po::value<string>(&nc), "...node coords for mesh")
("field-mesh-connect", po::value<string>(&eb), "...connectivity for mesh")
+ ("overwrite", "Overwrite existing output datasets")
;
args.add("function", 1);
@@ -113,7 +114,7 @@
<< endl;
}
- WriteArray(path, op.values);
+ WriteArray(path, op.values, vm.count("overwrite"));
return status;
}
Modified: cs/cigma/trunk/src/cli_extract_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_extract_cmd.cpp 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/cli_extract_cmd.cpp 2008-12-17 10:33:53 UTC (rev 13775)
@@ -49,6 +49,7 @@
("mesh-connect", po::value<string>(&eb), "connectivity for mesh")
("rule-weights", po::value<string>(&qw), "integration weights on reference cell")
("rule-points", po::value<string>(&qx), "integration points on reference cell")
+ ("overwrite", "Overwrite existing output datasets")
;
args.add("mesh", 1);
@@ -123,7 +124,7 @@
cout << "Writing quadrature points to the file " << path.filename() << endl;
}
- WriteQPoints(path, op.weights, op.points);
+ WriteQPoints(path, op.weights, op.points, vm.count("overwrite"));
return status;
}
Modified: cs/cigma/trunk/src/core_compare_op.h
===================================================================
--- cs/cigma/trunk/src/core_compare_op.h 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/core_compare_op.h 2008-12-17 10:33:53 UTC (rev 13775)
@@ -33,8 +33,7 @@
boost::shared_ptr<Function> first;
boost::shared_ptr<Function> second;
- boost::shared_ptr<Field> domain; // integration region (container for mesh & fe objects, w/ respective coords as the dof_values)
-
+ boost::shared_ptr<Field> domain;
boost::shared_ptr<Residuals> residuals;
};
Modified: cs/cigma/trunk/src/core_writers.cpp
===================================================================
--- cs/cigma/trunk/src/core_writers.cpp 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/core_writers.cpp 2008-12-17 10:33:53 UTC (rev 13775)
@@ -16,7 +16,7 @@
#include "vtkCellType.h"
#endif
-void cigma::WriteArray(const DataPath& path, const cigma::array<double>& x)
+void cigma::WriteArray(const DataPath& path, const cigma::array<double>& x, bool overwrite)
{
TRI_LOG_STR("cigma::WriteArray()");
TRI_LOG(path);
@@ -25,8 +25,9 @@
std::string location = path.location();
// XXX: implement read/write mode so we don't truncate an existing file
- shared_ptr<FileWriter> writer = FileWriter::New(filename, "w");
+ shared_ptr<FileWriter> writer = FileWriter::New(filename, "a");
+ writer->setOverwriteMode(overwrite);
const FileWriter::WriterType wt = writer->getWriterType();
if (wt == FileWriter::HDF5_FILE_WRITER)
{
@@ -77,7 +78,7 @@
throw cigma::Exception("WriteElementBlock", "Need implementation");
}
-void cigma::WriteQuadrature(const DataPath& path, shared_ptr<Quadrature> Q)
+void cigma::WriteQuadrature(const DataPath& path, shared_ptr<Quadrature> Q, bool overwrite)
{
//throw cigma::Exception("WriteQuadrature", "need implementation");
@@ -85,17 +86,41 @@
TRI_LOG(path);
std::string filename = path.filename();
- shared_ptr<FileWriter> writer = FileWriter::New(filename, "w");
+ shared_ptr<FileWriter> writer = FileWriter::New(filename, "a");
const FileWriter::WriterType wt = writer->getWriterType();
if (wt == FileWriter::HDF5_FILE_WRITER)
{
int status;
- string pts_loc = path.location() + "/points";
- string wts_loc = path.location() + "/weights";
+ string loc = path.location();
+ string pts_loc = loc + "/points";
+ string wts_loc = loc + "/weights";
HDF5_Writer *hdf5_writer = static_cast<HDF5_Writer*>(&(*writer));
+ hdf5_writer->setOverwriteMode(overwrite);
+
+ bool is_dset = hdf5_writer->locationIsDataset(loc.c_str());
+ if (overwrite && is_dset)
+ {
+ try
+ {
+ // remove loc
+ hdf5_writer->file->unlink(loc);
+ }
+ catch (H5::Exception e)
+ {
+ ostringstream stream;
+ stream << "Could not remove existing dataset '" << loc << "'";
+ throw cigma::Exception("WriteQuadrature", stream.str());
+ }
+ }
+
+ bool not_there = !(hdf5_writer->locationIsGroup(loc.c_str()));
+ if (not_there)
+ {
+ hdf5_writer->file->createGroup(loc);
+ }
+
status = hdf5_writer->writeDataset(wts_loc.c_str(), Q->weights, Q->npts, 1);
-
if (status < 0)
{
ostringstream stream;
@@ -151,7 +176,7 @@
}
}
-void cigma::WriteQPoints(const DataPath& path, const cigma::array<double>& w, const cigma::array<double>& x)
+void cigma::WriteQPoints(const DataPath& path, const cigma::array<double>& w, const cigma::array<double>& x, bool overwrite)
{
shared_ptr<Quadrature> Q(new Quadrature);
@@ -167,7 +192,7 @@
try
{
- WriteQuadrature(path, Q);
+ WriteQuadrature(path, Q, overwrite);
}
catch (cigma::Exception& e)
{
@@ -207,7 +232,7 @@
#endif
}
-void cigma::WriteResiduals(const DataPath& path, shared_ptr<Residuals> residuals)
+void cigma::WriteResiduals(const DataPath& path, shared_ptr<Residuals> residuals, bool overwrite)
{
TRI_LOG_STR("cigma::WriteResiduals()");
TRI_LOG(path);
@@ -223,12 +248,15 @@
std::string filename = path.filename();
std::string location = path.location();
- shared_ptr<FileWriter> writer = FileWriter::New(filename, "w");
+ shared_ptr<FileWriter> writer = FileWriter::New(filename, "a");
const FileWriter::WriterType wt = writer->getWriterType();
if (wt == FileWriter::HDF5_FILE_WRITER)
{
HDF5_Writer *hdf5_writer = static_cast<HDF5_Writer*>(&(*writer));
+ // prepare writer to overwrite exsting datasets
+ hdf5_writer->setOverwriteMode(overwrite);
+
string eps_loc = location;
if (hdf5_writer->locationIsGroup(eps_loc.c_str()))
{
Modified: cs/cigma/trunk/src/core_writers.h
===================================================================
--- cs/cigma/trunk/src/core_writers.h 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/core_writers.h 2008-12-17 10:33:53 UTC (rev 13775)
@@ -14,13 +14,13 @@
namespace cigma
{
- void WriteArray(const DataPath& path, const cigma::array<double>& x);
+ void WriteArray(const DataPath& path, const cigma::array<double>& x, bool overwrite=false);
void WriteNodeCoordinates(const DataPath& path, boost::shared_ptr<NodeCoordinates> nc);
void WriteElementBlock(const DataPath& path, boost::shared_ptr<ElementBlock> eb);
- void WriteQuadrature(const DataPath& path, boost::shared_ptr<Quadrature> Q);
- void WriteQPoints(const DataPath& path, const cigma::array<double>& w, const cigma::array<double>& x);
+ void WriteQuadrature(const DataPath& path, boost::shared_ptr<Quadrature> Q, bool overwrite=false);
+ void WriteQPoints(const DataPath& path, const cigma::array<double>& w, const cigma::array<double>& x, bool overwrite=false);
void WriteDofs(const DataPath& path, boost::shared_ptr<DofHandler> dofs);
- void WriteResiduals(const DataPath& path, boost::shared_ptr<Residuals> residuals);
+ void WriteResiduals(const DataPath& path, boost::shared_ptr<Residuals> residuals, bool overwrite=false);
}
#endif
Modified: cs/cigma/trunk/src/io_file_writer.cpp
===================================================================
--- cs/cigma/trunk/src/io_file_writer.cpp 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/io_file_writer.cpp 2008-12-17 10:33:53 UTC (rev 13775)
@@ -22,17 +22,8 @@
fs::path p(filename);
string ext = fs::extension(p);
- if (fs::exists(p))
- {
- // The file exists...don't allow overwriting unless mode is "w"
- // XXX: how to make exception for HDF5 and NetCDF files?
- if (mode != "w")
- {
- std::ostringstream stream;
- stream << "Overwriting existing file '" << filename << "'" << std::ends;
- throw cigma::Exception("FileWriter::New", stream.str());
- }
- }
+ // XXX: check if file exists? handling overwrites?
+ // Assume append mode for now
if (is_hdf5_extension(ext.c_str()))
{
@@ -73,9 +64,20 @@
FileWriter::FileWriter()
{
+ overwrite_mode = false;
}
FileWriter::~FileWriter()
{
}
+void FileWriter::setOverwriteMode(bool overwrite)
+{
+ this->overwrite_mode = overwrite;
+}
+
+bool FileWriter::overwrite() const
+{
+ return overwrite_mode;
+}
+
Modified: cs/cigma/trunk/src/io_file_writer.h
===================================================================
--- cs/cigma/trunk/src/io_file_writer.h 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/io_file_writer.h 2008-12-17 10:33:53 UTC (rev 13775)
@@ -21,6 +21,7 @@
class cigma::FileWriter : private boost::noncopyable
{
public:
+
FileWriter();
virtual ~FileWriter();
@@ -31,6 +32,13 @@
virtual int writeCoordinates(const char *loc, const double *coordinates, int nno, int nsd) = 0;
virtual int writeConnectivity(const char *loc, const int *connectivity, int nel, int ndofs) = 0;
+ void setOverwriteMode(bool overwrite);
+ bool overwrite() const;
+
+ static boost::shared_ptr<FileWriter> New(std::string filename, std::string mode);
+
+public:
+
typedef enum {
NULL_FILE_WRITER,
HDF5_FILE_WRITER,
@@ -40,7 +48,8 @@
virtual WriterType getWriterType() = 0;
- static boost::shared_ptr<FileWriter> New(std::string filename, std::string mode);
+public:
+ bool overwrite_mode;
};
Modified: cs/cigma/trunk/src/io_hdf5.h
===================================================================
--- cs/cigma/trunk/src/io_hdf5.h 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/io_hdf5.h 2008-12-17 10:33:53 UTC (rev 13775)
@@ -174,7 +174,7 @@
* @param FT file type of data (what gets written to disk)
*/
template <typename MT, typename FT>
-int write_full_dataset(H5::H5File *file, const char *loc, const MT *data, int nrows, int ncols)
+int write_full_dataset(H5::H5File *file, const char *loc, const MT *data, int nrows, int ncols, bool overwrite)
{
if (file == 0)
{
@@ -187,26 +187,61 @@
H5::DataSpace dataspace(2, dims);
H5::DataType filetype = h5_datatype_from<FT>();
H5::DataType memtype = h5_datatype_from<MT>();
- H5::DataSet dataset = file->createDataSet(loc, filetype, dataspace);
- dataset.write(data, memtype);
+ H5::DataSet dataset;
+
+ try
+ {
+ dataset = file->createDataSet(loc, filetype, dataspace);
+ }
+ catch (H5::Exception error)
+ {
+ TRI_LOG_STR("Dataset creation failed!");
+ if (overwrite)
+ {
+ TRI_LOG_STR("Unlinking location...");
+ file->unlink(loc);
+
+ TRI_LOG_STR("Attempting to create dataset again");
+ dataset = file->createDataSet(loc, filetype, dataspace);
+ }
+ else
+ {
+ //error.printError();
+ std::cout << "Error: " << error.getDetailMsg() << " (in " << error.getFuncName() << ")" << std::endl;
+ return -2;
+ }
+ }
+
+ try
+ {
+ TRI_LOG_STR("Writing data to dataset");
+ dataset.write(data, memtype);
+ }
+ catch (H5::DataSetIException error)
+ {
+ //error.printError();
+ std::cout << "Error: " << error.getDetailMsg() << " (in " << error.getFuncName() << ")" << std::endl;
+ return -2;
+ }
+
}
catch (H5::DataSpaceIException error)
{
//error.printError();
std::cout << "Error: " << error.getDetailMsg() << " (in " << error.getFuncName() << ")" << std::endl;
- return -1;
+ return -3;
}
catch (H5::DataSetIException error)
{
//error.printError();
std::cout << "Error: " << error.getDetailMsg() << " (in " << error.getFuncName() << ")" << std::endl;
- return -1;
+ return -4;
}
catch (H5::Exception error)
{
//error.printError();
std::cout << "Error: " << error.getDetailMsg() << " (in " << error.getFuncName() << ")" << std::endl;
- return -1;
+ return -5;
}
return 0;
Modified: cs/cigma/trunk/src/io_hdf5_writer.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5_writer.cpp 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/src/io_hdf5_writer.cpp 2008-12-17 10:33:53 UTC (rev 13775)
@@ -29,7 +29,7 @@
}
string m(mode);
- if ((m == "w") || (m == "rw") || (m == "x"))
+ if ((m == "w") || (m == "rw") || (m == "a") || (m == "x"))
{
file = h5_open_file(filename, mode);
}
@@ -62,21 +62,21 @@
{
TRI_LOG_STR("HDF5_Writer::writeDataset()");
TRI_LOG(loc);
- return write_full_dataset<double,double>(file, loc, data, nno, ndim);
+ return write_full_dataset<double,double>(file, loc, data, nno, ndim, this->overwrite());
}
int HDF5_Writer::writeCoordinates(const char *loc, const double *coordinates, int nno, int nsd)
{
TRI_LOG_STR("HDF5_Writer::writeCoordinates()");
TRI_LOG(loc);
- return write_full_dataset<double,double>(file, loc, coordinates, nno, nsd);
+ return write_full_dataset<double,double>(file, loc, coordinates, nno, nsd, this->overwrite());
}
int HDF5_Writer::writeConnectivity(const char *loc, const int *connectivity, int nel, int ndofs)
{
TRI_LOG_STR("HDF5_Writer::writeConnectivity()");
TRI_LOG(loc);
- return write_full_dataset<int,int>(file, loc, connectivity, nel, ndofs);
+ return write_full_dataset<int,int>(file, loc, connectivity, nel, ndofs, this->overwrite());
}
bool HDF5_Writer::locationIsGroup(const char *loc) const
Modified: cs/cigma/trunk/tests/system/100-extract.sh
===================================================================
--- cs/cigma/trunk/tests/system/100-extract.sh 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/tests/system/100-extract.sh 2008-12-17 10:33:53 UTC (rev 13775)
@@ -6,5 +6,6 @@
--output=$D/system/out/100.h5 \
--mesh=$D/data/brick2/brick2.h5:/ \
--mesh-cell=tet4 \
+ --overwrite \
$*
Modified: cs/cigma/trunk/tests/system/200-eval.sh
===================================================================
--- cs/cigma/trunk/tests/system/200-eval.sh 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/tests/system/200-eval.sh 2008-12-17 10:33:53 UTC (rev 13775)
@@ -6,5 +6,6 @@
--output=$D/system/out/200.h5:/values \
--points=$D/data/brick1/brick1.h5:/coordinates \
--field=test.cube \
+ --overwrite \
$*
Modified: cs/cigma/trunk/tests/system/300-compare.sh
===================================================================
--- cs/cigma/trunk/tests/system/300-compare.sh 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/tests/system/300-compare.sh 2008-12-17 10:33:53 UTC (rev 13775)
@@ -12,5 +12,6 @@
--second=$B/CubeFn.dat \
--second-mesh=$B/brick2.h5:/ \
--second-mesh-cell=tet4 \
+ --overwrite \
$*
Modified: cs/cigma/trunk/tests/system/301-compare.sh
===================================================================
--- cs/cigma/trunk/tests/system/301-compare.sh 2008-12-17 10:33:52 UTC (rev 13774)
+++ cs/cigma/trunk/tests/system/301-compare.sh 2008-12-17 10:33:53 UTC (rev 13775)
@@ -14,7 +14,7 @@
--second-mesh-coordinates=$B/coords.dat \
--second-mesh-connectivity=$B/connect.dat \
\
- --max-epsilon="1e-8"
+ --threshold="1e-8"
\
$*
More information about the CIG-COMMITS
mailing list