% m-file: driver_rotating_3d_globe_9_Manual_03_anim_Earth_topography
% Examples in the Manual: 2. Making of 3D graphs step by step
%
% When using this driver or fuctions it calls, please cite the reference:
%  Bezdek A, Sebera J, 2013. MATLAB script for 3D visualizing geodata on a rotating globe.
%  Computers & geosciences 56, 127–130. http://dx.doi.org/10.1016/j.cageo.2013.03.007

% Ales Bezdek, bezdek@asu.cas.cz, 1/2015
% 6/2016 update to new Matlab versions up to R2015a

%% Selection of Earth topographical data: 10-arcmin grid
model='ETOPO2_010arcmin'; load (model);
%% Earth topography: getting started
rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'radius',6378,'units','km');

% we generate figures and thumbnails for the manual
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'tn_width',200,...
   'radius',6378,'units','km');
uiwait(gcf,1)
movefile(name_png,[ name_png(1:end-4) 'a.png']);
movefile(['tn200_' name_png],[ 'tn200_' name_png(1:end-4) 'a.png']);
%% Earth topography: omission of specifying the radius
model='ETOPO2_010arcmin'; load (model);
rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km);

% generation of figures and thumbnails for the manual
rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'tn_width',200);
%% Earth topography: label, larger image size and colorbar limits
model='ETOPO2_010arcmin'; load (model);
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'radius',6378,'units','km',...
   'cptcmap_pm','GMT_globe',...
   'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
   'graph_label',sprintf('Earth topography (%s)',model),...
   'tn_width',200,...
   'window_height',650);

uiwait(gcf,1)
movefile(name_png,[ name_png(1:end-4) 'a.png']);
movefile(['tn200_' name_png],[ 'tn200_' name_png(1:end-4) 'a.png']);
%% Earth topography: slight exaggeration of elevation
model='ETOPO2_010arcmin'; load (model);
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'exaggeration_factor',13,'radius',6378,'units','km',...
   'cptcmap_pm','GMT_globe',...
   'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
   'graph_label',...
   sprintf('Earth topography: exaggerated elevation (%s)',model),...
   'tn_width',200,...
   'window_height',650);

uiwait(gcf,1)
movefile(name_png,[ name_png(1:end-4) 'b.png']);
movefile(['tn200_' name_png],[ 'tn200_' name_png(1:end-4) 'b.png']);
%% Earth topography: colour scale on a perfect sphere
model='ETOPO2_010arcmin'; load (model);
grid_of_ones=ones(size(elev_etopo2_km));  %unit sphere
rotating_3d_globe(lond_etopo2,latd_etopo2,grid_of_ones,...
  'units','km',...
  'elev_colour',elev_etopo2_km,...
  'cptcmap_pm','GMT_globe',...
  'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
  'graph_label',...
   sprintf('Earth topography: on perfect sphere (%s)',model),...
  'tn_width',200,...
  'window_height',650);


%% Earth topography: changing the view point
% geographic coordinates of view point: Himalaya
latd_view_point=28;  %latitude (deg)
lond_view_point=87;  %longitude (deg)

model='ETOPO2_010arcmin'; load (model);
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'exaggeration_factor',13,'radius',6378,'units','km',...
   'cptcmap_pm','GMT_globe',...
   'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
   'graph_label',sprintf('Earth topography: (%s)',model),...
   'tn_width',200,...
   'azimuth',90+lond_view_point,'elevation',latd_view_point,...
   'window_height',650);

%% Earth topography: changing the view point, zoom in
% geographic coordinates of view point: Himalaya
latd_view_point=28;  %latitude (deg)
lond_view_point=87;  %longitude (deg)

% Zooming can be implemented by changing the camera view angle (in degrees).
% Try values: 3 corresponds to regional view, 1 or 2 gets you more closer
view_angle=3;

model='ETOPO2_010arcmin'; load (model);
%model='ETOPO2_004arcmin'; load (model);   % Earth topographical data: 4-arcmin grid
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'exaggeration_factor',13,'radius',6378,'units','km',...
   'cptcmap_pm','GMT_globe',...
   'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
   'graph_label',sprintf('Earth topography: (%s)',model),...
   'preview_figure_visible',0,...
   'tn_width',200,...
   'azimuth',90+lond_view_point,'elevation',latd_view_point,...
   'view_angle',view_angle,...
   'window_height',650);

%% Earth topography: changing the view point, zoom in, more details (figure invisible)
% geographic coordinates of view point: Himalaya
latd_view_point=28;  %latitude (deg)
lond_view_point=87;  %longitude (deg)

% Zooming can be implemented by changing the camera view angle (in degrees).
% Try values: 3 corresponds to regional view, 1 or 2 gets you more closer
view_angle=3;

% model='ETOPO2_010arcmin'; load (model);
model='ETOPO2_004arcmin'; load (model);   % Earth topographical data: 4-arcmin grid
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'exaggeration_factor',13,'radius',6378,'units','km',...
   'cptcmap_pm','GMT_globe',...
   'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
   'graph_label',sprintf('Earth topography: (%s)',model),...
   'preview_figure_visible',0,...
   'tn_width',200,...
   'azimuth',90+lond_view_point,'elevation',latd_view_point,...
   'view_angle',view_angle,...
   'window_height',650);

