# This file contains Application runtime attributes
# Phil Tobin

#debug=true
defaultLookAndFeelClass=com.formdev.flatlaf.intellijthemes.FlatCobalt2IJTheme

# Colors all stored in RGB i.e. 
# normally only for System use unless you wish to add colors
white= -1
black=-16777216
dark_blue=-16777038
blue=-16776961
yellow=-256
dark_green=-16731648
green=-16711936
red=-65536
dark_red=-5111808
dark_gray=-10921639
gray=-8355712
lightGray=-1381668
cyan=-16711681
magenta=-65281
pink=-20561
orange=-14336

# You can set to any of the colors defined above
graphForeColor0=white
graphForeColor1=red
graphForeColor2=green
graphForeColor3=yellow
graphForeColor4=cyan
graphForeColor5=pink
graphForeColor6=orange
graphForeColor7=magenta
graphForeColor8=dark_red
graphForeColor9=dark_blue
graphForeColor10=blue
graphForeColor11=dark_green
graphForeColor12=gray
graphForeColor13=lightGray
graphForeColor14=green
graphForeColor15=orange


foreColor=black
graphBackColor=black
graphFontColor=cyan
backColor=lightGray

#Number of selectors and max number of graphs
numberOfGraphs=4
numberOfOverlayGraphs=4
numberOfOverlays=4


# default Graphs
graph0.0=Field.RPM
graph0.1=Field.MAP
graph0.2=Field.TPS
graph0.3=Field.speedMPH
graph1.0=Field.AFR
graph1.1=Field.AFR2
graph1.2=Field.afrTarget
graph1.3=Field.iacPosition
graph2.0=Field.coolantTemp
graph2.1=Field.MAT
graph2.2=Field.ignitionAdv
graph2.3=Field.ignitionAdv2
graph3.0=Field.pulseWidth
graph3.1=Field.pulseWidth2
graph3.2=Field.ve
graph3.3=Field.ve2


FIELD_GROUP_NAME_Tuning=0
FIELD_SELECTED_GROUP_Tuning_graph0.0=Field.RPM
FIELD_SELECTED_GROUP_Tuning_graph0.1=Field.MAP
FIELD_SELECTED_GROUP_Tuning_graph0.2=Field.TP
FIELD_SELECTED_GROUP_Tuning_graph0.3=Field.pulseWidth
FIELD_SELECTED_GROUP_Tuning_graph1.0=Field.coolantTemp
FIELD_SELECTED_GROUP_Tuning_graph1.1=Field.MAT
FIELD_SELECTED_GROUP_Tuning_graph1.2=Field.speedMPH
FIELD_SELECTED_GROUP_Tuning_graph1.3=Field.AFR
FIELD_SELECTED_GROUP_Tuning_graph2.0=Field.DutyCycle1
FIELD_SELECTED_GROUP_Tuning_graph2.1=Field.Dwell
FIELD_SELECTED_GROUP_Tuning_graph2.2=Field.ignitionAdv
FIELD_SELECTED_GROUP_Tuning_graph2.3=Field.egoCorrection
FIELD_SELECTED_GROUP_Tuning_graph3.0=Field.ve
FIELD_SELECTED_GROUP_Tuning_graph3.1=Field.O2Volts
FIELD_SELECTED_GROUP_Tuning_graph3.2=Field.ve
FIELD_SELECTED_GROUP_Tuning_graph3.3=Field.batteryVoltage


# The file delimiter options
APP_OPTION_delimiter=File Delimiter
delimiter_OPTIONS=Auto Detect;Tab;Pipe |;Comma ,;CSV with double Quotes ",";CSV w/ double Quotes 2 ", "; Quote ';Semicolon <semi>;Space ' ';Other Delimiter;
delimiter_SOLUTIONS=Auto;\t;|;,;",";", ";';<semi>;\ ;Other;

# default Delimiter
DEFAULT_delimiter=Auto

# The FieldMappings options
APP_OPTION_fieldMapping=Field\ Naming\ (Log ECU)
fieldMapping_OPTIONS=Auto\ Detect;Torque;Harley\ DataMaster;Dynojet Power\ Vision;Dynojet Power\ Commander;Twin\ Tec;Twin\ Scan;MegaSquirt;MegaSquirt\ MS3\ Sequential;MS3 1.2+ / MS3 Pro;MS3 1.3+\ MS2 3.3+\ / MS3 Pro;Buell;TCFI;eecAnalyzer BE;DTA S80;Fuel\ Monster;Diablosport;Harley SERT;rusEFI;
fieldMapping_SOLUTIONS=Auto;FieldMaps/torque.properties;FieldMaps/Harley.properties;FieldMaps/PowerVision.properties;FieldMaps/PowerCommander.properties;FieldMaps/TCFI.properties;FieldMaps/TwinScan.properties;FieldMaps/MegaSquirt.properties;FieldMaps/MS3Seq.properties;FieldMaps/MS3_1.2.properties;FieldMaps/MS3_1.3.properties;FieldMaps/Buell.properties;FieldMaps/TCFI.properties;FieldMaps/eecAnalyzerBE.properties;FieldMaps/DtaS80.properties;FieldMaps/PWMonster.properties;FieldMaps/Diablo.properties;FieldMaps/SERT_Harley.properties;FieldMaps/rusEFI.properties;

