[cig-commits] r13636 - in cs/cigma/trunk: . src

luis at geodynamics.org luis at geodynamics.org
Tue Dec 9 18:16:40 PST 2008


Author: luis
Date: 2008-12-09 18:16:40 -0800 (Tue, 09 Dec 2008)
New Revision: 13636

Modified:
   cs/cigma/trunk/Makefile.am
   cs/cigma/trunk/src/core_readers.cpp
   cs/cigma/trunk/src/core_writers.cpp
   cs/cigma/trunk/src/io_file_reader.cpp
   cs/cigma/trunk/src/io_file_reader.h
   cs/cigma/trunk/src/io_file_writer.cpp
   cs/cigma/trunk/src/io_file_writer.h
   cs/cigma/trunk/src/io_hdf5_reader.cpp
   cs/cigma/trunk/src/io_hdf5_reader.h
   cs/cigma/trunk/src/io_hdf5_writer.cpp
   cs/cigma/trunk/src/io_hdf5_writer.h
   cs/cigma/trunk/src/io_vtk_reader.cpp
   cs/cigma/trunk/src/io_vtk_reader.h
   cs/cigma/trunk/src/io_vtk_writer.cpp
   cs/cigma/trunk/src/io_vtk_writer.h
Log:
Finally, conditional compilation of HDF5 & VTK code.

This allows us to disable HDF5 or VTK by using either
of the --without-hdf5 or --without-vtk when calling the
./configure script.

Modified: cs/cigma/trunk/Makefile.am
===================================================================
--- cs/cigma/trunk/Makefile.am	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/Makefile.am	2008-12-10 02:16:40 UTC (rev 13636)
@@ -6,7 +6,10 @@
 ACLOCAL_AMFLAGS = -I ./config
 
 # Main programs to build
-bin_PROGRAMS = cigma h5attr
+bin_PROGRAMS = cigma
+if COND_HDF5
+bin_PROGRAMS += h5attr
+endif
 
 # Libraries
 lib_LTLIBRARIES =
@@ -221,7 +224,7 @@
 	src/io_hdf5_writer.cpp
 #endif
 
-if COND_VTK
+#if COND_VTK
 libcigma_la_cppflags += $(VTK_INCLUDES)
 libcigma_la_sources  += \
 	src/io_vtk.h \
@@ -230,7 +233,7 @@
 	src/io_vtk_reader.cpp \
 	src/io_vtk_writer.h \
 	src/io_vtk_writer.cpp
-endif
+#endif
 
 # }}}
 
@@ -279,10 +282,10 @@
 cigma_ldadd   += $(HDF5_LIBS)
 #endif
 
-if COND_VTK
+#if COND_VTK
 cigma_ldflags += $(VTK_LDFLAGS)
 cigma_ldadd   += $(VTK_LIBS)
-endif
+#endif
 
 # }}} 
 
@@ -441,11 +444,11 @@
 cigma_mod_libs     += $(HDF5_LIBS)
 #endif
 
-if COND_VTK
+#if COND_VTK
 cigma_mod_cppflags += $(VTK_INCLUDES)
 cigma_mod_ldflags  += $(VTK_LDFLAGS)
 cigma_mod_libs     += $(VTK_LIBS)
-endif
+#endif
 
 # Additional files
 EXTRA_DIST += src/py_cigma_setup.py

Modified: cs/cigma/trunk/src/core_readers.cpp
===================================================================
--- cs/cigma/trunk/src/core_readers.cpp	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/core_readers.cpp	2008-12-10 02:16:40 UTC (rev 13636)
@@ -1,9 +1,15 @@
 #include "core_readers.h"
+#include "Common.h"
+
 #include "nc_array.h"
 #include "eb_array.h"
 #include "AnnLocator.h"
-#include "Common.h"
+
 #include "io_file_reader.h"
+#include "io_text_reader.h"
+#include "io_hdf5_reader.h"
+#include "io_vtk_reader.h"
+
 #include <string>
 #include <sstream>
 
@@ -11,6 +17,7 @@
 using namespace cigma;
 using boost::shared_ptr;
 
+
 // ----------------------------------------------------------------------------
 
 cigma::array<double>* cigma::ReadArray(const DataPath& array_path)

Modified: cs/cigma/trunk/src/core_writers.cpp
===================================================================
--- cs/cigma/trunk/src/core_writers.cpp	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/core_writers.cpp	2008-12-10 02:16:40 UTC (rev 13636)
@@ -1,6 +1,7 @@
 #include "core_writers.h"
 #include "io_text_writer.h"
 #include "io_hdf5_writer.h"
