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

luis at geodynamics.org luis at geodynamics.org
Wed Jan 21 11:37:53 PST 2009


Author: luis
Date: 2009-01-21 11:37:53 -0800 (Wed, 21 Jan 2009)
New Revision: 13902

Modified:
   cs/cigma/trunk/Makefile.am
   cs/cigma/trunk/src/cli_application.cpp
   cs/cigma/trunk/src/cli_info_cmd.cpp
   cs/cigma/trunk/src/cli_list_cmd.cpp
   cs/cigma/trunk/src/core_list_op.cpp
Log:
Restore 'cigma info' command.

In general, we should use 'cigma list' for introspecting data files,
and 'cigma info' for querying information fixed at compile time.

Modified: cs/cigma/trunk/Makefile.am
===================================================================
--- cs/cigma/trunk/Makefile.am	2009-01-21 19:37:51 UTC (rev 13901)
+++ cs/cigma/trunk/Makefile.am	2009-01-21 19:37:53 UTC (rev 13902)
@@ -303,6 +303,8 @@
 	src/cli_base_cmd.cpp \
 	src/cli_list_cmd.h \
 	src/cli_list_cmd.cpp \
+	src/cli_info_cmd.h \
+	src/cli_info_cmd.cpp \
 	src/cli_extract_cmd.h \
 	src/cli_extract_cmd.cpp \
 	src/cli_eval_cmd.h \

Modified: cs/cigma/trunk/src/cli_application.cpp
===================================================================
--- cs/cigma/trunk/src/cli_application.cpp	2009-01-21 19:37:51 UTC (rev 13901)
+++ cs/cigma/trunk/src/cli_application.cpp	2009-01-21 19:37:53 UTC (rev 13902)
@@ -14,10 +14,11 @@
 #include "Exception.h"
 
 /* basic commands */
+#include "cli_compare_cmd.h"
+#include "cli_eval_cmd.h"
+#include "cli_extract_cmd.h"
 #include "cli_list_cmd.h"
-#include "cli_extract_cmd.h"
-#include "cli_eval_cmd.h"
-#include "cli_compare_cmd.h"
+#include "cli_info_cmd.h"
 
 using namespace std;
 using namespace cigma;
@@ -27,10 +28,11 @@
 Application::Application()
 {
     /* Initialize the basic set of commands */
-    addCommand(new CompareCmd());
-    addCommand(new EvalCmd());
-    addCommand(new ExtractCmd());
-    addCommand(new ListCmd());
+    this->addCommand(new CompareCmd());
+    this->addCommand(new EvalCmd());
+    this->addCommand(new ExtractCmd());
+    this->addCommand(new ListCmd());
+    this->addCommand(new InfoCmd());
 }
 
 

Modified: cs/cigma/trunk/src/cli_info_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_info_cmd.cpp	2009-01-21 19:37:51 UTC (rev 13901)
+++ cs/cigma/trunk/src/cli_info_cmd.cpp	2009-01-21 19:37:53 UTC (rev 13902)
@@ -1,15 +1,59 @@
+#include "cli_info_cmd.h"
+#include "FunctionRegistry.h"
 #include <iostream>
-using namespace std;
 
-#include "cli_info_cmd.h"
 using namespace cigma;
+using namespace std;
 
+namespace po = boost::program_options;
 
 // ----------------------------------------------------------------------------
 
+static int info_on_functions()
+{
+    cout << "List of registered functions:" << endl;
+    global_function_registry.listFunctions();
+    return 0;
+}
+
+static int info_on_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;
+    return 0;
+}
+
+static int info_on_quadratures()
+{
+    // XXX: what should we display here?
+    // default quadrature orders on each element?
+    // perhaps that should go in the info section on the specific
+    return 0;
+}
+
+static int info(const string& obj)
+{
+    // XXX: first, assume it's a registered function,
+    // XXX: else look in list of elements
+    return 1;
+}
+
+// ----------------------------------------------------------------------------
+
 InfoCmd::InfoCmd()
 {
     name = "info";
+    brief = "Information on functions, elements, quadratures.";
+    usage = "Usage: cigma info [ functions | elements | <ObjectToQuery> ]";
+    appendix = "";
 }
 
 InfoCmd::~InfoCmd()
