2011年8月13日 星期六

FAST installation on Linux

First Arrival Seismic Tomography(FAST)是一隻能夠計算二維/三維first arrival tomography的小程式,雖然他已經13歲了(1998年first release),不過到現在還是非常實用。 請下載FAST主程式,也必須下載for g77的patch檔
請注意這個patch檔(十分感謝Drew Brenders提供這個patch)是必要的,因為作者Colin Zelt當初是在Sun Solaris上開發這隻程式的,沒有這個patch檔將無法在linux上成功編譯。

1. 準備好編譯器以及所需的libraries

  • For Debian/Ubuntu users:
  • aptitude install fort77 libf2c make -y
    ln -s /usr/bin/f77 /usr/bin/g77
  • For CentOS/Fedora users:
  • 以我自己的Fedora14為例,套件名稱會像下面這樣:
    yum install compat-libf2c-34 compat-gcc-34-g77-3.4.6-20.fc14.i686 make -y
    ln -s /usr/bin/g77 /usr/bin/f77
    ln -s /usr/lib/libg2c.so.0 /usr/lib/libf2c.so.2
    如果你的版本不同,你需要用yum search找確切的套件名稱。你或許會發現兩套linux對於fortran77的稱呼剛好相反。
  • For OpenSuSE users:
  • 以我自己的OpenSuSE 11.4為例,套件名稱會像下面這樣:
    yum install -y gcc33-fortran make libg2c33
    ln -s /usr/bin/g77-3.3 /usr/bin/g77
    ln -s /usr/bin/g77-3.3 /usr/bin/f77
    ln -s /usr/lib/libg2c.so.0 /usr/lib/libf2c.so.2

2. 下載FAST以及其patch

cd ; http://terra.rice.edu/department/faculty/zelt/fast.tar.gz
wget -c http://terra.rice.edu/department/faculty/zelt/fast_g77_patch.tar.gz
tar zxvf fast.tar.gz && mv fast fast_g77
tar zxvf fast_g77_patch.tar.gz
rsync -av fast/2d_example_linux/ fast_g77/2d_example/

3. 開始編譯:
我覺得COMPILE_FAST.csh實在寫得很爛,決定寫一個更好一點的script,所以在此先刪除他。