+#include "io_vtk_writer.h"
 #include "tri_logger.hpp"
 using namespace cigma;
 

Modified: cs/cigma/trunk/src/io_file_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_file_reader.cpp	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_file_reader.cpp	2008-12-10 02:16:40 UTC (rev 13636)
@@ -1,23 +1,20 @@
 #include "io_file_reader.h"
-#include "Exception.h"
+#include "io_null_reader.h"
+#include "io_text_reader.h"
+#include "io_hdf5_reader.h"
+#include "io_vtk_reader.h"
 
-// std
 #include <string>
 #include <cstdlib>
 #include <cassert>
 #include <sstream>
-using namespace std;
 
-// boost
-#include "Filesystem.h"
+
 namespace fs = boost::filesystem;
+
 using boost::shared_ptr;
 
-// readers
-#include "io_null_reader.h"
-#include "io_text_reader.h"
-#include "io_hdf5_reader.h"
-//#include "io_vtk_reader.h"
+using namespace std;
 using namespace cigma;
 
 
@@ -44,7 +41,6 @@
         }
         else if (is_vtk_extension(ext.c_str()))
         {
-            /*
             tmp.reset(new VtkReader());
             status = tmp->open(filename.c_str(), mode.c_str());
             if (status < 0)
@@ -52,7 +48,7 @@
                 std::ostringstream stream;
                 stream << "Could not open VTK file '" << filename << "' for reading" << std::ends;
                 throw cigma::Exception("FileReader::New", stream.str());
-            } // */
+            }
             throw cigma::Exception("FileReader::New", "Need VtkReader");
         }
         else if (is_text_extension(ext.c_str()))

Modified: cs/cigma/trunk/src/io_file_reader.h
===================================================================
--- cs/cigma/trunk/src/io_file_reader.h	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_file_reader.h	2008-12-10 02:16:40 UTC (rev 13636)
@@ -4,9 +4,11 @@
 #include <string>
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
+
+#include "Common.h"
 #include "Filesystem.h"
-#include "Exception.h"
 