# default Delimiter
DEFAULT_fieldMapping=Auto

# file extensions
fileExtensions=csv;dm3;log;msl;mlg;log;msq;dif;dat;txt;etl;mdf;mf4;emulog;emublog;mtl;maxxecu-zip-log;maxxecu-log;rec;tlg;

# tune file extensions
tuneFileExtensions=msq;tune;map;

TABLE_GEN_VIEW_Current\ View=16^|^16^|^0^|^1^|^2^|^Field.RPM^|^Field.MAP^|^Field.AFR^|^Field.targetAFR^|^501,800.0,1100,1400.0,2000.0,2600.0,3100.0,3700.0,4300.0,4900.0,5400.0,6000.0,6500.0,7000.0,7200.0,7500^|^100,95,90,85,80,75,70,65,60,55,50,45,40,35,25,15
TABLE_GEN_VIEW_RPM\ vs.\ MAP\ vs.\ AFR=16^|^16^|^0^|^1^|^2^|^Field.RPM^|^Field.MAP^|^Field.AFR^|^^|^0.0,577.9,1155.9,1733.8,2311.7,2889.6,3467.6,4045.5,4623.4,5201.4,5779.3,6357.2,6935.1,7513.1,8091.0,8668.9^|^186.5,175.9,165.4,154.8,144.2,133.6,123.0,112.4,101.8,91.3,80.7,70.1,59.5,48.9,38.3,27.8
TABLE_GEN_VIEW_RPM\ vs.\ MAP\ vs.\ PW=16^|^16^|^0^|^1^|^2^|^Field.RPM^|^Field.MAP^|^Field.pulseWidth^|^^|^501.0,800.0,1100.0,1400.0,2000.0,2600.0,3100.0,3700.0,4300.0,4900.0,5400.0,6000.0,6500.0,7000.0,7200.0,7500.0^|^100.0,95.0,90.0,85.0,80.0,75.0,70.0,65.0,60.0,55.0,50.0,45.0,40.0,35.0,25.0,15.0
TABLE_GEN_VIEW_RPM\ vs.\ MAP\ vs.\ (\ AFR\ -\ AFR\ 1\ Target\ )=16^|^16^|^0^|^1^|^2^|^Field.RPM^|^Field.MAP^|^Field.AFR^|^Field.targetAFR^|^600.0,700.0,1200.0,1500.0,2000.0,2600.0,3100.0,3700.0,4300.0,4900.0,5400.0,6000.0,6500.0,7000.0,7200.0,7500.0^|^100.0,95.0,90.0,85.0,80.0,75.0,70.0,65.0,60.0,55.0,50.0,45.0,35.0,25.0,15.0,10.0


# Fixed Min and Max fields
FIELD_MIN_MAX_Batt\ V=0;20
FIELD_MIN_MAX_TPS=0;100
FIELD_MIN_MAX_Lambda\ Right=0.5;1.5
FIELD_MIN_MAX_Lambda\ Left=0.5;1.5
FIELD_MIN_MAX_AFR_1_Error=-4;4
FIELD_MIN_MAX_AFR_2_Error=-4;4
FIELD_MIN_MAX_AFR_Error=-4;4

