On Sep 5, 5:10 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> 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
Thank you ~ :)
|