changeset 3803:63c75bc3db82

[project @ 2001-02-28 08:24:40 by jwe]
author jwe
date Wed, 28 Feb 2001 08:24:43 +0000
parents 4f1a26a730fd
children 4073be5aefa1
files ChangeLog configure.in doc/interpreter/arith.txi doc/interpreter/basics.txi doc/interpreter/emacs.txi doc/interpreter/image.txi liboctave/ChangeLog liboctave/lo-cutils.c liboctave/lo-sysdep.cc liboctave/lo-utils.h liboctave/oct-env.cc scripts/ChangeLog scripts/general/cart2pol.m scripts/general/cart2sph.m scripts/general/pol2cart.m scripts/general/sph2cart.m scripts/image/hsv2rgb.m scripts/image/rgb2hsv.m scripts/plot/meshdom.m scripts/plot/meshgrid.m
diffstat 20 files changed, 464 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Feb 26 20:26:15 2001 +0000
+++ b/ChangeLog	Wed Feb 28 08:24:43 2001 +0000
@@ -1,3 +1,9 @@
+2001-02-28  Albert Chin-A-Young  <china@thewrittenword.com>
+
+	* configure.in: Check for getpwnam in libsun only after checking
+	default libraries first.  Check for gethostname in libsocket only
+	after checking default libraries first.	
+
 2001-02-22  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* configure.in: Allow for using f2c when setting functions to look
--- a/configure.in	Mon Feb 26 20:26:15 2001 +0000
+++ b/configure.in	Wed Feb 28 08:24:43 2001 +0000
@@ -21,7 +21,7 @@
 ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 ### 02111-1307, USA. 
 
-AC_REVISION($Revision: 1.340 $)
+AC_REVISION($Revision: 1.341 $)
 AC_PREREQ(2.9)
 AC_INIT(src/octave.cc)
 AC_CONFIG_HEADER(config.h)
@@ -853,8 +853,8 @@
 AC_ISC_POSIX
 AC_MINIX
 AC_AIX
-AC_CHECK_LIB(sun, getpwnam)
-AC_CHECK_LIB(socket, gethostname)
+AC_CHECK_FUNC(getpwnam, , AC_CHECK_LIB(sun, getpwnam))
+AC_CHECK_FUNC(gethostname, , AC_CHECK_LIB(socket, gethostname))
 
 ### How big are ints and how are they oriented?  These could probably
 ### be eliminated in favor of run-time checks.