# Map Root canonical fields
ROOT_FIELD_RPM=RPM;rpm;Engine\ Speed;PC5\ RPM;Engine\ RPM;RPM_ENGINE;
ROOT_FIELD_CLT=Coolant;CLT;CLT_Temp;Engine\ Temp;Engine\ temp;Coolant\ Temperature;
ROOT_FIELD_AFR=Act_AFR;R_UEGO_AF;Act\ AFR;AFR;AFR1;WB2\ AFR\ 1;AFR\ 1;Air\ Fuel\ Ratio;AFR_R_BANK;
ROOT_FIELD_AFR2=Act_AFR;L_UEGO_AF;Act\ AFR;AFR2;WB2\ AFR\ 2;AFR_L_BANK;
ROOT_FIELD_Lambda1=Lambda\ Right;Lambda1;lambdaR;Lambda\ 1;Exhaust\ Lambda;LAMBDA;LAMB;LAMBDA_R_BANK;
ROOT_FIELD_Lambda2=Lambda\ Left;Lambda2;lambdaL;LAMBDA_L_BANK;
ROOT_FIELD_AFR\ Target=AFR\ Target;Target AFR;afrtgt_R;AFR_TARGET;
ROOT_FIELD_EGO\ cor1=R_O2_Corr;RO2_Corr;Gego;EGO\ Corr.;O2_CORR_R_BANK;
ROOT_FIELD_EGO\ cor2=L_O2_Corr;LO2_Corr;O2_CORR_L_BANK;
ROOT_FIELD_TPS=TPS_Pct;TPS;tps;Thottle\ Pos;TP;Throttle\ Position;PedalPos;PC5\ TPS;
ROOT_FIELD_Batt\ V=VBatt;Vbat;Vbatt;Batt.\ Volt;Batt.\ Voltg.;voltage;Bat\ Volts\ ECU;Battery\ Voltage;ECU\ Battery\ Voltage;Ecu\ power;BATTERY_VOLTAGE;
ROOT_FIELD_Duty_Cycle=DutyCycle1;DutyCycle;Duty\ Cycle;PC5\ Fuel\ Duty\ Cyl\ 1;DUTY\ CYCLE\ AVE;
ROOT_FIELD_AFR_1_Error=AFR_Error;AFR_1_Error;AFR\ 1\ Error;RO2_AFR_CORR;
ROOT_FIELD_AFR_2_Error=AFR_2_Error;AFR\ 2\ Error;LO2_AFR_CORR;
ROOT_FIELD_O2=EGO\ Volt.;O2\ Volt;
ROOT_FIELD_PW=pulsewidth1;Injector\ PW\ Rear;injector;Fuel\ Actual\ PW;PW1;INJ_GPW_AVE;
ROOT_FIELD_MAP=map;Manifold\ Pres;PC5\ Map\ Num;Manifold\ Pressure;Inlet\ Manifold\ Pressure;
ROOT_FIELD_MAT=Air\ Temp\ Inlet;IAT;Inlet\ Manifold\ Temperature;TAIR;
ROOT_FIELD_MAF=Mass\ Air\ Flow;Mass\ Air\ Flow\ Rate;
ROOT_FIELD_Time=Time_s;Device\ Time;Timestamp;TIME;:Time;Offset;
ROOT_FIELD_EGT1=Exhaust\ Temperature;Exhaust\ temp;EGT_CYL1;

#enableTuningPanel=false

#######################  VE Table generation parameters #############
# this is the name used in the formula to reference the current table value
DEFINE_CURRENT_CELL_VALUE=cellValue
# this is the name used in the formula to reference the target AFR table value
DEFINE_CURRENT_AFR_VALUE=afrValue
DEFINE_INTERPOLATED_CELL_VALUE=cellInterpolated
DEFINE_AFR_RECORD_OFFSET_VALUE=WBafrOffSet

#default afr offset
WBafrOffSet=1

# Minimum total weight before a calculated value will be used.
# valid values are 0.0 - as high as you want to go.
veAnalysisWeightThreshold=0.0

#minimum weight for an individual hit before it would be used toward a calculated value.
# Valid values 0.0-1.0, at 1.0 or greater, nothing will be counted.
veAnalysisWindowThreshold=0.0



# Min RPM's to include in VE Analysis, below this will be filtered
veAnalysisMinRPM=500
# Max RPM included in VE Analysis, Log entries with RPM above this will not be used in VE Analysis
# To filter rev limiter hits.
veAnalysisMaxRPM=18500

# list of tables to be loaded into table editor
tableLoadList=veTable,veBins1,veBins2,veBins3,advTable1,advTable2,afrTable,afrBins1,afrBins2,advanceTable,advanceTable1,advanceTable2,advanceTable3,veTable1,veTable2,veTable3,veTable4,afrTable1,afrTable2,afrTable3,alphaMAPtable,xTauTable,veTable1dozen,veTable3dozen,veTable2dozen,lambdaTable,sparkTable,pwBTable1,pwBTable2,pwATable1,pwATable2,afrBTable1,afrBTable2,afrATable1,afrATable2



#######################  Formula Groups will append one of many #############

# FORMULA_GROUP_ used as prefix to define any formula set where
# only one should be selected at a time.
# list all 3, group, options and solutions
# The remaining piece after the FORMULA_GROUP_ prefix will display on the application menu 
# _Options will display as single select sub menu items separate by ;
# _SOLUTIONS contains the formula mapping file to apply, separated by ;
# for file mapping give inc file and field separated by |
# you can apply further calculation if needed

FORMULA_GROUP_AFR(WBO2)=Wideband\ O2-AFR \ Front
AFR(WBO2)_OPTIONS=Off;Innovate\ 0-5V\ (10:1-20:1);Innovate\ 1-2V;Innovate\ LC-1\ Default;TechEdge-DIY;TechEdge\ Linear;AEM\ Linear;AEM\ Non\ Linear;Zeitronix;Dynojet\ Linear;NGK\ Powerdex;Custom Linear;
AFR(WBO2)_SOLUTIONS=\ ;[Field.O2Volts]*2+10;[Field.O2Volts]*10;[Field.O2Volts]*2.94+7.35;[Field.O2Volts|TechEdge_DIYwbo2.inc];[Field.O2Volts]*2+9;[Field.O2Volts]*1.97195+9.72;[Field.O2Volts|aemWBo2.inc];[Field.O2Volts|zeitronix.inc];[Field.O2Volts]*1.6+10;[Field.O2Volts]*1.4+9;{AFR at Low Voltage} < {AFR at High Voltage} ? {AFR at Low Voltage}+(([Field.O2Volts]-{Low Voltage})*({AFR at High Voltage}-{AFR at Low Voltage})/({High Voltage}-{Low Voltage})) : {AFR at Low Voltage}-(([Field.O2Volts]-{Low Voltage})*({AFR at Low Voltage}-{AFR at High Voltage})/({High Voltage}-{Low Voltage}));
# default value
DEFAULT_APPEND_FIELD_AFR(WBO2)=\ 

