% Aurora Nephelometer data processing - T1
% Written by Luciana Rizzo
% Read raw data files, apply corrections, calculate averages, make plots
% Functions used: frepeated; export_LFA_GoAmazon_jan2015
% Outputs: neph_Level0 (mattime(utc);scat450;scat525;scat635;bscat450;bscat525;bscat635;inlettemp;sampletemp;rh;pres)--> all raw data, without filters
%          neph_Level1_5min (dd-mmm-yyyy HH:MM; sec_since_1970; mean_o3; std_o3; median_o3; p25_o3; p75_o3; max_o3; min_o3; num_o3)
%          neph_Level1_30min
% Time stamps in the output files refer to the start of the period 
% Criteria for Level1: 5sec aerosol light scattering at 450nm must be within 
% -10Mm-1 and 900 Mm-1. RH must be smaller than 60%. 
% Criteria for Level2: STP (1013.25; 293.15) and Muller et al. 2011 truncation correction
% Criteria for Level3: SSA calculated with MAAP BC data (MAC of 6.6 m2/g) must be >0.1.    
%  
%
% Parametros de entrada --------------------------------------------
caminho1='C:\A\GOAMAZON\T1\AURORA2000_090034sn\csv\'; % arquivos flex (Labview)
caminho2='C:\A\GOAMAZON\T1\AURORA2000_090034sn\txt\'; % arquivos do datalogger do instrumento
caminho3='C:\A\GOAMAZON\T1\AURORA2000_090034sn\';
tit='T1_2015-2016';
pref=1013.25; % Reference pressure for STP correction (mbar)
tref=293.15; % Reference temp for STP correction (K)
maxrh=60; % Maximum rh to consider the measurement valid
lambda=[450 525 635];
lerflex=true; % logical para ler arquivos flex (Labview)
lerdatalogger=true; % logical para ler arquivos do datalogger do instrumento
corrigirtempoflex=false;
corrigirtempodatalogger=true;
readprev=false; % logical for reading previous processed data (Warning: if corrections are needed for the new data, then this reaprev should be set false)
filtmanut=0; % logical para filtrar dados em períodos de manutenção ou com problemas
basicplots=true;
lev1=false;
lev2=false;
lev3=false;
%
%
% Program start -----------------------------------------------------
% inicio e termino de periodos de manutencao (horario em utc): removidos das analises
if(filtmanut)
%     C1=xlsread('C:\A\Diadema2016\logbook_trailer_Diadema2016.xlsx','todos','A4:M135');
%     C2=xlsread('C:\A\Diadema2016\logbook_trailer_Diadema2016.xlsx','neph_maap','A4:M5');
%     manut(:,1)=cat(1,datenum(C1(:,1:6)),datenum(C2(:,1:6)));
%     manut(:,2)=cat(1,datenum(C1(:,7:12)),datenum(C2(:,7:12)));
%     manut(:,3)=cat(1,C1(:,13),C2(:,13));    
end
%
if (readprev)
%     prevdata=load([caminho3,'Diadema-2016_neph_level0.mat']);
%     lerdaqui=floor(prevdata.alldatang(length(prevdata.alldatang),1));    
else
    lerdaqui=datenum(1900,1,1);
end
if(lerdatalogger && ~readprev) % No caso do T1, só precisa ler 1 arquivo txt
    nome='T1-nef-aurora-20fev2016.txt';
    fid=fopen(strcat(caminho2,nome));
    C=textscan(fid,'%s%*s %f%f%f %f%f%f%f','Delimiter',',');
    fclose(fid);
    alldata1=nan(size(C{1,1},1),size(C,2));
    for icol=2:size(C,2) % somente numeros
        alldata1(:,icol)=C{1,icol};
    end
    alldata1(:,1)=datenum(C{1,1},'dd/mm/yyyy HH:MM:SS'); %
