% still experimental... problems with color tables longer than 256
% color display to be written as MEX file, or to be resolved with Mathworks
% for now just displaying the various parts as separate images

% display complex image
%
% for now scale it (later make 2 versions, one to not scale, other to scale)
%
% scaling is ``isotropic'' in the Argand plane (e.g. if it is nearly real, we
%                                               won't see the imag part
%                                               brightened up to reveal
%                                               the ``noise'').

function no_deposit_no_return(Z,threshold)

%if nargin<2
%  threshold=.001;
%  disp(sprintf('tvc: threshold defaulting to %g',threshold))
%end%if

clg
subplot(221)
tvs(real(Z))
title('Real part')
subplot(222)
tvs(imag(Z))
title('Imag part')
subplot(223)
tvs(abs(Z))
title('magnitude')
subplot(224)
%tvslog(abs(Z))
%title('log magnitude on 60db scale')
tvs(angle(Z))
title('phase')

return




% color display to be written as MEX file, or to be resolved with Mathworks

disp('tvc: setting colormap to complex')

% for whatever the reason, L=16 does not work... color 257 takes on color 256
% can only have 256 colors?
L=8; % sqrt of length of colortable (e.g. colortable is 64^2=4096 long)
mapcycle=hsv(L);  % once around the unit circle
map=[];
for l=1:L
  map=[map;mapcycle*l/L]; % first time around is very dark then it gets lighter
end%for
% 4096 long now

map=[map;[1 1 1]];  % 4095 long now; white represents NaN

colormap(map)

% polar coordinates and components
% min2nan calls chnan and chnan only works on real matrices
most_extreme_real=max2nan(abs(real(Z)));
most_extreme_imag=max2nan(abs(imag(Z)));
max_boxsize=max(most_extreme_real,most_extreme_imag);
A=angle(Z);
R=abs(Z);
% clear Z
Rsc=R/max_boxsize; % scaled on 0..1
Rsclog=(log(Rsc)+36)/36; % log(Rsc) on -inf..0; -36..0 = log(eps)..0;
% clear R
Asc=(A+pi)/(2*pi); % scaled on 0..1
% clear A

%AandR=L*(L-1)*Rsc + L*Asc;
AandR=L*floor((L-1)*Rsclog) + floor(L*Asc);
% clear Asc
% clear Rsc

image(chnan(AandR,L^2+1)) % NaNs to 4097

