%% Bottom Gravity Current Test Case Post-Processing Script

% This test case is based on the paper "Dynamics of Two-Dimensional Turbulent Bottom
% Gravity Currents" by Ozgokmen and Chassignet in 2002 published in
% Journal of Physical Oceanography.

% Date: Jan. 2014
% Author: Jing Lin

%% Set up data loading and images saving directory

%clc;
%clear;

%d0 = fileparts([pwd, filesep]);
%d0 = d0(1 : strfind(d0,'trunk')+4);

%app.savemat = 'Save/mat/Bottom_Gravity_Current_15';
%app.saveimg = 'Save/img/Bottom_Gravity_Current_15';

if ~exist(sprintf('%s/%s', d0, app.savemat), 'dir')
    disp (' ');
    disp (['***Error: cannot find directory: ',sprintf('%s/%s', d0, app.savemat)]);
    disp (' ');
    error('Wrong data directory!');
end;

if ~exist(sprintf('%s/%s', d0, app.saveimg), 'dir')
    mkdir(sprintf('%s/%s', d0, app.saveimg));
end;


if isfield (app,'saveimg')
   savedir = app.saveimg;
end;

if isfield (app,'resetP');
   resetPflag = app.resetP;
else
   resetPflag = 0;
end;

if isfield (app,'redoPlots');
   redoPlots = app.redoPlots;
else
   redoPlots = 0;
end;

if isfield (app,'checkvarflag')
   checkvarflag = app.checkvarflag;
else
   checkvarflag = 0;
end;

if isfield (app,'totvarXlim')
   totvarXlim = app.totvarXlim;
else
   totvarXlim = Inf;
end;

if isfield (app,'suffix_string')
   suffix_string = app.suffix_string;
else
   suffix_string = '';
end;

if isfield (app,'computeerrs')
   computeerrs = app.computeerrs;
else
   computeerrs = 0;
end;

if isfield (app,'truthdir')
   truthdir = app.truthdir;
else
   truthdir = '';
end;

if isfield (app,'truth_offset')
   truth_offset = app.truth_offset;
else
   truth_offset = 0;
end;

%% Load setup data

load(sprintf('%s/%s/setup', d0, app.savemat));
d0 = fileparts([pwd, filesep]);
d0 = d0(1 : strfind(d0,'trunk')+4);
Nbcs = length(bcsDu) + length(bcsNu);


%% Plot salinity variation and save images

switch (plot_choice)

   case 'Plot_RhoPUV'

      % Standard plotting

      BGC_PlotRhoPUV

   case 'Temporal_Variance'

      % Checking temporal variance

      BGC_TemporalVariance

   case 'Ensemble_Variance'

      % Checking DO ensemble variance

      BGC_DOvariance

   case 'Ensemble_Mean'

      % Checking DO ensemble means

      BGC_DOmean
end;