%% Earth topography: changing the view point, plot a point
% geographic coordinates of view point: Prague, Czech Republic
latd_view_point=50;  %latitude (deg)
lond_view_point=14.5;  %longitude (deg)

model='ETOPO2_010arcmin'; load (model);
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'exaggeration_factor',13,'radius',6378,'units','km',...
   'cptcmap_pm','GMT_globe',...
   'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
   'graph_label',sprintf('Earth topography: (%s)',model),...
   'tn_width',200,...
   'azimuth',90+lond_view_point,'elevation',latd_view_point,...
   'window_height',650);

% Plot and label the point
% we need to know 'exaggeration_factor' and 'radius' to place the point
% on the displayed surface
exaggeration_factor=13;
radius=6378;
elev_view_point=interp2(lond_etopo2,latd_etopo2,elev_etopo2_km,lond_view_point,latd_view_point);
r=radius/exaggeration_factor+elev_view_point;
[xx,yy,zz]=sph2cart(lond_view_point/rad,latd_view_point/rad,r);
hold on
plot3(xx,yy,zz,'r.','MarkerSize',13)
text(xx,yy,zz,' Prague','fontSize',12,'color','red','FontWeight','bold')
eval(sprintf('print -dpng -r0 %s;',name_png)); %save the figure again
% system(sprintf('convert -resize %d %s tn%d_%s.png',200,name_png,200,name_png(1:end-4)));
system(sprintf('magick %s -resize %d tn%d_%s.png',name_png,200,200,name_png(1:end-4)));
%% Earth topography: changing the view point, zoom in, plot a point (figure invisible)
% geographic coordinates of view point: Prague, Czech Republic
latd_view_point=50;  %latitude (deg)
lond_view_point=14.5;  %longitude (deg)

% Zooming can be implemented by changing the camera view angle (in degrees).
% Try values: 3 corresponds to regional view, 1 or 2 gets you more closer
view_angle=2;

model='ETOPO2_004arcmin'; load (model);   % Earth topographical data: 4-arcmin grid
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'exaggeration_factor',13,'radius',6378,'units','km',...
   'cptcmap_pm','GMT_globe',...
   'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
   'graph_label',sprintf('Earth topography: (%s)',model),...
   'preview_figure_visible',0,...
   'tn_width',200,...
   'azimuth',90+lond_view_point,'elevation',latd_view_point,...
   'view_angle',view_angle,...
   'window_height',650);

% Plot and label the point
% we need to know 'exaggeration_factor' and 'radius' to place the point
%  on the displayed surface
exaggeration_factor=13;
radius=6378;
elev_view_point=interp2(lond_etopo2,latd_etopo2,elev_etopo2_km,lond_view_point,latd_view_point);
r=radius/exaggeration_factor+elev_view_point;
[xx,yy,zz]=sph2cart(lond_view_point/rad,latd_view_point/rad,r);
hold on
plot3(xx,yy,zz,'r.','MarkerSize',13)
text(xx,yy,zz,' Prague','fontSize',12,'color','red','FontWeight','bold')
eval(sprintf('print -dpng -r0 %s;',name_png)); %save the figure again
% system(sprintf('convert -resize %d %s tn%d_%s.png',200,name_png,200,name_png(1:end-4)));
system(sprintf('magick %s -resize %d tn%d_%s.png',name_png,200,200,name_png(1:end-4)));

%% Earth topography: zoom in, coastlines and country boundaries, more details (figure invisible)
% geodetic coordinates of view point: Potsdam, Germany
latd_view_point=52;
lond_view_point=13;

% Zooming can be implemented by changing the camera view angle (in degrees).
% Try values: 3 corresponds to regional view, 1 or 2 gets you more closer
view_angle=2;

% model='ETOPO2_010arcmin'; load (model);
model='ETOPO2_004arcmin'; load (model);
[hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,...
   'exaggeration_factor',13,'radius',6378,'units','km',...
   'coastlines',1,...
   'countries',1,...
   'cptcmap_pm','GMT_globe',...
   'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
   'graph_label',sprintf('Earth topography: (%s)',model),...
   'preview_figure_visible',0,...
   'tn_width',200,...
   'azimuth',90+lond_view_point,'elevation',latd_view_point,...
   'view_angle',view_angle,...
   'window_height',650);

  %% Earth topography: colour scale on a perfect sphere + grid lines
  model='ETOPO2_010arcmin'; load (model);
  grid_of_ones=ones(size(elev_etopo2_km));  %unit sphere
  rotating_3d_globe(lond_etopo2,latd_etopo2,grid_of_ones,...
    'units','km',...
    'elev_colour',elev_etopo2_km,...
    'cptcmap_pm','GMT_globe',...
    'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
    'grid',1,...
   'preview_figure_visible',1,...
   'tn_width',200,...
    'graph_label',...
    sprintf('Earth topography: on perfect sphere + grid lines (%s)',model),...
    'window_height',650);
