Hello,<div><br></div><div>i am experiencing a little trouble when reading my stored matrix.</div><div>when i write and read the same matrix i stored, it works.</div><div>but if i only run the program to read the matrix file, i get this error.</div>
<div><br></div><div><div>terminate called after throwing an instance of 'std::runtime_error'</div><div> what(): unknown matrix dimensions in archive</div></div><div><br></div><div>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.</div>
<div>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.</div><div>
<br></div><div>how can this be solved?</div><div><br></div><div><div>//CODE</div><div>#include <fstream></div><div>#include <ginac/ginac.h></div><div><br></div><div>using namespace std;</div><div>using namespace GiNaC;</div>
<div>symbol q("q"),v("v");</div><div><br></div><div>void read( string filename, GiNaC::matrix* qvCol, GiNaC::matrix* qvMat );</div><div>void write( string filename, GiNaC::matrix qvCol, GiNaC::matrix qvMat );</div>
<div><br></div><div>int main(int argc, char** argv){</div><div><br></div><div> GiNaC::matrix qvMat(2,2), qvCol(2,1), rm1, rm2;</div><div><br></div><div> //mat1</div><div> qvCol(0,0) = q*v;</div><div> qvCol(1,0) = 2*q*v;</div>
<div> //mat2</div><div> qvMat(0,0) = q*v;</div><div> qvMat(0,1) = 2*q*v;</div><div> qvMat(1,0) = 3*q*v;</div><div> qvMat(1,1) = 4*q*v;</div><div><br></div><div> cout << endl << "m1: " << endl << qvCol << endl;</div>
<div> cout << "m2: " << endl << qvMat << endl << endl;</div><div><br></div><div> write("example.gin", qvCol, qvMat);</div><div> read("example.gin", &rm1, &rm2);</div>
<div> cout << endl << "rm1: " << endl << rm1 << endl;</div><div> cout << "rm2: " << endl << rm2 << endl << endl;</div><div> return 0;</div>
<div>}</div><div><br></div><div>void read( string filename, GiNaC::matrix* qvCol, GiNaC::matrix* qvMat ){</div><div> cout << "Main::Read File.......";</div><div> fstream fr(filename.c_str(),ios::in|ios::binary);</div>
<div> if( !fr.is_open() ){</div><div> printf("bad file\n");</div><div> return;</div><div> }</div><div> GiNaC::archive_node canCol, canMat;</div><div> GiNaC::lst syms(q, v);</div><div> fr >> canCol;</div>
<div> fr >> canMat;</div><div> qvCol->read_archive(canCol, syms);</div><div> qvMat->read_archive(canMat, syms);</div><div> fr.close();</div><div> cout << "OK: " << filename << endl;</div>
<div>}</div><div><br></div><div>void write( string filename, GiNaC::matrix qvCol, GiNaC::matrix qvMat ){</div><div><br></div><div> cout << "Main::Write File......";</div><div> fflush(stdout);</div><div>
//abrir archivo para escritura</div><div> fstream fw(filename.c_str(),ios::out|ios::binary);</div><div> GiNaC::archive_node anCol, anMat;</div><div> qvCol.archive( anCol );</div><div> qvMat.archive( anMat );</div>
<div> fw << anCol;</div><div> fw << anMat;</div><div> fw.close();</div><div> cout << "OK: " << filename << endl;</div><div>}</div><div>//END</div></div><div><br></div><div>
<br></div>