@@ -20,20 +64,50 @@
 
 void InfoCmd::defineOptions()
 {
+    BaseCmd::defineOptions();
 
+    opts_section = "Info Options: ";
+
+    opts.add_options()
+        ("query", po::value<string>(&objpath), "Object to query")
+        ;
+
+    args.add("query", -1);
 }
 
 void InfoCmd::configure()
 {
+    BaseCmd::configure();
 }
 
 int InfoCmd::run()
 {
-    cout << "Calling InfoCmd::run()" << endl;
-    //
-    // 'cigma info functions' should list the available functions
-    // 'cigma info mesh <MESH>' should give statistics about the mesh
-    //
+    BaseCmd::run();
+
+    if (objpath == "")
+    {
+        printUsage();
+    }
+    else if (objpath == "functions")
+    {
+        info_on_functions();
+    }
+    else if (objpath == "elements")
+    {
+        info_on_elements();
+    }
+    else
+    {
+        int ret = info(objpath);
+
+        if (ret != 0)
+        {
+            cout << "No information on '" << objpath << "'" << endl;
+            return 1;
+        }
+    }
+
+    return 0;
 }
 
 // ----------------------------------------------------------------------------

Modified: cs/cigma/trunk/src/cli_list_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_list_cmd.cpp	2009-01-21 19:37:51 UTC (rev 13901)
+++ cs/cigma/trunk/src/cli_list_cmd.cpp	2009-01-21 19:37:53 UTC (rev 13902)
@@ -20,7 +20,7 @@
     name = "list";
     brief = "List file contents (fields, dimensions, ...)";
 
-    usage = "Usage: cigma list [ <FILE> | functions | elements ]";
+    usage = "Usage: cigma list <FILE>";
     appendix =
         "Only the following file extensions are supported:\n"
         "   .h5                 - Cigma HDF5 file\n"
@@ -56,26 +56,19 @@
 
     if (op.filename != "")
     {
-        if ((op.filename == "functions") || (op.filename == "elements"))
+        fs::path p(op.filename);
+
+        if (!fs::exists(p))
         {
-            return;
+            throw std::invalid_argument(string("The file '")
+                    .append(op.filename).append("' does not exist!"));
         }
-        else
-        {
-            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("')"));
-            }
+        if (fs::is_directory(p))
+        {
+            throw std::invalid_argument(string("Please specify a file, ")
+                    .append("not a directory (given '")
+                    .append(op.filename).append("')"));
         }
     }
 }

Modified: cs/cigma/trunk/src/core_list_op.cpp
===================================================================
--- cs/cigma/trunk/src/core_list_op.cpp	2009-01-21 19:37:51 UTC (rev 13901)
+++ cs/cigma/trunk/src/core_list_op.cpp	2009-01-21 19:37:53 UTC (rev 13902)
@@ -2,7 +2,6 @@
 #include "Common.h"
 #include "Filesystem.h"
 
-#include "FunctionRegistry.h"
 #include "io_hdf5_reader.h"
 #include "io_exo_reader.h"
 #include "io_vtk_reader.h"
@@ -26,39 +25,25 @@
 {
 }
 
-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)
 {
+    assert(filename != 0);
+
     // XXX: need own list function for HDF5 files
     //return hdf5_print_contents(filename);
     
     // XXX: for now, defer work to /usr/bin/h5ls
-    assert(filename != 0);
     string cmd = string("h5ls -r ").append(filename);
+
+    cout << "Running '" << cmd << "'" << endl;
+
     int ret = system(cmd.c_str());
+    
     if (ret < 0)
     {
         cerr << "Error: Could not find h5ls in your PATH" << endl;
     }
+    
     return ret;
 }
 
@@ -69,17 +54,23 @@
 
 static int list_exo(const char *filename)
 {
+    assert(filename != 0);
+
     // XXX: need own list function for exodus files
     //return exo_print_contents(filename);
 
     // XXX: for now, defer work to /usr/bin/ncdump
-    assert(filename != 0);
     string cmd = string("ncdump -h ").append(filename);
+
+    cout << "Running '" << cmd << "'" << endl;
+
     int ret = system(cmd.c_str());
+
     if (ret < 0)
     {
         cerr << "Error: Could not find ncdump in your PATH" << endl;
     }
+
     return ret;
 }
 
@@ -98,52 +89,41 @@
 {
     TRI_LOG_STR("ListOp::run()");
     
-    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);
+    // 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 (fs::exists(p))
+    {
+        if (is_hdf5_extension(ext.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);
-            }
+            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 << "File '" << filename << "' does not exist!" << std::ends;
-            throw cigma::Exception("ListOp::run", stream.str(), 2);
+            stream << "Unsupported file extension "
+                   << "(found '" << ext << "')"
+                   << std::ends;
+            throw cigma::Exception("ListOp::run", stream.str(), 1);
         }
     }
+    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