%     files=dir(caminho2);
%     alldata1=zeros(1,11);
%     disp('-----Reading datalogger files')
%     for ifile=3:size(files,1)
%         nome=getfield(files, {ifile,1}, 'name');
%         disp(nome)
%         fid=fopen(strcat(caminho2,nome));
%         C=textscan(fid,'%s%*s %f%f%f%f%f%f%f%f%f%f','Delimiter',',');        
%         fclose(fid);
%         %
%         for icol=2:size(C,2) % somente numeros
%             data_(:,icol)=C{1,icol};
%         end
%         data_(:,1)=datenum(C{1,1},'dd/mm/yyyy HH:MM:SS'); %
%         alldata1=cat(1,alldata1,data_);
%         clear data_ C
%     end
%     alldata1(1,:)=[];
else
    alldata1=[];
end
%
if(lerflex)
    files=dir(caminho1);
    alldata2=zeros(1,8);
    disp('-----Reading flexdata files')
    for ifile=3:size(files,1)
        nome=getfield(files, {ifile,1}, 'name');
        aux1=strfind(nome,'nef-')+11;
        aux2=strfind(nome,'.csv')-1;
        filedia=datenum(nome(aux1:aux2),'yyyy-mm-dd');
        if(filedia>=lerdaqui)                
            disp(nome)
            fid=fopen(strcat(caminho1,nome));
            C=cell(floor(getfield(files, {ifile,1}, 'bytes')/100),13);
            textscan(fid,'%s%s%s%s%s%s %*s%s%s%s%s%s %s%s%s%s%s',1,'Delimiter',',');
            i=1;
            while (~feof(fid))
                C(i,:)=textscan(fid,'%*s%s%s%s%s %f%f%f%f%f%f%f%f%s',1,'Delimiter',',');
                i=i+1;
            end
            fclose(fid);
            %
            % removendo linhas com defeito
            rem=0;
            for j=5:13
                aux=find(cellfun(@isempty,C(:,j)));
                rem=cat(1,rem,aux);
            end
            rem(1)=[];
            C(rem,:)=[];
            %
            % removendo linhas com zero check (04,AB) e os 48 pontos subsquentes
            aux=cell2mat(C(:,11:12));
            rem=0;
            rem=cat(1,rem,find(aux(:,2)==4));
            rem(1)=[];
            remi=rem;
            for iii=1:48;
                rem=cat(1,rem,remi+iii);
            end
            rem=unique(rem);
            rem(rem>size(C,1))=[];
            C(rem,:)=[];                     
            %
            % removendo mais linhas com defeito
            aux=cell2mat(C(:,11:12));
            rem=0;
            rem=cat(1,rem,find(aux(:,1)<500));
            rem=cat(1,rem,find(aux(:,2)~=0));
            rem(1)=[];
            rem=unique(rem);
            C(rem,:)=[];
            %
            % removendo linhas com valores repetidos de espalhamento
            aux=cell2mat(C(:,6));
            rem=find(diff(aux)==0);
            C(rem,:)=[];
            %
            data_(:,2:8)=cell2mat(C(:,5:11));
            for i=1:length(C)
                data_(i,1)=datenum(strcat(C{i,1},C{i,2}),'yyyy-mm-ddHH:MM:SS');
            end
            %
            alldata2=cat(1,alldata2,data_);
            clear data_ C rem aux
        end
    end
    alldata2(1,:)=[];
end
if(corrigirtempodatalogger && ~readprev) % tapando buracos do flexdata (períodos com computador travado, dados armazenados no datalogger do instrumento)    
    aux1=find(alldata1(:,1)>=datenum(2016,2,17,15,45,00) & alldata1(:,1)<=datenum(2016,2,18,16,05,00));
    aux=alldata1; clear alldata1
    alldata1=aux(aux1,:);
    clear aux1 aux
