%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%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
close all
clc

% Import the file
newData1 = importdata('0_Ascii-files\Level1\T2_WCPC_3787_Level1_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;

time_CPC=data(:,1)./(60*60*24)+datenum(1970,1,1);
CPC=data(:,2);

% 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);

CPC=CPC.*((Temp+273)./273).*(1013./Press);

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

orig_size=max(size(time_CPC));

%Exporting data
Instrument='WCPC';
Model='3787';
serial_num='N/A';
Site='T2';
Val_level='2';
Proc_vers='1.0';

labels{1}='Total concentration';

units{1}='(cm-3)';

export_LFA_GoAmazon(labels,units,Instrument,Model,serial_num,Site,Val_level,Proc_vers,orig_size,time_CPC,CPC)

mkdir mat-files/Level2

save mat-files/Level2/WCPC_3787_L2.mat