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

Home » Public Forums » archive » That filelength question - again ....
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
That filelength question - again .... [message #37928] Mon, 09 February 2004 12:47 Go to next message
jeyadev is currently offline  jeyadev
Messages: 78
Registered: February 1995
Member
Sometime back there was thread about how to determine the length
of files, but did not follow it ....

Faced suddenly with a huge bunch of files with varying lengths,
but, thankfully, the same number of columns, I was looking for
the answer to the question ... but did not find it. So the
following kludge:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

; Function to find out the number of lines in a simple
; ASCII file

function filelength , filename

cmd = 'spawn, ' + " 'wc -l " + filename + ' | sed "s/' + filename + '//"'
cmd = cmd + "', s1"

; s1 is a string array with just one element

filelength = -1
val = execute(cmd)
if(val eq 1) then filelength = atoi(s1(0)) ; command executed properly
if(val eq 0) then print, " *** Error in finding no. of lines *** "

return, filelength
end

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

where 'atoi' is just the same as the corresponding C function. It
removes leading and trailing blanks from a string and returns the
corresponding integer value.

Seems to work allright, but the fact that I did not find it in any
of the sites began to make me wonder. Am I overlooking something
here?

Have to confess that not all the error checking that ought to be
done is done here -- but then, again, I know more about my data
files :-)

For completeness, here is atoi.pro

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

; Function that mimics the C 'atoi' function
; Leading and trailing blanks are removed before conversion

; Remove leading and trailing blanks in string by using
; strtrim(str, 2)

function atoi, str

str = strtrim(str, 2) ; trim leading and trailing blanks
l = strlen(str)
m = fix(byte(str)) - 48

a = 0
for i=0,l-1 do a = a + m(i)*10^(l-1-i)

return, a

end

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

atoi.pro was written solely for dealing with filenames and
I never intended 'a' to be larger than 9999. Hope I never
have to deal with that many data files!
thanks
--

Surendar Jeyadev jeyadev@wrc.xerox.bounceback.com

Remove 'bounceback' for email address
Re: That filelength question - again .... [message #37977 is a reply to message #37928] Wed, 11 February 2004 15:31 Go to previous message
jeyadev is currently offline  jeyadev
Messages: 78
Registered: February 1995
Member
In article <aelh20tihfqcc3r7vr37a6sl2i3o8ej26n@4ax.com>,
Norbert Hahn <hahn@hrzpub.tu-darmstadt.de> wrote:
> jeyadev@wrc.xerox.bounceback.com (Surendar Jeyadev) wrote:
>
>> For completeness, here is atoi.pro
>
> [snip]
>
> Hm, to convert any data item to long integer, just use the long
> function. Thus, = long(str) will do, and str may be a string
> array. The function will then return an interger array.
>
> Norbert


Ah! Blessed is (s)he, who readeth the manual .....

Thanks!

--

Surendar Jeyadev jeyadev@wrc.xerox.bounceback.com

Remove 'bounceback' for email address
Re: That filelength question - again .... [message #38014 is a reply to message #37928] Tue, 10 February 2004 05:02 Go to previous message
Norbert Hahn is currently offline  Norbert Hahn
Messages: 46
Registered: May 2003
Member
jeyadev@wrc.xerox.bounceback.com (Surendar Jeyadev) wrote:

> For completeness, here is atoi.pro

[snip]

Hm, to convert any data item to long integer, just use the long
function. Thus, = long(str) will do, and str may be a string
array. The function will then return an interger array.

Norbert
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: GE PET DICOM format
Next Topic: Re: modify widget base colour

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

Current Time: Fri Oct 10 09:19:22 PDT 2025

Total time taken to generate the page: 0.32138 seconds