Skip line in reading a file [message #71018] |
Tue, 25 May 2010 23:54  |
Fred[1]
Messages: 4 Registered: April 2010
|
Junior Member |
|
|
Hi to everybody,
I need to read a file of n columns "namefile", but also I need to
select only the lines where the variable in column 3, i.e. [2,*], for
example, has value larger than X.
I tried this way:
n1=numlines(namefile)
OPENR, 1, namefile
aaa=fltarr(col,n1)
readf,1,aaa
close,1
aa = REFORM(aaa[2,*])
if aa[2,*] gt X then a[*,*] = aaa[*,*]
The array a should be an array a[col,n2], where n2 is the number of
the lines where aa[2,*] gt X.
But
help,/st,a
gives an array with columns=col and lines=n1!!!
So it completes the routine without errors but does not select the
lines where aa[2,*] gt X.
I could not use Skipline of readcol, because it skips only the first
line. There should be an easy way to do it.
Thanks
|
|
|
Re: Skip line in reading a file [message #71115 is a reply to message #71018] |
Wed, 26 May 2010 00:34  |
mankoff
Messages: 131 Registered: March 2004
|
Senior Member |
|
|
On May 25, 11:54 pm, Fred <fedef...@gmail.com> wrote:
> Hi to everybody,
> I need to read a file of n columns "namefile", but also I need to
> select only the lines where the variable in column 3, i.e. [2,*], for
> example, has value larger than X.
> I tried this way:
>
> n1=numlines(namefile)
>
> OPENR, 1, namefile
> aaa=fltarr(col,n1)
> readf,1,aaa
> close,1
>
> aa = REFORM(aaa[2,*])
> if aa[2,*] gt X then a[*,*] = aaa[*,*]
>
> The array a should be an array a[col,n2], where n2 is the number of
> the lines where aa[2,*] gt X.
> But
> help,/st,a
> gives an array with columns=col and lines=n1!!!
> So it completes the routine without errors but does not select the
> lines where aa[2,*] gt X.
> I could not use Skipline of readcol, because it skips only the first
> line. There should be an easy way to do it.
> Thanks
a = randomu(seed,3,10) ; 3 col x 10 row array of random values
gd = where(a[2,*] gt 0.5, ngd) ; All rows where 3rd column > 0.5
if ngd gt 0 then aa = a[*,gd] ; subset 1st array
-k.
|
|
|
|