Earthworm 是一套模組化、可擴張、穩定且跨系統的地震資料處理程式,早在1993年便開始開發,是一個非常成熟且具有彈性的地震資料處理程式。今天到臺大參加 Earthworm 的 Pre-workshop(正式的 Earthworm workshop在7/27星期四),由達逸學長教我們建立基本的 earthworm 系統,並建立一個 Wave server 給其他的客戶端使用。下面會精簡的記述課堂練習的成果。
上篇記述基本概念與如何啟動一個沒有任何模組的 Earthworm 程式。
架構
Earthworm (下面用 EW 簡寫)有些比較專門的名詞,先說一下:
- Module 模組(M):具有特別目的的程式,可以參考 這個網頁 裡面羅列的所有Earthworm 模組。
- Ring 共享記憶體(R):一個共享的記憶體空間,提供給不同模組間交換資料使用。
- Diagram:工作的流程圖,使用者規劃的資料處理流程,由許多 M 與 R 或其他單元組成。可以注意的是這個流程圖不侷限在同一台電腦裡完成所有工作。
圖:這次 Pre-workshop 主要的工作流程圖,今天將會建立一個從 IRIS 接收及時震波資料,並架設波形伺服器供其他客戶端使用。
啟航!
我們開始一個最基本的 EW 程式吧!就是…啟動不含模組的 EW 。
下載軟體:
請至 這邊 點選一個 EW 發佈版的下載位置,並下載相對應自己作業系統的程式版本。筆者以「MacOSX Intel 64-bit」版本為例,下載完後是個 tar.gz 的壓縮檔,解壓縮後即包含所有必要的執行檔。
將檔案放置在你想放的地方,筆者是放在「/usr/local/Cellar/earthworm_7.8/」資料夾內,EW版本為7.8
準備啟動的必要檔案:
首先,在 EW根目錄($EW_ROOT/earthworm_7.8/) 建立一個「Run」的資料夾,並在下面建立「params」、「logs」、「data」等資料夾,裡面將分別存放「必要的參數設定檔」、「執行記錄」與「資料」檔案
要成功啟動 EW 最少要下面四個檔案:「earthworm_global.d」、「earthworm.d」、「ew_macosx_intel.sh」、「startstop_unix.d」。請在 EW根目錄 下「params」與「environment」找到上面提到的檔案。(註:請選擇符合自己作業系統的檔案,如果是 Windows 作業系統則使用檔名內有 nt 的設定檔。)
「earthworm_global.d」是 EW 的核心設定檔,程式設計者以明確說明若非必要使用者不應更動檔案的任何部分 。
「earthworm.d」則是設定使用者可客製化的參數,比較重要的是任何 EW 使用到的 M 與 R 都要在這個檔案中定義(像是C的標頭檔,先宣告有什麼模組或是共享記憶體可以使用)。
「ew_macosx_intel.sh」是幫助建立執行環境的設定檔,裡面記述了安裝的路徑等必要的參數。講師說因為有部分 EW 模組會用到 C 與 Fortran 編譯器(Compiler),因此在執行 Windows 的設定檔後若系統沒有安裝對應的編譯器會顯示「裝置未就緒」,但以今天的範例我們不需要編譯器。
「startstop_unix.d」是 startstop 程式的設定檔,專門用來啟動與結束 EW。
設定基礎設定
ew_macosx_intel.sh
由於 EW 是命令列工具,因此我們需要為命令列建立一個執行環境(定義安裝位置等),所以我們要先編輯「ew_macosx_intel.sh」這個檔案(Windows 則是 「ew_nt.cmd」這個檔案)。參考的設定如下:(注意:筆者是在「run_20170725」資料夾中執行 EW ,請替代為你想執行 EW 的路徑)
# 這邊省略了原檔案中的說明,請至各系統的設定檔閱讀 #===== ===== #這邊路徑結尾不用加「/」 export EW_HOME=/usr/local/Cellar export EW_VERSION=earthworm_7.8 #===== ===== export SYS_NAME=`hostname` #===== ===== # 注意 EW_INSTALLATION 必須是由 EW 開發人員給予的唯一識別碼,定義在「earthworm_global.d」檔案之中 export EW_INSTALLATION=INST_UNKNOWN #===== ===== #以下路徑結尾一定要加「/」 # 筆者在「run_20170725」路徑裡執行 EW export EW_PARAMS=${EW_HOME}/earthworm_7.8/run_20170725/params/ export EW_LOG=${EW_HOME}/earthworm_7.8/run_20170725/logs/ export EW_DATA_DIR=${EW_HOME}/earthworm_7.8/run_20170725/data/ export PATH=${EW_HOME}/$EW_VERSION/bin:$PATH #===== ===== #結尾編譯器設定的部分省略
earthworm.d
目前不需要更動檔案,不過之後想要增加 Ring 數目時,請到這個檔案新增 Ring 資訊(第 29 行附近)。範例如下:
#-------------------------------------------------------------------------- # Shared Memory Ring Keys # # Define unique keys for shared memory regions (transport rings). # All string/value mappings for shared memory keys may be locally altered. # # The maximum length of ring string is 32 characters. #-------------------------------------------------------------------------- Ring WAVE_RING 1000 # public waveform data Ring PICK_RING 1005 # public parametric data Ring HYPO_RING 1015 # public hypocenters etc. Ring BINDER_RING 1020 # private buffer for binder_ew Ring EQALARM_EW_RING 1025 # private buffer for eqalam_ew Ring DRINK_RING 1030 # DST drink messages Ring AD_RING 1035 # A/D waveform ring Ring CUBIC_RING 1036 # private buffer for cubic_msg # Do not put FLAG_RING in starstop*.d This is a hidden ring used for termination flags. Ring FLAG_RING 2000 # a private ring for Startstop 7.5 and later to use # for flags. If this doesn''t exist, startstop will # create the ring automatically at key 9999 # If you run multiple startstops, you''ll need to change # all ring keys values here in earthworm.d, including # this one. Do NOT include this private ring in # the ring area in startstop*d Ring NAMED_EVENT_RING 2001 # this is a ring used for the tsunami ATWC programs for # a named event API (see src/libsrc/util/ew_nevent_message.c) # this does not need to be declared, but it is if you wish # to have multiple earthworms running on the same host computer Ring XYZ_RING 1024
這邊我增加(宣告)了「Ring XYZ_RING 1024」,之後 startstop 模組即可順利創建共享記憶體。
startstop_unix.d
這邊定義了 startstop 應該初始化(或說起動)哪些模組與共享記憶體。設定檔比較重要的部分擷取出來如下:
#===== ===== #首先定義有多少個共享記憶體 Ring 要被初始化 nRing 2 #接著指定 Ring 名稱,後面大小的單位是(KB)。 #注意:這些 Ring 名稱要在 earthworm.d 裡面先被宣告。 Ring WAVE_RING 1024 Ring XYZ_RING 1024 #===== ===== #接著決定有什麼模組要啟動。 #此時我們應該註解掉或刪掉所有 Process 開頭的數據 #如以下的設定: ##Process "slink2ew slink2ew.d" ##Class/Priority OTHER 0 #上面兩句是要啟動「slink2ew」模組,並讀取「slink2ew.d」設定檔。 #===== =====
準備啟動啦!
首先,打開「終端機.app」(Terminal.app),進入剛剛創建的「run」 中「params」資料夾。
cd /usr/local/Cellar/earthworm_7.8/run/params
執行設定檔:
source ew_macosx_intel.sh
此時,所有 EW 的執行檔(位於 「…/earthworm_7.8/bin/」 路徑內,「…」為省略安裝路徑)應該已經被加入 PATH 的變數中,接著執行 startstop 程式啟動 EW:
startstop
執行後畫面的訊息應該向下面這樣:
EARTHWORM SYSTEM STATUS Hostname-OS: Hostname.local - Darwin 16.7.0 Start time (UTC): Tue Jul 25 04:06:00 2017 Current time (UTC): Tue Jul 25 04:06:01 2017 Disk space avail: xxxxxxx kb Ring 1 name/key/size: WAVE_RING / 1000 / 1024 kb Ring 2 name/key/size: XYZ_RING / 1024 / 1024 kb Startstop's Log Dir: /usr/local/Cellar/earthworm_7.8/run_20170725/log Startstop's Params Dir: /usr/local/Cellar/earthworm_7.8/run_20170725/par Startstop's Bin Dir: /usr/local/Cellar/earthworm_7.8/bin Startstop Version: v7.8 2015-06-01 Process Process Class/ CPU Name Id Status Priority Used Argument ------- ------- ------ -------- ---- -------- Press return to print Earthworm status, or type restart nnn where nnn is proc id or name to restart, or type quit<cr> to stop Earthworm.
就代表成功啦!
如果要跳出,在終端機打入「quit」即可