UNITED STATES ENVIRONMENTAL PROTECTION AGENCY 

NATIONAL VEHICLE AND FUEL EMISSIONS LABORATORY 

2000 TRAVERWOOD ROAD 

ANN ARBOR, MI 48105-2498 

 OFFICE OF 

 AIR AND RADIATION 

August 2011 

MEMORANDUM

SUBJECT: Greenhouse gas Emission Model” (GEM) simulation tool, Version 2.0 

FROM: Houshun Zhang 

 Assessment and Standards Division 

 

TO: Docket EPA–HQ–OAR–2010–0162 

The attached document includes the source code for Version 2.0 of the Greenhouse gas Emission 

Model” (GEM) simulation tool. This model was developed to support the final rule adopting 

greenhouse gas emission standards for heavy-duty highway engines. 

In addition, a compact disk with the executable files for GEM has been placed in the docket for 

this rulemaking. 

Attachments 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 1 of 103

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Parameter Initialization for Ambient System

% - This file initializes model parameters of Ambient System for GEM.

%

% - Created by Lisandro Quinones

% - Edited by Byungho Lee

% - Edited by Houshun Zhang

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define Ambient Temperature

ambient.temperature = 25; % [C] 

%% Define Atmospheric Pressure

ambient.pressure = 101325; % [Pa]

%% Air gas constant

Rgas = 286.9; % [J/kg-k]

%% Define Ambient Air Density

ambient.air_density = ambient.pressure/Rgas/(ambient.temperature+273.15); 

 % [kg/m^3] 

%% Define Gravitational Acceleration

ambient.gravity = 9.80665; % [m/s^2]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Parameter Initialization for Driver System

% - This file initializes model parameters of Driver System for GEM.

%

% - Created by Byungho Lee

% - Modified by Houshun Zhang

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define PID Controller Gains

driver.proportional = 30.0;

driver.integral = 0.01; 

driver.derivative = 0.1;

%% Define Acceleration Test Parameters

% ... acceleration test flag (0=cycle / 1=acceleration)

driver.acl_test = 0;

% ... accelerator pedal during acceleration test
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 2 of 103

driver.acl_test_acl = 1;

% ... brake pedal during acceleration test

driver.acl_test_brk = 0;

%% Define Driver's Response

% ... accelerator pedal time constant (sec)

driver.acl_resp = 0.5;

% ... brake pedal time constant (sec)

driver.brk_resp = 0.5;

% ... speed time constants

driver.spd_resp = 0.3;

%% Define Ignition Key Parameters

% ... ignition key on position

driver.ign_key_on = [0 0;

 2*0.01 0;

 3*0.01 1;

 10000 1];

% ... ignition key start position

driver.ign_key_start_pos = [0 1;

 1 1;

 1+0.01 0;

 10000 0];

%% Driver Braking Map

driver_MaxBrkTq = 9000;

driver.axle.spd = [0 100];

driver.brk.pedal = [-1 0];

driver.brkTq.map = [driver_MaxBrkTq driver_MaxBrkTq; 0 0];

% ... engine torque map (Nm)

driver.brake.pedal = [-1.0 -0.6 -0.5 -0.4 -0.35 -0.3 -0.25 -0.05 0 ];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Parameter Initialization for Electrical System

% - This file initializes model parameters of Electrical System for GEM.

%

% - Created by Soduk Lee

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Denzo HD Class 8 Truck Starter Motor

electric.strt.inertia = 0;

electric.strt.off_volt = 6;

electric.strt.spd = [0, 500, 750, 1000, 1500, 2000, 2500, 3000]; % [RPM]

electric.strt.torq = [140, 85, 70, 48, 25, 10, 5, 0];

electric.strt.volt = [6.6, 7.7, 9, 10, 10.5, 11, 11.2, 12.0];

electric.strt.curr = [1300, 1100, 800, 500, 300, 250, 150, 0];

electric.strt.max_curr = electric.strt.curr(1);
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 3 of 103

% electric.strt.powr = [0.5, 4.5, 5, 4.2, 3.35, 2, 1.5, 0.5];

electric.strt.gratio = 4.15;

electric.ees.volt = 12.5;

%electric.acc.power = 360; % total accessory power [W]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Pre-Processing

% - Define enigne map for 200 HP / 7 L engine

%

% - Created by Lisandro Quinones on 8/17/2010

% - Edited by Byungho Lee on 8/20/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define General Engine Parameters

% ... desity of diesel fuel (kg/L)

engine.cyl.fuel_desity = 0.847;

% ... displacement volume (cc)

engine.cyl.disp_vol = 7000;

%% Define Wide-Open Throttle (WOT) Torque Table

% ... engine speed axis (RPM)

engine.cyl.wot_spd = [750 907 1055 1150 1300 1500 1600 1800 2000 2100 2226 2400 2550 

2600];

% ... engine torque map (Nm)

engine.cyl.wot_torq = [440 580 690 720 730 730 730 730 713 678 640 450 50 0];

%% Define Closed Throttle Torque Table

% ... engine speed axis (RPM)

engine.cyl.closed_spd = [600 700 965 1050 1100 1150 1200 1300 1400 1500 1600 1700 

1800 1900 2000 2100 2200 2600];

% ... engine torque map (Nm)

engine.cyl.closed_torq = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];

%engine.cyl.closed_torq = [0 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5];

% ... engine torque map calibration factor

engine.cyl.closed_torq_cal = 1.0;

%% Define Engine Fuel Map Axes

% ... redefine engine maximum and idle speed

engine.cyl.idle_spd = 750; % idle engine speed in RPM

engine.cyl.max_spd = max(engine.cyl.wot_spd)*rpm2rps;

engine.cyl.min_spd = engine.cyl.idle_spd*rpm2rps;% Define Engine Fuel Map Axes

% ... engine speed axis (RPM)

engine.cyl.fuel_spd = [600:100:2600];

% ... engine torque axis (Nm)
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 4 of 103

engine.cyl.fuel_torq = [0:100:1000];

% ... minimum fuel torque (Nm)

engine.cyl.fuel_min_torq = min(engine.cyl.fuel_torq);

%% Define Engine Fuel Map (kg/s)

% ... 2013, 2014, 2015, and 2016 vehicle models

if veh_year >= 2 || veh_year <= 5

% ... 2014 6.7 L - 200 hp

engine.cyl.fuel_map = [...

0.00014216 0.000487734 0.000840522 0.001209681 0.001602336 0.002017922 0.002455918 

0.00291502 0.003390309 0.003874774 0.004362322

0.000194276 0.000575228 0.000964964 0.001374152 0.001825012 0.002309888 0.002816684 

0.003333048 0.003850007 0.004362456 0.004871141

0.000239178 0.00066078 0.001091438 0.001546313 0.002047644 0.002602638 0.003181064 

0.003753169 0.004308786 0.004847127 0.005376877

0.000273003 0.000740469 0.001221301 0.001725697 0.002277767 0.002897209 0.003549298 

0.004173604 0.004759881 0.005322756 0.005880212

0.000304079 0.000820689 0.001356134 0.001914456 0.002520696 0.0031893 0.003902038 

0.004583198 0.005187052 0.005783406 0.006390421

0.000342832 0.000907826 0.001497511 0.002112874 0.002777147 0.003489748 0.004225678 

0.004945921 0.005570704 0.006235702 0.006922196

0.00038859 0.001000232 0.001643204 0.0023207 0.003048142 0.003807661 0.004569632 

0.005243889 0.005942889 0.00671509 0.007479569

0.000436041 0.001093935 0.001792115 0.002538039 0.003333641 0.0041468 0.004954793 

0.005744583 0.006490052 0.007259794 0.008045077

0.000487614 0.001194747 0.001945468 0.002754871 0.003611107 0.004477229 0.005339259 

0.006208178 0.007027614 0.007819393 0.008608977

0.000545294 0.001302922 0.002102704 0.002967052 0.003873887 0.004787637 0.005706452 

0.006647139 0.00752939 0.008350268 0.009145987

0.000608156 0.001410817 0.002262512 0.003183528 0.004144513 0.005110064 0.006075287 

0.007066423 0.007993367 0.008832071 0.009633022

0.000673053 0.001520011 0.002427004 0.003409407 0.004426804 0.005442451 0.006450106 

0.007488133 0.008418805 0.009255512 0.010072151

0.000743153 0.001635823 0.002596368 0.00363757 0.004714058 0.005781613 0.006840572 

0.007901427 0.008771813 0.009624037 0.010503197

0.000820686 0.001763018 0.002774096 0.003866625 0.004996103 0.00613593 0.007267762 

0.008194357 0.009021959 0.009994924 0.010986052

0.000911923 0.001906035 0.002970879 0.004113782 0.005283964 0.006499941 0.007706628 

0.008522601 0.009457551 0.010497479 0.011553671

0.00101605 0.002059115 0.003180041 0.004379518 0.005592041 0.006876387 0.008155681 

0.009065272 0.01009391 0.011151972 0.012220847

0.00112474 0.002208613 0.003380933 0.00464485 0.005925641 0.007280431 0.008665189 

0.009812654 0.010847258 0.01190622 0.01298611

0.001237315 0.002356942 0.003582637 0.004918402 0.006286789 0.007702766 0.009104223 

0.010389901 0.011562802 0.01270025 0.013837174

0.001358887 0.0025281 0.0038144 0.005215386 0.006660043 0.008113136 0.009539143 

0.010915569 0.0122264 0.013491582 0.014740826

0.001500338 0.002781121 0.004123819 0.005545179 0.007015814 0.008499776 0.009975212 

0.011433893 0.012866304 0.01427214 0.015664381

0.001682685 0.003052489 0.004449001 0.005888098 0.00736989 0.008881367 0.01041121 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 5 of 103

0.011953153 0.013501001 0.01504762 0.016591088

];

end

% ... 2017 and later vehicle models

if veh_year == 6

% ... 2017 6.7 L - 200 hp

engine.cyl.fuel_map = [...

0.000136782 0.000469283 0.000808726 0.00116392 0.001541721 0.001941585 0.002363012 

0.002804746 0.003262055 0.003728194 0.004197298

0.000186926 0.000553467 0.00092846 0.001322169 0.001755973 0.002222506 0.00271013 

0.00320696 0.003704363 0.004197427 0.004686868

0.00023013 0.000635783 0.00105015 0.001487817 0.001970182 0.002504181 0.003060726 

0.003611188 0.004145787 0.004663763 0.005173472

0.000262675 0.000712458 0.0011751 0.001660415 0.0021916 0.002787609 0.00341503 

0.004015719 0.004579817 0.005121399 0.005657767

0.000292576 0.000789643 0.001304832 0.001842033 0.00242534 0.00306865 0.003754426 

0.004409818 0.004990828 0.005564623 0.006148675

0.000329863 0.000873483 0.001440861 0.002032945 0.002672089 0.003357733 0.004065822 

0.004758819 0.005359967 0.005999809 0.006660333

0.000373889 0.000962394 0.001581043 0.002232909 0.002932832 0.003663619 0.004396765 

0.005045516 0.005718072 0.006461062 0.007196621

0.000419546 0.001052552 0.001724321 0.002442026 0.003207531 0.003989928 0.004767356 

0.005527269 0.006244536 0.00698516 0.007740736

0.000469168 0.001149551 0.001871872 0.002650656 0.003474501 0.004307858 0.005137277 

0.005973326 0.006761763 0.007523589 0.008283304

0.000524666 0.001253633 0.002023159 0.00285481 0.00372734 0.004606523 0.00549058 

0.006395681 0.007244557 0.008034381 0.008799999

0.00058515 0.001357447 0.002176922 0.003063096 0.003987729 0.004916753 0.005845462 

0.006799104 0.007690982 0.008497958 0.00926861

0.000647592 0.001462509 0.002335192 0.003280431 0.00425934 0.005236566 0.006206102 

0.007204861 0.008100326 0.008905381 0.009691127

0.00071504 0.001573941 0.002498148 0.003499963 0.004535728 0.005562897 0.006581797 

0.007602521 0.00843998 0.009259965 0.010105867

0.00078964 0.001696324 0.002669153 0.003720353 0.004807103 0.005903811 0.006992826 

0.007884369 0.008680663 0.009616822 0.010570456

0.000877426 0.00183393 0.002858492 0.00395816 0.005084075 0.006254052 0.00741509 

0.008200195 0.009099777 0.010100365 0.011116602

0.000977613 0.001981219 0.003059742 0.004213843 0.005380497 0.006616257 0.007847156 

0.008722338 0.009712063 0.010730098 0.011758539

0.001082192 0.002125062 0.003253034 0.004469138 0.005701477 0.007005016 0.008337389 

0.009441447 0.010436912 0.011455814 0.012494852

0.001190508 0.00226778 0.003447108 0.004732341 0.006048963 0.007411375 0.008759815 

0.009996857 0.011125388 0.012219807 0.013313721

0.001307481 0.002432464 0.003670103 0.00501809 0.006408097 0.00780622 0.009178282 

0.010502638 0.011763882 0.012981203 0.014183189

0.001443581 0.002675913 0.003967818 0.005335408 0.006750409 0.008178234 0.009597855 

0.011001355 0.012379578 0.013732233 0.015071805

0.00161903 0.002937015 0.004280698 0.005665354 0.007091091 0.008545389 0.010017359 

0.011500972 0.012990265 0.014478377 0.015963455

];
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 6 of 103

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Pre-Processing

% - Define enigne map for 270 HP / 7 L engine

%

% - Created by Lisandro Quinones on 8/17/2010

% - Edited by Byungho Lee on 8/20/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define General Engine Parameters

% ... desity of diesel fuel (kg/L)

engine.cyl.fuel_desity = 0.847;

% ... displacement volume (cc)

engine.cyl.disp_vol = 7000;

%% Define Wide-Open Throttle (WOT) Torque Table

% ... engine speed axis (RPM)

engine.cyl.wot_spd = [750 907 1055 1208 1358 1507 1660 1809 1954 2105 2258 2405 2556 

2600];

% ... engine torque map (Nm)

engine.cyl.wot_torq = [470 579 721 850 876 866 870 868 869 878 850 800 734 0];

%% Define Closed Throttle Torque Table

% ... engine speed axis (RPM)

engine.cyl.closed_spd = [600 700 965 1050 1100 1150 1200 1300 1400 1500 1600 1700 

1800 1900 2000 2100 2200 2600];

% ... engine torque map (Nm)

engine.cyl.closed_torq = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];

%engine.cyl.closed_torq = [0 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5];

% ... engine torque map calibration factor

engine.cyl.closed_torq_cal = 1.0;

%% Define Engine Fuel Map Axes

% ... engine speed axis (RPM)

engine.cyl.fuel_spd = [600:100:2600];

% ... engine torque axis (Nm)

engine.cyl.fuel_torq = [0:100:1000];

% ... minimum fuel torque (Nm)

engine.cyl.fuel_min_torq = min(engine.cyl.fuel_torq);

%% Define Engine Fuel Map (kg/s)

% ... 2013, 2014, 2015, and 2016 vehicle models

if veh_year >= 2 || veh_year <= 5

% ... 2014 6.7 L - 270 hp
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 7 of 103

engine.cyl.fuel_map = [...

0.000142467 0.000487517 0.000838166 0.001199221 0.00157075 0.001945109 0.002327951 

0.002725008 0.003142159 0.003577827 0.00402301

0.000193535 0.000570786 0.000957213 0.00136179 0.001806059 0.002250766 0.00270094 

0.00315977 0.003627278 0.004097652 0.004567472

0.000239003 0.000654851 0.001080996 0.001532071 0.002028071 0.002556347 0.003073778 

0.003601991 0.00411982 0.004617992 0.005102419

0.000271376 0.000733209 0.001209821 0.001709484 0.002259217 0.002863616 0.003449478 

0.004064964 0.004624817 0.005135388 0.005618887

0.000301716 0.000812183 0.00134361 0.001895898 0.00249748 0.003162565 0.003873843 

0.004550094 0.005132113 0.005638548 0.006121661

0.000340664 0.00089837 0.001483806 0.002092018 0.00275001 0.00345897 0.00420029 

0.004967177 0.005615694 0.006111315 0.006642597

0.000386848 0.000989947 0.001627835 0.002297436 0.003017754 0.003771538 0.004545395 

0.005316453 0.006015923 0.006566478 0.007236871

0.000434116 0.001082228 0.001774677 0.002512932 0.003301131 0.004111969 0.004924235 

0.005712592 0.006501714 0.007241045 0.007924

0.000485236 0.001182113 0.001925979 0.002728037 0.003576289 0.00444098 0.005304989 

0.006149405 0.00699826 0.00782507 0.00860366

0.000542403 0.001289849 0.002081334 0.002938071 0.003836319 0.004747886 0.005667765 

0.006584339 0.007505547 0.008387569 0.009231903

0.000605334 0.001396318 0.002239316 0.003152488 0.004104103 0.005068025 0.006033705 

0.006997559 0.007969593 0.008892477 0.009812999

0.000670061 0.001503812 0.002402194 0.003376923 0.004383491 0.005397424 0.006402846 

0.007411536 0.008422059 0.009393001 0.010388908

0.000739992 0.001618113 0.002569868 0.003603312 0.004668463 0.005730587 0.006785918 

0.007850437 0.008902516 0.009950859 0.011003954

0.000816553 0.00174377 0.002745327 0.003830179 0.004948091 0.006073938 0.007221896 

0.008344265 0.009448201 0.010575147 0.011677491

0.000907053 0.001885221 0.002940389 0.004076636 0.005232952 0.006428507 0.007678683 

0.008867543 0.010023433 0.011211907 0.012424123

0.001011027 0.002036965 0.003148456 0.004342375 0.005537757 0.006803593 0.008142828 

0.009404257 0.010619607 0.011880832 0.013283058

0.001119322 0.002185263 0.003347397 0.00460506 0.005868651 0.007210506 0.008624823 

0.009957659 0.011302923 0.012791481 0.014269759

0.001231821 0.002332593 0.003547986 0.004874997 0.006223879 0.0076372 0.009118767 

0.010534528 0.012040003 0.01372273 0.015258688

0.001352363 0.002494835 0.003769478 0.005161506 0.006590838 0.008072981 0.00962508 

0.011142996 0.012676339 0.01441923 0.016134587

0.001485469 0.002702296 0.004015461 0.005438693 0.006938408 0.008496971 0.010102523 

0.011727721 0.013389701 0.015141049 0.016928968

0.001673028 0.00289106 0.004250035 0.005719191 0.007279175 0.008907321 0.01058777 

0.0123183 0.014088883 0.015883642 0.017700874

];

end

% ... 2017 and later vehicle models

if veh_year == 6

% ... 2017 6.7 L - 270 hp

engine.cyl.fuel_map = [...

0.000137086 0.000469104 0.000806511 0.00115393 0.001511427 0.001871647 0.002240031 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 8 of 103

0.002622092 0.003023488 0.003442702 0.003871072

0.000186226 0.000549229 0.000921062 0.001310359 0.001737849 0.00216576 0.002598933 

0.003040434 0.003490285 0.003942895 0.004394971

0.000229976 0.000630119 0.001040169 0.001474208 0.001951476 0.0024598 0.00295769 

0.003465953 0.003964226 0.004443583 0.004909714

0.000261127 0.000705517 0.001164129 0.001644922 0.002173893 0.002755465 0.0033192 

0.003911441 0.00445015 0.004941438 0.005406677

0.000290321 0.000781509 0.001292866 0.001824295 0.002403157 0.003043124 0.003727539 

0.004378249 0.004938287 0.005425595 0.005890462

0.000327798 0.000864441 0.001427766 0.002013008 0.002646149 0.003328334 0.004041656 

0.00477958 0.005403604 0.005880507 0.006391724

0.000372238 0.00095256 0.001566356 0.002210668 0.002903782 0.003629097 0.004373728 

0.005115664 0.005788718 0.00631848 0.006963554

0.00041772 0.001041355 0.001707652 0.002418025 0.003176457 0.003956671 0.00473826 

0.005496843 0.006256162 0.00696757 0.007624732

0.00046691 0.001137468 0.00185324 0.002625006 0.003441222 0.004273256 0.005104634 

0.005917158 0.006733955 0.007529538 0.008278723

0.000521917 0.001241135 0.002002728 0.002827108 0.003691431 0.004568571 0.005453708 

0.006335667 0.007222083 0.008070793 0.008883239

0.000582472 0.001343582 0.002154743 0.003033427 0.003949102 0.00487662 0.005805828 

0.00673328 0.007668603 0.008556632 0.009442388

0.000644755 0.001447017 0.00231147 0.003249386 0.004217938 0.005193578 0.006161028 

0.007131622 0.008103981 0.009038252 0.009996547

0.000712045 0.001557001 0.002472811 0.003467225 0.004492148 0.005514158 0.006529632 

0.007553947 0.008566292 0.009575042 0.010588364

0.000785714 0.001677913 0.002641644 0.003685524 0.004761215 0.005844542 0.006949145 

0.008029124 0.009091368 0.010175752 0.011236463

0.000872796 0.001814021 0.002829339 0.003922672 0.005035317 0.00618572 0.00738868 

0.00853264 0.009644875 0.010788464 0.011954898

0.000972843 0.001960035 0.003029547 0.004178375 0.005328611 0.006546639 0.007835295 

0.009049084 0.010218533 0.011432125 0.012781393

0.001077048 0.002102731 0.003220975 0.004431139 0.005647008 0.006938185 0.008299086 

0.009581585 0.010876042 0.012308381 0.013730828

0.001185299 0.002244497 0.003413988 0.004690881 0.00598882 0.007348763 0.008774375 

0.010136667 0.011585285 0.013204459 0.014682408

0.001301288 0.002400611 0.003627115 0.00496657 0.006341919 0.007768087 0.009261567 

0.010722155 0.012197588 0.013874654 0.015525227

0.001429367 0.002600237 0.003863808 0.005233288 0.006676363 0.008176063 0.009720978 

0.011284796 0.012884008 0.014569212 0.016289606

0.001609842 0.002781872 0.004089523 0.005503193 0.00700426 0.008570916 0.010187899 

0.01185307 0.013556784 0.015283759 0.01703236

];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Pre-Processing

% - Define enigne map for 350 HP / 11 L engine

%

% - Created by Lisandro Quinones on 8/17/2010

% - Edited by Byungho Lee on 8/20/2010

% - Edited by Lisandro Quinones on 5/23/2011
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 9 of 103

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define General Engine Parameters

% ... desity of diesel fuel (kg/L)

engine.cyl.fuel_desity = 0.847;

% ... displacement volume (cc)

engine.cyl.disp_vol = 11000;

%% Define Wide-Open Throttle (WOT) Torque Table

% ... engine speed axis (RPM)

engine.cyl.wot_spd = [600 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 

2000 2100 2200];

% ... engine torque map (Nm)

engine.cyl.wot_torq = [949.074 1071.0978 1220.238 1586.3094 1626.984 1626.984 1626.984 

1626.984 1626.984 1559.193 1466.99724 1387.00386 1247.3544 1084.656 813.492 0];

%% Define Closed Throttle Torque Table

% ... engine speed axis (RPM)

engine.cyl.closed_spd = [600 700 965 1050 1100 1150 1200 1300 1400 1500 1600 1700 

1800 1900 2000 2100 2200 2300];

% ... engine torque map (Nm)

%engine.cyl.closed_torq = [0 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5];

engine.cyl.closed_torq = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];

% ... engine torque map calibration factor

engine.cyl.closed_torq_cal = 1.0;

%% Define Engine Fuel Map Axes

% ... engine speed axis (RPM)

engine.cyl.fuel_spd = [600:100:2200];

% ... engine torque axis (Nm)

engine.cyl.fuel_torq = [0:100:3000];

% ... minimum fuel torque (Nm)

engine.cyl.fuel_min_torq = min(engine.cyl.fuel_torq);

%% Define Engine Fuel Map (kg/s)

% ... 2013, 2014, 2015, and 2016 vehicle models

if veh_year >= 2 || veh_year <= 5

% ... 2014 10.8 L - 350 hp

