home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / plot / subplot.m < prev    next >
Text File  |  1999-12-24  |  5KB  |  174 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} subplot (@var{rows}, @var{cols}, @var{index})
  22. ## @deftypefnx {Function File} {} subplot (@var{rcn})
  23. ## Sets @code{gnuplot} in multiplt mode and plots in location
  24. ## given by index (there are @var{cols} by @var{rows} subwindws).
  25. ## 
  26. ## Input:
  27. ## 
  28. ## @table @var
  29. ## @item rows
  30. ## Number of rows in subplot grid.
  31. ## 
  32. ## @item columns
  33. ## Number of columns in subplot grid.
  34. ## 
  35. ## @item index
  36. ## Index of subplot where to make the next plot.
  37. ## @end table
  38. ## 
  39. ## If only one argument is supplied, then it must be a three digit value
  40. ## specifying the location in digits 1 (rows) and 2 (columns) and the plot
  41. ## index in digit 3.
  42. ## 
  43. ## The plot index runs row-wise.  First all the columns in a row are filled
  44. ## and then the next row is filled.
  45. ## 
  46. ## For example, a plot with 4 by 2 grid will have plot indices running as
  47. ## follows:
  48. ## @iftex
  49. ## @tex
  50. ## \vskip 10pt
  51. ## \hfil\vbox{\offinterlineskip\hrule
  52. ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr
  53. ## height13pt&1&2&3&4\cr height12pt&&&&\cr\noalign{\hrule}
  54. ## height13pt&5&6&7&8\cr height12pt&&&&\cr\noalign{\hrule}}}
  55. ## \hfil
  56. ## \vskip 10pt
  57. ## @end tex
  58. ## @end iftex
  59. ## @ifinfo
  60. ## @display
  61. ## @group
  62. ## +-----+-----+-----+-----+
  63. ## |  1  |  2  |  3  |  4  |
  64. ## +-----+-----+-----+-----+
  65. ## |  5  |  6  |  7  |  8  |
  66. ## +-----+-----+-----+-----+
  67. ## @end group
  68. ## @end display
  69. ## @end ifinfo
  70. ## @end deftypefn
  71.  
  72. ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
  73. ## Adapted-By: jwe
  74.  
  75. function subplot (rows, columns, index)
  76.  
  77.   if (! gnuplot_has_multiplt)
  78.     error ("subplot: gnuplot does not appear to support this feature");
  79.   endif
  80.  
  81.   ## global variables to keep track of multiplt options
  82.  
  83.   global __multiplt_mode__ = 0;
  84.   global __multiplt_xsize__;
  85.   global __multiplt_ysize__;
  86.   global __multiplt_xn__;
  87.   global __multiplt_yn__;
  88.   global __multiplt_xi__;
  89.   global __multiplt_yi__;
  90.  
  91.   if (nargin != 3 && nargin != 1)
  92.     usage ("subplot (rows, columns, index) or subplot (rcn)");
  93.   endif
  94.  
  95.   if (nargin == 1)
  96.  
  97.     if (! (is_scal (rows) && rows >= 0))
  98.       error ("subplot: input rcn has to be a positive scalar");
  99.     endif
  100.  
  101.     tmp = rows;
  102.     index = rem (tmp, 10);
  103.     tmp = (tmp - index) / 10;
  104.     columns = rem (tmp, 10);
  105.     tmp = (tmp - columns) / 10;
  106.     rows = rem (tmp, 10);
  107.  
  108.   elseif (! (is_scal (columns) && is_scal (rows) && is_scal (index)))
  109.     error ("subplot: columns, rows, and index have to be scalars");
  110.   endif
  111.  
  112.   columns = round (columns);
  113.   rows = round (rows);
  114.   index = round (index);
  115.  
  116.   if (index > columns*rows)
  117.     error ("subplot: index must be less than columns*rows");
  118.   endif
  119.  
  120.   if (columns < 1 || rows < 1 || index < 1)
  121.     error ("subplot: columns,rows,index must be be positive");
  122.   endif
  123.  
  124.   if (columns*rows == 1)
  125.  
  126.     ## switching to single plot ?
  127.  
  128.     oneplot ();
  129.  
  130.     ## XXX FIXME XXX -- do we really need to reset these here?
  131.  
  132.     __multiplt_xn__ = 1;
  133.     __multiplt_yn__ = 1;
  134.  
  135.   else
  136.  
  137.     ## doing multiplt plots
  138.  
  139.     if (! __multiplt_mode__
  140.      || __multiplt_xn__ != columns
  141.     || __multiplt_yn__ != rows)
  142.  
  143.       __multiplt_mode__ = 1;
  144.       __multiplt_xn__ = columns;
  145.       __multiplt_yn__ = rows;
  146.       __multiplt_xsize__ = 1.0 ./ columns;
  147.       __multiplt_ysize__ = 1.0 ./ rows;
  148.  
  149.       gnuplot_command_replot = "cle;rep";
  150.  
  151.       gset multiplt;
  152.  
  153.       eval (sprintf ("gset size %g, %g", __multiplt_xsize__,
  154.              __multiplt_ysize__));
  155.     endif
  156.  
  157.     ## get the sub plot location
  158.  
  159.     yp = fix ((index-1)/columns);
  160.     xp = index - yp*columns - 1;
  161.     __multiplt_xi__ = ++xp;
  162.     __multiplt_yi__ = ++yp;
  163.  
  164.     ## set the origin
  165.  
  166.     xo = (xp - 1.0) * __multiplt_xsize__;
  167.     yo = (rows - yp) * __multiplt_ysize__;
  168.  
  169.     eval (sprintf ("gset origin %g, %g", xo, yo));
  170.  
  171.   endif
  172.  
  173. endfunction
  174.