@@ -953,7 +953,7 @@
 
 AC_CHECK_FUNCS(atexit bcopy bzero dup2 endgrent endpwent execvp \
   fcntl fork getcwd getegid geteuid getgid getgrent getgrgid \
-  getgrnam gethostname getpgrp getpid getppid getpwent getpwnam \
+  getgrnam getpgrp getpid getppid getpwent \
   getpwuid gettimeofday getuid getwd link localtime_r lstat \
   memmove mkdir mkfifo on_exit pipe poll putenv readlink rename \
   rindex rmdir select setgrent setpwent setvbuf sigaction sigpending \
--- a/doc/interpreter/arith.txi	Mon Feb 26 20:26:15 2001 +0000
+++ b/doc/interpreter/arith.txi	Wed Feb 28 08:24:43 2001 +0000
@@ -14,6 +14,7 @@
 * Trigonometry::                
 * Sums and Products::           
 * Special Functions::           
+* Coordinate Transformations::
 * Mathematical Constants::      
 @end menu
 
@@ -157,7 +158,7 @@
 
 @DOCSTRING(sumsq)
 
-@node Special Functions, Mathematical Constants, Sums and Products, Arithmetic
+@node Special Functions, Coordinate Transformations, Sums and Products, Arithmetic
 @section Special Functions
 
 @DOCSTRING(besselj)
@@ -188,7 +189,18 @@
 
 @DOCSTRING(duplication_matrix)
 
-@node Mathematical Constants,  , Special Functions, Arithmetic
+@node Coordinate Transformations, Mathematical Constants, Special Functions, Arithmetic
+@section Coordinate Transformations
+
+@DOCSTRING(cart2pol)
+
+@DOCSTRING(pol2cart)
+
+@DOCSTRING(cart2sph)
+
+@DOCSTRING(sph2cart)
+
+@node Mathematical Constants,  , Coordinate Transformations, Arithmetic
 @section Mathematical Constants
 
 @DOCSTRING(I)
--- a/doc/interpreter/basics.txi	Mon Feb 26 20:26:15 2001 +0000
+++ b/doc/interpreter/basics.txi	Wed Feb 28 08:24:43 2001 +0000
@@ -203,7 +203,7 @@
 @example
 printf ("%s", program_name);
 for i = 1:nargin
-  printf (" %s", argv(i));
+  printf (" %s", nth (argv, i));
 endfor
 printf ("\n");
 @end example
--- a/doc/interpreter/emacs.txi	Mon Feb 26 20:26:15 2001 +0000
+++ b/doc/interpreter/emacs.txi	Wed Feb 28 08:24:43 2001 +0000
@@ -474,9 +474,9 @@
 (it does with XEmacs).  It can be retrieved from any GNU Emacs Lisp Code
 Directory archive, e.g.@:
 @url{ftp://ftp.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive},
-in the @file{packages} subdirectory.  The alpha version of an enhanced
-version of gnuserv is available at 
-@url{ftp://ftp.wellfleet.com/netman/psmith/emacs/gnuserv-2.1alpha.tar.gz}.
+in the @file{packages} subdirectory.  A recent version of gnuserv is
+available from
+@url{http://www.meltin.net/hacks/emacs/src/gnuserv-3.12.2.tar.gz}.
 
 If @file{gnuserv} is installed, add the lines
 @lisp
--- a/doc/interpreter/image.txi	Mon Feb 26 20:26:15 2001 +0000
+++ b/doc/interpreter/image.txi	Wed Feb 28 08:24:43 2001 +0000
@@ -39,6 +39,10 @@
 
 @DOCSTRING(ntsc2rgb)
 
+@DOCSTRING(hsv2rgb)
+
+@DOCSTRING(rgb2hsv)
+
 @DOCSTRING(ocean)
 
 @DOCSTRING(rgb2ind)
--- a/liboctave/ChangeLog	Mon Feb 26 20:26:15 2001 +0000
+++ b/liboctave/ChangeLog	Wed Feb 28 08:24:43 2001 +0000
@@ -1,3 +1,13 @@
+2001-02-28  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* lo-cutils.c (octave_gethostname): New function.
+	* lo-utils.h: Provide declaration.
+	* oct-env.cc (octave_env::do_get_host_name):
+	Call octave_gethostname, instead of gethostname.
+
+	* lo-cutils.c (gethostname): Define here.
+	* lo-sysdep.cc: Not here.
+
 2001-02-07  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* lo-cutils.c: Don't declare strptime.
--- a/liboctave/lo-cutils.c	Mon Feb 26 20:26:15 2001 +0000
+++ b/liboctave/lo-cutils.c	Wed Feb 28 08:24:43 2001 +0000
@@ -20,11 +20,27 @@
 
 */
 
+/*
+
+The function gethostname was adapted from a similar function from GNU
+Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free
+Software Foundation, Inc.
+
+*/
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
+#ifdef HAVE_UNISTD_H
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#include <unistd.h>
+#endif
+
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 
 void
@@ -40,7 +56,33 @@
   return (char *) strptime (buf, format, tm);
 }
 
+#if ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H)
 
+#include <sys/utsname.h>
+
+int
+gethostname (char *name, int namelen)
+{
+  int i;
+  struct utsname ut;
+
+  --namelen;
+
+  uname (&ut);
+  i = strlen (ut.nodename) + 1;
+  strncpy (name, ut.nodename, i < namelen ? i : namelen);
+  name[namelen] = '\0';
+
+  return 0;
+}
+
+#endif
+
+int
+octave_gethostname (char *name, int namelen)
+{
+  return gethostname (name, namelen);
+}
 
 /*
 ;;; Local Variables: ***
--- a/liboctave/lo-sysdep.cc	Mon Feb 26 20:26:15 2001 +0000
+++ b/liboctave/lo-sysdep.cc	Wed Feb 28 08:24:43 2001 +0000
@@ -20,14 +20,6 @@
 
 */
 
-/*
-
-The function gethostname was adapted from a similar function from GNU
-Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free
-Software Foundation, Inc.
-
-*/
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -42,10 +34,6 @@
 #include <unistd.h>
 #endif
 
-#if ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H)
-#include <sys/utsname.h>
-#endif
-
 #include "lo-error.h"
 #include "pathlen.h"
 
@@ -100,26 +88,6 @@
 #endif
 }
 
-#if ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H)
-
-int
-gethostname (char *name, int namelen)
-{
-  int i;
-  struct utsname ut;
-
-  --namelen;
-
-  uname (&ut);
-  i = strlen (ut.nodename) + 1;
-  strncpy (name, ut.nodename, i < namelen ? i : namelen);
-  name[namelen] = '\0';
-
-  return 0;
-}
-
-#endif
-
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/lo-utils.h	Mon Feb 26 20:26:15 2001 +0000
+++ b/liboctave/lo-utils.h	Wed Feb 28 08:24:43 2001 +0000
@@ -36,6 +36,8 @@
 
 extern std::string octave_fgets (std::FILE *);
 
+extern "C" int octave_gethostname (char *, int);
+
 extern "C" void octave_qsort (void *base, size_t n, size_t size,
 			      int (*cmp) (const void *, const void *));
 
--- a/liboctave/oct-env.cc	Mon Feb 26 20:26:15 2001 +0000
+++ b/liboctave/oct-env.cc	Wed Feb 28 08:24:43 2001 +0000
@@ -398,7 +398,7 @@
     {
       char hostname[256];
 
-      int status = gethostname (hostname, 255);
+      int status = octave_gethostname (hostname, 255);
 
       host_name = (status < 0) ? "unknown" : hostname;
     }
--- a/scripts/ChangeLog	Mon Feb 26 20:26:15 2001 +0000
+++ b/scripts/ChangeLog	Wed Feb 28 08:24:43 2001 +0000
@@ -1,3 +1,17 @@
+2001-02-28  Kai Habel  <kai.habel@gmx.de>
+
+    * general/cart2pol.m: New file.
+    * general/pol2cart.m: New file.
+    * general/cart2sph.m: New file.
+    * general/sph2cart.m: New file.
+    * image/rgb2hsv.m: New file.
+    * image/hsv2rgb.m: New file.
+
+2001-02-26  Paul Kienzle  <pkienzle@kienzle.powernet.co.uk>
+
+	* plot/meshgrid.m: Avoid for loops.
+	* plot/meshdom.m: Likewise.
+
 2001-02-22  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* linear-algebra/norm.m: Use sqrt instead of ^0.5.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/general/cart2pol.m	Wed Feb 28 08:24:43 2001 +0000
@@ -0,0 +1,52 @@
+## Copyright (C) 2000  Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} [@var{theta}, @var{r}] = cart2pol (@var{x}, @var{y})
+## @deftypefnx {Function File} {} [@var{theta}, @var{r}, @var{z}] = cart2pol (@var{x}, @var{y}, @var{z})
+## Transform cartesian to polar or cylindrical coordinates.
+## @var{x}, @var{y} (and @var{z}) must be of same shape.
+## @var{theta} describes the angle relative to the x - axis.
+## @var{r} is the distance to the z - axis (0, 0, z).
+## @end deftypefn
+## @seealso{pol2cart, cart2sph, sph2cart}
+
+## Author: Kai Habel <kai.habel@gmx.de>
+## Adapted-by: jwe
+
+function [Theta, R, Z] = cart2pol (X, Y, Z)
+
+  if (nargin < 2 || nargin > 3)
+    error ("cart2pol: number of arguments must be 2 or 3");
+  endif
+
+  if (nargin == 2 && nargout > 2)
+    error ("cart2pol: number of output arguments must not be greater than number of input arguments");
+  endif
+
+  if ((! (is_matrix (X) && is_matrix (Y)))
+      || (size (X) != size (Y))
+      || (nargin == 3 && (! (size (X) == size (Z) && is_matrix (Z)))))
+    error ("cart2pol: arguments must be matrices of same size");
+  endif
+
+  Theta = atan2 (Y, X);
+  R = sqrt (X .^ 2 + Y .^ 2);
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/general/cart2sph.m	Wed Feb 28 08:24:43 2001 +0000
@@ -0,0 +1,49 @@
+## Copyright (C) 2000  Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} [@var{theta}, @var{phi}, @var{r}] = cart2sph (@var{x}, @var{y}, @var{z})
+## Transform cartesian to spherical coordinates.
+## @var{x}, @var{y} and @var{z} must be of same shape.
+## @var{theta} describes the angle relative to the x - axis.
+## @var{phi} is the angle relative to the xy - plane.
+## @var{r} is the distance to the origin (0, 0, 0).
+## @end deftypefn
+## @seealso{pol2cart, cart2pol, sph2cart}
+
+## Author: Kai Habel <kai.habel@gmx.de>
+## Adapted-by: jwe
+
+function [Theta, Phi, R] = cart2sph (X, Y, Z)
+
+  if (nargin != 3)
+    usage ("[Theta, Phi, R] = cart2sph (X, Y, Z)")
+  endif
+
+  if ((! (is_matrix (X) && is_matrix (Y) && is_matrix (Z)))
+      || size (X) != size (Y)
+      || size (X) != size (Z))
+    error ("cart2sph: arguments must be matrices of same size");
+  endif
+
+  Theta = atan2 (Y, X);
+  Phi = atan2 (Z, sqrt (X .^ 2 + Y .^ 2));
+  R = sqrt (X .^ 2 + Y .^ 2 + Z .^ 2);
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/general/pol2cart.m	Wed Feb 28 08:24:43 2001 +0000
@@ -0,0 +1,52 @@
+## Copyright (C) 2000  Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} [@var{x}, @var{y}] = pol2cart (@var{theta}, @var{r})
+## @deftypefnx {Function File} {} [@var{x}, @var{y}, @var{z}] = pol2cart (@var{theta}, @var{r}, @var{z})
+## Transform polar or cylindrical to cartesian coordinates.
+## @var{theta}, @var{r} (and @var{z}) must be of same shape.
+## @var{theta} describes the angle relative to the x - axis.
+## @var{r} is the distance to the z - axis (0, 0, z).
+## @end deftypefn
+## @seealso{cart2pol, cart2sph, sph2cart}
+
+## Author: Kai Habel <kai.habel@gmx.de>
+## Adapted-by: jwe
+
+function [X, Y, Z] = pol2cart (Theta, R, Z)
+
+  if (nargin < 2 || nargin > 3)
+    error ("pol2cart: number of arguments must be 2 or 3");
+  endif
+
+  if (nargin == 2 && nargout > 2)
+    error ("pol2cart: number of output arguments must not be greater than number of input arguments");
+  endif
+
+  if ((! (is_matrix (Theta) && is_matrix (R)))
+      || (size (Theta) != size (R))
+      || (nargin == 3 && (! (size (R) == size (Z) && is_matrix (Z)))))
+    error ("pol2cart: arguments must be matrices of same size");
+  endif
+
+  X = cos (Theta) .* R;
+  Y = sin (Theta) .* R;
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/general/sph2cart.m	Wed Feb 28 08:24:43 2001 +0000
@@ -0,0 +1,49 @@
+## Copyright (C) 2000  Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} [@var{x}, @var{y}, @var{z}] = sph2cart (@var{theta}, @var{phi}, @var{r})
+## Transform spherical to cartesian coordinates.
+## @var{x}, @var{y} and @var{z} must be of same shape.
+## @var{theta} describes the angle relative to the x-axis.
+## @var{phi} is the angle relative to the xy-plane.
+## @var{r} is the distance to the origin (0, 0, 0).
+## @end deftypefn
+## @seealso{pol2cart, cart2pol, cart2sph}
+
+## Author: Kai Habel <kai.habel@gmx.de>
+## Adapted-by: jwe
+
+function [X, Y, Z] = sph2cart (Theta, Phi, R)
+
+  if (nargin != 3)
+    usage ("[X, Y, Z] = sph2cart (Theta, Phi, R)");
+  endif
+
+  if ((! (is_matrix (Theta) && is_matrix (Phi) && is_matrix (R)))
+      || size (Theta) != size (Phi)
+      || size (Theta) != size (R))
+    error ("sph2cart: arguments must be matrices of same size");
+  endif
+
+  X = R .* cos (Phi) .* cos (Theta);
+  Y = R .* cos (Phi) .* sin (Theta);
+  Z = R .* sin (Phi);
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/image/hsv2rgb.m	Wed Feb 28 08:24:43 2001 +0000
@@ -0,0 +1,67 @@
+## Copyright (C) 1999,2000  Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} @var{rgb_map} = hsv2rgb (@var{hsv_map})
+## Transform a colormap from the hsv space to the rgb space. 
+## @end deftypefn
+## @seealso{rgb2hsv}
+
+## Author: Kai Habel <kai.habel@gmx.de>
+## Adapted-by: jwe
+
+function rgb_map = hsv2rgb (hsv_map)
+
+## each color value x=(r,g,b) is calculated with
+## x = (1-sat)*val+sat*val*f_x(hue)
+## where f_x(hue) is a piecewise defined function for
+## each color with f_r(hue-2/3) = f_g(hue) = f_b(hue-1/3)
+
+  if (nargin != 1)
+    usage ("rgb_map = hsv2rgb (hsv_map)");
+  endif
+
+  if (! is_matrix (hsv_map) || columns (hsv_map) != 3)
+    error ("hsv2rgb: argument must be a matrix of size nx3");
+  endif
+
+  ## set values <0 to 0 and >1 to 1
+  hsv_map = (hsv_map >= 0 & hsv_map <= 1) .* hsv_map \
+      + (hsv_map < 0) .* 0 + (hsv_map > 1);
+
+  ## fill rgb map with v*(1-s)
+  rgb_map = kron ([1, 1, 1], hsv_map(:,3) .* (1 - hsv_map(:,2)));
+
+  ## red(hue-2/3)=green(hue)=blue(hue-1/3)
+  ## apply modulo 1 for red and blue 
+  t = hsv_map(:,1);
+  tp = t';
+  hue = [(tp - 2/3 - floor (t - 2/3)');
+         tp;
+         (tp - 1/3 - floor (t - 1/3)')]';
+
+  ## factor s*v -> f
+  f = kron ([1, 1, 1], hsv_map(:,2)) .* kron ([1, 1, 1], hsv_map(:,3));
+
+  ## add s*v* hue-function to rgb map
+  rgb_map = rgb_map +  f .* (6 * (hue < 1/6) .* hue
+			     + (hue >= 1/6 & hue < 1/2)
+			     + (hue >= 1/2 & hue < 2/3) .* (4 - 6 * hue));
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/image/rgb2hsv.m	Wed Feb 28 08:24:43 2001 +0000
@@ -0,0 +1,90 @@
+## Copyright (C) 1999, 2000  Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} @var{hsv_map} = rgb2hsv (@var{rgb_map})
+## Transform a colormap from the rgb space to the hsv space.
+##
+## A color n the RGB space consists of the red, green and blue intensities.
+##
+## In the HSV space each color is represented by their hue, saturation
+## and value (brightness).  Value gives the amount of light in the color.
+## Hue describes the dominant wavelegth. 
+## Saturation is the amount of Hue mixed into the color. 
+## @end deftypefn
+## @seealso{hsv2rgb}
+
+## Author: Kai Habel <kai.habel@gmx.de>
+## Adapted-by: jwe
+
+function hsval = rgb2hsv (rgb)
+
+  if (nargin != 1)
+    usage ("hsv_map = rgb2hsv (rgb_map)");
+  endif
+
+  if (! is_matrix (rgb) || columns (rgb) != 3)
+    error ("rgb2hsv: argument must be a matrix of size n x 3");
+  endif
+
+  # get saturation and value
+  v = max (rgb');
+  s = (v' > 0) .* (1 .- min (rgb') ./ v)';
+
+  # if v==0 set s to 0 too
+  s(isnan (s)) = 0;
+
+  # subtract minimum and divide trough maximum
+  # to get the bright and saturated colors
+  sc = (rgb - kron ([1, 1, 1], min (rgb')'));
+  sv = sc ./ kron([1, 1, 1], max (sc')');
+
+  # if r=g=b (gray value) set hue to 0
+  sv(isnan (sv)) = 0;
+
+  # hue=f(color) must be splitted into 6 parts 
+  # 2 for each color
+
+  # h1(green)
+  tmp = (sv(:, 1) == 1 & sv(:,3) == 0) .* (1/6 * sv(:,2) + eps);
+  # avoid problems with h2(red) since hue(0)==hue(1)
+  h = (tmp < 1/6) .* tmp; 
+  # h2(green)
+  h = h + ((h == 0) & sv(:,1) == 0 & sv(:,3) == 1) \
+      .* (-1/6 * sv(:,2) + 2/3 + eps);
+
+  # h1(red)
+  h = h + ((h == 0) & sv(:,2) == 1 & sv(:,3) == 0) \
+      .* (-1/6 * sv(:,1) + 1/3 + eps);
+
+  # h2(red)
+  h = h + ((h == 0) & sv(:,2) == 0 & sv(:,3) == 1) \
+      .* (1/6 * sv(:,1) + 2/3 + eps);
+
+  # h1(blue)
+  h = h + ((h == 0) & sv(:,1) == 1 & sv(:,2) == 0) \
+      .* (-1/6 * sv(:,3) + 1 + eps);
+
+  # h2(blue)
+  h = h + ((h == 0) & sv(:,1) == 0 & sv(:,2) == 1) \
+      .* (1/6 * sv(:,3) + 1/3);
+
+  hsval = [h, s, v'];
+
+endfunction
--- a/scripts/plot/meshdom.m	Mon Feb 26 20:26:15 2001 +0000
+++ b/scripts/plot/meshdom.m	Wed Feb 28 08:24:43 2001 +0000
@@ -32,23 +32,8 @@
 
   if (nargin == 2)
     if (is_vector (x) && is_vector (y))
-      xlen = length (x);
-      ylen = length (y);
-      xx = zeros (ylen, xlen);
-      yy = zeros (ylen, xlen);
-      y = y (ylen:-1:1);
-      if (columns (x) == 1)
-        x = x';
-      endif
-      if (rows (y) == 1)
-        y = y';
-      endif
-      for i = 1:ylen
-        xx(i,:) = x;
-      endfor
-      for i = 1:xlen
-        yy(:,i) = y;
-      endfor
+      xx = ones (length (y), 1) * x(:).';
+      yy = flipud (y(:)) * ones (1, length (x));
     else
       error ("meshdom: arguments must be vectors");
     endif
--- a/scripts/plot/meshgrid.m	Mon Feb 26 20:26:15 2001 +0000
+++ b/scripts/plot/meshgrid.m	Wed Feb 28 08:24:43 2001 +0000
@@ -36,22 +36,8 @@
   endif
   if (nargin > 0 && nargin < 3)
     if (is_vector (x) && is_vector (y))
-      xlen = length (x);
-      ylen = length (y);
-      xx = zeros (ylen, xlen);
-      yy = zeros (ylen, xlen);
-      if (columns (x) == 1)
-        x = x.';
-      endif
-      if (rows (y) == 1)
-        y = y.';
-      endif
-      for i = 1:ylen
-        xx(i,:) = x;
-      endfor
-      for i = 1:xlen
-        yy(:,i) = y;
-      endfor
+      xx = ones (length (y), 1) * x(:).';
+      yy = y(:) * ones (1, length (x));
     else
       error ("meshgrid: arguments must be vectors");
     endif