engine.cyl.fuel_map = [...

2.74E-04 0.000699211 0.001085538 0.00135243 0.001609069 0.001974042 0.002364936 

0.002708857 0.003077934 0.003545854 0.003951549 0.004309832 0.004672199 0.005104391 

0.005604629 0.006148532 0.006724894 0.007343455 0.008027287 0.008800157 0.009672274 

0.010635637 0.011670037 0.012752247 0.013862459 0.014986685 0.016116495 0.017247686 

0.018378861 0.019510231 0.020642687

0.000433995 0.000926129 0.001358744 0.001652726 0.001924054 0.002312771 0.002720805 

0.003078409 0.003449679 0.003920657 0.004351302 0.00467622 0.005126094 0.005634132 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 10 of 103

0.006158685 0.006720783 0.007343819 0.008045329 0.00884156 0.009733517 0.010704439 

0.011731516 0.012795462 0.013882843 0.014984775 0.01609536 0.017210765 0.018328738 

0.019448234 0.020569044 0.021691417

0.000531257 0.001098877 0.001610737 0.001942495 0.002243008 0.002641426 0.003063704 

0.003444312 0.003828574 0.004293945 0.004713265 0.005027659 0.005647401 0.006187101 

0.00670052 0.007273301 0.007950955 0.008748447 0.009671686 0.010687622 0.011751454 

0.012833077 0.013920131 0.015010248 0.01610413 0.017202362 0.018304761 0.019410677 

0.020519401 0.021630399 0.022743373

0.000644784 0.001269045 0.001826823 0.002186438 0.002511905 0.002923562 0.003398013 

0.003782137 0.004233658 0.004758746 0.00522491 0.005646838 0.006278894 0.006723564 

0.007214609 0.007790768 0.008533982 0.009467189 0.010548875 0.011686529 0.012821726 

0.013937193 0.015035838 0.0161255 0.017212811 0.018301846 0.019394467 0.020491066 

0.02159125 0.022694339 0.02379969

0.000757038 0.001412276 0.001999555 0.002367581 0.002698211 0.003115382 0.003578131 

0.004035345 0.004540037 0.005121271 0.005550411 0.006072522 0.006624128 0.007171844 

0.007725679 0.008288413 0.009089535 0.01025493 0.01151603 0.012739452 0.013905751 

0.015030611 0.016131213 0.017219684 0.018303831 0.019388397 0.020475905 0.021567284 

0.022662434 0.023760726 0.024861407

0.000857926 0.001519129 0.002108027 0.002510864 0.002851965 0.003304128 0.003777577 

0.004298489 0.004801757 0.005409378 0.005893805 0.006495279 0.00705509 0.007655713 

0.008215335 0.008840743 0.009678712 0.011216126 0.012581785 0.013814231 0.014973688 

0.016095066 0.017196036 0.0182864 0.019372371 0.020458038 0.02154586 0.02263698 

0.023731565 0.024829181 0.025929171

0.001009177 0.001677137 0.002278984 0.002696817 0.003074854 0.003587934 0.004150565 

0.004689699 0.005271163 0.005919833 0.006472017 0.007074395 0.007706561 0.008306315 

0.008937815 0.009627011 0.010694592 0.01231945 0.013640396 0.01484339 0.015994135 

0.017117317 0.01822439 0.019322283 0.02041581 0.021508351 0.022602115 0.023698316 

0.024797363 0.025899102 0.027003105

0.001191887 0.001873987 0.002494612 0.002954575 0.003381767 0.003950155 0.004558212 

0.00514158 0.005764192 0.006485944 0.007099324 0.007726319 0.008393383 0.009066078 

0.009747451 0.010487451 0.011583431 0.013228699 0.014564326 0.015784827 0.016952994 

0.018092029 0.019213946 0.020326083 0.021433131 0.022538207 0.023643404 0.024750032 

0.025858753 0.026969731 0.028082828

0.001410625 0.002119604 0.002783469 0.003278995 0.003786607 0.00436503 0.005025063 

0.00563034 0.006305901 0.007080381 0.007732181 0.008407177 0.009155757 0.009916229 

0.010698916 0.011404559 0.012366919 0.013929624 0.015346819 0.016637714 0.017849525 

0.019018447 0.020164513 0.021297983 0.022424476 0.023547457 0.024669249 0.025791413 

0.026914918 0.028040255 0.029167575

0.001623584 0.002369479 0.003047453 0.003616061 0.00412478 0.004774645 0.005430598 

0.006137661 0.006821162 0.007605646 0.008345464 0.009132944 0.009889725 0.010798942 

0.011656723 0.012466347 0.013261326 0.014690806 0.016113875 0.017441213 0.018694346 

0.019900585 0.021078589 0.022239761 0.023391016 0.024536726 0.025679802 0.026822229 

0.027965329 0.029109908 0.030256379

0.001827752 0.002669353 0.003438737 0.004031542 0.004637984 0.005270984 0.006012826 

0.006743069 0.007599393 0.008430707 0.009215425 0.010030656 0.010929135 0.01176636 

0.012720148 0.01375368 0.014715205 0.01574348 0.016964193 0.018245958 0.019514502 

0.020752375 0.021963401 0.023155395 0.024335087 0.025507404 0.02667581 0.027842718 

0.029009785 0.030178086 0.031348245

0.001884086 0.002861186 0.003774737 0.004438118 0.005077086 0.005767986 0.006544495 

0.007328475 0.008224113 0.009229053 0.010089496 0.010964784 0.011853967 0.012662602 

0.013653651 0.014733811 0.015747137 0.016764926 0.017885718 0.019097187 0.020345991 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 11 of 103

0.0215952 0.022830781 0.024051475 0.025260527 0.026461831 0.027658694 0.028853634 

0.030048473 0.031244449 0.03244231

0.001981317 0.003100501 0.004087648 0.004925161 0.005496357 0.006383638 0.00710435 

0.008064431 0.008802917 0.009877622 0.010833013 0.011994224 0.012658776 0.013547989 

0.014206653 0.015408791 0.016577216 0.017686581 0.018808572 0.019983197 0.021203665 

0.022446617 0.023693777 0.024936488 0.026172702 0.027403436 0.028630655 0.029856318 

0.031082042 0.032309008 0.033537966

0.002381719 0.003710726 0.004930226 0.005731147 0.006565192 0.00734957 0.008425992 

0.009229806 0.010412048 0.011649885 0.012681859 0.013268982 0.014561392 0.01484133 

0.015341296 0.016278022 0.017399413 0.01855076 0.019703452 0.020875552 0.022079395 

0.023311462 0.024561025 0.025818359 0.027077637 0.028336488 0.029594629 0.030852713 

0.032111634 0.033372187 0.034634934

0.002703621 0.004167826 0.005484476 0.006374007 0.007151673 0.008007474 0.008949935 

0.010074434 0.01122473 0.012389427 0.013351389 0.013537443 0.014859499 0.015729362 

0.016442048 0.017288266 0.018311241 0.019431896 0.020587831 0.021762176 0.022959812 

0.024184903 0.02543458 0.026702007 0.027980472 0.029265305 0.030553931 0.031845223 

0.03313884 0.034434809 0.035733283

0.002973482 0.004488162 0.005879117 0.006899037 0.007689692 0.00860091 0.009579162 

0.010817587 0.012041955 0.013018295 0.013802729 0.014422298 0.015386972 0.016415991 

0.017359303 0.018287358 0.019283661 0.020357835 0.021484993 0.022646801 0.023838657 

0.025061033 0.026312575 0.027588909 0.028884295 0.030193311 0.031511675 0.032836374 

0.034165494 0.035497979 0.036833372

0.0036127 0.005116357 0.006472471 0.007472318 0.008348874 0.00928773 0.010356304 

0.011532946 0.012651915 0.013578148 0.014386068 0.015220647 0.016095634 0.017112405 

0.018191625 0.019244829 0.020270328 0.021310608 0.02239642 0.02353386 0.024716661 

0.025937854 0.027192973 0.028478486 0.029790094 0.031122505 0.032470202 0.033828348 

0.035193322 0.036562825 0.03793569

];

end

% ... 2017 and later vehicle models

if veh_year == 6

% ... 2017 10.8 L - 350 hp

engine.cyl.fuel_map = [...

2.74E-04 0.000695447 0.001077212 0.001339129 0.00159004 0.001947113 0.002328681 

0.002662879 0.003020518 0.003473414 0.003863378 0.004205209 0.004549535 0.0049606 

0.005436785 0.005954685 0.006503791 0.007093759 0.007746899 0.00848593 0.009320324 

0.010241929 0.011230861 0.012264424 0.013323321 0.014393962 0.015468185 0.016541958 

0.017613978 0.018684509 0.019754465

0.000432802 0.000921687 0.001349424 0.00163797 0.001902887 0.002282497 0.002679396 

0.003024788 0.003381737 0.003834317 0.004245391 0.004551931 0.004979098 0.005461805 

0.005959852 0.006493832 0.007086389 0.007754286 0.008512867 0.009362693 0.010287228 

0.011264204 0.012274836 0.013306045 0.014349184 0.015398525 0.016450361 0.017502535 

0.018554069 0.019604801 0.020655004

0.000529932 0.001094233 0.001601031 0.00192701 0.002220299 0.002608397 0.00301742 

0.003382681 0.003749004 0.004192338 0.004588813 0.004882353 0.005471787 0.005983029 

0.006468743 0.007011659 0.00765521 0.008413164 0.009290515 0.010254907 0.011262967 

0.012285676 0.013311166 0.014337175 0.015364373 0.016393303 0.017423774 0.018455154 

0.01948677 0.020518121 0.021548937

0.000643286 0.001264354 0.001817427 0.002171351 0.002488974 0.002888916 0.003346999 

0.003712313 0.00414055 0.004637835 0.005075841 0.005470438 0.006068607 0.006486063 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 12 of 103

0.006948984 0.007493999 0.008198863 0.009084392 0.010109639 0.011185259 0.012255172 

0.013303016 0.014331791 0.015349143 0.016361483 0.017372719 0.018384618 0.019397534 

0.020411072 0.021424572 0.022437414

0.000755364 0.001407736 0.00199115 0.00235411 0.002676698 0.003080716 0.003524477 

0.003957795 0.004433752 0.004981505 0.005380058 0.005868866 0.006386969 0.006902586 

0.007425113 0.0079562 0.008714603 0.009819029 0.011010714 0.012161817 0.013254165 

0.014303211 0.0153257 0.016333407 0.01733388 0.018331672 0.019329178 0.020327254 

0.021325772 0.022324101 0.0233215

0.000856143 0.001515153 0.002101119 0.002499675 0.002832885 0.003269672 0.003720312 

0.004211463 0.004681188 0.005250941 0.005700558 0.006263604 0.006787512 0.007352979 

0.007880222 0.00847006 0.009261075 0.01071608 0.012000756 0.013152944 0.014230971 

0.01526865 0.016283132 0.017283934 0.018277075 0.019266486 0.020254504 0.021242187 

0.02222965 0.023216437 0.024201887

0.001007052 0.001673308 0.002272943 0.002687268 0.003057815 0.003551916 0.004085705 

0.004588772 0.00512862 0.005734589 0.006247614 0.006809639 0.007400774 0.007964349 

0.008558521 0.009206347 0.010212673 0.011743464 0.012977494 0.014093745 0.015155555 

0.016186795 0.017198588 0.018197674 0.019188728 0.020175011 0.02115863 0.022140713 

0.023121604 0.024101105 0.025078766

0.001189076 0.001869663 0.002488411 0.002944582 0.003362337 0.003909256 0.00448328 

0.005023914 0.005598782 0.006271018 0.006841796 0.007427885 0.008052774 0.008682745 

0.009319862 0.010010173 0.01103613 0.012578689 0.013819069 0.014944306 0.016014783 

0.017052845 0.018070097 0.01907365 0.020068061 0.021056348 0.022040513 0.02302178 

0.024000736 0.024977482 0.02595184

0.001406793 0.00211399 0.002775958 0.003267055 0.00376279 0.00431653 0.004937103 

0.005493092 0.006113594 0.006833683 0.007441124 0.008075112 0.008779525 0.009489224 

0.010215291 0.010864119 0.011753909 0.013209336 0.014519947 0.015704522 0.016808459 

0.017866468 0.018897781 0.01991229 0.020915429 0.021910549 0.02289987 0.023884858 

0.024866391 0.025844885 0.026820439

0.001618988 0.002362335 0.003038454 0.003601729 0.004097151 0.004717739 0.005329708 

0.005979575 0.006600608 0.007328866 0.008020364 0.008762889 0.009477118 0.010322783 

0.011112334 0.011851297 0.012572612 0.013892983 0.015201212 0.01641238 0.017547199 

0.018631875 0.019684336 0.020715554 0.021732182 0.022738415 0.023737026 0.024729877 

0.025718185 0.026702669 0.02768368

0.001823665 0.002662766 0.003428788 0.004014023 0.004602964 0.005203298 0.005895438 

0.006563927 0.0073496 0.00811528 0.008843889 0.009607291 0.010450381 0.011226376 

0.012102804 0.013047486 0.013918383 0.014848851 0.01595678 0.017116314 0.018257016 

0.019362601 0.020436911 0.021487488 0.02252078 0.02354148 0.024552867 0.025557204 

0.026556027 0.027550321 0.028540641

0.001881195 0.002855393 0.003763972 0.004417351 0.005034886 0.005688433 0.006411093 

0.007129575 0.00795107 0.008877464 0.009668923 0.010480372 0.011306682 0.012051733 

0.012961152 0.013945206 0.014858398 0.01577045 0.016774807 0.017858953 0.018972005 

0.020079045 0.021166934 0.022234578 0.023285092 0.024322163 0.025348905 0.026367679 

0.027380181 0.028387558 0.0293905

0.001979051 0.003094042 0.004074228 0.004899328 0.005446041 0.006288872 0.006953242 

0.007840747 0.008507427 0.009495555 0.010367991 0.011442652 0.012046672 0.012862288 

0.013452512 0.014547241 0.01560095 0.016591793 0.017588529 0.018628876 0.019706058 

0.02079782 0.021886865 0.022965027 0.024030379 0.025083875 0.026127357 0.027162664 

0.028191312 0.029214408 0.030232655

0.00237897 0.003700649 0.004908007 0.005690611 0.00649296 0.007230009 0.008238879 

0.008969218 0.010058954 0.011194719 0.012129642 0.012642868 0.013830866 0.01405664 

0.01448847 0.015326022 0.016329116 0.017352345 0.018369794 0.019398967 0.020451395 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 13 of 103

0.021523489 0.022604923 0.02368642 0.024762444 0.025830751 0.026891079 0.027944053 

0.028990526 0.03003126 0.031066797

0.002699791 0.004152212 0.005450659 0.006315175 0.007057452 0.0078636 0.008741286 

0.009783849 0.010840132 0.011901743 0.012764003 0.012886485 0.014091617 0.014865375 

0.015487894 0.016231585 0.017134721 0.018121926 0.019134744 0.020157704 0.021195421 

0.022251552 0.0233231 0.02440344 0.025486176 0.026566903 0.027643226 0.02871412 

0.029779308 0.030838854 0.03189293

0.002968793 0.00446721 0.005832867 0.006820448 0.00757159 0.008430823 0.009343862 

0.010497616 0.011624592 0.01250215 0.013189635 0.013717206 0.014571185 0.015483197 

0.016311311 0.017121522 0.01799085 0.018926827 0.019905272 0.020908632 0.021932336 

0.022976535 0.024039685 0.025117491 0.026204476 0.027295542 0.028386711 0.029475219 

0.030559347 0.031638173 0.032711321

0.003606473 0.00508766 0.006410747 0.007371471 0.008202778 0.009087137 0.010088372 

0.011182667 0.012207987 0.013035738 0.013740891 0.014464602 0.015221584 0.016108865 

0.017051864 0.017967757 0.018854606 0.01975078 0.02068323 0.021656197 0.022662968 

0.023696618 0.024752773 0.025828011 0.026918245 0.02801851 0.029123691 0.030229351 

0.031332208 0.032430216 0.033522363

];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Pre-Processing

% - Define enigne map for 455 HP / 15 L engine

%

% - Created by Lisandro Quinones on 8/17/2010

% - Edited by Byungho Lee on 8/20/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define General Engine Parameters

% ... desity of diesel fuel (kg/L)

engine.cyl.fuel_desity = 0.847;

% ... displacement volume (cc)

engine.cyl.disp_vol = 15000;

%% Define Wide-Open Throttle (WOT) Torque Table

% ... engine speed axis (RPM)

engine.cyl.wot_spd = [600 750 850 950 1050 1100 1200 1250 1300 1400 1500 1520 1600 1700 

1800 1900 2000 2100];

% ... engine torque map (Nm)

engine.cyl.wot_torq = [1200 1320 1490 1700 1950 2090 2100 2100 2093 2092 2090 2075 2010 

1900 1801 1640 1340 1028];

%% Define Closed Throttle Torque Table

% ... engine speed axis (RPM)

engine.cyl.closed_spd = [600 700 965 1050 1100 1150 1200 1300 1400 1500 1600 1700 

1800 1900 2000 2100 2200 2300];
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 14 of 103

% ... engine torque map (Nm)

%engine.cyl.closed_torq = [0 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5];

%engine.cyl.closed_torq = [0 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5];

engine.cyl.closed_torq = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];

% ... engine torque map calibration factor

engine.cyl.closed_torq_cal = 1.0;

%% Define Engine Fuel Map Axes

% ... engine speed axis (RPM)

engine.cyl.fuel_spd = [600:100:2200];

% ... engine torque axis (Nm)

engine.cyl.fuel_torq = [0:100:3000];

% ... minimum fuel torque (Nm)

engine.cyl.fuel_min_torq = min(engine.cyl.fuel_torq);

%% Define Engine Fuel Map (kg/s)

% ... 2013, 2014, 2015, and 2016 vehicle models

if veh_year >= 2 || veh_year <= 5

% ... 2014 15 L - 455 hp

engine.cyl.fuel_map = [...

9.10E-06 0.00059675 0.001168154 0.001596775 0.00189352 0.002227608 0.002577919 

0.002956942 0.003346881 0.003751595 0.004178426 0.004650602 0.005114281 0.005532568 

0.0058881 0.006189711 0.006450992 0.00669338 0.006938709 0.007193945 0.007453834 

0.007714444 0.007979328 0.008256251 0.008551824 0.008868899 0.009206509 0.009560983 

0.009927384 0.010300789 0.010677252

0.000315269 0.000973535 0.001527463 0.001899975 0.002197684 0.002540731 0.002925641 

0.003315291 0.003705467 0.004097159 0.004513557 0.004960436 0.005439982 0.005886479 

0.006306911 0.006645376 0.006973284 0.007323144 0.007684449 0.008041437 0.008387892 

0.008732848 0.009088549 0.009461524 0.009853161 0.01026208 0.010685435 0.01111974 

0.011561523 0.012007757 0.012456161

0.000567733 0.001321943 0.001973259 0.002249193 0.002460585 0.002819889 0.003251435 

0.003651018 0.004060698 0.004425449 0.004828649 0.00525265 0.005731849 0.006213622 

0.006720565 0.007093222 0.007495734 0.007968977 0.008444164 0.008889758 0.009316894 

0.009749673 0.010201685 0.01067335 0.011161105 0.011660702 0.012168308 0.012681099 

0.013197231 0.013715516 0.014235191

0.000778101 0.001588666 0.00226517 0.002533574 0.002691349 0.003065473 0.003491432 

0.003937579 0.004325736 0.004738011 0.005106557 0.005578781 0.006002423 0.006550828 

0.006997033 0.007564245 0.008061024 0.008651077 0.009220462 0.009722115 0.010229914 

0.010766271 0.011324929 0.011898166 0.01248086 0.013068021 0.013656323 0.014244554 

0.014832756 0.015421374 0.016010822

0.000974948 0.001793038 0.002493863 0.002738409 0.002974126 0.003307276 0.003834992 

0.004245597 0.004732195 0.005136887 0.005622922 0.00607683 0.006630932 0.007116464 

0.00770365 0.008212978 0.008821788 0.009352202 0.009973069 0.010508589 0.011126468 

0.01179712 0.012468378 0.013143014 0.013817145 0.014486237 0.015149657 0.015808917 

0.016465916 0.017122276 0.017779149

0.00107676 0.001859228 0.002475529 0.002816483 0.00296884 0.003443426 0.003902323 

0.004485721 0.004959574 0.005508952 0.005998748 0.006559636 0.007102186 0.007678772 

0.008243089 0.008838666 0.009407301 0.009987538 0.01054022 0.011270818 0.012034766 

0.012858131 0.013639473 0.014414741 0.015172953 0.015915387 0.016647198 0.017372577 

0.01809455 0.018815346 0.019536506
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 15 of 103

0.001212069 0.002035334 0.002767497 0.003058612 0.003353783 0.003781823 0.004365484 

0.004919255 0.005493631 0.00601789 0.006572276 0.00714162 0.00773464 0.008355685 

0.008950123 0.009595395 0.010189772 0.010817131 0.011450925 0.012228536 0.01300559 

0.013910104 0.014852318 0.015720829 0.01654735 0.017353339 0.018147426 0.018934187 

0.019716947 0.020498242 0.021279829

0.00138679 0.002233973 0.002942364 0.003327662 0.003623356 0.004152595 0.004783355 

0.005389158 0.005991473 0.006562536 0.007153192 0.00779571 0.008482736 0.009175027 

0.009889749 0.010539773 0.011199908 0.011857158 0.012615617 0.013431116 0.014372486 

0.015291733 0.016168154 0.017056512 0.017935536 0.018798931 0.019649987 0.020493176 

0.021332071 0.022169338 0.023006847

0.001629359 0.002571532 0.003345503 0.003798672 0.00405288 0.004604949 0.005234715 

0.005861335 0.006517335 0.007138507 0.007809305 0.008496651 0.009259897 0.010032631 

0.010814955 0.011547837 0.012280459 0.012960041 0.013755953 0.014655148 0.015627102 

0.01658413 0.01750508 0.018427443 0.019345639 0.020255096 0.021155776 0.022049762 

0.022939641 0.023827817 0.024716184

0.002049557 0.003167313 0.004117539 0.00455216 0.004860798 0.005185929 0.005667765 

0.006352584 0.007029973 0.00776084 0.008426475 0.009244494 0.010041231 0.010927742 

0.011772453 0.012583611 0.013322457 0.014127223 0.014884391 0.015893787 0.016823406 

0.01784154 0.018857365 0.019824385 0.020776274 0.021723623 0.022666608 0.023605066 

0.024540158 0.025473702 0.026407447

0.0027438 0.003962718 0.004985314 0.005289482 0.005477417 0.005807284 0.006297101 

0.006977646 0.007824013 0.008563612 0.009384498 0.010164987 0.01105061 0.011917593 

0.012854478 0.013713537 0.014658873 0.01554416 0.016429354 0.017197797 0.018528722 

0.019346832 0.020262704 0.021237178 0.022221571 0.023204224 0.02418382 0.025160395 

0.026134627 0.027107793 0.028081315

0.003104777 0.004244213 0.005192868 0.005955665 0.006192701 0.006468265 0.006868918 

0.007581774 0.008467771 0.009346119 0.010196764 0.01108709 0.011977636 0.01291732 

0.013829989 0.014823502 0.015810724 0.016983678 0.017895385 0.018117433 0.019486901 

0.020657262 0.021678675 0.022678921 0.023686162 0.024696988 0.025707458 0.026716411 

0.027724134 0.028731517 0.029739562

0.004493956 0.005421201 0.006485203 0.006831045 0.007141963 0.007156412 0.00743373 

0.008259447 0.009234424 0.010217025 0.011129959 0.012099419 0.013039013 0.014075895 

0.015055397 0.01610939 0.017191132 0.018394855 0.019455957 0.019958724 0.020869214 

0.021979405 0.023072098 0.0241256 0.025164369 0.026200697 0.027236954 0.028273198 

0.029309639 0.030346738 0.031384945

0.006845987 0.007128605 0.007144167 0.007290129 0.00751075 0.007759033 0.008242238 

0.00914831 0.010247157 0.011197345 0.012225343 0.013200097 0.01431307 0.01535716 

0.016505236 0.017487715 0.01856938 0.019706905 0.020746651 0.021593594 0.022449694 

0.02344314 0.024509715 0.025584795 0.026651039 0.02771137 0.028770331 0.02983027 

0.030892013 0.031955643 0.033020927

0.007376243 0.007460728 0.007490437 0.007646575 0.007838248 0.008418642 0.009158943 

0.010129956 0.01114085 0.012109811 0.013033587 0.014171457 0.015317454 0.016460416 

0.017574964 0.018734114 0.019878757 0.020999735 0.022065584 0.023065947 0.02401005 

0.024982598 0.026012298 0.027076363 0.028150976 0.029227357 0.030305482 0.031386921 

0.032472167 0.033560618 0.034651261

0.007416227 0.007674767 0.007998779 0.008207122 0.008574136 0.009296263 0.010235612 

0.011196971 0.012206602 0.013134081 0.014106749 0.01519318 0.016344839 0.017527226 

0.018715639 0.019934243 0.021134824 0.022294813 0.023414045 0.024493473 0.02552367 

0.026531776 0.027553174 0.028599898 0.029667396 0.030749234 0.031841845 0.032943214 

0.034051358 0.035164096 0.036279473

0.007445763 0.007903163 0.008366886 0.008833253 0.00943886 0.010255486 0.011229646 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 16 of 103

0.012231481 0.01321913 0.014187528 0.015188757 0.016249307 0.017390336 0.018601518 

0.019856877 0.021125113 0.022376487 0.023592919 0.024773699 0.025918551 0.027019746 

0.028075804 0.029106445 0.03013985 0.031194735 0.032275988 0.033379952 0.034500332 

0.035631281 0.036768296 0.037908328

];

end

% ... 2017 and later vehicle models

if veh_year == 6

% ... 2017 15 L - 455 hp

engine.cyl.fuel_map = [...

9.07E-06 0.000594165 0.001161565 0.001585665 0.001877883 0.002206377 0.00255011 

0.002921266 0.003301976 0.003695723 0.004109389 0.004565481 0.005010959 0.005409948 

0.005746096 0.00602881 0.006272081 0.006497382 0.006726354 0.006966023 0.007211448 

0.007458826 0.007711449 0.007976563 0.00826024 0.008564936 0.008889477 0.009230164 

0.00958216 0.00994071 0.010302039

0.000314373 0.000969714 0.001519759 0.001888148 0.002181224 0.00251823 0.002895389 

0.003275638 0.003654568 0.004032945 0.004433424 0.004861528 0.005319399 0.005743092 

0.006140145 0.00645696 0.006763743 0.007092406 0.007432961 0.007770272 0.008098335 

0.008425744 0.008764082 0.009119363 0.00949266 0.00988243 0.01028579 0.010699308 

0.011119614 0.011543797 0.011969684

0.000566206 0.001317247 0.001964463 0.002236869 0.00244411 0.002796889 0.003219318 

0.003607721 0.004003534 0.004352487 0.004736799 0.005139173 0.005593449 0.006048598 

0.006527273 0.006875471 0.007253271 0.007700325 0.008150098 0.008572089 0.008976811 

0.009387142 0.009815816 0.010262934 0.010724877 0.011197479 0.011677058 0.012160925 

0.012647332 0.013135151 0.013623649

0.000776068 0.001583506 0.00225634 0.00252163 0.002675602 0.00304278 0.003458662 

0.003891219 0.004263089 0.004655607 0.005002492 0.00544862 0.005845452 0.006362496 

0.006779781 0.007314627 0.007782173 0.008340851 0.008880563 0.009355655 0.009836649 

0.01034443 0.010872509 0.011413198 0.011961541 0.01251287 0.013064158 0.013614362 

0.014163578 0.014712238 0.015260717

0.000972424 0.001787626 0.002485442 0.002727583 0.002959361 0.0032855 0.003800972 

0.004195736 0.004661156 0.005042079 0.005499857 0.005923939 0.006444054 0.006896605 

0.00744753 0.007923917 0.008497776 0.008997799 0.00958612 0.010092718 0.010677654 

0.011311454 0.011943503 0.012576359 0.013206583 0.013830207 0.014446907 0.015058287 

0.015666216 0.016272231 0.016877391

0.001073972 0.00185415 0.002468348 0.002807243 0.002956605 0.003423677 0.003869565 

0.004432606 0.004881577 0.005400252 0.005857226 0.006381763 0.006887494 0.007425891 

0.007952486 0.008509994 0.009043538 0.009590677 0.01011246 0.010804484 0.011526739 

0.012302997 0.013035126 0.013758072 0.014462103 0.015148979 0.015823904 0.016490997 

0.01715317 0.017812523 0.018470473

0.00120885 0.002030079 0.002760328 0.003049963 0.003341967 0.00376281 0.004330013 

0.004859457 0.00540213 0.005890207 0.006404717 0.006933104 0.007485064 0.008064902 

0.008619462 0.009223027 0.009779424 0.010370705 0.010967878 0.011701094 0.012431454 

0.013280432 0.014159412 0.014964327 0.015726474 0.016466718 0.017193452 0.017911099 

0.018622837 0.01933105 0.020037361

0.001382902 0.002228138 0.002935001 0.003318786 0.003610962 0.00413115 0.004743587 

0.005320479 0.005885052 0.006412684 0.006956668 0.007551533 0.008192162 0.008840379 

0.009511495 0.010120214 0.010738067 0.01135419 0.012065217 0.012827984 0.013707993 

0.014563371 0.0153727 0.016189666 0.016994692 0.017782073 0.018555068 0.019317999 

0.020074281 0.020826435 0.021576201
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 17 of 103

0.001624524 0.002564329 0.003336768 0.00378821 0.004038123 0.004578968 0.005187605 

0.005781669 0.006393936 0.006964024 0.007579214 0.008213164 0.008925627 0.009651668 

0.01038977 0.011080537 0.011767241 0.012398133 0.01313649 0.013970112 0.014869712 

0.015751865 0.016596623 0.017439235 0.018274322 0.019097703 0.019909523 0.020711883 

0.021507299 0.022298065 0.023085958

0.002043418 0.003157734 0.004106122 0.004538679 0.004841331 0.005153849 0.005612358 

0.006260423 0.00688937 0.007560895 0.008163818 0.008920204 0.009663196 0.010497701 

0.011296238 0.012064394 0.012755826 0.013498733 0.014191264 0.015120409 0.015969654 

0.016900066 0.01782726 0.018704834 0.019564161 0.020415278 0.021258502 0.022093825 

0.022922437 0.0237461 0.024566475

0.002736229 0.003951705 0.004971372 0.005272512 0.005452992 0.005767318 0.006230426 

0.006870312 0.007660908 0.008336742 0.009086827 0.009800253 0.010622529 0.011433023 

0.012315397 0.013124415 0.014010238 0.01482668 0.015634935 0.016326638 0.017547328 

0.018278877 0.019101916 0.019977611 0.020858971 0.021734642 0.022603331 0.023465126 

0.024320737 0.025171422 0.026018548

0.003097291 0.004233194 0.005177843 0.005934528 0.006161984 0.006419271 0.006790379 

0.007458881 0.008285849 0.009095317 0.009872116 0.010686769 0.011505373 0.012376377 

0.013226828 0.014156645 0.015076388 0.016164004 0.016993195 0.017161133 0.018410899 

0.019467278 0.020380095 0.021270186 0.022163455 0.023056137 0.023944235 0.024826552 

0.025703347 0.026575485 0.027443947

0.004484509 0.005407041 0.006464229 0.006802659 0.007101381 0.007096269 0.007341628 

0.008118656 0.009030967 0.009940714 0.010775421 0.0116617 0.012519198 0.013472164 

0.014375119 0.01535318 0.016354594 0.017464973 0.018430873 0.018859331 0.019667555 

0.020658932 0.021629509 0.022559662 0.023472397 0.024378875 0.025280937 0.02617839 

0.027071321 0.027960144 0.028845314

0.006833138 0.007108421 0.0071167 0.007252573 0.007457742 0.007682433 0.00813005 

0.008984007 0.010015458 0.010891365 0.01183506 0.012721831 0.013738874 0.014689433 

0.015741539 0.016637813 0.017627321 0.018665047 0.019602932 0.020350859 0.021100923 

0.021974581 0.02291184 0.023852582 0.024780839 0.025699258 0.026611803 0.027520393 

0.028425633 0.02932754 0.030225914

0.007363893 0.007436996 0.007455717 0.007597791 0.007770622 0.008321811 0.009021583 

0.00993767 0.010881658 0.011774711 0.012615742 0.013656975 0.014700297 0.015737452 

0.016746285 0.017797069 0.01883256 0.0198423 0.020794804 0.02167943 0.022504951 

0.023351333 0.024245704 0.025166944 0.026092997 0.027015718 0.02793497 0.028852038 

0.029767245 0.030679968 0.031589266

0.007405941 0.00764865 0.007955192 0.008144093 0.008486471 0.00917409 0.010067358 

0.010972166 0.011913827 0.012765422 0.013652001 0.014640204 0.01568359 0.016750255 

0.017818113 0.018911425 0.019985048 0.021017654 0.022008509 0.02295769 0.023855666 

0.024727472 0.025605917 0.02650206 0.027411624 0.02832866 0.02924988 0.030173401 

0.031097358 0.032019716 0.032938662

0.007437858 0.00787445 0.008314485 0.00875394 0.009327424 0.010104067 0.011028828 

0.011972206 0.012892166 0.01378333 0.014696182 0.015656211 0.016683798 0.017769348 

0.018889034 0.020014832 0.02112069 0.022191293 0.023226706 0.024226242 0.025181513 

0.02608987 0.026968689 0.027843536 0.028731479 0.029637018 0.0305569 0.031485481 

0.032417487 0.033348825 0.034276687

];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Parameter Initialization for Engine System

