// $Id$
// Version: $Name$
//
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
class GridIn
{
public:
+ /**
+ * List of possible mesh input
+ * formats. These values are used
+ * when calling the function
+ * read() in order to determine
+ * the actual reader to be
+ * called.
+ */
+ enum Format
+ {
+ /// Use #default_format stored in this object
+ Default,
+ /// Use read_ucd()
+ ucd,
+ /// Use read_dbmesh()
+ dbmesh,
+ /// Use read_xda()
+ xda,
+ /// Use read_msh()
+ msh
+ };
+
/**
* Constructor.
*/
*/
void attach_triangulation (Triangulation<dim> &tria);
+ /**
+ * Read from the given stream. If
+ * no format is given, the
+ * #default_format variable is
+ * used.
+ */
+ void read (std::istream &, Format format=Default);
+
+ /**
+ * Open the file given by the
+ * string and call the previous
+ * function read().
+ */
+ void read (const std::string&, Format format=Default);
+
/**
* Read grid data from an ucd file.
* Numerical data is ignored.
* Read grid data from an msh file.
*/
void read_msh (std::istream &);
+
+ /**
+ * Returns the standard suffix
+ * for a file in this format.
+ */
+ static std::string default_suffix (const Format format);
+
+ /**
+ * Return the enum Format for the
+ * format name.
+ */
+ static Format parse_format (const std::string &format_name);
+
+ /**
+ * Return a list of implemented input
+ * formats. The different names are
+ * separated by vertical bar signs (<tt>`|'</tt>)
+ * as used by the ParameterHandler
+ * classes.
+ */
+ static std::string get_format_names ();
/**
* Exception
static void debug_output_grid (const std::vector<CellData<dim> > &cells,
const std::vector<Point<dim> > &vertices,
std::ostream &out);
+
+ /**
+ * Input format used by read() if
+ * no format is given.
+ */
+ Format default_format;
};
// $Id$
// Version: $Name$
//
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
#include <map>
#include <algorithm>
-
+#include <fstream>
template <int dim>
GridIn<dim>::GridIn () :
- tria(0) {}
+ tria(0), default_format(ucd)
+{}
template <int dim>
#endif
+template <int dim>
+void GridIn<dim>::read (const std::string& filename,
+ Format format)
+{
+ std::ifstream in(filename.c_str());
+
+ Assert (in.is_open(), ExcFileNotOpen(filename.c_str()));
+
+ if (!in)
+ {
+ std::ios_base::iostate state = in.rdstate();
+ std::cerr << "File open, but error " << state << std::endl;
+ exit(1);
+ }
+
+ read(in, format);
+ in.close();
+}
+
+
+template <int dim>
+void GridIn<dim>::read (std::istream& in,
+ Format format)
+{
+ if (format == Default)
+ format = default_format;
+
+ switch (format)
+ {
+ case dbmesh:
+ read_dbmesh (in);
+ return;
+
+ case msh:
+ read_msh (in);
+ return;
+
+ case ucd:
+ read_ucd (in);
+ return;
+
+ case xda:
+ read_xda (in);
+ return;
+
+ case Default:
+ break;
+ }
+ Assert (false, ExcInternalError());
+}
+
+
+
+template <int dim>
+std::string
+GridIn<dim>::default_suffix (const Format format)
+{
+ switch (format)
+ {
+ case dbmesh:
+ return ".dbmesh";
+ case msh:
+ return ".msh";
+ case ucd:
+ return ".inp";
+ case xda:
+ return ".xda";
+ default:
+ Assert (false, ExcNotImplemented());
+ return ".unknown_format";
+ }
+}
+
+
+
+template <int dim>
+typename GridIn<dim>::Format
+GridIn<dim>::parse_format (const std::string &format_name)
+{
+ if (format_name == "dbmesh")
+ return dbmesh;
+
+ if (format_name == "msh")
+ return msh;
+
+ if (format_name == "ucd")
+ return ucd;
+
+ if (format_name == "xda")
+ return xda;
+
+ AssertThrow (false, ExcInvalidState ());
+ // return something weird
+ return Format(Default);
+}
+
+
+
+template <int dim>
+std::string GridIn<dim>::get_format_names ()
+{
+ return "dbmesh|msh|ucd|xda";
+}
+
//explicit instantiations