end
if(corrigirtempoflex && ~readprev) % correção segundo o logbook
%     %subtrair 1h dos horarios anteriores a 25nov2016 16:25
%     aux1=find(alldata2(:,1)==datenum(2016,11,25,17,24,50));
%     aux2=find(alldata2(:,1)<=datenum(2016,11,25,17,24,51));
%     alldata2(aux2(1):aux1,1)=alldata2(aux2(1):aux1,1)-datenum(0,0,0,1,0,0);
%     %somar 2h dos horarios entre 25nov2016 14:25 e 15:19:33
%     aux1=find(alldata2(:,1)==datenum(2016,11,25,14,25,15));
%     aux2=find(alldata2(:,1)==datenum(2016,11,25,15,19,33));
%     if(length(aux1)~=1 || length(aux2)~=1)
%         disp('Problema na correcao do tempo')
%         stop
%     end
%     alldata2(aux1:1:aux2,1)=alldata2(aux1:1:aux2,1)+datenum(0,0,0,2,0,0);    
end
%
alldata=cat(1,alldata1,alldata2);
aux=sortrows(alldata,1); % sort data based on day of year
alldata=aux;
alldata(:,2)=aux(:,4); % invertendo a ordem dos comprimentos de onda: 450,525,635nm
alldata(:,4)=aux(:,2);
alldata(:,5)=aux(:,7);
alldata(:,7)=aux(:,5);
if (readprev)
%     iprev=find(prevdata.alldatang(:,1)<alldata(1,1));
%     alldata=cat(1,prevdata.alldatang(iprev,1:11),alldata);
end
%
% Obs: é comum a repetição de horários nos arquivos flexdata. Nada grave,
% dura alguns segundos por dia, com valores de espalhamento ligeiramente diferentes.
% Tem a ver com o fato de que o LabView loga os dados a cada segundo,
% enquanto que o neph mede a cada 5 segundos. Assim, vou dispensar a verificação de 
% dados repetidos aqui, e remover linhas com mesmo time stamp.
disp('----Checking for repeated data')
aux=find(diff(alldata(:,1))==0);
disp(['Número de linhas com timestamp repetido: ',num2str(length(aux))])
alldata(aux,:)=[];
clear aux
% [newdata,erro]=frepeated(alldata,2);
% if (strcmp(erro,'none')~=1) 
%     disp(erro)
% else
%     alldata=newdata;
% end
% clear aux erro 
%
disp('Calculating Angstrom')
ang=nan(length(alldata),1);
if(readprev)
   ang(iprev)=prevdata.alldatang(iprev,12); 
   istart=max(iprev)+1; 
else
    istart=1;
end
for i=istart:length(alldata)
    if(mod(i,100)==0),disp(i),end
    if(alldata(i,2)*alldata(i,3)*alldata(i,4) >0)
        aux=polyfit(log10(lambda),log10(alldata(i,2:4)),1);   % Angstrom
        ang(i,1)=-aux(1);
    end
