% Aurora Nephelometer data processing - Diadema
% 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\Diadema2016\flex_data_files\nefaurora\csv\'; % arquivos flex (Labview)
caminho2='C:\A\Diadema2016\data_trailer_2016\neph_aurora\'; % arquivos do datalogger do instrumento
caminho3='C:\A\Diadema2016\processados\neph_aurora\';
tit='Diadema-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=true;
corrigirtempodatalogger=true;
readprev=true; % logical for reading previous processed data (Warning: if corrections are needed for the new data, then this reaprev should be set false)
filtmanut=1; % 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)
    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,11);
    disp('-----Reading flexdata files')
    for ifile=3:size(files,1)
        nome=getfield(files, {ifile,1}, 'name');
        aux1=strfind(nome,'aurora-')+7;
        aux2=strfind(nome,'.csv')-1;
        filedia=datenum(nome(aux1:aux2),'mm_dd_yyyy');
        if(filedia>=lerdaqui)                
            disp(nome)
            fid=fopen(strcat(caminho1,nome));
            C=cell(floor(getfield(files, {ifile,1}, 'bytes')/150),17);
            i=1;
            while (~feof(fid))
                C(i,:)=textscan(fid,'%*s%s%s%s%s%s %f%f%f%f%f%f%f%f%f%f %f%f',1,'Delimiter',',');
                i=i+1;
            end
            fclose(fid);
            %
            % removendo linhas com defeito
            rem=0;
            for j=6:17
                aux=find(cellfun(@isempty,C(:,j)));
                rem=cat(1,rem,aux);
            end
            rem(1)=[];
            C(rem,:)=[];
            %
            % removendo mais linhas com defeito
            aux=cell2mat(C(:,15:17));
            rem=0;
            rem=cat(1,rem,find(aux(:,1)<500));
            rem=cat(1,rem,find(aux(:,2)~=0));
            rem=cat(1,rem,find(aux(:,3)~=7));
            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:11)=cell2mat(C(:,6:15));
            for i=1:length(C)
                data_(i,1)=datenum(strcat(C{i,1},C{i,2},C{i,3}),'mm/dd/yyyyHH:MM:SSAM');
            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,11,26,18,31,00) & alldata1(:,1)<=datenum(2016,11,28,20,03,00));
    aux2=find(alldata1(:,1)>=datenum(2016,12,03,22,42,00) & alldata1(:,1)<=datenum(2016,12,05,19,03,00));
    aux3=find(alldata1(:,1)>=datenum(2016,12,10,21,18,00) & alldata1(:,1)<=datenum(2016,12,11,20,00,00));
    aux4=find(alldata1(:,1)>=datenum(2016,12,20,20,05,00) & alldata1(:,1)<=datenum(2016,12,22,14,15,00));
    aux5=find(alldata1(:,1)>=datenum(2017,01,01,00,00,00) & alldata1(:,1)<=datenum(2017,01,05,16,26,00));
    aux6=find(data1(:,1)>=datenum(2017,02,24,20,15,00) & data1(:,1)<=datenum(2017,02,25,21,15,00));
    aux7=find(data1(:,1)>=datenum(2017,02,27,21,35,00) & data1(:,1)<=datenum(2017,02,28,15,05,00));    
    aux8=find(data1(:,1)>=datenum(2017,03,02,21,45,00) & data1(:,1)<=datenum(2017,03,02,22,10,00));
    aux9=find(data1(:,1)>=datenum(2017,03,04,17,15,00) & data1(:,1)<=datenum(2017,03,06,11,59,00));
    aux10=find(data1(:,1)>=datenum(2017,03,06,14,29,00) & data1(:,1)<=datenum(2017,03,07,16,52,00));
    aux11=find(data1(:,1)>=datenum(2017,03,07,23,44,00) & data1(:,1)<=datenum(2017,03,09,21,43,00));    
    aux=alldata1; clear alldata1
    alldata1=aux(cat(1,aux1,aux2,aux3,aux4,aux5,aux6,aux7,aux8,aux9,aux10,aux11),:);
    clear aux1 aux2 aux3 aux4 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);