% - This file initializes model parameters of Engine System for GEM.
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 18 of 103

%

% - Created by Soduk Lee

% - Edited by Byungho Lee

% - Modified by Houshun Zhang

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Engine Cylinder Block

engine.cyl.inertia = 4.17; % kg-m^2

engine.cyl.idle_spd = 750; % idle engine speed in RPM

engine.cyl.engine_off_spd = 50; % RPM

engine.cyl.throttling_tau = 0.4; % 0.037 => 200ms small engine, 0.1 => 600ms for big

diesel, throttling low pass filter phase delay time constant

engine.cyl.fuel_flow_ini = 0; % fuel flow init

engine.cyl.fuel_desity = 0.847; % density of fuel (kg/L)

engine.cyl.fuel_spd = [600:100:2100];

engine.cyl.fuel_torq = [0:200:3000];

engine.cyl.fuel_map = [ ...

 4.8629600e-004 9.4716300e-004 1.4189410e-003 1.9080870e-003 2.4220190e-003 

2.9734630e-003 3.5810670e-003 4.2611530e-003 5.0198210e-003 5.8561040e-003 

6.7575060e-003 7.6900930e-003 8.6181040e-003 9.5226950e-003 1.0404521e-002 

1.1275165e-002; 

 4.6068200e-004 1.1154150e-003 1.7703970e-003 2.4270550e-003 3.1007500e-003 

3.8027120e-003 4.5335080e-003 5.3129450e-003 6.1863100e-003 7.1496490e-003 

8.1450010e-003 9.1257970e-003 1.0078726e-002 1.1010573e-002 1.1931931e-002 

1.2850101e-002;

 4.5696900e-004 1.2886270e-003 2.1208900e-003 2.9407160e-003 3.7735580e-003 

4.6342900e-003 5.4961680e-003 6.3718040e-003 7.3643300e-003 8.4646290e-003 

9.5343260e-003 1.0544581e-002 1.1519850e-002 1.2487523e-002 1.3459741e-002 

1.4436220e-002;

 4.9680500e-004 1.4709140e-003 2.4555260e-003 3.4478940e-003 4.4451830e-003 

5.4512840e-003 6.4537870e-003 7.4940400e-003 8.6194200e-003 9.8110870e-003 

1.0894053e-002 1.1909430e-002 1.2918174e-002 1.3945909e-002 1.4992461e-002 

1.6047893e-002;

 6.0123900e-004 1.6831300e-003 2.7885000e-003 3.9328260e-003 5.0721150e-003 

6.2100200e-003 7.3260000e-003 8.5054040e-003 9.7768590e-003 1.1089528e-002 

1.2139460e-002 1.3180390e-002 1.4265643e-002 1.5390519e-002 1.6538583e-002 

1.7695229e-002;

 7.8081400e-004 1.9593780e-003 3.1517590e-003 4.3730200e-003 5.5983900e-003 

6.8130580e-003 8.0359210e-003 9.2978680e-003 1.0639984e-002 1.1984365e-002 

1.3165975e-002 1.4352843e-002 1.5580004e-002 1.6835899e-002 1.8105541e-002 

1.9379459e-002;

 1.0225930e-003 2.2776080e-003 3.5377710e-003 4.7972090e-003 6.0600050e-003 

7.3318160e-003 8.6081160e-003 9.9241240e-003 1.1318758e-002 1.2715342e-002 

1.4069439e-002 1.5480196e-002 1.6890737e-002 1.8294767e-002 1.9694750e-002 

2.1093227e-002;

 1.2998240e-003 2.6145270e-003 3.9244710e-003 5.2241670e-003 6.5147880e-003 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 19 of 103

7.8257240e-003 9.1634400e-003 1.0563977e-002 1.2029234e-002 1.3551314e-002 

1.5078690e-002 1.6662442e-002 1.8230754e-002 1.9774324e-002 2.1302426e-002 

2.2824904e-002;

 1.5806060e-003 2.9665650e-003 4.3358460e-003 5.6901850e-003 7.0314370e-003 

8.3948530e-003 9.8190520e-003 1.1316895e-002 1.2922253e-002 1.4585124e-002 

1.6263195e-002 1.7948998e-002 1.9624208e-002 2.1281697e-002 2.2925819e-002 

2.4564369e-002;

 1.8377990e-003 3.3331750e-003 4.7929840e-003 6.2555350e-003 7.7015700e-003 

9.1660440e-003 1.0726250e-002 1.2292146e-002 1.4033205e-002 1.5807013e-002 

1.7573616e-002 1.9326763e-002 2.1076673e-002 2.2823445e-002 2.4566395e-002 

2.6307124e-002;

 2.0609370e-003 3.6953960e-003 5.3168490e-003 6.9470900e-003 8.6134390e-003 

1.0291892e-002 1.2015321e-002 1.3682868e-002 1.5389790e-002 1.7172377e-002 

1.8971472e-002 2.0771438e-002 2.2582248e-002 2.4402679e-002 2.6227851e-002 

2.8054242e-002;

 2.2751270e-003 4.0754660e-003 5.8821440e-003 7.7216130e-003 9.6354480e-003 

1.1620670e-002 1.3557042e-002 1.5267491e-002 1.6917250e-002 1.8637476e-002 

2.0430448e-002 2.2268842e-002 2.4135819e-002 2.6020221e-002 2.7913265e-002 

2.9809015e-002;

 2.5184780e-003 4.4940880e-003 6.4895120e-003 8.5198310e-003 1.0579129e-002 

1.2769219e-002 1.5026069e-002 1.6730152e-002 1.8380821e-002 2.0115058e-002 

2.1934172e-002 2.3815997e-002 2.5735920e-002 2.7675539e-002 2.9623409e-002 

3.1573518e-002;

 2.8227620e-003 4.9518560e-003 7.1244730e-003 9.3270260e-003 1.1373273e-002 

1.3411222e-002 1.5754751e-002 1.7789063e-002 1.9674620e-002 2.1547469e-002 

2.3455785e-002 2.5404240e-002 2.7378716e-002 2.9365260e-002 3.1355820e-002 

3.3347122e-002;

 3.1999350e-003 5.4540920e-003 7.7180060e-003 1.0020741e-002 1.2074804e-002 

1.3827237e-002 1.6029133e-002 1.8522790e-002 2.0780461e-002 2.2900529e-002 

2.4970879e-002 2.7018697e-002 2.9053410e-002 3.1080575e-002 3.3104262e-002 

3.5126960e-002;

 3.6184310e-003 5.9882160e-003 8.3166770e-003 1.0530605e-002 1.2551649e-002 

1.4485312e-002 1.6661783e-002 1.9169187e-002 2.1737384e-002 2.4183563e-002 

2.6473833e-002 2.8644325e-002 3.0743312e-002 3.2807896e-002 3.4859969e-002 

3.6909420e-002];

engine.cyl.fuel_rate_cal = 1.00; % fuel map calibration factor

engine.cyl.fuel_min_torq = min(engine.cyl.fuel_torq);

engine.cyl.closed_torq_cal = 1.0;

engine.cyl.wot_spd = [600, 700, 965, 1050, 1100, 1150, 1200, 1300, 1400, 1500, 

1600, 1700, 1800, 1900, 2000, 2100, 2129, 2131];

engine.cyl.wot_torq = [1244.6, 1382.9, 1678.5, 1965.9, 2100.2, 2100.2, 2101.5, 

2100.2, 2100.2, 2100.2, 2025.6, 1906.3, 1720.5, 1549.7, 1378.9, 1208, 1156.5, 0];

engine.cyl.closed_spd = [600, 700, 965, 1050, 1100, 1150, 1200, 1300, 1400, 1500, 

1600, 1700, 1800, 1900, 2000, 2100, 2129, 2131];

engine.cyl.max_spd = max(engine.cyl.wot_spd)*rpm2rps;

engine.cyl.min_spd = engine.cyl.idle_spd*rpm2rps;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 20 of 103

engine.cyl.clutching_Kp = 1.57; % M. Dassen, automotive clutch

engine.cyl.clutching_Ki = 0.01; % M. Dassen, automotive clutch

engine.cyl.clutching_Kd = 0.018; % M. Dassen, automotive clutch

engine.cyl.starting_Kp = 0.72; % M. Dassen, automotive clutch

engine.cyl.starting_Ki = 0.01; % M. Dassen, automotive clutch

engine.cyl.starting_Kd = 0.021; % M. Dassen, automotive clutch

engine.cyl.starter_max_time = 15; % maximum starter key on time

engine.cyl.idle_spd_start_cal = 1.05; % idle speed calibration for engine torque 

/w starting

engine.cyl.idle_spd_shift_cal = 1.25; % idle speed calibration for engine torque 

/w gear shifting

engine.cyl.idle_exit_cal = 1.055; % exit idle state at engine_rpm > idle_rpm * 

idle_exit_cal

%% Define Engine Gear Shifting Time and Idle PID Gains

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 engine.cyl.shifting_time = .5;

 engine.cyl.idling_Kp = 1.25;

 engine.cyl.idling_Ki = 0.0015;

 engine.cyl.idling_Kd = 1.2;

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 engine.cyl.shifting_time = 1.0;

 engine.cyl.idling_Kp = 1.35;

 engine.cyl.idling_Ki = 0.0015;

 engine.cyl.idling_Kd = 1.2;

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 engine.cyl.shifting_time = 0.5;

 engine.cyl.idling_Kp = 1.1;

 engine.cyl.idling_Ki = 0.0015;

 engine.cyl.idling_Kd = 1.2;

end

%% Define Engine Accessory

engine.acc.power = 1000; % mechanical accesory power [W]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Parameter Initialization for Manual Transmission System

% - This file initializes model parameters of Transmission System for GEM.

%

% - Created by Byungho Lee

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 21 of 103

%% Define Transmission Inertia Values

% ... clutch (kg-m^2)

trans.cltch.inertia = 0.004;

% ... gear (kg-m^2)

trans.gear.inertia = 0.200;

%% Define Damping Coefficients

% ... crankshaft

trans.cltch.damping = 0.1;

%trans.cltch.damping = 0.1;

% ... gear

trans.gear.damping = 0.005;

%% Define Gear Ratio

% ... gear number

trans.gear.number = [0:1:10];

% ... gear ratio

trans.gear.ratio = [0 14.8 10.95 8.09 5.97 4.46 3.32 2.45 1.81 1.35 1];

%% Define Gear Efficiency

trans.gear.eff = [0 0.96 0.96 0.96 0.96 0.98 0.98 0.98 0.98 0.98 0.98];

%% Define Transmission Shifting Schedule

% ... class 8 combination/vocational truck

trans.gear.up_shift_gear_c8 = [1 2 3 4 5 6 7 8 9];

trans.gear.up_shift_vehspd_c8 = [4.1 6.0 7.5 10.0 14.0 20. 29.0 39.9 50]/mps2mph; 

% convert mph to m/s

trans.gear.down_shift_gear_c8 = [2 3 4 5 6 7 8 9 10];

trans.gear.down_shift_vehspd_c8 = [3.9 5.8 7.0 9.0 13.0 19.0 28.1 39.00 49.0]/mps2mph; 

% convert mph to m/s

% ... class 7 combination truck

trans.gear.up_shift_gear_c7 = [1 2 3 4 5 6 7 8 9];

trans.gear.up_shift_vehspd_c7 = [4.1 6.0 7.0 10.0 14.0 20. 29.0 39.9 50]/mps2mph; 

% convert mph to m/s

trans.gear.down_shift_gear_c7 = [2 3 4 5 6 7 8 9 10];

trans.gear.down_shift_vehspd_c7 = [3.4 5.6 6.0 9.0 13.0 19.0 28.1 39.00 49.0]/mps2mph; 

% convert mph to m/s

% ... class 6-7 vocational truck

trans.gear.up_shift_gear_c6 = [1 2 3 4 5];

trans.gear.up_shift_vehspd_c6 = [7.4 12.95 20.78 32.5 48]/mps2mph; 

% convert mph to m/s

trans.gear.down_shift_gear_c6 = [2 3 4 5 6];

trans.gear.down_shift_vehspd_c6 = [6.8 12 19.5 31.5 47]/mps2mph; 

% convert mph to m/s

% ... class 2b-5 vocational truck

trans.gear.up_shift_gear_c4 = [1 2 3 4 5];

trans.gear.up_shift_vehspd_c4 = [8.1 14.0 22 32.5 48]/mps2mph; 

% convert mph to m/s

trans.gear.down_shift_gear_c4 = [2 3 4 5 6];

trans.gear.down_shift_vehspd_c4 = [7.2 13 21 31.5 47]/mps2mph; 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 22 of 103

% convert mph to m/s

%% Define Clutch Conditions During Shifting

trans.gear.clutch_holding_spd = 0.2; % 0.2 m/s = 0.4474 mph

trans.gear.clutching_spd = 0.3; % 0.3 m/s = 0.6711 mph

trans.gear.declutching_spd = 0.25; % 0.25 m/s = 0.5592 mph

trans.gear.clutching_min_time = 3; % 3 seconds

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Parameter Initialization for Vehicle System

% - This file initializes model parameters of Vehicle System for GEM.

%

% - Created by James Sanchez & Lisandro Quinones

% - Edited by Byungho Lee

% - Modified by Houshun Zhang

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define Drive Shaft Inertia Value (kg-m^2)

vehicle.shaft.inertia = 1.00;

%% Define Drive Shaft Efficiency

vehicle.shaft.eff = 0.99;

%% Define Number of Differential

vehicle.diff.num = 2;

%% Define Differential Inertia Value (kg-m^2)

vehicle.diff.inertia = 0.5;

%% Define Differential Gear Ratio

vehicle.diff.ratio = 1;

%% Define Gear Efficiency

vehicle.diff.eff = 0.99;

%% Define Torque Split Ratio

% ... front torque ratio

if vehicle.diff.num == 2

 vehicle.diff.trq_ratio_front = 0.5;

elseif vehicle.diff.num == 1

 vehicle.diff.trq_ratio_front = 1.0;

end

% ... rear torque ratio

vehicle.diff.trq_ratio_rear = 1 - vehicle.diff.trq_ratio_front;

%% Define Final Drive Inertia Value (kg-m^2)

% ... front drive
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 23 of 103

vehicle.fdr.inertia_front = 2;

% ... rear drive

vehicle.fdr.inertia_rear = 2;

%% Define Final Drive Gear Ratio

% ... front drive

vehicle.fdr.ratio_front = 2.64;

% ... rear drive

vehicle.fdr.ratio_rear = 2.64;

%% Define Final Drive Efficiency

% ... front drive

vehicle.fdr.eff_front = 0.99;

% ... rear drive

vehicle.fdr.eff_rear = 0.99;

%% Define Number of Axles

vehicle.axle.num = 5;

%% Define Brake Force Table

% ... brake pedal input (fraction)

vehicle.axle.brk_frac = [1.0, 0.5, 0.15, 0.1, 0.05, 0]*-1;

% ... brake force array (Nm)

vehicle.axle.brk_force = [5e6, 2e6, 5.0e5, 3.5e5, 2.0e5, 0];

%% Define Brake Fraction Values (fraction)

% ... steering axle

vehicle.axle.brk_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

% ... first propulsion axle

vehicle.axle.brk_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

% ... second propulsion axle

vehicle.axle.brk_frac_prop2 = 4/(2+(vehicle.axle.num-1)*4);

% ... first trailer axle

vehicle.axle.brk_frac_trail1 = 4/(2+(vehicle.axle.num-1)*4);

% ... second trailer axle

vehicle.axle.brk_frac_trail2 = 4/(2+(vehicle.axle.num-1)*4);

%% Define Axle Inertia Values (kg-m^2)

% ... steering axle

vehicle.axle.inertia_steer = 360*2/(2+(vehicle.axle.num-1)*4);

% ... first propulsion axle

vehicle.axle.inertia_prop1 = 360*4/(2+(vehicle.axle.num-1)*4);

% ... second propulsion axle

vehicle.axle.inertia_prop2 = 360*4/(2+(vehicle.axle.num-1)*4);

% ... first trailer axle

vehicle.axle.inertia_trail1 = 360*4/(2+(vehicle.axle.num-1)*4);

% ... second trailer axle

vehicle.axle.inertia_trail2 = 360*4/(2+(vehicle.axle.num-1)*4);

%% Define Vehicle Weight Fraction Values (fraction)

% ... steering tire
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 24 of 103

vehicle.tire.weight_frac_steer = 2/18;

% ... first propulsion tire

vehicle.tire.weight_frac_prop1 = 4/18;

% ... second propulsion tire

vehicle.tire.weight_frac_prop2 = 4/18;

% ... first trailer tire

vehicle.tire.weight_frac_trail1 = 4/18;

% ... second trailer tire

vehicle.tire.weight_frac_trail2 = 4/18;

%% Define Tire Inertia Values (kg-m^2)

% ... steering tire

vehicle.tire.inertia_steer = 0;

% ... first propulsion tire

vehicle.tire.inertia_prop1 = 0;

% ... second propulsion tire

vehicle.tire.inertia_prop2 = 0;

% ... first trailer tire

vehicle.tire.inertia_trail1 = 0;

% ... second trailer tire

vehicle.tire.inertia_trail2 = 0;

%% Define Tire Radius (m)

% ... steering tire

vehicle.tire.radius_steer = 0.489;

% ... first propulsion tire

vehicle.tire.radius_prop1 = vehicle.tire.radius_steer;

% ... second propulsion tire

vehicle.tire.radius_prop2 = vehicle.tire.radius_steer;

% ... first trailer tire

vehicle.tire.radius_trail1 = vehicle.tire.radius_steer;

% ... second trailer tire

vehicle.tire.radius_trail2 = vehicle.tire.radius_steer;

%% Define Rolling Friction Coefficient

% ... steering tire

vehicle.tire.roll_coef_steer = 0.005659;

% ... first propulsion tire

vehicle.tire.roll_coef_prop1 = vehicle.tire.roll_coef_steer;

% ... second propulsion tire

vehicle.tire.roll_coef_prop2 = vehicle.tire.roll_coef_steer;

% ... first trailer tire

vehicle.tire.roll_coef_trail1 = vehicle.tire.roll_coef_steer;

% ... second trailer tire

vehicle.tire.roll_coef_trail2 = vehicle.tire.roll_coef_steer;

%% Define Vehicle Total Mass (kg)

vehicle.chs.mass_static = 31978;

%% Define Vehicle Frontal Area (m^2)

vehicle.chs.frontal_area = 9.8;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 25 of 103

%% Define Drag Coefficient

vehicle.chs.drag_coef = 0.6111;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% HD Truck Compliance Model User Interface and Simulation Run

% - Launch GUI window for user inputs to run single simulation

% - Run GEM (GHG Emissions Model) according to user inputs through GUI

%

% - Created by Byungho Lee on 6/16/2010

% - Edited by Lisandro Quinones on 7/12/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Initialize Script

warning off

clear all

close all

clc

%MathWorks addition

addpath(genpath(pwd));

%% Define Global Variables

global i_sim veh_type veh_year c_d c_rr_steer c_rr_drive

global speed_limit weight_reduce idle_reduce plot_output 

global single_sim batch_sim batch_n

global manufacturer_name vehicle_family vehicle_config date_sim

global use_generated_code error_flag reset_GEM reset_on

% Initialize Input Variables

i_sim = 0;

veh_type = 0; % vehicle regulatory class

veh_year = '';

c_d = 0; % coefficient of aerodynamic drag

c_rr_steer = 0; % steer tire rolling resistance (kg/ton)

c_rr_drive = 0; % drive tire rolling resistance (kg/ton)

speed_limit = 0; % vehicle speed limiter (mph)

weight_reduce = 0; % weight reduction (kg)

idle_reduce = 0; % idle reduction CO2 credit (g/ton-mile)

plot_output = 0;

single_sim = 0;

batch_sim = 0;

manufacturer_name = ''; 

vehicle_family = '';

vehicle_config = '';

date_sim = '';

batch_n = 0;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 26 of 103

use_generated_code = 1;

error_flag = 0;

reset_GEM = 0;

reset_on = 0;

%% Run GUI for User Interface

run GEM

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Pre-Processing

% - Perform pre-processing for HD truck simulation

%

% - Created by Byungho Lee on 6/28/2010

% - Edited by Lisandro Quinones on 7/12/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Determine Unit Conversion Factors

% ... m/s to mph

mps2mph = 2.23693629;

% ... rad/s to RPM

rps2rpm = 30/pi;

% ... RPM to rad/s

rpm2rps = pi/30;

% ... kg to ton

kg2ton = 0.00110231131;

% ... lb to ton

lb2ton = 0.0005;

% ... gallon to liter

gal2lit = 3.78541178;

% ... mile to meter

mi2mtr = 1609.344;

% ... gallon to CO2 conversion (1g_CO2/ton-mile = 10180/mpg/payload_ton)

gal2co2 = 10180;

%% Determine Simulation Parameters

% ... simulation step time (sec)

sim_step_time = 0.01;

% ... simulation stop time (sec)

sim_stop_time = inf;

%% Download Vehicle Model Parameters

% ... ambient system parameters

run ambient_param

% ... driver system parameters

run driver_param

% ... electrical system parameters
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 27 of 103

run electric_param

% ... engine system parameters

run engine_param

% ... transmission system parameters

run transmission_manual_param

% ... vehicle system parameters

run vehicle_param

%% Define Vehicle Model Parameters based on Regulatory Class

% - electrical accessary power

% - mechanical accessary power

% - engine map

% - engine inertia

% - transmission inertia

% - transmission ratio

% - transmission efficiency

% - number of differentials

% - torque split ratio of differentials

% - final drive ratio

% - number of axles

% - brake fraction

% - axle inertia

% - weight fraction

% - loaded tire radius

% - tire rolling resistance

% - total mass of vehicle

% - frontal area of vehicle

% - coefficient of aerodynamic drag

%% Define Electrical Accessary Power (W)

% ... class 8 combination/vocational & class 7 combination truck

if veh_type <= 10

 electric.acc.power = 350;

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 electric.acc.power = 300;

end

%% Define Mechanical Accessary Power (W)

engine.acc.power = 1000;

%% Define Engine Maps

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 run engine_map_455

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 run engine_map_350

% ... class 6-7 vocational truck

elseif veh_type == 11

 run engine_map_270
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 28 of 103

% ... class 2b-5 vocational truck

elseif veh_type == 12

 run engine_map_200

end

%% Define Engine Inertia (kg-m^2) and engine idle speed

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 engine.cyl.inertia = 4.17;

 engine.cyl.idle_spd = 600;

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9 

 engine.cyl.inertia = 3.36;

 engine.cyl.idle_spd = 600;

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 engine.cyl.inertia = 2.79;

 engine.cyl.idle_spd = 750;

end

%% Define Transmission Inertia (kg-m^2)

% ... class 8 combination/vocational & class 7 combination truck

if veh_type <= 10

 trans.gear.inertia = 5.0; %0.2;

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 trans.gear.inertia = 0.5;

end

%% Define Transmission Ratio

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 trans.gear.number = [0:1:10];

 trans.gear.ratio = [0 14.8 10.95 8.09 5.97 4.46 3.32 2.45 1.81 1.35 1];

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 trans.gear.number = [0:1:10];

 trans.gear.ratio = [0 11.06 8.19 6.05 4.46 3.34 2.48 1.83 1.36 1 0.75];

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 trans.gear.number = [0:1:6];

 trans.gear.ratio = [0 9.01 5.27 3.22 2.04 1.36 1];

end

%% Define Transmission Efficiency

% ... class 8 combination/vocational & class 7 combination truck

if veh_type <= 10

 trans.gear.eff = [0 0.96 0.96 0.96 0.96 0.98 0.98 0.98 0.98 0.98 0.98];

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 trans.gear.eff = [0 0.92 0.92 0.93 0.95 0.95 0.95];
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 29 of 103

end

%% Define Drive Shaft Inertia & Efficiency

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 vehicle.shaft.inertia = 1.0;

 vehicle.shaft.eff = 1.0;

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 vehicle.shaft.inertia = 1.0;

 vehicle.shaft.eff = 1.0;

% ... class 6-7 vocational truck

elseif veh_type == 11

 vehicle.shaft.inertia = 0.30;

 vehicle.shaft.eff = 1.00;

% ... class 2b-5 vocational truck

elseif veh_type == 12

 vehicle.shaft.inertia = 0.20;

 vehicle.shaft.eff = 1.00;

end

%% Define Number of Differentials

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 vehicle.diff.num = 2;

% ... class 7 combination, class 6-7 & 2b-5 vocational truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9 || veh_type >= 11

 vehicle.diff.num = 1;

end

%% Define Differential Inertia & Efficiency

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 vehicle.diff.inertia = 0.50;

 vehicle.diff.eff = 0.99;

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 vehicle.diff.inertia = 0.5;

 vehicle.diff.eff = 0.99;

% ... class 6-7 vocational truck

elseif veh_type == 11

 vehicle.diff.inertia = 0.15;

 vehicle.diff.eff = 0.99;

% ... class 2b-5 vocational truck

elseif veh_type == 12

 vehicle.diff.inertia = 0.10;

 vehicle.diff.eff = 0.99;

end

%% Define Torque Split Ratio of Differentials

% ... front torque ratio
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 30 of 103

if vehicle.diff.num == 2

 vehicle.diff.trq_ratio_front = 0.5;

elseif vehicle.diff.num == 1

 vehicle.diff.trq_ratio_front = 1.0;

end

% ... rear torque ratio

vehicle.diff.trq_ratio_rear = 1 - vehicle.diff.trq_ratio_front;

%% Define Final Drive Ratio

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 vehicle.fdr.ratio_front = 2.64;

 vehicle.fdr.ratio_rear = 2.64;

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 vehicle.fdr.ratio_front = 3.73;

 vehicle.fdr.ratio_rear = 3.73;

