home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / electronic / rlab / !RLaB / RISC_OS / gnuplot < prev    next >
Encoding:
Text File  |  1995-10-17  |  51.2 KB  |  2,005 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. //  Syntax:    plot ( A, KeyTitles, I ) or plot ( X, Y, I )
  4. //        replot ( A, KeyTitles, I ) or replot ( X, Y, I ) or replot ( I )
  5. //        splot ( X, Y, Z, KeyTitles, I )
  6. //        cont ( X, Y, Z, KeyTitles, I )
  7. //        pstring ( "string", I )
  8. //        postplot ( "file_name", "mode", I )
  9. //        latexplot ( "file_name", "mode", I )
  10. //        printplot ( "printer-name", I )
  11. //        psave ( "file_name", A )
  12. //        pssave ( "file_name", X, Y, Z )
  13. //        multiplot ( rows, columns, I )    !!!!!! Special GNUPLOT-contrib needed !!!!!!
  14. //        nomultiplot ( I )        !!!!!! Special GNUPLOT-contrib needed !!!!!!
  15. //        plotyy ( I )            !!!!!! Special GNUPLOT-contrib needed !!!!!!
  16. //        noplotyy ( I )            !!!!!! Special GNUPLOT-contrib needed !!!!!!
  17. //        pclose ( I )
  18. //        setterm ( "term", I )
  19. //        showplot ( I )
  20. //        showpwin ( )
  21. //        phelp ( "string", I)
  22. //        autoscale ( "axis", I )
  23. //        range ( x-start, x-end, y-start, y-end, z-start, z-end, I )
  24. //        xrange ( start, end, I )
  25. //        yrange ( start, end, I )
  26. //        zrange ( start, end, I )
  27. //        xtics ( start, end, incr, I ) or xtics (vector, I ) or xtics ( I )
  28. //        noxtics ( I )
  29. //        ytics ( start, end, incr, I ) or ytics (vector, I ) or ytics ( I )
  30. //        noytics ( I )
  31. //        ztics ( start, end, incr, I ) or ytics (vector, I ) or ytics ( I )
  32. //        noztics ( I )
  33. //        loglog ( I )
  34. //        semilogx ( I )
  35. //        semilogy ( I )
  36. //        nolog ( I )
  37. //        xlabel ( "label_name", I )
  38. //        ylabel ( "label_name", I )
  39. //        zlabel ( "label_name", I )
  40. //        title ( "title_name", I )
  41. //        notitle ( "title_name", I )
  42. //        linestyle ( "line_style", I )
  43. //        pformat ( "format-string", "axis", I )
  44. //        key ( x, y, z, I )    (*)
  45. //        nokey ( I )
  46. //        grid ( I )
  47. //        nogrid ( I )
  48. //        axis ( I )
  49. //        noaxis ( I )
  50. //        label ( "label_text", x, y, z, labelnr, I )    (*)
  51. //        nolabel ( labelnr, I )
  52. //        time ( I )
  53. //        notime ( I )
  54.  
  55. //        (*) Be alert how you send these commands. You will get into trouble
  56. //            if you try to send "I" without fully specified coordinates.
  57. //            Do not leave out "z" or "labelnr" for example.
  58.  
  59. // Description:
  60.  
  61. //  The plot function plots numeric data via the GNUPLOT program. The
  62. //  argument A can be a matrix, or a list of matrices, or a string.
  63. //  plot can also plot a vector Y versus a vector X. X and Y can
  64. //  also be matrixes. 
  65. //  When A is a matrix, columns 2 through N are plotted versus the 1st
  66. //  column. When A is a list of matrices, each matrix is plotted
  67. //  versus it's own 1st column. When A is a string, the string is sent
  68. //  to GNUPLOT as a command.
  69.  
  70. //  plot ( M )                  plots the contents of matrix M
  71. //  plot( X, Y )            plots Y verus X
  72. //  plot ( << M1 ; M2>> )        plots M1, and M2 on the same graph
  73. //  plot ( "set noborder" )        sends the string directly to
  74. //                      GNUPLOT as a command
  75.  
  76. //  Using a list of matrices as an argument to plot is useful when the
  77. //  the independent variable (1st column) of each matrix is different.
  78.  
  79. //  The second and third, and optional argument to plot denotes the plot process
  80. //  number and sends key-titles. The plot() function will open distinct plot
  81. //  processes when given distinct values of N. When this feature is used in a
  82. //  X-windows environment, the effect is to create separate plot windows.
  83. //  The KeyTitles is a string-vector containing the titles to be plotted as keys.
  84. //  They are chosen from the beginning of KeyTitles[1] and so on.
  85. //  For example:
  86.  
  87. //  plot ( M );                plot the contents if matrix M
  88. //  plot ( 2.*M, 1 );            plot 2 times M, to another window
  89. //  plot (<<M1;M2>>, KeyTitles, 2);    plot M1, and M2 on the same graph in another
  90. //                    window with the keytitles from KeyTitles
  91.  
  92. //  The replot() command can be used to replot the last plot. It can also be
  93. //  used to superinpose a new plot in an old plot.
  94.  
  95. //  replot( I );            replot the I-th plot-window
  96. //  replot( A, KeyTitles, I );        superinpose new plot on the I-th plot-window
  97. //  replot( X, Y, I );            superinpose new plot on the I-th plot-window
  98.  
  99. //  For 3D-plotting there are several commands. splot() makes a 3D-surface plot
  100. //  and cont() makes a 2D-contour plot. This is in GNUPLOT a 3D-plot with no 
  101. //  surface.
  102. //  
  103. //  The splot() function splots numeric data via the GNUPLOT program. The
  104. //  argument Z is a matrix as functions of vectors X and Y.
  105.  
  106. //  splot ( X, Y, Z )            splots the contents of matrix Z
  107. //                    versus X and Y
  108. //  splot ( Z )                splots the contents of matrix Z
  109. //                    versus rows and columns
  110. //  splot ( X, Y, [Z1,Z2] )        splots Z1, and Z2 on the same graph
  111. //  cont ( X, Y, Z )            splots the contents of matrix Z
  112. //                    as a 2D-contour-plot
  113. //  cont ( X, Y, [Z1,Z2] )        splots Z1, and Z2 on the same graph
  114. //                    as a 2D-contour-plot
  115.  
  116. //  The psave() and pssave() saves the usual temporary file to a specific, 
  117. //  non-temporary file named "file_name". psave() is for 2D-plots and pssave() 
  118. //  is for 3D-plots. This is useful if you wish to save session-output in a 
  119. //  GNUPLOT-way.
  120.  
  121. //  multiplot() allows you to make multiple plots in one window. After giving 
  122. //  the command you enter multimode. After making rows*columns plot commands 
  123. //  you automaticly leaves this mode. plotyy() allows you to make one plot with 
  124. //  two y-axes. You will enter multimode, and after making two plot commands you 
  125. //  leave. The first plot will be on the left axis and the second on the right. 
  126. //  If you want to leave multiplot() or plotyy() before ending the plot commands
  127. //  just type nomultiplot() or noplotyy().
  128. //  If you want a PostScript output from plots made in multimode you do not 
  129. //  use postplot(). This will not work. plotyy() is for 2D-plots only. 
  130. //  GNUPLOT-3.5 DO NOT SUPPORT THESE FEATURES. If you want to use them 
  131. //  you must add GNUPLOT-contributions and recompile GNUPLOT.
  132.  
  133. //  The pclose function closes (destroys)  the I-th GNUPLOT
  134. //  subprocess. If I = "all", all GNUPLOT subprocess are closed.
  135.  
  136. //  The postplot() function generates a PostScript file named "file_name" 
  137. //  of the current I-th plot. "mode" is further postscript definitions to 
  138. //  GNUPLOT if needed, for example "eps color 'Times-Roman' 14" for making
  139. //  a smaller plot in color with Times-Roman-font size 14.
  140. //  The PostScript plot is saved in a file for printing, or whatever. 
  141. //  Immediately after calling postplot(), the GNUPLOT variables
  142. //  term, and output are reset to there former values.
  143. //  printplot() generates a PostScript file and sends it to the printer.
  144. //  latexplot() generates a LaTeX file named "file_name" of the current 
  145. //  I-th plot. 
  146.  
  147. //  The setterm function allows the user to set/reset the I-th plot's
  148. //  term type. The argument "term" is a string that corresponds to one
  149. //  of GNUPLOT's available term types, for example "vttek".
  150.  
  151. //  The showplot function prints the contents of the I-th plot list to
  152. //  stdout.
  153. //  The showpwin function prints the currently existing plotwindows 
  154. //  to stdout.
  155.  
  156. //  A bunch of often used commands to GNUPLOT has special functions.
  157. //  These could just as well be sent as strings, but this makes life easier.
  158. //  These are range(), xrange(), yrange(), zrange(), xtics(), ytics(), 
  159. //  noxtics(), noytics(), loglog(), semilogx(), semilogy(), nolog(), 
  160. //  autoscale(), xlabel(), ylabel(), zlabel(), 
  161. //  title(), notitle(), linestyle(), pformat(), key(), nokey(), 
  162. //  grid(), nogrid(), axis(), noaxis(), label(), nolabel(), 
  163. //  time() and notime().
  164.  
  165. //  The xtics(), ytics() and ztics() functions sets the tics on the axes. 
  166. //  If it is used as xtics(start,end,incr,I), the tics will be set 
  167. //  for plotwindow I, starting from "start", ending at "end", 
  168. //  with an increment of "incr". 
  169. //  If, however, it is used as xtics([a,b,c,d],I), the tics will 
  170. //  set at "a", "b", "c" and "d" in plotwindow I. 
  171. //  The command xtics(I) will reset the tics in plotwindow I.
  172. //  The noxtics() function results in a tics-less x-axis.
  173.  
  174. //  The plot function is an interface to the GNUPLOT program. The plot
  175. //  function uses temporary files and Rlab's piping capability to
  176. //  transparently plot numerical data via GNUPLOT. Since the plot
  177. //  function is an rfile, it could easily be modified to to use
  178. //  another plotting program.
  179.  
  180. //  To be able to use all commands in this r-file you must add some
  181. //  contributions to GNUPLOT and recompile it. These are "multiplot"
  182. //  and "borders". See the GNUPLOT FAQ for help.
  183.  
  184. //-------------------------------------------------------------------//
  185.  
  186.  
  187.  
  188. _RePlotParameter = zeros(1,100);
  189.  
  190. //
  191. // List to contain plot-object lists.
  192. //
  193.  
  194. static (p);
  195. p = <<>>;
  196.  
  197. //
  198. // Internal plot-related functions
  199. //
  200.  
  201. static (plotl, plotm, splotm, plots);
  202. static (pobj_Create, pobj_Reset, pobj_Destroy);
  203. static (pobj_TmpFileName, pobj_WriteData, pobj_PlotCmd, pobj_RePlotCmd, pobj_SPlotCmd);
  204. static (pobj_PlotKeyTitle, pobj_Plot, pobj_SetRm, pobj_Rm);
  205.  
  206.  
  207.  
  208. //
  209. // User interface to plot functionality
  210. //
  211.  
  212. plot = function ( data, titles, N )
  213. {
  214.     local( WaitAMoment, sizemem, flag1, flag2, flag3 )
  215.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  216.  
  217.     flag1 = 0;
  218.     flag2 = 0;
  219.     flag3 = 0;
  220.     // Check the existence titles
  221.     if (exist (titles)) {
  222.     if (class (titles) == "num") {
  223.         if (max (size (titles)) == 1) {
  224.         N = titles;
  225.         else
  226.         flag1=1;
  227.         sizemem = size (data);
  228.         if (data.nr < data.nc) {
  229.             flag2 = 1;
  230.             data = data';
  231.         }
  232.         if (titles.nr < titles.nc) {
  233.             flag3 = 1;
  234.             titles = titles';
  235.         }
  236.         data = [data,titles];
  237.         }
  238.     }
  239.     }
  240.     
  241.     // Set the default plot-object
  242.     if (!exist (N)) { N = 0; }
  243.  
  244.     // Check the existence of p.[N]
  245.     if (max (size (N)) != 1) { error ("plot(): N must be a 1-by-1"); }
  246.     if (exist (p.[N])) {
  247.     pobj_Reset (N);
  248.     else
  249.     pobj_Create (N);
  250.     }
  251.  
  252.     // Check for multiplot and/or plotyy mode
  253.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  254.     // Delay (RLaB is a bit to fast)
  255.     for(i in 1:1000) {
  256.         WaitAMoment=1;
  257.         clear(WaitAMoment);
  258.     }
  259.     // Check for plotyy mode
  260.     if (exist (_PlotYyParameter)) {
  261.         if (_PlotYyParameter==1) {
  262.         printf (" Plot on left y-axis done!\n");
  263.         if (!exist (_MultiPlotParameter)) {
  264.             system("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  265.         }
  266.         system("taskwindow \"gnupipe set border 7\" -wimpslot 32k -quit");
  267.         else if (_PlotYyParameter==2) {
  268.             printf (" Plot on right y-axis done!\n");
  269.             system("taskwindow \"gnupipe set border 8\" -wimpslot 32k -quit");
  270.         }   }
  271.         _PlotYyParameter=_PlotYyParameter+1;
  272.     }
  273.     // Check for multiplot mode
  274.     if (exist (_MultiPlotParameter)) {
  275.         printf (" Plot number %i/%i done!\n",_MultiPlotParameter[3],_MultiPlotParameter[1]*_MultiPlotParameter[2]);
  276.         if (_MultiPlotParameter[3]==1) {
  277.         system("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  278.         system("taskwindow \"gnupipe set size " + 1./_MultiPlotParameter[2] + "," + 1./_MultiPlotParameter[1] + "\" -wimpslot 32k -quit");
  279.         }
  280.         N=_MultiPlotParameter[4];
  281.         system ("taskwindow \"gnupipe set orgin " +_MultiOrginParameter[_MultiPlotParameter[3];1] + "," + _MultiOrginParameter[_MultiPlotParameter[3];2] + "\" -wimpslot 32k -quit");
  282.         if (exist (_PlotYyParameter)) {
  283.         if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  284.         else
  285.         _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  286.         }
  287.     }
  288.     }
  289.    
  290.  
  291.     // Time to plot
  292.     if (class (data) == "num") {
  293.         system("taskwindow \"gnupipe set noparametric\" -wimpslot 32k -quit");
  294.     pobj_Rm (N);
  295.     plotm (data, N, 1, titles);
  296.     pobj_Plot (N);
  297.     pobj_SetRm (N);
  298.     else if (class (data) == "string") {
  299.         plots (data, N);
  300.         pobj_Plot (N);
  301.         else if (class (data) == "list") {
  302.         pobj_Rm (N);
  303.         plotl (data, N, titles);
  304.         pobj_Plot (N);
  305.         pobj_SetRm (N);    
  306.         else
  307.         error ("Invalid data for plot()");
  308.     }   }   }
  309.     
  310.     // Check for multiplot and/or plotyy mode
  311.     // Check for plotyy mode
  312.     if (exist (_PlotYyParameter)) {
  313.     if (_PlotYyParameter==3) {
  314.         if (!exist (_MultiPlotParameter)) { 
  315.           system("taskwindow \"gnupipe setnomultiplot\" -wimpslot 32k -quit"); 
  316.         }
  317.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  318.         clear(_PlotYyParameter);
  319.     }
  320.     }
  321.     // Check for multiplot mode
  322.     if (exist (_MultiPlotParameter)) {
  323.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  324.         system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  325.         system ("taskwindow \"gnupipe set size 1,1\" -wimpslot 32k -quit");
  326.         system ("taskwindow \"gnupipe set orgin 0,0\" -wimpslot 32k -quit");
  327.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  328.         clear(_MultiPlotParameter);
  329.         clear(_MultiOrginParameter);
  330.     }
  331.     }
  332.     
  333.     if (flag1 == 1) { 
  334.     if (flag2 == 0) {
  335.         data = data[;1:sizemem[2]];
  336.         else
  337.         data = data[;1:sizemem[1]];
  338.     }
  339.     if (flag2 == 1) { data = data'; }
  340.     if (flag3 == 1) { titles = titles'; }
  341.     }
  342.  
  343. };
  344.  
  345. //
  346. // User interface to replot functionality
  347. //
  348.  
  349. replot = function ( data, titles, N )
  350. {
  351.     local( sizemem, flag1, flag2, flag3, flag4 );
  352.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  353.     global( _RePlotParameter );
  354.     
  355.     flag1 = 0;
  356.     flag2 = 0;
  357.     flag3 = 0;
  358.     flag4 = 0;
  359.     // Check the existence titles
  360.     if (exist (titles)) {
  361.     if (class (titles) == "num") {
  362.         if (max (size (titles)) == 1) {
  363.         N = titles;
  364.         else
  365.         flag1=1;
  366.         sizemem = size (data);
  367.         if (data.nr < data.nc) {
  368.             flag2 = 1;
  369.             data = data';
  370.         }
  371.         if (titles.nr < titles.nc) {
  372.             flag3 = 1;
  373.             titles = titles';
  374.         }
  375.         data = [data,titles];
  376.         }
  377.     }
  378.     }
  379.     
  380.     if (exist (data) && !exist (titles)) {
  381.     if (max(size(data)) == 1) {
  382.         N = data;
  383.         clear(data);
  384.         flag4=1;
  385.     }
  386.     }
  387.     // Set the default plot-object
  388.     if (!exist (N)) { N = 0; }
  389.  
  390.     // Check the existence of p.[N]
  391.     if (max (size (N)) != 1) { error ("plot(): N must be a 1-by-1"); }
  392.     if (exist (p.[N])) {
  393.     pobj_Reset (N);
  394.     else
  395.     pobj_Create (N);
  396.     }
  397.  
  398.     // Time to plot
  399.     if (!exist(data)) {
  400.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit");
  401.     if (flag4 == 1) { data = N; }
  402.     return 0;
  403.     }
  404.     if (class (data) == "num") {
  405.     system ("taskwindow \"gnupipe set noparametric\" -wimpslot 32k -quit");
  406.     _RePlotParameter[N+1] = _RePlotParameter[N+1]+1;
  407.     pobj_Rm (N);
  408.     replotm (data, N, 1, titles);
  409.     pobj_Plot (N);
  410.     pobj_SetRm (N);
  411.     else if (class (data) == "string") {
  412.         plots (data, N);
  413.         pobj_Plot (N);
  414.         else if (class (data) == "list") {
  415.         pobj_Rm (N);
  416.         plotl (data, N, titles);
  417.         pobj_Plot (N);
  418.         pobj_SetRm (N);    
  419.         else
  420.         error ("Invalid data for replot()");
  421.     }   }   }
  422.  
  423.     if (flag1 == 1) { 
  424.     if (flag2 == 0) {
  425.         data = data[;1:sizemem[2]];
  426.         else
  427.         data = data[;1:sizemem[1]];
  428.     }
  429.     if (flag2 == 1) { data = data'; }
  430.     if (flag3 == 1) { titles = titles'; }
  431.     }
  432.  
  433. };
  434.  
  435.  
  436. //
  437. // User interface to splot functionality
  438. //
  439.  
  440. splot = function ( datax, datay, datazz, titles, N )
  441. {
  442.     local (flag1, flag2, flag3, flag4, flagx, flagy, WaitAMoment)
  443.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  444.  
  445.     // Reset flags
  446.     flag1=0;
  447.     flag2=0;
  448.     flag3=0;
  449.     flag4=0;
  450.     flagx=0;
  451.     flagy=0;
  452.  
  453.     // Check what has been sent here
  454.     // One input!
  455.     if (!exist (datay)) {
  456.     datazz=datax;
  457.     datax=1:datazz.nc;
  458.     datax=datax';
  459.     datay=1:datazz.nr;
  460.     datay=datay';
  461.     flag1=flag1+1;
  462.     // Two inputs!
  463.     else if (!exist (datazz)) {
  464.         if (exist (datay)) {
  465.         if (class (datay) == "num") {
  466.             N = datay;
  467.             flag2=flag2+0;
  468.             else
  469.             titles = datay;
  470.             flag2=flag2+1;
  471.         }
  472.         }
  473.         datazz=datax;
  474.         datax=1:datazz.nc;
  475.         datax=datax';
  476.         datay=1:datazz.nr;
  477.         datay=datay';
  478.         flag2=flag2+1;
  479.         // Three inputs!
  480.         else if (!exist (titles)) {
  481.         if (class (datay) != "num") {
  482.             titles = datay;
  483.             N = datazz;
  484.             datazz=datax;
  485.             datax=1:datazz.nc;
  486.             datax=datax';
  487.             datay=1:datazz.nr;
  488.             datay=datay';
  489.             flag3=flag3+1;
  490.         }
  491.         // Four inputs!
  492.         else if (!exist (N)) {
  493.             if (class (titles) == "num") {
  494.             N=titles;
  495.             flag4=flag4+1;
  496.             }
  497.     }   }   }   }
  498.     
  499.     // Transpose x- and y-vectors if nessecary
  500.     if (datax.nc != 1 ) {
  501.     if (datax.nr != 1 ) {
  502.         error ("Invalid data for x-axis (not a vector)");
  503.         else
  504.         datax = datax';
  505.         flagx=flagx+1;
  506.     }
  507.     }
  508.     if (datay.nc != 1 ) {
  509.     if (datay.nr != 1 ) {
  510.         error ("Invalid data for y-axis (not a vector)");
  511.         else
  512.         datay = datay';
  513.         flagy=flagy+1;
  514.     }
  515.     }
  516.     
  517.     // Check how many splots to do
  518.     plotantal=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  519.     if (plotantal == int(plotantal)) {
  520.     
  521.     // Set the default splot-object
  522.     if (!exist (N)) { N = 0; }
  523.  
  524.     // Check the existence of p.[N]
  525.     if (max (size (N)) != 1) { error ("splot(): N must be a 1-by-1"); }
  526.     if (exist (p.[N])) {
  527.         pobj_Reset (N);
  528.         else
  529.         pobj_Create (N);
  530.     }
  531.  
  532.     // Check for multiplot and/or plotyy mode
  533.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  534.         // Delay (RLaB is a bit to fast)
  535.         for(i in 1:1000) {
  536.         WaitAMoment=1;
  537.         clear(WaitAMoment);
  538.         }
  539.         // Check for plotyy mode
  540.         if (exist (_PlotYyParameter)) {
  541.         if (_PlotYyParameter==1) {
  542.             if (!exist (_MultiPlotParameter)) {
  543.             system ("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  544.             }
  545.             system ("taskwindow \"gnupipe set border 7\" -wimpslot 32k -quit");
  546.             else if (_PlotYyParameter==2) {
  547.             system ("taskwindow \"gnupipe set border 8\" -wimpslot 32k -quit");
  548.         }   }
  549.         _PlotYyParameter=_PlotYyParameter+1;
  550.         }
  551.         // Check for multiplot mode
  552.         if (exist (_MultiPlotParameter)) {
  553.         printf (" Plot number %i/%i done!\n",_MultiPlotParameter[3],_MultiPlotParameter[1]*_MultiPlotParameter[2]);            
  554.         if (_MultiPlotParameter[3]==1) {
  555.             system ("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  556.             system ("taskwindow \"gnupipe set size " + 1./_MultiPlotParameter[2], + "," + 1./_MultiPlotParameter[1]+ "\" -wimpslot 32k -quit");
  557.         }
  558.         N=_MultiPlotParameter[4];
  559.         system ("taskwindow \"set orgin " + _MultiOrginParameter[_MultiPlotParameter[3];1] + "," +_MultiOrginParameter[_MultiPlotParameter[3];2] + "\" -wimpslot 32k -quit");
  560.         if (exist (_PlotYyParameter)) {
  561.             if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  562.             else
  563.             _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  564.         }
  565.         }
  566.     }
  567.  
  568.     if (class (datax) != "num") {
  569.         error ("Invalid data class for splot() in x-vector (must be num)");
  570.         else if (class (datay) != "num") {
  571.         error ("Invalid data class for splot() in y-vector (must be num)");
  572.         else if (class (datazz) != "num") {
  573.             error ("Invalid data class for splot() in x-matrix (must be num)");
  574.             else
  575.             system ("taskwindow \"gnupipe set parametric\" -wimpslot 32k -quit");
  576.             system ("taskwindow \"gnupipe set view 60, 30, 1, 1\" -wimpslot 32k -quit");
  577.             system ("taskwindow \"gnupipe set surface\" -wimpslot 32k -quit");
  578.             system ("taskwindow \"gnupipe set nocontour\" -wimpslot 32k -quit");
  579.             pobj_Rm (N);
  580.             splotm (datax, datay, datazz, N, 1, titles);
  581.             pobj_Plot (N);
  582.             pobj_SetRm (N);
  583.     }   }   }
  584.     else
  585.     error ("Invalid data for splot(), bad x/y-range in z-matrix");
  586.     }
  587.     
  588.     // Restore the output/input
  589.     if (flag1 == 1) { datax=datazz; }
  590.     if (flag2 == 1) {
  591.     datax=datazz;
  592.     datay=N;
  593.     else if (flag2 == 2) {
  594.         datax=datazz;
  595.         datay=titles;
  596.     }   }
  597.     if (flag3 == 1) {
  598.     datax=datazz;
  599.     datay=titles;
  600.     datazz=N;
  601.     }
  602.     if (flag4 == 1) { titles=N; }
  603.     if (flagx == 1) { datax=datax'; }
  604.     if (flagy == 1) { datay=datay'; }
  605.  
  606.     // Check for multiplot and/or plotyy mode
  607.     // Check for plotyy mode
  608.     if (exist (_PlotYyParameter)) {
  609.     if (_PlotYyParameter==3) {
  610.         if (!exist (_MultiPlotParameter)) { 
  611.           system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit"); 
  612.         }
  613.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  614.         clear(_PlotYyParameter);
  615.     }
  616.     }
  617.     // Check for multiplot mode
  618.     if (exist (_MultiPlotParameter)) {
  619.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  620.         system("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  621.         system("taskwindow \"gnupipe set size 1,1\" -wimpslot 32k -quit");
  622.         system("taskwindow \"gnupipe set orgin 0,0\" -wimpslot 32k -quit");
  623.         system("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  624.         clear(_MultiPlotParameter);
  625.         clear(_MultiOrginParameter);
  626.     }
  627.     }
  628. };
  629.  
  630.  
  631.  
  632. //
  633. // User interface to splot functionality as 2D-contour
  634. //
  635.  
  636. cont = function ( datax, datay, datazz, titles, N )
  637. {
  638.     local (flag1, flag2, flag3, flag4, flagx, flagy, WaitAMoment)
  639.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  640.  
  641.     // Reset flags
  642.     flag1=0;
  643.     flag2=0;
  644.     flag3=0;
  645.     flag4=0;
  646.     flagx=0;
  647.     flagy=0;
  648.  
  649.     // Check what has been sent here
  650.     // One input!
  651.     if (!exist (datay)) {
  652.     datazz=datax;
  653.     datax=1:datazz.nc;
  654.     datax=datax';
  655.     datay=1:datazz.nr;
  656.     datay=datay';
  657.     flag1=flag1+1;
  658.     // Two inputs!
  659.     else if (!exist (datazz)) {
  660.         if (exist (datay)) {
  661.         if (class (datay) == "num") {
  662.             N = datay;
  663.             flag2=flag2+0;
  664.             else
  665.             titles = datay;
  666.             flag2=flag2+1;
  667.         }
  668.         }
  669.         datazz=datax;
  670.         datax=1:datazz.nc;
  671.         datax=datax';
  672.         datay=1:datazz.nr;
  673.         datay=datay';
  674.         flag2=flag2+1;
  675.         // Three inputs!
  676.         else if (!exist (titles)) {
  677.         if (class (datay) != "num") {
  678.             titles = datay;
  679.             N = datazz;
  680.             datazz=datax;
  681.             datax=1:datazz.nc;
  682.             datax=datax';
  683.             datay=1:datazz.nr;
  684.             datay=datay';
  685.             flag3=flag3+1;
  686.         }
  687.         // Four inputs!
  688.         else if (!exist (N)) {
  689.             if (class (titles) == "num") {
  690.             N=titles;
  691.             flag4=flag4+1;
  692.             }
  693.     }   }   }   }
  694.     
  695.     // Transpose x- and y-vectors if nessecary
  696.     if (datax.nc != 1 ) {
  697.     if (datax.nr != 1 ) {
  698.         error ("Invalid data for x-axis (not a vector)");
  699.         else
  700.         datax = datax';
  701.         flagx=flagx+1;
  702.     }
  703.     }
  704.     if (datay.nc != 1 ) {
  705.     if (datay.nr != 1 ) {
  706.         error ("Invalid data for y-axis (not a vector)");
  707.         else
  708.         datay = datay';
  709.         flagy=flagy+1;
  710.     }
  711.     }
  712.     
  713.     // Check how many splots to do
  714.     plotantal=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  715.     if (plotantal == int(plotantal)) {
  716.  
  717.     // Set the default splot-object
  718.     if (!exist (N)) { N = 0; }
  719.  
  720.     // Check the existence of p.[N]
  721.     if (max (size (N)) != 1) { error ("splot(): N must be a 1-by-1"); }
  722.     if (exist (p.[N])) {
  723.         pobj_Reset (N);
  724.         else
  725.         pobj_Create (N);
  726.     }
  727.  
  728.     // Check for multiplot and/or plotyy mode
  729.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  730.         // Delay (RLaB is a bit to fast)
  731.         for(i in 1:1000) {
  732.         WaitAMoment=1;
  733.         clear(WaitAMoment);
  734.         }
  735.         // Check for plotyy mode
  736.         if (exist (_PlotYyParameter)) {
  737.         if (_PlotYyParameter==1) {
  738.             if (!exist (_MultiPlotParameter)) {
  739.                 system("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  740.             }
  741.             system ("taskwindow \"gnupipe set border 7\" -wimpslot 32k -quit");
  742.             else if (_PlotYyParameter==2) {
  743.                 system("taskwindow \"gnupipe set border 8\" -wimpslot 32k -quit");
  744.         }   }
  745.         _PlotYyParameter=_PlotYyParameter+1;
  746.         }
  747.         // Check for multiplot mode
  748.         if (exist (_MultiPlotParameter)) {
  749.         if (_MultiPlotParameter[3]==1) {
  750.             system("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  751.             system("taskwindow \"gnupipe set size " + 1/_MultiPlotParameter[2] + "," + 1/_MultiPlotParameter[1] + "\" -wimpslot 32k -quit");
  752.         }
  753.         N=_MultiPlotParameter[4];
  754.             system ("taskwindow \"gnupipe set orgin " +_MultiOrginParameter[_MultiPlotParameter[3];1] + "," + _MultiOrginParameter[_MultiPlotParameter[3];2] + "\" -wimpslot 32k -quit");
  755.         if (exist (_PlotYyParameter)) {
  756.             if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  757.             else
  758.             _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  759.         }
  760.         }
  761.     }
  762.  
  763.     if (class (datax) != "num") {
  764.         error ("Invalid data class for splot() in x-vector (must be num)");
  765.         else if (class (datay) != "num") {
  766.         error ("Invalid data class for splot() in y-vector (must be num)");
  767.         else if (class (datazz) != "num") {
  768.             error ("Invalid data class for splot() in x-matrix (must be num)");
  769.             else
  770.             system ("taskwindow \"gnupipe set parametric\" -wimpslot 32k -quit");
  771.             system ("taskwindow \"gnupipe set view 0, 0, 1\" -wimpslot 32k -quit");
  772.             system ("taskwindow \"gnupipe set nosurface\" -wimpslot 32k -quit");
  773.             system ("taskwindow \"gnupipe set contour\" -wimpslot 32k -quit");
  774.             pobj_Rm (N);
  775.             splotm (datax, datay, datazz, N, 1, titles);
  776.             pobj_Plot (N);
  777.             pobj_SetRm (N);
  778.     }   }   }
  779.     else
  780.     error ("Invalid data for splot(), bad x/y-range in z-matrix");
  781.     }
  782.     
  783.     // Restore the output/input
  784.     if (flag1 == 1) { datax=datazz; }
  785.     if (flag2 == 1) {
  786.     datax=datazz;
  787.     datay=N;
  788.     else if (flag2 == 2) {
  789.         datax=datazz;
  790.         datay=titles;
  791.     }   }
  792.     if (flag3 == 1) {
  793.     datax=datazz;
  794.     datay=titles;
  795.     datazz=N;
  796.     }
  797.     if (flag4 == 1) { titles=N; }
  798.     if (flagx == 1) { datax=datax'; }
  799.     if (flagy == 1) { datay=datay'; }
  800.  
  801.     // Check for multiplot and/or plotyy mode
  802.     // Check for plotyy mode
  803.     if (exist (_PlotYyParameter)) {
  804.     if (_PlotYyParameter==3) {
  805.         if (!exist (_MultiPlotParameter)) { 
  806.           system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  807.         }
  808.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  809.         clear(_PlotYyParameter);
  810.     }
  811.     }
  812.     // Check for multiplot mode
  813.     if (exist (_MultiPlotParameter)) {
  814.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  815.         system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  816.         system ("taskwindow \"gnupipe set size 1,1\" -wimpslot 32k -quit");
  817.         system ("taskwindow \"gnupipe set orgin 0,0\" -wimpslot 32k -quit");
  818.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  819.         clear(_MultiPlotParameter);
  820.         clear(_MultiOrginParameter);
  821.     }
  822.     }
  823. };
  824.  
  825.  
  826.  
  827. //
  828. // Send string to GNUPLOT
  829. //
  830.  
  831. pstring = function ( string, N )
  832. {
  833.     if (!exist (N)) { N = 0; }
  834.     if (!exist (p.[N])) { pobj_Create (N); }
  835.     system ("taskwindow \"gnupipe " + string + "\" -wimpslot 32k -quit");
  836. };
  837.  
  838.  
  839.  
  840. //
  841. // User interface to save a plot ot splot as postscript hardcopy
  842. //
  843.  
  844. postplot = function ( file, mode, N )
  845. {
  846.     local ( flag1 );
  847.     flag1 = 0;
  848.     if (!exist (N) && exist (mode)) {
  849.     if (class (mode) == "num") {
  850.         N = mode;
  851.         flag1 = 1;
  852.     }
  853.     }
  854.  
  855.     if (!exist (N)) { N = 0; }
  856.     if (!exist (p.[N])) { error ("No existing plot to make hardcopy from"); }
  857.  
  858.     // Make hardcopy file
  859.     if (!exist (mode)) { mode="default"; }
  860.     if (class (mode) == "num") { mode="default"; }
  861.  
  862.     system ("taskwindow \"gnupipe set term post " + mode + "\" -wimpslot 32k -quit");
  863.     system ("taskwindow \"gnupipe set output " + file + "\" -wimpslot 32k -quit"); 
  864.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit" );
  865.  
  866.  
  867.     // Reset to original term type, and replot
  868.     system ("taskwindow \"gnupipe set term  " + p.[N].term + "\" -wimpslot 32k -quit");
  869.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit" );
  870.  
  871.     if (flag1 == 1) {
  872.     mode = N;
  873.     }
  874. };
  875.  
  876.  
  877.  
  878. //
  879. // User interface to save a plot ot splot as LaTeX hardcopy
  880. //
  881.  
  882. latexplot = function ( file, mode, N )
  883. {
  884.     local ( flag1 );
  885.     flag1 = 0;
  886.     if (!exist (N) && exist (mode)) {
  887.     if (class (mode) == "num") {
  888.         N = mode;
  889.         flag1 = 1;
  890.     }
  891.     }
  892.  
  893.     if (!exist (N)) { N = 0; }
  894.     if (!exist (p.[N])) { error ("No existing plot to make hardcopy from"); }
  895.  
  896.     // Make hardcopy file
  897.     if (!exist (mode)) { mode="default"; }
  898.     if (class (mode) == "num") { mode="default"; }
  899.     system ("taskwindow \"gnupipe set term latex " + mode + "\" -wimpslot 32k -quit");
  900.     system ("taskwindow \"gnupipe set output " + file + "\" -wimpslot 32k -quit"); 
  901.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit" );
  902.  
  903.  
  904.     // Reset to original term type, and replot
  905.     system ("taskwindow \"gnupipe set term  " + p.[N].term + "\" -wimpslot 32k -quit");
  906.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit" );
  907.  
  908.     if (flag1 == 1) {
  909.     mode = N;
  910.     }
  911. };
  912.  
  913.  
  914. //
  915. // User interface to print a plot ot splot
  916. //
  917.  
  918. printplot = function ( printername, N )
  919. {
  920.     local(fn, flag1);
  921.     
  922.     flag1 = 0;
  923.     if (exist (printername) && !exist(N)) {
  924.     if (class (printername) == "num") {
  925.         N = printername;
  926.         clear(printername);
  927.         flag1 = 1;
  928.     }
  929.     }
  930.     
  931.     if (!exist (N)) { N = 0; }
  932.     if (!exist (p.[N])) { pobj_Create (N); }
  933.     
  934.     // Create tmp-file-name
  935.     fn = "rtmpf";
  936.  
  937.     postplot (fn, "default", N);
  938.         // Delay (RLaB is a bit to fast)
  939.     for(i in 1:1000) {
  940.     WaitAMoment=1;
  941.     clear(WaitAMoment);
  942.     }
  943.     if (exist (printername)) {
  944.     system ("lp -d" + printername + " " + fn);
  945.     else
  946.     system ("lp " + fn);
  947.     }
  948.     // Delay (RLaB is a bit to fast)
  949.     for(i in 1:1000) {
  950.     WaitAMoment=1;
  951.     clear(WaitAMoment);
  952.     }
  953.     system ("rm -f " + fn);
  954.     
  955.     if (flag1 == 1) {
  956.     printername = N;
  957.     }
  958. };
  959.  
  960.  
  961. //
  962. // User interface to save plots as GNUPLOT-datafiles
  963. //
  964.  
  965. psave = function ( file, data )
  966. {
  967.     local (ans, i, nplot, flag1);
  968.  
  969.     flag1 = 0;
  970.     // Check file-name
  971.     if (class (file) != "string") {
  972.     error ("Invalid string for file_name");
  973.     }
  974.  
  975.     // Determine how many lines to save
  976.     nplot = max ([1, data.nc - 1]);
  977.  
  978.     if (nplot > data.nr) {
  979.     printf (" Save %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  980.     ans = getline ("stdin");
  981.     if (ans.[1] != "y" && ans.[1] != "t") {
  982.         return 0;
  983.     }
  984.     if (ans.[1] == "t") {
  985.         data = data';
  986.         nplot = max ([1, data.nc - 1]);
  987.         flag1 = 1;
  988.     }
  989.     }
  990.  
  991.     // Generate two column matrices for saving
  992.     for (i in 1:nplot) {
  993.  
  994.     // Write data to file
  995.     if (nplot == 1) {
  996.         pobj_WriteData (real (data), file);
  997.         else
  998.         pobj_WriteData (real (data[;1,i+1]), file);
  999.     }
  1000.     }
  1001.  
  1002.     // Check flag1
  1003.     if (flag1 == 1) {
  1004.     data = data';
  1005.     }
  1006. };
  1007.  
  1008.  
  1009.  
  1010. //
  1011. // User interface to save splots as GNUPLOT-datafiles
  1012. //
  1013.  
  1014. pssave = function ( file, datax, datay, datazz)
  1015. {
  1016.     local (ans, i, nsplot, m, n, flag2, flagx, flagy);
  1017.  
  1018.     // Reset flags
  1019.     flag2=0;
  1020.     flagx=0;
  1021.     flagy=0;
  1022.  
  1023.     // Determine how many plots to draw
  1024.     if (!exist (datazz)) { 
  1025.     datazz=datax;
  1026.     datax=1:datazz.nr;
  1027.     datax=datax';
  1028.     datay=1:datazz.nc;
  1029.     datay=datay';
  1030.     flag2=flag2+1;
  1031.     }
  1032.  
  1033.     if (datax.nc != 1 ) {
  1034.     if (datax.nr != 1 ) {
  1035.         error ("Invalid data for x-axis (not a vector)");
  1036.         else
  1037.         datax = datax';
  1038.         flagx=flagx+1;
  1039.     }
  1040.     }
  1041.     if (datay.nc != 1 ) {
  1042.     if (datay.nr != 1 ) {
  1043.         error ("Invalid data for y-axis (not a vector)");
  1044.         else
  1045.         datay = datay';
  1046.         flagy=flagy+1;
  1047.     }
  1048.     }
  1049.  
  1050.     // Create file-name
  1051.     if (!exist (file)) { error ("Invalid string for file_name"); }
  1052.     if (class (file) != "string") { error ("Invalid string for file_name"); }
  1053.  
  1054.     nsplot=(datazz.nr/datazz.nc)/(datax.nr/datay.nr);
  1055.  
  1056.     // Generate three column matrices for splot program
  1057.     // Write data to new data-file
  1058.     for (i in 1:nsplot) {
  1059.     newdata=[];
  1060.     for (m in 1:datax.nr){
  1061.         rownumber=0;
  1062.         for (n in 1:datay.nr){
  1063.         rownumber=rownumber+1;
  1064.         // x-value
  1065.         newdata[rownumber;1]=datax[m];
  1066.         // y-value
  1067.         newdata[rownumber;2]=datay[n];
  1068.         // z-value
  1069.         newdata[rownumber;3]=datazz[m;n+(i-1)*datax.nr];
  1070.         }
  1071.         write (file,real (newdata[;1,2,3]));
  1072.         write (file,"");
  1073.     }
  1074.     close (file);
  1075.     }
  1076.     
  1077.     if (flag2 == 1) {
  1078.     datax=datazz;
  1079.     }
  1080.     if (flagx == 1) { datax=datax'; }
  1081.     if (flagy == 1) { datay=datay'; }
  1082.  
  1083. };
  1084.  
  1085.  
  1086.  
  1087. //
  1088. // Make multiplots
  1089. //
  1090.  
  1091. multiplot = function ( row, col, N )
  1092. {
  1093.     local (i, j, k)
  1094.     global( _MultiPlotParameter, _MultiOrginParameter );
  1095.  
  1096.     if (!exist (N)) { N = 0; }
  1097.     if (!exist (p.[N])) { pobj_Create (N); }
  1098.     _MultiPlotParameter=[row,col,1,N];
  1099.     _MultiOrginParameter=[];
  1100.     printf (" Make %i plots!\n",_MultiPlotParameter[1]*_MultiPlotParameter[2]);    
  1101.     k=1;
  1102.     for (i in 1:row) {
  1103.     for (j in 1:col) {
  1104.         _MultiOrginParameter[k;1]=(j-1)/col;
  1105.         _MultiOrginParameter[k;2]=(row-i)/row;
  1106.         k=k+1;
  1107.     }
  1108.     }
  1109. };
  1110.  
  1111.  
  1112.  
  1113. //
  1114. // Make plot with two y-axes
  1115. //
  1116.  
  1117. plotyy = function ( N )
  1118. {
  1119.     global( _PlotYyParameter );
  1120.  
  1121.     if (!exist (N)) { N = 0; }
  1122.     if (!exist (p.[N])) { pobj_Create (N); }
  1123.     printf (" Make 2 plots!\n The first on left y-axis, the second on the right!\n");
  1124.     _PlotYyParameter=1;
  1125. };
  1126.  
  1127.  
  1128.  
  1129. //
  1130. // User interface to close a GNUPLOT-window
  1131. //
  1132.  
  1133. pclose = function ( N )
  1134. {
  1135.     local (i)
  1136.     if (!exist (N)) { N = 0; }
  1137.     if (N == "all") {
  1138.     for (i in 0:99) {
  1139.         if (exist (p.[i])) {
  1140.         close (p.[i].rmf);
  1141.         close (p.[i].prog);
  1142.         pobj_Destroy (i);
  1143.         }
  1144.     }
  1145.     else
  1146.     if (!exist (p.[N])) { return -1; }
  1147.     close (p.[N].rmf);
  1148.     close (p.[N].prog);
  1149.     pobj_Destroy (N);
  1150.     }
  1151.     return N;
  1152. };
  1153.  
  1154.  
  1155.  
  1156. //
  1157. // Set the terminal type for the I-th GNUPLOT process
  1158. //
  1159.  
  1160. setterm = function ( TERM, N )
  1161. {
  1162.     if (!exist (N)) { N = 0; }
  1163.     if (!exist (p.[N])) { pobj_Create (N); }
  1164.     p.[N].term = TERM;
  1165.  
  1166.     // Now send the "set term" command to GNUPLOT
  1167.     system ("taskwindow \"gnupipe set term  " + TERM + "\" -wimpslot 32k -quit");
  1168. };
  1169.  
  1170.  
  1171.  
  1172. //
  1173. // Print out the plot list
  1174. //
  1175.  
  1176. showplot = function ( N )
  1177. {
  1178.     if (!exist (N)) { N = 0; }
  1179.     if (!exist (p.[N])) {
  1180.     pobj_Create (N);
  1181.     }
  1182.  
  1183.     printf ("\tPlot List %i\n", N);
  1184.     printf ("\t\tTerm:\t\t\t%s\n", p.[N].term);
  1185.     printf ("\t\tOutput:\t\t\t%s\n", p.[N].output);
  1186.     printf ("\t\tTmp Files:\t\t%s\n", p.[N].files);
  1187.     //    printf ("\t\tHardCopy:\t\t%s\n", p.[N].hrd);
  1188.     //    printf ("\t\tHardCopy Files:\t\t%s\n", p.[N].hrdf);
  1189. };
  1190.  
  1191. showpwin = function ()
  1192. {
  1193.     local ( i )
  1194.     for ( i in 0:99) {
  1195.     if (exist (p.[i])) {
  1196.         printf ("\tPlot window number %i exists!\n", i);
  1197.     }
  1198.     }
  1199. };
  1200.  
  1201. //
  1202. // End multiplot mode
  1203. //
  1204.  
  1205. nomultiplot = function(N)
  1206. {
  1207.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  1208.  
  1209.     if (!exist (N)) { N = 0; }
  1210.     if (!exist (p.[N])) { pobj_Create (N); }
  1211.     system ("taskwindow \"gnupipe set size 1,1\" -wimpslot 32k -quit");
  1212.     system ("taskwindow \"gnupipe set orgin 0,0\" -wimpslot 32k -quit");
  1213.     system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  1214.     if (exist (_MultiPlotParameter)) {clear(_MultiPlotParameter);}
  1215.     if (exist (_MultiOrginParameter)) {clear(_MultiOrginParameter);}
  1216.     if (exist (_PlotYyParameter)) {clear(_PlotYyParameter);}
  1217. };
  1218.  
  1219.  
  1220.  
  1221. //
  1222. // End plotyy mode
  1223. //
  1224.  
  1225. noplotyy = function(N)
  1226. {
  1227.     global( _PlotYyParameter );
  1228.  
  1229.     if (!exist (N)) { N = 0; }
  1230.     if (!exist (p.[N])) { pobj_Create (N); }
  1231.  
  1232.     system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");    
  1233.     if (exist (_PlotYyParameter)) {clear(_PlotYyParameter);}
  1234. };
  1235.  
  1236.  
  1237.  
  1238. //
  1239. // Here comes a bunch of functions that really is not nessecary.
  1240. // They could be done with string("set key") etc, but this is more convinient.
  1241. //
  1242.  
  1243.  
  1244. xrange = function ( start, end, N )
  1245. {
  1246.     if (!exist (N)) { N = 0; }
  1247.     if (!exist (p.[N])) { pobj_Create (N); }
  1248.     system ("taskwindow \"gnupipe set xrange [" + start + "," + end + "]\" -wimpslot 32k -quit");    
  1249. };
  1250.  
  1251. yrange = function ( start, end, N )
  1252. {
  1253.     if (!exist (N)) { N = 0; }
  1254.     if (!exist (p.[N])) { pobj_Create (N); }
  1255.     system ("taskwindow \"gnupipe set yrange [" + start + "," + end + "]\" -wimpslot 32k -quit");    
  1256.  
  1257. };
  1258.  
  1259. zrange = function ( start, end, N )
  1260. {
  1261.     if (!exist (N)) { N = 0; }
  1262.     if (!exist (p.[N])) { pobj_Create (N); }
  1263.     system ("taskwindow \"gnupipe set zrange [" + start + "," + end + "]\" -wimpslot 32k -quit");    
  1264. };
  1265.  
  1266. range = function ( startx, endx, starty, endy, startz, endz, N )
  1267. {
  1268.     if (exist (startz) && !exist (endz)) { N = startz; }
  1269.     if (exist (starty) && !exist (endy)) { N = starty; }
  1270.     if (!exist (N)) { N = 0; }
  1271.     if (!exist (p.[N])) { pobj_Create (N); }
  1272.     system ("taskwindow \"gnupipe set xrange [" + startx + "," + endx + "]\" -wimpslot 32k -quit");    
  1273.     if (exist(endy)) {
  1274.         system ("taskwindow \"gnupipe set yrange [" + starty + "," + endy + "]\" -wimpslot 32k -quit");    
  1275.     }
  1276.     if (exist(endz)) {
  1277.         system ("taskwindow \"gnupipe set zrange [" + startz + "," + endz + "]\" -wimpslot 32k -quit");    
  1278.     }
  1279. };
  1280.  
  1281. xtics = function ( start, end, incr, N )
  1282. {
  1283.     local ( string, i )
  1284.     if (!exist (start)) { start = 0; }
  1285.     if (!exist (incr)) {
  1286.     if (length(start) > 1) {
  1287.         if (!exist (end)) { end = 0; }
  1288.         if (!exist (p.[end])) { pobj_Create (end); }
  1289.         string = "set xtics (" + num2str(start[1])[1];
  1290.         for (i in 2:length(start)) {
  1291.         string = string + "," + num2str(start[i])[1];
  1292.         }
  1293.         string = string + ")\n";
  1294.             system ("taskwindow \"gnupipe " + string + "\" -wimpslot 32k -quit");    
  1295.         else
  1296.         if (!exist (p.[start])) { pobj_Create (start); }
  1297.             system ("taskwindow \"gnupipe set xtics\" -wimpslot 32k -quit");    
  1298.     }
  1299.     else
  1300.     if (!exist (N)) { N = 0; }
  1301.     if (!exist (p.[N])) { pobj_Create (N); }
  1302.         system ("taskwindow \"gnupipe set xtics " + start + "," + incr + "," + end + "\" -wimpslot 32k -quit");    
  1303.     }
  1304. };
  1305.  
  1306. noxtics = function ( N )
  1307. {
  1308.     if (!exist (N)) { N = 0; }
  1309.     if (!exist (p.[N])) { pobj_Create (N); }
  1310.     system ("taskwindow \"gnupipe set noxtics\" -wimpslot 32k -quit");  
  1311. };
  1312.  
  1313. ytics = function ( start, end, incr, N )
  1314. {
  1315.     local ( string, i )
  1316.     if (!exist (start)) { start = 0; }
  1317.     if (!exist (incr)) {
  1318.     if (length(start) > 1) {
  1319.         if (!exist (end)) { end = 0; }
  1320.         if (!exist (p.[end])) { pobj_Create (end); }
  1321.         string = "set ytics (" + num2str(start[1])[1];
  1322.         for (i in 2:length(start)) {
  1323.         string = string + "," + num2str(start[i])[1];
  1324.         }
  1325.         string = string + ")\n";
  1326.             system ("taskwindow \"gnupipe " + string + "\" -wimpslot 32k -quit");    
  1327.         else
  1328.         if (!exist (p.[start])) { pobj_Create (start); }
  1329.         system ("taskwindow \"gnupipe set xtics\" -wimpslot 32k -quit");
  1330.     }
  1331.     else
  1332.     if (!exist (N)) { N = 0; }
  1333.     if (!exist (p.[N])) { pobj_Create (N); }
  1334.         system ("taskwindow \"gnupipe set ytics " + start + "," + incr + "," + end + "\" -wimpslot 32k -quit");    
  1335.     }
  1336. };
  1337.  
  1338. noytics = function ( N )
  1339. {
  1340.     if (!exist (N)) { N = 0; }
  1341.     if (!exist (p.[N])) { pobj_Create (N); }
  1342.     system ("taskwindow \"gnupipe set noytics\" -wimpslot 32k -quit");  
  1343. };
  1344.  
  1345. ztics = function ( start, end, incr, N )
  1346. {
  1347.     local ( string, i )
  1348.     if (!exist (start)) { start = 0; }
  1349.     if (!exist (incr)) {
  1350.     if (length(start) > 1) {
  1351.         if (!exist (end)) { end = 0; }
  1352.         if (!exist (p.[end])) { pobj_Create (end); }
  1353.         string = "set ztics (" + num2str(start[1])[1];
  1354.         for (i in 2:length(start)) {
  1355.         string = string + "," + num2str(start[i])[1];
  1356.         }
  1357.         string = string + ")\n";
  1358.             system ("taskwindow \"gnupipe " + string + "\" -wimpslot 32k -quit");    
  1359.         else
  1360.         if (!exist (p.[start])) { pobj_Create (start); }
  1361.         system ("taskwindow \"gnupipe set ztics\" -wimpslot 32k -quit");
  1362.     }
  1363.     else
  1364.     if (!exist (N)) { N = 0; }
  1365.     if (!exist (p.[N])) { pobj_Create (N); }
  1366.         system ("taskwindow \"gnupipe set ytics " + start + "," + incr + "," + end + "\" -wimpslot 32k -quit");    
  1367.     }
  1368. };
  1369.  
  1370. noztics = function ( N )
  1371. {
  1372.     if (!exist (N)) { N = 0; }
  1373.     if (!exist (p.[N])) { pobj_Create (N); }
  1374.     system ("taskwindow \"gnupipe set noztics\" -wimpslot 32k -quit");  
  1375. };
  1376.  
  1377. loglog = function ( N )
  1378. {
  1379.     if (!exist (N)) { N = 0; }
  1380.     if (!exist (p.[N])) { pobj_Create (N); }
  1381.     system ("taskwindow \"gnupipe set nologscale\" -wimpslot 32k -quit");  
  1382.     system ("taskwindow \"gnupipe set logscale xy\" -wimpslot 32k -quit");  
  1383. };
  1384.  
  1385. semilogx = function ( N )
  1386. {
  1387.     if (!exist (N)) { N = 0; }
  1388.     if (!exist (p.[N])) { pobj_Create (N); }
  1389.     system ("taskwindow \"gnupipe set logscale x\" -wimpslot 32k -quit");  
  1390. };
  1391.  
  1392. semilogy = function ( N )
  1393. {
  1394.     if (!exist (N)) { N = 0; }
  1395.     if (!exist (p.[N])) { pobj_Create (N); }
  1396.     system ("taskwindow \"gnupipe set logscale y\" -wimpslot 32k -quit");  
  1397. };
  1398.  
  1399. nolog = function ( N )
  1400. {
  1401.     if (!exist (N)) { N = 0; }
  1402.     if (!exist (p.[N])) { pobj_Create (N); }
  1403.     system ("taskwindow \"gnupipe set nologscale\" -wimpslot 32k -quit");  
  1404. };
  1405.  
  1406. autoscale = function ( axis, N )
  1407. {
  1408.     local( flag )
  1409.     flag = 0;
  1410.     if (!exist (axis) && !exist (N)) {
  1411.     N = 0;
  1412.     axis = "xy";
  1413.     }
  1414.     if (exist (axis) && !exist (N)) {
  1415.     if (class (axis) == "num") {
  1416.         N = axis;
  1417.         axis = "xy";
  1418.         flag = 1;
  1419.     }
  1420.     }
  1421.     if (!exist (p.[N])) { pobj_Create (N); }
  1422.     if (class(axis) != "string") {
  1423.     error ("Must be of class string");
  1424.     }
  1425.     system ("taskwindow \"gnupipe set autoscale " + axis + "\" -wimpslot 32k -quit");  
  1426.     if (flag == 1) { axis = N; }
  1427. };
  1428.  
  1429. xlabel = function ( string, N )
  1430. {
  1431.     if (!exist (N)) { N = 0; }
  1432.     if (!exist (p.[N])) { pobj_Create (N); }
  1433.     system ("taskwindow \"gnupipe set xlabel '" + string + "'\" -wimpslot 32k -quit");  
  1434. };
  1435.  
  1436. ylabel = function ( string, N )
  1437. {
  1438.     if (!exist (N)) { N = 0; }
  1439.     if (!exist (p.[N])) { pobj_Create (N); }
  1440.     system ("taskwindow \"gnupipe set ylabel '" + string + "'\" -wimpslot 32k -quit");  
  1441. };
  1442.  
  1443. zlabel = function ( string, N )
  1444. {
  1445.     if (!exist (N)) { N = 0; }
  1446.     if (!exist (p.[N])) { pobj_Create (N); }
  1447.     system ("taskwindow \"gnupipe set zlabel '" + string + "'\" -wimpslot 32k -quit");  
  1448. };
  1449.  
  1450. title = function ( string, N )
  1451. {
  1452.     if (!exist (N)) { N = 0; }
  1453.     if (!exist (p.[N])) { pobj_Create (N); }
  1454.     system ("taskwindow \"gnupipe set title '" + string + "'\" -wimpslot 32k -quit");  
  1455. };
  1456.  
  1457. notitle = function ( N )
  1458. {
  1459.     if (!exist (N)) { N = 0; }
  1460.     if (!exist (p.[N])) { pobj_Create (N); }
  1461.     system ("taskwindow \"gnupipe set notitle\" -wimpslot 32k -quit");  
  1462. };
  1463.  
  1464. linestyle = function ( string, N )
  1465. {
  1466.     if (!exist (N)) { N = 0; }
  1467.     if (!exist (p.[N])) { pobj_Create (N); }
  1468.     system ("taskwindow \"gnupipe set data style " + string + "\" -wimpslot 32k -quit");  
  1469. };
  1470.  
  1471. pformat = function ( string1, string2, N )
  1472. {
  1473.     local( flag1);
  1474.     flag1 = 0;
  1475.     if (!exist(string2)) {
  1476.     string2 = "xy";
  1477.     }
  1478.     if (exist (string2) && !exist (N)) {
  1479.     if (class (string2) == "num") {
  1480.         N = string2;
  1481.         string2 = "xy";
  1482.         flag1 = 1;
  1483.     }
  1484.     }
  1485.     if (!exist (N)) { N = 0; }
  1486.     if (!exist (p.[N])) { pobj_Create (N); }
  1487.     system ("taskwindow \"gnupipe set format " + string2 + "'" + string1 + "'" + "\" -wimpslot 32k -quit");  
  1488.     if (flag1 == 1) {
  1489.     string1 = string2;
  1490.     string2 = N;
  1491.     }
  1492. };
  1493.  
  1494.  
  1495. key = function ( x, y, z, N )
  1496. {
  1497.     local ( flag1 )
  1498.     flag1 = 0;
  1499.     if (exist(x) && !exist(y)) {
  1500.     N = x;
  1501.     flag1 = 1;
  1502.     }
  1503.     if (!exist (z)) { z = 0; }
  1504.     if (!exist (N)) { N = 0; }
  1505.     if (!exist (p.[N])) { pobj_Create (N); }
  1506.     if (exist(y)) {
  1507.         system ("taskwindow \"gnupipe set key " + x + "," + y + "," + z + "\" -wimpslot 32k -quit");  
  1508.     else
  1509.         system ("taskwindow \"gnupipe set key \" -wimpslot 32k -quit");  
  1510.     }
  1511.     if (flag1 == 1) {
  1512.     x = N;
  1513.     }
  1514. };
  1515.  
  1516. nokey = function ( N )
  1517. {
  1518.     if (!exist (N)) { N = 0; }
  1519.     if (!exist (p.[N])) { pobj_Create (N); }
  1520.     system ("taskwindow \"gnupipe set nokey\" -wimpslot 32k -quit");  
  1521. };
  1522.  
  1523. grid = function ( N )
  1524. {
  1525.     if (!exist (N)) { N = 0; }
  1526.     if (!exist (p.[N])) { pobj_Create (N); }
  1527.     system ("taskwindow \"gnupipe set grid\" -wimpslot 32k -quit");  
  1528. };
  1529.  
  1530. nogrid = function ( N )
  1531. {
  1532.     if (!exist (N)) { N = 0; }
  1533.     if (!exist (p.[N])) { pobj_Create (N); }
  1534.     system ("taskwindow \"gnupipe set nogrid\" -wimpslot 32k -quit");  
  1535. };
  1536.  
  1537. axis = function ( N )
  1538. {
  1539.     if (!exist (N)) { N = 0; }
  1540.     if (!exist (p.[N])) { pobj_Create (N); }
  1541.     system ("taskwindow \"gnupipe set xzeroaxis\" -wimpslot 32k -quit");  
  1542.     system ("taskwindow \"gnupipe set yzeroaxis\" -wimpslot 32k -quit");  
  1543. };
  1544.  
  1545. noaxis = function ( N )
  1546. {
  1547.     if (!exist (N)) { N = 0; }
  1548.     if (!exist (p.[N])) { pobj_Create (N); }
  1549.     system ("taskwindow \"gnupipe set noxzeroaxis\" -wimpslot 32k -quit");  
  1550.     system ("taskwindow \"gnupipe set noyzeroaxis\" -wimpslot 32k -quit");  
  1551. };
  1552.  
  1553. label = function ( label, x, y, z, labelnr, N )
  1554. {
  1555.     if (!exist (N)) { N = 0; }
  1556.     if (!exist (p.[N])) { pobj_Create (N); }
  1557.     if (class(label) != "string") {
  1558.     error ("The label must be a string!")
  1559.     }
  1560.     if (exist (labelnr)) {
  1561.     system ("taskwindow \"gnupipe set label " + label + "'" + labelnr + "' at " + x + y + z + "\" -wimpslot 32k -quit");
  1562.     else
  1563.     system ("taskwindow \"gnupipe set label '" + label + "' at " + x + y + z + "\" -wimpslot 32k -quit");
  1564.     }
  1565. };
  1566.  
  1567. nolabel = function ( labelnr, N )
  1568. {
  1569.     if (!exist (N)) { N = 0; }
  1570.     if (!exist (p.[N])) { pobj_Create (N); }
  1571.     if (exist (labelnr)) {
  1572.     system ("taskwindow \"gnupipe set nolabel " + labelnr + "\" -wimpslot 32k -quit");
  1573.     else
  1574.     system ("taskwindow \"gnupipe set nolabel\" -wimpslot 32k -quit");
  1575.     }
  1576. };
  1577.  
  1578. time = function ( N )
  1579. {
  1580.     if (!exist (N)) { N = 0; }
  1581.     if (!exist (p.[N])) { pobj_Create (N); }
  1582.     system ("taskwindow \"gnupipe set time\" -wimpslot 32k -quit");
  1583. };
  1584.  
  1585. notime = function ( N )
  1586. {
  1587.     if (!exist (N)) { N = 0; }
  1588.     if (!exist (p.[N])) { pobj_Create (N); }
  1589.     system ("taskwindow \"gnupipe set notime\" -wimpslot 32k -quit");
  1590. };
  1591.  
  1592.  
  1593. //====================
  1594. // Static Functions    =
  1595. //====================
  1596.  
  1597. plotl = function ( data, N, titles )
  1598. {
  1599.     local (I, i);
  1600.     I = 1;
  1601.     for (i in members (data)) {
  1602.     if (class (data.[i]) == "num") {
  1603.         // Check for plotting titles
  1604.         pobj_PlotKeyTitle (titles, I, title );
  1605.  
  1606.         plotm (data.[i], N, I, title);
  1607.         I++;
  1608.     }
  1609.     }
  1610. };
  1611.  
  1612.  
  1613.  
  1614. //
  1615. // Set-Up to plot a matrix. Columns 2...N against 1st column.
  1616. //
  1617.  
  1618. plotm = function ( data, N, I, titles )
  1619. {
  1620.     local (ans, fn, i, nplot, title);
  1621.     global( _RePlotParameter );
  1622.     
  1623.     flag1 = 0;
  1624.     // Determine how many lines to draw
  1625.     nplot = max ([1, data.nc - 1]);
  1626.  
  1627.     if (nplot > data.nr) {
  1628.     printf (" Plot %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  1629.     ans = getline ("stdin");
  1630.     if (ans.[1] != "y" && ans.[1] != "t") {
  1631.         return 0;
  1632.     }
  1633.     if (ans.[1] == "t") {
  1634.         data = data';
  1635.         nplot = max ([1, data.nc - 1]);
  1636.         flag1 = 1;
  1637.     }
  1638.     }
  1639.  
  1640.     // Generate two column matrices for plot program
  1641.     _RePlotParameter[N+1] = 0;
  1642.     for (i in 1:nplot) {
  1643.     // Create tmp-file-name
  1644.     fn = pobj_TmpFileName (N, i, I);
  1645.  
  1646.     // Check for plotting titles
  1647.     pobj_PlotKeyTitle (titles, i, title );
  1648.  
  1649.     // Write data to tmp-file
  1650.     // Add to plot command
  1651.     if (nplot == 1) {
  1652.         pobj_WriteData (real (data), fn);
  1653.         pobj_PlotCmd (N, fn, title);
  1654.         else
  1655.         pobj_WriteData (real (data[;1,i+1]), fn);
  1656.         pobj_PlotCmd (N, fn, title);
  1657.     }
  1658.     }
  1659.     
  1660.     // Check flag1
  1661.     if (flag1 == 1) {
  1662.     data = data';
  1663.     }
  1664.  
  1665. };
  1666.  
  1667. replotm = function ( data, N, I, titles )
  1668. {
  1669.     local ( ans, fn, i, nplot, title );
  1670.     global( _RePlotParameter );
  1671.     
  1672.     flag1 = 0;
  1673.     // Determine how many lines to draw
  1674.     nplot = max ([1, data.nc - 1]);
  1675.  
  1676.     if (nplot > data.nr) {
  1677.     printf (" Plot %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  1678.     ans = getline ("stdin");
  1679.     if (ans.[1] != "y" && ans.[1] != "t") {
  1680.         return 0;
  1681.     }
  1682.     if (ans.[1] == "t") {
  1683.         data = data';
  1684.         nplot = max ([1, data.nc - 1]);
  1685.         flag1 = 1;
  1686.     }
  1687.     }
  1688.  
  1689.     // Generate two column matrices for plot program
  1690.     for (i in 1+_RePlotParameter[N+1]:nplot+_RePlotParameter[N+1]) {
  1691.     // Create tmp-file-name
  1692.     fn = pobj_TmpFileName (N, i, I);
  1693.  
  1694.     // Check for plotting titles
  1695.     pobj_PlotKeyTitle (titles, i, title );
  1696.  
  1697.     // Write data to tmp-file
  1698.     // Add to plot command
  1699.     if (nplot == 1) {
  1700.         pobj_WriteData (real (data), fn);
  1701.         pobj_RePlotCmd (N, fn, title);
  1702.         else
  1703.         pobj_WriteData (real (data[;1,i+1]), fn);
  1704.         pobj_RePlotCmd (N, fn, title);
  1705.     }
  1706.     }
  1707.     
  1708.     // Check flag1
  1709.     if (flag1 == 1) {
  1710.     data = data';
  1711.     }
  1712.  
  1713. };
  1714.  
  1715.  
  1716. //
  1717. // Set-Up to splot a matrix. 
  1718. //
  1719.  
  1720. splotm = function ( datax, datay, datazz, N, I, titles )
  1721. {
  1722.     local ( ans, fn, i, nsplot, m, n, title );
  1723.     global( _RePlotParameter );
  1724.     // Determine how many plots to draw
  1725.     nsplot=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  1726.  
  1727.     // Generate three column matrices for splot program
  1728.     _RePlotParameter[N+1] = 0;
  1729.     // Write data to new data-file
  1730.     // Create tmp-file-name
  1731.     for (i in 1:nsplot) {
  1732.     fn = pobj_TmpFileName (N, i, I);
  1733.  
  1734.     // Check for plotting titles
  1735.     pobj_PlotKeyTitle (titles, I, title );
  1736.     newdata=[];
  1737.     for (m in 1:datax.nr){
  1738.         rownumber=0;
  1739.         for (n in 1:datay.nr){
  1740.         rownumber=rownumber+1;
  1741.         // x-value
  1742.         newdata[rownumber;1]=datax[m];
  1743.         // y-value
  1744.         newdata[rownumber;2]=datay[n];
  1745.         // z-value
  1746.         newdata[rownumber;3]=datazz[m;n+(i-1)*datax.nr];
  1747.         }
  1748.         write (fn,real (newdata[;1,2,3]));
  1749.         write (fn,"");
  1750.     }
  1751.     close (fn);
  1752.     // Add to splot command
  1753.     pobj_SPlotCmd (N, fn, title);
  1754.     }
  1755. };
  1756.  
  1757.  
  1758.  
  1759. //
  1760. // Set-Up to splot a matrix. 
  1761. //
  1762.  
  1763.  
  1764.  
  1765.  
  1766. //
  1767. // Form a plain string to send to GNUPLOT as 
  1768. // command
  1769. //
  1770.  
  1771. plots = function ( data, N )
  1772. {
  1773.     // Send the string to GNUPLOT
  1774.  
  1775.     p.[N].pcmd = data + "\n";
  1776. };
  1777.  
  1778.  
  1779.  
  1780. //
  1781. // Create a plot-object.
  1782. //
  1783.  
  1784. pobj_Create = function ( N )
  1785. {
  1786.     local (plist, string);
  1787.  
  1788.     // The tmp files to plot
  1789.     plist.files = "";
  1790.     // Where the plot command will go
  1791.     plist.pcmd = "";
  1792.  
  1793.     // Init string for plotting program
  1794.     plist.init = "set nogrid\nset data style lines\nset nokey\nset noxzeroaxis\nset noyzeroaxis\n";
  1795.  
  1796.     // The program that draws the plot(s)
  1797. //    sprintf (plist.prog, "|gnuplot #%i", N);
  1798. //RISC OS debugging purposes
  1799.     sprintf (plist.prog, "gnupl_cmd ", N);
  1800.  
  1801.     // To remove tmp-files
  1802.  
  1803. //    sprintf (plist.rmf, "appocmd |rm -f `cat` #%i", N);
  1804. //RISC OS debugging purposes - anyone wants to fix this?
  1805.     sprintf (plist.rmf, "wipe rtmpf%i ~C", N); 
  1806. //    sprintf (stdout, "|rm -f `cat` #%i", N);
  1807.  
  1808.    // Keep track of terminal type, and output
  1809. //    plist.term = "X11";
  1810.      plist.term = "arcdraw col";
  1811.      plist.output = "stdout";
  1812.  
  1813.     // Copy the local list into the static plot-object collection
  1814.     p.[N] = plist;
  1815.     system ("taskwindow \"gnupipe set nogrid\" -wimpslot 32k -quit");  
  1816.     system ("taskwindow \"gnupipe set data style line\" -wimpslot 32k -quit");  
  1817.     system ("taskwindow \"gnupipe set nokey \" -wimpslot 32k -quit");  
  1818.     system ("taskwindow \"gnupipe set noxzeroaxis\" -wimpslot 32k -quit");  
  1819.     system ("taskwindow \"gnupipe set noyzeroaxis\" -wimpslot 32k -quit");  
  1820.     system ("taskwindow" + "\"gnupipe set term " + p.[N].term + "\"" + " -wimpslot 32k -quit");
  1821. };
  1822.  
  1823.  
  1824.  
  1825. //
  1826. // Reset a plot object to plot new data
  1827. //
  1828.  
  1829. pobj_Reset = function ( N )
  1830. {
  1831.  
  1832.     // Close any existing tmp-files that belong
  1833.     // to plot-object N. Reset the file-name list.
  1834.     p.[N].files = "";
  1835.     p.[N].pcmd = "";
  1836. };
  1837.  
  1838.  
  1839.  
  1840. //
  1841. // Destroy a plot-object
  1842. //
  1843.  
  1844. pobj_Destroy = function ( N )
  1845. {
  1846.     if (exist (p.[N])) {
  1847.     clear (p.[N]);    
  1848.     }
  1849. };
  1850.  
  1851.  
  1852.  
  1853. //
  1854. // Create a tmp-file name
  1855. //
  1856.  
  1857. pobj_TmpFileName = function ( N, i, j )
  1858. {
  1859.     local (tmp);
  1860.     sprintf (tmp, "rtmpf%i%i%i", N, i, j);
  1861.     p.[N].files = p.[N].files + " " + tmp;
  1862.     return tmp;
  1863. };
  1864.  
  1865.  
  1866.  
  1867. //
  1868. // Add data-file (tmp-file) to plot object list of stuff
  1869. // to be plotted.
  1870. //
  1871.  
  1872. pobj_WriteData = function ( m, file )
  1873. {
  1874.     write (file, m);
  1875.     close (file);
  1876. };
  1877.  
  1878.  
  1879.  
  1880. //
  1881. // Create the command(s) to plot all the data in the plot object.
  1882. //
  1883.  
  1884. pobj_PlotCmd = function ( N, fn, title )
  1885. {
  1886.     local (tmp);
  1887.  
  1888.     if(p.[N].pcmd == "") {
  1889.     sprintf(tmp, "plot '%s' title '%s'", fn, title);
  1890.     else
  1891.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1892.     }
  1893.  
  1894.     p.[N].pcmd = p.[N].pcmd + tmp;
  1895. };
  1896.  
  1897.  
  1898.  
  1899. //
  1900. // Create the command(s) to replot all the data in the plot object.
  1901. //
  1902.  
  1903. pobj_RePlotCmd = function ( N, fn, title )
  1904. {
  1905.     local (tmp);
  1906.  
  1907.     if(p.[N].pcmd == "") {
  1908.     sprintf(tmp, "replot '%s' title '%s'", fn, title);
  1909.     else
  1910.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1911.     }
  1912.  
  1913.     p.[N].pcmd = p.[N].pcmd + tmp;
  1914. };
  1915.  
  1916.  
  1917. //
  1918. // Create the command(s) to splot all the data in the splot object.
  1919. //
  1920.  
  1921. pobj_SPlotCmd = function ( N, fn, title )
  1922. {
  1923.     local (tmp);
  1924.  
  1925.     if(p.[N].pcmd == "") {
  1926.     sprintf(tmp, "splot '%s' title '%s'", fn, title);
  1927.     else
  1928.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1929.     }
  1930.  
  1931.     p.[N].pcmd = p.[N].pcmd + tmp;
  1932. };
  1933.  
  1934.  
  1935.  
  1936. //
  1937. // Check for plotting titles
  1938. //
  1939.  
  1940. pobj_PlotKeyTitle = function (titles, i, title )
  1941. {
  1942.     if (!exist (titles)) {
  1943.     sprintf (title, "%.4g", i+1);
  1944.     title = "C-" + title;
  1945.     else
  1946.     if (i > length(titles)) {
  1947.         sprintf (title, "%.4g", i+1);
  1948.         title = "C-" + title;
  1949.         else
  1950.         title = titles[i];
  1951.     }
  1952.     }
  1953. };
  1954.  
  1955.  
  1956.  
  1957. //
  1958. // Force the plot program to create the plot
  1959. //
  1960.  
  1961. pobj_Plot = function ( N )
  1962. {
  1963.     //    fprintf ("stdout", "%s\n", p.[N].pcmd);
  1964.     system ("taskwindow" + "\"gnupipe " + p.[N].pcmd + "\" -wimpslot 32k -quit");
  1965.     
  1966. };
  1967.  
  1968.  
  1969.  
  1970. //
  1971. // Setup so the tmp-files can be removed
  1972. //
  1973.  
  1974. pobj_SetRm = function ( N )
  1975. {
  1976.     fprintf(p.[N].rmf, "%s", p.[N].files);
  1977.     system(p.[N].rmf);
  1978. };
  1979.  
  1980.  
  1981.  
  1982. //
  1983. // Remove the tmp-files
  1984. //
  1985.  
  1986. pobj_Rm = function ( N )
  1987. {
  1988.     if (length (p.[N].files) != 0) {
  1989.     close (p.[N].rmf);
  1990.     }
  1991. };
  1992.  
  1993.  
  1994.  
  1995. //
  1996. // Provide access to the plot-list
  1997. //
  1998.  
  1999. _pobj_list = function ( N )
  2000. {
  2001.     if (!exist (N)) { N = 0; }
  2002.     return p.[N];
  2003. };
  2004.  
  2005.