%% 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


% Standard plotting

   for i = 0 : round(Nt/app.PlotIntrvl)
%   for i = 0 : 0

        if ( ((exist(sprintf('%s/%s/%03d', d0, app.savemat, i),'file')==2) | ...
              (exist(sprintf('%s/%s/%03d.mat', d0, app.savemat, i),'file')==2)) & ...
             ( (exist(sprintf('%s/%s/%03d.png', d0, app.saveimg, i),'file')~=2) | redoPlots) )
    
           load(sprintf('%s/%s/%03d', d0, app.savemat, i));
    
           clf; set(figure(1), 'Position', [0, 200, 1200, 1200]);
    
           subplot(4,1,1);
           S_Plot = rho*DelS;
           S_Plot(1:Nbcs) = NaN;   
           colormap(mk_colmap);
           surf(XP*h/1e3, YP*h/1e3, S_Plot(NodeRho(2:app.Ny+1, 2:app.Nx+1)), 'LineStyle','none');
           axis tight
           view(2); caxis([0,DelS]); colorbar;
           shading interp    
           TT(1) = xlabel('x(km)');
           TT(2) = ylabel('z(km)');
           TT(3) = zlabel('Salinity(psu)');
           TT(4) = title(sprintf(...
               'Salinity Variation (unit: psu) (Nx=%g, Ny=%g, dt=%g, time=%3.3gh)',...
               app.Nx, app.Ny, app.dt*h^2/nu_x, i*app.PlotIntrvl*app.dt*h^2/nu_x/3600));
           formatplot([], gca, TT, [], font_settings.fontsize);
    
           subplot(4,1,2);
           P_Plot = P*(nu_x/h)^2;
           P_Plot(1:Nbcs) = NaN;
           if (resetPflag)
              P_Plot = P_Plot - P_Plot(NodeP(2,2));
           end;
           colormap(mk_colmap);
           surf(XP*h/1e3, YP*h/1e3, P_Plot(NodeP(2:app.Ny+1, 2:app.Nx+1)), 'LineStyle','none');
           axis tight
           view(2); colorbar;
           shading interp    
           TT(1) = xlabel('x(km)');
           TT(2) = ylabel('z(km)');
           TT(3) = zlabel('Normalized Pressure(Pa/(kg/m^3))');
           TT(4) = title('Normalized Pressure(Pa/(kg/m^3)) (Without hydrostatic part)');
           formatplot([], gca, TT, [], font_settings.fontsize);
    
           subplot(4,1,3);
           u_Plot = u*(nu_x/h);
           u_Plot(1:Nbcs) = NaN;   
           colormap(mk_colmap);
           surf(XU*h/1e3, YU*h/1e3, u_Plot(Nodeu(2:app.Ny+1, 2:app.Nx)), 'LineStyle','none');
           axis tight
           view(2); colorbar;
           shading interp    
           TT(1) = xlabel('x(km)');
           TT(2) = ylabel('z(km)');
           TT(3) = zlabel('u Velocity(m/s)');
           TT(4) = title('u Velocity(m/s)');
           formatplot([], gca, TT, [], font_settings.fontsize);
    
           subplot(4,1,4);
           v_Plot = v*(nu_x/h);
           v_Plot(1:Nbcs) = NaN;   
           colormap(mk_colmap);
           surf(XV*h/1e3, YV*h/1e3, v_Plot(Nodev(2:app.Ny, 2:app.Nx+1)), 'LineStyle','none');
           axis tight
           view(2); colorbar;
           shading interp    
           TT(1) = xlabel('x(km)');
           TT(2) = ylabel('z(km)');
           TT(3) = zlabel('w Velocity(m/s)');
           TT(4) = title('w Velocity(m/s)');
           formatplot([], gca, TT, [], font_settings.fontsize);
    
           drawnow;
    
%           set(figure(1), 'PaperPosition', [0, 0, 12, 12]);
%           print('-dpng', '-r400', sprintf('%s/%s/%03d', d0, app.saveimg, i));
           print('-dpng', sprintf('%s/%s/%03d', d0, app.saveimg, i));
        end;
   end;

