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

Home » Public Forums » archive » Re: Read Total lines in an ASCII file
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: Read Total lines in an ASCII file [message #33172 is a reply to message #33170] Fri, 13 December 2002 10:39 Go to previous messageGo to previous message
Med Bennett is currently offline  Med Bennett
Messages: 109
Registered: April 1997
Senior Member
David Burridge wrote:

> Hi Maria,
>
> Actually, I beleive there is a new feature in IDL 5.6 that does this. But
> assuming you're still on IDL 5.5, something like:
>
> noLines = 0L
> line = ''
> OpenR, lun, 'mytextfile.txt', /Get_lun
> While Not EOF (lun) Do Begin
> ReadF, lun, line
> noLines = noLines + 1
> EndWhile
>
> Will do the trick. If (as I suspect) you then want to read the file, don't
> forget to:
>
> Point_Lun, lun, 0
>
> before you do. Otherwise, you'll need a:
>
> Free_Lun, lun
>
> to close the file and make the allocated file unit available to IDL again.
>
> On the other point, will a simple:
>
> mychar EQ 'P'
>
> in a statement do the trick? Examples
>
> If mychar EQ 'P' Then Print, 'Hello'
>
> mybool = mychar EQ 'P'
>
> Hope this helps.
>
> Best regards,
>
> David
>
> David Burridge
>
> Burridge Computing
>
> 18 The Green South
>
> Warborough
>
> Oxon
>
> OX10 7DN
>
> Tel: 01865 858279
>
> Mobile: 0780 244 1748
>
> Email: davidb@burridgecomputing.co.uk
>
> "Maria" <msmimb@hotmail.com> wrote in message
> news:d19b702e.0212130942.1d6d6dbf@posting.google.com...
>> I bet my question seems simple to all of you but...does anybody know
>> how to read the total number of lines in an ASCII file?
>>
>> Also, is there any command in IDL such as if ( variable_char is char)
>> then give me a boolean (true or false)?
>>
>> Thanks a lot!
>> Maria.

That should work fine, but I would think that it would be slow for large files
because of the loop. I do this instead - also somewhat crude but maybe
faster:

junk=strarr(1000000L)
on_ioerror,done
openr,lun,'mytextfile.txt'
readf,lun,junk
stop,'need to increase array size'
done:
close,lun
junk = junk[where(strlen(junk) gt 0)]
end

The readf will generate an error unless your file is bigger than the initial
array; if that is the case, you have to make it bigger.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Histogram indeterminate results
Next Topic: handling numbers

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

Current Time: Sat Oct 11 10:31:23 PDT 2025

Total time taken to generate the page: 0.16598 seconds