[cig-commits] r11726 - cs/benchmark/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Wed Apr 2 11:01:47 PDT 2008


Author: luis
Date: 2008-04-02 11:01:47 -0700 (Wed, 02 Apr 2008)
New Revision: 11726

Added:
   cs/benchmark/cigma/trunk/src/InfoCmd.cpp
   cs/benchmark/cigma/trunk/src/InfoCmd.h
Log:
Added InfoCmd as an aid for debugging


Added: cs/benchmark/cigma/trunk/src/InfoCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/InfoCmd.cpp	                        (rev 0)
+++ cs/benchmark/cigma/trunk/src/InfoCmd.cpp	2008-04-02 18:01:47 UTC (rev 11726)
@@ -0,0 +1,124 @@
+#include <string>
+#include <iostream>
+#include <cstdlib>
+#include <cassert>
+#include "InfoCmd.h"
+
+using namespace std;
+using namespace cigma;
+
+// ---------------------------------------------------------------------------
+
+InfoCmd::InfoCmd()
+{
+    name = "info";
+}
+
+InfoCmd::~InfoCmd()
+{
+}
+
+
+// ---------------------------------------------------------------------------
+
+void InfoCmd::setupOptions(AnyOption *opt)
+{
+    /* setup usage */
+    opt->addUsage("Usage:");
+    opt->addUsage("   cigma info [options]");
+    opt->addUsage("     --mesh      Path to mesh");
+    opt->addUsage("     --field     Path to field data");
+    opt->addUsage("     --output    Output file name");
+    
+    /* setup flags and options */
+    opt->setFlag("help",'h');
+    
+    opt->setOption("mesh");
+    opt->setOption("mesh-coordinates");
+    opt->setOption("mesh-connectivity");
+    opt->setOption("output",'o');
+}
+
+void InfoCmd::configure(AnyOption *opt)
+{
+    char *in;
+    string inputstr;
+
+    /* Determine the --output option */
+    in = opt->getValue("output");
+    if (in == 0)
+    {
+        cerr << "info: Please specify an output file" << endl;
+        exit(1);
+    }
+    outputFilename = in;
+
+    /* Load mesh */
+    if (opt->getValue("mesh") != 0)
+    {
+        meshPartReader.load_args(opt, "mesh");
+        meshPartReader.validate_args("info");
+        meshPartReader.load_mesh();
+        meshPart = meshPartReader.meshPart;
+        if (meshPart == 0)
+        {
+            cerr << "info: Could not load mesh." << endl;
+            exit(1);
+        }
+        meshPart->set_cell();
+    }
+
+    /* Load field */
+    if (opt->getValue("field") != 0)
+    {
+        fieldReader.load_args(opt, "field");
+        fieldReader.validate_args("info");
+        fieldReader.load_field();
+        field = fieldReader.field;
+        if (field == 0)
+        {
+            cerr << "info: Could not load field." << endl;
+            exit(1);
+        }
+    }
+}
+
+// ---------------------------------------------------------------------------
+
+
+int InfoCmd::run()
+{
+    int e;
+    int nel = meshPart->nel;
+    double *vols = 0; // XXX: use auto_ptr?
+    int status;
+
+    cout << "Creating file " << outputFilename << endl;
+    status = hdfWriter.open(outputFilename.c_str());
+    if (status < 0)
+    {
+        cerr << "info: Could not create " << outputFilename << endl;
+        exit(1);
+    }
+
+
+    vols = new double[nel];
+    for (e = 0; e < nel; e++)
+    {
+        meshPart->select_cell(e);
+        vols[e] = meshPart->cell->volume();
+    }
+    status = hdfWriter.write_dataset("/volume", vols, nel, 1);
+    if (status < 0)
+    {
+        cerr << "info: Could not write /volume dataset" << endl;
+        exit(1);
+    }
+
+    status = hdfWriter.close();
+    delete [] vols;
+
+    return 0;
+}
+
+// ---------------------------------------------------------------------------

Added: cs/benchmark/cigma/trunk/src/InfoCmd.h
===================================================================
--- cs/benchmark/cigma/trunk/src/InfoCmd.h	                        (rev 0)
+++ cs/benchmark/cigma/trunk/src/InfoCmd.h	2008-04-02 18:01:47 UTC (rev 11726)
@@ -0,0 +1,41 @@
+#ifndef __INFO_CMD_H__
+#define __INFO_CMD_H__
+
+#include <string>
+#include "Command.h"
+#include "MeshPart.h"
+#include "MeshPartReader.h"
+#include "Field.h"
+#include "FieldReader.h"
+#include "HdfWriter.h"
+
+namespace cigma
+{
+    class InfoCmd;
+}
+
+class cigma::InfoCmd : public Command
+{
+public:
+    InfoCmd();
+    ~InfoCmd();
+
+public:
+    void setupOptions(AnyOption *opt);
+    void configure(AnyOption *opt);
+    int run();
+
+public:
+    std::string outputFilename;
+
+public:
+    FieldReader fieldReader;
+    MeshPartReader meshPartReader;
+    HdfWriter hdfWriter;
+
+public:
+    Field *field;
+    MeshPart *meshPart;
+};
+
+#endif



More information about the cig-commits mailing list