% ... class 6-7 vocational truck

elseif veh_type == 11

 vehicle.fdr.ratio_front = 3.36;

 vehicle.fdr.ratio_rear = 3.36;

% ... class 2b-5 vocational truck

elseif veh_type == 12

 vehicle.fdr.ratio_front = 2.85;

 vehicle.fdr.ratio_rear = 2.85;

end

%% Define Final Drive Inertia & Efficiency

% ... class 8 combination/vocational truck

if veh_type <= 6 || veh_type == 10

 vehicle.fdr.inertia_front = 2.0;

 vehicle.fdr.inertia_rear = 2.0;

 vehicle.fdr.eff_front = 0.99;

 vehicle.fdr.eff_rear = 0.99;

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 vehicle.fdr.inertia_front = 2.0;

 vehicle.fdr.inertia_rear = 2.0;

 vehicle.fdr.eff_front = 0.98;

 vehicle.fdr.eff_rear = 0.98;

% ... class 6-7 vocational truck

elseif veh_type == 11

 vehicle.fdr.inertia_front = 0.5;

 vehicle.fdr.inertia_rear = 0.5;

 vehicle.fdr.eff_front = 0.98;

 vehicle.fdr.eff_rear = 0.98;

% ... class 2b-5 vocational truck

elseif veh_type == 12

 vehicle.fdr.inertia_front = 0.5;

 vehicle.fdr.inertia_rear = 0.5;

 vehicle.fdr.eff_front = 0.98;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 31 of 103

 vehicle.fdr.eff_rear = 0.98;

end

%% Define Number of Axles

% ... class 8 combination truck

if veh_type <= 6

 vehicle.axle.num = 5;

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 vehicle.axle.num = 4;

% ... class 8 vocational truck

elseif veh_type == 10

 vehicle.axle.num = 3;

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 vehicle.axle.num = 2;

end

%% Define Brake Fraction Values (fraction)

% ... class 8 combination truck

if veh_type <= 6

 vehicle.axle.brk_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_prop2 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_trail1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_trail2 = 4/(2+(vehicle.axle.num-1)*4);

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 vehicle.axle.brk_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_prop2 = 0;

 vehicle.axle.brk_frac_trail1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_trail2 = 4/(2+(vehicle.axle.num-1)*4);

% ... class 8 vocational truck

elseif veh_type == 10

 vehicle.axle.brk_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_prop2 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_trail1 = 0;

 vehicle.axle.brk_frac_trail2 = 0;

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 vehicle.axle.brk_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.brk_frac_prop2 = 0;

 vehicle.axle.brk_frac_trail1 = 0;

 vehicle.axle.brk_frac_trail2 = 0;

end

%% Define Axle Inertia (kg-m^2)

% ... class 8 combination truck
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 32 of 103

if veh_type <= 6

 vehicle.axle.inertia_steer = 360*2/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_prop1 = 360*4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_prop2 = 360*4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_trail1 = 360*4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_trail2 = 360*4/(2+(vehicle.axle.num-1)*4);

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 vehicle.axle.inertia_steer = 233.4*2/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_prop1 = 233.4*4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_prop2 = 0;

 vehicle.axle.inertia_trail1 = 233.4*4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_trail2 = 233.4*4/(2+(vehicle.axle.num-1)*4);

% ... class 8 vocational truck

elseif veh_type == 10

 vehicle.axle.inertia_steer = 200*2/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_prop1 = 200*4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_prop2 = 200*4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_trail1 = 0;

 vehicle.axle.inertia_trail2 = 0;

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >= 11

 vehicle.axle.inertia_steer = 60*2/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_prop1 = 60*4/(2+(vehicle.axle.num-1)*4);

 vehicle.axle.inertia_prop2 = 0;

 vehicle.axle.inertia_trail1 = 0;

 vehicle.axle.inertia_trail2 = 0;

end

%% Define Weight Fraction Values (fraction)

% ... class 8 combination truck

if veh_type <= 6

 vehicle.tire.weight_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_prop2 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_trail1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_trail2 = 4/(2+(vehicle.axle.num-1)*4);

% ... class 7 combination truck

elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 vehicle.tire.weight_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_prop2 = 0;

 vehicle.tire.weight_frac_trail1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_trail2 = 4/(2+(vehicle.axle.num-1)*4);

% ... class 8 vocational truck

elseif veh_type == 10

 vehicle.tire.weight_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_prop2 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_trail1 = 0;

 vehicle.tire.weight_frac_trail2 = 0;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 33 of 103

% ... class 6-7 & 2b-5 vocational truck

elseif veh_type >=11

 vehicle.tire.weight_frac_steer = 2/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_prop1 = 4/(2+(vehicle.axle.num-1)*4);

 vehicle.tire.weight_frac_prop2 = 0;

 vehicle.tire.weight_frac_trail1 = 0;

 vehicle.tire.weight_frac_trail2 = 0;

end

%% Define Loaded Tire Radius (mm)

% ... class 8 combination/vocational & class 7 combination truck

if veh_type <= 10

 vehicle.tire.radius_steer = 0.489;

 vehicle.tire.radius_prop1 = vehicle.tire.radius_steer;

 vehicle.tire.radius_prop2 = vehicle.tire.radius_steer;

 vehicle.tire.radius_trail1 = vehicle.tire.radius_steer;

 vehicle.tire.radius_trail2 = vehicle.tire.radius_steer;

% ... class 6-7 vocational truck

elseif veh_type == 11

 vehicle.tire.radius_steer = 0.389;

 vehicle.tire.radius_prop1 = vehicle.tire.radius_steer;

 vehicle.tire.radius_prop2 = vehicle.tire.radius_steer;

 vehicle.tire.radius_trail1 = vehicle.tire.radius_steer;

 vehicle.tire.radius_trail2 = vehicle.tire.radius_steer;

% ... class 2b-5 vocational truck

elseif veh_type == 12

 vehicle.tire.radius_steer = 0.378;

 vehicle.tire.radius_prop1 = vehicle.tire.radius_steer;

 vehicle.tire.radius_prop2 = vehicle.tire.radius_steer;

 vehicle.tire.radius_trail1 = vehicle.tire.radius_steer;

 vehicle.tire.radius_trail2 = vehicle.tire.radius_steer;

end

%% Define Tire Rolling Resistance (kg/ton)

% ... combination truck

if veh_type <= 9

 % trailer tire rolling resistance (kg/ton)

 c_rr_trail = 6e-3;

 % weighted tire rolling resistance (kg/ton)

 c_rr_weighted = 0.425*c_rr_trail + 0.425*c_rr_drive + 0.15

*c_rr_steer;

 % tire rolling resistance (kg/ton)

 vehicle.tire.roll_coef_steer = c_rr_weighted;

 vehicle.tire.roll_coef_prop1 = c_rr_weighted;

 vehicle.tire.roll_coef_prop2 = c_rr_weighted;

 vehicle.tire.roll_coef_trail1 = c_rr_weighted;

 vehicle.tire.roll_coef_trail2 = c_rr_weighted;

% ... vocational truck

elseif veh_type >= 10

 % weighted tire rolling resistance (kg/ton)

 c_rr_weighted = 0.5*c_rr_drive + 0.5*c_rr_steer;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 34 of 103

 % tire rolling resistance (kg/ton)

 vehicle.tire.roll_coef_steer = c_rr_weighted;

 vehicle.tire.roll_coef_prop1 = c_rr_weighted;

 vehicle.tire.roll_coef_prop2 = c_rr_weighted;

 vehicle.tire.roll_coef_trail1 = c_rr_weighted;

 vehicle.tire.roll_coef_trail2 = c_rr_weighted;

end

%% Define Total Mass of Vehicle (kg)

if veh_type == 1

 vehicle.chs.mass_static = 31978;

elseif veh_type == 2

 vehicle.chs.mass_static = 30277;

elseif veh_type == 3

 vehicle.chs.mass_static = 30391;

elseif veh_type == 4

 vehicle.chs.mass_static = 31298;

elseif veh_type == 5

 vehicle.chs.mass_static = 29529;

elseif veh_type == 6

 vehicle.chs.mass_static = 29710;

elseif veh_type == 7 

 vehicle.chs.mass_static = 22680; 

elseif veh_type == 8

 vehicle.chs.mass_static = 20910;

elseif veh_type == 9

 vehicle.chs.mass_static = 21092; 

elseif veh_type == 10 

 vehicle.chs.mass_static = 19051;

elseif veh_type == 11

 vehicle.chs.mass_static = 11408;

elseif veh_type == 12

 vehicle.chs.mass_static = 7257;

end

%% Define Frontal Area of Vehicle (m^2)

if veh_type == 1 

 vehicle.chs.frontal_area = 10.4;

elseif veh_type == 2

 vehicle.chs.frontal_area = 7.7;

elseif veh_type == 3

 vehicle.chs.frontal_area = 6.9;

elseif veh_type == 4

 vehicle.chs.frontal_area = 10.4;

elseif veh_type == 5

 vehicle.chs.frontal_area = 7.7;

elseif veh_type == 6

 vehicle.chs.frontal_area = 6.9;

elseif veh_type == 7 

 vehicle.chs.frontal_area = 10.4;

elseif veh_type == 8
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 35 of 103

 vehicle.chs.frontal_area = 7.7;

elseif veh_type == 9

 vehicle.chs.frontal_area = 6.9;

elseif veh_type == 10 

 vehicle.chs.frontal_area = 9.8;

elseif veh_type == 11

 vehicle.chs.frontal_area = 9.0;

elseif veh_type == 12

 vehicle.chs.frontal_area = 9.0;

end

%% Define Coefficient of Aerodynamic Drag

vehicle.chs.drag_coef = c_d;

% keep vocational truck c_d as constant

if veh_type == 10

 vehicle.chs.drag_coef = 0.7;

elseif veh_type >= 11

 vehicle.chs.drag_coef = 0.6;

end

%% Define Post-Processing Parameters based on Regulatory Class

% - vehicle payload and weight reducition

% - vehicle speed limiter

%% Define Vehicle Payload (ton) and Weight Reducition (lb)

% ... in case there is weight reduction

if isempty(weight_reduce) == 0

 % class 8 combination truck

 if veh_type <= 6

 payload = 19 + (weight_reduce*lb2ton)/3;

 % class 7 combination truck

 elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 payload = 12.5 + (weight_reduce*lb2ton)/3;

 % class 8 vocational truck

 elseif veh_type == 10

 payload = 7.5; %+ (weight_reduce*lb2ton)/3; % temporarily added for weight 

reduction impact on vocational truck

 % class 6-7 vocational truck

 elseif veh_type == 11

 payload = 5.6;

 % class 2b-5 vocational truck

 elseif veh_type == 12

 payload = 2.85;

 end

 

% ... in case there is no weight reduction

else

 % class 8 combination truck

 if veh_type <= 6

 payload = 19;

 % class 7 combination truck
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 36 of 103

 elseif veh_type == 7 || veh_type == 8 || veh_type == 9

 payload = 12.5;

 % class 8 vocational truck

 elseif veh_type == 10

 payload = 7.5;

 % class 6-7 vocational truck

 elseif veh_type == 11

 payload = 5.6;

 % class 2b-5 vocational truck

 elseif veh_type == 12

 payload = 2.85;

 end

end

%% Define Vehicle Speed Limiter (m/s)

if isempty(speed_limit) == 0

 vehicle.chs.speed_limit_mps = speed_limit/mps2mph;

else

 vehicle.chs.speed_limit_mps = inf;

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Transient Cycle Run

% - Run GEM for transient cycle simulation

%

% - Created by Byungho Lee on 6/2/2010

% - Edited by Lisandro Quinones on 7/12/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Download Vehicle Driving Cycle

load('drive_cycles\ARB_Transient')

%% Apply Vehicle Speed Limit

if isscalar(speed_limit) == 1

 if speed_limit > 0

 driving_cycle(:,2) = min(driving_cycle(:,2),speed_limit/mps2mph);

 end

end

% MathWorks modification

driving_cycle_time = driving_cycle(:,1);

driving_cycle_data = driving_cycle(:,2);

%% Define Vehicle Simulation Parameters

% ... simulation step time

sim_step_time = 0.01;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 37 of 103

% ... simulation stop time

sim_stop_time = driving_cycle(end,1);

%% Perform Vehicle Simulation

if use_generated_code

 run_generated_code;

else

 sim GEM_manual_v2

end

%% Perform Post-Processing

% ... calculate percent time trace missed by 2mph (%)

veh_spd_err = (driver_veh_spd_des-vehicle_chassis_spd_out)*mps2mph;

num_err_plus2mph = find(veh_spd_err >= 2);

per_err_trans = length(num_err_plus2mph)/length(veh_spd_err)*100;

% ... calculate total fuel consumption (mpg)

fuel_mile_total_trans = sum(vehicle_chassis_spd_out)/(sum(engine_fuel_flowrate)*engine.

cyl.fuel_rate_cal);

mpg_total_trans = fuel_mile_total_trans*(engine.cyl.fuel_desity*gal2lit/mi2mtr);

% ... calculate CO2 (g/ton-mile)

CO2_trans = gal2co2/mpg_total_trans/payload;

%% Plot Simulation Results

if plot_output == 1,

 figure(1)

 plot(total_sim_time,driver_veh_spd_des*mps2mph,'b-')

 hold on

 plot(total_sim_time,vehicle_chassis_spd_out*mps2mph,'r--')

 hold off

 legend('Demanded Speed','Actual Speed')

 title('Transient Cycle Simulation')

 xlabel('Time (sec)')

 ylabel('Speed (mph)')

 grid on

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 55 mph Steady-State Cycle Run

% - Run GEM for 55 mph steady-state cycle simulation

%

% - Created by Byungho Lee on 6/2/2010

% - Edited by Lisandro Quinones on 7/12/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Download Vehicle Driving Cycle

load('drive_cycles\Mild_55mph')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 38 of 103

%% Apply Vehicle Speed Limit

if isscalar(speed_limit) == 1

 if speed_limit > 0

 driving_cycle(:,2) = min(driving_cycle(:,2),speed_limit/mps2mph);

 end

end

% MathWorks modification

driving_cycle_time = driving_cycle(:,1);

driving_cycle_data = driving_cycle(:,2);

%% Define Vehicle Simulation Parameters

% ... simulation step time

sim_step_time = 0.01;

% ... simulation stop time

sim_stop_time = driving_cycle(end,1);

%% Perform Vehicle Simulation

if use_generated_code

 run_generated_code; 

else

 sim GEM_manual_v2

end

%% Perform Post-Processing

% ... find 55 mph steady-state time indices

idx_ti_55 = min(find(total_sim_time >= 300));

idx_tf_55 = max(find(total_sim_time <= 600));

% ... calculate percent time trace missed by 2mph (%)

veh_spd_err = (driver_veh_spd_des-vehicle_chassis_spd_out)*mps2mph;

num_err_plus2mph = find(veh_spd_err >= 2);

per_err_55 = length(num_err_plus2mph)/length(veh_spd_err)*100;

% ... calculate total fuel consumption (mpg)

fuel_mile_total_55 = sum(vehicle_chassis_spd_out)/(sum(engine_fuel_flowrate)*engine.

cyl.fuel_rate_cal);

mpg_total_55 = fuel_mile_total_55*(engine.cyl.fuel_desity*gal2lit/mi2mtr);

% ... calculate steady-state fuel consumption (mpg)

fuel_mile_cruise_55 = sum(vehicle_chassis_spd_out(idx_ti_55:idx_tf_55))/(sum

(engine_fuel_flowrate(idx_ti_55:idx_tf_55))*engine.cyl.fuel_rate_cal);

mpg_cruise_55 = fuel_mile_cruise_55*(engine.cyl.fuel_desity*gal2lit/mi2mtr);

% ... calculate CO2 (g/ton-mile)

CO2_55 = gal2co2/mpg_cruise_55/payload;

%% Plot Simulation Results

if plot_output == 1,

 figure(2)

 plot(total_sim_time,driver_veh_spd_des*mps2mph,'b-')

 hold on

 plot(total_sim_time,vehicle_chassis_spd_out*mps2mph,'r--')

 hold off
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 39 of 103

 %legend('Measurement','GEM','location','best')

 legend('Demanded Speed','Actual Speed','location','best')

 title('55 mph Steady-State Cycle Simulation')

 xlabel('Time (sec)')

 ylabel('Speed (mph)')

 grid on

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 65 mph Steady-State Cycle Run

% - Run GEM for 65 mph steady-state cycle simulation

%

% - Created by Byungho Lee on 6/2/2010

% - Edited by Lisandro Quinones on 7/12/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Download Vehicle Driving Cycle

load('drive_cycles\Mild_65mph')

%% Apply Vehicle Speed Limit

if isscalar(speed_limit) == 1

 if speed_limit > 0

 driving_cycle(:,2) = min(driving_cycle(:,2),speed_limit/mps2mph);

 end

end

% MathWorks modification

driving_cycle_time = driving_cycle(:,1);

driving_cycle_data = driving_cycle(:,2);

%% Define Vehicle Simulation Parameters

% ... simulation step time

sim_step_time = 0.01;

% ... simulation stop time

sim_stop_time = driving_cycle(end,1);

%% Perform Vehicle Simulation

if use_generated_code

 run_generated_code;

else

 sim GEM_manual_v2

end

%% Perform Post-Processing

% ... find 65 mph steady-state time indices

idx_ti_65 = min(find(total_sim_time >= 300));
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 40 of 103

idx_tf_65 = max(find(total_sim_time <= 600));

% ... calculate percent time trace missed by 2mph (%)

veh_spd_err = (driver_veh_spd_des-vehicle_chassis_spd_out)*mps2mph;

num_err_plus2mph = find(veh_spd_err >= 2);

per_err_65 = length(num_err_plus2mph)/length(veh_spd_err)*100;

% ... calculate total fuel consumption (mpg)

fuel_mile_total_65 = sum(vehicle_chassis_spd_out)/(sum(engine_fuel_flowrate)*engine.

cyl.fuel_rate_cal);

mpg_total_65 = fuel_mile_total_65*(engine.cyl.fuel_desity*gal2lit/mi2mtr);

% ... calculate steady-state fuel consumption (mpg)

fuel_mile_cruise_65 = sum(vehicle_chassis_spd_out(idx_ti_65:idx_tf_65))/(sum

(engine_fuel_flowrate(idx_ti_65:idx_tf_65))*engine.cyl.fuel_rate_cal);

mpg_cruise_65 = fuel_mile_cruise_65*(engine.cyl.fuel_desity*gal2lit/mi2mtr);

% ... calculate CO2 (g/ton-mile)

CO2_65 = gal2co2/mpg_cruise_65/payload;

%% Plot Simulation Results

if plot_output == 1,

 figure(3)

 plot(total_sim_time,driver_veh_spd_des*mps2mph,'b-')

 hold on

 plot(total_sim_time,vehicle_chassis_spd_out*mps2mph,'r--')

 hold off

 %legend('Meassurement','GEM','location','best')

 legend('Demanded Speed','Actual Speed','Location','best')

 title('65 mph Steady-State Cycle Simulation')

 xlabel('Time (sec)')

 ylabel('Speed (mph)')

 grid on

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Post-Processing

% - Perform post-processing for HD truck simulation

%

% - Created by Byungho Lee on 6/28/2010

% - Edited by Lisandro Quinones on 7/12/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define Driving Cycle Weighting Factors

if veh_type == 1 

 weight_trans = 0.05;

 weight_55mph = 0.09;

 weight_65mph = 0.86;

elseif veh_type == 2

 weight_trans = 0.05;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 41 of 103

 weight_55mph = 0.09;

 weight_65mph = 0.86;

elseif veh_type == 3

 weight_trans = 0.05;

 weight_55mph = 0.09;

 weight_65mph = 0.86;

elseif veh_type == 4 

 weight_trans = 0.19;

 weight_55mph = 0.17;

 weight_65mph = 0.64;

elseif veh_type == 5

 weight_trans = 0.19;

 weight_55mph = 0.17;

 weight_65mph = 0.64;

elseif veh_type == 6

 weight_trans = 0.19;

 weight_55mph = 0.17;

 weight_65mph = 0.64;

elseif veh_type == 7

 weight_trans = 0.19;

 weight_55mph = 0.17;

 weight_65mph = 0.64;

elseif veh_type == 8

 weight_trans = 0.19;

 weight_55mph = 0.17;

 weight_65mph = 0.64;

elseif veh_type == 9

 weight_trans = 0.19;

 weight_55mph = 0.17;

 weight_65mph = 0.64;

elseif veh_type == 10

 weight_trans = 0.42;

 weight_55mph = 0.21;

 weight_65mph = 0.37;

elseif veh_type == 11

 weight_trans = 0.42;

 weight_55mph = 0.21;

 weight_65mph = 0.37;

elseif veh_type == 12

 weight_trans = 0.42;

 weight_55mph = 0.21;

 weight_65mph = 0.37;

end

%% Calculate Weighted Fuel Consumption and CO2 Production

% ... weighted fuel consumption (mpg)

mpg_weighted = weight_trans*mpg_total_trans + weight_55mph*mpg_cruise_55 + 

weight_65mph*mpg_cruise_65;

% ... weighted CO2 production (g/ton-mile)

% CO2_weighted = gal2co2/mpg_weighted/payload;

CO2_weighted = weight_trans*CO2_trans + weight_55mph*CO2_55 + weight_65mph*CO2_65;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 42 of 103

% ... apply idle reduction credit 

if isempty(weight_reduce) == 0

 CO2_final = CO2_weighted - idle_reduce;

else

 CO2_final = CO2_weighted;

end

% ... weighted fuel consumption (gal/1000 ton-mile)

gptm_weighted = CO2_final*(1000/gal2co2);

%% Post-Processing for Multiple Configurations

if batch_sim == 1,

 mpg_weighted_i_raw(k)=mpg_weighted;

 gptm_weighted_i_raw(k)=gptm_weighted;

 CO2_final_i_raw(k)=CO2_final;

end

reset_GEM = 1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Output File

% - Write XML format output file for HD truck simulations

%

% - Created by Lisandro Quinones on 5/23/2011 

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Delete temporary files

delete mprm.bin

delete mprm.txt

delete GEM_manual_v2.mat

%% Define timestamp on file

runtime = clock;

if runtime(4)>12

 runtime(4) = runtime(4)-12;

 tod = 'pm';

else

 tod = 'am';

end

ts1 = [ num2str(runtime(4),'%02.0f') ':' ...

 num2str(runtime(5),'%02.0f') ':' num2str(runtime(6),'%02.0f') ];

date_time_run = strcat(date,'/',ts1,tod);

%% Transfer GUI Identification Parameters

if veh_year == 2,
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 43 of 103

 model_year = 2013;

elseif veh_year == 3,

 model_year = 2014;

elseif veh_year == 4,

 model_year = 2015;

elseif veh_year == 5,

 model_year = 2016;

elseif veh_year == 6,

 model_year = '2017 and later';

end

if veh_type == 1,

 regulatory_subcategory = 'Class 8 Combination - Sleeper Cab - High Roof';

elseif veh_type == 2,

 regulatory_subcategory = 'Class 8 Combination - Sleeper Cab - Mid Roof';

elseif veh_type == 3,

 regulatory_subcategory = 'Class 8 Combination - Sleeper Cab - Low Roof';

elseif veh_type == 4,

 regulatory_subcategory = 'Class 8 Combination - Day Cab - High Roof';

elseif veh_type == 5,

 regulatory_subcategory = 'Class 8 Combination - Day Cab - Mid Roof';

elseif veh_type == 6,

 regulatory_subcategory = 'Class 8 Combination - Day Cab - Low Roof';

elseif veh_type == 7,

 regulatory_subcategory = 'Class 7 Combination - Day Cab - High Roof';

elseif veh_type == 8,

 regulatory_subcategory = 'Class 7 Combination - Day Cab - Mid Roof';

elseif veh_type == 9,

 regulatory_subcategory = 'Class 7 Combination - Day Cab - Low Roof';

elseif veh_type == 10,

 regulatory_subcategory = 'Heavy Heavy-Duty - Vocational Truck (Class 8)';

elseif veh_type == 11,

 regulatory_subcategory = 'Medium Heavy-Duty - Vocational Truck (Class 6-7)';

elseif veh_type == 12,

 regulatory_subcategory = 'Light Heavy-Duty - Vocational Truck (Class 2b-5)'; 

end

if single_sim == 1,

 input_file_name = 'N/A';

end

%% Define spreadsheet header and data

header1 = {...

 'Manufacturer Name',char

(manufacturer_name),'','','','','','','','','','','','','','','';...

 'Model Year',model_year,'','','','','','','','','','','','','','','';...

 'Vehicle Family Name',char(vehicle_family),'','','','Passed through from input 

matrix','','','','','','','','','','','';...

 'Regulatory Subcategory',char(regulatory_subcategory),'','','','GEM Inputs (from 

input matrix)','','','','','','','','','','','';...

 'Date/Time of Run',date_time_run,'','','','GEM 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 44 of 103

Outputs','','','','','','','','','','','';...

 'Input File Name',input_file_name,'','','','User Input following GEM 

run','','','','','','','','','','','';...

 '','','','','','','','','','','','','','','','','';...

 '','','','','','','','','','','','','','','','','';...

 '','','','','','','','','','','','','','','','','';...

 '','','','','','','','','','','','','','','','','';...

 '','','','','','','','','','','','','','','','','';...

 '','','Aerodynamics','','','Steer Tires','Drive 

Tires','','','','Results','','FEL','','Subfamily','','';...

 'Configuration','Brand/Model Name',...

 'Bin','CdA (Test)','Cd (Bin)',...

 'CRR','CRR',...

 'Idle Reduction','Weight Reduction','VSL',...

 'g CO2/ton-mile','gal/1000 ton-mile','g CO2/ton-mile','gal/1000 ton-mile',...

 'Subfamily Name','Subfamily FEL','Subfamily Volume'};

ts2 = [ num2str(runtime(4),'%02.0f') '-'...

 num2str(runtime(5),'%02.0f') '-' num2str(runtime(6),'%02.0f') ];

%% Write spreadsheet file in XML format

filename = strcat('GEM_Results_',date,'_',ts2,'-',tod,'.xlsx');

if single_sim == 1,

 batch_n = 1;

 config_i_sim = 1;

 brand_i_sim = {'N/A'};

 bin_i_sim = {'N/A'};

 cda_i_sim = {'N/A'};

 cd_i_sim = c_d;

 crr_steer_i_sim = c_rr_steer*1000;

 crr_drive_i_sim = c_rr_drive*1000;

 idle_reduction_i_sim = idle_reduce;

 weight_reduction_i_sim = weight_reduce;

 if speed_limit == 0,

 vsl_i_sim = 0;

 elseif speed_limit ~= 0,

 vsl_i_sim = speed_limit;

 end

 results1_i_sim = CO2_final;

 results2_i_sim = gptm_weighted;

 fel1_i_sim = round(results1_i_sim);

 fel2_i_sim = round(gptm_weighted*10)/10;

 PathName = cd;

end

if batch_sim == 1,

 results1_i_sim = (CO2_final_i_sim)';

 results2_i_sim = (gptm_weighted_i_sim)';

 fel1_i_sim = round(results1_i_sim);

 fel2_i_sim = round(results2_i_sim*10)/10;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 45 of 103

end

folder_name = uigetdir(PathName,'Select where to write the results file:');

if folder_name == 0,

 clc

 error_output = 1;

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'No location selected for the results file.';

 ms4 = {''};

 ms5 = 'Click RESET to restart the program.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

elseif ischar(folder_name)

 error_output = 0;

 cd(folder_name);

end

xlswrite(filename, header1, 1, 'A1');

xlswrite(filename, config_i_sim, 1, 'A14');

