Commit 7f89f5d5 authored by Henrik Grythe's avatar Henrik Grythe
Browse files

bugfixes with temporary files

parent 8f1bb566
......@@ -28,9 +28,9 @@ end
fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factor_Model_group_HBEFA *\n')
fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factor_Model_group_HBEFA *\n')
fprintf('--- Grouping Vehicles according to ---\n--- Model SSB HBEFA merger specifications ---\n%s \n',input.files.SSB_Vehicle_dist)
fprintf('--- Grouping Vehicles according to ---\n')
fprintf('--- Model SSB HBEFA merger specifications')
fprintf('--- \n%s \n',input.files.SSB_Vehicle_dist)
T = readtable(input.files.SSB_Vehicle_dist,'Sheet','HBEFA778toMODEL');
Tm = readtable(input.files.SSB_Vehicle_dist,'Sheet','MODEL');
......@@ -40,147 +40,151 @@ fprintf('read Sheet : %s and Sheet %s\n','HBEFA778toMODEL','MODEL')
modelN = unique(T.ModelNumber);
fprintf('Found %i Model Vehicles \n',length(modelN))
% ConVfile = sprintf('%s/EFA_conversion.xlsx',tfold);
% Loop all components (comps) to do conversion for
for com =1:length(comps)
fprintf('<--- \nSpec| %s\n',char(comps(com)))
iEFfile = sprintf('%s/EFA_matrix41_RAW_%s.mat',tfold,char(comps(com)));
oEFfile = sprintf('%s/EFA_Table_MODEL_%s',tfold,char(comps(com)));
load(iEFfile);
D = size(EF_AVG);
fprintf('EF_AVG -- Dimensions\n')
for i=1:length(D)
fprintf('EF_AVG D%i : %i\n',i,D(i));
end
iEFfile = sprintf('%sEFA_matrix41_RAW_%s.mat',tfold,char(comps(com)));
oEFfile = sprintf('%sEFA_Table_MODEL_%s.mat',tfold,char(comps(com)));
ofile = 'modelHBEFA.xlsx';
% Tables are slow to work with and requires a lot of memory, but given
% the state of HBEFA, they offer good control of emission factors and
% what/where they are missing.
TFout = table;
% Loop all model vehicles
for mod = 1:length(modelN)
if (~input.options.do_preProcessing_HBEFA && input.options.use_temporary_files && exist(oEFfile))
fprintf('Using saved %s EFA_Table_MODEL file\n',char(comps(com)))
load(oEFfile)
else
% Make the subset of emissions/weights needed to calculate a model
% vehicle group.
Tsub = T(T.ModelNumber==modelN(mod),:);
% Make vehicles with HBEFA weight
EFsub = EF_AVG(Tsub.HBEFA_Num,:,:,:,:,:);
% check how many non-nan EF there are in each Vehicle.
Nef=[];
for i =1:size(EFsub,1)
Nef(i) = length(find(~isnan(EFsub(i,:,:,:,:,:,:))));
load(iEFfile);
D = size(EF_AVG);
fprintf('EF_AVG -- Dimensions\n')
for i=1:length(D)
fprintf('EF_AVG D%i : %i\n',i,D(i));
end
uef = unique(Nef);
% If there are only one amount (1440) of Emission factors
if length(uef) == 1
fprintf('MODEL Vehicle: %3i %-42s Found #%i EF',modelN(mod),char(Tm.Name(modelN(mod))),uef)
Tout = table;
k = 1;
for roa = 1:size(EF_AVG,2)
for spd = 1:size(EF_AVG,3)
for dec = 1:size(EF_AVG,4)
for cog = 1:size(EF_AVG,5)
for urb = 1:size(EF_AVG,6)
Trout = table;
if ~isnan(EFsub(1,roa,spd,dec,cog,urb))
Trout.Name = {sprintf('%s/%s-%i/%i%%/%s',char(roads.RoadEnv(urb)),char(roads.RoadType(roa)),roads.RoadSpeeds(spd),roads.RoadGradient(dec),char(roads.Congestion(cog)))};
%fprintf('%s/%s-%i/%i%%/%s\n',char(roads.RoadEnv(urb)),char(roads.RoadType(roa)),roads.RoadSpeeds(spd),roads.RoadGradient(dec),char(roads.Congestion(cog)))
Trout.Nr = k;
Trout.RoadNum = roa;
Trout.SpeedNum = spd;
Trout.DeclNum = dec;
Trout.CongNum = cog;
Trout.EnviNum = urb;
k = k+1;
Tout = [Tout;Trout];
% Tables are slow to work with and requires a lot of memory, but given
% the state of HBEFA, they offer good control of emission factors and
% what/where they are missing.
TFout = table;
% Loop all model vehicles
for mod = 1:length(modelN)
% Make the subset of emissions/weights needed to calculate a model
% vehicle group.
Tsub = T(T.ModelNumber==modelN(mod),:);
% Make vehicles with HBEFA weight
EFsub = EF_AVG(Tsub.HBEFA_Num,:,:,:,:,:);
% Check how many non-nan EF there are in each Vehicle.
Nef=[];
for i =1:size(EFsub,1)
Nef(i) = length(find(~isnan(EFsub(i,:,:,:,:,:,:))));
end
uef = unique(Nef);
% If there are only one amount (1440) of Emission factors
if length(uef) == 1
fprintf('MODEL Vehicle: %3i %-42s Found #%i EF',modelN(mod),char(Tm.Name(modelN(mod))),uef)
Tout = table;
k = 1;
for roa = 1:size(EF_AVG,2)
for spd = 1:size(EF_AVG,3)
for dec = 1:size(EF_AVG,4)
for cog = 1:size(EF_AVG,5)
for urb = 1:size(EF_AVG,6)
Trout = table;
if ~isnan(EFsub(1,roa,spd,dec,cog,urb))
Trout.Name = {sprintf('%s/%s-%i/%i%%/%s',char(roads.RoadEnv(urb)),char(roads.RoadType(roa)),roads.RoadSpeeds(spd),roads.RoadGradient(dec),char(roads.Congestion(cog)))};
%fprintf('%s/%s-%i/%i%%/%s\n',char(roads.RoadEnv(urb)),char(roads.RoadType(roa)),roads.RoadSpeeds(spd),roads.RoadGradient(dec),char(roads.Congestion(cog)))
Trout.Nr = k;
Trout.RoadNum = roa;
Trout.SpeedNum = spd;
Trout.DeclNum = dec;
Trout.CongNum = cog;
Trout.EnviNum = urb;
k = k+1;
Tout = [Tout;Trout];
end
end
end
end
end
end
end
EFac = nan(height(Tout),1);
Wght = nan(height(Tout),1);
for cond = 1:height(Tout)
for veh = 1:height(Tsub)
if veh == 1
switch Vehicle_weight
case 'Uniform'
EFac(cond) = EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.Uniform_Weight(veh);
Wght(cond) = Tsub.Uniform_Weight(veh);
case 'NERVE'
EFac(cond) = EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.NERVE_Weight(veh);
Wght(cond) = Tsub.NERVE_Weight(veh);
case 'HBEFA'
EFac(cond) = EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.HBEFA_Weight(veh);
Wght(cond) = Tsub.HBEFA_Weight(veh);
end
else
switch Vehicle_weight
case 'Uniform'
EFac(cond) = EFac(cond) + EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.Uniform_Weight(veh);
Wght(cond) = Wght(cond)+ Tsub.Uniform_Weight(veh);
case 'NERVE'
EFac(cond) = EFac(cond) + EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.NERVE_Weight(veh);
Wght(cond) = Wght(cond)+ Tsub.NERVE_Weight(veh);
case 'HBEFA'
EFac(cond) = EFac(cond) + EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.HBEFA_Weight(veh);
Wght(cond) = Wght(cond)+ Tsub.HBEFA_Weight(veh);
EFac = nan(height(Tout),1);
Wght = nan(height(Tout),1);
for cond = 1:height(Tout)
for veh = 1:height(Tsub)
if veh == 1
switch Vehicle_weight
case 'Uniform'
EFac(cond) = EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.Uniform_Weight(veh);
Wght(cond) = Tsub.Uniform_Weight(veh);
case 'NERVE'
EFac(cond) = EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.NERVE_Weight(veh);
Wght(cond) = Tsub.NERVE_Weight(veh);
case 'HBEFA'
EFac(cond) = EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.HBEFA_Weight(veh);
Wght(cond) = Tsub.HBEFA_Weight(veh);
end
else
switch Vehicle_weight
case 'Uniform'
EFac(cond) = EFac(cond) + EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.Uniform_Weight(veh);
Wght(cond) = Wght(cond)+ Tsub.Uniform_Weight(veh);
case 'NERVE'
EFac(cond) = EFac(cond) + EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.NERVE_Weight(veh);
Wght(cond) = Wght(cond)+ Tsub.NERVE_Weight(veh);
case 'HBEFA'
EFac(cond) = EFac(cond) + EFsub(veh,Tout.RoadNum(cond),Tout.SpeedNum(cond),Tout.DeclNum(cond),Tout.CongNum(cond),Tout.EnviNum(cond))*Tsub.HBEFA_Weight(veh);
Wght(cond) = Wght(cond)+ Tsub.HBEFA_Weight(veh);
end
end
end
end
end
if debug_mode
sprintf('%s_%sWeight',char(comps(com)),Vehicle_Weight)
fprintf(' %7.1f/%7.1f/%7.1f (mean/max/min) \n',mean(EFac./Wght),max(EFac./Wght),min(EFac./Wght))
fprintf(' %7.1f/%7.1f/%7.1f (mean/max/min) \n',mean(Wght),max(Wght),min(Wght))
if debug_mode
sprintf('%s_%sWeight',char(comps(com)),Vehicle_Weight)
fprintf(' %7.1f/%7.1f/%7.1f (mean/max/min) \n',mean(EFac./Wght),max(EFac./Wght),min(EFac./Wght))
fprintf(' %7.1f/%7.1f/%7.1f (mean/max/min) \n',mean(Wght),max(Wght),min(Wght))
else
fprintf('\n')
end
Tout.EFac = EFac./Wght;
Tout.Properties.VariableNames(find(ismember(Tout.Properties.VariableNames,{'EFac'}))) = Tm.Name(modelN(mod));
else
fprintf('\n')
end
Tout.EFac = EFac./Wght;
Tout.Properties.VariableNames(find(ismember(Tout.Properties.VariableNames,{'EFac'}))) = Tm.Name(modelN(mod));
else
% if this is the case, there are NaNs in the emission factor
% and we will get wrong results.
for i=1:length(uef)
fprintf('\n\n\n\n\n\n\n\n\n\n#### Found #%i EF\n',uef(i))
% if this is the case, there are NaNs in the emission factor
% and we will get wrong results.
for i=1:length(uef)
fprintf('\n\n\n\n\n\n\n\n\n\n#### Found #%i EF\n',uef(i))
end
end
end
if mod == 1
% Add the first part of the table as well
TFout = Tout;
else
% Concatonate only the column of the new vehicle data if the
% align.
[a,b,c] = intersect(TFout.Name,Tout.Name);
addCol = find(ismember(Tout.Properties.VariableNames,Tm.Name(modelN(mod))));
% Not 100% robust test!!!!?
if length(b)==length(c)
TFout = [TFout,Tout(:,addCol)];
if mod == 1
% Add the first part of the table as well
TFout = Tout;
else
fprintf('\n\n\n\n\n\n\n\n\n\n#### Found #%i & %i EF\n',a,b)
% Concatonate only the column of the new vehicle data if the
% align.
[a,b,c] = intersect(TFout.Name,Tout.Name);
addCol = find(ismember(Tout.Properties.VariableNames,Tm.Name(modelN(mod))));
% Not 100% robust test!!!!?
if length(b)==length(c)
TFout = [TFout,Tout(:,addCol)];
else
fprintf('\n\n\n\n\n\n\n\n\n\n#### Found #%i & %i EF\n',a,b)
end
end
end
EFrdCond = table2array(TFout(:,8:end));
save(oEFfile,'TFout','roads','EFrdCond')
fprintf('Saved an excel-file for Emission Factors Model:\n%s\n',oEFfile)
writetable(TFout,ofile,'Sheet',sprintf('%s_%s_Weight',char(comps(com)),Vehicle_weight))
fprintf('Saved an excel-file for Emission Factors Model:\n%s\n',ofile)
end
%__________________________________________________________________________
if input.options.Subtract_bio_from_CO2
switch char(comps(com))
case 'CO2'
fprintf('### ADD CALL TO: Emission_Factor_mix_in_biofuels()\n')
TFout = Emissions_Factor_Mix_in_biofuels(TFout);
end
end
%__________________________________________________________________________
switch char(comps(com))
case 'FC'
MunicpalHBEFA_RoadsEF_FC = TFout;
......@@ -232,10 +236,6 @@ for com =1:length(comps)
save(ofiles.MatlabOutput,'MunicpalHBEFA_RoadsEF_NH3','roads','-append');
end
writetable(TFout,'modelHBEFA.xlsx','Sheet',sprintf('%s_%s_Weight',char(comps(com)),Vehicle_weight))
fprintf('Saved a temp-file for Emission Factors Model:\n%s\n',oEFfile)
end
end
%--------------------------------------------------------------------------
% This file is part of NERVE
%
%
% NERVE is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation version 3.
%
%
% NERVE is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
%
% You should have received a copy of the GNU General Public License
% along with NERVE. If not, see <https://www.gnu.org/licenses/>.
%--------------------------------------------------------------------------
function Emission_Factors_OnRoadAllCond()
% Function for Road link calculations computes for each municipality an
% emission factor (EF) for Light, Heavy and Buses.
% This needs to be run for each component and each year.
global tfold Tyear SSB_Vehicle_dist comps Vehicle_dist Vehicle_weight
global debug_mode ofiles use_temporary_files
%--------------------------------------------------------------
% COMBINE Municipal VEHICLE DISTRIBUTION & EMISSION FACTORS
% This is an extremely slow loop
%--------------------------------------------------------------
global debug_mode ofiles use_temporary_files input
fprintf('---------------------------------------------------------------\n')
fprintf('in Emission_Factors_OnRoadAllCond *\n')
fprintf('---------------------------------------------------------------\n')
ofile = 'OnRoadEF_RoadClasses.xlsx';
end
TM = readtable(SSB_Vehicle_dist,'Sheet','MODEL');
LightVehiclesIdx = TM.ClassNum==1|TM.ClassNum==2;
......@@ -33,114 +33,149 @@ HeavyVehiclesIdx = TM.ClassNum==5|TM.ClassNum==6|TM.ClassNum==7;
VD = Vehicle_dist.Vdist;
% Loop all components to be calculated:
for com = 1:length(comps)
% Load the component file with
fprintf('<--- %s\n',char(comps(com)))
TFout = readtable('modelHBEFA.xlsx','Sheet',sprintf('%s_%s_Weight',char(comps(com)),Vehicle_weight),'PreserveVariableNames',1);
ofile = sprintf('OnRoadEF_RoadClasses_%s.xlsx',char(comps(com)));
osheet = sprintf('%s_%i',char(comps(com)),Tyear);
tmpfile = sprintf('%sEF_On_AllRoadCond_Municipality_%i_%s.mat',tfold,Tyear,char(comps(com)));
for i= 1:height(TM)
idef(i) = find(ismember(TFout.Properties.VariableNames,TM.Name(i)));
end
Trout = TFout(:,1:7);
for komm = 1: length(Vehicle_dist.D1_KommNr)
if use_temporary_files && exist(tmpfile)
fprintf('Has all necessary EF files for :%s \n',char(comps(com)))
else
if debug_mode
fprintf('Sum Weights: Komm: %04i@\n \tT:%f\n \tL:%f\n \tH:%f\n \tB:%f \n',...
Vehicle_dist.D1_KommNr(komm),sum(VD(komm,:)),...
sum(VD(komm,LightVehiclesIdx)),...
sum(VD(komm,HeavyVehiclesIdx)),...
sum(VD(komm,BusesVehiclesIdx)))
else
% fprintf('Komm:%04i;',Vehicle_dist.D1_KommNr(komm))
if rem(komm,15)==0;fprintf('@%03i/%3i \n',komm,length(Vehicle_dist.D1_KommNr)); end
oEFfile = sprintf('%sEFA_Table_MODEL_%s.mat',tfold,char(comps(com)));
load(oEFfile);
fprintf('Found Temporary HBEFA EF on file, \n------------------------\n')
if input.options.Subtract_bio_from_CO2
switch char(comps(com))
case 'CO2'
fprintf('### CO2 component: Factor in Biofuels \n')
TFout = Emissions_Factor_Mix_in_biofuels(TFout);
end
end
if abs(sum(VD(komm,:))-3)>1e-5
VD(komm,LightVehiclesIdx) = VD(komm,LightVehiclesIdx)/sum(VD(komm,LightVehiclesIdx));
VD(komm,HeavyVehiclesIdx) = VD(komm,HeavyVehiclesIdx)/sum(VD(komm,HeavyVehiclesIdx));
VD(komm,BusesVehiclesIdx) = VD(komm,BusesVehiclesIdx)/sum(VD(komm,BusesVehiclesIdx));
% Calculate an EF file that can be used on roads. Light / Heavy / Buses
% for all road types and all municpalities.
% It also saves a file that can be used in NERVE statistical output
for i= 1:height(TM)
idef(i) = find(ismember(TFout.Properties.VariableNames,TM.Name(i)));
end
Trout = TFout(:,1:7);
for komm = 1: length(Vehicle_dist.D1_KommNr)
if debug_mode
fprintf('\tNEW Sum Weights: Komm: %04i@\n \t\tT:%f NV:%i \n \t\tL:%f NV:%i \n \t\tH:%f NV:%i \n \t\tB:%f NV:%i \n',...
Vehicle_dist.D1_KommNr(komm),sum(VD(komm,:)),sum(Vehicle_dist.modelNV(komm,:)),...
sum(VD(komm,LightVehiclesIdx)),sum(Vehicle_dist.modelNV(komm,LightVehiclesIdx)),...
sum(VD(komm,HeavyVehiclesIdx)),sum(Vehicle_dist.modelNV(komm,HeavyVehiclesIdx)),...
sum(VD(komm,BusesVehiclesIdx)),sum(Vehicle_dist.modelNV(komm,BusesVehiclesIdx)))
fprintf('Sum Weights: Komm: %04i@\n \tT:%f\n \tL:%f\n \tH:%f\n \tB:%f \n',...
Vehicle_dist.D1_KommNr(komm),sum(VD(komm,:)),...
sum(VD(komm,LightVehiclesIdx)),...
sum(VD(komm,HeavyVehiclesIdx)),...
sum(VD(komm,BusesVehiclesIdx)))
else
% fprintf('Komm:%04i;',Vehicle_dist.D1_KommNr(komm))
if rem(komm,15)==0;fprintf('@%03i/%3i \n',komm,length(Vehicle_dist.D1_KommNr)); end
end
if abs(sum(VD(komm,:))-3)>1e-5
VD(komm,LightVehiclesIdx) = VD(komm,LightVehiclesIdx)/sum(VD(komm,LightVehiclesIdx));
VD(komm,HeavyVehiclesIdx) = VD(komm,HeavyVehiclesIdx)/sum(VD(komm,HeavyVehiclesIdx));
VD(komm,BusesVehiclesIdx) = VD(komm,BusesVehiclesIdx)/sum(VD(komm,BusesVehiclesIdx));
if debug_mode
fprintf('\tNEW Sum Weights: Komm: %04i@\n \t\tT:%f NV:%i \n \t\tL:%f NV:%i \n \t\tH:%f NV:%i \n \t\tB:%f NV:%i \n',...
Vehicle_dist.D1_KommNr(komm),sum(VD(komm,:)),sum(Vehicle_dist.modelNV(komm,:)),...
sum(VD(komm,LightVehiclesIdx)),sum(Vehicle_dist.modelNV(komm,LightVehiclesIdx)),...
sum(VD(komm,HeavyVehiclesIdx)),sum(Vehicle_dist.modelNV(komm,HeavyVehiclesIdx)),...
sum(VD(komm,BusesVehiclesIdx)),sum(Vehicle_dist.modelNV(komm,BusesVehiclesIdx)))
end
end
for i= 1:height(TFout)
EFs = VD(komm,:).*table2array(TFout(i,idef));
EFLight(i,1) = nansum(EFs(LightVehiclesIdx));
EFHeavy(i,1) = nansum(EFs(HeavyVehiclesIdx));
EFBuses(i,1) = nansum(EFs(BusesVehiclesIdx));
end
Trout.Light = EFLight;
Trout.Heavy = EFHeavy;
Trout.Buses = EFBuses;
Trout.Properties.VariableNames(find(ismember(Trout.Properties.VariableNames,'Light'))) = {sprintf('EF_Light_%04i',Vehicle_dist.D1_KommNr(komm))};
Trout.Properties.VariableNames(find(ismember(Trout.Properties.VariableNames,'Heavy'))) = {sprintf('EF_Heavy_%04i',Vehicle_dist.D1_KommNr(komm))};
Trout.Properties.VariableNames(find(ismember(Trout.Properties.VariableNames,'Buses'))) = {sprintf('EF_Buses_%04i',Vehicle_dist.D1_KommNr(komm))};
end
for i= 1:height(TFout)
EFs = VD(komm,:).*table2array(TFout(i,idef));
EFLight(i,1) = nansum(EFs(LightVehiclesIdx));
EFHeavy(i,1) = nansum(EFs(HeavyVehiclesIdx));
EFBuses(i,1) = nansum(EFs(BusesVehiclesIdx));
K_EF.distNames = Trout.Properties.VariableNames;
K_EF.traffSit = Trout.Name;
K_EF.TraffSitID = Trout(:,2:7);
idl = find(contains(Trout.Properties.VariableNames,'Light'));
idh = find(contains(Trout.Properties.VariableNames,'Heavy'));
idb = find(contains(Trout.Properties.VariableNames,'Buses'));
K_EF.TraffDataL = table2array(Trout(:,idl));
K_EF.TraffDataH = table2array(Trout(:,idl));
K_EF.TraffDataB = table2array(Trout(:,idl));
K_EF.kommNamesL = Trout.Properties.VariableNames(idl);
K_EF.kommNamesH = Trout.Properties.VariableNames(idh);
K_EF.kommNamesB = Trout.Properties.VariableNames(idb);
save(tmpfile,'K_EF')
fprintf('saved a tmp file \n%s\n',tmpfile)
writetable(Trout,ofile,'Sheet',osheet)
fprintf('Wrote Sheet: %s \n to file; %s\n',osheet,ofile)
fprintf('%s--- >\n',char(comps(com)))
% Use a switch for string as MatLab do not love variable names changes
% inside loops...
switch char(comps(com))
case 'FC'
OnRoadEF_RoadClasses_FC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC','-append');
case 'FC_MJ'
OnRoadEF_RoadClasses_FC_MJ = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC_MJ','-append');
case 'CH4'
OnRoadEF_RoadClasses_CH4 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CH4','-append');
case 'BC'
OnRoadEF_RoadClasses_BC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_BC','-append');
case 'PM'
OnRoadEF_RoadClasses_PM = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PM','-append');
case 'HC'
OnRoadEF_RoadClasses_HC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_HC','-append');
case 'CO'
OnRoadEF_RoadClasses_CO = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO','-append');
case 'NOx'
OnRoadEF_RoadClasses_NOx = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NOx','-append');
case 'Be'
OnRoadEF_RoadClasses_Be = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_Be','-append');
case 'NMHC'
OnRoadEF_RoadClasses_NMHC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NMHC','-append');
case 'NO2'
OnRoadEF_RoadClasses_NO2 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO2','-append');
case 'NO'
OnRoadEF_RoadClasses_NO = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO','-append');
case 'PN'
OnRoadEF_RoadClasses_PN = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PN','-append');
case 'CO2'
OnRoadEF_RoadClasses_CO2 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO2','-append');
case 'N2O'
OnRoadEF_RoadClasses_N2O = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_N2O','-append');
case 'NH3'
OnRoadEF_RoadClasses_NH3 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NH3','-append');
end
Trout.Light = EFLight;
Trout.Heavy = EFHeavy;
Trout.Buses = EFBuses;
Trout.Properties.VariableNames(find(ismember(Trout.Properties.VariableNames,'Light'))) = {sprintf('EF_Light_%04i',Vehicle_dist.D1_KommNr(komm))};
Trout.Properties.VariableNames(find(ismember(Trout.Properties.VariableNames,'Heavy'))) = {sprintf('EF_Heavy_%04i',Vehicle_dist.D1_KommNr(komm))};
Trout.Properties.VariableNames(find(ismember(Trout.Properties.VariableNames,'Buses'))) = {sprintf('EF_Buses_%04i',Vehicle_dist.D1_KommNr(komm))};
end
% Use a switch for string as MatLab do not love variable names changes
% inside loops...
switch char(comps(com))
case 'FC'
OnRoadEF_RoadClasses_FC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC','-append');
case 'FC_MJ'
OnRoadEF_RoadClasses_FC_MJ = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_FC_MJ','-append');
case 'CH4'
OnRoadEF_RoadClasses_CH4 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CH4','-append');
case 'BC'
OnRoadEF_RoadClasses_BC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_BC','-append');
case 'PM'
OnRoadEF_RoadClasses_PM = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_PM','-append');
case 'HC'
OnRoadEF_RoadClasses_HC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_HC','-append');
case 'CO'
OnRoadEF_RoadClasses_CO = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_CO','-append');
case 'NOx'
OnRoadEF_RoadClasses_NOx = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NOx','-append');
case 'Be'
OnRoadEF_RoadClasses_Be = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_Be','-append');
case 'NMHC'
OnRoadEF_RoadClasses_NMHC = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NMHC','-append');
case 'NO2'
OnRoadEF_RoadClasses_NO2 = Trout;
save(ofiles.MatlabOutput,'OnRoadEF_RoadClasses_NO2','-append');