FORMULA_GROUP_AFR(WBO2)Rear=Wideband\ O2-AFR \ Rear
AFR(WBO2)Rear_OPTIONS=Off;Innovate\ 0-5V\ (10:1-20:1);Innovate\ 1-2V;Innovate\ LC-1\ Default;TechEdge-DIY;TechEdge\ Linear;AEM\ Linear;AEM\ Non\ Linear;Zeitronix;Dynojet\ Linear;NGK\ Powerdex;Custom Linear;
AFR(WBO2)Rear_SOLUTIONS=\ ;[Field.O2Volts2]*2+10;[Field.O2Volts2]*10;[Field.O2Volts2]*2.94+7.35;[Field.O2Volts2|TechEdge_DIYwbo2.inc];[Field.O2Volts2]*2+9;[Field.O2Volts2]*1.97195+9.72;[Field.O2Volts2|aemWBo2.inc];[Field.O2Volts2|zeitronix.inc];[Field.O2Volts2]*1.6+10;[Field.O2Volts2]*1.4+9;{AFR at Low Voltage} < {AFR at High Voltage} ? {AFR at Low Voltage}+(([Field.O2Volts2]-{Low Voltage})*({AFR at High Voltage}-{AFR at Low Voltage})/({High Voltage}-{Low Voltage})) : {AFR at Low Voltage}-(([Field.O2Volts2]-{Low Voltage})*({AFR at Low Voltage}-{AFR at High Voltage})/({High Voltage}-{Low Voltage}));
# default value
DEFAULT_APPEND_FIELD_AFR(WBO2)Rear=\ 


############# Replace Field ################################################
##########  This is now done with Group Field.which append 
# Innovate 0-5 WB formula
# Example for field replacement
# This would replace the O2 field with a calculated field AFR
#O2_NAME=AFR
#AFR_FORMULA=logVal*2+10


# Uses external map file to transform MAF Volt to Air Flow
# "MAF Volts" will be remapped to the value it maps to for 
# Air Flow in MAF_Volts_AirFlow.inc
#MAF\ Volts_NAME=Air Flow
#Air\ Flow_MAP_FILE=MAF_Volts_AirFlow.inc

#TP replace with raw
#TP_FORMULA=({Maximum TPS ADC}-{Minimum TPS ADC})*logVal/100+{Minimum TPS ADC Again}
#TP_FORMULA=(201-41)*logVal/100+41


# Uses external map file to transform O2 Volt to AFR
# WB O2 Volts for AME
# Download map file from http://www.ideasandsolutions.biz/MSGraph
# Air Flow in aemWBo2.inc
#O2_NAME=AFR
#AFR_MAP_FILE=aemWBo2.inc

# Uses external map file to Replace O2 Volt with AFR Mapping
# Download map file from http://www.ideasandsolutions.biz/MSGraph
# Air Fuel in TechEdge_DIYwbo2.inc
#O2_NAME=AFR
#AFR_MAP_FILE=TechEdge_DIYwbo2.inc


################ Sample Filters ####################################
# These filters will be loaded if there are no other filters. 
DATA_FILTER_Idle\ Range=[Field.TP] == 0 && [Field.RPM] <1000 ;Filter to identify and remove data while at idle
DATA_FILTER_Cold=[Field.coolantTemp] < 160 ;Filter to identify and remove data when coolant temperature is below 160 degrees
DATA_FILTER_RPM\ Change= abs([Field.RPM] - [RPM-4]) > ([Field.RPM] * 0.05);Filter any data where the engine is experiencing a change in RPM greater than 5%, likely a transient point
DATA_FILTER_Transients= (abs([Field.RPM] - [RPM-4]) > ([Field.RPM] * 0.10) ) || (abs([Field.TP] - [TP-4]) > 5 )  || (abs([Field.MAP] - [MAP-4]) > ([Field.MAP] * 0.15) )  ;Any data where the engine is going through transient conditions
DATA_FILTER_AFR\ Out\ of\ range=[Field.AFR] > 20 || [Field.AFR] < 10;AFR Above 20 or below 10


#################  Sample Append field functions    ##################
# if uncommented here, these will show on the Calculate Field.--> Optional Fields
# menu. You then enable there.