end
%
alldatang=[alldata ang];
save([caminho3,tit,'_neph_level0.mat'],'alldatang','-mat')
% 
% Remove períodos de manutencao/contaminacao de acordo com o logbook
if(filtmanut)
%    dataorig=alldatang;
%    for i=1:size(manut,1)
%         aux=find(alldatang(:,1)>=manut(i,1) & alldatang(:,1)<=manut(i,2));
%         if(manut(i,3)==0)            
%             alldatang(aux,:)=[]; % remove maintanance periods from dataset
%         end    
%    end
%    save([caminho3,tit,'_neph_clean.mat',],'alldatang','-mat')
%    csvwrite([caminho3,tit,'_neph_clean.csv',],[alldatang,datevec(alldatang(:,1))])
%    figure,plot(dataorig(:,1),dataorig(:,2),'r.'),hold on,grid on
%    plot(alldatang(:,1),alldatang(:,2),'b.')
%    ylabel('scat450 (Mm^-^1)'),title(tit)
%    dynamicDateTicks      
end
%
% Basic plots --------------------------------------------------------
if(basicplots)
    figure,subplot(2,1,1)
    plot(alldata(:,1),alldata(:,2),'b.'),grid on, hold on
    plot(alldata(:,1),alldata(:,3),'g.')
    plot(alldata(:,1),alldata(:,4),'r.')
    ylabel('Scattering (Mm^-^1)'),hold off,axis tight
    %set(gca,'YLim',[0 prctile(alldata(:,2),99)])
    title([tit,'-Level0'])
    dynamicDateTicks
    subplot(2,1,2)
    plot(alldata(:,1),ang,'m.'),grid on, axis tight
    ylabel('Angstrom')
    %set(gca,'YLim',[-1 4])
    dynamicDateTicks
    saveas(gcf,strcat(caminho3,tit,'_neph_level0'),'jpg')
    %
    figure
    subplot(2,2,1), plot(alldata(:,1),alldata(:,8),'b.')
    grid on,ylabel('Pressure [mbar]'), axis tight
    %set(gca,'YLim',[850 1000])
    dynamicDateTicks
    subplot(2,2,2), plot(alldata(:,1),alldata(:,5),'k.')
    grid on,hold on,ylabel('Sample, Intel Temp [oC]'), axis tight
    %set(gca,'YLim',[10 50])
    dynamicDateTicks
    plot(alldata(:,1),alldata(:,6),'r.')
    hold off
    subplot(2,2,3), plot(alldata(:,1),alldata(:,7),'c.')
    grid on,ylabel('RH [%]')
    set(gca,'YLim',[20 40])
    dynamicDateTicks
    saveas(gcf,strcat(caminho3,tit,'_neph_diag'),'jpg')
end
%
% ------------ Level 1 ------------------------------------------------
% Level 1: 5-sec aerosol light scattering at 450nm must be within -10Mm-1 and 900 Mm-1. 
% Relative humidity must be smaller than 60%.
% Angstrom must be within -1 and 10.
% 
if(lev1)       
    origsize=size(alldata,1);
    orig=alldata;
    alldata(alldata(:,2)<=-10,2:size(alldata,2))=[]; % remove lines with scat450<=-10Mm-1
    alldata(alldata(:,2)>900,2:size(alldata,2))=[]; % remove lines with scat450>=900Mm-1
    alldata(alldata(:,7)>maxrh,2:size(alldata,2))=[]; % remove lines with rh>60%
    alldata(ang<=-1 | ang>=10,2:size(alldata,2))=[]; % remove lines with angstrom<-1 or angstrom>=10
    %
    % Additional periods to remove (specific for T1)
    rem=[datenum(2015,12,09,12,15,00) datenum(2015,12,09,23,00,00);...
    datenum(2015,12,11,04,00,00) datenum(2015,12,11,04,05,00);... % 
    datenum(2015,12,16,02,15,00) datenum(2015,12,16,02,17,00);... % 
    datenum(2015,12,19,04,27,00) datenum(2015,12,19,04,28,00);... % 
    datenum(2015,12,19,20,51,00) datenum(2015,12,19,23,00,00);... % 
    datenum(2015,12,19,23,58,00) datenum(2015,12,19,23,59,00);... % 
    datenum(2016,01,03,01,00,00) datenum(2016,01,03,01,03,00);... %
    datenum(2016,01,06,14,31,00) datenum(2016,01,06,18,06,00);... %
    datenum(2016,01,06,18,24,00) datenum(2016,01,06,18,26,00);... %
    datenum(2016,01,07,00,20,00) datenum(2016,01,07,00,35,00);... %
    datenum(2016,01,07,09,00,00) datenum(2016,01,07,10,12,00);... %
    datenum(2016,01,12,12,00,00) datenum(2016,01,12,12,38,00);... %
    datenum(2016,01,13,12,00,00) datenum(2016,01,13,12,40,00);... %
    datenum(2016,01,14,12,00,00) datenum(2016,01,14,12,40,00);... %
    datenum(2016,01,15,12,00,00) datenum(2016,01,15,12,40,00);... %
    datenum(2016,01,16,12,00,00) datenum(2016,01,16,12,40,00);... %
    datenum(2016,01,17,12,00,00) datenum(2016,01,17,12,40,00);... %
    datenum(2016,01,18,13,16,00) datenum(2016,01,18,13,17,00);... %
    datenum(2016,02,18,16,00,00) datenum(2016,02,18,16,50,00);... %
    datenum(2016,02,23,13,47,00) datenum(2016,02,23,13,48,00);... %
    datenum(2016,02,25,12,40,00) datenum(2016,02,25,12,41,00);... %
    datenum(2016,02,25,21,35,00) datenum(2016,02,25,21,36,00);... %
    datenum(2016,03,09,22,18,00) datenum(2016,03,09,22,20,00);... %
    datenum(2016,03,09,22,18,00) datenum(2016,03,09,22,20,00)]; %
    for i=1:length(rem)
        alldata(alldata(:,1)>=rem(i,1) & alldata(:,1)<=rem(i,2),:)=[];
    end
    alldata(alldata(:,2)>425,:)=[];
    %
    figure,plot(orig(:,1),orig(:,2),'-r.'),grid on, hold on
    plot(alldata(:,1),alldata(:,2),'b.')
    dynamicDateTicks
    %       
    % Save Level 1 data 
    Instrument='Nephelometer';
    Model='Aurora_Ecotech_2000';
    serial_num='090034';
    Site=tit;
    Val_level='1';
    Proc_vers='1.0';
    labels={'scat450';'scat525';'scat635';'RH'};
    units={'(Mm-1)';'(Mm-1)';'(Mm-1)';'(prct)'};
    export_LFA_GoAmazon_jan2015(labels,units,Instrument,Model,serial_num,Site,Val_level,Proc_vers,origsize,alldata(:,1),cat(2,alldata(:,2:4),alldata(:,7)))
