% m-file: driver_rotating_3d_globe_8_gravity_gradient
%
% 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: gravity_gradient
% 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 geopotential model and computation/loading of the grid values
% model='asu-ch-0309'; %nmax 120
% model='itg-grace2010s'; %nmax 180
% model='GOCO03S';  %nmax 250
model='egm2008';  %nmax=2190
nmax=500;
% nmax=80;

% Computation of grid for the selected geopotential functional
[lond,latd,Trr]=compute_geopot_grids(model,nmax,'functional','Trr');
Trr_E=Trr*1e9;

%% Gravity gradient as 2D map
if strcmp(output,'a') || strcmp(output,'1') || strcmp(output,'2')
   [hc,htit,name_png]=elevation_2d_map(lond,latd,Trr_E,'coastlines',1,...
      'units','E',...
      'graph_label',sprintf('Gravity gradient (%s, nmax=%d)',upper(model),nmax),...
      'clbr_limits',[-50 50],'clbr_tick',-500:10:500,...
      'clrmap','clrmap_byr1',...
      'preview_figure_visible',0,...
      'tn_width',165,...
      'window_height',650);
end
%% Gravity gradient 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,latd,Trr_E,'coastlines',1,...
      'units','E',...
      'graph_label',sprintf('Gravity gradient (%s, nmax=%d)',upper(model),nmax),...
      'clbr_limits',[-50 50],'clbr_tick',-500:10:500,...
      'clrmap','clrmap_byr1',...
      'map_center','Pacific',...
      'preview_figure_visible',0,...
      'tn_width',165,...
      'window_height',650);
end
%% Gravity gradient in 3D as PNG image
if strcmp(output,'b') || strcmp(output,'1') || strcmp(output,'2')
   [hc,hlab,name_png]=rotating_3d_globe(lond,latd,Trr_E,'coastlines',1,...
      'exaggeration_factor',1,'radius',5e3/4,'units','E',...
      'graph_label',sprintf('Gravity gradient (%s, nmax=%d)',upper(model),nmax),...
      'clbr_limits',[-50 50],'clbr_tick',-500:10:500,...
      'clrmap','clrmap_byr1',...
      'preview_figure_visible',0,...
      'tn_width',266,...
      'window_height',650);
end
%% Gravity gradient in 3D as animated GIF
% For smoother animations, see below
if strcmp(output,'c')
   [hc,hlab,name_png]=rotating_3d_globe(lond,latd,Trr_E,'coastlines',1,...
      'exaggeration_factor',1,'radius',5e3/4,'units','E',...
      'graph_label',sprintf('Gravity gradient (%s, nmax=%d)',upper(model),nmax),...
      'clbr_limits',[-50 50],'clbr_tick',-500:10:500,...
      'clrmap','clrmap_byr1',...
      'preview_figure_visible',0,'clbr_anim',1,...
      'anim_gif',1,'anim_angle',360,'time_for_360deg',42,'fps',1,...
      'window_height',650);
end
%% Gravity gradient in 3D as WMV video
% For smoother animations, see below
if strcmp(output,'d')
   [hc,hlab,name_png]=rotating_3d_globe(lond,latd,Trr_E,'coastlines',1,...
      'exaggeration_factor',1,'radius',5e3/4,'units','E',...
      'graph_label',sprintf('Gravity gradient (%s, nmax=%d)',upper(model),nmax),...
      'clbr_limits',[-50 50],'clbr_tick',-500:10:500,...
      'clrmap','clrmap_byr1',...
      'preview_figure_visible',0,'clbr_anim',1,...
      'video_format','wmv','anim_angle',360,'time_for_360deg',42,'fps',1,...
      'window_height',650);
end
%% Gravity gradient 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,latd,Trr_E,'coastlines',1,...
      'exaggeration_factor',1,'radius',5e3/4,'units','E',...
      'graph_label',sprintf('Gravity gradient (%s, nmax=%d)',upper(model),nmax),...
      'clbr_limits',[-50 50],'clbr_tick',-500:10:500,...
      'clrmap','clrmap_byr1',...
      'preview_figure_visible',0,'clbr_anim',1,...
      'video_format','wmv','anim_gif',1,'anim_angle',360,'time_for_360deg',42,'fps',1,...
      'tn_width',133,...
      'window_height',650);
end
%% Gravity gradient in 3D as PNG image (high resolution)
if strcmp(output,'bhr') || strcmp(output,'1') || strcmp(output,'2')
   model='egm2008'; nmax=1000;    %selection of geopotential model
   [lond,latd,Trr]=compute_geopot_grids(model,nmax,'functional','Trr');
   Trr_E=Trr*1e9;
   [hc,hlab,name_png]=rotating_3d_globe(lond,latd,Trr_E,'coastlines',1,...
      'exaggeration_factor',1,'radius',5e3/4,'units','E',...
      'graph_label',sprintf('Gravity gradient (%s, nmax=%d)',upper(model),nmax),...
      'clbr_limits',[-50 50],'clbr_tick',-500:10:500,...
      'clrmap','clrmap_byr1',...
      'preview_figure_visible',0,...
      'font_size',18,...
      'tn_width',266,...
      'window_height',3000);
end
%% Gravity gradient 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')
   model='egm2008'; nmax=500;    %selection of geopotential model
   [lond,latd,Trr]=compute_geopot_grids(model,nmax,'functional','Trr');
   Trr_E=Trr*1e9;
   [hc,hlab,name_png]=rotating_3d_globe(lond,latd,Trr_E,'coastlines',1,...
      'exaggeration_factor',1,'radius',5e3/4,'units','E',...
      'graph_label',sprintf('Gravity gradient (%s, nmax=%d)',upper(model),nmax),...
      'clbr_limits',[-50 50],'clbr_tick',-500:10:500,...
      'clrmap','clrmap_byr1',...
      'preview_figure_visible',0,'clbr_anim',1,...
      'video_format','wmv','anim_gif',1,'anim_angle',360,'time_for_360deg',42,'fps',15,...
      'tn_width',266,...
      'window_height',450);
end
