Index: contourc.m =================================================================== RCS file: /cvs/octave/scripts/plot/contourc.m,v retrieving revision 1.9 diff -u -r1.9 contourc.m --- contourc.m 13 Sep 2007 18:22:38 -0000 1.9 +++ contourc.m 8 Oct 2007 22:14:51 -0000 @@ -57,6 +57,7 @@ ## @end deftypefn ## Author: shaia +## Grid mapping contributed by Peter A. Gustafson (2007) and Alexander Barth function [c, lev] = contourc (varargin) @@ -90,25 +91,52 @@ vv = unique (sort (vn)); endif - ## Vectorize the x,y vectors, assuming they are output from meshgrid. - if (! isvector (x)) - x = x(1,:); - endif + if (isvector (x) & isvector (y)) - if (! isvector (y)) - y = y(:,1); - endif + ## Make everyone the right dimensions. + if (size (x, 2) == 1) + x = x'; + endif + if (size (y, 2) == 1) + y = y'; + endif - ## Make everyone the right dimensions. - if (size (x, 2) == 1) - x = x'; - endif - if (size (y, 2) == 1) - y = y'; + ## Now call __contourc__ for the real work... + c = __contourc__ (x, y, z, vv); + else + ## Indexes x,y for the purpose of __contourc__. + ii = 1:size (z,2); + jj = 1:size (z,1); + + ## Now call __contourc__ for the real work... + c = __contourc__ (ii, jj, z, vv); + + ## Map the contour lines from index space (i,j) back + ## to the original grid (x,y) + i = 1; + + while (i < size (c,2)) + clen = c(2,i); + ind = i+[1:clen]; + + ci = c(1,ind); + cj = c(2,ind); + + ## due to rounding errors some elements of ci and cj + ## can fall out of the range of ii and jj and interp2 would + ## return NA for those values. + ## The permitted range is enforced here: + + ci = max(ci,1); ci = min(ci,size(z,2)); + cj = max(cj,1); cj = min(cj,size(z,1)); + + c(1,ind) = interp2 (ii, jj, x, ci, cj); + c(2,ind) = interp2 (ii, jj, y, ci, cj); + + i = i + clen + 1; + endwhile endif - - ## Now call __contourc__ for the real work... - c = __contourc__ (x, y, z, vv); + if (nargout == 2) lev = vv; endif