Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14147

Re: Reading a file in reverse order --- How?

From plank.in.sequim@gmail.com
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Reading a file in reverse order --- How?
Date 2013-04-11 08:11 +0000
Message-ID <kk5r70$ril$1@smc.vnet.net> (permalink)
References <kfi2i3$d0p$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


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[[n-i+1]]];
PIn=Read[strm];

Print[PIn];(*Process PIn...*)];

Close[strm];

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Reading a file in reverse order --- How? Virgil Stokes <vs@it.uu.se> - 2013-02-14 07:08 +0000
  Re: Reading a file in reverse order --- How? debguy <johnandsara2@cox.net> - 2013-04-10 04:48 +0000
  Re: Reading a file in reverse order --- How? Waclaw Kusnierczyk <waku@idi.ntnu.no> - 2013-04-11 08:11 +0000
  Re: Reading a file in reverse order --- How? plank.in.sequim@gmail.com - 2013-04-11 08:11 +0000

csiph-web