Calc から wgnuplot を使う(実践編)


ご意見はこちらへ


  1. wgnuplot の入手とインストール
  2. pgnuplot の入手とインストール
  3. Calc-graph.el の改変
  4. 使用上の注意
  5. ダウンロードファイル

  1. wgnuplot の入手とインストール
    私は 福井さんのHPからバイナリをダウンロードしました。インストール方法もそこに書いてあります。

    別にこのバージョンに限りませんが、次の要件を満たせば大丈夫と思います。

    1. Ver.3 以上であること。
      無理にとは言いませんが、Ver.2 では 3D ができない?
    2. win32api に対応していることが多分必須。
      何のことか私に聞かないでください。 このあたりに pgnuplot.exe との相性がありそうだと、私のカンが囁きました。 (w32api に詳しい人は pgnuplot.c を読んで私に解説してください。) 同じ理由でコンパイラは cygwin-gcc でないほうが無難?
    3. ロングファイル名に対応していること。
      Calc はデータファイルを作ってそれを wgnuplot に読ませるのですが、 8 + 3 ファイル名しか理解できない版の wgnuplot ではファイルを見つけられません。
    4. 一時データファイルの所在 (ファイル名の例: /tmp/calc1-3861167bPR )
      このファイルの所在は calc-graph.el の中で、次のように定義されています。
      (defvar calc-gnuplot-tempfile "/tmp/calc")
      自分の環境に /tmp が無い人は別に設定してやる必要があります。
  2. pgnuplot の入手とインストール
    1. pgnuplot には色々なバージョンがあるようです。日本製のものもありました。私が使ったものは、 http://feff.phys.washington.edu/~ravel/software/gnuplot-mode/Win9x/pgnuplot.c
      です。私が使ったバージョンでは、ファイル先頭に次の記述があります。
      
      /*
       * pgnuplot.c -- pipe stdin to wgnuplot
       * 
       * Version 0.3 -- 30 Jun 1999
       * 
       * This program is based on pgnuplot.c Copyright (C) 1999 Hans-Bernhard Broeker
       * with substantial modifications Copyright (C) 1999 Craig R. Schardt.
       *
       * The code is released to the public domain.
       *
       */
      (このソースファイルは gnuplot-3.7.1 の配布にも含まれているようです。)
      
      不思議なことに、同じサイトの圧縮ファイル
      • http://feff.phys.washington.edu/~ravel/software/gnuplot-mode/gnuplot-mode.tar.gz
      • http://feff.phys.washington.edu/~ravel/software/gnuplot-mode/gnuplot-mode.zip
      にはなぜか古いものが入っている。
    2. コンパイル
      私はMinGW32 の gcc を使いました。 http://www.mingw.org/ からたどって最新版が入手できます。ソースファイル中のコンパイル例を下記します。Cygwin の gcc を使うなら -mno-cygwin というオプションが必要です。
       * For the record, I usually use MinGW32 to compile this, with a
       * command line looking like this:
       *
       *     gcc -o pgnuplot.exe pgnuplot.c -luser32 -s
       *
       * Note that if you're using Cygwin GCC, you'll want to add the option
       * -mno-cygwin to that command line to avoid getting a pgnuplot.exe
       * that depends on their GPL'ed cygwin1.dll.
       */
      
              ・・・中略・・・
      
              This program has been compiled using Microsoft Visual C++ 4.0 with the
              following command line:
      
                      cl /O2 pgnuplot.c /link user32.lib
      
              The resulting program has been tested on WinNT and Win98 both by calling
              it directly from the command line with and without redirected input. The
              program also works on WinNT with a modified version of Gnuplot.py (a script
              for interactive control of Gnuplot from Python). 
      
    3. インストール
      1. コンパイルして得られたpgnuplot.exe は wgnuplot.exe と同じフォルダに置きます。
        (重要。pgnuplot の初期バージョンではソース中に wgnuplot.exe の所在をフルパスで書かねばならないものもあります。 上記のバージョンなら、同じフォルダに入れるだけです。)
      2. .emacs 中に pgnuplot.exe をフルパスで指定します。次は私の例です。
        (defvar calc-gnuplot-name C:/usr/local/gnuplot/gnuplot-3.7.1/pgnuplot.exe)
  3. calc-graph.el の改変
    なにせ lisp をいじるのは初めてなものですから、あなたの責任でお使いください。何がやりたかったか意図を載せて置きます。お気づきの点はお知らせくださいね。
    1. 起動メッセージから GNUPLOT のバージョンを調べる段階を騙す。
      1469a1475,1486
      >         (insert                       ; by JA5QAZ on 2002/04/02
      >          "G N U P L O T\nMS-Windows 32 bit version 3.7\n"
      >          "patchlevel 1\nlast modified Fri Oct 22 18:00:00 BST 1999\n\n"
      >          "Copyright(C) 1986 - 1993, 1998, 1999\n"
      >          "Thomas Williams, Colin Kelley and many others\n\n"
      >          "Type `help` to access the on-line reference manual\n"
      >          "The gnuplot FAQ is available from\n"
      >          "<http://www.ucc.ie/gnuplot/gnuplot-faq.html>\n\n"
      >          "Send comments and requests for help to <info-gnuplot@dartmouth.edu>\n"
      >          "Send bugs, suggestions and mods to <bug-gnuplot@dartmouth.edu>\n\n\n"
      >          "Terminal type set to 'windows'\n"
      >          "gnuplot> ")
      Calc は gnuplot の標準出力を Emacs のバッファにコピーして、 「G N U P L O T」という文字列の後に来るバージョン番号を読み取ります。 そして「gnuplot> 」というプロンプトを検出して起動が完了したことを知ります。 wgnuplot では標準出力が見えないので、予定の文字をここで書きこんでやろうと言うわけです。 必要なのは下線部だけなのですが、ワルノリで全部入れています。

      もしあなたのGNUPLOTがこれと異なるバージョン番号を表示するときは、そちらに合わせる必要があります。

    2. 子プロセスからの返事をずっと待っているのでタイムアウトさせる。
      1418c1422,1423
      <                                 calc-gnuplot-process))
      ---
      > ;;;                             calc-gnuplot-process))
      >                                 calc-gnuplot-process) nil 1000) ; by JA5QAZ 2002/4/2
    3. Calc が windows というデバイスを知らなかったので教え込む。
      351,352c353,356
      <                             (if (>= calc-gnuplot-version 3)
      <                                 "dumb" "postscript")))))
      ---
      >                             (if (eq window-system 'w32) "windows"     ; by JA5QAZ on 2002/4/2
      >                               (if (>= calc-gnuplot-version 3)
      >                                   "dumb" "postscript")))))
      >          ) ; by JA5QAZ on 2002/4/2
    4. なにやら `g a' の動作に不具合(ここまでに エンバグしたか?) があるので FIX。
      212,217c212,219
      <       (calc-graph-set-styles
      <        (or (and (Math-num-integerp lstyle) (math-trunc lstyle))
      <          0)
      <        (or (and (Math-num-integerp pstyle) (math-trunc pstyle))
      <          (if (eq (car-safe (calc-var-value (nth 2 ydata))) 'vec)
      <              0 -1)))))
      ---
      >     (let ((calc-graph-no-auto-view t)) ; by JA5QAZ on 2002/4/8
      >       (calc-graph-set-styles
      >        (or (and (Math-num-integerp lstyle) (math-trunc lstyle))
      >          0)
      >        (or (and (Math-num-integerp pstyle) (math-trunc pstyle))
      >          (if (eq (car-safe (calc-var-value (nth 2 ydata))) 'vec)
      >              0 -1)))))
      >      )                                 ;  by JA5QAZ on 2002/4/8
  4. 使用上の注意
    オリジナルの Calc は gnuplot から帰ってくる標準出力を、Emacs のバッファに表示しますが、 改造版は wgnuplot の CUI窓にそのまま表示したきりです。Calc がその情報を表示したい局面とは
    1. Calc が* Gnuplot Trail * バッファを表示したとき
      gnuplot からの情報を期待している時、 例えば 「g D ? RET」 などとして Available terminal types を表示させる時がこれにあたります。 当の CUI窓では 「Press return for more:」 などを表示して止まってしまう場合があります。
    2. 文字列内にエラーを検出したとき
      本改造ではエラーが検出できません。動作がおかしかったら、自分で CUI窓をチェックする必要があります。
    このような場合には gnuplot の CUI 窓に手動で切り替えて処理してください。
  5. ダウンロードファイル
    ここには を置きます。無保証です。あなたの責任でどうぞ。