<Gauge Name="Itt" Version="1.0" (c) Tom Aguilo 2011 >
   <Image Name="itt_background.bmp"/>

<Macro Name="Time">(P:Absolute time,seconds)</Macro>
<Macro Name="Paused">@Time (L:ITTCounter,seconds) - 0 ==</Macro> 
<Macro Name="SimRate">(P:Simulation rate, number)</Macro>
<Macro Name="UpdateTimer">(P:Absolute time,seconds) (>L:ITTCounter,seconds)</Macro>
<Macro Name="TurnOnElapsed">(P:Absolute time,seconds) (>L:ITTElapsed,seconds)</Macro>
<Macro Name="Elapsed">(P:Absolute time,seconds) (L:ITTElapsed,seconds) - abs</Macro>

<Macro Name="TurnOnElapsedCooling">(P:Absolute time,minutes) (>L:CoolingElapsed,minutes)</Macro>
<Macro Name="ElapsedCooling">(P:Absolute time,minutes) (L:CoolingElapsed,minutes) - abs</Macro>

<Macro Name="TurnOnElapsedStarter">(P:Absolute time,minutes) (>L:StarterElapsed,minutes)</Macro>
<Macro Name="ElapsedStarter">(P:Absolute time,minutes) (L:StarterElapsed,minutes) - abs</Macro>
<Macro Name="TurnOffElapsedStarter">(P:Absolute time,minutes) (>L:StarterElapsed,minutes)</Macro>

<Macro Name="TurnOnEngineTimer">(A:GENERAL ENG ELAPSED TIME:1,hours) (>L:Eng1 Elapsed Time,hours)</Macro>


<Macro Name="Damped">
	(@3,celsius) @Paused ! 
	if{ p @1 sp0 (@3,celsius) s1 @2 * 1.0 @2 - @SimRate * l0 * + 
  		l0 d l1 > if{ min } els{ max } 
		  d (>@3,celsius) 
		} 	
</Macro>

<!-- Polinomial for Normal Starts -->		         
<Macro Name="NormalStart">
	l0 3 pow -0.86888112 * sp10 
  l0 2 pow 7.97290210 * sp11
  l0 59.75087413 * sp12
  l10 l11 + l12 + 166.95 +
</Macro>

<!-- Polinomial for Hot Starts factor -->		         
<Macro Name="HotStartFactor">
	l0 3 pow -0.00150932 * sp10 
  l0 2 pow 0.01842657 * sp11
  l0 0.01324592 * sp12
  l10 l11 + l12 - 1.105 +
</Macro>

<!-- Polinomial for Hot Starts factor correction due to seconds with fuel on and no combustion -->		         

<Macro Name="FuelOnHotCorrection">
  l23 0.0200 * 0.770 + 
</Macro>


<!-- Damp Constant affected by (A:..ITT) and (L:...ITT) difference in degrees (Max 400 dC min 100 dC) -->

<Macro Name="DampConstant">
  (L:Turb Eng1 ITT,celsius) (A:TURB ENG1 ITT,celsius) - abs 100 max 400 min sp9
  l9 2 pow 0.00000017 * sp11
  l9 0.00025000 * sp12
  l11 l12 - 0.97333333 +
</Macro>

<!-- Polinomial for Cooling Rate in degrees for a shut engine based on OAT (15 dC = base) -->		         
<Macro Name="CoolOATDiffFactor">
 (A:TOTAL AIR TEMPERATURE,celsius) -0.00721409 * 1.07387534 + 
</Macro>
<!-- Old Macro 
<Macro Name="CoolOATDiffFactor">
	l0 3 pow 0.00000155 * sp10 
  l0 2 pow 0.00038991 * sp11
  l0 0.02585717 * sp12
  l10 l11 - l12 + 0.71182813 +
</Macro>
-->
<!-- Polinomial for Determining actual minute seed in Cooling Rate -->		         
<Macro Name="CoolMinuteSeed">
	l0 -2.12774574 pow 1014493.97254775 * 
</Macro>
<!--
Old macro
<Macro Name="CoolMinuteSeed">
	l0 4 pow 0.000000014835 * sp10 
	l0 3 pow 0.000021078617 * sp11 
  l0 2 pow 0.0109133992 * sp12
  l0 2.477213126323 * sp13
  l10 l11 - l12 + l13 - 218.911079745922 +
