File: [local] / OpenXM / src / kan96xx / Doc / gnuplot.sm1 (download)
Revision 1.8, Fri Feb 4 11:25:45 2005 UTC (19 years, 7 months ago) by takayama
Branch: MAIN
Changes since 1.7: +2 -1
lines
Cleaning the fifo before sending commands to gnuplot.
|
%$OpenXM: OpenXM/src/kan96xx/Doc/gnuplot.sm1,v 1.8 2005/02/04 11:25:45 takayama Exp $
%%% 1999, 6/7 Mon.
[(parse) (ox.sm1) pushfile] extension
[(getenv) (OpenXM_HOME)] extension /OpenXM_HOME set
[OpenXM_HOME (/bin/gnuplot)] cat /plot.gnuplotexec set
%(gnuplot) /plot.gnuplotexec set
(SSkan/lib/plot.sm1 for ox_sm1_gnuplot. 1999/09/03. ) message
/gnuplot.callingMethod 1 def % 0 : old, 1 : pipe, 2: file
% If your gnuplot is version 3, then set the callingMethod to 0.
/plotstart {
sm1connectr
ox.ccc 1 copy /gnuplot.ccc set
(Your peer is set to gnuplot.ccc) message
gnuplot.ccc $[(parse) (gnuplot.sm1) pushfile] extension $ oxsubmit
gnuplot.ccc $ plotstart.aux $ oxsubmit
gnuplot.ccc $ gnuplot.pid $ oxsubmit gnuplot.ccc oxpopcmo /gnuplot.pid set
} def
/plotstart.aux {
{
gnuplot.callingMethod 0 eq {
plotstart.aux.0
} { } ifelse
gnuplot.callingMethod 1 eq {
plotstart.aux.1
} { } ifelse
gnuplot.callingMethod 2 eq {
(Not yet implemented.) error
} { } ifelse
exit
} loop
} def
/plotstart.aux.0 {
/peer [(oxGetPort) (localhost)] extension def
[(sm1.socket) (close) [peer 2 get]] extension %% close the second.
/myport peer 1 get def
/myportStr peer 1 get toString def
(port number = ) messagen myportStr message
[(forkExec)
[ plot.gnuplotexec
[(r) myportStr] cat
]
[ 3 4 << peer 0 get >> ] %% close ox_sm1 channel, this channel.
0
] extension /gnuplot.pid set
(gnuplot.pid = ) messagen gnuplot.pid message
[(sm1.socket) (accept) [peer 0 get ]] extension /gnuplot.ff2 set
(Accepted ) messagen
gnuplot.ff2 message
} def
/plotstart.aux.1 {
[(getUniqueFileName) (/tmp/gnuplot.fifo.tmp)] extension /gnuplot.fifo set
[(fp2mkfifo) gnuplot.fifo] extension /gnuplot.status set
gnuplot.status -1 eq {
(Warning: mkfifo failed.) message
} { } ifelse
gnuplot.fifo message
[(fp2popen) plot.gnuplotexec (w)] extension /gnuplot.pfp set
(Started gnuplot) message
[(fp2fputs) [(set print ") gnuplot.fifo (" ; ) nl ] cat
gnuplot.pfp ] extension message
[(fp2fflush) gnuplot.pfp] extension message
[(fp2fputs) [(set mouse ; ) nl ] cat gnuplot.pfp ] extension message
[(fp2fflush) gnuplot.pfp] extension message
[(fp2fopen) gnuplot.fifo (r)] extension /gnuplot.fifoFp set
% This must be the last. Otherwise, fopen is blocked.
% When mkfifo fails, then gnuplot.fifoFp will be null. (old cygwin)
/gnuplot.pid -2 def % dummy.
gnuplot.pid message
} def
/plotstop {
gnuplot.ccc $ plotstop.aux $ oxsubmit
} def
/plotstop.aux {
{
gnuplot.callingMethod 0 eq {
plotstop.aux.0
} { } ifelse
gnuplot.callingMethod 1 eq {
plotstop.aux.1
} { } ifelse
gnuplot.callingMethod 2 eq {
(Not yet implemented.) error
} { } ifelse
exit
} loop
} def
/plotstop.aux.0 { } def
/plotstop.aux.1 {
[(fp2fclose) gnuplot.pfp] extension pop
gnuplot.fifoFp tag 0 eq { }
{
[(fp2fclose) gnuplot.fifoFp] extension pop
} ifelse
% [(rm) gnuplot.fifo] oxshell pop % It is OS dependent.
[(unlink) gnuplot.fifo] extension
} def
/gnuplot {
{
gnuplot.callingMethod 0 eq {
gnuplot.0
} { } ifelse
gnuplot.callingMethod 1 eq {
gnuplot.1
} { } ifelse
gnuplot.callingMethod 2 eq {
(Not yet implemented.) error
} { } ifelse
exit
} loop
} def
/gnuplot.0 {
/cccc set
/fd gnuplot.ff2 0 get def
[(sm1.socket) (write) [fd
[cccc 10 (string) dc] cat]] extension
} def
/gnuplot.1 {
/cccc set
gnuplot.read.1
[(fp2fputs) [cccc nl] cat gnuplot.pfp] extension pop
[(fp2fflush) gnuplot.pfp] extension pop
gnuplot.read.1
} def
%% (plot sin(x);) gnuplot
/gnuplot.read.1 {
[
gnuplot.fifoFp tag 0 eq { }
{
{
[(fp2select) gnuplot.fifoFp 0] extension 1 eq {
[(fp2fgetc) gnuplot.fifoFp] extension
} { exit } ifelse
} loop
} ifelse
] { (string) dc } map cat
} def
/isAlive {
{
gnuplot.callingMethod 0 eq {
isAlive.0
} { } ifelse
gnuplot.callingMethod 1 eq {
isAlive.1
} { } ifelse
gnuplot.callingMethod 2 eq {
(Not yet implemented.) error
} { } ifelse
exit
} loop
} def
/isAlive.0 {
[/in-isAlive /ans /i /nn] pushVariables
[ [ gnuplot.ccc ([(getchild)] extension ) oxsubmit ] pop
gnuplot.ccc oxpopcmo /gnuplot.pidList set
gnuplot.pidList isArray {
} {
(getchild returns the following strange output.) message
gnuplot.pidList message
/gnuplot.pidList [ ] def
} ifelse
gnuplot.pidList length 0 eq {
/ans 0 def
} {
/nn gnuplot.pidList length def
0 1 nn 1 sub {
/i set
gnuplot.pidList i get gnuplot.pid eq {
/isAlive.LLL goto
} {
(length of gnuplot.pidList = ) messagen gnuplot.pidList length message
(gnuplot.pidList and gnuplot.pid are differenct) message
i nn 1 sub eq {
error
} { } ifelse
} ifelse
} for
/isAlive.LLL
/ans 1 def
} ifelse
/arg1 ans def
] pop
popVariables
arg1
} def
/isAlive.1 {
1
} def
/demo0 {
(/u/nobuki/Trash/gnuplot-3.5beta6.347.orig/demo/airfoil.dem) pushfile /ff set
ff gnuplot
} def
/rplot {
/rplot.arg set
isAlive {
gnuplot.ccc [ ($ ) rplot.arg ( $) ( gnuplot )] cat oxsubmit
} {
(You peer got error. Restaring gnuplot) message
gnuplot.ccc ( plotstart.aux ) oxsubmit
gnuplot.ccc $ gnuplot.pid $ oxsubmit gnuplot.ccc oxpopcmo /gnuplot.pid set
(New gnuplot.pid is ) messagen gnuplot.pid message
(We have started new gnuplot. Try your command again.) message
} ifelse
} def
/test0 {
(Type in ctrl-C and gnuplot.ccc oxreset . ) message
0 1 10000 {
/i set
[$plot cos(x+$ i toString $);$] cat rplot
} for ;
} def
$plotstart ; (plot sin(x);) rplot$ message
$plotstart.aux ; (splot x**2-y**2;) gnuplot $ message