+
 namespace cigma
 {
     class FileReader;

Modified: cs/cigma/trunk/src/io_file_writer.cpp
===================================================================
--- cs/cigma/trunk/src/io_file_writer.cpp	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_file_writer.cpp	2008-12-10 02:16:40 UTC (rev 13636)
@@ -2,19 +2,8 @@
 #include "io_null_writer.h"
 #include "io_text_writer.h"
 #include "io_hdf5_writer.h"
-
-/*
-#ifdef HAVE_HDF5
-#include "io_hdf5_writer.h"
-#endif
-
-#ifdef HAVE_VTK
 #include "io_vtk_writer.h"
-#endif
-*/
 
-#include "Exception.h"
-
 #include <sstream>
 #include <cassert>
 #include <cstdlib>
@@ -59,7 +48,6 @@
     else if (is_vtk_extension(ext.c_str()))
     {
         throw cigma::Exception("FileWriter::New", "Need VTK writer");
-        /*
         tmp.reset(new VtkWriter());
         status = tmp->open(filename.c_str(), mode.c_str());
         if (status < 0)
@@ -68,7 +56,6 @@
             stream << "Could not open VTK file '" << filename << "' for writing" << std::ends;
             throw cigma::Exception("FileWriter::New", stream.str());
         }
-        // */
     }
     else if (is_text_extension(ext.c_str()))
     {

Modified: cs/cigma/trunk/src/io_file_writer.h
===================================================================
--- cs/cigma/trunk/src/io_file_writer.h	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_file_writer.h	2008-12-10 02:16:40 UTC (rev 13636)
@@ -4,8 +4,11 @@
 #include <string>
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
+
+#include "Common.h"
 #include "Filesystem.h"
 
+
 namespace cigma
 {
     class FileWriter;
@@ -28,9 +31,6 @@
     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;
 
-    static boost::shared_ptr<FileWriter> New(std::string filename, std::string mode);
-
-public:
     typedef enum {
         NULL_FILE_WRITER,
         HDF5_FILE_WRITER,
@@ -40,6 +40,9 @@
 
     virtual WriterType getWriterType() = 0;
 
+    static boost::shared_ptr<FileWriter> New(std::string filename, std::string mode);
+
 };
 
+
 #endif

Modified: cs/cigma/trunk/src/io_hdf5_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5_reader.cpp	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_hdf5_reader.cpp	2008-12-10 02:16:40 UTC (rev 13636)
@@ -1,14 +1,14 @@
 #include "io_hdf5_reader.h"
 #include "io_hdf5.h"
 
-#include "Common.h"
 #include <iostream>
 
 using namespace std;
 using namespace cigma;
 
-// ----------------------------------------------------------------------------
 
+#ifdef HAVE_HDF5
+
 HDF5_Reader::HDF5_Reader()
 {
     file = 0;
@@ -19,9 +19,6 @@
     close();
 }
 
-// ----------------------------------------------------------------------------
-
-
 int HDF5_Reader::open(const char *filename, const char *mode)
 {
     TRI_LOG_STR("HDF5_Reader::open()");
@@ -49,46 +46,6 @@
     }
 
     return 0;
-
-    /*
-    H5::Exception::dontPrint();
-
-    if (file != 0) { return -2; }
-
-    try
-    {
-        string m(mode);
-
-        if (m == "r")
-        {
-            file = new H5::H5File(filename, H5F_ACC_RDONLY);
-        }
-        else if (m == "a")
-        {
-            try
-            {
-                file = new H5::H5File(filename, H5F_ACC_RDWR);
-            }
-            catch (H5::FileIException e)
-            {
-            }
-
-            if (file == 0)
-            {
-                file = new H5::H5File(filename, H5F_ACC_TRUNC);
-            }
-        }
-    }
-    catch (H5::FileIException error)
-    {
-        error.printError();
-        return -1;
-    }
-
-    if (file == 0) { return -3; }
-
-    return 0;
-    // */
 }
 
 int HDF5_Reader::close()
@@ -102,92 +59,6 @@
 }
 
 
-// ----------------------------------------------------------------------------
-
-/*
-template <typename T> static H5::PredType predtype_from();
-template <> H5::PredType predtype_from<int>()   { return H5::PredType::NATIVE_INT; }
-template <> H5::PredType predtype_from<long>()  { return H5::PredType::NATIVE_LONG; }
-template <> H5::PredType predtype_from<float>() { return H5::PredType::NATIVE_FLOAT; }
-template <> H5::PredType predtype_from<double>(){ return H5::PredType::NATIVE_DOUBLE; }
-// */
-
-/*
-template <typename T> static H5T_class_t typeclass_from();
-template <> H5T_class_t typeclass_from<float>()  { return H5T_FLOAT; }
-template <> H5T_class_t typeclass_from<double>() { return H5T_FLOAT; }
-template <> H5T_class_t typeclass_from<int>()    { return H5T_INTEGER; }
-// */
-
-/*
-template <typename MT>
-static int get_full_dataset(H5::H5File *file, const char *loc, MT **data, int *nrows, int *ncols)
-{
-    try
-    {
-        H5::DataSet dataset = file->openDataSet(loc);
-
-        H5T_class_t type_class = dataset.getTypeClass();
-        if (type_class != typeclass_from<MT>())
-        {
-            cerr << "Dataset type mismatch in read operation." << endl;
-            return -2;
-        }
-
-        H5::DataSpace dataspace = dataset.getSpace();
-        
-        int rank = dataspace.getSimpleExtentNdims();
-        if ((rank != 1) && (rank != 2))
-        {
-            cerr << "Dataset rank must be 1 or 2." << endl;
-            return -3;
-        }
-
-        hsize_t dims[2];
-        int ndims = dataspace.getSimpleExtentDims(dims, NULL);
-        int size = dataspace.getSimpleExtentNpoints();
-        MT *array = 0;
-
-        try
-        {
-            array = new MT[size];
-            dataset.read(array, predtype_from<MT>());
-        }
-        catch (H5::DataSetIException error)
-        {
-            cerr << "Dataset '" << loc << "' could not be read." << endl;
-            delete array;
-            array = 0;
-        }
-
-        if (array == 0)
-        {
-            return -1;
-        }
-
-        *nrows = dims[0];
-        *ncols = dims[1];
-        *data  = array;
-    }
-    catch (H5::DataSetIException error)
-    {
-        error.printError();
-        return -1;
-    }
-    catch (H5::DataSpaceIException error)
-    {
-        error.printError();
-        return -1;
-    }
-    catch (H5::Exception error)
-    {
-        //error.printError();
-        return -1;
-    }
-    return 0;
-}
-// */
-
 int HDF5_Reader::getDataset(const char *loc, double **data, int *num, int *dim)
 {
     TRI_LOG_STR("HDF5_Reader::getDataset()");
@@ -209,152 +80,94 @@
     return get_full_dataset<int>(file, loc, connectivity, nel, ndofs);
 }
 
-// ----------------------------------------------------------------------------
+int HDF5_Reader::readAttrString(const char *loc, const char *attr_name, string& val)
+{
+    return read_scalar_attribute<string>(file, loc, attr_name, val);
+}
 
-/*
-static H5::H5Object* load_h5obj(H5::H5File *file, const char *loc)
+int HDF5_Reader::readAttrInteger(const char *loc, const char *attr_name, int& val)
 {
-    H5::H5Object* obj = 0;
+    return read_scalar_attribute<int>(file, loc, attr_name, val);
+}
 
-    if (file)
-    {
-        H5::Exception::dontPrint();
+int HDF5_Reader::readAttrLong(const char *loc, const char *attr_name, long& val)
+{
+    return read_scalar_attribute<long>(file, loc, attr_name, val);
+}
 
-        try
-        {
-            obj = new H5::Group(file->openGroup(loc));
-        }
-        catch (H5::Exception error)
-        {
-        }
+int HDF5_Reader::readAttrFloat(const char *loc, const char *attr_name, float& val)
+{
+    return read_scalar_attribute<float>(file, loc, attr_name, val);
+}
 
-        if (obj == 0)
-        {
-            try
-            {
-                obj = new H5::DataSet(file->openDataSet(loc));
-            }
-            catch (H5::Exception error)
-            {
-            }
-        }
-    }
-
-    return obj;
-} // */
-
-/*
-int HDF5_Reader::readAttrString(const char *loc, const char *attr_name, std::string& val)
+int HDF5_Reader::readAttrDouble(const char *loc, const char *attr_name, double& val)
 {
-    H5::H5Object* obj = 0;
-    H5::Attribute* attr = 0;
+    return read_scalar_attribute<double>(file, loc, attr_name, val);
+}
 
-    if (file)
-    {
-        try
-        {
-            obj = load_h5obj(file, loc);
-            if (obj == 0) { return -2; }
 
-            H5::StrType tid(0, H5T_VARIABLE);
-            attr = new H5::Attribute(obj->openAttribute(attr_name));
-            attr->read(tid, val);
-        }
-        catch (H5::Exception error)
-        {
-            if (obj) { delete obj; }
-            if (attr) { delete attr; }
-            return -1;
-        }
+#else
 
-        if (obj) { delete obj; }
-        if (attr) { delete attr; }
-    }
+HDF5_Reader::HDF5_Reader()
+{
+    throw cigma::Exception("HDF5_Reader", "Can't create HDF5_Reader. Cigma is not configured with the C++ HDF5 Library");
+}
 
-    return 0;
-} // */
-
-/*
-template <typename T>
-static int read_attribute(H5::H5File *file, const char *loc, const char *attr_name, T* val)
+HDF5_Reader::~HDF5_Reader()
 {
-    H5::H5Object* obj = 0;
-    H5::Attribute* attr = 0;
+}
 
-    if (file)
-    {
-        try
-        {
-            obj = load_h5obj(file, loc);
-            if (obj == 0) { return -2; }
-
-            if (obj == 0)
-            {
-                return -2;
-            }
-
-            attr = new H5::Attribute(obj->openAttribute(attr_name));
-            attr->read(predtype_from<T>(), val);
-        }
-        catch (H5::Exception error)
-        {
-            if (obj) { delete obj; }
-            if (attr) { delete attr; }
-            return -1;
-        }
-
-        if (obj) { delete obj; }
-        if (attr) { delete attr; }
-    }
-
-    return 0;
+int HDF5_Reader::open(const char *filename, const char *mode)
+{
+    return -1;
 }
 
-int HDF5_Reader::readAttrInteger(const char *loc, const char *attr_name, int& val)
+int HDF5_Reader::close()
 {
-    return read_attribute<int>(file, loc, attr_name, &val);
+    return -1;
 }
 
-int HDF5_Reader::readAttrLong(const char *loc, const char *attr_name, long& val)
+
+int HDF5_Reader::getDataset(const char *loc, double **data, int *num, int *dim)
 {
-    return read_attribute<long>(file, loc, attr_name, &val);
+    return -1;
 }
 
-int HDF5_Reader::readAttrFloat(const char *loc, const char *attr_name, float& val)
+int HDF5_Reader::getCoordinates(const char *loc, double **coordinates, int *nno, int *nsd)
 {
-    return read_attribute<float>(file, loc, attr_name, &val);
+    return -1;
 }
 
-int HDF5_Reader::readAttrDouble(const char *loc, const char *attr_name, double& val)
+int HDF5_Reader::getConnectivity(const char *loc, int **connectivity, int *nel, int *ndofs)
 {
-    return read_attribute<double>(file, loc, attr_name, &val);
+    return -1;
 }
-// */
 
-
 int HDF5_Reader::readAttrString(const char *loc, const char *attr_name, string& val)
 {
-    return read_scalar_attribute<string>(file, loc, attr_name, val);
+    return -1;
 }
 
 int HDF5_Reader::readAttrInteger(const char *loc, const char *attr_name, int& val)
 {
-    return read_scalar_attribute<int>(file, loc, attr_name, val);
+    return -1;
 }
 
 int HDF5_Reader::readAttrLong(const char *loc, const char *attr_name, long& val)
 {
-    return read_scalar_attribute<long>(file, loc, attr_name, val);
+    return -1;
 }
 
 int HDF5_Reader::readAttrFloat(const char *loc, const char *attr_name, float& val)
 {
-    return read_scalar_attribute<float>(file, loc, attr_name, val);
+    return -1;
 }
 
+
 int HDF5_Reader::readAttrDouble(const char *loc, const char *attr_name, double& val)
 {
-    return read_scalar_attribute<double>(file, loc, attr_name, val);
+    return -1;
 }
 
-// ----------------------------------------------------------------------------
+
+#endif

Modified: cs/cigma/trunk/src/io_hdf5_reader.h
===================================================================
--- cs/cigma/trunk/src/io_hdf5_reader.h	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_hdf5_reader.h	2008-12-10 02:16:40 UTC (rev 13636)
@@ -2,7 +2,10 @@
 #define __CIGMA_HDF5_READER_H__
 
 #include "io_file_reader.h"
+
+#ifdef HAVE_HDF5
 #include "H5Cpp.h"
+#endif
 
 namespace cigma
 {
@@ -30,8 +33,10 @@
     int readAttrFloat(const char *loc, const char *attr_name, float& val);
     int readAttrDouble(const char *loc, const char *attr_name, double& val);
 
+#ifdef HAVE_HDF5
 public:
     H5::H5File *file;
+#endif
 };
 
 #endif

Modified: cs/cigma/trunk/src/io_hdf5_writer.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5_writer.cpp	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_hdf5_writer.cpp	2008-12-10 02:16:40 UTC (rev 13636)
@@ -1,12 +1,12 @@
 #include "io_hdf5_writer.h"
 #include "io_hdf5.h"
-#include "Common.h"
 
 using namespace std;
 using namespace cigma;
 
-// ----------------------------------------------------------------------------
 
+#ifdef HAVE_HDF5
+
 HDF5_Writer::HDF5_Writer()
 {
     file = 0;
@@ -17,14 +17,12 @@
     close();
 }
 
-// ----------------------------------------------------------------------------
-
 int HDF5_Writer::open(const char *filename, const char *mode)
 {
     TRI_LOG_STR("HDF5_Writer::open()");
     TRI_LOG(filename);
+    TRI_LOG(mode);
 
-
     if (file != 0)
     {
         return -3;
@@ -47,45 +45,7 @@
     }
 
     return 0;
-    /*
-    H5::Exception::dontPrint();
 
-    if (file != 0) { return -2; }
-
-    try
-    {
-        string m(mode);
-
-        if (m == "w")
-        {
-            file = new H5::H5File(filename, H5F_ACC_TRUNC);
-        }
-        else if (m == "a")
-        {
-            try
-            {
-                file = new H5::H5File(filename, H5F_ACC_RDWR);
-            }
-            catch (H5::FileIException e)
-            {
-            }
-
-            if (file == 0)
-            {
-                file = new H5::H5File(filename, H5F_ACC_TRUNC);
-            }
-        }
-    }
-    catch (H5::FileIException error)
-    {
-        error.printError();
-        return -1;
-    }
-
-    if (file == 0) { return -3; }
-
-    return 0;
-    // */
 }
 
 int HDF5_Writer::close()
@@ -99,46 +59,6 @@
 }
 
 