# Append field functionality
# Append a field with true PW, subtracking open time
APPEND_FIELD_Front\ PW-1=[Field.pulseWidth]-1
APPEND_FIELD_Rear\ PW-1=[Field.pulseWidth]-1

# Append field functionality
# Calculate change in RPM
#APPEND_FIELD_deltaRPM=[Field.RPM]-[Field.RPM-1]

# Append field functionality
# Calculate Time between log records
#APPEND_FIELD_deltaTime=[Field.Time]-[Field.Time-1]

# Append field functionality
# Calculate RPM per Sec, engine acceleration rate
# Compound formula 
APPEND_FIELD_RPM/Sec=([Field.RPM]-[Field.RPM-1])/([Field.Time]-[Field.Time-1])

APPEND_FIELD_TP\ ADC=([Field.TP]/100)*({Maximum TPS ADC}-{Minimum TPS ADC})+{Minimum TPS ADC}
SUB_FORMULA_TP_VOLT=([Field.TP]/100)*({Maximum TPS ADC}-{Minimum TPS ADC})+{Minimum TPS ADC}*5/255
SUB_FORMULA_TP_VOLT2=([Field.TP-1]/100)*({Maximum TPS ADC}-{Minimum TPS ADC})+{Minimum TPS ADC}*5/255
APPEND_FIELD_TPdot=(SUB_FORMULA(TP_VOLT)-SUB_FORMULA(TP_VOLT2))/([Field.Time]-[Field.Time-1])

# For tuning map based accel enrich
APPEND_FIELD_MAPdot=([Field.MAP]-[Field.MAP-1])/([Field.Time]-[Field.Time-1])


# adds Vacuum in inHg
#Enter your typical starting kpa for the constant "97" which represents 
# engine off kpa MAP reading.
# a more typical kpa is ~97 kpa depending on your elavation and weather.
# Change the 97 to your engine off MAP reading
# and uncomment the following 2 lines
APPEND_FIELD_VAC(inHg)={Engine off MAP pressure in KPA}-[Field.MAP]*0.29536

# adds new Boost(psi) field.
# Vacuum will show as negative boost
# Change the 97 to your engine off MAP reading
# and uncomment the following 2 lines
APPEND_FIELD_Boost(psi)=([Field.MAP]-{Engine off MAP pressure in KPA})*0.145113524

APPEND_FIELD_BoostVac=[Field.MAP]>{Engine off MAP pressure in KPA} ? ([Field.MAP]-{Engine off MAP pressure in KPA})*0.145113524  : 0-({Engine off MAP pressure in KPA} -[Field.MAP])*0.29536


APPEND_FIELD_TP\ ADC=({Maximum TPS ADC}-{Minimum TPS ADC})*[Field.TP]/100+{Minimum TPS ADC}

#The original Andy Whittle fomula
#APPEND_FIELD_Fuel\ Flow=([Field.pulseWidth]-{Injector Opening Time in ms, usually about 1.0})*[Field.RPM]*{Alternating(enter 0.5) or Simultaneous (enter 1)}*{Number of Squirts}/1200

#MAF calculation for Air Flow
APPEND_FIELD_Mass\ Air\ Flow=[Field.AFR]* 0.126*(([Field.pulseWidth]-{Injector Opening Time in ms})*[Field.RPM]*{Alternating(enter 0.5) or Simultaneous (enter 1)}*{Number of Squirts}/1200)*{Injector Size in lb/hr}*{Number of Injectors or Cyl}/100

# Duty cycles
#DC = RPM * NPC * PW / 60000
APPEND_FIELD_Duty\ Cycle1=[Field.pulseWidth]*[Field.RPM]*{Number of Squirts per engine revolution (Usually 0.5 or 1.0)}/600
APPEND_FIELD_Duty\ Cycle2=[Field.pulseWidth2]*[Field.RPM]*{Number of Squirts per engine revolution (Usually 0.5 or 1.0)}/600

#This one gives total fuel consumption in lbs/hr or cc/min
APPEND_FIELD_Fuel\ Flow = SUB_FORMULA(FuelFlow)
SUB_FORMULA_FuelFlow=(([Field.pulseWidth]-{Injector Opening Time in ms, usually about 1.0})*[Field.RPM]*{Alternating(enter 0.5) or Simultaneous (enter 1)}*{Number of Squirts}/1200)*{Injector Size}*{Number of Cylinders/Injectors}/100
APPEND_FIELD_Fuel\ Flow/1000\ RPM=(([Field.pulseWidth]-{Injector Opening Time in ms, usually about 1.0})*[Field.RPM]*{Alternating(enter 0.5) or Simultanious (enter 1)}*{Number of Squirts}/1200)*{Injector Size}*{Number of Injectors or Cyl}*10/[Field.RPM]

