如何使用tcl读取和执行定点值计算

如何使用tcl读取和执行定点值计算,tcl,point,Tcl,Point,我想用tcl阅读下面的文件: BEGIN %Time (real) HG (real) !Time HG -0.000110400001 0.6 -0.000110399901 0.6 -0.000110399801 0.6 -0.000110399701 0.6

我想用tcl阅读下面的文件:

        BEGIN
        %Time (real)        HG (real)
        !Time               HG

        -0.000110400001          0.6
        -0.000110399901          0.6
        -0.000110399801          0.6
        -0.000110399701          0.6
        -0.000110399601         0.55
        -0.000110399501          0.5
        -0.000110399401         0.45
        -0.000110399301          0.4
        -0.000110399201         0.45
        -0.000110399101          0.5
        -0.000110399001         0.55
        -0.000110398901          0.6
对于每个时间列,我希望增加+0.00011040001,并将此结果写入新文件。我想其他列不被修改和复制这样

我开始编码(见下文),我可以打开并读取值,但我不知道如何在定点转换字符串并在此基础上进行加法。如果有人帮我,那就太好了

set inVector  [lindex $argv 0]

puts "input vector : $inVector"

set filename "resultat.mdf"

set fileId [open $filename "w"]

set PROCESSING_FILE [open "$inVector" r]

while {[eof $PROCESSING_FILE]==0} {
    set string [gets $PROCESSING_FILE]
    if {[string index $string 3] != "B"} {
        if {[string index $string 3] != "%"} {
            if {[string index $string 3] != "!"} {
                foreach line $string {
                    puts "input value : $line"
                }
            } else {
              puts $fileId $string
            }

        } else {
            puts $fileId $string
        }
    } else {
      puts $fileId $string
    }
}


close $PROCESSING_FILE
close $fileId

对于打开数字的行,您可能可以这样读取:

scan $string "%f %f" time hg
如果返回2(对于已处理的两个字段),则您已经成功地从该行读取了两个(浮点)数字。否则,这条线是另一条线。这就产生了这样的代码(使用一些标准的逐行习惯用法,这些习惯用法一定已经在其他问题中编写好了):


对于具有真正固定宽度字段的文件,可以使用
stringrange
挑出行中的片段,然后尝试解析这些片段(或者编写一个凌乱的正则表达式并使用
regexp
)。这些往往需要对数据进行更多调整。

欢迎使用。请将
testvector
我所做的代码
粘贴到问题中,以便于复制和粘贴到答案中。来自tcllib的包可能会有所帮助。文本图片不会帮助我们帮助您。完成后,我将代码放入问题中。耐心的坦克,我是新来的
# Skipping all the code for opening files

# While we successfully read a line from the input file
while {[gets $PROCESSING_FILE line] >= 0} {
    # Attempt to parse two floats (with at least one whitespace between) out of line
    if {[scan $line "%f %f" time hg] == 2} {
        # Action to take on a matched line
        puts "input line: '$line' time:$time HG:$hg"
    } else {
        # Action to take on an unmatched line
        puts $fileId $line
    }
}

# Skipping the code for closing files