[GiNaC-list] Store matrix, then read it?
Cristobal Navarro
axischire at gmail.com
Wed Jul 7 03:05:06 CEST 2010
Hello,
i am experiencing a little trouble when reading my stored matrix.
when i write and read the same matrix i stored, it works.
but if i only run the program to read the matrix file, i get this error.
terminate called after throwing an instance of 'std::runtime_error'
what(): unknown matrix dimensions in archive
This is a one-file example source code i made for you guys so you can test,
its based on the same problem i have on my bigger code.
try running it as it is, then comment the "write" method and run it again so
it only reads the matrices, youll get the error eventually. but you will
never get it if you write and read, its weird.
how can this be solved?
//CODE
#include <fstream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
symbol q("q"),v("v");
void read( string filename, GiNaC::matrix* qvCol, GiNaC::matrix* qvMat );
void write( string filename, GiNaC::matrix qvCol, GiNaC::matrix qvMat );
int main(int argc, char** argv){
GiNaC::matrix qvMat(2,2), qvCol(2,1), rm1, rm2;
//mat1
qvCol(0,0) = q*v;
qvCol(1,0) = 2*q*v;
//mat2
qvMat(0,0) = q*v;
qvMat(0,1) = 2*q*v;
qvMat(1,0) = 3*q*v;
qvMat(1,1) = 4*q*v;
cout << endl << "m1: " << endl << qvCol << endl;
cout << "m2: " << endl << qvMat << endl << endl;
write("example.gin", qvCol, qvMat);
read("example.gin", &rm1, &rm2);
cout << endl << "rm1: " << endl << rm1 << endl;
cout << "rm2: " << endl << rm2 << endl << endl;
return 0;
}
void read( string filename, GiNaC::matrix* qvCol, GiNaC::matrix* qvMat ){
cout << "Main::Read File.......";
fstream fr(filename.c_str(),ios::in|ios::binary);
if( !fr.is_open() ){
printf("bad file\n");
return;
}
GiNaC::archive_node canCol, canMat;
GiNaC::lst syms(q, v);
fr >> canCol;
fr >> canMat;
qvCol->read_archive(canCol, syms);
qvMat->read_archive(canMat, syms);
fr.close();
cout << "OK: " << filename << endl;
}
void write( string filename, GiNaC::matrix qvCol, GiNaC::matrix qvMat ){
cout << "Main::Write File......";
fflush(stdout);
//abrir archivo para escritura
fstream fw(filename.c_str(),ios::out|ios::binary);
GiNaC::archive_node anCol, anMat;
qvCol.archive( anCol );
qvMat.archive( anMat );
fw << anCol;
fw << anMat;
fw.close();
cout << "OK: " << filename << endl;
}
//END
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cebix.net/pipermail/ginac-list/attachments/20100706/c43cf5b8/attachment.htm>
More information about the GiNaC-list
mailing list