Exporting vectors to .dat file afte each time step
Posted: Thu Mar 29, 2012 8:12 pm
I need to be able to export the spatial CSD vector at each time step to the external file for plotting with Matlab. I implemented the solution, but wanted to ask for the feedback on whether or not this is the optimal way of doing this. The CSD vector is calculated at each time step with the update_csd() procedure which is called by a custom advance() procedure. Then, I store CSD vector at each time step into the matrix column. This matrix is then saved to a file within a custom run() procedure. I have placed the definition of the matrix within the run() to be able to rerun the simulation using the Run Control panel. Obviously, this code is not going to work with the variable time step, because I would not know how many columns to allocate in the matrix. I suppose for the variable time step the only solution is to output each vector directly into the file. However, I was not able to accomplish the latter because I could not figure out how to save vector generated at each time step in the row format. Could you please advice on how to store vectors as rows?
Code: Select all
objref fobj2
proc advance() { // custom proc advance()
fadvance()
update_csd() // calculate CSD vector after each time step
it=it+1 // column index for csdmat
csdmat.setcol(it,csdvec) // populate it-th column of the output matrix with csdvec(dt*it)
}
proc run() { // custom proc run()
stdinit() // standard run system procedure
fobj2 = new File("./Data/csd.dat") // redefine the reference to the file for each run
fobj2.wopen()
it=0 // start at the beginning on the matrix for each run
Nt = (tstop/dt+1) // number of time steps (= number of columns in csdmat)
csdmat = new Matrix(Nzpos+1,Nt+1) // create an empty matrix with enough columns to store the data
continuerun(tstop) // standard run system procedure
csdmat.fprint(0,fobj2) // output the csdmat to ASCII file
fobj2.close()
it=0 // reinitialize, otherwise the Movie Run will not work
}