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

Home » Public Forums » archive » idl readf error
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
idl readf error [message #65149] Thu, 12 February 2009 11:50 Go to next message
rollo.tomasi is currently offline  rollo.tomasi
Messages: 4
Registered: February 2009
Junior Member
I have a file with 5 columns that looks like this (except for the
column labels):

T/F	I/U	Time	   Blocks	Volume
T	I	7.12	        227	11145.6
F	U	16.34	227	10914.9
T	I	21.43	232	11151.9
T	U	25.99	224	11364.1
F	I	37.13	199	7566.9

Essentially I want to calculate the median for each time, blocks, and
volume for the entire file, and then depending on T/F and I/U.

I've gotten the script to work with the first three columns, but when
I add the last two columns (blocks and volume) it returns an error.
Can anyone tell me what I am doing wrong?

Here is the first part of the script that works fine with the first 3
columns:
____________________________________________________________ _
pro metrics1, xmed
xx=fltarr(9999) & x1= strarr(9999) & x2= strarr(9999)

i= 0 & x1i= '~' & x2i= '~'
openr,67, 'file1.out'
;
while not eof(67) do BEGIN
readf, 67, x1i, x2i, xxi, format='(2A2, G7.2)'
x1(i)= x1i & x2(i)= x2i & xx(i)= xxi
i = i + 1
ENDwhile
PRINT, ' last record was: ', x1i, x2i, xxi

ind= where(xx gt 0.0)
yy= xx(ind)
s=size( yy )
xm = median(yy)
print ,s(1), xm, ' total'

ind= where(xx gt 0.0 and x1 eq 'T ')
z= max(ind) & IF z gt 0 then BEGIN
yy= xx(ind) & s=size( yy ) & xm = median(yy)
print ,s(1), xm, ' All with True' & END
__________________________________________________________


Here is the script when I tried to add the last two columns, it
doesn't work:
The errors I get are:
1. Type conversion error: Unable to convert given STRING to Float. (at
the readf line)
2. Attempt to subscript XX with IND is out of range. (at the yy=xx
(ind) line)
____________________________________________________________ ___
pro metrics1test, xmed
xx=fltarr(9999) & x1= strarr(9999) & x2= strarr(9999) &
x3=fltarr(9999) & x4=fltarr(9999)

i= 0 & x1i= '~' & x2i= '~'
openr,68, 'file1.out'
;
while not eof(68) do BEGIN
readf,68, data, x1i, x2i, xxi, x3i, x4i, format='(2A2, G7.2)'
x1(i)= x1i & x2(i)= x2i & xx(i)= xxi & x3(i)= x3i &
x4(i)= x4i
i = i + 1
ENDwhile
PRINT, ' last record was: ', x1i, x2i, xxi, x3i, x4i

ind= where(xx gt 0.0)
yy= xx(ind)
s=size( yy )
xm = median(yy)
ind3= where(x3 gt 0.0)
y3= x3(ind3)
s3=size( y3 )
xm3 = median(y3)
ind4= where(x4 gt 0.0)
y4= x4(ind4)
s4=size( y4 )
xm4 = median(y4)
print ,s(1), xm, xm3, xm4, ' Total'

ind= where(xx gt 0.0 and x1 eq 'T ')
z= max(ind) & IF z gt 0 then BEGIN
yy= xx(ind) & s=size( yy ) & xm = median(yy)
print ,s(1), xm, ' All with True' & END
____________________________________________________________ __
Re: idl readf error [message #65218 is a reply to message #65149] Sat, 14 February 2009 07:08 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Vince Hradil writes:

> Of course that's all relative. If I have to spend 2 days to figure
> out how to read in a file that takes 2 seconds to parse (instead of
> the normal 10 seconds) then I don't think it's worth it. Like wise if
> I read a file 5 seconds faster as part of a 2 hour simulation run, I
> don't think it's worth.
>
> Just sayin'...

I hear you. I use your method most of the time myself,
just for the reason you mention: it takes me about 10 times
as long to get the format statement right. But, my ASCII files
are a couple of hundred lines, not a couple of hundred thousand
lines.

> I guess what I what I really want to know is whether the accuracy (in
> terms of round-off errors, or anything else) is any different in the
> two approaches. I'm guessing not.

I don't think so, either.

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.")
Re: idl readf error [message #65219 is a reply to message #65149] Sat, 14 February 2009 07:04 Go to previous messageGo to next message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On Feb 14, 8:52 am, David Fanning <n...@dfanning.com> wrote:
> Vince Hradil writes:
>> This thread makes me think... Can anyone compare and contrast this
>> approach with the approach I usually use - that is:
>> read each line into a string buf: buf =3D '' $ readf, lun, buf
>> then use strsplit(buf,/extract) to chop up the buf
>> then use fix, float, etc. to get the values.
>
>> I don't usually use format statements for reading, just writing.
>
> Can you spell S-L-O-W? ;-)
>
> 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.")

Of course that's all relative. If I have to spend 2 days to figure
out how to read in a file that takes 2 seconds to parse (instead of
the normal 10 seconds) then I don't think it's worth it. Like wise if
I read a file 5 seconds faster as part of a 2 hour simulation run, I
don't think it's worth.

Just sayin'...

I guess what I what I really want to know is whether the accuracy (in
terms of round-off errors, or anything else) is any different in the
two approaches. I'm guessing not.

Thanks,
Vince
Re: idl readf error [message #65239 is a reply to message #65149] Thu, 19 February 2009 11:41 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
rollo.tomasi@hotmail.com writes:

> Thanks for your help. Even after using format='(2
> (A1,7x),F5.2,3x,I3,5x,G8.2)' , I'm still getting the same error:
> "Type conversion error: Unable to convert given STRING to Float"
>
> I'll keep playing around with it to see what format its asking for.

Well, I would *definitely* learn how to put a breakpoint
in your program, and I would have a look around just before
and after you read this line. Maybe just read bits of
the line. The answer is probably there. Assuming, of course,
that this is where the problem is. It isn't always. :-)

Cheers,

David

--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: idl readf error [message #65241 is a reply to message #65218] Thu, 19 February 2009 10:17 Go to previous message
rollo.tomasi is currently offline  rollo.tomasi
Messages: 4
Registered: February 2009
Junior Member
Thanks for your help. Even after using format='(2
(A1,7x),F5.2,3x,I3,5x,G8.2)' , I'm still getting the same error:
"Type conversion error: Unable to convert given STRING to Float"

I'll keep playing around with it to see what format its asking for.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: get LAT/LON from georef image
Next Topic: Interpolating/gridding field reflectance spectra

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

Current Time: Wed Oct 08 19:16:41 PDT 2025

Total time taken to generate the page: 0.00688 seconds