[cig-commits] r13900 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Jan 21 11:37:50 PST 2009
Author: luis
Date: 2009-01-21 11:37:50 -0800 (Wed, 21 Jan 2009)
New Revision: 13900
Modified:
cs/cigma/trunk/src/cli_list_cmd.cpp
cs/cigma/trunk/src/core_list_op.cpp
Log:
Extend 'cigma list' command to show us list of registered functions.
Modified: cs/cigma/trunk/src/cli_list_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_list_cmd.cpp 2009-01-21 19:37:47 UTC (rev 13899)
+++ cs/cigma/trunk/src/cli_list_cmd.cpp 2009-01-21 19:37:50 UTC (rev 13900)
@@ -20,9 +20,9 @@
name = "list";
brief = "List file contents (fields, dimensions, ...)";
- usage = "Usage: cigma list <FILE>\n";
+ usage = "Usage: cigma list [ <FILE> | functions | elements ]";
appendix =
- "Supported file extensions:\n"
+ "Only the following file extensions are supported:\n"
" .h5 - Cigma HDF5 file\n"
" .vtk - Legacy VTK file\n"
" .vtu, .vts, .vtr - VTK files\n"
@@ -54,24 +54,28 @@
{
BaseCmd::configure();
- //
- // Validate input data as much as possible, i.e.,
- // - Make sure the file exists.
- // - If so, create the appropriate file object.
- //
if (op.filename != "")
{
- fs::path p(op.filename);
- if (!fs::exists(p))
+ if ((op.filename == "functions") || (op.filename == "elements"))
{
- throw std::invalid_argument(string("The file '")
- .append(op.filename).append("' does not exist!"));
+ return;
}
- if (fs::is_directory(p))
+ else
{
- throw std::invalid_argument(string("Please specify a file, ")
- .append("not a directory (given '")
- .append(op.filename).append("')"));
+ fs::path p(op.filename);
+
+ if (!fs::exists(p))
+ {
+ throw std::invalid_argument(string("The file '")
+ .append(op.filename).append("' does not exist!"));
+ }
+
+ if (fs::is_directory(p))
+ {
+ throw std::invalid_argument(string("Please specify a file, ")
+ .append("not a directory (given '")
+ .append(op.filename).append("')"));
+ }
}
}
}
@@ -82,12 +86,10 @@
if (op.filename == "")
{
- cout << usage;
+ cout << usage << endl;
return 1;
}
- cout << "Reading file '" << op.filename << "'\n";
-
int status = op.run();
return status;
Modified: cs/cigma/trunk/src/core_list_op.cpp
===================================================================
--- cs/cigma/trunk/src/core_list_op.cpp 2009-01-21 19:37:47 UTC (rev 13899)
+++ cs/cigma/trunk/src/core_list_op.cpp 2009-01-21 19:37:50 UTC (rev 13900)
@@ -2,6 +2,7 @@
#include "Common.h"
#include "Filesystem.h"
+#include "FunctionRegistry.h"
#include "io_hdf5_reader.h"
#include "io_exo_reader.h"
#include "io_vtk_reader.h"
@@ -25,6 +26,26 @@
{
}
+static int list_functions()
+{
+ cout << "List of registered functions:" << endl;
+ global_function_registry.listFunctions();
+}
+
+static int list_elements()
+{
+ // XXX: define static method Cell::list_elements()
+ const char *indent = " ";
+ cout << "List of elements available for use in a Field:" << endl;
+ cout << indent << "hex8, hex20, hex27" << endl;
+ cout << indent << "tet4, tet10" << endl;
+ //cout << indent << "prism6, prism15, prism18" << endl;
+ //cout << indent << "pyramid5" << endl;
+ cout << indent << "quad4, quad8, quad9" << endl;
+ cout << indent << "tri3, tri6" << endl;
+ //cout << indent << "edge2, edge3, edge4" << endl;
+}
+
static int list_h5(const char *filename)
{
// XXX: need own list function for HDF5 files
@@ -76,42 +97,53 @@
int ListOp::run()
{
TRI_LOG_STR("ListOp::run()");
-
- fs::path p(filename);
- string ext = fs::extension(p);
- // XXX: Use file magic number instead of extension?
- // Create static methods in each of the respective readers
+ if (filename == "functions")
+ {
+ list_functions();
+ }
+ else if (filename == "elements")
+ {
+ list_elements();
+ }
+ else
+ {
+ // XXX: Use file magic number instead of extension?
+ // Create static methods in each of the respective readers
+ //
+ fs::path p(filename);
+ string ext = fs::extension(p);
- if (fs::exists(p))
- {
- if (is_hdf5_extension(ext.c_str()))
+ if (fs::exists(p))
{
- return list_h5(filename.c_str());
+ if (is_hdf5_extension(ext.c_str()))
+ {
+ return list_h5(filename.c_str());
+ }
+ else if (is_exo_extension(ext.c_str()))
+ {
+ return list_exo(filename.c_str());
+ }
+ else if (is_vtk_extension(ext.c_str()))
+ {
+ return list_vtk(filename.c_str());
+ }
+ else
+ {
+ std::ostringstream stream;
+ stream << "Unsupported file extension "
+ << "(found '" << ext << "')"
+ << std::ends;
+ throw cigma::Exception("ListOp::run", stream.str(), 1);
+ }
}
- else if (is_exo_extension(ext.c_str()))
- {
- return list_exo(filename.c_str());
- }
- else if (is_vtk_extension(ext.c_str()))
- {
- return list_vtk(filename.c_str());
- }
else
{
std::ostringstream stream;
- stream << "Unsupported file extension "
- << "(found '" << ext << "')"
- << std::ends;
- throw cigma::Exception("ListOp::run", stream.str(), 1);
+ stream << "File '" << filename << "' does not exist!" << std::ends;
+ throw cigma::Exception("ListOp::run", stream.str(), 2);
}
}
- else
- {
- std::ostringstream stream;
- stream << "File '" << filename << "' does not exist!" << std::ends;
- throw cigma::Exception("ListOp::run", stream.str(), 2);
- }
return 0;
}
More information about the CIG-COMMITS
mailing list