[BACK]Return to gnuplot.sm1 CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Doc

Annotation of OpenXM/src/kan96xx/Doc/gnuplot.sm1, Revision 1.10

1.10    ! takayama    1: %$OpenXM: OpenXM/src/kan96xx/Doc/gnuplot.sm1,v 1.9 2005/02/04 11:54:06 takayama Exp $
1.1       maekawa     2: %%% 1999, 6/7 Mon.
                      3: [(parse) (ox.sm1) pushfile] extension
                      4: [(getenv) (OpenXM_HOME)] extension /OpenXM_HOME set
                      5:
1.10    ! takayama    6: [(which) (gnuplot)] oxshell /plot.gnuplotexec set
        !             7: %[OpenXM_HOME (/bin/gnuplot)] cat /plot.gnuplotexec set
1.4       takayama    8: %(gnuplot) /plot.gnuplotexec set
1.1       maekawa     9:
                     10: (SSkan/lib/plot.sm1 for ox_sm1_gnuplot.  1999/09/03. ) message
                     11:
1.4       takayama   12: /gnuplot.callingMethod 1 def  % 0 : old, 1 : pipe, 2: file
1.5       takayama   13: % If your gnuplot is version 3, then set the callingMethod to 0.
1.3       takayama   14:
1.1       maekawa    15: /plotstart {
                     16:   sm1connectr
                     17:   ox.ccc 1 copy /gnuplot.ccc set
                     18:   (Your peer is set to gnuplot.ccc) message
                     19:   gnuplot.ccc $[(parse) (gnuplot.sm1) pushfile] extension $ oxsubmit
                     20:   gnuplot.ccc $ plotstart.aux $ oxsubmit
                     21:   gnuplot.ccc $ gnuplot.pid $ oxsubmit gnuplot.ccc oxpopcmo /gnuplot.pid set
                     22: } def
                     23:
                     24: /plotstart.aux {
1.10    ! takayama   25:   plot.gnuplotexec tag 0 eq {
        !            26:     (No gnuplot is installed in this system.) error
        !            27:   } { } ifelse
1.3       takayama   28:   {
                     29:     gnuplot.callingMethod 0 eq {
                     30:       plotstart.aux.0
                     31:     } { } ifelse
                     32:     gnuplot.callingMethod 1 eq {
                     33:       plotstart.aux.1
                     34:     } { } ifelse
                     35:     gnuplot.callingMethod 2 eq {
                     36:       (Not yet implemented.) error
                     37:     } { } ifelse
                     38:     exit
                     39:   } loop
                     40: } def
                     41: /plotstart.aux.0 {
1.1       maekawa    42:   /peer [(oxGetPort) (localhost)] extension def
                     43:   [(sm1.socket) (close) [peer 2 get]] extension  %% close the second.
                     44:   /myport peer 1 get def
                     45:   /myportStr peer 1 get toString def
                     46:
                     47:   (port number = ) messagen myportStr message
                     48:
                     49:   [(forkExec)
                     50:    [ plot.gnuplotexec
                     51:     [(r) myportStr] cat
                     52:    ]
                     53:    [ 3 4 << peer 0 get >> ]  %% close ox_sm1 channel, this channel.
                     54:    0
                     55:   ] extension /gnuplot.pid set
                     56:   (gnuplot.pid = ) messagen gnuplot.pid message
                     57:
                     58:   [(sm1.socket) (accept) [peer 0 get ]] extension /gnuplot.ff2 set
                     59:   (Accepted ) messagen
                     60:   gnuplot.ff2 message
                     61: } def
                     62:
