ソフトウェア/Igor のバックアップ(No.2)

更新


公開メモ

Igor とは

データ解析に Wave Metrics 社の Igor Pro を使っています。

なかなか癖のあるソフトですが、 Igor 上でプログラムを組むことでかなり複雑なデータ解析も自動化できていろいろ捗ります。

ここには使い回しの効きそうなコード例を上げていこうと思います。

公式のオンラインヘルプはこちら: http://www.hulinks.co.jp/support/igor/programming/index.html

分野別記事へのリンク

あるグラフ上に表示されたウェーブの一覧を表示する

LANG:Igor
string graph_name = "Graph1"
string traces = TraceNameList(graph_name, ";", 1)
variable i
for(i = ItemsInList(traces) - 2; i>=0; i-=1)
    print StringFromList(i, traces)
endfor

画像の一覧なら、TraceNameList ではなく ImageNameList を呼べばいい。

LANG:Igor
string graph_name = "Graph1"
string images = ImageNameList(graph_name, ";", 1)
variable i
for(i = ItemsInList(images) - 2; i>=0; i-=1)
    print StringFromList(i, images)
endfor

グラフウィンドウ上の選択領域を得る

グラフ上をマウスで斜めにドラッグすると矩形領域を選べますが、 この範囲を Igor では Marquee と呼んでいます。

使用例

LANG:Igor
// 与えられた座標がグラフの選択領域に含まれているかどうか返す
function IsPointInSelectedRegion(x, y)
variable x, y

    string graph_name = "Graph1"

    struct Rectangle selected_region
    GetMarqueeRegion(graph_name, selected_region)

    return IsPointInRect(x, y, selected_region)
end

コード

LANG:Igor
// 矩形領域を格納するための構造体
Structure Rectangle
    double left
    double right
    double top
    double bottom
EndStructure

// 指定された名前のグラフから選択範囲を得る
// 選択されていなければ全範囲 (left, bottom 軸で) を返す
function GetMarqueeRegion(graph_name, region)
string graph_name
Struct Rectangle &region

    GetMarquee/W=$graph_name left, bottom
    if(!V_Flag)
        GetAxis/q/W=$graph_name bottom
        V_Left   = V_min
        V_Right  = V_max
        GetAxis/q/W=$graph_name left
        V_Top    = V_min
        V_Bottom = V_max
    endif

    region.left = V_Left
    region.right = V_Right
    region.top = V_Top
    region.bottom = V_Bottom
end

// x, y で指定された点が rect 領域に入っているかどうかを返す 
function IsPointInRect(x, y, rect)
variable x, y
Struct Rectangle &rect
    variable result
    result = rect.left <= x
    result = x <= rect.right   && result
    result = rect.top <= y     && result
    result = y <= rect.bottom  && result
    return result
end

Counter: 14238 (from 2010/06/03), today: 1, yesterday: 3