Madagascar是著名的開源的地震資料處理工具包,基本可以代替古老的Seismic Unix用于學(xué)習(xí)和科研任務(wù)。Madagascar所有工具包都通過命令行界面交互,而完成一個(gè)研究項(xiàng)目,往往需要諸多步驟,執(zhí)行大量命令。雖然也可以考慮將命令寫入Shell腳本,但Madagascar提供了一種更加完善解決辦法,那就是將操作寫入SCons腳本,并使用SCons軟件自動(dòng)執(zhí)行。
SCons is an Open Source software construction tool—that is, a next-generation build tool. Think of SCons as an improved, cross-platform substitute for the classic Make utility with integrated functionality similar to autoconf/automake and compiler caches such as ccache. In short, SCons is an easier, more reliable and faster way to build software.
執(zhí)行SCons腳本十分簡(jiǎn)單,只要建立名為SConstruct的字符文件,在該文件所在的目錄中執(zhí)行scons命令,就能夠讓SCons代替人工自動(dòng)執(zhí)行處理操作了。

基本語法
SCons使用Python作為其腳本語言,SConstruct腳本文件實(shí)際上相當(dāng)于一個(gè)Python腳本,由于Python的基本語法簡(jiǎn)單易學(xué),因而不需要專門學(xué)習(xí)Python編程語言也可以輕松使用,同時(shí),Python能夠?qū)崿F(xiàn)復(fù)雜的邏輯,使得使用SCons腳本這種方式具有處理復(fù)雜任務(wù)的能力。
四種SCons腳本命令
為了讓SCons執(zhí)行Madagascar命令,專門為其設(shè)計(jì)了四個(gè)基本函數(shù):
-
Fetch(獲取數(shù)據(jù)) -
Flow(執(zhí)行處理) -
Plot(繪制圖鑒) -
Result(輸出圖鑒)
這些函數(shù)定義了,文件與Madagascar命令的關(guān)系。
Flow
顯然,F(xiàn)low函數(shù)是其中最為核心的部分。其語法可以表示為:
Flow(output file, input file, command)
三個(gè)參數(shù)的類型都是字符串,最后的command字符中包含要執(zhí)行的Madagascar命令和其相應(yīng)的參數(shù)。
例如:
Flow("spike1","spike","scale dscale=4.0")
一個(gè)Flow命令就構(gòu)建了輸出文件、輸入文件、所執(zhí)行命令之間的關(guān)系,定義了一個(gè)操作步驟。相對(duì)應(yīng)的Madagascar命令行為:
< spike.rsf sfscale dscale=4.0 > spike1.rsf
注意:Flow函數(shù)的參數(shù)中,文件名不需要加后綴
Plot和Result
Plot和Result兩個(gè)函數(shù)負(fù)責(zé)執(zhí)行繪圖命令,它們的區(qū)別在于,Plot將生成的vpl文件保存在當(dāng)前工作路徑下,而Result則會(huì)將vpl文件保存在當(dāng)前路徑下的一個(gè)Fig文件夾中,以便使用Latex創(chuàng)建論文時(shí)使用。
它們的語法類似:
Plot(input file, command)
Result(input file, command)
這兩個(gè)函數(shù)接受指定的輸入文件,執(zhí)行指定繪圖命令,例如如果要生成一個(gè)數(shù)據(jù)文件的圖鑒,可以使用:
Plot("spike1", "sfgraph pclip=100")
這樣SCons就會(huì)知道我們要利用spike1.rsf數(shù)據(jù)文件使用sfgraph創(chuàng)建圖鑒spike1.vpl
SConstruct基本結(jié)構(gòu)
from rsf.proj import * # Remember, this statement comes first... ALWAYS
Flow("spike",None,"sfspike n1=100 k1=50") # None is a trick, see Advanced SCons for more information
Flow("spike1","spike","sfadd scale=4.0")
Flow("noise","spike1","sfnoise")
Plot("spike",'sfgraph title="spike" ' ) # Note string nesting
Plot("spike1",'sfgraph title="spike1" ')
Plot("noise",'sfgraph title="noisy" ')
Result("noise",'sfgraph title="noisy" pclip=75 ')
End() # Remember, this always ends the script.