%opt1=fitoptions('Method','NonlinearLeastSquares','Startpoint',[1.5 10]);
%f1=fittype('-a1*x + b1','options',opt1);
if(readprev)
   ang(iprev)=prevdata.alldatang(iprev,12); 
   istart=max(iprev)+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)
        %[c,gof] = fit(lambda',log(alldata(i,2:4))',f1);
        %ang(i,1)=getfield(c,'a1');   % Angstrom
        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(3,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
    set(gca,'YLim',[0 prctile(alldata(:,2),99)])
    title([tit,'-Level0'])
    dynamicDateTicks
    subplot(3,1,2)
    plot(alldata(:,1),alldata(:,5),'b.'),grid on, hold on
    plot(alldata(:,1),alldata(:,6),'g.')
    plot(alldata(:,1),alldata(:,7),'r.')
    ylabel('BackScat (Mm^-^1)'),hold off
    set(gca,'YLim',[0 0.3*prctile(alldata(:,2),99)])
    dynamicDateTicks
    subplot(3,1,3)
    plot(alldata(:,1),ang,'m.'),grid on
    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(:,11),'b.')
    grid on,ylabel('Pressure [mbar]')
    set(gca,'YLim',[850 1000])
    dynamicDateTicks
    subplot(2,2,2), plot(alldata(:,1),alldata(:,8),'k.')
    grid on,hold on,ylabel('Sample, Intel Temp [oC]')
    set(gca,'YLim',[10 50])
    dynamicDateTicks
    plot(alldata(:,1),alldata(:,9),'r.')
    hold off
    subplot(2,2,3), plot(alldata(:,1),alldata(:,10),'c.')
    grid on,ylabel('RH [%]')
    set(gca,'YLim',[30 100])
    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%.
