clear all
cd H:\honors proj\BD02\TSRB\TSRB_spreadsheets\Total_data
%   %%%add in next data sets
%   %[status,sheetNames] = xlsfinfo('BD02_TSRB_.xls');%
%   [Edat,Etxt] =xlsread('BD02_TSRB.xls','BD02_TSRB_DE');%
%   %SN ED443 ED490 ED555 LU683 LU665 LU555 LU705 LU490 LU443 LU412 Tw Ms Y  M  D  H  M  S    
%   % 1  2     3     4      5    6     7     8       9   10   11    12 13 14 15 16 17 18 19
%   for i=1:10
%       TE=char(Etxt(1,i+1));,L(i)=str2num(TE(4:8));,end%get wavelengths for Ed and Lu
%   w3=L(1:3);,w7=L([10 9 8 6 5 4 7]);
%   'BD02_TSRB.xls read in'
%   %[status,sheetNames] = xlsfinfo('BD02_TSRB_F.xls');%
%   [Fdat,Ftxt] =xlsread('BD02_TSRB_F.xls','BD02_TSRB_F');,'BD02_TSRB_F.xls read in'%
%   %SN ED443 ED490 ED555 LU683 LU665 LU555 LU705 LU490 LU443 LU412.0 Tw MS Y  M  D  H  M  S 
%   % 1  2     3     4      5    6     7     8       9   10   11      12 13 14 15 16 17 18 19


   [status,sheetNames] = xlsfinfo('TSRB_BD02_proc_sample_times.xls');%
   [Gdat,Gtxt] =xlsread('TSRB_BD02_proc_sample_times.xls','TSRB_BD02_proc_sample_times');%
   %SN ED443 ED490 ED555 LU683 LU665 LU555 LU705 LU490 LU443 LU412 Tw Ms Y  M  D  H  M  S    
   % 1  2     3     4      5    6     7     8       9   10   11    12 13 14 15 16 17 18 19
   for i=1:10
       TE=char(Gtxt(1,i+1));,L(i)=str2num(TE(4:8));,end%get wavelengths for Ed and Lu
   w3=L(1:3);,w7=L(4:10);
   'TSRB_BD02_proc_sample_times.xls read in'

%if Dat(:,14)<2000;Dat(:,14)=Dat(:,14)+2000;,end
%     Sn E1 E2 E3 L1 L2 L3 L4 L5 L6 L7 tW  Y  M  D  H mn  s
%      1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 
Dat=Gdat;
Gtime=Dat(:,13:18);,Mtime =datenum(Gtime);
Lu=Dat(:,5:11);
Edex=[Dat(:,2) Dat(:,2:4) Dat(:,4)  Dat(:,4) Dat(:,4)];%'410',410 490 555 '555' '555' '555'
for i=1:7
    Rex(:,i)=Lu(:,i)./Edex(:,i);,end
for j=1:length(Rex)
Rexmax(j,:)=Rex(j,:)/max(Rex(j,:));,end

clr=scalecolormap(Mtime);

figure(1)
for i=1:length(Rex)
    subplot(2,1,1),plot(w7,Rex(i,:),'ok-','MarkerFaceColor',clr(i,:)),hold on
    subplot(2,1,2),plot(w7,Rexmax(i,:),'ok-','MarkerFaceColor',clr(i,:)),hold on
