%Process CDOM Abosrbance from Spec
%October 2015
clear all
%Define raw data file name
filename=['CDOM_A'];
filewrite='YR151026_CDOM1.csv'; %name for CSV file
CDOM1=xlsread ([(filename) '.xls']);

%Change Sample ID names
str1=['wv']; str2=['T5589_A']; str3=['T5591_A']; str4=['T5593_A']; str5=['T5593D_A']; str6=['T5595_A']; 
str7=['T5597_A']; str8=['T5599_A']; 

CDOM1=CDOM1(39:end,:);
%Remove DI blank
x=find(CDOM1(1,:)<1);
for ii=3:size(CDOM1,2)
    CDOM1(:,ii)=CDOM1(:,ii)-CDOM1(:,x(1)); %subtract blank
    CDOM1(:,ii)=CDOM1(:,ii)-CDOM1(end,ii); %subtract NIR 750 nm which should be the end
    CDOM1(:,ii)=(CDOM1(:,ii).*2.303)./0.01; %convert from absorbance to absorption
end
aCDOM1=[];
aCDOM1(:,1)=CDOM1(:,1);
aCDOM1(:,2:(size(CDOM1,2)-2))=CDOM1(:,3:end-1);

fid = fopen([filewrite],'w');
fprintf(fid,'%s,%s,%s,%s,%s,%s,%s,%s\n',str1,str2,str3,str4,str5,str6,str7,str8);

datain=[aCDOM1];
 [s1, s2]=size(datain);
for i=1:s1,
    fprintf(fid,'%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f\n',datain(i,:));
end
fclose(fid);