-// ----------------------------------------------------------------------------
-
-/*
-template <typename T> static H5::PredType predtype_from();
-template <> H5::PredType predtype_from<float>() { return H5::PredType::NATIVE_FLOAT; }
-template <> H5::PredType predtype_from<double>(){ return H5::PredType::NATIVE_DOUBLE; }
-template <> H5::PredType predtype_from<int>()   { return H5::PredType::NATIVE_INT; }
-// */
-
-/*
-template <typename MT, typename FT>
-static int write_dataset(H5::H5File *file, const char *loc, const MT *data, int nrows, int ncols)
-{
-    try
-    {
-        hsize_t dims[2] = {nrows, ncols};
-        H5::DataSpace dataspace(2, dims);
-        H5::DataSet dataset = file->createDataSet(loc, predtype_from<FT>(), dataspace);
-        dataset.write(data, predtype_from<MT>());
-    }
-    catch (H5::DataSpaceIException error)
-    {
-        error.printError();
-        return -1;
-    }
-    catch (H5::DataSetIException error)
-    {
-        error.printError();
-        return -1;
-    }
-    catch (H5::Exception error)
-    {
-        //error.printError();
-        return -1;
-    }
-    return 0;
-}
-// */
-
-
 int HDF5_Writer::writeDataset(const char *loc, const double *data, int nno, int ndim)
 {
     TRI_LOG_STR("HDF5_Writer::writeDataset()");
@@ -160,4 +80,41 @@
     return write_full_dataset<int,int>(file, loc, connectivity, nel, ndofs);
 }
 
