Write output to file continuously
- To: mathgroup at smc.vnet.net
- Subject: [mg31074] Write output to file continuously
- From: <bradamanteus at yahoo.com>
- Date: Sat, 6 Oct 2001 03:33:30 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I have a NestList in my program and I wish to write the output of this list to a file one line at a time, as the program is being run. In this way if I have to abort the calculation halfway through I will still have a record of the output up to the time of aborting. Gradually the program will build up a record of the whole simulation from the NestList. No doubt, the constant writing to the file will slow the program down, so I may wish to change it so that the output accumulates n steps and then writes to the file. I've tried appending the output of a function called "nextstate" to a file, however I can't seem to get the right result ("nextstate" is ordinarily embedded into my NestList directly but now I've added an additional outputstep function). I get different results depending on whether I use ">>>" or "PutAppend". The former calculates the NestList accurately but doesn't write the output (line by line) to a file. The latter produces the first initial output list but will not calculate further, and the NestList simulation fails. I've listed both these attempts here under 1. and 2. 1.Here the NestList works but the output is not written to a file. Although it does create a file called datafilename with a content of NULL Clear[outputstep]; outputstep[datafilename_String][{variablelist_}] := nextstate[{variablelist}] >>> datafilename Clear[simulation]; simulation[datafilename_String, simlength_][{variablelist_}] := NestList[outputstep[datafilename], {variablelist}, simlength] simulation["dat3", 3][{initiallist}] 2. This creates a filename named dat3, but only has the initial list of variables and NestList cannot be calculated. Clear[outputstep]; outputstep[datafilename_String][{variablelist_}] := PutAppend[nextstate[{variablelist}], datafilename] Clear[simulation]; simulation[datafilename_String, simlength_][{variablelist_}] := NestList[outputstep[datafilename], {variablelist}, simlength] simulation["dat3", 3][{initiallist}] I would appreciate any assistance. Amateur mathematica programmer Leanne Ussher bradamanteus at yahoo.com