Re: byte offset in POINT_LUN [message #55240] |
Thu, 09 August 2007 15:44 |
badjelly.witch
Messages: 27 Registered: May 2006
|
Junior Member |
|
|
>> And, viola! You are back! :-)
Magniifque!
I'd just like to add a warning: jumping around in a file *may* not be
as efficient as you might think, especially if you're going backwards
from the current position. Specifically, if you have gzipped your
large ASCII file and opened it in IDL with the OPENR COMPRESS keyword
(and why wouldn't you?) then moving around with POINT_LUN involves
reinitialising the compressed data stream. I think to all intents and
purposes it means IDL goes back to the start of the file and reads up
to the saved position again.
I remember years ago I discovered a BACKSPACE command in an old
version of Fortran on a PDP 11. I wrote a program that read a line,
thought about it for a while and then backspaced to the start of the
line and reread it. It worked beautifully on a small file but bogged
down horribly on a large one, because BACKSPACE was rereading the
entire file. A valuable lesson!
|
|
|
|
Re: byte offset in POINT_LUN [message #55266 is a reply to message #55264] |
Wed, 08 August 2007 14:36  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Josh writes:
> as i'm cruising through, reading a large ascii file, I'd like to keep
> track of the beginning of certain "blocks" of code. in the event that
> i find what i'm looking for within the block, I'd like to PRINTF the
> entire block (the beginning of which is now above my file position).
> I've used POINT_LUN to return to the start of a file before, by
> setting position=0, but is there a way I can use POINT_LUN to go to a
> specific line within the file (since I'm not sure how that would
> correspond to a byte offset) ?
I've never used POINT_LUN like this in an ASCII file,
but I had an idea that seems to work in the few tests
I've just made.
Suppose you open an ASCII data file:
OPENR, lun, 'myfile.txt', /GET_LUN
And suppose you read the first 10 lines of the
file:
data = StrArr(10)
READF, lun, data
Now, say you want to come back to this spot later,
you need to know where you are in the file. In an
unformatted file you could probably count and get
the value correctly. An ASCII file is *way* more
complicated, but POINT_LUN can tell us if we use
a "negative" value for the logical unit number:
POINT_LUN, -lun, thisPoint
Now you could read more data:
READF, lun, data
When you want to return to the previous point in the
file, you can use POINT_LUN again:
POINT_LUN, lun, thisPoint
And, viola! You are back! :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: byte offset in POINT_LUN [message #55267 is a reply to message #55266] |
Wed, 08 August 2007 14:30  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
Josh wrote:
> as i'm cruising through, reading a large ascii file, I'd like to keep
> track of the beginning of certain "blocks" of code. in the event that
> i find what i'm looking for within the block, I'd like to PRINTF the
> entire block (the beginning of which is now above my file position).
> I've used POINT_LUN to return to the start of a file before, by
> setting position=0, but is there a way I can use POINT_LUN to go to a
> specific line within the file (since I'm not sure how that would
> correspond to a byte offset) ?
Sure. Just keep track of the byte offsets corresponding to the start
of the lines you're interested in.
|
|
|
Re: byte offset in POINT_LUN [message #55269 is a reply to message #55267] |
Wed, 08 August 2007 13:05  |
Josh
Messages: 21 Registered: June 2007
|
Junior Member |
|
|
On Aug 8, 2:03 pm, Josh <joshuamonta...@gmail.com> wrote:
> as i'm cruising through, reading a large ascii file, I'd like to keep
> track of the beginning of certain "blocks" of code. in the event that
> i find what i'm looking for within the block, I'd like to PRINTF the
> entire block (the beginning of which is now above my file position).
> I've used POINT_LUN to return to the start of a file before, by
> setting position=0, but is there a way I can use POINT_LUN to go to a
> specific line within the file (since I'm not sure how that would
> correspond to a byte offset) ?
sorry, where I said ".... certain 'blocks' of code," I meant "....
certain 'blocks' of text." That is, the data in the file (which are
in ascii format).
|
|
|