%addpath('/data/srb1/wchen/tools/m_fx/','-end')
addpath('/data/srb1/wchen/tools/m_fx//','-end')
%comparisons between MODIS5km and SURFRAD ground-truth for instantaneous
%cases by wchen 10.13.2020
clear all;clc;
pth       = './';
StOrg     = 'st_8sts';
nStd      = 0;
modSat    = 'terra';%'aqua';%
yyyy      = 2015;
mm        = 7;
FigName1   = ['abcd-ssda_modis_',modSat,'_flx_vs_st_',...
				num2str(yyyy),num2str(mm,'%02d')];         

StLon       = [-116.018,-88.37,-105.10,-89.97,-105.237,-77.93,-96.62,-97.49];%
StLat       = [  36.626, 40.06,  48.31,34.25,   40.125, 40.72, 43.73,36.61];%
nSt         = length(StLat);
stid  		= {'dra', 'bon','fpk', 'gwn','tbl','psu','sxf', 'SGPC1'};%
subti  		= {'(a)', '(b)','(c)', '(d)','(e)','(f)','(g)', '(h)'};%

tistrs = {'Observed SW{\downarrow} (W m^{-2})','c6flx','c7flx','flx'};
ylim	 = [0 1200];
nxbin	 = 300;nybin    = nxbin;
for ist=1:8
    %e.g. ana_c07/aqua_datetime_9-xyzn.mat
    timestr = load(['ana_c061/',modSat,'_datetime_',num2str(ist),'-xyzn.mat'],'timstr');
    stflx = load(['ana_c07/',modSat,'_datetime_',num2str(ist),'-xyzn.mat'],'onsite');
    c6flx = load(['ana_c061/',modSat,'_datetime_',num2str(ist),'-xyzn.mat'],'satellite');
    c7flx = load(['ana_c07/',modSat,'_datetime_',num2str(ist),'-xyzn.mat'],'satellite');
    flx = load(['ana_nasa/',modSat,'_datetime_',num2str(ist),'-xyzn.mat'],'satellite');
    dimsz = size(timestr.timstr);
    for it = 1:dimsz(1)
%         disp(timestr.timstr(it,:))
        if strcmpi(timestr.timstr(it,1:10),'07/19/2015')
            c6flx.satellite(it)=NaN;
        end
    end
    inds = find(~isnan(c6flx.satellite));
    figcap = [subti{ist},' ',upper(stid{ist})];


    figure('Units','inches','Position',[0.08 3 18.5 10])
    pltdata = nan(length(stflx.onsite),4);
    pltdata(:,1) = stflx.onsite;
    pltdata(:,2) = c6flx.satellite(inds);
    pltdata(:,3) = c7flx.satellite;
    pltdata(:,4) = flx.satellite;

    bar(pltdata,'linewidth',2.5)
    box off
    set(gca,'ylim',ylim,'linewidth',2.125,'FontSize', 22);
    if ist==1 
        legend(tistrs,'Orientation','horizontal','FontSize',18);
    end
    cap1=annotation('textbox', [0.15 0.80 0.1 0.1],...
    'String',figcap,...
    'EdgeColor', 'none', 'FontSize', 18);
    % keyboard
    print(gcf,'-djpeg','-r300',['Bar_',FigName1,'_st',num2str(ist)])
end


