clear all;
fnam='DRE_20130711_T20p0_a.dat'
[t1_dre_a,a_dre_a,c_dre_no,wla_dre_a,wlc_dre_a]=rd_wetview_ac9(fnam);
tmp=20.0 ;sal=31;caltmp=19.4;
[adat_dre,cdat_dre] = tscorr_ac9(tmp,sal,a_dre_a',c_dre_no',caltmp);
clear c_dre* cdat* fnam wlc* tmp

fnam='DRE_20130711_T20p1_c.dat'
tmp=20.1;
[t1_dre_c,a_dre_no,c_dre_c,wla_dre_c,wlc_dre_c]=rd_wetview_ac9(fnam);
[adat_dre_c,cdat_dre] = tscorr_ac9(tmp,sal,a_dre_no',c_dre_c',caltmp);
clear a_dre_no adat_dre_c* fnam wla_dre_c* tmp

fnam='FSW_20130711_T20p3_a.dat'
tmp=20.3;
[t1_fsw_a,a_fsw_a,c_fsw_no,wla_fsw_a,wlc_fsw_a]=rd_wetview_ac9(fnam);
[adat_fsw,cdat_fsw] = tscorr_ac9(tmp,sal,a_fsw_a',c_fsw_no',caltmp);
clear c_fsw* cdat_fsw* fnam wlc_fsw* tmp 


fnam='FSW_20130711_T20p1_c.dat'
tmp=20.1;
[t1_fsw_c,a_fsw_no,c_fsw_c,wla_fsw_c,wlc_fsw_c]=rd_wetview_ac9(fnam);
[adat_fsw_c,cdat_fsw] = tscorr_ac9(tmp,sal,a_fsw_no',c_fsw_c',caltmp);
cdat_fsw=cdat_fsw(:,100:end)
clear a_fsw_no adat_fsw_c fnam wla_fsw_c tmp


figure
subplot(2,2,1)
plot(wla_dre_a,mean(a_dre_a),'g');hold on; plot(wla_dre_a,mean(adat_dre'),'-r*');
hold on;
subplot(2,2,2)
plot(wlc_dre_c, mean(c_dre_c),'g');hold on; plot(wlc_dre_c,mean(cdat_dre'),'-r*');
hold on;
subplot(2,2,3)
plot(wla_fsw_a,mean(a_fsw_a),'g'); hold on; plot(wla_fsw_a,mean(adat_fsw'),'-r*');
hold on;
subplot(2,2,4)
plot(wlc_fsw_c,mean(c_fsw_c),'g'); hold on; plot(wlc_fsw_c,mean(cdat_fsw'),'-r*');

%%%%%%%%scattering correction%%%%%%%%%%%%%%%%%%%%
adat=mean(adat_dre')-mean(adat_fsw'); cdat=mean(cdat_dre')-mean(cdat_fsw');
bdat=cdat-adat;
adat_dre_scat=adat-bdat*(adat(9)/bdat(9));


A_fsw=mean(adat_fsw');
bdat_fsw=mean(cdat_fsw')-mean(adat_fsw');
adat_fsw_scat=mean(adat_fsw')-bdat_fsw*(A_fsw(9)/bdat_fsw(9));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure
plot(wlc_fsw_c, cdat,'g');
hold on;
plot(wlc_fsw_c, adat_dre_scat,'k');

figure
plot(wlc_fsw_c, cdat,'g');
hold on;
plot(wlc_fsw_c, adat,'k');

b_dre=cdat-adat_dre_scat;
save('b_az.mat','b_dre','adat_dre_scat','cdat')

