idl readf error [message #65149] |
Thu, 12 February 2009 11:50  |
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
____________________________________________________________ __
|
|
|