-// ----------------------------------------------------------------------------
+#else
+
+HDF5_Writer::HDF5_Writer()
+{
+    throw cigma::Exception("HDF5_Writer", "Can't create HDF5_Writer. Cigma is not configured with the C++ HDF5 Library");
+}
+
+HDF5_Writer::~HDF5_Writer()
+{
+}
+
+int HDF5_Writer::open(const char *filename, const char *mode)
+{
+    return -1;
+}
+
+int HDF5_Writer::close()
+{
+    return -1;
+}
+
+
+int HDF5_Writer::writeDataset(const char *loc, const double *data, int nno, int ndim)
+{
+    return -1;
+}
+
+int HDF5_Writer::writeCoordinates(const char *loc, const double *coordinates, int nno, int nsd)
+{
+    return -1;
+}
+
+int HDF5_Writer::writeConnectivity(const char *loc, const int *connectivity, int nel, int ndofs)
+{
+    return -1
+}
+
+#endif

Modified: cs/cigma/trunk/src/io_hdf5_writer.h
===================================================================
--- cs/cigma/trunk/src/io_hdf5_writer.h	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_hdf5_writer.h	2008-12-10 02:16:40 UTC (rev 13636)
@@ -2,7 +2,10 @@
 #define __CIGMA_HDF5_WRITER_H__
 
 #include "io_file_writer.h"
