Thanks Alexei<br><br>i complicated myself with the archive_node because i didnt know i could do this<br>ex_to<matrix><br><br>best regards,<br>Cristobal<br>
<br><br><span style="color: black;"><div dir="ltr"><div><a href="http://www.youtube.com/neoideo">Cristobal</a></div></div></span><br><br><div class="gmail_quote">On Wed, Jul 7, 2010 at 1:41 AM, Alexei Sheplyakov <span dir="ltr"><<a href="mailto:alexei.sheplyakov@gmail.com">alexei.sheplyakov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hello,<br>
<div class="im"><br>
On Tue, Jul 06, 2010 at 09:05:06PM -0400, Cristobal Navarro wrote:<br>
><br>
> i am experiencing a little trouble when reading my stored matrix.<br>
> when i write and read the same matrix i stored, it works.<br>
> but if i only run the program to read the matrix file, i get this error.<br>
><br>
> terminate called after throwing an instance of 'std::runtime_error'<br>
> what(): unknown matrix dimensions in archive<br>
><br>
<br>
</div>The example below works for me just fine.<br>
<br>
#include <string><br>
#include <fstream><br>
#include <stdexcept><br>
<div class="im">#include <ginac/ginac.h><br>
using namespace std;<br>
using namespace GiNaC;<br>
<br>
</div>static void read(const string& filename, matrix& qvCol, matrix& qvMat, const lst& symlst)<br>
{<br>
archive ar;<br>
ifstream f(filename.c_str());<br>
if (!f.is_open())<br>
throw std::runtime_error(string("Failed to open input file: ") + filename);<br>
f >> ar;<br>
f.close();<br>
ex qvColEx = ar.unarchive_ex(symlst, "qvCol");<br>
ex qvMatEx = ar.unarchive_ex(symlst, "qvMat");<br>
if (!(is_a<matrix>(qvColEx) && is_a<matrix>(qvMatEx)))<br>
throw std::runtime_error("expected a matrix");<br>
qvCol = ex_to<matrix>(qvColEx);<br>
qvMat = ex_to<matrix>(qvMatEx);<br>
}<br>
<br>
static void write(const string& filename, const matrix& qvCol, const matrix& qvMat)<br>
{<br>
archive ar;<br>
ar.archive_ex(qvCol, "qvCol");<br>
ar.archive_ex(qvMat, "qvMat");<br>
ofstream f(filename.c_str());<br>
if (!f.is_open())<br>
throw std::runtime_error(string("Failed to open output file: ") + filename);<br>
f << ar << flush;<br>
f.close();<br>
<div class="im">}<br>
<br>
int main(int argc, char** argv)<br>
{<br>
</div> const symbol q("q"), v("v");<br>
lst symlst;<br>
symlst = q, v;<br>
<br>
matrix qvMat(2, 2), qvCol(2, 1);<br>
qvCol = q*v, 2*q*v;<br>
qvMat = q*v, 2*q*v,<br>
3*q*v, 4*q*v;<br>
<div class="im"> cout << endl << "m1: " << endl << qvCol << endl;<br>
cout << "m2: " << endl << qvMat << endl << endl;<br>
<br>
</div> write("example.gar", qvCol, qvMat);<br>
matrix rm1, rm2;<br>
read("example.gar", rm1, rm2, symlst);<br>
<div class="im"> cout << endl << "rm1: " << endl << rm1 << endl;<br>
cout << "rm2: " << endl << rm2 << endl << endl;<br>
return 0;<br>
}<br>
<br>
</div><div class="im">> This is a one-file example source code i made for you guys so you can test,<br>
> its based on the same problem i have on my bigger code.<br>
> try running it as it is, then comment the "write" method and run it again so<br>
> it only reads the matrices, youll get the error eventually. but you will<br>
> never get it if you write and read, its weird.<br>
<br>
</div>[skipped the code]<br>
<div class="im"><br>
> how can this be solved?<br>
<br>
</div>First of all, please (re)read the manual, in particular, the (sub)section<br>
called `Archiving'. Secondly, stop abusing read_archive() and archive_node.<br>
<br>
Hope this helps,<br>
Alexei<br>
<br>
_______________________________________________<br>
GiNaC-list mailing list<br>
<a href="mailto:GiNaC-list@ginac.de">GiNaC-list@ginac.de</a><br>
<a href="https://www.cebix.net/mailman/listinfo/ginac-list" target="_blank">https://www.cebix.net/mailman/listinfo/ginac-list</a><br>
</blockquote></div><br>