0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SAC ASCIIファイルをawkで時間ー振幅のファイルにする

0
Last updated at Posted at 2026-01-28

更新履歴
2026-01-28 微修正:Genetic Mapping Toolsの略称追加/awkスクリプトのデバグ用の行を削除


Seismic Analysis Code (SAC) ファイルの波形をGenetic Mapping Tools (GMT) で描きたい時がある。SACファイルはバイナリーだが、アスキーファイルに変換できる。

sac
 SEISMIC ANALYSIS CODE [09/01/2020 (Version 102.0)]
 Copyright 1995 Regents of the University of California

SAC> r sample.sac
SAC> w alpha append .asc
sample.sac.asc
SAC> q

データフォーマットは次のページで解説されている。
https://ds.iris.edu/files/sac-manual/manual/file_format.html

これを awk で時間、振幅のデータに変換する。awkスクリプトは次の通り。

#!/usr/bin/awk -f
BEGIN{
    # it: increment for time
    it=0;
}
{
    if(NR==1){
        # DELTA: samping period
        DELTA=$1;
    }
    if(NR==2){
        # B: begin time
        # E: end time
        B=$1;
        E=$2;
    }
    if(NR>30){
        for(i=1; i<=NF; i++){
            # $i: amplitude
            print B+it*DELTA, $i;
            ++it;
        }
    }
}
END{
    if(B+(it-1)*DELTA != E){
        # check for end time
        print "Warning: E=", E;
    }
}

これを例えばsacasc2xy.awkというファイル名に保存すると、次の形でコマンドを実行する。

awk -f sacasc2xy.awk sample.sac.asc > sample.xy

このsample.xyを使えばGMTで波形の図が描ける。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?