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

Home » Public Forums » archive » how to find number of 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: how to find number of lines in an ASCII file? [message #12561 is a reply to message #12560] Tue, 18 August 1998 00:00 Go to previous messageGo to previous message
Phillip & Suzanne[2] is currently offline  Phillip & Suzanne[2]
Messages: 3
Registered: August 1998
Junior Member
Jason Li wrote:
>
> Hi,
>
> I have an ASCII text file that contains data in a nice tabular form,
>
> 0 28660 1827.1 72.7705 -158.8828 3388.0 22.3846 10.8545
> 1 28661 1827.7 72.7701 -158.8752 3391.0 21.1213 10.6029
> 2 28662 1828.3 72.7698 -158.8677 3394.0 19.8743 10.3546
>
> I want to read them all and save into an array: data[8, numberOfLines]. But
> I don't know numberOfLines in the file before hand. What is the most efficient
> way to find that out?

The simplest method I've found for this is to read the data into a text array
as follows:

line=''
readf, lun, line
text = [line]
while (not eof(lun)) do begin
readf, lun, line
text = [text, line]
endwhile
data = fltarr[8, N_Elements(text)]
tmpdata = fltarr[8]
for i=0, N_Elements(text)-1 do begin
reads, text[i], tmpdata
data[*, i] = tmpdata
endfor

Phillip
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: XCD (was:Inconsistent behavior in setting default directory)
Next Topic: row calculation in a 2D array

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

Current Time: Sat Oct 11 08:03:45 PDT 2025

Total time taken to generate the page: 0.23976 seconds