%testCase = 'Bottom_Gravity_Current_001';

opengl neverselect;
addpath ('/home/phaley/Students/Jing/FV_Matlab_Framework_JingPJH/trunk/Src/Util');

readFrom='/home/phaley/Students/Jing/FV_Matlab_Framework_JingPJH/trunk/Save_Class1/mat/Bottom_Gravity_Current_006';
%readFrom='/home/phaley/Students/Jing/FV_Matlab_Framework_JingPJH/trunk/Save_Class1/mat/Bottom_Gravity_Current_009';
d0 = '/home/phaley/Students/Jing/FV_Matlab_Framework_JingPJH/trunk/Save_Class1/figures';

load(sprintf('%s/setup.mat',readFrom),'XP','YP','XU','YU','XV','YV','NodeP','Nodeu','Nodev','Nbcs','NodeRho','app','dx','dy','a','b','DelS','h');
%load(sprintf('%s/%03d.mat',readFrom,0),'YYt','u','v','rho','ui','vi','rhoi','T');
NodeP=NodeP;
XP=XP*h/1000;
YP=YP*h/1000;
b=b*h/1000;
ymin=0.6;

realIDs = [1011 2021 4041 6062 11112 17173 21213 29294 30304 39395 48485 73738 78788 86869 95960];
nReal = length(realIDs);

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

ridgex = [0 33.2667 33.2667 7.414 0].*(h/1000);
ridgey = [0 0 4.25 5.37 5.37].*(h/1000);
ridgeColor = [105 105 105]/255;
%%
k=43;
    
%    if mod(k,10)==0
%        k
%    end
    load(sprintf('%s/%03d.mat',readFrom,k),'Yi','u','v','rho','ui','vi','rhoi','T');
    
    %%
    u(abs(u)<1e-6)=NaN;

    rhoR = bsxfun(@plus,rho,rhoi*Yi(realIDs,:)').*DelS;
    
    
%    f1=figure('visible','off');
    %f1=figure(1);
    clf
    PLTNUM=1;

    subplot(8,2,1);
        rhoplot=rho.*DelS;
        rhoplot(1:Nbcs) = NaN;   

        pcolor(XP,YP,rhoplot(NodeP(2:end-1,2:end-1))),shading interp
        %pcolor(flipud(dvdx-dudy)),shading interp,caxis([-100,100])
        %set(gca,'FontSize',12);
        %colorbar
        caxis([0 DelS]);set(gca,'YLim',[ymin b],'FontWeight','Bold');
        title('Mean');
        hold on;
        patch(ridgex,ridgey,ridgeColor)
    
    for n=1:length(realIDs)
        subplot(8,2,n+1)
        rhoplot=rhoR(:,n);
        rhoplot(1:Nbcs) = NaN;   

        pcolor(XP,YP,rhoplot(NodeP(2:end-1,2:end-1))),shading interp
        %pcolor(flipud(dvdx-dudy)),shading interp,caxis([-100,100])
        %set(gca,'FontSize',12);
        %colorbar
        caxis([0 DelS]);set(gca,'YLim',[ymin b],'FontWeight','Bold');
        title(['realization ',num2str(realIDs(n))]);
        hold on;
        patch(ridgex,ridgey,ridgeColor)
            
    end
    colormap(mk_colmap)

