% m-file: driver_rotating_3d_globe_1_Earth_topography
%
% 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

%% Visualization output (2D map, 3D picture/animation)
% Input: Earth_topography
% Output: select one of the following options
output='2';
%     'a'..2D map; 'aa'..2D map centred on the Pacific;
%     'b'..3D as PNG image; 'bhr'..3D as PNG image (high resolution)
%     'c'..3D as animated GIF
%     'd'..3D as WMV video
%     'e'..3D as both animated GIF and WMV video; 'ehr'..high resolution
%     '1'..all images
%     '2'..all images/animations (animations may take longer time)
%% Selection of Earth topographical data
% model='ETOPO2_002arcmin';
% model='ETOPO2_004arcmin';
model='ETOPO2_010arcmin';
% model='ETOPO2_030arcmin';
fprintf('Loading Earth data: %s\n',model);
load (model);
%% Earth topography as 2D map
if strcmp(output,'a') || strcmp(output,'1') || strcmp(output,'2')
   [hc,htit,name_png]=elevation_2d_map(lond_etopo2,latd_etopo2,elev_etopo2_km,'coastlines',1,...
      'units','km',...
      'graph_label',sprintf('Earth topography (%s)',model),...
      'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
      'cptcmap_pm','GMT_globe',...
      'preview_figure_visible',0,...
      'tn_width',150,...
      'window_height',650);
end
%% Earth topography as 2D map (centred on the Pacific)
if strcmp(output,'aa') || strcmp(output,'1') || strcmp(output,'2')
   [hc,htit,name_png]=elevation_2d_map(lond_etopo2,latd_etopo2,elev_etopo2_km,'coastlines',1,...
      'units','km',...
      'graph_label',sprintf('Earth topography (%s)',model),...
      'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
      'cptcmap_pm','GMT_globe',...
      'map_center','Pacific',...
      'preview_figure_visible',0,...
      'tn_width',150,...
      'window_height',650);
end
%% Earth topography in 3D as PNG image
if strcmp(output,'b') || strcmp(output,'1') || strcmp(output,'2')
   [hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,'coastlines',0,...
      'exaggeration_factor',13,'radius',6378,'units','km',...
      'graph_label',sprintf('Earth topography (%s)',model),...
      'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
      'cptcmap_pm','GMT_globe',...
      'preview_figure_visible',0,...
      'tn_width',200,...
      'window_height',650);
end
%% Earth topography in 3D as animated GIF
% For smoother animations, see below
if strcmp(output,'c')
   [hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,'coastlines',0,...
      'exaggeration_factor',13,'radius',6378,'units','km',...
      'graph_label',sprintf('Earth topography (%s)',model),...
      'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
      'cptcmap_pm','GMT_globe',...
      'preview_figure_visible',0,'clbr_anim',1,...
      'anim_gif',1,'anim_angle',360,'time_for_360deg',42,'fps',1,...
      'window_height',650);
end
%% Earth topography in 3D as WMV video
% For smoother animations, see below
if strcmp(output,'d')
   [hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,'coastlines',0,...
      'exaggeration_factor',13,'radius',6378,'units','km',...
      'graph_label',sprintf('Earth topography (%s)',model),...
      'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
      'cptcmap_pm','GMT_globe',...
      'preview_figure_visible',0,'clbr_anim',1,...
      'video_format','wmv','anim_angle',360,'time_for_360deg',42,'fps',1,...
      'window_height',650);
end
%% Earth topography in 3D as both animated GIF and WMV video
% For smoother animations, see below
if strcmp(output,'e') || strcmp(output,'2')
   [hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,'coastlines',0,...
      'exaggeration_factor',13,'radius',6378,'units','km',...
      'graph_label',sprintf('Earth topography (%s)',model),...
      'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
      'cptcmap_pm','GMT_globe',...
      'preview_figure_visible',0,'clbr_anim',1,...
      'video_format','wmv','anim_gif',1,'anim_angle',360,'time_for_360deg',42,'fps',1,...
      'tn_width',100,...
      'window_height',650);
end
%% Earth topography in 3D as PNG image (high resolution)
if strcmp(output,'bhr') || strcmp(output,'1') || strcmp(output,'2')

   if exist('ETOPO2_004arcmin.mat','file')
      % model='ETOPO2_002arcmin';  %one needs more RAM than 4 GB
      model='ETOPO2_004arcmin';  % RAM of 4 GB is OK
      % model='ETOPO2_010arcmin';
      % model='ETOPO2_030arcmin';
      fprintf('Loading Earth data: %s\n',model);
      load (model);

   end

   [hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,'coastlines',0,...
      'exaggeration_factor',13,'radius',6378,'units','km',...
      'graph_label',sprintf('Earth topography (%s)',model),...
      'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
      'cptcmap_pm','GMT_globe',...
      'preview_figure_visible',0,...
      'font_size',18,...
      'tn_width',200,...
      'window_height',3000);
end
%% Earth topography in 3D as both animated GIF and WMV video (high resolution)
% High time resolution animation: smoother motion, but much larger file size
if strcmp(output,'ehr')
   [hc,hlab,name_png]=rotating_3d_globe(lond_etopo2,latd_etopo2,elev_etopo2_km,'coastlines',0,...
      'exaggeration_factor',13,'radius',6378,'units','km',...
      'graph_label',sprintf('Earth topography (%s)',model),...
      'clbr_limits',[-10 10],'clbr_tick',-10:2:10,...
      'cptcmap_pm','GMT_globe',...
      'preview_figure_visible',0,'clbr_anim',1,...
      'video_format','wmv','anim_gif',1,'anim_angle',360,'time_for_360deg',42,'fps',15,...
      'tn_width',200,...
      'window_height',450);
end