% Bscatratio must be within -1 and 2.
% Maintenance and local contamination periods removed based on field logbook.
if(lev1)       
    C=load('C:\A\Diadema2016\processados\neph_aurora\Diadema-2016_neph_clean.mat');
    alldata=C.alldatang;
    C=load('C:\A\Diadema2016\processados\neph_aurora\Diadema-2016_neph_level0.mat');
    alldata_level0=C.alldatang;
    tit='Diadema-2016';
    maxrh=60;
    %
    origsize=size(alldata_level0,1);
    orig=alldata;
    bsratio(:,1)=alldata(:,5)./alldata(:,2);
    bsratio(:,2)=alldata(:,6)./alldata(:,3);
    bsratio(:,3)=alldata(:,7)./alldata(:,4);
    alldata(alldata(:,2)<=-10,2:size(alldata,2))=NaN; % remove lines with scat450<=-10Mm-1
    alldata(alldata(:,2)>900,2:size(alldata,2))=NaN; % remove lines with scat450>=900Mm-1
    alldata(alldata(:,10)>maxrh,2:size(alldata,2))=NaN; % remove lines with rh>60%
    alldata(bsratio(:,1)<-1 | bsratio(:,1)>2,2:size(alldata,2))=NaN; % remove lines with bscat450 <-1 or >2
    alldata(bsratio(:,2)<-1 | bsratio(:,2)>2,2:size(alldata,2))=NaN; % remove lines with bscat525 <-1 or >2
    alldata(bsratio(:,3)<-1 | bsratio(:,3)>2,2:size(alldata,2))=NaN; % remove lines with bscat635 <-1 or >2
    %
    figure,plot(alldata_level0(:,1),alldata_level0(:,2),'r.'),grid on, hold on
    plot(alldata(:,1),alldata(:,2),'b.')
    dynamicDateTicks
    %   
    % Save Level 1 data 
    Instrument='Nephelometer';
    Model='Aurora_Ecotech_3000';
    serial_num='110191';
    Site=tit;
    Val_level='1';
    Proc_vers='1.0';
    labels={'scat450';'scat525';'scat635';'bscat450';'bscat525';'bscat635';'RH'};
    units={'(Mm-1)';'(Mm-1)';'(Mm-1)';'(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:7),alldata(:,10)))
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 que ja salvou
    aux=importdata('C:\A\Diadema2016\processados\LFA_standard\Diadema-2016_Nephelometer_Aurora_Ecotech_3000_Level1_5min.csv');
    level1_5min=cat(2,aux.data(:,1:2),aux.data(:,9),aux.data(:,16),aux.data(:,23),aux.data(:,30),aux.data(:,37),aux.data(:,44));
    level1_5min(:,1)=level1_5min(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time
    origsize=sum(~isnan(level1_5min(:,2)));
    tit='Diadema-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ê dados de meteorologia e calcula fator stp
    C=importdata('C:\A\Diadema2016\meteorologia_IAG\Diadema-2016_Meteo_5min.csv');
    met(:,1)=datenum(C.textdata(3:length(C.textdata)),'dd-mmm-yyyy HH:MM:SS ');
    met(:,2:3)=C.data;
    met(:,1)=met(:,1)+3/24; % local time to utc time
    met(:,3)=met(:,3)+273.15; % oC to K
    met(met(:,1)<level1_5min(1,1),:)=[];
    met(met(:,1)>level1_5min(length(level1_5min),1),:)=[];
    if(length(met)~=length(level1_5min))
        disp('check length of meteorological data file')
        stop
    end    
    pref=1013.25; tref=293.15;
    stp=(pref*met(:,3))./(tref*met(:,2));
    %
    % 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(:,4)=0.932; % backscatter correction 450 nm (sub-um)
    trunc(:,5)=0.935; % same for 525 nm
    trunc(:,6)=0.935; % same for 635 nm    
    trunc(trunc(:,1:3)<1)=1; % truncation correction factor should be >1.0    
    level1_5min(:,2)=level1_5min(:,2).*stp.*trunc(:,1); % corrected scat
    level1_5min(:,3)=level1_5min(:,3).*stp.*trunc(:,2);
    level1_5min(:,4)=level1_5min(:,4).*stp.*trunc(:,3);
    level1_5min(:,5)=level1_5min(:,5).*stp.*trunc(:,4);
    level1_5min(:,6)=level1_5min(:,6).*stp.*trunc(:,5);
    level1_5min(:,7)=level1_5min(:,7).*stp.*trunc(:,6);
    %
    % 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
    %   
    % Save Level 2 data
    data=[level1_5min(:,2:7),scat637,angstrom,level1_5min(:,8)];
    Instrument='Nephelometer';
    Model='Aurora_Ecotech_3000';
    serial_num='110191';
    Site=tit;
    Val_level='2';
    Proc_vers='1.0';
    labels={'scat450';'scat525';'scat635';'bscat450';'bscat525';'bscat635';'scat637';'Angstrom(powerlawfit)';'RH'};
    units={'(Mm-1)';'(Mm-1)';'(Mm-1)';'(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 MAAP BC data (MAC of 6.6 m2/g) must be >0.1.
% if(lev3)    
%     % Lê os arquivos Level 2 que já salvou
%     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
%     origsize=sum(~isnan(level2_5min(:,2)));   
%     scat637=level2_5min(:,8);
%     angstrom=level2_5min(:,9);
%     %
%     C=importdata('C:\A\Diadema2016\processados\LFA_standard\Diadema-2016_MAAP_5012_Level2_5min.csv');  
%     maap=C.data;
%     maap(:,1)=maap(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time (utc)
%     maap(:,2)=maap(:,2)*6.6/1000; % ng/m3 to Mm-1
%     if (maap(1,1)~=level2_5min(1,1))
%         disp('!!!!')
%         stop
%     end
%     maap(maap(:,2)<=0,2)=NaN;
%     clear C aux
%     %
%     ssa=scat637./(scat637+maap(:,2));
%     %
%     rem1=find(ssa<0.1); 
%     rem2=find(angstrom<=-1 | angstrom>=10);
%     level2_5min(rem1,2:size(level2_5min,2))=NaN;
%     level2_5min(rem2,2:size(level2_5min,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_3000';
%     serial_num='PM1 inlet installed on 04May2014; Data within 04May-31Dec2014 corrected using Mie calculations, and channel 635nm was out of order';
%     Site='T0a';
%     Val_level='3';
%     Proc_vers='1.0';
%     labels={'scat450';'scat525';'scat635';'Angstrom_powerlawfit';'SSA637'};
%     units={'(Mm-1)';'(Mm-1)';'(Mm-1)';'(prct)';'(adim)';'(adim)'};
%     data=cat(2,level2_5min(:,2:4),angstrom,ssa);
%     export_LFA_GoAmazon_jan2015(labels,units,Instrument,Model,serial_num,Site,Val_level,Proc_vers,origsize,level2_5min(:,1),data)
% 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')
