gnuplotだけでいろいろがんばろうとする
背景
- result*.datをまとめてplotしたい
- gnuplotでワイルドカードを使用する方法
- ファイル名等を凡例にも用いる場合が多い
- 拡張子やディレクトリ名が邪魔だなぁ・・・
- シェルにあるファイル名装飾(:hとか:tとか)が欲しい
方法
~/.gnuplot
# path edit
# _t : tail : extract filename
# _h : head : extract path name
# _e : extention : extract file extention
# _r : root : remove file extention
#
# USAGE:
# r e
# <----------------------------> <->
# /home/someone/somedir/somefile.ext
# <-------------------> <---------->
# h t
#
# > print t(h("/home/someone/somedir/somefile.ext"))
# > somedir
e(x) = (strstrt(x,".") == 0 ? x : e(substr(x,strstrt(x,".") + 1, strlen(x) )))
t(x) = (strstrt(x,"/") == 0 ? x : t(substr(x,strstrt(x,"/") + 1, strlen(x) )))
r(x) = substr(x,0,strlen(x) - strlen(e(x)) - 1)
h(x) = substr(x,0,strlen(x) - strlen(t(x)) - 1)
# replace string
s(x,a,b) = system("echo ".x." | sed 's/".a."/".b."/'")
sg(x,a,b) = system("echo ".x." | sed 's/".a."/".b."/g'")
こんな感じです。
e()
やr()
は.tar.gzの様に拡張子が複数ついている場合1個ずつ削ります。
ディレクトリ名に.があったりすると変なことになるかも。
sのように、systemで外部でやってもらえばいい気もします。
使用例
gnuplot> list(x) = system("ls ".x)
gnuplot> p for [fn in list("result*.dat")] fn ti s(r(fn),"result","")
こんな具合でしょうか。