% Plots
%Save initially everything for plotting later
if k==0
    colormap(mk_colmap)
    if isfield(app,'savemat')
        if isempty(app.savemat)
            d0=fileparts([pwd,filesep]);
            d0=d0(1:strfind(d0,'trunk')+4);
            save(sprintf('%s/Save/mat/param.mat',d0));
            fprintf('Saving %s mat-file in %s/Save/mat/parameters.mat',...
                SetupScript,d0);
        else
            if k < 10
                d0=fileparts([pwd,filesep]);
                d0=d0(1:strfind(d0,'trunk')+4);
                if ~exist(sprintf('%s/Save/%s/',d0,app.savemat),'dir')
                    mkdir(sprintf('%s/Save/%s/',d0,app.savemat))
                end
            end
            save(sprintf('%s/Save/%s/param.mat',d0,app.savemat));
            fprintf('Saving %s mat-file in %s/Save/%s/parameters.mat',...
                SetupScript,d0,app.savemat);
        end
    end
end


clf
subplot(131)
surf(XP,YP,P(NodeP(2:app.Ny+1,2:app.Nx+1)),'LineStyle','none') 
TT(1)=xlabel('x(m)');TT(2)=ylabel('y(m)');TT(3)=zlabel('T(^oC)');
TT(4)=title(sprintf('Pressure time=%2.4g',T));

view(2),colorbar,shading interp
subplot(132)
surf(XP,YP,rho(NodeP(2:app.Ny+1,2:app.Nx+1)),'LineStyle','none') 
TT(1)=xlabel('x(m)');TT(2)=ylabel('y(m)');TT(3)=zlabel('T(^oC)');
TT(4)=title(sprintf('Rho (app.Nx=%g, app.Ny=%g)',app.Nx,app.Ny));%caxis([-1 1]*0.5);
view(2),colorbar,shading interp

subplot(133)
tmp1 = 0.5*(u(Nodeu(2:app.Ny+1,1:app.Nx))+u(Nodeu(2:app.Ny+1,2:app.Nx+1)));
tmp2 = 0.5*(v(Nodev(2:app.Ny+1,2:app.Nx+1))+v(Nodev(1:app.Ny,2:app.Nx+1)));
quiver(XP(:),YP(:),(tmp1(:)),(tmp2(:)),'g') 
axis([-0 1 0 5])
hold on
streamslice(XP,YP,tmp1,tmp2)

%Save image
if isfield(app,'saveimg')
    d0=fileparts([pwd,filesep]);
    d0=d0(1:strfind(d0,'trunk')+4);
    print('-djpeg85','-r200',...
        sprintf('%s/Save/img/%05d.jpg',d0,k/app.PlotIntrvl));
    fprintf('Saving %s image in %s/Save/img/%05d.jpg\n',...
             SetupScript,d0,k/app.PlotIntrvl);
end

%Save only essentials for plotting later
if isfield(app,'savemat')
    if isempty(app.savemat)
        d0=fileparts([pwd,filesep]);
        d0=d0(1:strfind(d0,'trunk')+4);
        save(sprintf('%s/Save/mat/%05d.mat',d0,k/app.PlotIntrvl),'P','u','v','T','rho');
        fprintf('Saving %s mat-file in %s/Save/mat/%05d.mat\n',...
             SetupScript,d0,k/app.PlotIntrvl);
    else
        if k < 10
            if ~exist(sprintf('%s/Save/%s/',d0,app.savemat),'dir')
                mkdir(sprintf('%s/Save/%s/',d0,app.savemat))
            end
        end
        d0=fileparts([pwd,filesep]);
        d0=d0(1:strfind(d0,'trunk')+4);
        save(sprintf('%s/Save/%s/%05d.mat',d0,app.savemat,k/app.PlotIntrvl),'P','u','v','T','rho');
        fprintf('Saving %s mat-file in %s/Save/%s/%05d.mat\n',...
             SetupScript,d0,app.savemat,k/app.PlotIntrvl);
    end
end

drawnow;