if single_sim == 1,

 S1 = [brand_i_sim,bin_i_sim,cda_i_sim,cd_i_sim,crr_steer_i_sim,crr_drive_i_sim,

idle_reduction_i_sim,...

 weight_reduction_i_sim,vsl_i_sim,results1_i_sim,results2_i_sim,...

 fel1_i_sim,fel2_i_sim];

 xlswrite(filename, S1, 1, 'B14');

elseif batch_sim == 1,

 S1 = [brand_i_sim,bin_i_sim];

 xlswrite(filename, S1, 1, 'B14');

 S2 = [cda_i_sim,cd_i_sim,crr_steer_i_sim,crr_drive_i_sim,idle_reduction_i_sim,...

 weight_reduction_i_sim,vsl_i_sim,results1_i_sim,results2_i_sim,...

 fel1_i_sim,fel2_i_sim];

 xlswrite(filename, S2, 1, 'D14');

end

%% Open ActiveX COM Interface for spreadsheet editing

e = actxserver('excel.application');

eW = e.WorkBooks;

file = fullfile(pwd, filename);

eF = eW.Open(file);

eS = eF.ActiveSheet;

%% Define sheet name and close unwanted sheets
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 46 of 103

Sheets = e.ActiveWorkBook.Sheets;

Sheets.Item(1).Name = 'GEM Results';

Sheets.Item(2).Delete;

Sheets.Item(2).Delete;

%% Define font style

c1 = e.ActiveSheet.Range('A1:A6'); set(c1.Font, 'Bold', true);

c2 = e.ActiveSheet.Range('A12:Q12'); set(c2.Font, 'Italic', true);

c3 = e.ActiveSheet.Range('A13:Q13'); set(c3.Font, 'Bold', true);

%% Define cell border style

c4 = e.ActiveSheet.Range('A1:B6'); set(c4.cell.borders,'linestyle',1);

r_n = num2str(batch_n + 13);

Range_n = strcat('A13:','Q',r_n);

c5 = e.ActiveSheet.Range(Range_n); set(c5.cell.borders,'linestyle',1);

c6 = e.ActiveSheet.Range('C12:E12'); set(c6.cell.borders,'linestyle',1);

c7 = e.ActiveSheet.Range('F12'); set(c7.cell.borders,'linestyle',1);

c8 = e.ActiveSheet.Range('G12'); set(c8.cell.borders,'linestyle',1);

c9 = e.ActiveSheet.Range('K12:L12'); set(c9.cell.borders,'linestyle',1);

c10 = e.ActiveSheet.Range('M12:N12'); set(c10.cell.borders,'linestyle',1);

c11 = e.ActiveSheet.Range('O12:Q12'); set(c11.cell.borders,'linestyle',1);

c12 = e.ActiveSheet.Range('E3:E6'); set(c12.cell.borders,'linestyle',1);

%% Merge and center cells

Range = e.Range('B1:B6'); Range.Select; Range.HorizontalAlignment = -4108;

Range = e.Range('C12:E12'); Range.Select; Range.MergeCells = 1; Range.

HorizontalAlignment = -4108;

Range = e.Range('A13:Q13'); Range.Select; Range.HorizontalAlignment = -4108;

Range = e.Range('F12'); Range.Select; Range.HorizontalAlignment = -4108;

Range = e.Range('G12'); Range.Select; Range.HorizontalAlignment = -4108;

Range = e.Range('K12:L12'); Range.Select; Range.MergeCells = 1; Range.

HorizontalAlignment = -4108;

Range = e.Range('M12:N12'); Range.Select; Range.MergeCells = 1; Range.

HorizontalAlignment = -4108;

Range = e.Range('O12:Q12'); Range.Select; Range.MergeCells = 1; Range.

HorizontalAlignment = -4108;

Range = e.Range('F3:H3'); Range.Select; Range.MergeCells = 1;

Range = e.Range('F4:H4'); Range.Select; Range.MergeCells = 1;

Range = e.Range('F5:H5'); Range.Select; Range.MergeCells = 1;

Range = e.Range('F6:H6'); Range.Select; Range.MergeCells = 1;

r_n = num2str(batch_n + 14);

Range_n = strcat('A14:','A',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('B14:','B',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('C14:','C',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('D14:','D',r_n);
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 47 of 103

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('E14:','E',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('F14:','F',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('G14:','G',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('H14:','H',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('I14:','I',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('J14:','J',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('K14:','K',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('L14:','L',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('M14:','M',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('N14:','N',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('O14:','O',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('P14:','P',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

Range_n = strcat('Q14:','Q',r_n);

Range = e.Range(Range_n); Range.Select; Range.HorizontalAlignment = -4108;

%% Autofit columns 

eS.Range('A1:Q1').EntireColumn.AutoFit;

%% Define cell interior color

Range = e.Range('E3'); Range.interior.Color=hex2dec('FFFFFF'); % White

Range = e.Range('E13:J13'); Range.interior.Color=hex2dec('66CC99'); % Green

Range = e.Range('E4'); Range.interior.Color=hex2dec('66CC99'); % Green

Range = e.Range('K13:N13'); Range.interior.Color=hex2dec('9999FF'); % Red

Range = e.Range('E5'); Range.interior.Color=hex2dec('9999FF'); % Red

Range = e.Range('O13:Q13'); Range.interior.Color=hex2dec('00FFFF'); % Yellow

Range = e.Range('E6'); Range.interior.Color=hex2dec('00FFFF'); % Yellow

%% Default cell selection at file opening

Range = e.Range('A1'); Range.Select;

%% Save and close output file

eF.Save;

eF.Close; 

e.Quit;

%% Clear COM Interface Objects

clear Range Sheets c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 e eF eS eW
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 48 of 103

winopen(filename)

if error_output == 1,

 clc

 

elseif error_output == 0,

 

 if single_sim == 1,

 CO2_final_s = strcat({' '},num2str(CO2_final));

 gptm_weighted_s = strcat({' '},num2str(gptm_weighted));

 ms1 = 'SIMULATION COMPLETED';

 ms2 = {''};

 ms3 = 'Model Year:';

 if veh_year == 2,

 model_year_w = '2013';

 elseif veh_year == 3,

 model_year_w = '2014';

 elseif veh_year == 4,

 model_year_w = '2015';

 elseif veh_year == 5,

 model_year_w = '2016';

 elseif veh_year == 6,

 model_year_w = '2017 and later';

 end

 ms4 = model_year_w;

 ms5 = {''};

 ms6 = 'Regulatory Subcategory:';

 ms7 = regulatory_subcategory;

 ms8 = {''};

 ms9 = 'Cycle-Weighted Results';

 ms10 = {''};

 ms11 = strcat('CO2 Emissions: ', CO2_final_s,'',' CO2/ton-mile');

 ms12 = strcat('Fuel Consumption: ',gptm_weighted_s,' gal/1000 ton-mile');

 ms13 = {''};

 ms14 = 'A results file is now available for review at:';

 ms15 = pwd;

 ms16 = {''};

 ms17 = 'Results file name:';

 ms18 = filename;

 ms19 = {''};

 ms20 = 'To run more simulations click RESET.';

 ms21 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6; ms7; ms8; ms9; ms10;...

 ms11; ms12; ms13; ms14; ms15; ms16; ms17; ms18; ms19; ms20; ms21];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','help');
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 49 of 103

 elseif batch_sim == 1,

 ms1 = 'SIMULATIONS COMPLETED';

 ms2 = {''};

 ms3 = 'Model Year:';

 if veh_year == 2,

 model_year_w = '2013';

 elseif veh_year == 3,

 model_year_w = '2014';

 elseif veh_year == 4,

 model_year_w = '2015';

 elseif veh_year == 5,

 model_year_w = '2016';

 elseif veh_year == 6,

 model_year_w = '2017 and later';

 end

 ms4 = model_year_w;

 ms5 = {''};

 ms6 = 'Regulatory Subcategory:';

 ms7 = regulatory_subcategory;

 ms8 = {''};

 ms9 = 'A results file is now available for review at:';

 ms10 = pwd;

 ms11 = {''};

 ms12 = 'Results file name:';

 ms13 = filename;

 ms14 = {''};

 ms15 = 'To run more simulations click RESET.';

 ms16 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6; ms7; ms8; ms9; ms10;...

 ms11; ms12; ms13; ms14; ms15; ms16];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','help');

 end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Batch Script for Multiple Configurations

% - Iteration loop for multiple configurations

%

% - Created by Lisandro Quinones on 5/23/2011 

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ms0 = {''};

ms1 = 'Running Multiple Configurations...';
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 50 of 103

ms2 = {''};

ms3 = 'Model Year:';

if veh_year == 2,

 model_year_w = '2013';

elseif veh_year == 3,

 model_year_w = '2014';

elseif veh_year == 4,

 model_year_w = '2015';

elseif veh_year == 5,

 model_year_w = '2016';

elseif veh_year == 6,

 model_year_w = '2017 and later';

end

ms4 = model_year_w;

ms5 = {''};

ms6 = 'Regulatory Subcategory:';

ms7 = regulatory_subcategory;

ms8 = {''};

S = [ms0; ms1; ms2; ms3; ms4; ms5; ms6; ms7; ms8];

h = waitbar(0,S,'Name','Greenhouse Gas Emissions Model (GEM)');

j=0;

 for k = 1:batch_n,

 j = j+1;

 %iteration = num2str(j);

 c_d = cd_i_sim(k);

 c_rr_drive = (crr_drive_i_sim(k))/1000;

 c_rr_steer = (crr_steer_i_sim(k))/1000;

 idle_reduce = idle_reduction_i_sim(k);

 weight_reduce = weight_reduction_i_sim(k);

 speed_limit = vsl_i_sim(k);

 run run_preproc 

 run run_transient

 run run_55mph

 run run_65mph

 run run_postproc

 mpg_weighted_i_sim(j) = mpg_weighted_i_raw(k);

 gptm_weighted_i_sim(j) = gptm_weighted_i_raw(k);

 CO2_final_i_sim(j)= CO2_final_i_raw(k);

 pct_done = j/batch_n*100;

 %fprintf(1,'Simulation for Configuration %1.0f of %1.0f : Done \n',j,batch_n)

 waitbar(pct_done / 100)

 

 end

 

close(h) 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Simulation Input Prompt
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 51 of 103

% - Open Input File for HD truck simulations

%

% - Created by Lisandro Quinones on 5/23/2011 

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[FileName, PathName] = uigetfile( ...

 {'*.xlsx','Excel 2007-2010 (*.xlsx)'}, ...

 'Select the XLSX input file for Multiple Configurations:');

if FileName == 0,

 clc

 error_flag = 1;

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'No input file selected for Multiple Configurations.';

 ms4 = {''};

 ms5 = 'Click RESET to restart the program.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 

elseif ischar(FileName)

 error_flag = 0;

 addpath(PathName);

 [num,txt,raw] = xlsread(FileName);

 id_config = num(:,1);

 batch_n = sum(isfinite(id_config));

 id_s = txt(:,2);

 id_n = num(:,2);

 manufacturer_name = id_s(1);

 model_year = id_n(1);

 if model_year == 2013,

 veh_year = 2;

 elseif model_year == 2014,

 veh_year = 3;

 elseif model_year == 2015,

 veh_year = 4;

 elseif model_year == 2016,

 veh_year = 5;

 elseif isnan(model_year),
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 52 of 103

 veh_year = 6;

 end

 vehicle_family = id_s(3);

 regulatory_subcategory = id_s(4);

 regulatory_subcategory1 = 'Class 8 Combination - Sleeper Cab - High Roof';

 regulatory_subcategory2 = 'Class 8 Combination - Sleeper Cab - Mid Roof';

 regulatory_subcategory3 = 'Class 8 Combination - Sleeper Cab - Low Roof';

 regulatory_subcategory4 = 'Class 8 Combination - Day Cab - High Roof';

 regulatory_subcategory5 = 'Class 8 Combination - Day Cab - Mid Roof';

 regulatory_subcategory6 = 'Class 8 Combination - Day Cab - Low Roof';

 regulatory_subcategory7 = 'Class 7 Combination - Day Cab - High Roof';

 regulatory_subcategory8 = 'Class 7 Combination - Day Cab - Mid Roof';

 regulatory_subcategory9 = 'Class 7 Combination - Day Cab - Low Roof';

 regulatory_subcategory10 = 'Heavy Heavy-Duty - Vocational Truck (Class 8)';

 regulatory_subcategory11 = 'Medium Heavy-Duty - Vocational Truck (Class 6-7)';

 regulatory_subcategory12 = 'Light Heavy-Duty - Vocational Truck (Class 2b-5)'; 

 if strcmp(regulatory_subcategory,regulatory_subcategory1) == 1,

 veh_type = 1;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory2) == 1,

 veh_type = 2;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory3) == 1,

 veh_type = 3;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory4) == 1,

 veh_type = 4;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory5) == 1,

 veh_type = 5;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory6) == 1,

 veh_type = 6;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory7) == 1,

 veh_type = 7;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory8) == 1,

 veh_type = 8;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory9) == 1,

 veh_type = 9;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory10) == 1,

 veh_type = 10;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory11) == 1,

 veh_type = 11;

 elseif strcmp(regulatory_subcategory,regulatory_subcategory12) == 1,

 veh_type = 12;

 end

 input_file_name = FileName; 

 config_i_raw = num(:,1);

 j = 0;

 for i=1:length(config_i_raw),

 if not(isnan(config_i_raw(i))),
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 53 of 103

 j = j+1;

 config_i_sim(j) = config_i_raw(i);

 end

 end

 config_i_sim = (config_i_sim)';

 brand_i_raw = txt(:,2);

 j=0;

 for i=12:length(brand_i_raw),

 j=j+1;

 brand_i_sim(j) = brand_i_raw(i);

 end

 brand_i_sim = brand_i_sim(1:batch_n);

 brand_i_sim = (brand_i_sim)';

 bin_i_raw = txt(:,3);

 j=0;

 for i=12:length(bin_i_raw),

 j=j+1;

 bin_i_sim(j) = bin_i_raw(i);

 end

 bin_i_sim = bin_i_sim(1:batch_n);

 bin_i_sim = (bin_i_sim)';

 cda_i_raw = num(:,4);

 j = 0;

 for i=1:length(cda_i_raw),

 if not(isnan(cda_i_raw(i))),

 j = j+1;

 cda_i_sim(j) = cda_i_raw(i);

 end

 end

 cda_i_sim = (cda_i_sim)';

 

 cd_i_raw = num(:,5);

 j = 0;

 for i=1:length(cd_i_raw),

 if not(isnan(cd_i_raw(i))),

 j = j+1;

 cd_i_sim(j) = cd_i_raw(i);

 end

 end

 cd_i_sim = (cd_i_sim)';

 

 % Vocational class compliance limits

 if veh_type == 10,

 for i=1:length(cd_i_sim),

 cd_i_sim(i) = 0.7;

 end

 elseif veh_type >= 11,

 for i=1:length(cd_i_sim),
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 54 of 103

 cd_i_sim(i) = 0.6;

 end

 end

 crr_steer_i_raw = num(:,6);

 j = 0;

 for i=1:length(crr_steer_i_raw),

 if not(isnan(crr_steer_i_raw(i))),

 j = j+1;

 crr_steer_i_sim(j) = crr_steer_i_raw(i);

 end

 end

 crr_steer_i_sim = (crr_steer_i_sim)';

 crr_drive_i_raw = num(:,7);

 j = 0;

 for i=1:length(crr_drive_i_raw),

 if not(isnan(crr_drive_i_raw(i))),

 j = j+1;

 crr_drive_i_sim(j) = crr_drive_i_raw(i);

 end

 end

 crr_drive_i_sim = (crr_drive_i_sim)';

 idle_reduction_i_raw = num(:,8);

 j = 0;

 for i=1:length(idle_reduction_i_raw),

 if not(isnan(idle_reduction_i_raw(i))),

 j = j+1;

 idle_reduction_i_sim(j) = idle_reduction_i_raw(i);

 end

 end

 idle_reduction_i_sim = (idle_reduction_i_sim)';

 

 % Vocational class compliance limits

 if veh_type >= 4,

 for i=1:length(idle_reduction_i_sim),

 idle_reduction_i_sim(i) = 0;

 end

 end

 weight_reduction_i_raw = num(:,9);

 j = 0;

 for i=1:length(weight_reduction_i_raw),

 if not(isnan(weight_reduction_i_raw(i))),

 j = j+1;

 weight_reduction_i_sim(j) = weight_reduction_i_raw(i);

 end

 end

 weight_reduction_i_sim = (weight_reduction_i_sim)';

 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 55 of 103

 % Vocational class compliance limits

 if veh_type >= 10,

 for i=1:length(weight_reduction_i_sim),

 weight_reduction_i_sim(i) = 0;

 end

 end

 

 j=0;

 vsl_i_raw = num(:,10);

 for i=11:length(vsl_i_raw),

 if not(isnan(vsl_i_raw(i))),

 j=j+1;

 vsl_i_sim(j) = vsl_i_raw(i);

 elseif isnan(vsl_i_raw(i)),

 j=j+1;

 vsl_i_sim(j) = 0;

 end

 end

 vsl_i_sim = (vsl_i_sim)';

 

 % Vocational class compliance limits

 if veh_type >= 10,

 for i=1:length(vsl_i_sim),

 vsl_i_sim(i) = 0;

 end

 end

 iteration = num2str(batch_n);

 

 ms1 = 'VEHICLE INPUT PARAMETERS';

 ms2 = {''};

 ms3 = 'Vehicle parameters for Multiple Configurations were successfully loaded.';

 ms4 = {''};

 ms5 = 'Model Year:';

 if veh_year == 2,

 model_year_w = '2013';

 elseif veh_year == 3,

 model_year_w = '2014';

 elseif veh_year == 4,

 model_year_w = '2015';

 elseif veh_year == 5,

 model_year_w = '2016';

 elseif veh_year == 6,

 model_year_w = '2017 and later';

 end

 ms6 = model_year_w;

 ms7 = {''};

 ms8 = 'Regulatory Subcategory:';

 ms9 = regulatory_subcategory;

 ms10 = {''};

 ms11 = 'Number of configurations:';
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 56 of 103

 ms12 = iteration;

 ms13 = {''};

 ms14 = 'Click RUN BATCH to start the simulations.';

 ms15 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6; ms7; ms8; ms9; ms10; ms11; ms12; ms13; 

ms14; ms15];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','help');

 

end

%% Initialize Script

warning off

clear all

close all

clc

%MathWorks addition

%addpath(genpath(pwd));

%% Define Global Variables

global i_sim veh_type veh_year c_d c_rr_steer c_rr_drive

global speed_limit weight_reduce idle_reduce plot_output 

global single_sim batch_sim batch_n

global manufacturer_name vehicle_family vehicle_config date_sim

global use_generated_code error_flag reset_GEM reset_on 

% Initialize Input Variables

i_sim = 0;

veh_type = 0; % vehicle regulatory class

veh_year = '';

c_d = 0; % coefficient of aerodynamic drag

c_rr_steer = 0; % steer tire rolling resistance (kg/ton)

c_rr_drive = 0; % drive tire rolling resistance (kg/ton)

speed_limit = 0; % vehicle speed limiter (mph)

weight_reduce = 0; % weight reduction (kg)

idle_reduce = 0; % idle reduction CO2 credit (g/ton-mile)

plot_output = 0;

single_sim = 0;

batch_sim = 0;

manufacturer_name = ''; 

vehicle_family = '';

vehicle_config = '';

date_sim = '';

batch_n = 0;

use_generated_code = 1;

error_flag = 0;

reset_GEM = 0;

reset_on = 1;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 57 of 103

closereq

run GEM

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% epa_serialize_params.m

% - Write out the tunable parameters so that the Simulink Coder generated

% execuable can read the parameters. Before a simulation run is performed,

% the values of the parameters to be read by the Simulation are read from

% the base workspace and writtend out to mprm.bin. The location of the

% parameter data in mprm.bin are indexed by offsets specified in the

% mprm.txt file.

%

% - Created by MW on 15/6/2011

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function epa_serialize_params

 global paramTable;

 paramTable = [];

 %disp('epa_serialize_params v0.0');

 %

 % The global variable tunableParams is a list of parameters that need to

 % be set in the Simulink model based on the selction made in the GEM

 % GUI. If new parameters are added, make sure to add them here.

 %

 tunableParams = {

 'CO2_55', ...

 'CO2_65', ...

 'CO2_final', ...

 'CO2_trans', ...

 'CO2_weighted', ...

 'Rgas', ...

 'ambient', ...

 'batch_n', ...

 'batch_sim', ...

 'c_d', ...

 'c_rr_drive', ...

 'c_rr_steer', ...

 'c_rr_trail', ...

 'c_rr_weighted', ...

 'driver', ...

 'driver_MaxBrkTq', ...

 'driver_veh_spd_des', ...

 'driving_cycle', ...

 'driving_cycle_data', ...

 'driving_cycle_time', ...

 'driving_grade', ...

 'electric', ...
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 58 of 103

 'engine', ...

 'engine_fuel_flowrate', ...

 'fuel_mile_cruise_55', ...

 'fuel_mile_cruise_65', ...

 'fuel_mile_total_55', ...

 'fuel_mile_total_65', ...

 'fuel_mile_total_trans', ...

 'gal2co2', ...

 'gal2lit', ...

 'gptm_weighted', ...

 'idle_reduce', ...

 'idx_tf_55', ...

 'idx_tf_65', ...

 'idx_ti_55', ...

 'idx_ti_65', ...

 'kg2ton', ...

 'lb2ton', ...

 'mi2mtr', ...

 'mpg_cruise_55', ...

 'mpg_cruise_65', ...

 'mpg_total_55', ...

 'mpg_total_65', ...

 'mpg_total_trans', ...

 'mpg_weighted', ...

 'mps2mph', ...

 'num_err_plus2mph', ...

 'payload', ...

 'per_err_55', ...

 'per_err_65', ...

 'per_err_trans', ...

 'rpm2rps', ...

 'rps2rpm', ...

 'single_sim', ...

 'speed_limit', ...

 'trans', ...

 'veh_spd_err', ...

 'veh_type', ...

 'veh_year', ...

 'vehicle', ...

 'vehicle_chassis_spd_out', ...

 'weight_55mph', ...

 'weight_65mph', ...

 'weight_reduce', ...

 'weight_trans'

 };

 cmd=['assignin(' '''caller''' ',' '''varInfo''' ',' 'whos' ')'];

 evalin('base', cmd);

 

 % Find all the tunable parameters in the base workspace and 

 % create a copy in this functions workspace
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 59 of 103

 for i0=1:length(varInfo)

 res=strcmp(tunableParams,varInfo(i0).name);

 nameIndx = find(res,1);

 if ~isempty(nameIndx)

 cmd=['assignin(' '''caller''' ',' '''' varInfo(i0).name '''' ',' varInfo(i0).

name ')']; 

 evalin('base', cmd);

 end

 end

 paramDescFid = fopen('mprm.txt', 'w+');

 paramDataFid = fopen('mprm.bin', 'w');

 %disp([which('mprm.txt') ' and ' which('mprm.bin') ' opened']);

 

 % Process all the tunable parameters and create the paramTable structure

 % array

 parentList = {};

 for i0=1:length(varInfo)

 res=strcmp(tunableParams,varInfo(i0).name);

 nameIndx = find(res,1);

 if ~isempty(nameIndx)

 if isstruct(eval(varInfo(i0).name))

 strct = eval(varInfo(i0).name);

 parentList{1} = varInfo(i0).name; %#ok<AGROW>

 iOutputStructInfo(parentList, strct);

 else

 parentList = [];

 iOutputVarInfo(parentList, varInfo(i0)); 

 end

 end

 end

 fprintf(paramDescFid, '%d\n', length(paramTable));

 for i=1:length(paramTable)

 if ~iscell(paramTable(i).data)

 byteOffset = ftell(paramDataFid);

 fwrite(paramDataFid, paramTable(i).data, class(paramTable(i).data)); 

 fprintf(paramDescFid, '%s %d %d\n', paramTable(i).name, byteOffset, paramTable

(i).numBytes);

 else

 disp('Cell parameter not supported');

 end 

 end

 byteOffset = ftell(paramDataFid);

 %disp([ 'size of bin file is: ', num2str(byteOffset)]);

 fclose(paramDescFid);

 fclose(paramDataFid);

 %disp('mprm.txt and mprm.bin created');

 %disp(['num params is: ' num2str(length(paramTable))]);

end

function iOutputVarInfo(parentList, varInfo)

 if ~isempty(parentList)
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 60 of 103

 %If this is a strucuture field, creae the structure in this

 %functions workspace first

 cmd=['assignin(' '''caller''' ',' '''' parentList{1} '''' ',' parentList{1} 

')'];

 evalin('base', cmd);

 else

 %If this is a non structure variable, first create the variable in

 %this function's workspace

 cmd=['assignin(' '''caller''' ',' '''' varInfo.name '''' ',' varInfo.name ')'];

 evalin('base', cmd);

 end 

 

 simName = '';

 for i1=1:length(parentList)

 if i1 == 1

 simName = parentList{1};

 else

 simName = [simName '.' parentList{i1}]; %#ok<AGROW>

 end

 end

 if ~isempty(simName)

 simName = [simName '.' varInfo.name];

 else

 simName = varInfo.name;

 end

 addToParamTable(simName, varInfo.bytes,eval(simName));

end

function addToParamTable(varName, numBytes,data)

 global paramTable;

 paramTable(end+1).name = varName;

 paramTable(end).numBytes = numBytes;

 paramTable(end).data = data;

 if isempty(strfind(varName, '.'))

 paramTable(end).isStructField = false;

 paramTable(end).flattenedName = [];

 else

 paramTable(end).isStructField = true;

 paramTable(end).flattenedName = strrep(varName,'.', '_');

 end

 

end 

 

 

function iOutputStructInfo(parentList, var)

 %Create the toplevel structure in this function's workspace 

 cmd=['assignin(' '''caller''' ',' '''' parentList{1} '''' ',' parentList{1} ')'];

 evalin('base', cmd);

 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 61 of 103

 structCell = fieldnames(var);

 fieldPrefix = '';

 for i1=1:length(parentList)

 if i1==1 

 fieldPrefix = parentList{i1};

 else

 fieldPrefix = [fieldPrefix '.' parentList{i1}]; %#ok<AGROW>

 end

 end

 

 % Create the struct in this functions workspace

 parentIndex = length(parentList) + 1;

 for i1=1:length(structCell) 

 structFieldName = [fieldPrefix '.' structCell{i1}];

 

 cmd=['assignin(' '''caller''' ',' '''xxxtempFieldNamexxx''' ',' structFieldName 

')'];

 evalin('base', cmd); 

 

 if isstruct(xxxtempFieldNamexxx)

 

 parentList{parentIndex} = structCell{i1}; 

 

 iOutputStructInfo (parentList, xxxtempFieldNamexxx);

 

 else

 fieldName = structCell{i1};

 xxxtempFieldxxx = eval([fieldPrefix '.' fieldName]); %#ok<NASGU>

 fieldInfo = whos('xxxtempFieldxxx');

 fieldInfo.name = structCell{i1}; % The name needs to be that of the origial 

variable 

 iOutputVarInfo(parentList, fieldInfo);

 end 

 end

 

end

function epa_set_config

 cs=getActiveConfigSet(bdroot);

 model_M = sprintf(' &(rtmGetDataMapInfo(%s_M).mmi);', bdroot);

 cs.set_param('CustomHeaderCode', ' extern int epa_load_params

(rtwCAPI_ModelMappingInfo *capiMap );'); % Header file 

 cs.set_param('CustomInitializer', sprintf('%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%

s\n%s\n%s\n%s\n%s','{',' /* Get CAPI Mapping structure from Real-Time Model structure 

*/',' rtwCAPI_ModelMappingInfo* capiMap = ', model_M,' /* Get number of Model 

Parameters from capiMap */',' uint_T nModelParams = rtwCAPI_GetNumModelParameters

(capiMap);','',' if (nModelParams == 0) {',' printf("No Tunable Model Parameters 

in the model \n");',' }',' else {',' /* call print utility function */',' 

epa_load_params(capiMap );',' }','}')); % Initialize function 

 cs.set_param('CustomSource', 'epa_param.c'); % Source files 

% includePath = sprintf('%s/rtw/c/src', matlabroot);
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 62 of 103

% cs.set_param('CustomInclude', includePath); % Include directories 

 

 % Set the CAPI on

 cs.set_param('RTWCAPIParams', 'on'); % parameters 

 cs.set_param('RTWCAPIRootIO', 'off'); % root-level I/O 

 cs.set_param('RTWCAPISignals', 'on'); % signals 

 cs.set_param('RTWCAPIStates', 'off'); % states 

 

 clear rt_*;

%clear syscmd;

epa_serialize_params;

%disp('Starting simulation');

if ((veh_type >=1) && (veh_type <=6)) || (veh_type == 10)

 syscmd = sprintf ('GEM_1_6.exe -tf %f', sim_stop_time);

elseif (veh_type >= 7) && (veh_type <= 9)

 syscmd = sprintf ('GEM_7_9.exe -tf %f', sim_stop_time);

elseif (veh_type == 10)

 syscmd = sprintf ('GEM_10.exe -tf %f', sim_stop_time);

elseif (veh_type == 11)

 syscmd = sprintf ('GEM_11.exe -tf %f', sim_stop_time);

elseif (veh_type == 12)

 syscmd = sprintf ('GEM_12.exe -tf %f', sim_stop_time);

end

%syscmd = sprintf('GEM_manual_v2.exe -tf %f', sim_stop_time);

[status, res] = system(syscmd);

clear syscmd;

%disp(['Simulation completed. Status is: ' num2str(status)]);

if status == 0

 load GEM_manual_v2.mat

 driver_veh_spd_des = rt_driver_veh_spd_des;

 engine_fuel_flowrate = rt_engine_fuel_flowrate;

 total_sim_time = rt_total_sim_time;

 vehicle_chassis_spd_out = rt_vehicle_chassis_spd_out;

else

 %disp ('Simulation failed');

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% HD Truck Compliance Model User Interface

% - Define GUI window

%

% - Created by Byungho Lee on 6/16/2010

% - Edited by Lisandro Quinones on 7/12/2010

% - Edited by Lisandro Quinones on 5/23/2011

%

% - Assessment & Standards Division

% Office of Transportation & Air Quality

% US Environmental Protection Agency

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 63 of 103

function varargout = GEM(varargin)

global i_sim veh_type veh_year c_d c_rr_steer c_rr_drive

global speed_limit weight_reduce idle_reduce plot_output 

global single_sim batch_sim batch_n

global manufacturer_name vehicle_family vehicle_config date_sim

global use_generated_code error_flag reset_GEM reset_on file_xls file_xlsx

% GEM M-file for GEM.fig

% GEM, by itself, creates a new GEM or raises the existing

% singleton*.

%

% H = GEM returns the handle to a new GEM or the handle to

% the existing singleton*.

%

% GEM('CALLBACK',hObject,eventData,handles,...) calls the local

% function named CALLBACK in GEM.M with the given input arguments.

%

% GEM('Property','Value',...) creates a new GEM or raises the

% existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before GEM_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to GEM_OpeningFcn via varargin.

%

% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one

% instance to run (singleton)".

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GEM

% Last Modified by GUIDE v2.5 14-Sep-2010 09:12:27

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

 'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @GEM_OpeningFcn, ...

'gui_OutputFcn', @GEM_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

 gui_State.gui_Callback = str2func(varargin{1});

end

if nargout

 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

 gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 64 of 103

% --- Executes just before GEM is made visible.

function GEM_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to GEM (see VARARGIN)

% Choose default command line output for GEM

handles.output = hObject;

set(handles.GEM_buttongroup1,'SelectionChangeFcn',@GEM_buttongroup1_SelectionChangeFcn);

set(handles.GEM_buttongroup2,'SelectionChangeFcn',@GEM_buttongroup2_SelectionChangeFcn);

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes GEM wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = GEM_OutputFcn(hObject, eventdata, handles) 

% varargout cell array for returning output args (see VARARGOUT);

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

set(handles.radiobutton1,'Enable','Off')

 set(handles.radiobutton1,'Value',0)

 set(handles.radiobutton2,'Enable','Off')

 set(handles.radiobutton2,'Value',0)

 set(handles.radiobutton3,'Enable','Off')

 set(handles.radiobutton3,'Value',0)

 set(handles.radiobutton4,'Enable','Off')

 set(handles.radiobutton4,'Value',0)

 set(handles.radiobutton5,'Enable','Off')

 set(handles.radiobutton5,'Value',0)

 set(handles.radiobutton6,'Enable','Off')

 set(handles.radiobutton6,'Value',0)

 set(handles.radiobutton7,'Enable','Off')

 set(handles.radiobutton7,'Value',0)

 set(handles.radiobutton8,'Enable','Off')

 set(handles.radiobutton8,'Value',0)

 set(handles.radiobutton9,'Enable','Off')

 set(handles.radiobutton9,'Value',0)

 set(handles.radiobutton10,'Enable','Off')

 set(handles.radiobutton10,'Value',0)
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 65 of 103

 set(handles.radiobutton11,'Enable','Off')

 set(handles.radiobutton11,'Value',0)

 set(handles.radiobutton12,'Enable','Off')

 set(handles.radiobutton12,'Value',0)

% Get default command line output from handles structure

varargout{1} = handles.output;

function GEM_buttongroup1_SelectionChangeFcn(hObject, eventdata)

global i_sim veh_type veh_year c_d c_rr_steer c_rr_drive

global speed_limit weight_reduce idle_reduce plot_output 

global single_sim batch_sim batch_n

global manufacturer_name vehicle_family vehicle_config date_sim

global use_generated_code error_flag reset_GEM reset_on file_xls file_xlsx

% Retrieve GUI data, i.e. the handles structure

handles = guidata(hObject); 

switch get(eventdata.NewValue,'Tag') % Get Tag of selected object

 case 'radiobutton1'

 veh_type = 1;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','')

 set(handles.edit6,'Enable','On')

 set(handles.edit10,'String',date)

 

 case 'radiobutton2'

 veh_type = 2;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 66 of 103

 set(handles.edit6,'Enable','On')

 set(handles.edit10,'String',date)

 

 case 'radiobutton3'

 veh_type = 3;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','')

 set(handles.edit6,'Enable','On')

 set(handles.edit10,'String',date)

 

 case 'radiobutton4'

 veh_type = 4;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','0')

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 case 'radiobutton5'

 veh_type = 5;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','0')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 67 of 103

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 case 'radiobutton6'

 veh_type = 6;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','0')

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 case 'radiobutton7'

 veh_type = 7;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','0')

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 case 'radiobutton8'

 veh_type = 8;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','0')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 68 of 103

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 case 'radiobutton9'

 veh_type = 9;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','0')

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 case 'radiobutton10'

 veh_type = 10;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','0.7')

 set(handles.edit1,'Enable','Off')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','0')

 set(handles.edit4,'Enable','Off')

 set(handles.edit5,'String','0')

 set(handles.edit5,'Enable','Off')

 set(handles.edit6,'String','0')

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 case 'radiobutton11'

 veh_type = 11;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','0.6')

 set(handles.edit1,'Enable','Off')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','0')

 set(handles.edit4,'Enable','Off')

 set(handles.edit5,'String','0')

 set(handles.edit5,'Enable','Off')

 set(handles.edit6,'String','0')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 69 of 103

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 case 'radiobutton12'

 veh_type = 12;

 assignin('base','veh_type', veh_type);

 set(handles.edit1,'String','0.6')

 set(handles.edit1,'Enable','Off')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','0')

 set(handles.edit4,'Enable','Off')

 set(handles.edit5,'String','0')

 set(handles.edit5,'Enable','Off')

 set(handles.edit6,'String','0')

 set(handles.edit6,'Enable','Off')

 set(handles.edit10,'String',date)

 

 otherwise

 % Code for when there is no match.

end

% Updates the handles structure

guidata(hObject, handles);

function GEM_buttongroup2_SelectionChangeFcn(hObject, eventdata)

global i_sim veh_type veh_year c_d c_rr_steer c_rr_drive

global speed_limit weight_reduce idle_reduce plot_output 

global single_sim batch_sim batch_n

global manufacturer_name vehicle_family vehicle_config date_sim

global use_generated_code error_flag reset_GEM reset_on file_xls file_xlsx

% Retrieve GUI data, i.e. the handles structure

handles = guidata(hObject); 

switch get(eventdata.NewValue,'Tag') % Get Tag of selected object

 case 'radiobutton13'

 single_sim = 1;

 set(handles.radiobutton13,'BackgroundColor','white');

 set(handles.radiobutton14,'BackgroundColor','white');

 set(handles.checkbox1,'BackgroundColor','white');

 set(handles.pushbutton1,'Enable','on')

 assignin('base','single_sim', single_sim);

 

 if reset_on == 1,

 clc

 elseif reset_on == 0,

 set(handles.edit1,'String','')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 70 of 103

 set(handles.edit1,'Enable','On')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','On')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','On')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','On')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','On')

 set(handles.edit6,'String','')

 set(handles.edit6,'Enable','On')

 set(handles.edit7,'String','')

 set(handles.edit7,'Enable','On')

 set(handles.edit8,'String','')

 set(handles.edit8,'Enable','On')

 set(handles.edit9,'String','')

 set(handles.edit9,'Enable','On')

 end

 

 batch_sim = 0;

 

 set(handles.checkbox1,'Enable','On')

 set(handles.radiobutton1,'Enable','On')

 set(handles.radiobutton2,'Enable','On')

 set(handles.radiobutton3,'Enable','On')

 set(handles.radiobutton4,'Enable','On')

 set(handles.radiobutton5,'Enable','On')

 set(handles.radiobutton6,'Enable','On')

 set(handles.radiobutton7,'Enable','On')

 set(handles.radiobutton8,'Enable','On')

 set(handles.radiobutton9,'Enable','On')

 set(handles.radiobutton10,'Enable','On')

 set(handles.radiobutton11,'Enable','On')

 set(handles.radiobutton12,'Enable','On')

 set(handles.edit10,'String',date)

 set(handles.popupmenu1,'Enable','On')

 set(handles.popupmenu1,'String',{'';'2013';'2014';'2015';'2016';'2017 and 

later'})

 set(handles.text1,'Enable','On')

 set(handles.text2,'Enable','On')

 set(handles.text3,'Enable','On')

 set(handles.text4,'Enable','On')

 set(handles.text5,'Enable','On')

 set(handles.text6,'Enable','On')

 set(handles.text7,'Enable','On')

 set(handles.text8,'Enable','On')

 set(handles.text9,'Enable','On')

 set(handles.text_pop,'Enable','On')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 71 of 103

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0])

 

 clc

 

 case 'radiobutton14'

 batch_sim = 1;

 set(handles.radiobutton13,'BackgroundColor','white');

 set(handles.radiobutton14,'BackgroundColor','white');

 set(handles.checkbox1,'BackgroundColor','white')

 

 assignin('base','batch_sim', batch_sim);

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','Off')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','Off')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','Off')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','Off')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','Off')

 set(handles.edit6,'String','')

 set(handles.edit6,'Enable','Off')

 set(handles.edit7,'String','')

 set(handles.edit7,'Enable','Off')

 set(handles.edit8,'String','')

 set(handles.edit8,'Enable','Off')

 set(handles.edit9,'String','')

 set(handles.edit9,'Enable','Off')

 

 single_sim = 0;

 

 set(handles.checkbox1,'Enable','Off')

 set(handles.radiobutton1,'Enable','Off')

 set(handles.radiobutton1,'Value',0)

 set(handles.radiobutton2,'Enable','Off')

 set(handles.radiobutton2,'Value',0)

 set(handles.radiobutton3,'Enable','Off')

 set(handles.radiobutton3,'Value',0)

 set(handles.radiobutton4,'Enable','Off')

 set(handles.radiobutton4,'Value',0)

 set(handles.radiobutton5,'Enable','Off')

 set(handles.radiobutton5,'Value',0)

 set(handles.radiobutton6,'Enable','Off')

 set(handles.radiobutton6,'Value',0)

 set(handles.radiobutton7,'Enable','Off')

 set(handles.radiobutton7,'Value',0)

 set(handles.radiobutton8,'Enable','Off')

 set(handles.radiobutton8,'Value',0)

 set(handles.radiobutton9,'Enable','Off')

 set(handles.radiobutton9,'Value',0)
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 72 of 103

 set(handles.radiobutton10,'Enable','Off')

 set(handles.radiobutton10,'Value',0)

 set(handles.radiobutton11,'Enable','Off')

 set(handles.radiobutton11,'Value',0)

 set(handles.radiobutton12,'Enable','Off')

 set(handles.radiobutton12,'Value',0)

 set(handles.radiobutton13,'Enable','Off')

 set(handles.radiobutton13,'Value',0)

 set(handles.checkbox1,'Value',0)

 set(handles.edit10,'String',date)

 set(handles.popupmenu1,'Enable','Off')

 set(handles.popupmenu1,'String','')

 set(handles.text1,'Enable','Off')

 set(handles.text2,'Enable','Off')

 set(handles.text3,'Enable','Off')

 set(handles.text4,'Enable','Off')

 set(handles.text5,'Enable','Off')

 set(handles.text6,'Enable','Off')

 set(handles.text7,'Enable','Off')

 set(handles.text8,'Enable','Off')

 set(handles.text9,'Enable','Off')

 set(handles.text_pop,'Enable','Off')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0])

 

 clc

 

 if file_xls == file_xlsx,

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Results File Format.';

 ms4 = {''};

 ms5 = 'Select a file format and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 end

 

 

 set(handles.pushbutton1,'Enable','inactive') 

 evalin('base','run run_GEM_input')

 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 73 of 103

 if error_flag == 1,

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RESET')

 set(handles.pushbutton1,'BackgroundColor','yellow')

 set(handles.checkbox1,'BackgroundColor','white')

 elseif error_flag == 0,

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN BATCH')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0])

 end

 otherwise

 % Code for when there is no match.

