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

Home » Public Forums » archive » Re: Get rid of unwanted lines.
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
Re: Get rid of unwanted lines. [message #62323] Fri, 05 September 2008 14:45 Go to next message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Sep 5, 4:15 pm, mankoff <mank...@gmail.com> wrote:
> On Sep 5, 5:07 pm, xiao <littledd...@gmail.com> wrote:
>
>
>
>> On Sep 5, 2:34 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
>> wrote:
>
>>> xiao wrote:
>>>> Hi~ everyone, i have some data like this:
>
>>>> 1123.97 000 15.0600 000 271.850 000
>>>> 000 000 000 000 000
>>>> 000
>>>> 1127.98 000 15.2800 000 270.650 000
>>>> 000 000 000 000 000
>>>> 000
>>>> 1136.68 000 15.5100 000 269.300 000
>>>> 000 000 000 000 000
>>>> 000
>>>> 1139.05 000 15.7500 000 267.860 000
>>>> 000 000 000 000 000
>>>> 000
>>>> 000 000 000 000 000
>>>> 000
>>>> 000 000 000 000 000
>>>> 000
>>>> 000 000 000 000 000
>>>> 000
>>>> 1145.10 000 15.9900 000 266.410 000
>>>> 1155.74 000 16.2300 000 265.010 000
>>>> 1163.19 000 16.4500 000 263.700 000
>>>> I want to delete these zero lines and write other lines to another
>>>> file. How can I fulfill this ?
>>>> Anyone have good ideas?
>>>> Thank you
>
>>> so, do you always have 6 numbers per lines?
>
>>> do something like this:
>
>>> filname = 'originalFile.txt'
>>> nbLines = file_lines(filename) ;get the number of lines in the file
>>> data = fltarr(nbLines) ;create an array to get all the data
>
>>> openR, lun, filename, /get_lun ;open the file
>>> readf, lun, data ;get all the data
>>> close,lun ;close the file
>>> free_lun,lun
>
>>> ;Select the good lines, the ones that do NOT have only zeroes
>>> badLines = where(data[0,*] eq 0 and data[1,*] eq 0 and data[2,*] eq 0
>>> and data[3,*] eq 0 and data[4,*] eq 0 and data[5,*] eq 0, complement =
>>> goodLines)
>
>>> ;open and write the output!
>>> openW,lun, new_fileName, /get_lun
>>> printf,data[*,goodLines]
>>> close,lun
>>> free_lun,lun
>
>>> Jean
>>> PS: since you deal with float data, you might have to replace data[x,*]
>>> eq 0 by abs(data[x,0]) lt epsilon, epsilon being a number small
>>> enough to be considered as zero. Read David's Fanning website under "the
>>> sky is falling".
>
>> yes, it works, but another question arouse. When I have eight columns,
>> after i write them to another file, these numbers are not in the same
>> line. The last two numbers are in another line like this:
>
>> 964.850 0.00000 25.3800 0.00000 335.750
>> 0.00000
>> 0.237400 0.00000
>> 964.510 0.00000 25.0400 0.00000 338.800
>> 0.00000
>> 0.240100 0.00000
>> 964.140 0.00000 24.6500 0.00000 342.150
>> 0.00000
>> 0.245400 0.00000
>> 963.750 0.00000 24.2800 0.00000 345.690
>> 0.00000
>> 0.250700 0.00000
>
>> Why is that? thx
>
> See WIDTH keyword to OPEN command.

Thank you ,very much. it works. But when i read these files again in
the same program like this:


OPENr,3, 'sdata1.eol'
OPENr,4, 'wdata1.eol'

subsdata=fltarr(levlesforp,8)
subwdata=fltarr(levlesforh,6)

READF,3,subsdata
readf,4, subwdata

it always says, end of file encountered. levlesforp and levlesforh
are exactly the lines of the file generated last step. eight and six
are the column number, why is that?
Re: Get rid of unwanted lines. [message #62324 is a reply to message #62323] Fri, 05 September 2008 14:15 Go to previous messageGo to next message
mankoff is currently offline  mankoff
Messages: 131
Registered: March 2004
Senior Member
On Sep 5, 5:07 pm, xiao <littledd...@gmail.com> wrote:
> On Sep 5, 2:34 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
> wrote:
>
>
>
>> xiao wrote:
>>> Hi~ everyone, i have some data like this:
>
>>>       1123.97      000      15.0600      000      271.850      000
>>>       000            000       000            000      000
>>> 000
>>>       1127.98      000      15.2800      000      270.650      000
>>>       000            000       000           000       000
>>> 000
>>>       1136.68      000      15.5100      000      269.300      000
>>>        000            000       000           000       000
>>> 000
>>>       1139.05      000      15.7500      000      267.860      000
>>>       000            000       000           000       000
>>> 000
>>>       000            000       000           000       000
>>> 000
>>>       000            000       000           000       000
>>> 000
>>>       000            000       000           000       000
>>> 000
>>>       1145.10      000      15.9900      000      266.410      000
>>>       1155.74      000      16.2300      000      265.010      000
>>>       1163.19      000      16.4500      000      263.700      000
>>> I want to delete these zero lines and write other lines to another
>>> file.  How can I fulfill this ?
>>> Anyone have good ideas?
>>>                       Thank you
>
>> so, do you always have 6 numbers per lines?
>
>> do something like this:
>
>> filname = 'originalFile.txt'
>> nbLines = file_lines(filename)  ;get the number of lines in the file
>> data = fltarr(nbLines) ;create an array to get all the data
>
>> openR, lun, filename, /get_lun  ;open the file
>> readf, lun, data ;get all the data
>> close,lun       ;close the file
>> free_lun,lun
>
>> ;Select the good lines, the ones that do NOT have only zeroes
>> badLines = where(data[0,*] eq 0 and data[1,*] eq 0 and data[2,*] eq 0
>> and data[3,*] eq 0 and data[4,*] eq 0 and data[5,*] eq 0, complement =
>> goodLines)
>
>> ;open and write the output!
>> openW,lun, new_fileName, /get_lun
>> printf,data[*,goodLines]
>> close,lun
>> free_lun,lun
>
>> Jean
>> PS: since you deal with float data, you might have to replace data[x,*]
>> eq 0   by  abs(data[x,0]) lt epsilon,   epsilon being a number small
>> enough to be considered as zero. Read David's Fanning website under "the
>> sky is falling".
>
> yes, it works, but another question arouse. When I have eight columns,
> after i write them to another file, these numbers are not in the same
> line.  The last two numbers are in another line like this:
>
>       964.850      0.00000      25.3800      0.00000      335.750
> 0.00000
>      0.237400      0.00000
>       964.510      0.00000      25.0400      0.00000      338.800
> 0.00000
>      0.240100      0.00000
>       964.140      0.00000      24.6500      0.00000      342.150
> 0.00000
>      0.245400      0.00000
>       963.750      0.00000      24.2800      0.00000      345.690
> 0.00000
>      0.250700      0.00000
>
> Why is that?  thx

See WIDTH keyword to OPEN command.
Re: Get rid of unwanted lines. [message #62325 is a reply to message #62324] Fri, 05 September 2008 14:07 Go to previous messageGo to next message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Sep 5, 2:34 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> xiao wrote:
>> Hi~ everyone, i have some data like this:
>
>> 1123.97 000 15.0600 000 271.850 000
>> 000 000 000 000 000
>> 000
>> 1127.98 000 15.2800 000 270.650 000
>> 000 000 000 000 000
>> 000
>> 1136.68 000 15.5100 000 269.300 000
>> 000 000 000 000 000
>> 000
>> 1139.05 000 15.7500 000 267.860 000
>> 000 000 000 000 000
>> 000
>> 000 000 000 000 000
>> 000
>> 000 000 000 000 000
>> 000
>> 000 000 000 000 000
>> 000
>> 1145.10 000 15.9900 000 266.410 000
>> 1155.74 000 16.2300 000 265.010 000
>> 1163.19 000 16.4500 000 263.700 000
>> I want to delete these zero lines and write other lines to another
>> file. How can I fulfill this ?
>> Anyone have good ideas?
>> Thank you
>
> so, do you always have 6 numbers per lines?
>
> do something like this:
>
> filname = 'originalFile.txt'
> nbLines = file_lines(filename) ;get the number of lines in the file
> data = fltarr(nbLines) ;create an array to get all the data
>
> openR, lun, filename, /get_lun ;open the file
> readf, lun, data ;get all the data
> close,lun ;close the file
> free_lun,lun
>
> ;Select the good lines, the ones that do NOT have only zeroes
> badLines = where(data[0,*] eq 0 and data[1,*] eq 0 and data[2,*] eq 0
> and data[3,*] eq 0 and data[4,*] eq 0 and data[5,*] eq 0, complement =
> goodLines)
>
> ;open and write the output!
> openW,lun, new_fileName, /get_lun
> printf,data[*,goodLines]
> close,lun
> free_lun,lun
>
> Jean
> PS: since you deal with float data, you might have to replace data[x,*]
> eq 0 by abs(data[x,0]) lt epsilon, epsilon being a number small
> enough to be considered as zero. Read David's Fanning website under "the
> sky is falling".

yes, it works, but another question arouse. When I have eight columns,
after i write them to another file, these numbers are not in the same
line. The last two numbers are in another line like this:

964.850 0.00000 25.3800 0.00000 335.750
0.00000
0.237400 0.00000
964.510 0.00000 25.0400 0.00000 338.800
0.00000
0.240100 0.00000
964.140 0.00000 24.6500 0.00000 342.150
0.00000
0.245400 0.00000
963.750 0.00000 24.2800 0.00000 345.690
0.00000
0.250700 0.00000

Why is that? thx
Re: Get rid of unwanted lines. [message #62328 is a reply to message #62325] Fri, 05 September 2008 12:34 Go to previous messageGo to next message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
xiao wrote:
> Hi~ everyone, i have some data like this:
>
> 1123.97 000 15.0600 000 271.850 000
> 000 000 000 000 000
> 000
> 1127.98 000 15.2800 000 270.650 000
> 000 000 000 000 000
> 000
> 1136.68 000 15.5100 000 269.300 000
> 000 000 000 000 000
> 000
> 1139.05 000 15.7500 000 267.860 000
> 000 000 000 000 000
> 000
> 000 000 000 000 000
> 000
> 000 000 000 000 000
> 000
> 000 000 000 000 000
> 000
> 1145.10 000 15.9900 000 266.410 000
> 1155.74 000 16.2300 000 265.010 000
> 1163.19 000 16.4500 000 263.700 000
> I want to delete these zero lines and write other lines to another
> file. How can I fulfill this ?
> Anyone have good ideas?
> Thank you

so, do you always have 6 numbers per lines?

do something like this:

filname = 'originalFile.txt'
nbLines = file_lines(filename) ;get the number of lines in the file
data = fltarr(nbLines) ;create an array to get all the data

openR, lun, filename, /get_lun ;open the file
readf, lun, data ;get all the data
close,lun ;close the file
free_lun,lun

;Select the good lines, the ones that do NOT have only zeroes
badLines = where(data[0,*] eq 0 and data[1,*] eq 0 and data[2,*] eq 0
and data[3,*] eq 0 and data[4,*] eq 0 and data[5,*] eq 0, complement =
goodLines)

;open and write the output!
openW,lun, new_fileName, /get_lun
printf,data[*,goodLines]
close,lun
free_lun,lun

Jean
PS: since you deal with float data, you might have to replace data[x,*]
eq 0 by abs(data[x,0]) lt epsilon, epsilon being a number small
enough to be considered as zero. Read David's Fanning website under "the
sky is falling".
Re: Get rid of unwanted lines. [message #62329 is a reply to message #62328] Fri, 05 September 2008 12:36 Go to previous messageGo to next message
mankoff is currently offline  mankoff
Messages: 131
Registered: March 2004
Senior Member
On Sep 5, 3:23 pm, xiao <littledd...@gmail.com> wrote:
> Hi~ everyone, i have some data like this:
>
>       1123.97      000      15.0600      000      271.850      000
>       000            000       000            000      000
> 000
>       1127.98      000      15.2800      000      270.650      000
>       000            000       000           000       000
> 000
>       1136.68      000      15.5100      000      269.300      000
>        000            000       000           000       000
> 000
>       1139.05      000      15.7500      000      267.860      000
>       000            000       000           000       000
> 000
>       000            000       000           000       000
> 000
>       000            000       000           000       000         000
>       000            000       000           000       000         000
>       1145.10      000      15.9900      000      266.410      000
>       1155.74      000      16.2300      000      265.010      000
>       1163.19      000      16.4500      000      263.700      000
> I want to delete these zero lines and write other lines to another
> file.  How can I fulfill this ?
> Anyone have good ideas?
>                       Thank you

Which zero lines? The ones that start with them and have nothing else,
or the ones that have a bnuch of zeros and spaces? Or both?

How about this, outside of IDL:

% grep [^0\ ] file_with_zeros > file_without_zeros

-k.
Re: Get rid of unwanted lines. [message #62420 is a reply to message #62323] Fri, 05 September 2008 15:10 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
xiao wrote:
> On Sep 5, 4:15 pm, mankoff <mank...@gmail.com> wrote:
>> On Sep 5, 5:07 pm, xiao <littledd...@gmail.com> wrote:
>>
>>
>>
>>> On Sep 5, 2:34 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
>>> wrote:
>>>> xiao wrote:
>>>> > Hi~ everyone, i have some data like this:
>>>> > 1123.97 000 15.0600 000 271.850 000
>>>> > 000 000 000 000 000
>>>> > 000
>>>> > 1127.98 000 15.2800 000 270.650 000
>>>> > 000 000 000 000 000
>>>> > 000
>>>> > 1136.68 000 15.5100 000 269.300 000
>>>> > 000 000 000 000 000
>>>> > 000
>>>> > 1139.05 000 15.7500 000 267.860 000
>>>> > 000 000 000 000 000
>>>> > 000
>>>> > 000 000 000 000 000
>>>> > 000
>>>> > 000 000 000 000 000
>>>> > 000
>>>> > 000 000 000 000 000
>>>> > 000
>>>> > 1145.10 000 15.9900 000 266.410 000
>>>> > 1155.74 000 16.2300 000 265.010 000
>>>> > 1163.19 000 16.4500 000 263.700 000
>>>> > I want to delete these zero lines and write other lines to another
>>>> > file. How can I fulfill this ?
>>>> > Anyone have good ideas?
>>>> > Thank you
>>>> so, do you always have 6 numbers per lines?
>>>> do something like this:
>>>> filname = 'originalFile.txt'
>>>> nbLines = file_lines(filename) ;get the number of lines in the file
>>>> data = fltarr(nbLines) ;create an array to get all the data
>>>> openR, lun, filename, /get_lun ;open the file
>>>> readf, lun, data ;get all the data
>>>> close,lun ;close the file
>>>> free_lun,lun
>>>> ;Select the good lines, the ones that do NOT have only zeroes
>>>> badLines = where(data[0,*] eq 0 and data[1,*] eq 0 and data[2,*] eq 0
>>>> and data[3,*] eq 0 and data[4,*] eq 0 and data[5,*] eq 0, complement =
>>>> goodLines)
>>>> ;open and write the output!
>>>> openW,lun, new_fileName, /get_lun
>>>> printf,data[*,goodLines]
>>>> close,lun
>>>> free_lun,lun
>>>> Jean
>>>> PS: since you deal with float data, you might have to replace data[x,*]
>>>> eq 0 by abs(data[x,0]) lt epsilon, epsilon being a number small
>>>> enough to be considered as zero. Read David's Fanning website under "the
>>>> sky is falling".
>>> yes, it works, but another question arouse. When I have eight columns,
>>> after i write them to another file, these numbers are not in the same
>>> line. The last two numbers are in another line like this:
>>> 964.850 0.00000 25.3800 0.00000 335.750
>>> 0.00000
>>> 0.237400 0.00000
>>> 964.510 0.00000 25.0400 0.00000 338.800
>>> 0.00000
>>> 0.240100 0.00000
>>> 964.140 0.00000 24.6500 0.00000 342.150
>>> 0.00000
>>> 0.245400 0.00000
>>> 963.750 0.00000 24.2800 0.00000 345.690
>>> 0.00000
>>> 0.250700 0.00000
>>> Why is that? thx
>> See WIDTH keyword to OPEN command.
>
> Thank you ,very much. it works. But when i read these files again in
> the same program like this:
>
>
> OPENr,3, 'sdata1.eol'
> OPENr,4, 'wdata1.eol'
>
> subsdata=fltarr(levlesforp,8)
> subwdata=fltarr(levlesforh,6)
>
> READF,3,subsdata
> readf,4, subwdata
>
> it always says, end of file encountered. levlesforp and levlesforh
> are exactly the lines of the file generated last step. eight and six
> are the column number, why is that?
>

I guess you are using the number of lines from the original file. Now
you are reading the new file with less lines. There is not enough lines
to "feed" the array!
Do levlesforp = file_lines(sdata1.eol) before

jean
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: weighting: irregular grid
Next Topic: Re: Matching Lats and Lons from two arrays

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

Current Time: Wed Oct 08 13:34:29 PDT 2025

Total time taken to generate the page: 0.00714 seconds