Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Reading a file in reverse order  How?
Posted:
Apr 11, 2013 4:11 AM


One possibility is to keep track of the stream positions for each entry when writing out and then SetStreamPosition to those positions in reverse order when reading each record back in. You ought to have enough memory for a 10K integer array. Argh! I can't seem to get Mathematica to put out a nice text for pasting. Will MathML work? Anyway, hopefully you can make some sense of this. It's not that big a change from your original code.
fname="testfile"; entryLocs={}; Print["Input"]; strm=OpenWrite[fname]; n=3;(*In general,n could be very large*)For[k=1,k<=n,k++,(*Create list on each pass through this loop...*)POt={{k,k+1},{k+2,k+3}}; entryLocs=Append[entryLocs,StreamPosition[strm]]; Print[POt];(*Save list to a file*)Write[strm,POt];]; Close[strm]; (*Other processing performed...*) (*Open file with lists*) strm=OpenRead[fname]; (*Process,sequentially,each list that was saved*) For[i=1,i<=n,i++, SetStreamPosition[strm,entryLocs[[ni+1]]]; PIn=Read[strm];
Print[PIn];(*Process PIn...*)];
Close[strm];



