ラベル gnuplot の投稿を表示しています。 すべての投稿を表示
ラベル gnuplot の投稿を表示しています。 すべての投稿を表示

2012年5月25日金曜日

gnuplot で pdf ファイルの出力

gnuplot の configure オプションには --with-pdf というのがあり、PDFlib というライブラリがあれば gnuplot で直接 PDF 出力できる。

PDFlib の subset に PDFlib lite 7 というのがあり、非商用目的であればフリーでダウンロードしてよいようだ。Gnuplot から使う分にはこれで十分かもしれない。

PDFlib Lite 7

このページでソースコードの配布をしている。ソースコードというわりには、Windows 版、Linux 版、MacOSX 版の3つのリンクがあった(zip, tar.gz, dmg の違いだけで中身は同じだったりして)。

ひとまず OSX Lion に入れてみる。

./configure --prefix=/usr/local/pdflib
make 
make install

コンパイル最中のメッセージを見ていると、java binding(?) で no symbol とか出ていたが、gnuplot のビルドには関係ないと思われるので気にしないことに。 gnuplot は Ver. 4.6.0 が 3 月にリリースされていたので新しいのを入れる。

export PATH=/usr/local/pdflib/bin:$PATH
./configure --with-readline=/usr/local

pdflib-config に PATH を通して configure 実行。--with-pdflib=/usr/local/pdflib では上手く行かなかった。また 4.4 を入れたときに Gnu Readline を入れたので今回はハマらなかった。

ひとまずこれで

set term pdf
set output 'test.pdf'
plot x

とかやる分には PDF がちゃんと作られていた。さて、この pdf という terminal はどの位こなれているのだろうか。

追記: PDFlib lite 7 のソースツリーを眺めていると bind/pdflib/ruby の下に ruby binding らしきファイルがあった。pdflib_ruby.c, rb_wrapped.c の2ファイル。しかし extconf.rb がない。pg (ruby-pg) のコンパイルオプションをまねて、どうにかビルドしてみた:

gcc -c -I. -I/usr/local/ruby_1.9.3-p194/include/ruby-1.9.1/x86_64-darwin11.3.0
           -I/usr/local/ruby_1.9.3-p194/include/ruby-1.9.1/ruby/backward
           -I/usr/local/ruby_1.9.3-p194/include/ruby-1.9.1 -I. -DHAVE_OBJECT_ALLOCATE -DHAVE_PDFLIB_H
           -I/usr/local/pdflib/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common
           -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers
           -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32
           -Wimplicit-function-declaration -pipe -o pdflib_ruby.o pdflib_ruby.c

gcc -c -I. -I/usr/local/ruby_1.9.3-p194/include/ruby-1.9.1/x86_64-darwin11.3.0
           -I/usr/local/ruby_1.9.3-p194/include/ruby-1.9.1/ruby/backward
           -I/usr/local/ruby_1.9.3-p194/include/ruby-1.9.1 -I. -DHAVE_OBJECT_ALLOCATE -DHAVE_PDFLIB_H
           -I/usr/local/pdflib/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common
           -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers
           -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32
           -Wimplicit-function-declaration -pipe -o rb_wrapped.o rb_wrapped.c

gcc -dynamic -bundle -o pdflib.bundle -L. -L/usr/local/ruby_1.9.3-p194/lib -L/usr/local/pdflib/lib
           -L. -L/usr/local/lib -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace
           -lpdf -lpthread -ldl -lobjc pdflib_ruby.o rb_wrapped.o

できた PDFlib.bundle を site_ruby/1.9.1/x86_64-darwin11.3.0/ に放り込む。

サンプルを試してみる。 hello.rb, image.rb の2つは PDF を生成した。他のものは PDFlib lite に含まれない機能を使っているのか PDF は生成されなかった。

2011年11月7日月曜日

Gnuplot on MAC OSX lion

Gnuplot をビルドしたので、備忘録。

ハマった。原因が不明だが( built-in の readline に問題ありか?)、ともかく Gnu Readline を入れたら動くようになった。

初めはなにも考えずにビルドし、すんなりビルドまでは通った。しかし、いざプロットしようとすると gnuplot が落ちる ...

black-pearl:tmp shingo$ gnuplot

 G N U P L O T
 Version 4.5 patchlevel 0
 last modified 2011-11-06 
 System: Darwin 11.2.0

 Copyright (C) 1986-1993, 1998, 2004, 2007-2011
 Thomas Williams, Colin Kelley and many others

 gnuplot home:     http://www.gnuplot.info
 mailing list:     gnuplot-beta@lists.sourceforge.net
 faq, bugs, etc:   type "help seeking-assistance"
 immediate help:   type "help"
 plot window:      hit 'h'

Terminal type set to 'aqua'
gnuplot> plot "dat4"
gnuplot> plot "dat4"
gnuplot(16644,0x7fff74263960) malloc: *** error for object 0x7fff74358b88: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

メモリリーク?と言わんばかりのエラーメッセージが。 csv から最新版を checkout してビルドしても変わらない。 ネットを彷徨うと How to install gnuplot in Mac OSX lion というありがたいポストが見つかり、そこに書いてある通り作業を行ったら落ちずに動くようになった。

readline-6.2 のインスト

cd ./readline-6.2/
./configure --prefix=/usr/local/
vi shlib/Makefile  ( -dynamic -> -dynamiclib )
make
sudo make install

aquaterm を入れ、gnuplot のビルド

cd ./gnuplot-4.4.3
./configure --with-readline=/usr/local/
make
sudo make install