1.3       takayama   63: /plotstart.aux.1 {
                     64:     [(getUniqueFileName) (/tmp/gnuplot.fifo.tmp)] extension /gnuplot.fifo set
1.6       takayama   65:     [(fp2mkfifo) gnuplot.fifo]  extension /gnuplot.status set
                     66:
                     67:     gnuplot.status -1 eq {
                     68:        (Warning: mkfifo failed.) message
                     69:     } { } ifelse
                     70:
1.3       takayama   71:     gnuplot.fifo message
                     72:     [(fp2popen) plot.gnuplotexec (w)] extension /gnuplot.pfp set
1.4       takayama   73:     (Started gnuplot) message
                     74:
1.5       takayama   75:     [(fp2fputs) [(set print ") gnuplot.fifo (" ; ) nl ] cat
1.3       takayama   76:      gnuplot.pfp ] extension message
1.5       takayama   77:     [(fp2fflush) gnuplot.pfp] extension message
                     78:     [(fp2fputs) [(set mouse ; ) nl ] cat gnuplot.pfp ] extension message
1.3       takayama   79:     [(fp2fflush) gnuplot.pfp] extension message
1.4       takayama   80:
                     81:     [(fp2fopen) gnuplot.fifo (r)] extension /gnuplot.fifoFp set
                     82:     % This must be the last. Otherwise, fopen is blocked.
1.6       takayama   83:     % When mkfifo fails, then gnuplot.fifoFp will be null. (old cygwin)
1.4       takayama   84:     /gnuplot.pid -2 def  % dummy.
                     85:     gnuplot.pid message
                     86: } def
                     87:
                     88: /plotstop {
                     89:   gnuplot.ccc $ plotstop.aux $ oxsubmit
1.3       takayama   90: } def
                     91:
                     92: /plotstop.aux {
                     93:   {
                     94:     gnuplot.callingMethod 0 eq {
                     95:       plotstop.aux.0
                     96:     } { } ifelse
                     97:     gnuplot.callingMethod 1 eq {
                     98:       plotstop.aux.1
                     99:     } { } ifelse
                    100:     gnuplot.callingMethod 2 eq {
                    101:       (Not yet implemented.) error
                    102:     } { } ifelse
                    103:     exit
                    104:   } loop
                    105: } def
                    106:
                    107: /plotstop.aux.0 { } def
                    108: /plotstop.aux.1 {
                    109:   [(fp2fclose) gnuplot.pfp] extension pop
1.6       takayama  110:   gnuplot.fifoFp tag 0 eq { }
                    111:   {
                    112:     [(fp2fclose) gnuplot.fifoFp] extension pop
                    113:   } ifelse
1.7       takayama  114:   % [(rm) gnuplot.fifo] oxshell pop % It  is OS dependent.
                    115:   [(unlink) gnuplot.fifo] extension
1.3       takayama  116: } def
                    117:
1.1       maekawa   118:
                    119: /gnuplot {
1.3       takayama  120:   {
                    121:     gnuplot.callingMethod 0 eq {
                    122:       gnuplot.0
                    123:     } { } ifelse
                    124:     gnuplot.callingMethod 1 eq {
                    125:       gnuplot.1
                    126:     } { } ifelse
                    127:     gnuplot.callingMethod 2 eq {
                    128:       (Not yet implemented.) error
                    129:     } { } ifelse
                    130:     exit
                    131:   } loop
                    132: } def
                    133:
                    134: /gnuplot.0 {
1.1       maekawa   135:   /cccc set
                    136:   /fd gnuplot.ff2 0 get def
                    137:   [(sm1.socket) (write) [fd
                    138:     [cccc 10 (string) dc] cat]] extension
                    139: } def
                    140:
1.3       takayama  141: /gnuplot.1 {
                    142:   /cccc set
1.8       takayama  143:   gnuplot.read.1
1.3       takayama  144:   [(fp2fputs) [cccc nl] cat gnuplot.pfp] extension pop
                    145:   [(fp2fflush) gnuplot.pfp] extension pop
                    146:   gnuplot.read.1
1.9       takayama  147:   gnuplot.sync.1
1.3       takayama  148: } def
                    149:
1.1       maekawa   150: %% (plot sin(x);) gnuplot
                    151:
