Save data file each time step

The basics of how to develop, test, and use models.
Post Reply
Posts: 15
Joined: Wed Nov 25, 2009 7:07 pm

Save data file each time step

Post by henrychen1986 »


We have a simulation which record v into a vector then save to a file. But the saving to file process after the whole simulation. How to program to save to data file each timestep in the simulation.

Site Admin
Posts: 5935
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: Save data file each time step

Post by ted »

Use a custom proc advance()
proc advance() {
where print_data_to_output_file() contains a statement* that prints the data you're interested in to the output file. Just make sure that you open the output file for writing before calling run(), and close it after calling run().

You're still going to get buffered file output--modern operating systems generally do not write data to disk just a few bytes at a time. Instead, they accumulate data in a buffer until the buffer is full enough to trigger a write operation, or until you close the file.

*--this could be a statement of the form
filobj.printf("format", args)
See the Programmer's Reference for information about the File class's methods ... /file.html
Post Reply