[cig-commits] r11416 - cs/benchmark/cigma/trunk/scratch/utils
luis at geodynamics.org
luis at geodynamics.org
Wed Mar 12 11:03:08 PDT 2008
Author: luis
Date: 2008-03-12 11:03:08 -0700 (Wed, 12 Mar 2008)
New Revision: 11416
Added:
cs/benchmark/cigma/trunk/scratch/utils/freeze.py
cs/benchmark/cigma/trunk/scratch/utils/rebuild.sh
cs/benchmark/cigma/trunk/scratch/utils/vtkls.cpp
Log:
Trying again: Moving utils on local repository instead
Added: cs/benchmark/cigma/trunk/scratch/utils/freeze.py
===================================================================
--- cs/benchmark/cigma/trunk/scratch/utils/freeze.py (rev 0)
+++ cs/benchmark/cigma/trunk/scratch/utils/freeze.py 2008-03-12 18:03:08 UTC (rev 11416)
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+"""freeze.py
+
+This script will store the contents of a given file inside a
+C/C++ string literal.
+"""
+
+import sys
+
+def quote(s):
+ r = repr(s)
+ if len(r) > 2:
+ a,b = r[0],r[-1]
+ r = r[1:-1]
+ r = r.replace(r'\\','\\')
+ if a == b == "'":
+ r = r.replace(r"\'","'")
+ r = r.replace('"',r'\"')
+ elif a == b == '"':
+ r = r.replace(r'\"','"')
+ else:
+ raise Exception("Bad repr()?")
+ return r
+ return ''
+
+def escape(s):
+ return '"' + quote(s) + '"'
+
+def freeze(filename, varname="foobar"):
+ fp = open(filename, "" + 'r')
+
+ prefix = " "
+ print "const char %s[] = \\" % varname
+ for line in fp:
+ line2 = prefix + escape(line)
+ #print line2 + " <-- " + repr(line)
+ print line2
+ print prefix + '"";'
+ fp.close()
+
+
+def main(argv=None):
+ if argv == None:
+ argv = sys.argv[1:]
+ if len(argv) == 0:
+ return 1
+ elif len(argv) == 1:
+ freeze(filename=argv[0])
+ return 0
+ elif len(argv) >= 2:
+ freeze(filename=argv[0],
+ varname=argv[1])
+ return 0
+ else:
+ return 2
+
+if __name__ == "__main__":
+ sys.exit(main())
Property changes on: cs/benchmark/cigma/trunk/scratch/utils/freeze.py
___________________________________________________________________
Name: svn:executable
+ *
Added: cs/benchmark/cigma/trunk/scratch/utils/rebuild.sh
===================================================================
--- cs/benchmark/cigma/trunk/scratch/utils/rebuild.sh (rev 0)
+++ cs/benchmark/cigma/trunk/scratch/utils/rebuild.sh 2008-03-12 18:03:08 UTC (rev 11416)
@@ -0,0 +1,8 @@
+#!/bin/bash -v
+cd .. && make dist && cd - && \
+rm -rf cigma-0.9.1 && \
+tar xvzf cigma-0.9.1.tar.gz && \
+cd cigma-0.9.1 && \
+./configure --prefix=$HOME/cigma/build/cigma-0.9.1/opt \
+ --with-hdf5=$HOME/opt/hdf5/1.6.5 && \
+make && make install
Property changes on: cs/benchmark/cigma/trunk/scratch/utils/rebuild.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: cs/benchmark/cigma/trunk/scratch/utils/vtkls.cpp
===================================================================
--- cs/benchmark/cigma/trunk/scratch/utils/vtkls.cpp (rev 0)
+++ cs/benchmark/cigma/trunk/scratch/utils/vtkls.cpp 2008-03-12 18:03:08 UTC (rev 11416)
@@ -0,0 +1,321 @@
+#include <iostream>
+#include <cstdlib>
+#include <cassert>
+
+#include "AnyOption.h"
+
+#include <vtkDataSetReader.h>
+#include <vtkDataSet.h>
+#include <vtkPointData.h>
+#include <vtkCellData.h>
+
+#include <vtkDataArray.h>
+
+using namespace std;
+
+
+typedef enum {
+ VTK_FILE_NONE,
+ VTK_FILE_POLYDATA,
+ VTK_FILE_STRUCTURED_POINTS,
+ VTK_FILE_STRUCTURED_GRID,
+ VTK_FILE_UNSTRUCTURED_GRID,
+ VTK_FILE_RECTILINEAR_GRID
+} VtkFileType;
+
+VtkFileType getFileType(vtkDataSetReader *reader)
+{
+ // XXX: are these mutually exclusive?
+ if (reader->IsFilePolyData())
+ return VTK_FILE_POLYDATA;
+ if (reader->IsFileStructuredPoints())
+ return VTK_FILE_STRUCTURED_POINTS;
+ if (reader->IsFileStructuredGrid())
+ return VTK_FILE_STRUCTURED_GRID;
+ if (reader->IsFileUnstructuredGrid())
+ return VTK_FILE_UNSTRUCTURED_GRID;
+ if (reader->IsFileRectilinearGrid())
+ return VTK_FILE_RECTILINEAR_GRID;
+ return VTK_FILE_NONE;
+}
+
+const char *getFileTypeName(VtkFileType fileType)
+{
+ if (fileType == VTK_FILE_POLYDATA)
+ return "polydata";
+ if (fileType == VTK_FILE_STRUCTURED_POINTS)
+ return "structured points";
+ if (fileType == VTK_FILE_STRUCTURED_GRID)
+ return "structured grid";
+ if (fileType == VTK_FILE_UNSTRUCTURED_GRID)
+ return "unstructured grid";
+ if (fileType == VTK_FILE_RECTILINEAR_GRID)
+ return "rectilinear grid";
+ return "";
+}
+
+
+
+// ---------------------------------------------------------------------------
+int main(int argc, char *argv[])
+{
+ bool verbose = false;
+ bool by_class = false;
+ bool by_arrays = true;
+
+ int i,n;
+
+ // ------------------------------------------------------
+ /*
+ if (argc != 2)
+ {
+ cerr << "Usage: " << argv[0] << " " << "file.vtk" << endl;
+ exit(1);
+ }
+ // */
+
+ // ------------------------------------------------------
+
+ AnyOption *opt = new AnyOption();
+
+ opt->addUsage("Usage: vtkls file.vtk");
+
+ opt->setFlag("help", 'h');
+ opt->setFlag("verbose", 'v');
+ opt->setFlag('c'); // sort by class
+ opt->setFlag('a'); // sort by array
+
+ opt->processCommandArgs(argc, argv);
+
+ if (!opt->hasOptions())
+ {
+ opt->printUsage();
+ delete opt;
+ exit(1);
+ }
+
+ if (opt->getFlag("help"))
+ {
+ opt->printUsage();
+ delete opt;
+ exit(0);
+ }
+
+ if (opt->getFlag("verbose"))
+ {
+ verbose = true;
+ }
+
+ if (opt->getFlag('c') && !opt->getFlag('a'))
+ {
+ by_class = true;
+ by_arrays = false;
+ }
+ if (opt->getFlag('a') && !opt->getFlag('c'))
+ {
+ by_arrays = true;
+ by_class = false;
+ }
+ int nargs = opt->getArgc();
+ if (nargs != 1)
+ {
+ opt->printUsage();
+ delete opt;
+ exit(1);
+ }
+ char *filename = opt->getArgv(0);
+
+
+ // ------------------------------------------------------
+ //
+ // Assuming legacy format
+ //
+ if (verbose)
+ {
+ cout << "<< Creating vtkDataSetReader" << endl;
+ }
+ vtkDataSetReader *reader = vtkDataSetReader::New();
+ reader->SetFileName(filename);
+ cout << "Reading " << filename << endl;
+
+ int ierr;
+ ierr = reader->OpenVTKFile(); // does file exist?
+ if (ierr == 0)
+ {
+ cerr << "vtkls: Could not open " << filename << endl;
+ exit(1);
+ }
+
+ ierr = reader->ReadHeader(); // is the vtk header present?
+ if (ierr == 0)
+ {
+ cerr << "vtkls: Unrecognized file " << filename << endl;
+ exit(1);
+ }
+
+ /* // Determine type of file (direct method)
+ bool is_pd = reader->IsFilePolyData();
+ cout << "Is file poly data? " << is_pd << endl;
+ bool is_sp = reader->IsFileStructuredPoints();
+ cout << "Is file structured points? " << is_sp << endl;
+ bool is_sg = reader->IsFileStructuredGrid();
+ cout << "Is file structured grid? " << is_sg << endl;
+ bool is_ug = reader->IsFileUnstructuredGrid();
+ cout << "Is file unstructured grid? " << is_ug << endl;
+ bool is_rg = reader->IsFileRectilinearGrid();
+ cout << "Is file rectilinear grid? " << is_rg << endl;
+ bool is_valid = is_pd || is_sp || is_sg || is_ug || is_rg;
+ assert(is_valid); // */
+
+ /* // Determine type of file (second method)
+ VtkFileType fileType = getFileType(reader);
+ const char *fileTypeName = getFileTypeName(fileType);
+ cout << "Detected " << fileTypeName << " file" << endl;
+ // */
+
+
+
+ // ------------------------------------------------------
+
+ reader->Update();
+ //reader->PrintSelf(cout, 0);
+
+ if (verbose)
+ {
+ cout << "<< Creating vtkDataSet" << endl;
+ }
+ vtkDataSet *dataset = reader->GetOutput();
+ //dataset->PrintSelf(cout, 0);
+
+ if (verbose)
+ {
+ cout << "<< Creating vtkPointData" << endl;
+ }
+ vtkPointData *pointData = dataset->GetPointData();
+ //pointData->PrintSelf(cout, 0);
+
+ if (verbose)
+ {
+ cout << "<< Creating vtkCellData" << endl;
+ }
+ vtkCellData *cellData = dataset->GetCellData();
+ //cellData->PrintSelf(cout, 0);
+
+
+ // ------------------------------------------------------
+ int nno,nel;
+
+ nno = dataset->GetNumberOfPoints();
+ if (nno > 0)
+ {
+ cout << "Points = " << nno << endl;
+ }
+
+ nel = dataset->GetNumberOfCells();
+ if (nel > 0)
+ {
+ cout << "Cells = " << nel << endl;
+ }
+
+
+ // ------------------------------------------------------
+ int numArrays;
+ int numTuples, numComponents;
+
+ if (by_arrays)
+ {
+ //*
+ numArrays = pointData->GetNumberOfArrays();
+ if (numArrays > 0)
+ {
+ //cout << "PointData" << endl;
+ //cout << "\tNumber of arrays = " << numArrays << endl;
+ for (i = 0; i < numArrays; i++)
+ {
+ vtkDataArray *dataArray = pointData->GetArray(i);
+ const char *name = pointData->GetArrayName(i);
+ numTuples = dataArray->GetNumberOfTuples();
+ numComponents = dataArray->GetNumberOfComponents();
+ cout << "PointDataArray[" << i << "] = " << name;
+ //cout << " " << dataArray->GetClassName();
+ cout << " " << "(" << numTuples << " x " << numComponents << ")";
+ cout << endl;
+ }
+ }
+
+ numArrays = cellData->GetNumberOfArrays();
+ if (numArrays > 0)
+ {
+ //cout << "CellData" << endl;
+ //cout << "\tNumber of arrays = " << numArrays << endl;
+ for (i = 0; i < numArrays; i++)
+ {
+ vtkDataArray *dataArray = cellData->GetArray(i);
+ const char *name = cellData->GetArrayName(i);
+ numTuples = dataArray->GetNumberOfTuples();
+ numComponents = dataArray->GetNumberOfComponents();
+ cout << "CellDataArray[" << i << "] = " << name;
+ //cout << " " << dataArray->GetClassName();
+ cout << " " << "(" << numTuples << " x " << numComponents << ")";
+ cout << endl;
+ }
+ }
+ // */
+ }
+
+
+
+
+ // ------------------------------------------------------
+
+ if (by_class)
+ {
+ //*
+ n = reader->GetNumberOfFieldDataInFile();
+ //cout << "Number of field data = " << n << endl;
+ for (i = 0; i < n; i++)
+ {
+ const char *name = reader->GetFieldDataNameInFile(i);
+ cout << "FieldData[" << i << "] = " << name;
+ cout << endl;
+ }
+
+ n = reader->GetNumberOfScalarsInFile();
+ //cout << "Number of scalars = " << n << endl;
+ for (i = 0; i < n; i++)
+ {
+ const char *name = reader->GetScalarsNameInFile(i);
+ cout << "Scalars[" << i << "] = " << name;
+ cout << endl;
+ }
+
+ n = reader->GetNumberOfVectorsInFile();
+ //cout << "Number of vectors = " << n << endl;
+ for (i = 0; i < n; i++)
+ {
+ const char *name = reader->GetVectorsNameInFile(i);
+ cout << "Vectors[" << i << "] = " << name;
+ cout << endl;
+ }
+
+ n = reader->GetNumberOfTensorsInFile();
+ //cout << "Number of tensors = " << n << endl;
+ for (i = 0; i < n; i++)
+ {
+ const char *name = reader->GetTensorsNameInFile(i);
+ cout << "Tensors[" << i << "] = " << name;
+ cout << endl;
+ }
+ // */
+ }
+
+
+
+ // ------------------------------------------------------
+ // Sleep for a bit so we can examine memory usage with htop
+ //cout << "<< Sleeping..." << endl;
+ //sleep(100);
+
+ delete opt;
+ return 0;
+}
More information about the cig-commits
mailing list