APPEND_FIELD_Instant\ MPG=[Field.pulseWidth] == 0 ? 99 : SUB_FORMULA(MPH)/SUB_FORMULA(GPH)
SUB_FORMULA_MPH=({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission gear ratio})
SUB_FORMULA_GPH=(([Field.pulseWidth]-{Injector Opening Time in ms, usually about 1.0})*[Field.RPM]*{Squirts Per 720 crank degrees, each injector}/1200)*{Injector Size (lb/hr)}*{Number of Injectors or Cyl}/600


APPEND_FIELD_MPH\ 1st\ Gear=({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 1st gear ratio})
APPEND_FIELD_MPH\ 2nd\ Gear=({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 2nd gear ratio})
APPEND_FIELD_MPH\ 3rd\ Gear=({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 3rd gear ratio})
APPEND_FIELD_MPH\ 4th\ Gear=({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 4th gear ratio})
APPEND_FIELD_MPH\ 5th\ Gear=({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 5th gear ratio})
APPEND_FIELD_MPH\ 6th\ Gear=({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 6th gear ratio})

APPEND_FIELD_KPH\ 1st\ Gear=({Tire Diameter(cm)}*[Field.RPM])/(531.1788*{Final Drive Ratio}*{Transmission 1st gear ratio})
APPEND_FIELD_KPH\ 2nd\ Gear=({Tire Diameter(cm)}*[Field.RPM])/(531.1788*{Final Drive Ratio}*{Transmission 2nd gear ratio})
APPEND_FIELD_KPH\ 3rd\ Gear=({Tire Diameter(cm)}*[Field.RPM])/(531.1788*{Final Drive Ratio}*{Transmission 3rd gear ratio})
APPEND_FIELD_KPH\ 4th\ Gear=({Tire Diameter(cm)}*[Field.RPM])/(531.1788*{Final Drive Ratio}*{Transmission 4th gear ratio})
APPEND_FIELD_KPH\ 5th\ Gear=({Tire Diameter(cm)}*[Field.RPM])/(531.1788*{Final Drive Ratio}*{Transmission 5th gear ratio})
APPEND_FIELD_KPH\ 6th\ Gear=({Tire Diameter(cm)}*[Field.RPM])/(531.1788*{Final Drive Ratio}*{Transmission 6th gear ratio})

#APPEND_FIELD_mph\ 1=[Field.speedKPH]/1.6093
#APPEND_FIELD_kph\ 1=[Field.speedMPH]*1.6093

APPEND_FIELD_MAP\ X\ RPM = ([Field.MAP] * [Field.RPM])/10
APPEND_FIELD_PowerPercent = 10 * sqrt([Field.TP])

# HP & TQ for VSS
SUB_FORMULA_acclHpKph= smoothFiltered(accelHp(smoothFiltered([Field.KPH]*0.621), (smoothFiltered(0.621*[Field.KPH])-smoothFiltered(0.621*[Field.KPH-1])), [Field.Time]-[Field.Time-1], {Weight of Vehicle (kg)}*2.2))
SUB_FORMULA_aeroDragKph= aerodynamicDragHp(smoothFiltered(0.621*[Field.KPH])* 0.44704, 1.2041, { Aerodynamic Drag Coefficient}, {Vehicle Frontal Area (m^2)} )
SUB_FORMULA_roadDragKph= rollingDragHp(smoothFiltered(0.621*[Field.KPH]), {Tire Pressure(kPa)}/6.8948, {Weight of Vehicle (kg)}*2.2)

APPEND_FIELD_HP\ KPH=SUB_FORMULA(acclHpKph) + SUB_FORMULA(aeroDragKph) + SUB_FORMULA(roadDragKph)
APPEND_FIELD_TQ\ KPH=(5252*(SUB_FORMULA(acclHpKph) + SUB_FORMULA(aeroDragKph) + SUB_FORMULA(roadDragKph)))/[Field.RPM]
#APPEND_FIELD_HP\ KPH=[Field.TP]<{Min TP to calculate for} ? 0 : ({Weight of Vehicle}/32)*(SUB_FORMULA(VSSV2_kph)-SUB_FORMULA(VSSV1_kph))/SUB_FORMULA(TIME_DELTA)*(SUB_FORMULA(VSSV2_kph))/550
#APPEND_FIELD_TQ\ KPH=[Field.TP]<{Min TP to calculate for} ? 0 : ({Weight of Vehicle}/32)*(SUB_FORMULA(VSSV2_kph)-SUB_FORMULA(VSSV1_kph))/SUB_FORMULA(TIME_DELTA)*(SUB_FORMULA(VSSV2_kph))/550*5250/([Field.RPM]+[Field.RPM-1]/2)
#Where
SUB_FORMULA_VSSV2_kph=((([Field.KPH]+[Field.KPH-2])/2)*1.46667)/1.6093
SUB_FORMULA_VSSV1_kph=((([Field.KPH-4]+[Field.KPH-5])/2)*1.46667)/1.6093

