~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to dolfin/io/OctaveFile.cpp

  • Committer: Kent-Andre Mardal
  • Date: 2008-04-03 11:30:39 UTC
  • mfrom: (2482.1.3 trunk)
  • Revision ID: kent-and@simula.no-20080403113039-p859iv2wsv8seiyp
updated io to require GenericMatrix

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
#include <dolfin/log/dolfin_log.h>
14
14
#include <dolfin/common/Array.h>
15
 
#include <dolfin/la/Vector.h>
16
 
#include <dolfin/la/Matrix.h>
 
15
#include <dolfin/la/GenericVector.h>
 
16
#include <dolfin/la/GenericMatrix.h>
17
17
#include "MatlabFile.h"
18
18
#include "OctaveFile.h"
19
19
 
30
30
  // Do nothing
31
31
}
32
32
//-----------------------------------------------------------------------------
33
 
void OctaveFile::operator<<(Matrix& A)
 
33
void OctaveFile::operator<<(GenericMatrix& A)
34
34
{
35
35
  // Octave file format for Matrix is not the same as the Matlab format,
36
36
  // since octave cannot handle sparse matrices.
40
40
  real* row = new real[N];
41
41
  
42
42
  FILE *fp = fopen(filename.c_str(), "a");
43
 
  fprintf(fp, "%s = zeros(%u, %u);\n", A.name().c_str(), M, N);
 
43
//  fprintf(fp, "%s = zeros(%u, %u);\n", A.name().c_str(), M, N);
 
44
  fprintf(fp, "A = zeros(%u, %u);\n", M, N);
44
45
  
45
46
  for (uint i = 0; i < M; i++)
46
47
  {
52
53
 
53
54
    // Write nonzero entries
54
55
    for (int pos = 0; pos < ncols; pos++)
55
 
      fprintf(fp, "%s(%d, %d) = %.16e;\n",
56
 
              A.name().c_str(), (int)i + 1, columns[pos] + 1, values[pos]);
 
56
//      fprintf(fp, "%s(%d, %d) = %.16e;\n",
 
57
      fprintf(fp, "A(%d, %d) = %.16e;\n", (int)i + 1, columns[pos] + 1, values[pos]);
57
58
  }
58
59
  
59
60
  fclose(fp);
60
61
  delete [] row;
61
62
  
62
 
  message(1, "Saved matrix %s (%s) to file %s in Octave format.",
63
 
          A.name().c_str(), A.label().c_str(), filename.c_str());
 
63
//  message(1, "Saved matrix %s (%s) to file %s in Octave format.",
 
64
//          A.name().c_str(), A.label().c_str(), filename.c_str());
 
65
 
 
66
  message(1, "Saved matrix to file %s in Octave format.", filename.c_str());
64
67
}
65
68
//-----------------------------------------------------------------------------