Back to index

texmacs  1.0.7.15
contour.m
Go to the documentation of this file.
00001 ## Copyright (C) 1996, 1997 John W. Eaton
00002 ##
00003 ## This file is part of Octave.
00004 ##
00005 ## Octave is free software; you can redistribute it and/or modify it
00006 ## under the terms of the GNU General Public License as published by
00007 ## the Free Software Foundation; either version 2, or (at your option)
00008 ## any later version.
00009 ##
00010 ## Octave is distributed in the hope that it will be useful, but
00011 ## WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 ## General Public License for more details.
00014 ##
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with Octave; see the file COPYING.  If not, write to the Free
00017 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
00018 ## 02111-1307, USA.
00019 
00020 ## -*- texinfo -*-
00021 ## @deftypefn {Function File} {} contour (@var{z}, @var{n})
00022 ## @deftypefnx {Function File} {} contour (@var{x}, @var{y}, @var{z}, @var{n})
00023 ## Make a contour plot of the three-dimensional surface described by
00024 ## @var{z}.  Someone needs to improve @code{gnuplot}'s contour routines
00025 ## before this will be very useful.
00026 ## @end deftypefn
00027 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour,
00028 ## bar, stairs, gplot, gsplot, replot, xlabel, ylabel, and title}
00029 
00030 ## Author: jwe
00031 
00032 ## Modified Jan. 2003 -- Added TeXmacs interface support
00033 ## Author: Michael Graffam <mgraffam@mathlab.sunysb.edu>
00034 
00035 function contour (x, y, z, n)
00036 
00037   ## XXX FIXME XXX -- these plot states should really just be set
00038   ## temporarily, probably inside an unwind_protect block, but there is
00039   ## no way to determine their current values.
00040 
00041       if (length(getenv("TEXMACS_PATH"))>0)
00042        gset output '/tmp/tmplot.eps';
00043       endif
00044 
00045   if (nargin == 1 || nargin == 2)
00046     z = x;
00047     if (nargin == 1) 
00048       n = 10;
00049     else
00050       n = y; 
00051     endif
00052     if (is_matrix (z))
00053       gset nosurface;
00054       gset contour;
00055       gset cntrparam bspline;
00056       if (is_scalar (n))
00057         command = sprintf ("gset cntrparam levels %d", n);
00058       elseif (is_vector (n))
00059         tmp = sprintf ("%f", n(1));
00060         for i = 2:length (n)
00061           tmp = sprintf ("%s, %f", tmp, n(i));
00062         endfor
00063         command = sprintf ("gset cntrparam levels discrete %s", tmp);
00064       endif
00065       eval (command);
00066       gset noparametric;
00067       gset view 0, 0, 1, 1;
00068       gsplot z w l 1;
00069           if (length(getenv("TEXMACS_PATH"))>0)
00070                  P=[2;112;115;58]; #P= "\002ps:"
00071                 g=fopen("/tmp/tmplot.eps");
00072                 while (g==-1)
00073                         sleep(1);
00074                         g=fopen("/tmp/tmplot.eps");
00075                 endwhile
00076                 while (!feof(g))
00077                         f=fread(g,2048);
00078                         if (length(f))
00079                                 P=[P;f];
00080                         endif
00081                 endwhile
00082                 fclose(g);
00083                 P=[P;5];
00084                 disp(sprintf("%cverbatim:\n",2));
00085                 disp(setstr(P'));
00086                 system("rm /tmp/tmplot.eps");
00087         endif
00088 
00089     else
00090       error ("contour: argument must be a matrix");
00091     endif
00092   elseif (nargin == 4)
00093     if (is_vector (x) && is_vector (y) && is_matrix (z))
00094       xlen = length (x);
00095       ylen = length (y);
00096       if (xlen == rows (z) && ylen == columns (z))
00097         if (rows (x) == 1)
00098           x = x';
00099         endif
00100         len = 3 * ylen;
00101         zz = zeros (xlen, len);
00102         k = 1;
00103         for i = 1:3:len
00104           zz(:,i)   = x;
00105           zz(:,i+1) = y(k) * ones (xlen, 1);
00106           zz(:,i+2) = z(:,k);
00107           k++;
00108         endfor
00109         gset nosurface;
00110         gset contour;
00111         gset cntrparam bspline;
00112         if (is_scalar (n))
00113           command = sprintf ("gset cntrparam levels %d", n);
00114         elseif (is_vector (n))
00115           tmp = sprintf ("%f", n(1));
00116           for i = 2:length (n)
00117             tmp = sprintf ("%s, %f", tmp, n(i));
00118           endfor
00119           command = sprintf ("gset cntrparam levels discrete %s", tmp);
00120         endif
00121         eval (command);
00122         gset parametric;
00123         gset view 0, 0, 1, 1;
00124         gsplot zz w l 1;
00125           if (length(getenv("TEXMACS_PATH"))>0)
00126                  P=[2;112;115;58]; #P= "\002ps:"
00127                 g=fopen("/tmp/tmplot.eps");
00128                 while (g==-1)
00129                         sleep(1);
00130                         g=fopen("/tmp/tmplot.eps");
00131                 endwhile
00132                 while (!feof(g))
00133                         f=fread(g,2048);
00134                         if (length(f))
00135                                 P=[P;f];
00136                         endif
00137                 endwhile
00138                 fclose(g);
00139                 P=[P;5];
00140                 disp(sprintf("%cverbatim:\n",2));
00141                 disp(setstr(P'));
00142                 system("rm /tmp/tmplot.eps");
00143         endif
00144 
00145       else
00146         msg = "contour: rows (z) must be the same as length (x) and";
00147         msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg);
00148         error (msg);
00149       endif
00150     else
00151       error ("contour: x and y must be vectors and z must be a matrix");
00152     endif
00153   else
00154     usage ("contour (z, levels, x, y)");
00155   endif
00156 
00157 endfunction