function patchhandle = scarpdater_createisosurface(dim1vec,dim2vec,dim3vec,matrix,value,color,transpose)

% Makes 3D isosurface for matrix.  The value of matrix at the value "value" is
%   the value of the isocontour.  Color is a standard matlab color string (see
%   plot for valid colors).  In many cases, the first and second dimension of
%   the matrix will need to be transposed.  Using 'transpose' or 'none' for this
%   option transposes or leaves the matrix intact, respectively.  dim1vec,
%   dim2vec, and dim3vec are vectors representing the values of the first,
%   second, and third dimensions of the matrix, respectively.  The returned
%   patchhandle may be used to change the isosurface attributes after plotting
%   (see "set" command).

[D1,D2,D3] = meshgrid(dim1vec,dim2vec,dim3vec);

if(strcmp(transpose,'transpose'))
   for(i=1:length(matrix(1,1,:)))
      matrixnew(:,:,i) = matrix(:,:,i)';
   end
elseif(strcmp(transpose,'none'))
   matrixnew = matrix;
else
   fprintf('createisosurface: Transpose token not understood.  Valid tokens are "transpose" and "none".\n');
end

v1 = isosurface(D1,D2,D3,matrixnew,value);
patchhandle = patch(v1);
isonormals(D1,D2,D3,matrixnew,patchhandle);

set(patchhandle,'edgecolor','none','facecolor',color);

illuminate;