cd fast
rm -f COMPILE_FAST.csh
patch -p0 < fast_g77.diff
打完patch應該顯示下列結果:
patching file ../fast_g77/fd/fd.com
patching file ../fast_g77/fd/fd.par
patching file ../fast_g77/fd/findiff.f
patching file ../fast_g77/fd/main.f
patching file ../fast_g77/fd/Makefile
patching file ../fast_g77/fd/misc.f
patching file ../fast_g77/misc/1dvel2.f
patching file ../fast_g77/misc/1dvel.f
patching file ../fast_g77/misc/2dvel.f
patching file ../fast_g77/misc/add2.f
patching file ../fast_g77/misc/add.f
patching file ../fast_g77/misc/ave2.f
patching file ../fast_g77/misc/ave4.f
patching file ../fast_g77/misc/ave.f
patching file ../fast_g77/misc/difference2.f
patching file ../fast_g77/misc/difference.f
patching file ../fast_g77/misc/gmtslice_2d.f
patching file ../fast_g77/misc/gmtslice.f
patching file ../fast_g77/misc/gmtslicep.f
patching file ../fast_g77/misc/h2z.f
patching file ../fast_g77/misc/inverse_2d.f
patching file ../fast_g77/misc/inverse.f
patching file ../fast_g77/misc/lambda3.f
patching file ../fast_g77/misc/latave.f
patching file ../fast_g77/misc/ray.par
patching file ../fast_g77/misc/real2int.f
patching file ../fast_g77/misc/rec_ascii.f
patching file ../fast_g77/misc/rec_binary.f
patching file ../fast_g77/misc/rec_deci.f
patching file ../fast_g77/misc/rec_diff.f
patching file ../fast_g77/misc/rec_noise2.f
patching file ../fast_g77/misc/rec_noise.f
patching file ../fast_g77/misc/rec_offset.f
patching file ../fast_g77/misc/regrid_2d.f
patching file ../fast_g77/misc/regrid.f
patching file ../fast_g77/misc/resamp.f
patching file ../fast_g77/misc/smodel.f
patching file ../fast_g77/misc/vz.f
patching file ../fast_g77/misc/z2h.f
patching file ../fast_g77/ray/blkdat.f
patching file ../fast_g77/ray/main.f
patching file ../fast_g77/ray/Makefile
patching file ../fast_g77/ray/ray.com
patching file ../fast_g77/ray/ray.par
patching file ../fast_g77/ray/tomo.f
patching file ../fast_g77/zslice/main.f
patching file ../fast_g77/zslice/Makefile
If you're using Fedora, patching will be failed because Fedora have security concern about command "patch". The easiest solution is to copy patch from other Linux, and replace original patch. 由於個人因素,我覺得作者的Makefile寫得很不好,因此我自己寫了一個小script,開始進行自動編譯:
cd ../fast_g77
find . -name Makefile -exec rm {} \;
bash COMPILE_FAST.sh
The script "COMPILE_FAST.sh" is hiding in the source code of this article. 這個COMPILE_FAST.sh威力強大,能自動產生正確的Makefile並進行編譯(if you can't download the script from it, check the source code of this page)。通常只有misc資料夾下的小程式會出現問題,你可以參考misc.log來檢視是否有任何錯誤發生,而這類fortran的問題我無法解決。如果有編譯上的困難,請千萬不要問我,我很討厭fortran。

4. 設定環境變數:
至此你已經完成編譯。現在你只需要把這東西放到/opt裡,再設定環境變數即可:

cd ..; rsync -av fast_g77 /opt/
新增(append)幾行到/etc/profile裡:
export FAST="/opt/fast_g77"
export PATH="$PATH:$FAST/bin"
   
然後重新登入(re-login),就可以快樂的使用這些指令了。關於fast的操作,請參考Traveltime calculation using FAST.

Share this Link

2011年7月28日 星期四

Wanna use zplot? Give up!!

If you concern about Rayinvr, you can probably find out there is a program named zplot. It's 20-years-old already, so you can never compile it successfully without modifying those codes.

I've been trying compiling zplot for 2 days, I failed on all Linux distributions. I tried to email to Dr. Zelt about the issue, and these are his reply:

As my web page clearly states, I do not help people install the code on their computers, since I don't know
about such things.

But have a look at the Linux patch on my rayinvr web page, maybe it will help you.

http://terra.rice.edu/department/faculty/zelt/rayinvr.html
My reply is:
Hi Prof. Zelt,
Thanks for your answer.

I've read your pages three times, fully understood what are provided by the page, then asked your help.

The linux patch wrote by Scott is to modify your fortran 77 code and Makefile, it works on rayinvr to make sure the syntax can be recognized by f77/f2c compiler in modern Linux systems, and it doesn't help with zplot at all.

I'm not a student nor a researcher, I'm just a linux admin and java programmer and try to help both seismic program authors and users. The more people know and use your program, the more feedback and fame you have. If a user can't even compile it, probably there is no future story.

Last night I spent three hours to check the error messages from f77 in all linux distributions, I'm not a f77 expert but I knew it due to the syntax of codes, and I don't understand fortran at all. Just hope if Dr. Scott and you would help us through this if you are available.

Thankyou.
And his reply was pretty powerful:
Sorry, I've already told you I don't know how to help you, and I don't have the time.
I do not know much about fortran compilers or makefiles.

This code has been available for 20 years, I am not concerned about its future.

My suggestion is to google search for other rayinvr users, and ask them for help.

Good luck.

So give up! Don't waste your time on it. Zplot's already dead since the author gave it up.

這就是標準的科學家阿,如果你的程式有人用,就不會20年程式碼不變了...恐怕該google的是他吧(茶)

Share

2011年7月27日 星期三

Rayinvr installation on Linux

Rayinvr是一隻能夠計算二維走時以及振幅modeling的小程式,相信許多玩RayGUI的朋友都知道他。只是許多人只是想要用這隻程式,並不想要真正用到這麼大型的程式。你可以下載Rayinvr原始碼,或是直接連到Rayinvr的網頁

不過因為大部分的使用者並不能成功編譯這隻程式。主要原因當然是萬惡的Fortran77,而作者也只靠fortran77來撰寫程式,這使得許多人沒有如此老舊的編譯器及古董級函式庫,根本無法成功編譯或執行。有些人退而求其次試用intel的fortran編譯器,可是這會變得讓程式只能在自己的系統上跑,我非常不贊成用這類型的編譯器。幸好Scott Pearse救了作者 Colin Zelt一命 -- Scott寫了一個patch讓新一代的地球物理學家也能使用這隻程式,本文的目的就是紀錄這隻程式如何使用,並幫助各位成功安裝rayinvr。

1. 準備好編譯器以及所需的libraries

  • For Debian/Ubuntu users:
  • aptitude install fort77 libf2c -y
    ln -s /usr/bin/f77 /usr/bin/g77
  • For CentOS/Fedora users:
  • 以我自己的Fedora14為例,套件名稱會像下面這樣:
    yum install compat-libf2c-34 compat-gcc-34-g77-3.4.6-20.fc14.i686 -y
    ln -s /usr/bin/g77 /usr/bin/f77
    ln -s /usr/lib/libg2c.so.0 /usr/lib/libf2c.so.2
    如果你的版本不同,你需要用yum search找確切的套件名稱。你或許會發現兩套linux對於fortran77的稱呼剛好相反。

2. 下載rayinvr以及patch

cd ; wget -c http://terra.rice.edu/department/faculty/zelt/rayinvr.tar.gz
wget -c http://terra.rice.edu/department/faculty/zelt/rayinvr_g77_patch.tgz
tar zxvf rayinvr.tar.gz && tar zxvf rayinvr_g77_patch.tgz
cp rayinvr_g77_patch/rayinvr_g77.diff rayinvr_g77_patch/build_all.bash rayinvr/

3. 開始編譯:

cd rayinvr/
sed -i 's/usr\/X11R6\/lib/usr\/lib\/X11/g' rayinvr_g77.diff
sed -i 's/usr\/X11R6\/include\/X11/usr\/include\/X11/g' rayinvr_g77.diff
patch -p0 < rayinvr_g77.diff
打完patch應該顯示下列結果:
patching file misc/iseis.f
patching file misc/order_picks.f
patching file misc/phercount.f
patching file misc/reciprocity2.f
patching file misc/reciprocity.f
patching file misc/resample.f
patching file misc/smooth_picks.f
patching file misc/tx2pois.f
patching file misc/tx2rec.f
patching file misc/txmatch.f
patching file misc/txoffset2.f
patching file misc/txoffset.f
patching file misc/txphase.f
patching file misc/txshift.f
patching file misc/vex.f
patching file misc/xshot.f
patching file pltlib/pltlib.f
patching file pltsyn/Makefile
patching file pltsyn/pltsec.f
patching file rayinvr/main.f
patching file rayinvr/Makefile
patching file rayinvr/plt.f
patching file rayinvr/rngkta.f
patching file rayinvr/trc.f
patching file rayplot/Makefile
patching file rayplot/rayplot.f
patching file tramp/amp.f
patching file tramp/Makefile
patching file tramp/plt.f
patching file tramp/rngkta.f
patching file tramp/trc.f
patching file vmodel/Makefile
patching file vmodel/plt.f
另外建議大家額外在補個增加解析度的patch上來:
wget -c http://seismic.ocean.dal.ca/pwp_wiki/static/upload/rayinvr_hiprecision.diff
patch -p0 < rayinvr_hiprecision.diff
打完patch正常結果應該如下:
patching file read.me.precision
patching file vmodel/vmodel.par
patching file vmodel/main.f
patching file rayinvr/main.f
patching file rayinvr/rayinvr.par
patching file misc/v2c.com
patching file misc/v2c.par
patching file misc/rayinvr.par
patching file misc/v2c.f
patching file misc/c2v.f
patching file misc/README
patching file misc/dmplstsqr.f
patching file examples/setup9
patching file examples/d9.in
patching file examples/tx9.in
patching file examples/r9.in
patching file examples/v9.in
patching file examples/vm9.in
開始進行自動編譯:
mkdir bin
./build_all.bash | tee rayinvr.log 2>&1
你可以參考rayinvr.log來檢視是否有任何錯誤發生。如果有,請把這個log寄給Colin Zelt,然後他會告訴你:『I do not help people install the code on their computers, since I don't know about such things.』。也千萬不要寄給我,我很討厭fortran。

4. 設定環境變數:
至此你已經完成編譯。現在你只需要把這東西放到/opt裡,再設定環境變數即可:

cd ..; rsync -av rayinvr /opt/
新增(append)幾行到/etc/profile裡:
export Rayinvr="/opt/rayinvr"
export PATH="$PATH:$Rayinvr/bin"
			
然後重新登入(re-login),就可以快樂的使用這些指令了。關於rayinvr的操作,請參考射線追縱法與時間反演法的使用

後記:
1. I HATE fortran...想退休了,不想在寫文章描述如何debug該死的fortran。拜託新一代的地球物理學家,麻煩好好學fortran以外的語言...別葬送你們的青春在fortran上!
2. Fedora的使用者跑到patch -p0 < rayinvr_g77.diff可能會出現下列錯誤:

patch: **** rejecting target file name with ".." component: ../rayinvr_g77/misc/iseis.f
原因或許出在先前有cracker利用patch漏洞可任意使用../..來當作檔案路徑,理論上這應該是所有linux的問題,但只有Fedora出現,恐怕真的是Fedora比較安全@@...
解決的方法很簡單,從非Fedora的linux上複製/usr/bin/patch給Fedora服用即可。
3. 至於另一個程式zplot,請參考Wanna use zplot? Give up!!一文。

Share

2011年6月26日 星期日

SEISAN on Linux安裝筆記

SEISAN(SEISmic ANalysis system)是挪威的Bergen大學地科系所開發出來的一套完整地震分析程式組,套用目前IT的語言,他類似一套地震分析的framework;白話而言,SEISAN試圖包含所有地震學可能會用到的工具集於一身,裡面有focmec,有wkbj工具,有hyp(看起來像是hypoDD之類的重新定位程式),可以分析數位或是類比的地震資料。(脫離地球物理領域太久,都不太知道如何介紹這個好程式了!)作者提供了所有平台的版本(FreeBSD或許可以用solaris的版本試著編譯),包含Linux, Solaris, MacOSX(intel), MacOSX(ppc)以及windows版本,本文則是針對在linux的環境下編譯並設定的筆記。

  1. 取得最新版本的SEISAN
  2. 請到ftp://ftp.geo.uib.no/pub/seismo/SOFTWARE/SEISAN/取得適合你平台的package來安裝,以32bits的linux為例,你應該要下載seisan_v9.0.1_linux_32bit.tar.gz這個檔案。
  3. 安裝gfortran以及X11函式庫
  4. Debian/Ubuntu系列:
    aptitude install gfortran libX11-dev -y
    Fedora/CentOS系列:
    yum install gcc44-gfortran libX11-devel -y
    OpenSuSE/SLES系列:
    zypper in -y gcc-fortran xorg-x11-devel
  5. 解壓縮檔案

  6. 有些科學家似乎連tar跟tar.gz都搞不清楚。這個下載完成的檔案,你看他的檔名是tar.gz,於是你認為他是一個tar+gzip的檔案。其實她只是一個tar的檔案:
    file seisan_v9.0.1_linux_32bit.tar.gz
    seisan_v9.0.1_linux_32bit.tar.gz: POSIX tar archive (GNU)
    所以這壓根不是tar.gz,只是一個普通的tarball而已。真正的tar.gz其訊息應該是這樣:
    file seisan_v9.0_linux_32bit.tar.gz
    seisan_v9.0_linux_32bit.tar.gz: gzip compressed data, was "seisan_v9.0_linux_32bit.tar", from Unix, last modified: Tue Mar 1 16:52:15 2011
    所以解不開或是解開後有錯誤訊息很正常,因為你被檔名誤導了。版本在9.0的時候還沒這麼荒誕的錯誤,如果不小心點真的會被搞死。
    假設你要安裝seisan的目的地為/opt/SEISAN901:
    mv seisan_v9.0.1_linux_32bit.tar.gz seisan_v9.0.1_linux_32bit.tar
    sudo mkdir /opt/SEISAN901
    sudo tar xvf seisan_v9.0.1_linux_32bit.tar -C /opt/SEISAN901
  7. 修改COM/SEISAN.bash
  8. 修改下列變數:
    export SEISARCH="gfortran"
    export SEISAN_TOP="/opt/SEISAN_v901"
    			
  9. 修改~/.profile
  10. 新增兩行到~/.profile這個檔案(CentOS/Fedora則是~/.bash_profile)
    export SEISAN="/opt/SEISAN901"
    source /opt/SEISAN901/COM/SEISAN.bash
    稍候會用到root身份編譯,因此先用root身份export SEISAN變數到環境變數裡:
    sudo source /opt/SEISAN901/COM/SEISAN.bash
  11. 修改PRO/Makefile
  12. 修改下列變數:
    INSTALL_PRO_PATH = /opt/SEISAN901/PRO
    xlink_gfortran = -lX11 -L/usr/lib/X11
  13. 產生libmseed.a
  14. cd /opt/SEISAN901/SUP
    sudo tar zxvf libmseed-2.5.1.tar.gz -C ../LIB
    cd ../LIB/libmseed
    sudo make
  15. 修改DAT/SEISAN.DEF
  16. 修改下列變數:
    WAVEFORM_DIRS      Waveform drectory    /opt/SEISAN901/WOR/seisnet
    TEXT_PRINT               Unix example   lpr -Plp1
    INIT_IMGMAP_FILE         PC example     /opt/SEISAN901/DAT/IMGWORLD.gif
    IMGMAP_PATH              PC example     /opt/SEISAN901/DAT/IMGMAP
    INTERNET_BROWSER         Unix example   /usr/bin/google-chrome
    ACROBAT_READER           Unix example   /usr/bin/acroread
    HELP_DIR                 PC   example   /opt/SEISAN901/INF
  17. 進行最後編譯
  18. 雖然9.0.1版在PRO目錄下已經有許多編譯好的binaries,不過由於作者在編譯時的環境跟我們的環境未必相同,因此容易遇到遺失libgfortran.so.1這類訊息,因此還是要自行重新編譯。先前的準備工作就是為了能夠成功編譯,快樂的開始吧!
    sudo make all
    此時可以檢查程式是否可以執行,試著輸入seigmt看看有沒有 Nordic input file這樣的訊息出現。如果還是command not found,請重新登入應該就可以了。

這些天才科學家能不能寫一個不需要修改這麼多設定的程式呢?

Share this Link

2011年1月13日 星期四

Compilation and Installation of PSSAC on Linux

pssac是朱露培老師所寫的小程式,是一個特別設計跟gmt參數相同的程式,適合寫在GMT script裡直接繪出sac圖形的有用工具。一年多前嘗試想要編譯成功他,卻一直沒有成功。今年彷彿又聽到大家有使用pssac的需求,於是提筆寫信問朱教授。朱教授熱心的回應,使我終於成功編譯pssac。

首先,你的linux/unix主機必須有gcc任何的c編譯器。
第二,你需要先安裝好GMT;GMT的安裝請參考GMT簡易安裝筆記。新版的GMT已經到4.5.5,但是安裝form大致上是一樣的。
第三,請到朱教授的個人網站下載pssac的原始碼。如果你的GMT版本是4.5以上,還請多下載新的pssac.c取代原本tar裡的檔案。
假設我們安裝好的GMT路徑是/opt/GMT4.5.2,netcdf的路徑為/opt/netcdf-3.6.3:

tar xvf pssac.tar
cd pssac; mv pssac.c pssac-old.c
wget -c http://www.eas.slu.edu/People/LZhu/downloads/pssac.c
不過直接使用原本的Makefile編譯成功的機會恐怕很少。請修改Makefile成如下的樣子:
  1. CC = gcc
  2. GMT_INC = -I /opt/GMT4.5.2/include -I /opt/netcdf-3.6.3/include
  3. GMT_LIBS = -L /opt/GMT4.5.2/lib -L /opt/netcdf-3.6.3/lib -lgmt -lgmtps -lpsl -lnetcdf -lm -s
  4. CFLAGS = -O2 ${GMT_INC}
  5.  
  6. pssac: pssac.o sacio.o
  7.     ${CC} -o $@ $@.o sacio.o ${GMT_LIBS} ${CFLAGS}
  8.  
  9. clean:
  10.     @rm -f pssac *.o

接著請執行make。如果你有確實的寫對GMT以及netcdf的函式庫位置以及headers的位置,你應該可以看到如下的輸出:

gcc -O2 -I /opt/GMT4.5.2/include -I /opt/netcdf-3.6.3/include -c -o pssac.o pssac.c
gcc -O2 -I /opt/GMT4.5.2/include -I /opt/netcdf-3.6.3/include -c -o sacio.o sacio.c
gcc -o pssac pssac.o sacio.o -L /opt/GMT4.5.2/lib -L /opt/netcdf-3.6.3/lib -lgmt -lgmtps -lpsl -lnetcdf -lm -s -O2 -I /opt/GMT4.5.2/include -I /opt/netcdf-3.6.3/include
然而當你想要試著執行他的時候卻出現錯誤訊息:
./pssac: error while loading shared libraries: libnetcdf.so.4: cannot open shared object file: No such file or directory
可知pssac執行時期需要libnetcdf.so.4這個函式,利用find指令可以發現這個檔案就在/etc/netcdf-3.6.3/lib裡。原來是系統並不認識他,趕快加進來吧(別忘了切到root身份)!
echo "/opt/netcdf-3.6.3/lib" > /etc/ld.so.conf.d/libnetcdf.conf
echo "/opt/GMT4.5.2/lib" > /etc/ld.so.conf.d/libgmt.conf
ldconfig
此時再執行pssac試試看:
Usage: pssac standardGMToptions [SACfiles] [-C[t1/t2]] [-E(k|d|a|n|b)(t[n]|vel)] [-Gr/g/b/c] [-I] [-Msize[/alpha]] [-Q] [-r] [-Sshift] [-V]

    pssac plots SAC traces. If no SAC file names is provided in the command line, it expects (sacfile,[x,[y [pen]]) from stdin.
       -C only plot data between t1 and t2
       -E option determines
         (1) profile type:
   a: azimuth profile
   b: back-azimuth profiel
   d: epicentral distance (in degs.) profile
   k: epicentral distance (in km.) profile
   n: traces are numbered from 1 to N in y-axis
         (2) time alignment:
   tn: align up with time mark tn in SAC head
              default is the reference time. Others are
       n= -5(b), -3(o), -2(a), 0-9 (t0-t9)
   vel: use reduced velocity
       -G paint amplitudes larger than c with color r/g/b
       -I integrate the trace before plotting
       -M multiple traces
   size: each trace will normalized to size (in y-unit)
   size/alpha: if alpha<0, use same scale for all traces
       else plot absolute amplitude multiplied by size*r^alpha
       where r is the distance range in km
       -Q square the trace
       -r remove the mean value in the trace
       -S shift traces by shift seconds
       -V plot traces vertically
確定可以執行後,把他放到/usr/local/bin裡,這樣所有使用者都可以使用這隻程式啦!

再次感謝朱老師的熱心幫忙!

Share