end

% Updates the handles structure

guidata(hObject, handles);

% --- Executes on button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles)

global i_sim veh_type veh_year c_d c_rr_steer c_rr_drive

global speed_limit weight_reduce idle_reduce plot_output 

global single_sim batch_sim batch_n

global manufacturer_name vehicle_family vehicle_config date_sim

global use_generated_code error_flag reset_GEM reset_on

% hObject handle to pushbutton1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

if error_flag == 1,

 evalin('base','run run_reset')

 return

end 

if reset_GEM == 1,

 evalin('base','run run_reset')

 return

end

set(handles.pushbutton1,'FontSize',24.5)

set(handles.pushbutton1,'Enable','inactive') 

set(handles.pushbutton1,'String','RUNNING...')

set(handles.pushbutton1,'BackgroundColor','white')

set(handles.popupmenu1,'BackgroundColor','white')

set(handles.edit1,'BackgroundColor','white')

set(handles.edit2,'BackgroundColor','white')

set(handles.edit3,'BackgroundColor','white')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 74 of 103

set(handles.edit4,'BackgroundColor','white')

set(handles.edit5,'BackgroundColor','white')

set(handles.edit6,'BackgroundColor','white')

set(handles.radiobutton1,'BackgroundColor','white')

set(handles.radiobutton2,'BackgroundColor','white')

set(handles.radiobutton3,'BackgroundColor','white')

set(handles.radiobutton4,'BackgroundColor','white')

set(handles.radiobutton5,'BackgroundColor','white')

set(handles.radiobutton6,'BackgroundColor','white')

set(handles.radiobutton7,'BackgroundColor','white')

set(handles.radiobutton8,'BackgroundColor','white')

set(handles.radiobutton9,'BackgroundColor','white')

set(handles.radiobutton10,'BackgroundColor','white')

set(handles.radiobutton11,'BackgroundColor','white')

set(handles.radiobutton12,'BackgroundColor','white')

% Assign Vehicle Parameters to Proper Variable Names:

if single_sim == 1,

 

 % ... vehicle model year

 veh_year = get(handles.popupmenu1);

 assignin('base','veh_year', veh_year.Value);

 % ... coefficient of aerodynamic drag

 c_d = get(handles.edit1,'String');

 c_d = str2num(c_d);

 assignin('base','c_d', c_d);

 % ... steer tire rolling resistance (kg/ton)

 c_rr_steer = get(handles.edit2,'String');

 c_rr_steer = str2num(c_rr_steer);

 assignin('base','c_rr_steer', c_rr_steer*1e-3);

 % ... drive tire rolling resistance (kg/ton)

 c_rr_drive = get(handles.edit3,'String');

 c_rr_drive = str2num(c_rr_drive);

 assignin('base','c_rr_drive', c_rr_drive*1e-3);

 % ... vehicle speed limiter (mph)

 speed_limit = get(handles.edit4,'String');

 speed_limit = str2num(speed_limit);

 assignin('base','speed_limit', speed_limit);

 % ... weight reduction (lb)

 weight_reduce = get(handles.edit5,'String');

 weight_reduce = str2num(weight_reduce);

 assignin('base','weight_reduce', weight_reduce);

 % ... credits from extended idle reduction technology (g/ton-mile)

 idle_reduce = get(handles.edit6,'String');

 idle_reduce = str2num(idle_reduce);
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 75 of 103

 assignin('base','idle_reduce', idle_reduce);

 

 % ... manufacturer name

 manufacturer_name = get(handles.edit7,'String');

 assignin('base','manufacturer_name', manufacturer_name);

 % ... vehicle family

 vehicle_family = get(handles.edit8,'String');

 assignin('base','vehicle_family', vehicle_family);

 % ... vehicle configuration

 vehicle_config = get(handles.edit9,'String');

 assignin('base','vehicle_config', vehicle_config);

 % ... date

 date_sim = get(handles.edit10,'String');

 assignin('base','date_sim', date_sim);

 % ... check box for plot_output

 plot_output = get(handles.checkbox1);

 assignin('base','plot_output', plot_output.Value);

 

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Heavy-Duty Truck Simulation for Single and Multiple Configurations

% - Run GEM (GHG Emissions Model) according to user inputs

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Initialize Workspace

clc

% Check Validity of User Inputs

%... simulation type

if single_sim == 0 & batch_sim == 0 & reset_on == 0,

 set(handles.radiobutton13,'BackgroundColor','red')

 set(handles.radiobutton14,'BackgroundColor','red')

 set(handles.checkbox1,'BackgroundColor','red')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Simulation Type.';

 ms4 = {''};

 ms5 = 'Select a simulation type and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 76 of 103

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

elseif single_sim == 0 & batch_sim == 0 & reset_on == 1,

 set(handles.radiobutton13,'BackgroundColor','red');

 set(handles.radiobutton14,'BackgroundColor','red');

 set(handles.checkbox1,'BackgroundColor','red')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Simulation Type.';

 ms4 = {''};

 ms5 = 'Select a simulation type and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

elseif single_sim == 1 & reset_on == 1,

 set(handles.radiobutton13,'BackgroundColor','white');

 set(handles.radiobutton14,'BackgroundColor','white');

 set(handles.checkbox1,'BackgroundColor','white')

 

end

if single_sim == 1,

 %... vehicle model year

 if veh_year == 1

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.popupmenu1,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Vehicle Model Year.';

 ms4 = {''};

 ms5 = 'Select a year from the drop down menu and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 end
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 77 of 103

 %... vehicle regulatory class

 if veh_type < 1 || veh_type > 12

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Regulatory Subcategory.';

 ms4 = {''};

 ms5 = 'Select a subcategory from the list and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.radiobutton1,'BackgroundColor','red')

 set(handles.radiobutton2,'BackgroundColor','red')

 set(handles.radiobutton3,'BackgroundColor','red')

 set(handles.radiobutton4,'BackgroundColor','red')

 set(handles.radiobutton5,'BackgroundColor','red')

 set(handles.radiobutton6,'BackgroundColor','red')

 set(handles.radiobutton7,'BackgroundColor','red')

 set(handles.radiobutton8,'BackgroundColor','red')

 set(handles.radiobutton9,'BackgroundColor','red')

 set(handles.radiobutton10,'BackgroundColor','red')

 set(handles.radiobutton11,'BackgroundColor','red')

 set(handles.radiobutton12,'BackgroundColor','red')

 return

 end

 %... coefficient of aerodynamic drag

 

 if isempty(c_d) == 1

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit1,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Coefficient of Aerodynamic Drag.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 78 of 103

 return

 

 while c_d <= 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit1,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Coefficient of Aerodynamic Drag.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 set(handles.edit1,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 set(handles.edit1,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0])

 end

 

 while c_d <= 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit1,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Coefficient of Aerodynamic Drag.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 79 of 103

 set(handles.edit1,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 

 % ... steer tire rolling resistance (kg/ton)

 if isempty(c_rr_steer) == 1

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit2,'BackgroundColor','red')

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Steer Tire Rolling Resistance.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 while c_rr_steer <= 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit2,'BackgroundColor','red')

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Steer Tire Rolling Resistance.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit2,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 set(handles.edit2,'BackgroundColor','white')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 80 of 103

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0])

 end

 

 while c_rr_steer <= 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit2,'BackgroundColor','red')

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Steer Tire Rolling Resistance.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit2,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 

 % ... drive tire rolling resistance (kg/ton)

 if isempty(c_rr_drive) == 1

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit3,'BackgroundColor','red')

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Drive Tire Rolling Resistance.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 while c_rr_drive <= 0
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 81 of 103

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit3,'BackgroundColor','red')

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Drive Tire Rolling Resistance.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit3,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 set(handles.edit3,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0])

 end

 

 while c_rr_drive <= 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit3,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Drive Tire Rolling Resistance.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit3,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 82 of 103

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 

 % ... vehicle speed limiter (m/s)

 if isempty(speed_limit) == 1

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit4,'BackgroundColor','red')

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Vehicle Speed Limiter.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 while speed_limit < 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit4,'BackgroundColor','red')

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Vehicle Speed Limiter.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit4,'String',speed_limit)

 set(handles.edit4,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 set(handles.edit4,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 83 of 103

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0])

 end

 

 while speed_limit < 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit4,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Vehicle Speed Limiter.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit4,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 % ... vehicle weight reduction (lb)

 if isempty(weight_reduce) == 1

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit5,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Vehicle Weight Reduction.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 while weight_reduce < 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 84 of 103

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit5,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Vehicle Weight Reduction.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit5,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 end

 set(handles.edit5,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0])

 end

 

 while weight_reduce < 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit5,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Vehicle Weight Reduction.';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit5,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 85 of 103

 end

 

 %... idle reduction CO2 credit (g/ton-mile)

 if isempty(idle_reduce) == 1

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit6,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Extended Idle Reduction';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 while idle_reduce < 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit6,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Extended Idle Reduction';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit6,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 

 end

 set(handles.edit6,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 86 of 103

 

 end

 

 while idle_reduce < 0

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor','red')

 set(handles.edit6,'BackgroundColor','red')

 

 ms1 = 'ERROR';

 ms2 = {''};

 ms3 = 'Invalid input for Extended Idle Reduction';

 ms4 = {''};

 ms5 = 'Enter a valid input and click RUN.';

 ms6 = {''};

 msg_input = [ms1; ms2; ms3; ms4; ms5; ms6];

 msgbox(msg_input,...

 'Greenhouse Gas Emissions Model (GEM)','error');

 return

 

 set(handles.edit6,'BackgroundColor','white')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RUN')

 set(handles.pushbutton1,'BackgroundColor',[0,0.5,0]) 

 

 end 

end

% Close all plots before the next simulation

evalin('base','figure(1); close(1)')

evalin('base','figure(2); close(2)')

evalin('base','figure(3); close(3)')

if single_sim == 1,

 % Perform Pre-Processing for Simulation

 evalin('base','run run_preproc')

 % Perform Transient Cycle Simulation

 evalin('base','run run_transient')

 % Perform 55 mph Steady-State Cycle Simulation

 evalin('base','run run_55mph')

 % Perform 65 mph Steady-State Cycle Simulation

 evalin('base','run run_65mph')

 

 % Perform Cycle-Weighted Result Calculation

 evalin('base','run run_postproc')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 87 of 103

 

 set(handles.edit1,'Enable','Off')

 set(handles.edit2,'Enable','Off')

 set(handles.edit3,'Enable','Off')

 set(handles.edit4,'Enable','Off')

 set(handles.edit5,'Enable','Off')

 set(handles.edit6,'Enable','Off')

 set(handles.edit7,'Enable','Off')

 set(handles.edit8,'Enable','Off')

 set(handles.edit9,'Enable','Off')

 set(handles.edit10,'Enable','Off')

 set(handles.popupmenu1,'Enable','Off')

 set(handles.checkbox1,'Enable','Off')

 set(handles.radiobutton1,'Enable','Off')

 set(handles.radiobutton2,'Enable','Off')

 set(handles.radiobutton3,'Enable','Off')

 set(handles.radiobutton4,'Enable','Off')

 set(handles.radiobutton5,'Enable','Off')

 set(handles.radiobutton6,'Enable','Off')

 set(handles.radiobutton7,'Enable','Off')

 set(handles.radiobutton8,'Enable','Off')

 set(handles.radiobutton9,'Enable','Off')

 set(handles.radiobutton10,'Enable','Off')

 set(handles.radiobutton11,'Enable','Off')

 set(handles.radiobutton12,'Enable','Off')

 set(handles.radiobutton14,'Enable','Off')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'String','WRITING...')

 set(handles.pushbutton1,'BackgroundColor','white')

 

 if error_flag ==1,

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RESET')

 set(handles.pushbutton1,'BackgroundColor','yellow')

 end

 

 % Perform Results File

 evalin('base','run run_GEM_output')

 

 % Perform Result Notification

 evalin('base','run run_result_notification')

 

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RESET')

 set(handles.pushbutton1,'BackgroundColor','yellow')

 

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 88 of 103