</Macro>

-->

<!-- This macro takes into account the elapsed time the engine was running before shutdown, 
     and obtains a calculated ceiling ITT temperature immediately after shutdown. The idea is,
     as much time running, more hot it keeps.
 -->    
<Macro Name="GetEngineTimer">
	(A:GENERAL ENG ELAPSED TIME:1,hours) (L:Eng1 Elapsed Time,hours) - 60 * 1 max 5 min d (>L:EngineTimer,minutes) 30 * 350 +  
</Macro>

<Update>

    (L:InitITT,bool) ! 
    if{ (A:TOTAL AIR TEMPERATURE,Celsius) 0 max (>L:Turb Eng1 ITT,celsius) sp0
        @CoolMinuteSeed 1.8 max 1440 min (>L:CoolingSeed,minutes)
      	(A:GENERAL ENG1 MIXTURE LEVER POSITION, percent) (>L:MixtureLeverAnt,percent) 
    		1 (>L:InitITT,bool) 
    		} 
    (A:GENERAL ENG1 STARTER,bool) ! (L:StarterEngaged,bool) and (A:ENG1 COMBUSTION,bool) ! and 
    if{ 1 (>L:StarterOff,bool) } 
    (A:GENERAL ENG1 STARTER,bool) ! if{ 0 (>L:StarterEngaged,bool) } 
    (A:GENERAL ENG1 STARTER,bool) (L:StarterEngaged,bool) ! and 
		if{ @TurnOnElapsedStarter 1 (>L:StarterEngaged,bool) 0 (>L:StarterOff,bool) }

	(A:ENG1 COMBUSTION,bool) 
  if{ 
  		@TurnOffElapsedStarter
  		(L:InitCombustion,bool) !
  		if{ 1 (>L:InitCombustion,bool) 0 (>L:NoCombustion,bool) 
  				(L:Turb Eng1 ITT,celsius) (>L:Turb Eng1 ITTBase,celsius) 
  				@TurnOnElapsed 
  				@TurnOnEngineTimer
 				 }
  		els{ 
   					@Elapsed s0 10 &lt;=  
   					if{ 
   							(A:TURB ENG1 ITT,celsius) (L:MaxITTatStart,celsius) max (>L:MaxITTatStart,celsius)  
   							(L:MaxITTatStart,celsius) (A:TURB ENG1 ITT,celsius) > 
   							if{ (L:MaxITTatStart,celsius) 714 / (>L:MaxIttStartFactor,number) }
   							els{ 1 (>L:MaxIttStartFactor,number) }  
   							@NormalStart (L:MaxIttStartFactor,number) * sp20


								<!--   							
   							@NormalStart (L:MaxIttStartFactor,number) * sp20

   							@HotStartFactor sp22 (* Here comes the Hot Start factor when able *)

								(L:Eng1 Fuel Flow Vent,number) 18 / 1.5 > (* 1.5 are seconds after fuel on *)
								if{ @FuelOnHotCorrection 0.82 max l22 * }
								els{ 1 } 
								
								-->
								1 l20 * (L:Turb Eng1 ITTBase,celsius) 0 max max (>L:Turb Eng1 ITT,celsius)
			 					<!--
			 					(>L:Turb Eng1 ITTBase,celsius)	       
			 					@Damped((L:Turb Eng1 ITTBase,celsius),0.950,L:Turb Eng1 ITT)
			 					-->
								}
						els{ @DampConstant sp9 @Damped((A:TURB ENG1 ITT,celsius),l9,L:Turb Eng1 ITT) }
					 }
			}
 	els{ 

	  	 (L:NoCombustion,bool) !
  		 if{  1 (>L:NoCombustion,bool) @TurnOnElapsed @TurnOnElapsedCooling
            0 (>L:InitCombustion,bool) 1.8 (>L:CoolingSeed,minutes)	
            (L:Turb Eng1 ITT,celsius) d (>L:Turb Eng1 ITTBase,celsius) (>L:Turb Eng1 ITTAnt,celsius)			 			
			 			(L:Turb Eng1 N1,percent) 1 >			 
						if{ @GetEngineTimer (L:Turb Eng1 ITT,celsius) min (>L:Turb Eng1 ITTBase,celsius) }
					}
				<!-- Gas Generator Turbine spooling -->	
			 (L:Turb Eng1 N1,percent) 1 >			 
			 if{ 
					 (L:Turb Eng1 N1,percent) 100 / 33000 * 60 / 0.51227383 pow 0.38502765 * @Elapsed * sp0 (* sp0 are deg Celsius per fraction of second *)
					 (L:Turb Eng1 ITTBase,celsius) 500 min 0.00180361 * 0.09819639 + l0 * sp1 (* sp1 are deg Celsius corrected per current ITT temp *) 
					 (L:Turb Eng1 ITTBase,celsius) l1 @CoolOATDiffFactor * - s2 (>L:Turb Eng1 ITTBase,celsius) 
					 @TurnOnElapsed
					 <!--
					 @ElapsedCooling l2 sp0 @CoolMinuteSeed - 1.8 max 1440 min (>L:CoolingSeed,minutes) 
					 -->
					 l2 sp0 @CoolMinuteSeed 1.8 max 1440 min (>L:CoolingSeed,minutes) 				 
					 (L:Turb Eng1 ITTBase,celsius) (>L:Turb Eng1 ITTAnt,celsius) 					 			
					}
			 els{
 			      @ElapsedCooling (L:CoolingSeed,minutes) +  (* add the seed value to elapsed minutes since no combustion *)
 			      -0.478337 pow 665.37087 * sp0 (* obtain actual ITT temperature per calcs instead of gauge *)
 			      (L:Turb Eng1 ITTAnt,celsius) l0 - @CoolOATDiffFactor * sp2
 			      (L:Turb Eng1 ITTAnt,celsius) l2 - (>L:Turb Eng1 ITTBase,celsius)
 					  (L:Turb Eng1 ITTBase,celsius) (>L:Turb Eng1 ITTAnt,celsius) 					 			
			 		 }
       (L:Turb Eng1 ITTBase,celsius) (>L:Turb Eng1 ITT,celsius) 
 			 @Damped((L:Turb Eng1 ITTBase,celsius),0.950,L:Turb Eng1 ITT)
 			}
							
 		@UpdateTimer
