シェルスクリプト上でgnuplotを動かす


目的

シェルスクリプト上でgnuplotのスクリプトにパスを与えて繰り返し処理をしたい

描画プログラムをgnuplotで書いたが、繰り返し処理やファイル操作をgnuplotのスクリプト上で行うのは面倒なので、シェルスクリプトを用いて、描画部だけgnuplotを用いたい

参考

大筋はこちらのページを参考にした
http://auewe.hatenablog.com/entry/2013/06/03/012031

実行

今回はターミナル上で引数として入力データとタイトル名を与える。

Visualization.sh
#!/usr/bin/bash -f
# Visualization.sh
# 第一引数データ
# 第二引数タイトル

dataPath=$1
title=$2
echo "plot ${dataPath} Spectral. title is ${title} ."
echo ${dataPath} | sed -e  "s#/#\\\\#g"
gnuplot << EOF
  set terminal png
  set output '${title}.png'
  set nokey
  plot '${dataPath}' with lines
EOF

追加で加えた処理が以下
cygwin上で動かすため、入力パスは”/”区切りだが、gnuplot上では"\"で処理されるため、その置換を行った
(参考:https://qiita.com/miriwo/items/8bf37eedf92fc6ea8b77)


echo ${dataPath} | sed -e  "s#/#\\\\#g"

出力