+
+#ifdef HAVE_HDF5
 #include "H5Cpp.h"
+#endif
 
 namespace cigma
 {
@@ -24,7 +27,10 @@
     int writeCoordinates(const char *loc, const double *coordinates, int nno, int nsd);
     int writeConnectivity(const char *loc, const int *connectivity, int nel, int ndofs);
 
+#ifdef HAVE_HDF5
 public:
     H5::H5File *file;
+#endif
+
 };
 #endif

Modified: cs/cigma/trunk/src/io_vtk_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_vtk_reader.cpp	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_vtk_reader.cpp	2008-12-10 02:16:40 UTC (rev 13636)
@@ -1,8 +1,12 @@
 #include "io_vtk_reader.h"
 
-#include "Common.h"
-#include "BoostFilesystem.h"
 
+#ifdef HAVE_VTK
+
+//
+//
+//
+
 #include "vtkUnstructuredGridReader.h"
 #include "vtkStructuredGridReader.h"
 #include "vtkRectilinearGridReader.h"
@@ -29,7 +33,6 @@
 using namespace std;
 using namespace cigma;
 
-// ----------------------------------------------------------------------------
 
 VtkReader::VtkReader()
 {
@@ -39,17 +42,18 @@
     gridType = NULL_GRID;
 }
 
+
 VtkReader::~VtkReader()
 {
     close();
 }
 
-// ----------------------------------------------------------------------------
 
-int VtkReader::open(const char *filename)
+int VtkReader::open(const char *filename, const char *mode)
 {
     TRI_LOG_STR("VtkReader::open()");
     TRI_LOG(filename);
+    TRI_LOG(mode);
 
     string filepath = filename;
     string ext = boost::filesystem::extension(filepath);
@@ -160,7 +164,6 @@
     return 0;
 }
 
-// ----------------------------------------------------------------------------
 
 static int GetDimensionFromCellType(int cellType)
 {
@@ -200,6 +203,7 @@
     return -1;
 }
 
