comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: byte offset in POINT_LUN
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: byte offset in POINT_LUN [message #55266 is a reply to message #55264] Wed, 08 August 2007 14:36 Go to previous messageGo to previous message
David Fanning is currently offline  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.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Use IDL6.0 to read gcc3.4(Mingw32) written data
Next Topic: Re: Transforming a nonlinear equation

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 01:02:14 PDT 2025

Total time taken to generate the page: 0.08811 seconds