1
1

More than 1 year has passed since last update.

gnuplotで,ファイルのある位置にカレントディレクトリを移動する

Posted at

カレントディレクトリを移動したいのは,参照したいファイルの絶対パスを取得するのが面倒くさいからと推察します.

そこで,以下を冒頭に書くことでカレントディレクトリが移動できます.

move.gp
max(x,y)= ( (x) > (y) ) ? (x) : (y)
strstrlt_sub(str,index,target)=(strstrt(str[index:],target)==0 ? \
    max(index-strlen(target),0) : \
    strstrlt_sub(str, index-1+strstrt(str[index:],target)+strlen(target),target))
strstrlt(str,target)=strstrlt_sub(str,1,target)
dirname(path)=strstrt(path, "\\")!= 0 ? substr(path, 1, strstrlt(path,"\\")-1) : ""

cd dirname(ARG0)

ところで,そもそもカレントディレクトリを移動しなくても,pltファイルを実行すれば,pltファイルのあるディレクトリのファイルを相対パスで取得できます.
グラフを取得するだけなら,pltファイルにて処理すると良いでしょう.

ただし,statsコマンドを使うなどして入力データに対する標準偏差や平均値を使いたいということがあるかもしれません.(というか,筆者がそれでした)
そういうときは,gnuplotを立ち上げて,上記のmove.gpを書いたgpファイルをgnuplotで実行すると良いでしょう.
※ PythonやFortranにおけるような,input関数的なやつがgnuplotにあるなら,それを使えばいいのですが…探しても見つけられなかったので.

他にできそうなこと

釈迦に説法かとは存じますが,参考先のページにて,ファイル名の取得も紹介されています.
すなわち,pltファイルやgpファイルと同じ名前のepsファイルを作成する,という処理も,いちいち書き換えなくてもできそうです.

参考

1
1
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
1
1