+
 int VtkReader::getDataset(const char *loc, double **data, int *num, int *dim)
 {
     TRI_LOG_STR("VtkReader::getDataset()");
@@ -262,6 +266,7 @@
     return 0;
 }
 
+
 int VtkReader::getCoordinates(const char *loc, double **coordinates, int *nno, int *nsd)
 {
     TRI_LOG_STR("VtkReader::getCoordinates()");
@@ -352,4 +357,51 @@
     return 0;
 }
 
-// ----------------------------------------------------------------------------
+
+#else
+
+//
+//
+//
+
+
+using namespace cigma;
+
+
+VtkReader::VtkReader()
+{
+    throw cigma::Exception("VtkReader", "Can't create VtkReader. Cigma is not configured with the VTK library");
+}
+
+VtkReader::~VtkReader()
+{
+}
+
+int VtkReader::open(const char *filename, const char *mode)
+{
+    return -1;
+}
+
+int VtkReader::close()
+{
+    return -1;
+}
+
+int VtkReader::getDataset(const char *loc, double **data, int *num, int *dim)
+{
+    return -1;
+}
+
+
+int VtkReader::getCoordinates(const char *loc, double **coordinates, int *nno, int *nsd)
+{
+    return -1;
+}
+
+int VtkReader::getConnectivity(const char *loc, int **connectivity, int *nel, int *ndofs)
+{
+    return -1;
+}
+
+
+#endif

Modified: cs/cigma/trunk/src/io_vtk_reader.h
===================================================================
--- cs/cigma/trunk/src/io_vtk_reader.h	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_vtk_reader.h	2008-12-10 02:16:40 UTC (rev 13636)
@@ -2,14 +2,20 @@
 #define __CIGMA_VTK_READER_H__
 
 #include "io_file_reader.h"
+#include "io_vtk.h"
+
+#ifdef HAVE_VTK
 #include "vtkDataSetReader.h"
 #include "vtkXMLDataReader.h"
+#endif
 
+
 namespace cigma
 {
     class VtkReader;
 }
 
+
 class cigma::VtkReader : public cigma::FileReader
 {
 public:
@@ -18,22 +24,21 @@
 
     ReaderType getReaderType() { return VTK_FILE_READER; }
 
-    int open(const char *filename);
+    int open(const char *filename, const char *mode);
     int close();
 
     int getDataset(const char *loc, double **data, int *num, int *dim);
     int getCoordinates(const char *loc, double **coordinates, int *nno, int *nsd);
     int getConnectivity(const char *loc, int **connectivity, int *nel, int *ndofs);
 
+#ifdef HAVE_VTK
 public:
-    typedef enum {
-        NULL_GRID, VTK, VTU, VTS, VTR, PVTU, PVTS, PVTR
-    } GridType;
-
-    GridType gridType;
+    vtkGridType gridType;
     vtkDataSetReader *legacy_reader;
     vtkXMLReader *xml_reader;
     vtkDataSet *dataset;
+#endif
 };
 
-#endif
+
+#endif /* __CIGMA_VTK_READER_H__ */

Modified: cs/cigma/trunk/src/io_vtk_writer.cpp
===================================================================
--- cs/cigma/trunk/src/io_vtk_writer.cpp	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_vtk_writer.cpp	2008-12-10 02:16:40 UTC (rev 13636)
@@ -1,12 +1,12 @@
 #include "io_vtk_writer.h"
-#include "Common.h"
+#include "io_vtk.h"
+
 #include <cassert>
 #include <cstdlib>
 
 using namespace std;
 using namespace cigma;
 
-// ----------------------------------------------------------------------------
 
 VtkWriter::VtkWriter()
 {
@@ -18,15 +18,20 @@
     close();
 }
 
-// ----------------------------------------------------------------------------
 
 int VtkWriter::open(const char *filename, const char *mode)
 {
-    fp = fopen(filename, "w");
+    TRI_LOG_STR("VtkWriter::open()");
+    TRI_LOG(filename);
+    TRI_LOG(mode);
+
+    fp = fopen(filename, "w"); // XXX: use mode
+
     if (fp == 0)
     {
         return -1;
     }
+
     this->_writeHeader();
     return 0;
 }
@@ -41,7 +46,6 @@
     return 0;
 }
 
-// ----------------------------------------------------------------------------
 
 void VtkWriter::_writeHeader()
 {
@@ -52,7 +56,7 @@
     fprintf(fp, "DATASET UNSTRUCTURED_GRID\n");
 }
 
