Earthworm 是一套模組化、可擴張、穩定且跨系統的地震資料處理程式,早在1993年便開始開發,是一個非常成熟且具有彈性的地震資料處理程式。今天到臺大參加 Earthworm 的 Pre-workshop(正式的 Earthworm workshop在7/27星期四),由達逸學長教我們建立基本的 earthworm 系統,並建立一個 Wave server 給其他的客戶端使用。下面會精簡的記述課堂練習的成果。
下篇記述利用 slink2ew 與 wave_serverV 從 IRIS 接收資料並建立波形伺服器。
Earthworm Work Flow Diagram
複習一下上一篇中我們預計建立的 Earthworm Work Flow Diagram :
首先,我們要使用 slink2ew 模組從 IRIS 接收及時的震波資料,將資料放置至 WAVE_RING 這個資料暫存區中,這時,我們用 findwave 去確定 WAVE_RING 是否有資料流進來,並決定 Wave Server 要串流哪些 Wave 的資料,最後再使用一些波形顯示的客戶端(Swarm 等)來顯示資料。
使用新模組前…
首先,在 EW 安裝目錄下「params」資料夾找到欲使用的模組的設定檔。(通常和模組名稱相同的.d檔,如「slink2ew」模組的設定檔為「slink2ew.d」)
再來,確定「earthworm.d」檔案中的欲使用模組名是否已經在模組清單中:
... Module MOD_SLINK2EW 126 ... Module MOD_WAVESERVERV 142 ...
最後,在「startstop.d」中指定要開啟的模組:
... Process "slink2ew slink2ew.d" Class/Priority OTHER 0 Process "wave_serverV wave_serverV.d" Class/Priority OTHER 0 ...
我們就準備好可以啟動模組了!
建立共享記憶體(Ring)
我們要先創建一個共享記憶體的區域提供模組間做資料交換。先開啟「earthworm.d」,在「 Shared Memory Ring Keys」部分替共享記憶體取個獨特的 ID 名:
Ring XYZ_RING 1024
原本就有幾個預設的 Ring 存在,也可以使用之。
接著在「startstop.d」初始化共享記憶體,並決定其大小:
Ring XYZ_RING 1024
每個用到的共享記憶體必須經過這兩個步驟的初始化,才能使用喔!
slink2ew
一開始,我們先造訪 IRIS Buffer of Uniform Data 網站,點選其中的 Monitor 網頁,選擇一個喜歡的測站,如 TW KMNB。
接著,複製「slink2ew.d」至「run/params」,並以文字編輯器開啟準備編輯內容。再約 86-90 行附近,我們要加上我們想接收的站資訊:
## 想收所有臺灣提供的測站的資料:(本範例) Stream TW_* ## 想收單一站的資料: #Stream TW_KMNB ## 指定單一測站某個 Chennel: #Stream TW_KMNB BHE ## 多個 Chennel 需要用引號引起來: #Stream TW_KMNB "BHE BHN"
目前只需要更動這部分,不過如果要自訂輸出的 Ring,請編輯「RingName」這個變數,也請記得依據上一小節的內容初始化共享記憶體。
測試 slink2ew 是否成功輸出
當我們設定好「slink2ew」,用下面的方式啟動 EW :
# 建立執行環境 source ew_macosx_intel.sh # 啟動 earthworm startstop
螢幕輸出大概會是這樣:
EARTHWORM SYSTEM STATUS Hostname-OS: Hostname.local - Darwin 16.7.0 Start time (UTC): Thu Jul 27 07:56:48 2017 Current time (UTC): Thu Jul 27 07:56:48 2017 Disk space avail: 2252688 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 ------- ------- ------ -------- ---- -------- startstop 3593 Alive **/** 0:00.01 - slink2ew 3594 Alive **/** 0:00.00 slink2ew.d 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.
使用 findwave 測試 Ring 資料並整理供 Webserver 使用
使用 findwave 程式來讀取共享記憶體中的資料並儲存到檔案中:
findwave WAVE_RING 1 1 out.txt w #findwave 用法說明: Usage: findwave <ring name> <index size> <days> <file name> <output type> [<msg size> <hd size> <enforce limit>] output type = w for wave_server output; produces Tank commands to use in a wave_serverV configuration file. index size = waveserver index size, days = days to save per tank output type = d for SCNL debug output. Must still provide index size and days. <msg size> = the message size you wish to force all tanks to (-1 to not force message size) (-2 to produce "padded" message sizes) ("padded" message sizes = the max size seen + the difference between max message size and the min message size) <hd size> = the size of the target harddrives in mb (-1 to not seperate out into harddrives), <enforce limit> = y to force tanks bigger than 1 gigabyte to 1 gigabyte, n to not
程式會一直抓資料直到使用者按下「control + c」,這邊儲存的資料在 Wave Server 時會使用到,螢幕輸出範例如下:
20170727_UTC_08:02:27 FindWave: inRing flushed. Found 10 SCNLs, press <Ctrl C> to halt. Found 16 SCNLs, press <Ctrl C> to halt. Found 22 SCNLs, press <Ctrl C> to halt. Found 26 SCNLs, press <Ctrl C> to halt. ^C
而 out.txt 的內容則像下面這樣:
Findwave: Generating wave_serverV output: Found 39 SCNLs # Found 39 SCNLs, Num Days = 1, Msg Size = -1, HD Size = -1, # Enforce 1 Gig limit = no # SCNL Record Logo File Size Index Size File Name # names size Instid ModuleId (megabytes) (max breaks) (full path) Tank KMNB BHZ TW -- 1256 INST_NTU MOD_SLINK2EW 8 1 <insert path here>KMNB_BHZ_TW_--.tnk Tank KMNB BLE TW -- 2528 INST_NTU MOD_SLINK2EW 8 1 <insert path here>KMNB_BLE_TW_--.tnk Tank KMNB BLN TW -- 2528 INST_NTU MOD_SLINK2EW 8 1 <insert path here>KMNB_BLN_TW_--.tnk ...
到這邊我們確定 WAVE_RING 中已經有我們想要的資料了!
架設 Wave Server
首先,複製「wave_serverV.d」至「/run/params」裡面,再來開始設定 wave_serverV.d 重要的參數:
# 指定 IP 及 Port ServerIPAdr 127.0.0.1 ServerPort 16022 # 指定伺服器儲存 wave 資訊的位置(tnk檔) TankStructFile /usr/local/Cellar/earthworm_7.8/run_20170725/Tank_for_waveserver/p1000-1.str # 在 75 行左右的位置,加入我們剛剛利用 findwave 掃描出來測站資訊。 # 貼上後,將 Record size 改至適合的大小,這邊用 4096。(必須是2的指數倍的樣子) # File Name 欄位則把 <insert path here> 取代為你想存資料的路徑。 Tank KMNB BHE TW -- 4096 INST_NTU MOD_SLINK2EW 10 10 /usr/local/Cellar/earthworm_7.8/run_20170725/Tank_for_waveserver/KMNB_BHE_TW_--.tnk Tank KMNB BHN TW -- 4096 INST_NTU MOD_SLINK2EW 10 10 /usr/local/Cellar/earthworm_7.8/run_20170725/Tank_for_waveserver/KMNB_BHN_TW_--.tnk Tank KMNB BHZ TW -- 4096 INST_NTU MOD_SLINK2EW 10 10 /usr/local/Cellar/earthworm_7.8/run_20170725/Tank_for_waveserver/KMNB_BHZ_TW_--.tnk Tank KMNB BLE TW -- 4096 INST_NTU MOD_SLINK2EW 10 10 /usr/local/Cellar/earthworm_7.8/run_20170725/Tank_for_waveserver/KMNB_BLE_TW_--.tnk Tank KMNB BLN TW -- 4096 INST_NTU MOD_SLINK2EW 10 10 /usr/local/Cellar/earthworm_7.8/run_20170725/Tank_for_waveserver/KMNB_BLN_TW_--.tnk # TankStructFile2 的路徑也要指定: TankStructFile2 /usr/local/Cellar/earthworm_7.8/run_20170725/Tank_for_waveserver/p1000-2.str # InputQueueLen 決定有多少訊息數量可以緩衝,通常為上面 tank 數的兩倍。 InputQueueLen 40
完成後在「startstop」加入要啟動的模組清單中,即可準備啟動 EW。
啟動後螢幕範例:
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: 1326312 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 ------- ------- ------ -------- ---- -------- startstop 1794 Alive **/** 0:00.01 - slink2ew 1795 Alive **/** 0:00.00 slink2ew.d wave_serverV 1796 Alive **/** 0:00.00 wave_serverV.d 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.
使用 getmenu 向 wave server 存取資料
我們接著就可以使用其他程式向 wave server 存取資料了。比如說使用 getmenu 指令:
getmenu 127.0.0.1:16022 Tank contents for 127.0.0.1:16022 ws: 127.0.0.1:16022 pin: 0 KMNB.BLN.TW.-- Start: 20170725_0404_45.22 End: 20170727_0822_40.57 ws: 127.0.0.1:16022 pin: 0 KMNB.BLE.TW.-- Start: 20170725_0404_45.22 End: 20170727_0822_40.57 ws: 127.0.0.1:16022 pin: 0 KMNB.BHZ.TW.-- Start: 20170725_0405_15.62 End: 20170727_0823_12.87 ws: 127.0.0.1:16022 pin: 0 KMNB.BHN.TW.-- Start: 20170725_0405_06.92 End: 20170727_0822_58.52 ws: 127.0.0.1:16022 pin: 0 KMNB.BHE.TW.-- Start: 20170725_0404_46.27 End: 20170727_0823_13.97
有資料就完成啦!
筆者也是第一次接觸,若有錯誤請多指教!