%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Written by Joel Brito - 14/Aug/2014                                  %
%                                                                     %
%This routine reads the TEOM ascii file and plots daily values of fine%
% and coarse particles for a quick look. It saves a .mat data.        %
%                                                                     %
%Latest changes:                                                      %
%To improve processing time now the routine reads the previous mat    %
%file (if existing) and imports only updated ascii files. The same is %
%valid for making new plots                                           %
%                                                                     %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


clear
clc
close all


%% INPUT PARAMETERS
Instrument='ACSM';
Model='Quad';
time_resolution='5min';
Site='T2';
Level='1';

%%Run the script and assimilates variables
[time_ACSM,X]=import_LFA_GoAmazon(Instrument,Model,Site,Level,time_resolution);

if min(size(X))>0
    Org=X(:,1);
    SO4=X(:,2);
    NO3=X(:,3);
    NH4=X(:,4);
    Chl=X(:,5);
end;



% Import the file
newData1 = importdata('0_Ascii-files\Level2\0_Meteo\T2_Meteo_5min.csv');
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
    assignin('base', vars{i}, newData1.(vars{i}));
end;

Temp=data(:,2);
Press=data(:,3);
time_Meteo=data(:,1)./(60*60*24)+datenum(1970,1,1);

Org=Org.*((Temp+273)./273).*(1013./Press);
SO4=SO4.*((Temp+273)./273).*(1013./Press);
NO3=NO3.*((Temp+273)./273).*(1013./Press);
NH4=NH4.*((Temp+273)./273).*(1013./Press);
Chl=Chl.*((Temp+273)./273).*(1013./Press);





%--------------------------------


Val_level='2';
Proc_vers='1.0';

labels{1}='Org';
labels{2}='SO4';
labels{3}='NO3';
labels{4}='NH4';
labels{5}='Chl';

units{1}='(ugm-3)';
units{2}='(ugm-3)';
units{3}='(ugm-3)';
units{4}='(ugm-3)';
units{5}='(ugm-3)';

serial_num='Not Avail';

export_LFA_GoAmazon(labels,units,Instrument,Model,serial_num,Site,Val_level,Proc_vers,max(size(time_ACSM)),time_ACSM,[Org,SO4,NO3,NH4,Chl])

eval(['save mat-files/Level',Val_level,'/',Instrument,'_',Model,'_',Val_level,'.mat'])