SUB_FORMULA_acclHp= smoothFiltered(accelHp(smoothFiltered([Field.speedMPH]), (smoothFiltered([Field.speedMPH])-smoothFiltered([Field.speedMPH-1])), smoothFiltered([Field.Time]-[Field.Time-1]), {Weight of Vehicle (lbs)}))
SUB_FORMULA_aeroDrag= aerodynamicDragHp(smoothFiltered([Field.speedMPH])* 0.44704, 1.2041, { Aerodynamic Drag Coefficient}, {Vehicle Frontal Area (ft^2)} / 10.7639104)
SUB_FORMULA_roadDrag= rollingDragHp(smoothFiltered([Field.speedMPH]), {Tire Pressure(psi)}, {Weight of Vehicle (lbs)})

APPEND_FIELD_Accel\ HP= SUB_FORMULA(acclHp)
APPEND_FIELD_AerodynamicDrag= SUB_FORMULA(aeroDrag)
APPEND_FIELD_Road\ Drag= SUB_FORMULA(roadDrag)

#
APPEND_FIELD_HP= SUB_FORMULA(acclHp) + SUB_FORMULA(aeroDrag) + SUB_FORMULA(roadDrag)
#APPEND_FIELD_VSS\ HP=[Field.TP]<{Min TP to calculate for} ? 0 : smoothBasic(({Weight of Vehicle}/32)*(SUB_FORMULA(VSSV2)-SUB_FORMULA(VSSV1))/SUB_FORMULA(TIME_DELTA)*(SUB_FORMULA(VSSV2))/550, 5)
APPEND_FIELD_TQ= (5252*(SUB_FORMULA(acclHp) + SUB_FORMULA(aeroDrag) + SUB_FORMULA(roadDrag)))/[Field.RPM]
#APPEND_FIELD_VSS\ TQ=[Field.TP]<{Min TP to calculate for} ? 0 : smoothBasic(({Weight of Vehicle}/32)*(SUB_FORMULA(VSSV2)-SUB_FORMULA(VSSV1))/SUB_FORMULA(TIME_DELTA)*(SUB_FORMULA(VSSV2))/550*5250/([Field.RPM]+[Field.RPM-1]/2), 5)
#Where
SUB_FORMULA_VSSV2=(([Field.speedMPH]+[Field.speedMPH-2])/2)*1.46667
SUB_FORMULA_VSSV1=(([Field.speedMPH-4]+[Field.speedMPH-5])/2)*1.46667

APPEND_FIELD_TestDSpeed = isNan(SUB_FORMULA(V1)) ? 0 : (SUB_FORMULA(V2) - SUB_FORMULA(V1)) * 0.681818
SUB_FORMULA_acclHpRpm= smoothFiltered(accelHp(smoothFiltered(SUB_FORMULA(V2) * 0.681818),  0.681818 * (smoothFiltered(SUB_FORMULA(V2))-smoothFiltered(SUB_FORMULA(V1))), ([Field.Time]-[Field.Time-1]), {Weight of Vehicle (lbs)}))
SUB_FORMULA_aeroDragRpm= aerodynamicDragHp(smoothFiltered(SUB_FORMULA(V2))* 0.3048, 1.2041, { Aerodynamic Drag Coefficient}, {Vehicle Frontal Area (ft^2)} / 10.7639104)
SUB_FORMULA_roadDragRpm= rollingDragHp(smoothFiltered(SUB_FORMULA(V2)* 0.681818), {Tire Pressure}, {Weight of Vehicle (lbs)})

APPEND_FIELD_TQ\ RPM= [Field.TP]<{Min TP to calculate for} || isNan(SUB_FORMULA(V1)) ? 0 : (5252*(SUB_FORMULA(acclHpRpm) + SUB_FORMULA(aeroDragRpm) + SUB_FORMULA(roadDragRpm)))/[Field.RPM]
APPEND_FIELD_HP\ RPM= [Field.TP]<{Min TP to calculate for} || isNan(SUB_FORMULA(V1)) ? 0 : SUB_FORMULA(acclHpRpm) + SUB_FORMULA(aeroDragRpm) + SUB_FORMULA(roadDragRpm)
#Where
SUB_FORMULA_V2=({Tire Diameter(in.)}*SUB_FORMULA(RPM_V2_Corrected))/(228.8693*{Final Drive Ratio}*{Transmission gear ratio})
SUB_FORMULA_V1=({Tire Diameter(in.)}*SUB_FORMULA(RPM_V1_Corrected))/(228.8693*{Final Drive Ratio}*{Transmission gear ratio})
SUB_FORMULA_RPM_V2= smoothFiltered([Field.RPM])
SUB_FORMULA_RPM_V1=smoothFiltered([Field.RPM-1])
SUB_FORMULA_TIME_DELTA= [Field.Time]-[Field.Time-1]
SUB_FORMULA_RPM_V2_Corrected=(SUB_FORMULA(RPM_V2)*pow((log(SUB_FORMULA(RPM_V2)-{Converter stall speed (0 for manual trans)})/(log(SUB_FORMULA(RPM_V2)-({Converter stall speed (0 for manual trans)}*0.95)))),23)+({Converter stall speed (0 for manual trans)})*0.15)
SUB_FORMULA_RPM_V1_Corrected=(SUB_FORMULA(RPM_V1)*pow((log(SUB_FORMULA(RPM_V1)-{Converter stall speed (0 for manual trans)})/(log(SUB_FORMULA(RPM_V1)-({Converter stall speed (0 for manual trans)}*0.95)))),23)+({Converter stall speed (0 for manual trans)})*0.15)
SUB_FORMULA_V2_unc=({Tire Diameter(in.)}*SUB_FORMULA(RPM_V2))/(228.8693*{Final Drive Ratio}*{Transmission gear ratio})


