Re: counting elements in files [message #6609] |
Wed, 24 July 1996 00:00 |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
Gideon Z Romm wrote:
> I have a file with a bunch of numbers stored in it, formatted. It looks
> something like this:
> 2555 3456 4567 5678 6789 7890
> 2345 6788 3445 6778 8899 9900
> ..
> ..
> ..
>
> I am having trouble finding a procedure that will count the number of
> elements in this file, so that when I create an array into which to read
> this file, I will know what size to make the array.
Get Fred Knight's DDREAD procedure. You can grab his user library from
ftp://ftp.rsinc.com/pub/user_contrib/knight
It will handle this data file no problem.
(Ray, this is getting to be a FAQ - I know I've answered it at least 3 times).
Cheers,
Liam.
|
|
|
Re: counting elements in files [message #6610 is a reply to message #6609] |
Wed, 24 July 1996 00:00  |
Thomas A. McGlynn
Messages: 23 Registered: March 1996
|
Junior Member |
|
|
Andy Loughe wrote:
>
> Gideon Z Romm wrote:
>>
>> I have a file with a bunch of numbers stored in it, formatted. It looks
>> something like this:
>>
>> 2555 3456 4567 5678 6789 7890
>> 2345 6788 3445 6778 8899 9900
>> ..
>> ..
>> ..
>>
>> I am having trouble finding a procedure that will count the number of
>> elements in this file,
...
>> Gadi
>
> If the number of columns is fixed, why not use... cat filename | wc -l
> in an IDL spawn command, then multiply that by the number of columns
> you know to be in the file.
>
...
>
> Does this help, or am I way out in left field?
>
> --
> Andrew F. Loughe afl@cdc.noaa.gov
If you're going to use wc, you probably just want to use 'wc -w' to
count the words directly. Of course if you don't have wc it can
be a little more difficult. If the file is fixed format you may be
able to do a calculation based upon the size of the file.
Good luck,
Tom McGlynn
tam@silk.gsfc.nasa.gov
|
|
|
Re: counting elements in files [message #6613 is a reply to message #6609] |
Wed, 24 July 1996 00:00  |
Andy Loughe
Messages: 174 Registered: November 1995
|
Senior Member |
|
|
Gideon Z Romm wrote:
>
> I have a file with a bunch of numbers stored in it, formatted. It looks
> something like this:
>
> 2555 3456 4567 5678 6789 7890
> 2345 6788 3445 6778 8899 9900
> ..
> ..
> ..
>
> I am having trouble finding a procedure that will count the number of
> elements in this file, so that when I create an array into which to read
> this file, I will know what size to make the array.
> Any suggestions?
>
> Gadi
If the number of columns is fixed, why not use... cat filename | wc -l
in an IDL spawn command, then multiply that by the number of columns
you know to be in the file.
Or, if you know the number of columns, you could use free formatted read
(as long as there commas, whitespace, or tabs) and use the while not eof
logic. That way you don't even need to know the total number of
elements in the file.
Does this help, or am I way out in left field?
--
Andrew F. Loughe afl@cdc.noaa.gov
University of Colorado, CIRES http://cdc.noaa.gov/~afl
Campus Box 449 phn:(303)492-0707 fax:(303)497-7013
Boulder, CO 80309-0449 "He who laughs last thinks slowest!"
|
|
|