1.3       takayama  152:
                    153: /gnuplot.read.1 {
1.6       takayama  154:  [
                    155:   gnuplot.fifoFp tag 0 eq { }
                    156:   {
1.3       takayama  157:    {
                    158:     [(fp2select) gnuplot.fifoFp 0] extension 1 eq {
                    159:       [(fp2fgetc) gnuplot.fifoFp] extension
                    160:     } {  exit } ifelse
                    161:    } loop
1.6       takayama  162:   } ifelse
                    163:  ] { (string) dc } map cat
1.9       takayama  164: } def
                    165:
                    166: % It uses "@" to wait for the gnuplot.
                    167: /gnuplot.sync.1 {
                    168:   [(fp2fputs) [(print "@";) nl] cat gnuplot.pfp] extension pop
                    169:   [(fp2fflush) gnuplot.pfp] extension pop
                    170:   {
                    171:     [(fp2fgetc) gnuplot.fifoFp] extension 64 eq { exit} { } ifelse
                    172:   } loop
1.3       takayama  173: } def
                    174:
1.1       maekawa   175: /isAlive {
1.3       takayama  176:   {
                    177:     gnuplot.callingMethod 0 eq {
                    178:       isAlive.0
                    179:     } { } ifelse
                    180:     gnuplot.callingMethod 1 eq {
                    181:       isAlive.1
                    182:     } { } ifelse
                    183:     gnuplot.callingMethod 2 eq {
                    184:       (Not yet implemented.) error
                    185:     } { } ifelse
                    186:     exit
                    187:   } loop
                    188: } def
                    189:
                    190: /isAlive.0 {
1.1       maekawa   191:  [/in-isAlive /ans /i /nn] pushVariables
                    192:  [ [ gnuplot.ccc ([(getchild)] extension ) oxsubmit ] pop
                    193:     gnuplot.ccc oxpopcmo /gnuplot.pidList set
                    194:     gnuplot.pidList isArray {
                    195:     } {
                    196:       (getchild returns the following strange output.) message
                    197:        gnuplot.pidList message
                    198:       /gnuplot.pidList [  ] def
                    199:     } ifelse
                    200:     gnuplot.pidList length 0  eq {
                    201:       /ans 0 def
                    202:     } {
                    203:       /nn gnuplot.pidList length def
                    204:       0 1 nn 1 sub {
                    205:         /i set
                    206:         gnuplot.pidList i get gnuplot.pid eq {
                    207:            /isAlive.LLL goto
                    208:         } {
                    209:           (length of gnuplot.pidList = ) messagen gnuplot.pidList length message
                    210:           (gnuplot.pidList and gnuplot.pid are differenct) message
                    211:            i nn 1 sub eq {
                    212:              error
                    213:            } { } ifelse
                    214:         } ifelse
                    215:       } for
                    216:       /isAlive.LLL
                    217:       /ans 1 def
                    218:     } ifelse
                    219:     /arg1 ans def
                    220:   ] pop
                    221:   popVariables
                    222:   arg1
1.3       takayama  223: } def
                    224:
                    225: /isAlive.1 {
                    226:   1
1.1       maekawa   227: } def
                    228:
                    229: /demo0 {
                    230:   (/u/nobuki/Trash/gnuplot-3.5beta6.347.orig/demo/airfoil.dem) pushfile /ff set
                    231:   ff gnuplot
                    232: } def
                    233:
                    234: /rplot {
                    235:   /rplot.arg set
                    236:   isAlive {
                    237:     gnuplot.ccc [ ($ ) rplot.arg ( $) ( gnuplot )] cat oxsubmit
                    238:   } {
                    239:     (You peer got error. Restaring gnuplot) message
                    240:      gnuplot.ccc ( plotstart.aux ) oxsubmit
                    241:      gnuplot.ccc $ gnuplot.pid $ oxsubmit gnuplot.ccc oxpopcmo /gnuplot.pid set
                    242:     (New gnuplot.pid is ) messagen gnuplot.pid message
                    243:     (We have started new gnuplot. Try your command again.) message
                    244:   } ifelse
                    245: } def
                    246:
                    247:
                    248: /test0 {
                    249:   (Type in ctrl-C and gnuplot.ccc oxreset . ) message
                    250:   0 1 10000 {
                    251:    /i set
                    252:      [$plot cos(x+$ i toString $);$] cat rplot
                    253:   } for ;
                    254: } def
                    255:
                    256:
                    257:
                    258:
                    259: $plotstart ;   (plot sin(x);) rplot$ message
1.4       takayama  260: $plotstart.aux ; (splot x**2-y**2;) gnuplot $ message

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>