end
%
% ------------ Level 2 ------------------------------------------------
% Level 2: Correct for truncation error according to Müller et al,2011b. 
% Apply STP corrections.
% Ansgstrom must be within -1 and 10.
if(lev2)        
    % Lê os arquivos Level 1
    aux=importdata('C:\A\GOAMAZON\T1\LFA_standard\T1_2015-2016_Nephelometer_Aurora_Ecotech_2000_Level1_5min.csv');
    level1_5min=cat(2,aux.data(:,1:2),aux.data(:,9),aux.data(:,16),aux.data(:,23));
    level1_5min(:,1)=level1_5min(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time
    origsize=sum(~isnan(level1_5min(:,2)));
    orig=level1_5min;
    tit='T1_2015-2016';
    lambda=[450;525;635];
    clear aux
    %
    % Calculate Angstrom B/G B/R G/R
    angstrom=NaN(length(level1_5min),3);
    level1_5min(level1_5min(:,2)<0,2:size(level1_5min,2))=NaN;
    level1_5min(level1_5min(:,3)<0,2:size(level1_5min,2))=NaN;
    level1_5min(level1_5min(:,4)<0,2:size(level1_5min,2))=NaN;
    for i=1:length(angstrom)
        if(mod(i,100)==0)
            disp(i)
        end
        if(~isnan(level1_5min(i,2)))
            angstrom(i,1)=-log10(level1_5min(i,2)./level1_5min(i,3))/log10(lambda(1)/lambda(2));
            angstrom(i,2)=-log10(level1_5min(i,2)./level1_5min(i,4))/log10(lambda(1)/lambda(3));
            angstrom(i,3)=-log10(level1_5min(i,3)./level1_5min(i,4))/log10(lambda(2)/lambda(3));
        end
    end
    angstrom(angstrom(:,2)<=-1 | angstrom(:,2)>=10,:)=NaN;
    %    
    % Lê fator stp
    C=importdata('C:\A\GOAMAZON\T1\LFA_standard\T1_2015-2016_AWS_Gill_Level2_5min.csv');
    stp=[C.data(:,1) C.data(:,10)];  
    stp(:,1)=stp(:,1)/(24*60*60)+datenum(1970,1,1); 
    if(length(stp)~=length(level1_5min))
        disp('check length of meteorological data file')
        stop
    end        
    %
    % STP and truncation error correction (Muller et al., 2011)
    trunc(:,1)=1.213-0.060*angstrom(:,1); % Muller et al. 2011 truncation correction at 450 nm (sub-um)
    trunc(:,2)=1.207-0.061*angstrom(:,2); % same for 525 nm
    trunc(:,3)=1.176-0.053*angstrom(:,3); % same for 635 nm
    trunc(trunc(:,1:3)<1)=1; % truncation correction factor should be >1.0    
    level1_5min(:,2)=level1_5min(:,2).*stp(:,2).*trunc(:,1); % corrected scat
    level1_5min(:,3)=level1_5min(:,3).*stp(:,2).*trunc(:,2);
    level1_5min(:,4)=level1_5min(:,4).*stp(:,2).*trunc(:,3);
    %
    % Calculate Angstrom by power law fit
    angstrom=nan(length(level1_5min),1);
    scat637=nan(length(level1_5min),1);
    for i=1:length(level1_5min)
        if (mod(i,100)==0)
            disp(i)
        end
        if(level1_5min(i,4)>0)
            p=polyfit(log10(lambda)',log10(level1_5min(i,2:4)),1);
            angstrom(i)=-p(1);
            scat637(i)=10^polyval(p,log10(637));
        end
    end
    %  
    figure
    plot(orig(:,1),orig(:,2),'r.'),grid on, hold on
    plot(level1_5min(:,1),level1_5min(:,2),'b.'),dynamicDateTicks
    figure
    plot(level1_5min(:,1),angstrom,'b.'),grid on,dynamicDateTicks
    
    % Save Level 2 data
    data=[level1_5min(:,2:4),scat637,angstrom,level1_5min(:,5)];
    Instrument='Nephelometer';
    Model='Aurora_Ecotech_2000';
    serial_num='090034';
    Site=tit;
    Val_level='2';
    Proc_vers='1.0';
    labels={'scat450';'scat525';'scat635';'scat637';'Angstrom(powerlawfit)';'RH'};
    units={'(Mm-1)';'(Mm-1)';'(Mm-1)';'(Mm-1)';'(adim)';'(prct)'};    
    export_LFA_GoAmazon_jan2015(labels,units,Instrument,Model,serial_num,Site,Val_level,Proc_vers,origsize,level1_5min(:,1),data)
end
%
% ------------ Level 3 ------------------------------------------------
% Level 3: SSA calculated with corrected Aeth abs data must be >0.1.
if(lev3)    
    % Lê os arquivos Level 2 que já salvou
    aux=importdata('C:\A\GOAMAZON\T1\LFA_standard\T1_2015-2016_Nephelometer_Aurora_Ecotech_2000_Level2_5min.csv');
    level2=aux.data;    
    level2(:,1)=level2(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time
    origsize=sum(~isnan(level2(:,2)));   
    scat637=level2(:,5);
    angstrom=level2(:,6);
    tit='T1_2015-2016';
    caminho3='C:\A\GOAMAZON\T1\AURORA2000_090034sn\';
    %
    C=importdata('C:\A\GOAMAZON\T1\LFA_standard\T1_2015-2016_BC_Aethalometer_AE33_Level2_5min.csv');  
    aeth=C.data;
    aeth(:,1)=aeth(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time (utc)    
    if (aeth(1,1)~=level2(1,1))
        disp('!!!!')
        stop
    end
    abs637=aeth(:,17);
    abs637(abs637<=0)=NaN;
    clear C aux
    %
    ssa=scat637./(scat637+abs637);
    %
    figure
    subplot(3,1,1),plot(level2(:,1),scat637,'b.'),grid on,ylabel('Scat637 (Mm^-^1)'),dynamicDateTicks
    set(gca,'XLim',[datenum(2015,12,08) datenum(2016,04,26)])
    subplot(3,1,2),plot(level2(:,1),abs637,'k.'),grid on,ylabel('Abs637 (Mm^-^1)'),dynamicDateTicks
    set(gca,'XLim',[datenum(2015,12,08) datenum(2016,04,26)])
    subplot(3,1,3),plot(level2(:,1),ssa,'r.'),grid on,ylabel('SSA637'),dynamicDateTicks
    set(gca,'XLim',[datenum(2015,12,08) datenum(2016,04,26)])
    saveas(gcf,strcat(caminho3,'timeseries_level3'),'jpg')    
    %
    rem1=find(ssa<0.1); 
    rem2=find(angstrom<=-1 | angstrom>=10);
    level2(rem1,2:size(level2,2))=NaN;
    level2(rem2,2:size(level2,2))=NaN;
    ssa(rem1)=NaN;
    ssa(rem2)=NaN;
    angstrom(rem1)=NaN;
    angstrom(rem2)=NaN;
    clear rem1 rem2
    % 
    % Save Level 3 data
    Instrument='Nephelometer';
    Model='Aurora_Ecotech_2000';
    serial_num='090034, 1/4" Cu line, cutoff PM2.5, Magee dryer, in series with AE33, 4LPM';
    Site=tit;
    Val_level='3';
    Proc_vers='1.0';
    labels={'scat450';'scat525';'scat635';'scat637';'Angstrom(powerlawfit)';'SSA637';'RH'};
    units={'(Mm-1)';'(Mm-1)';'(Mm-1)';'(Mm-1)';'(adim)';'(adim)';'(prct)'}; 
    level2=cat(2,level2(:,1:6),ssa,level2(:,7));
    export_LFA_GoAmazon_jan2015(labels,units,Instrument,Model,serial_num,Site,Val_level,Proc_vers,origsize,level2(:,1),level2(:,2:size(level2,2)))
end
%
% Verificação final
% aux=importdata('C:\A\Diadema2016\processados\LFA_standard\Diadema-2016_Nephelometer_Aurora_Ecotech_3000_Level1_5min.csv');
% level1_5min=aux.data;
% level1_5min(:,1)=level1_5min(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time
% aux=importdata('C:\A\Diadema2016\processados\LFA_standard\Diadema-2016_Nephelometer_Aurora_Ecotech_3000_Level2_5min.csv');
% level2_5min=aux.data;
% level2_5min(:,1)=level2_5min(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time
% figure, plot(level1_5min(:,1),level1_5min(:,2),'r.'),grid on, hold on,dynamicDateTicks
% plot(level2_5min(:,1),level2_5min(:,2),'b.'),ylabel('scat450')
% figure, plot(level1_5min(:,1),level1_5min(:,23),'r.'),grid on, hold on,dynamicDateTicks
% plot(level2_5min(:,1),level2_5min(:,5),'b.'),ylabel('bscat450')
% figure,plot(level1_5min(:,2),level2_5min(:,2),'b.'),grid on, ylabel('scat450 level2'),xlabel('scat450 level1')
% figure,plot(level1_5min(:,23),level2_5min(:,5),'c.'),grid on, ylabel('bscat450 level2'),xlabel('bscat450 level1')
% figure, plot(level2_5min(:,1),level2_5min(:,5)./level2_5min(:,2),'c.'),grid on, dynamicDateTicks,ylabel('bscatratio450')
% figure, plot(level2_5min(:,1),level2_5min(:,9),'g.'),grid on, dynamicDateTicks,ylabel('angstrom')
