%CONVECT View COSY convection model

echo off
disp(' ------------------------------------------- ')
disp(' ')
disp('        View COSY convection model           ')
disp(' ')
disp(' ------------------------------------------- ')
disp(' ')
disp('The data used in this demo is available from')
disp('http://itg-www.esc.cam.ac.uk/COSY')
disp('')
nt=input(' Give number of points in theta ');
np=input(' Give number of points in phi ');
filename=input(' Give name of file (in single quotes) ');

% read and reorder 
eval(['load ' filename]);
s=eval([filename]);
s=reshape(s,np,nt);
s=s';

% interpolate to 1 deg spacing

phi=(0:np-1)*360.001/(np-1);
theta=(0:nt-1)*180.001/(nt-1);

nphi=1:360;
ntheta=1:180;

ns=interp2(theta,phi',s',ntheta,nphi');
topo=ns';
%load topo
clf reset
colormap('jet')
[x,y,z] = sphere(30);
a = min(min(topo));
b = max(max(topo));
to = fix(64*(topo-a)/(b-a)+1);
to(find(to>64)) = 64;

labels = [
    '  2-D Contour  '
    '      2-D      '
    '      3-D      '
    '     Done      '];

xl=' Longitude (deg) ';
yl=' Latitude (deg) ';
nc=3;
% Callbacks
s = str2mat(...
    'contour(1:360,-89:90,topo,nc),axis image,axis([0 360 -90 90]),xlabel(xl),ylabel(yl),title(filename)', ...
    'image([0 360],[-90 90],to), axis xy, axis image, title(filename),xlabel(xl),ylabel(yl)', ...
    ['cla,axis auto,surface(x,y,z,''FaceColor'',''texture'',''Cdata'',topo), ', ...
        'axis square,axis xy,axis off, view(3),title(filename)'], ...
    'clf reset');

cs = 'point = get(gcf,''pointer'');set(gcf,''pointer'',''watch'');drawnow,';
ce = ';set(gcf,''pointer'',point),drawnow';

for n=1:size(labels,1)
	rect = [.025 .02 .23 .07];
	uicontrol('units','normal','position',rect+[(n-1)*.24 0 0 0],...
                  'string',labels(n,:),'horiz','center','callback',[cs s(n,:) ce]);
end
axis off
text(.5,.5,'Select a view of the earth.','horiz','center');
