home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / plot / subplot.m < prev    next >
Text File  |  1999-04-29  |  4KB  |  158 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. ## usage: subplot (rows, columns, index)
  21. ##        subplot (rcn)
  22. ##
  23. ## NOTE: this will work only with gnuplot installed with
  24. ##       multiplt patch (or version 3.6 beta)
  25. ##
  26. ## Sets gnuplot in multiplt mode and plots in location
  27. ## given by index (there are columns X rows subwindws)
  28. ##
  29. ## Input:
  30. ##
  31. ##   rows   : number of rows in subplot grid
  32. ##   columns: number of columns in subplot grid
  33. ##   index  : index of subplot where to make the next plot
  34. ##
  35. ## If only one arg, then it (crn) has to be three digit value
  36. ## specifying the location in digit 1 (rows) and 2 (columns) and digit
  37. ## 3 is the plot index
  38. ##
  39. ## The plot index runs row-wise,i.e., first all the columns in a row
  40. ## are filled and then the next row is filled
  41. ##
  42. ## For example, plot with 4 X 2 grid, will have plot indices running as
  43. ## follows:
  44. ##
  45. ##   -----------------------------------
  46. ##   |        |       |       |        |
  47. ##   |    1   |    2  |    3  |    4   |
  48. ##   |        |       |       |        |
  49. ##   -----------------------------------
  50. ##   |        |       |       |        |
  51. ##   |    5   |    6  |    7  |    8   |
  52. ##   |        |       |       |        |
  53. ##   -----------------------------------
  54. ##
  55.  
  56. ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
  57. ## Adapted-By: jwe
  58.  
  59. function subplot (rows, columns, index)
  60.  
  61.   if (! gnuplot_has_multiplt)
  62.     error ("subplot: gnuplot does not appear to support this feature");
  63.   endif
  64.  
  65.   ## global variables to keep track of multiplt options
  66.  
  67.   global __multiplt_mode__ = 0;
  68.   global __multiplt_xsize__;
  69.   global __multiplt_ysize__;
  70.   global __multiplt_xn__;
  71.   global __multiplt_yn__;
  72.   global __multiplt_xi__;
  73.   global __multiplt_yi__;
  74.  
  75.   if (nargin != 3 && nargin != 1)
  76.     usage ("subplot (rows, columns, index) or subplot (rcn)");
  77.   endif
  78.  
  79.   if (nargin == 1)
  80.  
  81.     if (! (is_scal (rows) && rows >= 0))
  82.       error ("subplot: input rcn has to be a positive scalar");
  83.     endif
  84.  
  85.     tmp = rows;
  86.     index = rem (tmp, 10);
  87.     tmp = (tmp - index) / 10;
  88.     columns = rem (tmp, 10);
  89.     tmp = (tmp - columns) / 10;
  90.     rows = rem (tmp, 10);
  91.  
  92.   elseif (! (is_scal (columns) && is_scal (rows) && is_scal (index)))
  93.     error ("subplot: columns, rows, and index have to be scalars");
  94.   endif
  95.  
  96.   columns = round (columns);
  97.   rows = round (rows);
  98.   index = round (index);
  99.  
  100.   if (index > columns*rows)
  101.     error ("subplot: index must be less than columns*rows");
  102.   endif
  103.  
  104.   if (columns < 1 || rows < 1 || index < 1)
  105.     error ("subplot: columns,rows,index must be be positive");
  106.   endif
  107.  
  108.   if (columns*rows == 1)
  109.  
  110.     ## switching to single plot ?
  111.  
  112.     oneplot ();
  113.  
  114.     ## XXX FIXME XXX -- do we really need to reset these here?
  115.  
  116.     __multiplt_xn__ = 1;
  117.     __multiplt_yn__ = 1;
  118.  
  119.   else
  120.  
  121.     ## doing multiplt plots
  122.  
  123.     if (! __multiplt_mode__
  124.      || __multiplt_xn__ != columns
  125.     || __multiplt_yn__ != rows)
  126.  
  127.       __multiplt_mode__ = 1;
  128.       __multiplt_xn__ = columns;
  129.       __multiplt_yn__ = rows;
  130.       __multiplt_xsize__ = 1.0 ./ columns;
  131.       __multiplt_ysize__ = 1.0 ./ rows;
  132.  
  133.       gnuplot_command_replot = "cle;rep";
  134.  
  135.       gset multiplt;
  136.  
  137.       eval (sprintf ("gset size %g, %g", __multiplt_xsize__,
  138.              __multiplt_ysize__));
  139.     endif
  140.  
  141.     ## get the sub plot location
  142.  
  143.     yp = fix ((index-1)/columns);
  144.     xp = index - yp*columns - 1;
  145.     __multiplt_xi__ = ++xp;
  146.     __multiplt_yi__ = ++yp;
  147.  
  148.     ## set the origin
  149.  
  150.     xo = (xp - 1.0) * __multiplt_xsize__;
  151.     yo = (rows - yp) * __multiplt_ysize__;
  152.  
  153.     eval (sprintf ("gset origin %g, %g", xo, yo));
  154.  
  155.   endif
  156.  
  157. endfunction
  158.