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

Home » Public Forums » archive » Skip line in reading a file
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
Skip line in reading a file [message #71018] Tue, 25 May 2010 23:54 Go to next message
Fred[1] is currently offline  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 Go to previous message
mankoff is currently offline  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.
Re: Skip line in reading a file [message #71116 is a reply to message #71018] Wed, 26 May 2010 00:30 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
aaa=(read_ascii(namefile)).(0)
w=where(aaa[2,*] gt X,nw)
if (nw gt 0) then a=aaa[*,w] else ...(deal with the case of skipping
all lines)...
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Integrator taking vectors as input?
Next Topic: rotate tickname and titles

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

Current Time: Wed Oct 08 15:33:31 PDT 2025

Total time taken to generate the page: 0.00604 seconds