2016-09-21 9 views
-3

Unixシステム上で以下のような出力を解析して集計する簡単で柔軟な方法は何ですか?結果を解析し集計する

出力は、次の形式で複数のエントリを持っています

===================================================== 
====== SOLVING WITH MATRIX small_SPD ==== 
=================================================== 

sizes: 5,5,8 

Solving with Sparse LU AND COLAMD ... 
COMPUTE TIME : 8.9287e-05 
SOLVE TIME : 1.0663e-05 
TOTAL TIME : 9.995e-05 
REL. ERROR : 2.30263e-18 


Solving with BiCGSTAB ... 
COMPUTE TIME : 4.113e-06 
SOLVE TIME : 1.853e-05 
TOTAL TIME : 2.2643e-05 
REL. ERROR : 1.34364e-10 

ITERATIONS : 2 

これは、として(または類似の)表にする必要があります。

Matrix  Sizes   Solver    Compute Solve   Total  Rel Error 
small_SPD 5,5,8 Sparse LU AND COLAMD 8.9287e-05 1.0663e-05 9.995e-05 2.30263e-18 
small_SPD 5,5,8  BiCGSTAB   4.113e-06 1.853e-05 2.2643e-05 1.34364e-10 
+2

ここに結果をどのように構築しましたか? – KeepCalmAndCarryOn

+0

'.split'、' .strip'、 '.startswith'のような標準の' str'メソッドを使って、これをPythonで行うのは簡単です。あなたが立ち往生した場合は、あなたのコードを投稿し、特定の問題を説明してください。 –

+1

@PM2Ringはい、しかし、以下の答えが示すように、私が探していたものであるperlでそれを行うためのより良い、より柔軟な方法があります。私はそれをする方法を尋ねませんでしたが、最も簡単で最も柔軟な方法は何ですか。 –

答えて

1

あなただけの出力を解析している場合、私は思いますこのようにそれに取り組む:

#!/usr/bin/env perl 
use strict; 
use warnings; 

#set paragraph mode - look for empty lines between records. 
local $/ = ''; 

#init the matrix/size vars. 
my $matrix; 
my $sizes; 

#output order  
my @columns = ("COMPUTE TIME", "SOLVE TIME", "TOTAL TIME", "REL. ERROR"); 

#Column headings. 
print join "\t", "matrix", "sizes", "solver", @columns,"\n"; 

#iterate the data. 
#note - <> is a magic file handle that reads STDIN or 'files specified on command line' 
#that's just like how sed/grep/awk do it. 
while (<>) { 
    #find and set the matrix name 
    #note conditional - this only appears in the 'first' record. 
    if (m/MATRIX (\w+)/) { 
     $matrix = $1; 
    } 
    #find and set the sizes. 
    if (m/sizes: ([\d\,]+)/) { 
     $sizes = $1; 
    } 
    #multi-line pattern match to grab keys and values. 
    #this then maps neatly into a hash. 
    my %result_set = m/^(\w+).*: ([\d\.\-e]+)/gm; 

    #add the solver to the 'set': 
    #and use this test to check if this 'record' is of interest. 
    #skipping the "ITERATIONS" line. 
    my ($solver) = m/Solving with (.*) .../ or next; 
    #print it tab separated. 
    print join "\t", $matrix, $sizes, $solver, @result_set{@columns}, "\n"; 
} 

出力:

matrix sizes solver Compute Solve Total Rel Error 
small_SPD 5,5,8 Sparse LU AND COLAMD 8.9287e-05 1.0663e-05 9.995e-05 2.30263e-18 
small_SPD 5,5,8 BiCGSTAB 4.113e-06 1.853e-05 2.2643e-05 1.34364e-10 

一部のアプリケーションではおそらく便利ですが、代わりにprintfまたはformatを入力してください。

+0

thxこれはまさに私が探していたものです。これは非常に柔軟性があり、他の状況にも容易に拡張できるからです –