~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to plugins/octave/octave/plot/contour.m

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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} {} contour (@var{z}, @var{n})
 
22
## @deftypefnx {Function File} {} contour (@var{x}, @var{y}, @var{z}, @var{n})
 
23
## Make a contour plot of the three-dimensional surface described by
 
24
## @var{z}.  Someone needs to improve @code{gnuplot}'s contour routines
 
25
## before this will be very useful.
 
26
## @end deftypefn
 
27
## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour,
 
28
## bar, stairs, gplot, gsplot, replot, xlabel, ylabel, and title}
 
29
 
 
30
## Author: jwe
 
31
 
 
32
## Modified Jan. 2003 -- Added TeXmacs interface support
 
33
## Author: Michael Graffam <mgraffam@mathlab.sunysb.edu>
 
34
 
 
35
function contour (x, y, z, n)
 
36
 
 
37
  ## XXX FIXME XXX -- these plot states should really just be set
 
38
  ## temporarily, probably inside an unwind_protect block, but there is
 
39
  ## no way to determine their current values.
 
40
 
 
41
      if (length(getenv("TEXMACS_PATH"))>0)
 
42
        gset output '/tmp/tmplot.eps';
 
43
      endif
 
44
 
 
45
  if (nargin == 1 || nargin == 2)
 
46
    z = x;
 
47
    if (nargin == 1) 
 
48
      n = 10;
 
49
    else
 
50
      n = y; 
 
51
    endif
 
52
    if (is_matrix (z))
 
53
      gset nosurface;
 
54
      gset contour;
 
55
      gset cntrparam bspline;
 
56
      if (is_scalar (n))
 
57
        command = sprintf ("gset cntrparam levels %d", n);
 
58
      elseif (is_vector (n))
 
59
        tmp = sprintf ("%f", n(1));
 
60
        for i = 2:length (n)
 
61
          tmp = sprintf ("%s, %f", tmp, n(i));
 
62
        endfor
 
63
        command = sprintf ("gset cntrparam levels discrete %s", tmp);
 
64
      endif
 
65
      eval (command);
 
66
      gset noparametric;
 
67
      gset view 0, 0, 1, 1;
 
68
      gsplot z w l 1;
 
69
          if (length(getenv("TEXMACS_PATH"))>0)
 
70
                 P=[2;112;115;58]; #P= "\002ps:"
 
71
                g=fopen("/tmp/tmplot.eps");
 
72
                while (g==-1)
 
73
                        sleep(1);
 
74
                        g=fopen("/tmp/tmplot.eps");
 
75
                endwhile
 
76
                while (!feof(g))
 
77
                        f=fread(g,2048);
 
78
                        if (length(f))
 
79
                                P=[P;f];
 
80
                        endif
 
81
                endwhile
 
82
                fclose(g);
 
83
                P=[P;5];
 
84
                disp(sprintf("%cverbatim:\n",2));
 
85
                disp(setstr(P'));
 
86
                system("rm /tmp/tmplot.eps");
 
87
        endif
 
88
 
 
89
    else
 
90
      error ("contour: argument must be a matrix");
 
91
    endif
 
92
  elseif (nargin == 4)
 
93
    if (is_vector (x) && is_vector (y) && is_matrix (z))
 
94
      xlen = length (x);
 
95
      ylen = length (y);
 
96
      if (xlen == rows (z) && ylen == columns (z))
 
97
        if (rows (x) == 1)
 
98
          x = x';
 
99
        endif
 
100
        len = 3 * ylen;
 
101
        zz = zeros (xlen, len);
 
102
        k = 1;
 
103
        for i = 1:3:len
 
104
          zz(:,i)   = x;
 
105
          zz(:,i+1) = y(k) * ones (xlen, 1);
 
106
          zz(:,i+2) = z(:,k);
 
107
          k++;
 
108
        endfor
 
109
        gset nosurface;
 
110
        gset contour;
 
111
        gset cntrparam bspline;
 
112
        if (is_scalar (n))
 
113
          command = sprintf ("gset cntrparam levels %d", n);
 
114
        elseif (is_vector (n))
 
115
          tmp = sprintf ("%f", n(1));
 
116
          for i = 2:length (n)
 
117
            tmp = sprintf ("%s, %f", tmp, n(i));
 
118
          endfor
 
119
          command = sprintf ("gset cntrparam levels discrete %s", tmp);
 
120
        endif
 
121
        eval (command);
 
122
        gset parametric;
 
123
        gset view 0, 0, 1, 1;
 
124
        gsplot zz w l 1;
 
125
          if (length(getenv("TEXMACS_PATH"))>0)
 
126
                 P=[2;112;115;58]; #P= "\002ps:"
 
127
                g=fopen("/tmp/tmplot.eps");
 
128
                while (g==-1)
 
129
                        sleep(1);
 
130
                        g=fopen("/tmp/tmplot.eps");
 
131
                endwhile
 
132
                while (!feof(g))
 
133
                        f=fread(g,2048);
 
134
                        if (length(f))
 
135
                                P=[P;f];
 
136
                        endif
 
137
                endwhile
 
138
                fclose(g);
 
139
                P=[P;5];
 
140
                disp(sprintf("%cverbatim:\n",2));
 
141
                disp(setstr(P'));
 
142
                system("rm /tmp/tmplot.eps");
 
143
        endif
 
144
 
 
145
      else
 
146
        msg = "contour: rows (z) must be the same as length (x) and";
 
147
        msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg);
 
148
        error (msg);
 
149
      endif
 
150
    else
 
151
      error ("contour: x and y must be vectors and z must be a matrix");
 
152
    endif
 
153
  else
 
154
    usage ("contour (z, levels, x, y)");
 
155
  endif
 
156
 
 
157
endfunction