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

luis at geodynamics.org luis at geodynamics.org
Wed Feb 13 10:28:36 PST 2008


Author: luis
Date: 2008-02-13 10:28:36 -0800 (Wed, 13 Feb 2008)
New Revision: 9310

Modified:
   cs/benchmark/cigma/trunk/src/TextReader.cpp
   cs/benchmark/cigma/trunk/src/TextReader.h
Log:
Changed behavior of TextReader
 * TextReader::open() determines only the default file pointer
 * TextReader::get_*() no longer ignore their loc argument


Modified: cs/benchmark/cigma/trunk/src/TextReader.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/TextReader.cpp	2008-02-13 18:28:34 UTC (rev 9309)
+++ cs/benchmark/cigma/trunk/src/TextReader.cpp	2008-02-13 18:28:36 UTC (rev 9310)
@@ -1,6 +1,7 @@
 #include "TextReader.h"
 #include <cassert>
 #include <cstdlib>
+#include <cstring>
 
 // ---------------------------------------------------------------------------
 cigma::TextReader::TextReader()
@@ -16,9 +17,20 @@
 // ---------------------------------------------------------------------------
 int cigma::TextReader::open(std::string filename)
 {
-    fp = fopen(filename.c_str(), "r");
-    assert(fp != NULL);
-    return 0; // XXX: change return value instead of using assert
+    fp = NULL;
+
+    if (filename != "")
+    {
+        fp = fopen(filename.c_str(), "r");
+    }
+
+    // check for failure
+    if (fp == NULL)
+    {
+        return -1;
+    }
+    
+    return 0;
 }
 
 void cigma::TextReader::close()
@@ -32,6 +44,16 @@
 
 // ---------------------------------------------------------------------------
 
+static FILE *get_fp(const char *loc, FILE *default_fp)
+{
+    FILE *fp = default_fp;
+    if ((loc != NULL) && (strcmp(loc, "") != 0))
+    {
+        fp = fopen(loc, "r");
+    }
+    return fp;
+}
+
 static bool read_dmat(FILE *fp, double **mat, int *rows, int *cols)
 {
     assert(fp != NULL);
@@ -100,21 +122,32 @@
     return true;
 }
 
+
 // ---------------------------------------------------------------------------
 
 void cigma::TextReader::get_dataset(const char *loc, double **data, int *num, int *dim)
 {
-    read_dmat(fp, data, num, dim);
+    FILE *loc_fp = get_fp(loc, fp);
+    assert(loc_fp != NULL);
+    read_dmat(loc_fp, data, num, dim);
 }
 
 void cigma::TextReader::get_connectivity(const char *loc, int **connectivity, int *nel, int *ndofs)
 {
-    read_imat(fp, connectivity, nel, ndofs);
+    // XXX: add support for sections (c.f. gmsh format) so we can scan a single file
+    // for now, interpret loc argument to be an entirely new file
+    FILE *loc_fp = get_fp(loc, fp);
+    assert(loc_fp != NULL);
+    read_imat(loc_fp, connectivity, nel, ndofs);
 }
 
 void cigma::TextReader::get_coordinates(const char *loc, double **coordinates, int *nno, int *nsd)
 {
-    read_dmat(fp, coordinates, nno, nsd);
+    // XXX: add support for sections (c.f. gmsh format) so we can scan a single file
+    // for now, interpret loc argument to be an entirely new file
+    FILE *loc_fp = get_fp(loc, fp);
+    assert(loc_fp != NULL);
+    read_dmat(loc_fp, coordinates, nno, nsd);
 }
 
 

Modified: cs/benchmark/cigma/trunk/src/TextReader.h
===================================================================
--- cs/benchmark/cigma/trunk/src/TextReader.h	2008-02-13 18:28:34 UTC (rev 9309)
+++ cs/benchmark/cigma/trunk/src/TextReader.h	2008-02-13 18:28:36 UTC (rev 9310)
@@ -30,7 +30,7 @@
     void get_connectivity(const char *loc, int **connectivity, int *nel, int *ndofs);
 
 public:
-    FILE *fp;
+    FILE *fp;   // default file pointer
 };
 
 // ---------------------------------------------------------------------------



More information about the cig-commits mailing list