% END OF SINGLE CONFIGURATION SIMULATION

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if batch_sim == 1,

 % Perform Muiltiple Configurations (Batch Mode)

 evalin('base','run run_sim_batch')

 

 set(handles.edit1,'Enable','Off')

 set(handles.edit2,'Enable','Off')

 set(handles.edit3,'Enable','Off')

 set(handles.edit4,'Enable','Off')

 set(handles.edit5,'Enable','Off')

 set(handles.edit6,'Enable','Off')

 set(handles.edit7,'Enable','Off')

 set(handles.edit8,'Enable','Off')

 set(handles.edit9,'Enable','Off')

 set(handles.edit10,'Enable','Off')

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'String','WRITING...')

 set(handles.pushbutton1,'BackgroundColor','white')

 

 % Perform Results File

 evalin('base','run run_GEM_output')

 

 % Perform Result Notification

 evalin('base','run run_result_notification')

 

 set(handles.pushbutton1,'FontSize',24.5)

 set(handles.pushbutton1,'Enable','on')

 set(handles.pushbutton1,'String','RESET')

 set(handles.pushbutton1,'BackgroundColor','yellow') 

 set(handles.edit1,'String','')

 set(handles.edit1,'Enable','Off')

 set(handles.edit2,'String','')

 set(handles.edit2,'Enable','Off')

 set(handles.edit3,'String','')

 set(handles.edit3,'Enable','Off')

 set(handles.edit4,'String','')

 set(handles.edit4,'Enable','Off')

 set(handles.edit5,'String','')

 set(handles.edit5,'Enable','Off')

 set(handles.edit6,'String','')

 set(handles.edit6,'Enable','Off')

 set(handles.edit7,'String','')

 set(handles.edit7,'Enable','Off')

 set(handles.edit8,'String','')

 set(handles.edit8,'Enable','Off')

 set(handles.edit9,'String','')

 set(handles.edit9,'Enable','Off')

 set(handles.checkbox1,'Enable','Off')

 set(handles.radiobutton1,'Enable','Off')
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 89 of 103

 set(handles.radiobutton1,'Value',0)

 set(handles.radiobutton2,'Enable','Off')

 set(handles.radiobutton2,'Value',0)

 set(handles.radiobutton3,'Enable','Off')

 set(handles.radiobutton3,'Value',0)

 set(handles.radiobutton4,'Enable','Off')

 set(handles.radiobutton4,'Value',0)

 set(handles.radiobutton5,'Enable','Off')

 set(handles.radiobutton5,'Value',0)

 set(handles.radiobutton6,'Enable','Off')

 set(handles.radiobutton6,'Value',0)

 set(handles.radiobutton7,'Enable','Off')

 set(handles.radiobutton7,'Value',0)

 set(handles.radiobutton8,'Enable','Off')

 set(handles.radiobutton8,'Value',0)

 set(handles.radiobutton9,'Enable','Off')

 set(handles.radiobutton9,'Value',0)

 set(handles.radiobutton10,'Enable','Off')

 set(handles.radiobutton10,'Value',0)

 set(handles.radiobutton11,'Enable','Off')

 set(handles.radiobutton11,'Value',0)

 set(handles.radiobutton12,'Enable','Off')

 set(handles.radiobutton12,'Value',0)

 set(handles.checkbox1,'Value',0)

 set(handles.edit10,'String',date)

 set(handles.popupmenu1,'Enable','Off')

 set(handles.popupmenu1,'String','')

 set(handles.text1,'Enable','Off')

 set(handles.text2,'Enable','Off')

 set(handles.text3,'Enable','Off')

 set(handles.text4,'Enable','Off')

 set(handles.text5,'Enable','Off')

 set(handles.text6,'Enable','Off')

 set(handles.text7,'Enable','Off')

 set(handles.text8,'Enable','Off')

 set(handles.text9,'Enable','Off')

 set(handles.text_pop,'Enable','Off')

 

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% END OF MULTIPLE CONFIGURAITIONS SIMULATION

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function edit1_Callback(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text

% str2double(get(hObject,'String')) returns contents of edit1 as a double
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 90 of 103

% --- Executes during object creation, after setting all properties.

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit2_Callback(hObject, eventdata, handles)

% hObject handle to edit2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text

% str2double(get(hObject,'String')) returns contents of edit2 as a double

% --- Executes during object creation, after setting all properties.

function edit2_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit3_Callback(hObject, eventdata, handles)

% hObject handle to edit3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text

% str2double(get(hObject,'String')) returns contents of edit3 as a double

% --- Executes during object creation, after setting all properties.

function edit3_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 91 of 103

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit4_Callback(hObject, eventdata, handles)

% hObject handle to edit4 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text

% str2double(get(hObject,'String')) returns contents of edit4 as a double

% --- Executes during object creation, after setting all properties.

function edit4_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit4 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit5_Callback(hObject, eventdata, handles)

% hObject handle to edit5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text

% str2double(get(hObject,'String')) returns contents of edit5 as a double

% --- Executes during object creation, after setting all properties.

function edit5_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit6_Callback(hObject, eventdata, handles)

% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 92 of 103

% Hints: get(hObject,'String') returns contents of edit6 as text

% str2double(get(hObject,'String')) returns contents of edit6 as a double

% --- Executes during object creation, after setting all properties.

function edit6_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit7_Callback(hObject, eventdata, handles)

% hObject handle to edit7 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text

% str2double(get(hObject,'String')) returns contents of edit7 as a double

% --- Executes during object creation, after setting all properties.

function edit7_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit7 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit8_Callback(hObject, eventdata, handles)

% hObject handle to edit8 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text

% str2double(get(hObject,'String')) returns contents of edit8 as a double

% --- Executes during object creation, after setting all properties.

function edit8_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit8 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 93 of 103

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit9_Callback(hObject, eventdata, handles)

% hObject handle to edit9 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text

% str2double(get(hObject,'String')) returns contents of edit9 as a double

% --- Executes during object creation, after setting all properties.

function edit9_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit9 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

function edit10_Callback(hObject, eventdata, handles)

% hObject handle to edit10 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit10 as text

% str2double(get(hObject,'String')) returns contents of edit10 as a double

% --- Executes during object creation, after setting all properties.

function edit10_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit10 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

% --- Executes on selection change in popupmenu1.
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 94 of 103

function popupmenu1_Callback(hObject, eventdata, handles)

% hObject handle to popupmenu1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell 

array

% contents{get(hObject,'Value')} returns selected item from popupmenu1

% --- Executes during object creation, after setting all properties.

function popupmenu1_CreateFcn(hObject, eventdata, handles)

% hObject handle to popupmenu1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get

(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

end

/*

 * Copyright 2004-2008 The MathWorks, Inc.

 *

 * File: rtw_capi_examples.c $Revision: 1.1.4.3 $

 *

 * Abstract:

 * Provides utility functions to traverse and access RTW generated C-API

 * structures. The C-API structure types are provided in following 2 files.

 *

 * matlabroot/rtw/c/src/rtw_capi.h & rtw_modelmap.h

 *

 * The actual data structures arrays are generated by code generator in

 * <MODEL>_capi.c, where <MODEL> is the name of the model.

 * 

 * The functions provided in this file are

 * capi_PrintModelParameter - Prints a model parameter value to STDOUT

 */

#include "rtw_capi_examples.h"

#include <stddef.h>

#include <string.h>

#include <malloc.h>

#undef DEBUG_DUMP

/*

 * Function to read the param description file.

 */
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 95 of 103

#define MAX_LINE_SZ 256

#define PARAM_NAME_SIZE 4096

#define MAX_STRUCT_DEPTH 16

typedef struct fileDataTag{

 char_T *name;

 int_T isStruct;

 char_T *structElements[MAX_STRUCT_DEPTH];

 int_T numStructElements;

 int_T binFileOffset;

 int_T numBytes;

 int_T paramIdx; /* ParamIdx in the capiMap */

} fileDataT;

extern void processStructElem(

 const rtwCAPI_ModelMappingInfo *capiMap,

 const rtwCAPI_DataTypeMap *dataTypeMap, 

 const rtwCAPI_ElementMap *elementMap,

 void *paramAddress,

 char_T *paramName,

 int_T dataTypeIdx,

 fileDataT *fileDataPtr,

 int_T fileParamIdx,

 int_T structElemIdx,

 char_T *paramDataPtr

 );

static FILE *GBLfdump;

static FILE *GBLfdBin;

void associateParam(rtwCAPI_ModelMappingInfo *capiMap, fileDataT* fileDataPtr,int_T k)

{

 int_T paramIdx;

 const char_T *paramName;

 const char_T *fParamName;

 const rtwCAPI_ModelParameters* modelParams;

 #if 0

 printf("associateParam called\n");

 #endif

 modelParams = rtwCAPI_GetModelParameters(capiMap);

 fileDataPtr[k].paramIdx = -1;

 #if 0

 printf("Num Parameters %d\n",rtwCAPI_GetNumModelParameters(capiMap));

 #endif

 

 if (fileDataPtr[k].isStruct) {

 fParamName = fileDataPtr[k].structElements[0];

 }

 else {

 fParamName = fileDataPtr[k].name;

 } 

 for (paramIdx=0;paramIdx<(int_T)rtwCAPI_GetNumModelParameters(capiMap);paramIdx++) {
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 96 of 103

 /* Get modelParams, an array of rtwCAPI_ModelParameters structure */

 

 paramName = rtwCAPI_GetModelParameterName(modelParams, paramIdx);

 #if 0

 printf("paramName: %s paramIdx %d\n", paramName, paramIdx);

 #endif

 

 if (strcmp(fParamName, paramName) == 0) {

 fileDataPtr[k].paramIdx = paramIdx;

 #if 0

 printf("param found - param name: %s paramIdx %d\n", paramName, paramIdx);

 #endif

 return;

 }

 }

 #ifdef DEBUG_DUMP

 printf ("Parameter %s not found\n",fileDataPtr[k].name); 

 #endif

 

 

}

int_T getElementIndex(

 rtwCAPI_ElementMap *elementMap,

 int_T sIndex,

 int_T numElements, char_T *reqFieldName) 

{

 int_T i;

 

 for (i=sIndex; i<sIndex+numElements; i++) {

 if (strcmp(elementMap[i].elementName, reqFieldName) == 0) {

 #ifdef DEBUG_DUMP

 printf ("elementName found - %s\n", reqFieldName);

 #endif

 return i;

 }

 }

 return -1;

}

void setParamVal(rtwCAPI_ModelMappingInfo* capiMap, char_T *paramName,

 fileDataT *fileDataPtr, int_T fileParamIdx, 

 uchar_T *paramDataPtr) 

{ 

 void** dataAddrMap; 

 const rtwCAPI_ModelParameters* modelParams;

 uint_T addrIdx;

 const rtwCAPI_DataTypeMap* dataTypeMap;

 void* paramAddress;

 int_T paramIdx;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 97 of 103

 int dataOffset;

 

 

 paramIdx = fileDataPtr[fileParamIdx].paramIdx;

 

 dataTypeMap = rtwCAPI_GetDataTypeMap(capiMap);

 modelParams = rtwCAPI_GetModelParameters(capiMap);

 dataAddrMap = rtwCAPI_GetDataAddressMap(capiMap);

 addrIdx = rtwCAPI_GetModelParameterAddrIdx(modelParams,paramIdx);

 paramAddress= (void *) rtwCAPI_GetDataAddress(dataAddrMap,addrIdx);

 

 dataOffset = fileDataPtr[fileParamIdx].binFileOffset;

 fseek(GBLfdBin, dataOffset, SEEK_SET);

 fread(¶mDataPtr[dataOffset], 1,

 fileDataPtr[fileParamIdx].numBytes, 

 GBLfdBin);

 

 memcpy(paramAddress, ¶mDataPtr[dataOffset],

 fileDataPtr[fileParamIdx].numBytes);

 #ifdef DEBUG_DUMP

 fprintf(GBLfdump, "New scalar param -%s- set is: %f\n",paramName,*(double *)

paramAddress); 

 #endif

 }

int epa_load_params(rtwCAPI_ModelMappingInfo *capiMap )

{

 FILE *fd;

 char_T line[MAX_LINE_SZ];

 

 

 int_T i;

 char_T name[256];

 int_T size;

 int_T offset;

 

 int_T j;

 fileDataT *fileDataPtr;

 int_T numParams;

 int_T curParam=0;

 int_T k=0;

 int_T fileSz;

 void *paramAddress;
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 98 of 103

 int_T dataTypeIdx;

 const rtwCAPI_ModelParameters *modelParams;

 int_T paramIdx;

 const rtwCAPI_DataTypeMap *dataTypeMap;

 const rtwCAPI_ElementMap *elemMap;

 char_T *paramDataPtr;

 int_T addrIdx;

 const void** dataAddrMap;

 int_T itemsRead;

 int_T totalBytesRead;

 char_T *ptr;

 int_T count=0;

 

 modelParams = rtwCAPI_GetModelParameters(capiMap);

 dataAddrMap = rtwCAPI_GetDataAddressMap(capiMap);

 dataTypeMap = rtwCAPI_GetDataTypeMap(capiMap);

 elemMap = rtwCAPI_GetElementMap(capiMap);

 

 /* Open the parameter description file */

 fd = fopen("mprm.txt", "r");

 if (fd == NULL) {

 printf("Error openging parameter descriptor file\n");

 }

 else {

 #if 0

 printf("fopen succeeded %x\n", fd);

 #endif

 }

 #ifdef DEBUG_DUMP

 GBLfdump = fopen("dumpfile.txt", "wt+");

 #endif

 

 fgets(line, MAX_LINE_SZ, fd);

 sscanf(line, "%d\n", &numParams);

 #ifdef DEBUG_DUMP

 printf ("Number of parameters in mprm.txt is: %d\n", numParams);

 #endif

 fileDataPtr = (fileDataT *)malloc(sizeof(fileDataT)*numParams);

 /* Open the parameter data file */

 GBLfdBin = fopen("mprm.bin", "rb");

 fseek(GBLfdBin, 0L, SEEK_END);

 fileSz=ftell(GBLfdBin);

 rewind(GBLfdBin);

 #ifdef DEBUG_DUMP

 printf("file size is %d\n", fileSz);

 #endif

 

 /*
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 99 of 103

 * Malloc, memory for parameter data. All parameters are allocated here.

 */

 paramDataPtr = malloc(fileSz);

 

 ptr = (char_T *)paramDataPtr;

 totalBytesRead = 0;

 itemsRead=fread(paramDataPtr, 1 /*sizeof(char_T) */, 

 fileSz, GBLfdBin);

 #ifdef DEBUG_DUMP

 printf ("bytes red from bin file is %d\n", itemsRead);

 #endif

 for (i=0; i<numParams; i++) {

 fgets(line, MAX_LINE_SZ, fd);

 sscanf(line, "%s %d %d \n", name, &offset, &size);

 #ifdef DEBUG_DUMP

 printf("line read is: %s\n", line);

 printf("name: %s, offset %d, size %d\n", name, offset, size);

 #endif

 

 fileDataPtr[i].name = strdup(name);

 if (strchr(name, '.') != NULL) {

 j=0;

 fileDataPtr[i].binFileOffset = offset;

 fileDataPtr[i].isStruct = TRUE;

 fileDataPtr[i].numBytes = size;

 fileDataPtr[i].numStructElements = 0;

 fileDataPtr[i].structElements[j] = strdup(strtok(name, ".\n"));

 while (fileDataPtr[i].structElements[j] != NULL) {

 #ifdef DEBUG_DUMP

 printf("in do while %s %d\n", fileDataPtr[i].structElements[j], j );

 #endif

 fileDataPtr[i].structElements[++j] = strdup(strtok(NULL,".\n")); 

 }

 fileDataPtr[i].numStructElements = j; 

 }

 else {

 fileDataPtr[i].binFileOffset = offset;

 fileDataPtr[i].isStruct = FALSE;

 fileDataPtr[i].numBytes = size;

 fileDataPtr[i].numStructElements = 0;

 }

 }

 printf("Number of actual parameters read %d\n", i);

 for (k=0; k<numParams; k++) {

 #ifdef DEBUG_DUMP

 printf("Processing parameter %s, k is %d, numParams %d\n", fileDataPtr[k].name,k,

numParams);

 #endif

 

 associateParam(capiMap, fileDataPtr,k);
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 100 of 103

 

 if (fileDataPtr[k].paramIdx != -1) {

 /* 

 * Parameters can exist in the base workspace without being used in the

model,

 * so if a parameter in the base workspace is not found in the model, we just

 * ignore it.

 */ 

 if ((fileDataPtr[k].isStruct) && (fileDataPtr[k].numStructElements >= 1)) {

 paramIdx = fileDataPtr[k].paramIdx; 

 dataTypeIdx = rtwCAPI_GetModelParameterDataTypeIdx(modelParams, 

paramIdx);

 addrIdx = rtwCAPI_GetModelParameterAddrIdx(modelParams,paramIdx);

 paramAddress= (void *) rtwCAPI_GetDataAddress(dataAddrMap,addrIdx);

 

 processStructElem(capiMap, dataTypeMap, elemMap, paramAddress,

 fileDataPtr[k].name,

 dataTypeIdx,

 fileDataPtr, k, 1 /* structElem to be processed */, 

paramDataPtr);

 }

 else {

 /* This is a leaf node, just copy the data */ 

 

 setParamVal(capiMap, fileDataPtr[k].name, fileDataPtr, k, paramDataPtr);

 } 

 }

 }

 fclose(fd);

 fclose(GBLfdBin);

 #ifdef DEBUG_DUMP

 fclose (GBLfdump);

 #endif

 return 0;

}

void processStructElem(

 const rtwCAPI_ModelMappingInfo *capiMap,

 const rtwCAPI_DataTypeMap *dataTypeMap, 

 const rtwCAPI_ElementMap *elementMap,

 void *paramAddress,

 char_T *paramName,

 int_T dataTypeIdx,

 fileDataT *fileDataPtr,

 int_T fileParamIdx,

 int_T structElemIdx,

 char_T *paramDataPtr

 )

{

 /* This function processes structure elements */
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 101 of 103

 

 

 int numElements;

 int elemDataTypeIndex;

 int sIdx;

 int_T elemMapIndex;

 int_T dataOffset;

 int_T paramIdx;

 #ifdef DEBUG_DUMP

 int_T i,k,l;

 double *col;

 #endif

 

 

 paramIdx = fileDataPtr[fileParamIdx].paramIdx;

 if (structElemIdx <= fileDataPtr[fileParamIdx].numStructElements-1) {

 /* Find the structure element index for the current structure */

 sIdx = dataTypeMap[dataTypeIdx].elemMapIndex;

 numElements = dataTypeMap[dataTypeIdx].numElements;

 /* Find the elementIndex for this structure in the elementMap */

 elemMapIndex = getElementIndex(

 elementMap,

 sIdx,

 numElements, fileDataPtr[fileParamIdx].structElements

[structElemIdx]);

 elemDataTypeIndex = elementMap[elemMapIndex].dataTypeIndex;

 processStructElem(

 capiMap,

 dataTypeMap, 

 elementMap, 

 ((char *)paramAddress)+elementMap[elemMapIndex].elementOffset,

 paramName,

 elemDataTypeIndex,

 fileDataPtr,

 fileParamIdx,

 structElemIdx+1,

 paramDataPtr

 );

 }

 else {

 /* This is the element whose values have to be set */

 dataOffset = fileDataPtr[fileParamIdx].binFileOffset;

 

 fseek(GBLfdBin, dataOffset, SEEK_SET);

 fread(¶mDataPtr[dataOffset], 1,

 fileDataPtr[fileParamIdx].numBytes, 

 GBLfdBin);

 #ifdef DEBUG_DUMP
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 102 of 103

 if (strcmp(paramName, "engine.cyl.fuel_map") == 0) {

 for (k=0; k<31; k++) {

 col = ¶mDataPtr[dataOffset+17*k*sizeof(double)];

 fprintf(GBLfdump,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n",

 col[0], col[1], col[2], col[3], col[4], col[5], col[6], col[7],

 col[8], col[9], col[10], col[11], col[12], col[13], col[14], 

 col[15], col[16]);

 }

 }

 

 else {

 if (strcmp(paramName, "engine.cyl.wot_torq") == 0) { 

 col = ¶mDataPtr[dataOffset];

 fprintf(GBLfdump, "engine.cyl.wot before\n");

 fprintf(GBLfdump,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",

 col[0], col[1], col[2], col[3], col[4], col[5], col[6], col[7],

 col[8], col[9], col[10], col[11], col[12], col[13], col[14], 

 col[15], col[16], col[17]); 

 }

 fprintf(GBLfdump,"paramName %s, address %x cur value: %f, new vaue %f, 

fileoffset:%d \n",

 paramName, paramAddress,

 *(double *)paramAddress,

 *(double *)(¶mDataPtr[dataOffset]), 

 dataOffset 

 );

 }

 #endif

 memcpy(paramAddress, ¶mDataPtr[dataOffset],

 fileDataPtr[fileParamIdx].numBytes); 

 #ifdef DEBUG_DUMP

 fprintf(GBLfdump, "new param set is: %f\n",*(double *)paramAddress);

 if (strcmp(paramName, "engine.cyl.fuel_map") == 0) {

 fprintf(GBLfdump,"#### New parameter table for engine.cyl.fuel_map is: 

\n");

 for (k=0;k<31;k++) {

 col = (double *)((char_T *)paramAddress + 17*k*sizeof(double));

 fprintf(GBLfdump, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f 

\n",

 col[0],col[1], col[2], col[3], col[4], col[5], col[6], col[7],

 col[8],col[9], col[10], col[11], col[12], col[13], col[14], 

 col[15], col[16]);

 }

 }

 

 if (strcmp(paramName, "engine.cyl.wot_torq") == 0) { 

 col = (double *)((char_T *)paramAddress);

 fprintf(GBLfdump, "engine.cyl.wot set for this run\n");

 fprintf(GBLfdump,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",

 col[0], col[1], col[2], col[3], col[4], col[5], col[6], col[7],
7/26/11 6:01 PM C:\Documents and Settings...\GEM_Code.m 103 of 103

 col[8], col[9], col[10], col[11], col[12], col[13], col[14], 

 col[15], col[16], col[17]); 

 }

 

 #endif

 } 

} 

/* EOF - rtw_capi_examples.c */
system_bustrans_trqtrans_inertiadriving_cyc_spd

transmission

system_busengine_trq_outengine_iner_outtrans_spd_out

trans_bus

trans_trq

trans_inertia

clutch_spd

engine

system_busclutch spddriving_cyc_spdvehicle speed

engine_bus

engine_torq, inertia

strt_spd

electric

trans_spd elec_torq_iner

driver

system_b

vehicle_s

axle_spd_pro

driving_cyc_sp

driver_bus

ambient

Ambient

total_sim_time

[clutch_spd]

[driver]

[strt_spd]

[driving_

[system_bus]

[trans] [engine]

[clutch_spd][clutch_spd]

[vehicle_spd]

[driving_cyc_spd]

[driver]

[ambient]

[system_bus]

[vehicle]

[driving_cyc_spd]

[trans_spd]

[trans]

[system_bus]

[engine]

[system_bus]

Filtered data

1

den(s) Clock1

1-D Lookup

Table

n-D T(u)

driverengine

driver

transvehicleambient
ambient_bus

1

ambient.gravity

ambient.temperature

ambient.pressure

ambient.air_density

From

Workspace

driving_grade

ambient

driving_gradeair_density

pressure

temperaturegravity
driver_bus

1

trans.gear.clutching_spd

-Cmin gear state

gear_inputmax_gear_numberclutching

gear_output

trans.gear.declutching_spd

gear shifting

engine_onchassis_spddriver_acceldriver_breakgear_inputmax_gear_numberstep_timestate_min_timeup_shifting_spddown_shifting_spdclutch_holding_spdclutching_spddeclutching_spdclutching_min_time

driver_clutch

driver_gear

clutching

driver.ign_key_start_posdriver.ign_key_start_pos

driver ign_key_on

driver.ign_key_on

trans.gear.clutch_holding_spd

VehControl

System busdriver_cltchvehicle_spdaxle_spd_prop1driving_cyc_spd

driver_brk

driver_acl

True when gear

is neutral

u==0

Scope1

[engine_trq_pwm]

[fuel_flowrate]

[engine_spd]

[driver_cltch]

driver_gear

[driver_acl]

[driver_brk]

[max_gear_number]

driver_gear

[driver_brk]

[driver_acl]

driving_cycle_spd

driver_gear

[driver_acl]

driver_gear

driver_gear

[driver_cltch]

driver_gear

driver_gear

[max_gear_number]

driver_gear

[driver_cltch]

[gear_downshifting_spd]

[gear_upshifting_spd]

[gear_state_min_time]

[driver_brk]

veh_type

Constant

sim_step_time

Class Type

u1

case [ 1 2 ... ]:

case [ 7 8 9 ]:

case [ 11 ]:

case [ 12 ]:

Class 8

case: { }

gear number

max_gear_nu

up shifting 

down shifting 

gear_state_min_

Class 7

case: { }

gear number

max_gear_number

up shifting spd

down shifting spd

gear_state_min_time

Class 6

case: { }

gear number

max_gear_number

up shifting spd

down shifting spd

gear_state_min_time

Class 4

case: { }

gear number

max_gear_number

up shifting spd

down shifting spd

gear_state_min_time

Accelerator Pedal during

No Engine Power Demand

0

driving_cyc_spd Accelerator Pedal

4

axle_spd_prop1

3

vehicle_spd

2

system_bus

1

driver

driver_acldriver_brkdriver_cltchdriver_gear

driver_ign_keyondriver_ign_key_start_pos

<engine_on><engine_spd><engine_fuel_flowrate><engine_torq_pwm>
down shifting spd

3

up shifting spd

2

max_gear_number

1

up shifting speed

gear > 3

default: { }

gear_state_min_time

gear <=3

case: { }

gear_state_min_time

down shifting speed

Switch Case

u1

case [ 1 ]:

default:

<=

Convert 3

6

Action Port

case: { }

gear number

1
gear_state_min_time

0.5 1

Action Port

case: { }
gear_state_min_time

4 1

Action Port

default: { }
down shifting spd

3

up shifting spd

2

max_gear_number

1

up shifting speed

gear > 3

default: { }

gear_state_min_time

gear <=3

case: { }

gear_state_min_time

down shifting speed

Switch Case

u1

case [ 1 ]:

default:

<=

Convert 36

Action Port

case: { }

gear number

1
gear_state_min_time

0.5 1

Action Port

case: { }
gear_state_min_time

4 1

Action Port

default: { }
down shifting spd

3

up shifting spd

2

max_gear_number

1

up shifting speed

gear > 3

default: { }

gear_state_min_time

gear <=3

case: { }

gear_state_min_time

down shifting speed

Switch Case

u1

case [ 1 ]:

default:

<=

Convert 3

10

Action Port

case: { }

gear number

1
gear_state_min_time

0.5 1

Action Port

case: { }
gear_state_min_time

4 1

Action Port

default: { }
down shifting spd

3

up shifting spd

2

max_gear_number

1

up shifting speed

gear > 3

default: { }

gear_state_min_time

gear <=3

case: { }

gear_state_min_time

down shifting speed

Switch Case

u1

case [ 1 ]:

default:

<=

Convert 3

10

Action Port

case: { }

gear number

1
gear_state_min_time

0.5 1

Action Port

case: { }
gear_state_min_time

5 1

Action Port

default: { }
vehicle torque demand Estimate

system_busdriving_cyc_spd

vehicle Power demand

SpeedCorrection

chassis_spddriver_cltchdriving_cyc_spd

Power_correction Factor

Saturation

(0 to 1)3

Saturation

(0 to 1)2

Saturation

(0 to 1)1

Saturation

(-1 to 0)1

engine_rpm

Fcn1

1+u[1]

Fcn

1-u[1]

Corr. pedal

Corr. Power dmd2

-1

Braking Pedal

Braking poweraxle_spd_prop1

Brake Pedal

Accelerator pedal controlPower DemandEngSpd

Accelerator Pedal

driving_cyc_spd

5

axle_spd_prop1

4

vehicle_spd

3

driver_cltch

2

System bus

1
WOT torque

Saturation

(0 to 1)1

Power 

Fcn

f(u)

2pi/60

-KEngSpd

2

Power Demand

1
Saturation

(-1 to 0)2

Saturation

(-1 to 0)1

Normalized Braking torque

f(u)

Braking torque

u(2)/u(1)

axle_spd_prop1

2

Braking power

1
vehicle speed

error

driver_veh_spd_des

Proportional Gain

-KAND 1s Integral Gain -Kdriving_cycle_spd

u<0.01

u<1

Derivative Gain

du/dt -K- driving_cyc_spd

3

driver_cltch

2

chassis_spd

1
Rolling resistance force

vehicl

atan cosatan sin

Total Vehicle Force (N)

Total Power Demand (w)

Static Vehicle Mass (kg)1

vehicle.chs.mass_static

Static Vehicle Mass (kg)

vehicle.chs.mass_static

Sign

Rolling Friction Coefficient

c_rr_weighted

u

2

Gravitational Acceleration (m/sec^2)1

ambient.gravity

Gravitational Acceleration (m/sec^2)

ambient.gravity

Gradient Force (N)

0.5

Frontal Area (m^2)

vehicle.chs.frontal_area

Drag Force (N)

Drag Coefficient

vehicle.chs.drag_coef

Air Density (kg/m^3)

ambient.air_density

Acceleration force

Acceleration 

du/dt

% grade to ratio1

0.01

% grade to ratio

0.01

driving_cyc_spd

2

system_bus

1

<driving_grade>

<driving_grade>
 function driver_clutch_state

deClutchen:driver_gedu:state_hol step_timdriver_clu

Clutching

UpShiftingen:driver_gear = gear_input+ 1;du:state_holding_time += ... step_time;gear_upshifting_state ();

NoShiftingen:driver_gear=gear_input;du:state_holding_time += ... step_time;gear_noshifting_state ();

DownShiftingen:driver_gear=gear_input- 1;

du:state_holding_time += ... step_time;

gear_downshifting_state ();

 func

 func

 func

[chassis_spd >= clutching_spd && ...state_holding_time > state_min_time]{driver_clutch = 1;

driver_gear = 1;clutch_on_time = 0;}

[(chassis_clutch_on|| (engine_

{state_hol

driver_clut

[chassis_spd > clutch_holding_spd]

1

{clutching= 0;

driver_gear = 0;}

2 {driver_gear = 1;

clutching = 1;}

{clutching = 1;}

[chassis_spd > up_shifting_spd]{state_holding_time= 0;} 1

[state_holding_time > state_min_time] 2

[chassis_spd > up_shifting_spd]{state_holding_time= 0;}

2

[chassis_spd < down_shifting_spd && gear_input >= 1]

{state_holding_time= 0;}

1

[state_holding_time > state_min_time]

1

[chassis_spd < down_shifting_spd && gear_input >= 1]

{state_holding_time= 0;}

2

{c

{cl

[driv

{drive

{c
[gear_input < 0] 1

{gear_output = 0;} 2

[clutching > 0.5 && gear_input <= 1]

{gear_output = 1;} 1

2

[gear_input > max_gear_number]{gear_output = max_gear_number;}

1

{gear_output = gear_input;}

2
constant elec power

electric.acc.power

eps

Constant

0

trans_spd

1

inertia
trans gear shift

engine spdacc torqtrans speed

shifting torq

throttling delay filter

1

den(s)

strt_torq

0

strt_inertia

0

start

engine spdacc torq

strt torq

rps2rpm-Kidle engine spd acc torq idling torq 

engine spengine to

control

driver_ign_keyondriver_accel_onengine_rpmengine_idle_rpmign_key_start_positiontrans_gear_shiftingengine_strt_torqengine_idling_torqengine_torq_maxengine_torq_minengine_off_spdign_keyon_timestarter_max_timegear_shifting_timestep_timeidle_exit_caldriving_cyc_spddriver_accel

engine_torq_rqst

starting

clutching

idling

engine_torq_pwm

engine_stat_on

closed throttle torque

engine onacc torq clutch spengine_o

WOT torque

Scope

[engine_torq_pwm]

[trans_speed]

[ign_start_pos]

[accel_pedal_on]

[engine_on]

[system_bus][driving_cyc_spd]

[trans_gear_shifting]

[shifting_torq]

[vehicle_spd]

[engine_torq_ctrl]

[engine_torq_rqst]

[engine_stat_on]

[idling_torq]

[engine_idle_rpm]

[strt_torq]

[engine_idle_rpm]

[strt_torq]

engine_rpm

[trans_gear_shifting]

[idling_torq]

engine_rpm

[engine_on]

[ign_start_pos]

[vehicle_spd]

[driving_cyc_spd]

[driving_cyc_spd]

[acc_torq]

[engine_on]

[engine_spd]

[engine_torq_pwm]

[engine_torq_ctrl]

[engine_plant]

[engine_on]

[engine_stat_on]

[trans_speed]

[acc_torq]

[engine_spd]

[acc_torq]

engine_rpm

[engine_spd]

[engine_spd]

[engine_torq_pwm]

[system_bus]

[engine_idle_rpm]

[engine_torq][engine_on]

[engine_stat_on]

[engine_spd]

[engine_acc]

[accel_pedal_on]

Derivative

du/dt

0

engine.cyl.starter_max_time

engine.cyl.engine_off_spd

engine.cyl.idle_exit_cal

sim_step_time

sim_step_time

engine.cyl.shifting_time

Constant

engine.cyl.idle_spd

Clock

vehicle speed

4

driving_cyc_spd

3

clutch spd

2

system_bus

1

eng

engine_on

engine_torq_minengine_torq_max

engine_stat_on control

<driver_ign_keyon><driver_acl>

<driver_gear>

<driver_gear><trans_spd>

<driver_ign_key_start_pos>

plantacc

idle control On/Off

engine rpm (yellow), idle rpm 
engine acc spd

3

engine_to

no mechanical

accessory torque (Nm)

0

mechanical accessory power (W)

engine.acc.power

0

eps

Switch1

Sum

Mux1

[engine_system_torq]

[engine_acc_torq]

[engine_acc_power]

[engine_acc_spd]

[engine_acc_power]

[engine_system_torq]

[engine_acc_torq]

[engine_acc_spd]

[engine_acc_spd]

Demux

engine_on

4 clutch spd

3

acc torq inertia

2

engine on

1

<engine_torq>

engine_system_torq

<engine_inertia>

engineengineengineengine
Engine_Idling Ign_KeyOff

en:starting = 0;clutching = 0;idling= 0;

Trans_GearShiftingen:starting = 0;

clutching = 1;

idling=0;trans_shift_torq = engine_torq_min+5;du:engine_stat_on();engine_torq= trans_shift_torq;engine_torq_pwm();

Startingen:starting = 1;

clutching = 0;

idling=0;du:

engine_stat_on();engine_torq=engine_strt_torq;engine_torq_pwm();Idlingen:starting = 0; clutching = 0; idling=1;

du:

engine_stat_on();engine_torq = engine_idling_torq;engine_torq_pwm();

ex:engine_idling_torq_opt = engine_idling_torq;

Normalen:starting = 0;clutching = 0;idling=0;du:engine_stat_on();engine_torq=engine_torq_rqst;engine_torq_pwm();

 function e

 function e

[driver_ign_keyon > 0]

[ trans_gear_shifting > 0 ]

{gear_shifting_ontime=0;}

1

[(ign_key_start_position ==1) && ...ign_keyon_time < starter_max_time]

1

[engine_rpm < engine_idle_rpm && ...(driving_cyc_spd < 0.1 && driver_accel < 0.1) ]

3

[trans_gear_shifting < 0 || ...gear_shifting_ontime >= gear_shifting_time]

2

[trans_gear_shifting > 0]

{gear_shifting_ontime=0;}

1

[engine_rpm < engine_idle_rpm && ...(driving_cyc_spd < 0.1 && driver_accel < 0.1)]

2

[engine_rpm < engine_idle_rpm && ...(driving_cyc_spd < 0.1 && driver_accel <0.1)]

2

[engine_rpm > engine_idle_rpm*idle_exit_cal ...|| (driving_cyc_spd >= 0.202 && driver_accel > 0.05) ]

{engdrivegear

[edr

{e

2 

{engine

{engine_to(engine_to(engine_to

1

2

3
strt_spd

3

engine_torq_inertia

2

engine torque

engine torq ctrlengine spd

engine torq

engine fuel-flow

engine torq ctrlengine torqengine spd

total fuel flowrate

fuel flow rate

[engine_spd]

[strt_inertia]

[strt_torq]

[engine_torq_ctrl]

[engine_torq]

[strt_inertia]

[strt_torq]

[engine_torq_ctrl]

[engine_spd]

[engine_torq]

[engine_torq]

[engine_total_fuel_flow]

[engine_fuel_flowrate]

[engine_spd]

[engine_torq]

[engine_spd]

engine.cyl.inertia

engine torq ctrl

4

engine spd

3

21

engine_to

engin

engine_inertia

engine_to

engine

engine_torq
rps2rpm

fuel flow

closed throttle torq

<= 

>

Product

NOT

AND

[engine_off]

[WOT_torq_ctrl]

[fuel_flow]

[

[engine_torq]

[closed_throttle_torq]

[WOT_torq_ctrl]

[closed_throttle_torq]

[closing_throttle_torq]

[engine_torq]

[engine_torq]

[engine_spd_rpm]

[closing_throttle_fuelflow]

[engine_off]

[closed_throttle_torq]

[fuel_flow]

[engine_torq]

[closed_throttle_torq]

[engine_torq]

[engine_spd_rpm]

Engine Fuel Map

engine.cyl.closed_torq_cal

engine.cyl.fuel_min_torq

engine.cyl.fuel_flow_ini

0

0

eps

engine spd

3

engine torq

2

engine torq ctrl

1
engine torq

1

rps2rpm

rps2rpm

closed throttle torque

WOT torque

Product3Product2

[engine_throttling]

[engine_torq_min]

[engine_spd_rpm]

[engine_torq_max]

[engine_throttling]

[engine_spd_rpm][engine_spd_rpm]

[engine_throttling][engine_torq_min]

[engine_torq_max]

1

engine spd

2

engine torq ctrl

1
Product3

Product

Kp

-KKi -KKd -K1

s

Derivative

du/dt

rpm2rps

engine.cyl.idle_spd

engine.cyl.idle_spd_start_cal

engine.cyl.inertia

Add

Enable

acc torq

2

engine spd

1
<=

Product3

Product 

Kp

-KKi -KKd -K- 1s Derivative du/dt rpm2rps engine.cyl.idle_spd engine.cyl.idle_spd_start_cal engine.cyl.inertia

engine.cyl.starter_max_time

Add

Enable

engine spd

1
Product2

P

max -K-

-K-

-K1s du/dt rpm2rps

engine.cyl.idle_spd

engine.cyl.idle_spd_shift_cal

trans.gear.inertia

trans.cltch.inertia

engine.cyl.inertia

Enable

trans speed

3

engine spd 

1
clutch_spd

4 

gear

driver_gearcltch_trq_outcltch_iner_outtrans_spd_out

gear_trq_out

gear_iner_out

gear_spd_in

clutch

driver_cltchengine_trq_outengine_iner_outgear_spd_in

cltch_trq_out

cltch_iner_out

cltch_spd_in

[cltch_spd]

[trans_spd]

[cltch_inertia]

[cltch_trq]

Goto1

[driver_gear]

Goto

[driver_cltch]

From8

[trans_spd]

From7

[trans_inertia]

From6

[driver_cltch]

From5

[trans_trq]

From4

[cltch_spd]

From3

[cltch_inertia]

From2

[cltch_trq]

From1

[driver_gear]

Bus

Selector1

Bus

Creator

trans_spd_out

4

engine_iner_out

3

engine_trq_out

2

system_bus

1

<driver_cltch><driver_gear>

tra

cltch_trqcltch_inertiacltch_spdtrans_trqtrans_inertiatrans_spd
clutch engaged

cltch_trq_incltch_iner_incltch_spd_out

cltch_trq_out

cltch_iner_out

cltch_spd_in

clutch disengaged

cltch_trq_incltch_iner_incltch_spd_outcltch_pos

cltch_trq_out

cltch_iner_out

cltch_spd_in

True when clutch

is engaged

u==1

Clutch Torq

Clutch Spe

Clutch Iner

gear_spd_in

4

engine_iner_out

3

engine_trq_out

2

driver_cltch

1
cltch_iner_out

2

cltch_trq_out

1

no torque passing thru

when disengaged

0

no inertia passing thru

when disengaged

0

Trigger speed calculation

when clutch is disengaged

u==0

Scope

Damping Coefficient

-KClutch Input Speed (= Engine Speed)

1

s

xo

Clutch Inertia

trans.cltch.inertia

cltch_pos

4

cltch_spd_out

3

cltch_iner_in

2

cltch_trq_in

1
cltch_spd_in

3

cltch_iner_out

2

cltch_trq_out

1

Clutch Inertia

trans.cltch.inertia

cltch_spd_out

3

cltch_iner_in

2

cltch_trq_in

1
gear engaged

gear_trq_ingear_iner_ingear_spd_outgear_pos

gear_trq_out

gear_iner_out

gear_spd_in

gear disengaged

gear_trq_ingear_iner_ingear_spd_outgear_pos

gear_trq_out

gear_iner_out

gear_spd_in

True when gear

is engaged

u>0

Gear Torque

Gear Speed

Gear Inertia

trans_spd_out

4

cltch_iner_out

3

cltch_trq_out

2

driver_gear

1
gear_spd_in

3

gear_iner_out

2

gear_trq_out

1

no torque passing thru

when disengaged

0

no inertia passing thru

when disengaged

0

gear_trq_in1

1

gear1

4

Trigger speed calculation

when gear is disengaged

u==0

u2

Gear Ratio

Gear Inertia

trans.gear.inertia

Gear Efficiency

Damping Coefficient

-KClutch Input Speed (= Engine Speed)

1

s

xo

gear_pos

4

gear_spd_out

3

gear_iner_in

2

gear_trq_in

1
g

u2

Gear Ratio

Gear Inertia

trans.gear.inertia

Gear Efficiency

gear_pos

4

gear_spd_out

3

gear_iner_in

2

gear_trq_in

1
axle_spd_prop1

4

trans_spd_out

2

vehicle_bus

1

tire

system_busaxle_trq_outaxle_iner_outchs_spd_in

tire_force_out

tire_mass_out

tire_spd_in

final drive

diff_trq_outdiff_iner_outaxl_spd_in

drive shaft

trans_trq_outtrans_iner_outdiff_spd_in

shaft_trq_out

shaft_iner_out

shaft_spd_in

differential

shaft_trq_outshaft_iner_outfdr_spd_in

diff_bus

diff_trq_out

diff_iner_out

diff_spd_in

chass

system_bustire_force_outtire_mass_out

axle

system_busfdr_trq_outfdr_iner_outtire_spd_indriving_cyc_spd

axle_trq_out

axle_iner_out

axle_spd_in

axle_spd_prop1

Goto8

DynamicMass

[axle_spd]

Goto1 

[differential]

[system_bus]

[final_drive_iner][final_drive_trq]

[system_bus]

[system_bus]

[chassis]

[axle_spd]

[chassis_spd]

[final_drive]

[differential]

[system_bus]

Bus

Creator

driving_cyc_spd

4

trans_inertia

3

trans_trq

2

system_bus

1

chassisfinal_drivedifferential

vehicle
axle_spd_prop1

4

steering

system_busfdr_trq_outfdr_iner_outtire_spd_inaxle_spd_prop1driving_cyc_spd

axle_iner_out

axle_spd_in

axle_trq_out

second trailer

system_busfdr_trq_outfdr_iner_outtire_spd_inaxle_spd_prop1driving_cyc_spd

axle_iner_out

axle_spd_in

axle_trq_out

second propulsion

system_busfdr_trq_outfdr_iner_outtire_spd_inaxle_spd_prop1driving_cyc_spd

axle_iner_out

axle_spd_in

axle_trq_out

first trailer

system_busfdr_trq_outfdr_iner_outtire_spd_inaxle_spd_prop1driving_cyc_spd

axle_iner_out

axle_spd_in

axle_trq_out

first propulsion

system_busfdr_trq_outfdr_iner_outtire_spd_inaxle_spd_prop1driving_cyc_spd

axle_trq_out

axle_iner_out

axle_spd_in

[tire_spd_trail2][tire_spd_trail1]

[tire_spd_prop2][tire_spd_prop1]

[tire_spd_steer]

[fdr_iner_prop2][fdr_iner_prop1]

[driving_cyc_spd]

[axle_iner_trail2]

[axle_trq_trail2]

[fdr_trq_prop2]

[axle_iner_trail1]

[axle_trq_trail1]

[axle_spd_prop2]

[axle_iner_prop2]

[axle_trq_prop2]

[axle_spd_prop1]

[axle_iner_prop1]

[axle_trq_prop1]

[axle_iner_steer]

[axle_trq_steer]

[fdr_trq_prop1]

[system_bus]

[tire_spd_prop2]

[fdr_iner_prop2]

[fdr_trq_prop2]

[system_bus]

[tire_spd_prop1]

[fdr_iner_prop1]

[driving_cyc_spd]

[driving_cyc_spd]

[driving_cyc_spd][driving_cyc_spd][driving_cyc_spd][axle_spd_prop1]

[fdr_trq_prop1]

[axle_spd_prop1]

[axle_spd_prop1][axle_spd_prop1]

[axle_spd_prop1]

[axle_spd_pro[axle_spd_pro

[axle_iner_tra[axle_iner_tra

[axle_iner_pro[axle_iner_pro

[system_bus]

[axle_iner_ste

[axle_trq_trai[axle_trq_trai

[axle_trq_pro[axle_trq_pro

[axle_trq_ste

[tire_spd_trail2]

[system_bus]

[tire_spd_trail1]

[system_bus]

[tire_spd_steer]

[system_bus]

driving_cyc_spd

5

tire_spd_in

4

fdr_iner_out

3

fdr_trq_out

2

system_bus

1
axle_spd_in

3

axle_iner_out

2

0 Braking Torq Map

Axle Inertia (kg-m^2)

-Cdriving_cyc_spd

6

axle_spd_prop1

5

tire_spd_in

4

fdr_iner_out

3

fdr_trq_out

2

system_bus

1 <driver_brk>
axle_spd_in

2

axle_iner_out

1

0 Braking Torq Map

Axle Inertia (kg-m^2)

-Cdriving_cyc_spd

6

axle_spd_prop1

5

tire_spd_in

4

fdr_iner_out

3

fdr_trq_out

2

system_bus

1 <driver_brk>
axle_spd_in

2

axle_iner_out

1

0 Braking Torq Map

Axle Inertia (kg-m^2)

-Cdriving_cyc_spd

6

axle_spd_prop1

5

tire_spd_in

4

fdr_iner_out

3

fdr_trq_out

2

system_bus

1 <driver_brk>
axle_spd_in

2

axle_iner_out

1

0 Braking Torq Map

Axle Inertia (kg-m^2)

-Cdriving_cyc_spd

6

axle_spd_prop1

5

tire_spd_in

4

fdr_iner_out

3

fdr_trq_out

2

system_bus

1 <driver_brk>
axle_spd_in

2

axle_iner_out

1

0

Braking Torq Map

Axle Inertia (kg-m^2)

-Cdriving_cyc_spd

6 axle_spd_prop1

5

tire_spd_in

4

fdr_iner_out

3

fdr_trq_out

2

system_bus

1 <driver_brk>
vehicle speed

vehicle_forcetire_mass_out

chs_spd_out

vehicle force

system_bustire_force_outchs_spd_out

vehicle_force

tire_mass_out

3

tire_force_out

2

system_bus

1

chass

chassis_spd
atan sin

Total 

Static Vehicle Mass (kg)

vehicle.chs.mass_static

Sign

u2

Gravitational Acceleration (m/sec^2)

ambient.gravity

Gradient Force (N)

0.5

Frontal Area (m^2)

vehicle.chs.frontal_area

Drag Force (N)

Drag Coefficient

vehicle.chs.drag_coef

Air Density (kg/m^3)

ambient.air_density

% grade to ratio

0.01

chs_spd_out

3

tire_force_out

2

system_bus

1 <driving_grade>
Static Vehicle Mass (kg)

vehicle.chs.mass_static

Saturation

(0 to 1)2

1

s

tire_mass_out

2

vehicle_force

1
diff_spd_in

4

diff_iner_ou

3

diff_trq_ou

2

Rear Torque Ratio

-KRear Inertia Ratio -K- u2

Front Torque Ratio

-KFront Inertia Ratio -KDifferential Inertia vehicle.diff.inertia Differential Gear Ratio vehicle.diff.ratio Differential Efficiency vehicle.diff.eff

Average Speed

f(u)

fdr_spd_in

3

shaft_iner_out

2

shaft_trq_out

1

diff_spd_in

diff_spd_in

diff_trq_out_frnt

diff_trq_out_frnt

diff_trq_rear

diff_trq_rear

diff_iner_frnt

diff_iner_frnt

diff_iner_rear

diff_iner_rear
shaft_spd_in

3

shaft_iner_out

2

shaft_trq_out

1

Drive Shaft Inertia

vehicle.shaft.inertia

Drive Shaft Efficiency

vehicle.shaft.eff

diff_spd_in

3

trans_iner_out

2

trans_trq_out

1
rear drive

diff_trq_outdiff_iner_outaxl_spd_in

fdr2_bus

fdr_trq_out

fdr_iner_out

fdr_spd_in

front drive

diff_trq_outdiff_iner_outaxl_spd_in

fdr1_bus

fdr_trq_out

fdr_iner_out

fdr_spd_in [fdr_spd_front]

[fdr_iner_front]

[fdr_trq_front]

Goto6

[fdr1_bus]

[axl_spd_rear]

[axl_spd_front][diff_iner_rear]

[diff_iner_front]

[fdr_spd_rear]

[fdr_iner_rear]

[fdr_trq_rear]

Goto10

[fdr2_bus]

[diff_trq_rear]

[diff_trq_front]

[fdr_trq

[fdr_trq

[fdr2_[fdr1_

[axl_spd_rear]

[diff_iner_rear]

[diff_trq_rear]

[axl_spd_front]

[fdr_sp

[fdr_spd

[fdr_ine

[fdr_ine

[diff_iner_front]

[diff_trq_front]

axl_spd_in

3

diff_iner_out

2

diff_trq_out

1
fdr_spd_in

4

fdr_iner_out

3

fdr_trq_out

2

u2

Final Drive Inertia

vehicle.fdr.inertia_front

Final Drive Gear Ratio

vehicle.fdr.ratio_front

Final Drive Efficiency

vehicle.fdr.eff_front

axl_spd_in

3

diff_iner_out

2

diff_trq_out

1

fdr1_iner

fdr1_iner_out

fdr1_trq_out

fdr1_trq_out

fdr1_spd_in

fdr1_spd_in
fdr_spd_in

4

fdr_iner_out

3

fdr_trq_out

2

u2

Final Drive Inertia

vehicle.fdr.inertia_rear

Final Drive Gear Ratio

vehicle.fdr.ratio_rear

Final Drive Efficiency

vehicle.fdr.eff_rear

axl_spd_in

3

diff_iner_out

2

diff_trq_out

1

fdr2_spd_in

fdr2_spd_in

fdr2_trq_out

fdr2_trq_out

fdr2_iner_out

fdr2_iner_out
steering

system_busaxle_trq_outaxle_iner_outchs_spd_out

tire_force_out

tire_mass_out

tire_spd_in

second trailer

system_busaxle_trq_outaxle_iner_outchs_spd_out

tire_force_out

tire_mass_out

tire_spd_in

second propulsion

system_busaxle_trq_outaxle_iner_outchs_spd_out

tire_force_out

tire_mass_out

tire_spd_in

first trailer

system_busaxle_trq_outaxle_iner_outchs_spd_out

tire_force_out

tire_mass_out

tire_spd_in

first propulsion

system_busaxle_trq_outaxle_iner_outchs_spd_out

tire_force_out

tire_mass_out

tire_spd_in

class 10-12class 1-9

out

class 10-12class 1-9

out

class 10-12class 1-9

out

class 10-12class 1-9

out

class 10-12class 1-9

out

class 10-12class 1-9

out

class 7, 8, 9, 11,12class 1-6, 10

out

class 7, 8, 9, 11,12class 1-6, 10

out

class 7, 8, 9, 11,12class 1-6, 10

out

[axle_iner_trail1]

[axle_iner_prop2][axle_iner_prop1]

[axle_iner_steer]

[axle_trq_trail2][axle_trq_trail1]

[axle_trq_prop2]

[tire_spd_trail2]

[tire_mass_trail2][tire_force_trail2]

[tire_spd_trail1]

[tire_mass_trail1][tire_force_trail1]

[tire_spd_prop2]

[axle_trq_prop1]

[tire_mass_prop2][tire_force_prop2]

[tire_spd_prop1]

[tire_mass_prop1][tire_force_prop1]

[tire_spd_steer]

[tire_mass_steer][tire_force_steer]

[chs_spd_in]

[axle_iner_trail2]

[axle_trq_steer]

[system_bus]

[axle_trq_prop2]

[system_bus]

[chs_spd_in]

[axle_iner_prop1]

[axle_trq_prop1]

[system_bus]

[[

[[

[chs_spd_in]

[t[t

[t[t

[t

[t[t

[t[t

[t

[axle_iner_steer]

[axle_trq_trail2]

[system_bus]

[chs_spd_in]

[axle_iner_trail2]

[axle_trq_trail1]

[system_bus]

[chs_spd_in]

[axle_iner_trail1]

[chs_spd_in]

[axle_iner_prop2]

[axle_trq_steer]

[system_bus]

chs_spd_in

4

axle_iner_out

3

axle_trq_out

2

system_bus

1
out

1 9

87

veh_type

class 1-6, 10

2

class 7, 8, 9, 11,12

1
out

1 9

87

veh_type

class 1-6, 10

2

class 7, 8, 9, 11,12

1
out

1 9

87

veh_type

class 1-6, 10

2

class 7, 8, 9, 11,12

1
out

veh_type 1

class 1-9

2

class 10-12

1
out

veh_type 1

class 1-9

2

class 10-12

1
out

veh_type 1

class 1-9

2

class 10-12

1
out

veh_type 1

class 1-9

2

class 10-12

1
out

veh_type 1

class 1-9

2

class 10-12

1
out

veh_type 1

class 1-9

2

class 10-12

1
tt

Vehicle

Weight Fraction

-Katan cos

Traction Force (N)

Tire Radius (m)

-CTire Inertia (kg-m^2) -CStatic Vehicle Mass (kg)

vehicle.chs.mass_static

Rolling Friction Coefficient

-Cu2

Gravitational Acceleration (m/sec^2)

ambient.gravity

Dynamic Mass (kg)

Axle Speed (rad/sec)

% grade to ratio

0.01

chs_spd_out

4

axle_iner_out

3

axle_trq_out

2

system_bus

1 <driving_grade>
tt

Vehicle

Weight Fraction

-Katan cos

Traction Force (N)

Tire Radius (m)

vehicle.tire.radius_trail1

Tire Inertia (kg-m^2)

vehicle.tire.inertia_trail1

Static Vehicle Mass (kg)

vehicle.chs.mass_static

Rolling Friction Coefficient

-Cu2

Gravitational Acceleration (m/sec^2)

ambient.gravity

Dynamic Mass (kg)

Axle Speed (rad/sec)

% grade to ratio

0.01

chs_spd_out

4

axle_iner_out

3

axle_trq_out

2

system_bus

1 <driving_grade>
tt

Vehicle

Weight Fraction

-Katan cos

Traction Force (N)

Tire Radius (m)

-CTire Inertia (kg-m^2) -CStatic Vehicle Mass (kg)

vehicle.chs.mass_static

Rolling Friction Coefficient

-Cu2

Gravitational Acceleration (m/sec^2)

ambient.gravity

Dynamic Mass (kg)

Axle Speed (rad/sec)

% grade to ratio

0.01

chs_spd_out

4

axle_iner_out

3

axle_trq_out

2

system_bus

1 <driving_grade>
tt

Vehicle

Weight Fraction

-Katan cos

Traction Force (N)

Tire Radius (m)

vehicle.tire.radius_trail2

Tire Inertia (kg-m^2)

vehicle.tire.inertia_trail2

Static Vehicle Mass (kg)

vehicle.chs.mass_static

Rolling Friction Coefficient

-Cu2

Gravitational Acceleration (m/sec^2)

ambient.gravity

Dynamic Mass (kg)

Axle Speed (rad/sec)

% grade to ratio

0.01

chs_spd_out

4

axle_iner_out

3

axle_trq_out

2

system_bus

1 <driving_grade>
tt

Vehicle

Weight Fraction

-Katan cos

Traction Force (N)

Tire Radius (m)

vehicle.tire.radius_steer

Tire Inertia (kg-m^2)

vehicle.tire.inertia_steer

Static Vehicle Mass (kg)

vehicle.chs.mass_static

Rolling Friction Coefficient

-Cu2

Gravitational Acceleration (m/sec^2)

ambient.gravity

Dynamic Mass (kg)

Axle Speed (rad/sec)

% grade to ratio

0.01

chs_spd_out

4

axle_iner_out

3

axle_trq_out

2

system_bus

1 <driving_grade>