end
Gtime=Hmed(:,1:6);,Mtime=datenum(Gtime);
Hdata=[Mtime Hmed(:,7:17)];%hourly data with matlab time in first column
%% hourly bin averaged
%I=find(Gtime(:,4)==23)%find the night time samples (save for later analysis)
%Hdata(I,:)=[];,Gtime(I,:)=[];%remove those rows from the data set
%I=find(Hdata(:,3)<20),Hdata(I,:)=[];,Gtime(I,:)=[];
%I=find(Hdata(:,7)>2),Hdata(I,:)=[];,Gtime(I,:)=[];
ndata=length(Hdata);
for i=1:ndata,R(i,:)=Hdata(i,5:11)./Hdata(i,4);,nR(i,:)=R(i,:)/max(R(i,4));,end%compute the Reflectance and normalized reflectance
figure(2)
xmin=datenum(2008,5,10,0,0,0);,xmax=datenum(2008,8,15,0,0,0);
subplot(5,1,1),plot(Hdata(:,1),Hdata(:,12),'.b'),ylabel('T ^oC'),axis([xmin xmax 0 35]),datetick('x',6,'keeplimits')
subplot(5,1,2),plot(Hdata(:,1),Hdata(:,4),'.c-'),ylabel('E_d(555)'),axis([xmin xmax 0 200]),datetick('x',6,'keeplimits')
subplot(5,1,3),plot(Hdata(:,1),Hdata(:,7),'.g-'),ylabel('L_u(555)'),axis([xmin xmax 0 6]),datetick('x',6,'keeplimits')
subplot(5,1,4),plot(Hdata(:,1),R(:,4),'.m'),ylabel('L_u(555)/E_d(555)'),axis([xmin xmax 0 .05]),datetick('x',6,'keeplimits')
subplot(5,2,9),plot(w3,Hdata(:,2:4),'b-'),ylabel('E_d(\lambda)'),xlabel('Wavelength'),axis([400 710 0 200])
subplot(5,2,10),plot(w7,nR,'g-'),ylabel('R(\lambda)'),xlabel('Wavelength'),axis([400 710 0 1.1])



%look at each day observations to decide what to keep
del=diff(Gtime(:,3));J=find(del~=0);J=[1;J;length(Hdata)];,nJ=length(J)
figure(3),daily=[];,Gdaily=[];
for i=1:nJ-1
    d=[Hdata(J(i)+1:J(i+1),1:12)];%one days worth of data
    G=[Gtime(J(i)+1:J(i+1),1:6)];%
    r=[R(J(i)+1:J(i+1),1:7)];
    nr=[nR(J(i)+1:J(i+1),1:7)];
    I=find(G(:,4)>=10&G(:,4)<=14);
    if length(I)>=1
         Sdate=num2str([G])
    subplot(3,2,1),plot(w3,d(I,2:4)),ylabel('E_d(\lambda'),xlabel('Wavelength(nm)'),title(Sdate)
    subplot(3,2,2),plot(w7,d(I,5:11)),ylabel('L_u(\lambda'),xlabel('Wavelength(nm)')
    subplot(3,2,3),plot(w7,r(I,1:7)),ylabel('R(\lambda'),xlabel('Wavelength(nm)')
    subplot(3,2,4),plot(w7,nr(I,1:7)),ylabel('R^N(\lambda'),xlabel('Wavelength(nm)')
    subplot(3,1,3),plot(G(I,4),d(I,2:4),'.'),ylabel('Ed(\lambda'),xlabel('hour')
    
    [k]=input('enter vector of observations to discard (i.e. [1 3 4] or [])')
    d(I(k),:)=NaN;,G(I(k),:)=NaN;
    subplot(3,2,2),plot(w7,d(I,5:11),'k-'),pause
    daily=[daily;d];%new daily obs to keep
    Gdaily=[Gdaily;G];
    clf,clear r d nr
    end
end

figure(4)
subplot(2,2,1),plot(w7,daily(:,5:11))
for i=1:7,r(:,i)=daily(:,i+4)./daily(:,3);,end
subplot(2,2,2),plot(w7,r)
r4=r(:,4);
for i=1:7 rn(:,i)=r(:,i)./r4;,end
subplot(2,2,3);,plot(w7,rn)

%load TSRB_20080804%load existing processed data

TSRB_processed=[TSRB_processed;daily];, R=[R;r];, nR=[nR;rn];%concatonate new file with existing data

save TSRB_2008??? TSRB_processed R nR w3 w7%save new mat file with last date of observation