-void VtkWriter::_writePoints(double *points, int npts, int ndim)
+void VtkWriter::_writePoints(const double *points, int npts, int ndim)
 {
     assert(fp != 0);
     assert(ndim > 1);
@@ -71,7 +75,7 @@
 
 }
 
-void VtkWriter::_writeCells(int *cells, int nel, int ndofs)
+void VtkWriter::_writeCells(const int *cells, int nel, int ndofs)
 {
     assert(fp != NULL);
 
@@ -124,12 +128,14 @@
     }
 }
 
-void VtkWriter::_writePointData(const char *name, double *data, int nno, int nsd)
+void VtkWriter::_writePointData(const char *name, const double *data, int nno, int nsd)
 {
     assert(fp != NULL);
 
     fprintf(fp, "POINT_DATA %d\n", nno);
 
+    const int ndim = nsd;
+
     if (ndim == 1)
     {
         fprintf(fp, "SCALARS %s double 1\n", name);
@@ -167,12 +173,15 @@
     }
 }
 
-void VtkWriter::_writeCellData(const char *name, double *data, int nel, int ndofs)
+
+void VtkWriter::_writeCellData(const char *name, const double *data, int nel, int ndofs)
 {
     assert(fp != NULL);
 
     fprintf(fp, "CELL_DATA %d\n", nel);
 
+    const int ndim = ndofs;
+
     if (ndim == 1)
     {
         fprintf(fp, "SCALARS %s float 1\n", name);
@@ -208,25 +217,24 @@
 }
 
 
-// ----------------------------------------------------------------------------
-
-int VtkWriter::writeDataset(const char *loc, double *data, int num, int ndim)
+int VtkWriter::writeDataset(const char *loc, const double *data, int num, int ndim)
 {
     TRI_LOG_STR("VtkWriter::writeDataset()");
     return 0;
 }
 
-int VtkWriter::writeCoordinates(const char *loc, double *coordinates, int nno, int nsd)
+
+int VtkWriter::writeCoordinates(const char *loc, const double *coordinates, int nno, int nsd)
 {
     TRI_LOG_STR("VtkWriter::writeCoordinates()");
     return 0;
 }
 
-int VtkWriter::writeConnectivity(const char *loc, int *connectivity, int nel, int ndofs)
+
+int VtkWriter::writeConnectivity(const char *loc, const int *connectivity, int nel, int ndofs)
 {
     TRI_LOG_STR("VtkWriter::writeConnectivity()");
     return 0;
 }
 
 
-// ----------------------------------------------------------------------------

Modified: cs/cigma/trunk/src/io_vtk_writer.h
===================================================================
--- cs/cigma/trunk/src/io_vtk_writer.h	2008-12-10 02:16:38 UTC (rev 13635)
+++ cs/cigma/trunk/src/io_vtk_writer.h	2008-12-10 02:16:40 UTC (rev 13636)
@@ -4,12 +4,13 @@
 #include <cstdio>
 #include "io_file_writer.h"
 
+
 namespace cigma
 {
     class VtkWriter;
 }
 
-class cigma::VtkWriter : public FileWriter
+class cigma::VtkWriter : public cigma::FileWriter
 {
 public:
 
@@ -21,17 +22,18 @@
     int open(const char *filename, const char *mode);
     int close();
 
-    int writeDataset(const char *loc, double *data, int num, int ndim);
-    int writeCoordinates(const char *loc, double *coordinates, int nno, int nsd);
-    int writeConnectivity(const char *loc, int *connectivity, int nel, int ndofs);
+    int writeDataset(const char *loc, const double *data, int num, int ndim);
+    int writeCoordinates(const char *loc, const double *coordinates, int nno, int nsd);
+    int writeConnectivity(const char *loc, const int *connectivity, int nel, int ndofs);
 
 private:
+    /* XXX: turn these methods into functions and move to io_vtk.h */
     void _writeHeader();
-    void _writePoints(double *points, int npts, int ndim);
-    void _writeCells(int *cells, int nel, int ndofs);
+    void _writePoints(const double *points, int npts, int ndim);
+    void _writeCells(const int *cells, int nel, int ndofs);
     void _writeCellTypes(int nsd, int nel, int ndofs);
-    void _writePointData(const char *name, double *data, int nno, int nsd);
-    void _writeCellData(const char *name, double *data, int nel, int ndofs);
+    void _writePointData(const char *name, const double *data, int nno, int nsd);
+    void _writeCellData(const char *name, const double *data, int nel, int ndofs);
 
 public:
     FILE *fp;



More information about the CIG-COMMITS mailing list