APPEND_FIELD_FT/SEC^2=[Field.TP]<{Min TP to calculate for} ? 0 : (SUB_FORMULA(V2)-SUB_FORMULA(V1))/SUB_FORMULA(TIME_DELTA)

APPEND_FIELD_TraveledMiles = SUB_FORMULA(TripMiles)
SUB_FORMULA_TripMiles = [TripMiles-1] >= 0 ? [TripMiles-1]+(([MPH]/3600)*([Time]-[Time-1]))  : 0

APPEND_FIELD_TraveledFeet = [TraveledFeet-1] >= 0 ? [TraveledFeet-1]+(5280*([Field.speedMPH]/3600)*([Time]-[Time-1]))  : 0
#SUB_FORMULA_TripFeet = [TripFeet-1] >= 0 ? [TripFeet-1]+(5280*([MPH]/3600)*([Time]-[Time-1]))  : 0

SUB_FORMULA_GallonsUsed = [FuelUsed-1] >= 0 ? [FuelUsed-1]+([Fuel Flow]*(([Time]-[Time-1])/3600))/6.073  : 0
APPEND_FIELD_AvgMPG = (SUB_FORMULA(FuelFlow) / 6.073) 
#APPEND_FIELD_CorV2=SUB_FORMULA(V2)*3600/5280
#APPEND_FIELD_CorV1=SUB_FORMULA(V2)*3600/5280

APPEND_FIELD_FT/SEC^2=[Field.TP]<{Min TP to calculate for} ? 0 : (SUB_FORMULA(V2)-SUB_FORMULA(V1))/SUB_FORMULA(TIME_DELTA)

APPEND_FIELD_TripMiles = [TripMiles-1] >= 0 ? [TripMiles-1]+(([MPH]/3600)*([Time]-[Time-1]))  : 0

APPEND_FIELD_TripFeet = [TripFeet-1] >= 0 ? [TripFeet-1]+(5280*([Field.speedMPH]/3600)*([Time]-[Time-1]))  : 0

APPEND_FIELD_GallonsUsed = [GallonsUsed-1] >= 0 ? [GallonsUsed-1]+(SUB_FORMULA(FuelFlow)*(([Time]-[Time-1])/3600))/6.073  : 0
APPEND_FIELD_AvgMPG = [TripMiles]/[GallonsUsed]

APPEND_FIELD_MAPxRPM = [Field.MAP] * [Field.RPM] / 100
APPEND_FIELD_MsPerCycle =  [Field.RPM]==0 ? 0: ({Degrees Per Cycle (720 for 4 stroke, 360 for 2 Stroke) }/360) * 60000/[Field.RPM]

APPEND_FIELD_Zero\ To\ 60\ Time = timeToExceed(60, [Field.speedMPH], [Time])

# speed in each gear calculated with 2% head room.
SUB_FORMULA_EstimatedGear = [Field.speedMPH] < ({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 1st gear ratio}) * 1.02 ? 1 : [Field.speedMPH] < ({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 2nd gear ratio}) * 1.02 ? 2 : [Field.speedMPH] < ({Tire Diameter(in.)}*[Field.RPM])/(335.675*{Final Drive Ratio}*{Transmission 3rd gear ratio}) * 1.02 ? 3 : 4 
APPEND_FIELD_Predicted\ Gear=SUB_FORMULA(EstimatedGear)
SUB_FORMULA_TransRatio= selectExpression(SUB_FORMULA(EstimatedGear)-1, {Transmission 1st gear ratio}, {Transmission 2nd gear ratio}, {Transmission 3rd gear ratio}, {Transmission 4th gear ratio})
SUB_FORMULA_RpmSpeedMph= ({Tire Diameter(in.)}*[Field.RPM])/(335.675 * {Final Drive Ratio} * SUB_FORMULA(TransRatio))
APPEND_FIELD_Converter\ Slip= [Field.RPM] > 0 ? (1-([Field.speedMPH] / SUB_FORMULA(RpmSpeedMph))) * 100 : 0
APPEND_FIELD_Speed\ MPH\ From\ RPM=SUB_FORMULA(RpmSpeedMph)

#APPEND_FIELD_Test\ Field.speedMPH=[Field.speedMPH]
#APPEND_FIELD_Test\ TransRatio=SUB_FORMULA(TransRatio)