</Update>


<Element>
      <Position X="149" Y="145"/>
      <Image Name="itt_needle.bmp" PointsTo="East">
         <Axis X="3" Y="8"/>
      </Image>
      <Rotate>
         <Value>(L:Turb Eng1 ITT, celsius) 0 max</Value>
         <Nonlinearity>
           <Item Value="0" X="58" Y="50"/>
           <Item Value="100" X="72" Y="39"/>
           <Item Value="200" X="94" Y="28"/>
           <Item Value="300" X="121" Y="18"/>
           <Item Value="400" X="149" Y="11"/>
					 <Item Value="500" X="178" Y="17"/>
					 <Item Value="600" X="205" Y="27"/>
					 <Item Value="700" X="251" Y="61"/>
					 <Item Value="800" X="286" Y="138"/>
					 <Item Value="900" X="260" Y="222"/>
					 <Item Value="1000" X="200" Y="275"/>
					 <Item Value="1100" X="117" Y="279"/>
         </Nonlinearity>
				<Failures>
            <SYSTEM_ELECTRICAL_PANELS Action="Zero"/>
        </Failures>
       <Delay DegreesPerSecond="90"/>
      </Rotate>
</Element>




<Mouse>
      
   <Area Left="20" Top="20" Width="260" Height="263">
     		<Tooltip>Inter Turbine Temperature %((L:Turb Eng1 ITT, celsius))%!d! Celsius</Tooltip>
   </Area>

</Mouse>

</Gauge>


<!--

Hot Starts:
Factors that affect a hot start (between 1000 - 1090 degCelsius)

1-Seconds of Fuel On at Ng below 11-19 % rotation
2-Residual ITT too high (Above 200 dgCelsius)
3-Emergency Power lever not in NORMAL position

High ITT Start:
Factors that affect a high start (between 850 - 1000 degCelsius)

1-Low speed Ng rotation before stabilizing (11-19%) due to Low battery voltage or cold weather
2-Second of fuel On with Ng above 11-19 % and no lightup due to cold weather


-->