2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gnuplotでファイル名装飾っぽいことをやる

Last updated at Posted at 2014-09-04

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","")

こんな具合でしょうか。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?