<?xml version="1.0"?>

<!-- Dornier DO228(-212 NG) Fuel System, based on C172p fuel system-->
<!--	TODO outboard to inboard fuel flow condition!	-->
<system name="fuel">
	<channel name="Outboard to Inboard Main Tank">
		<!-- from tank 0 (left outboard wing tank) to tank 1 (left inboard wing tank) -->
		<fcs_function name="propulsion/tank[0]/contents-volume-gal">
			<function>
				<quotient>
					<p> propulsion/tank[0]/contents-lbs </p>
					<p> propulsion/tank[0]/density-lbs_per_gal </p>
				</quotient>
			</function>
		</fcs_function>
		<switch name="fuel/from-tank0-to-tank1">
			<default value="0"/>
			<test logic="AND" value="2.0">
				propulsion/tank[0]/priority EQ 1 
				propulsion/tank[0]/contents-volume-gal GT propulsion/tank[0]/unusable-volume-gal
				/consumables/fuel/tank[1]/level-lbs LT 0.05
				propulsion/tank[1]/priority EQ 1
				accelerations/Nz GE 0
			</test>
		</switch>
		
		<!-- from tank 5 (right outboard wing tank) to tank 4 (right inboard wing tank) -->
		<fcs_function name="propulsion/tank[5]/contents-volume-gal">
			<function>
				<quotient>
					<p> propulsion/tank[5]/contents-lbs </p>
					<p> propulsion/tank[5]/density-lbs_per_gal </p>
				</quotient>
			</function>
		</fcs_function>
		<switch name="fuel/from-tank5-to-tank4">
			<default value="0"/>
			<test logic="AND" value="2.0">
				propulsion/tank[5]/priority EQ 1 
				propulsion/tank[5]/contents-volume-gal GT propulsion/tank[5]/unusable-volume-gal
				/consumables/fuel/tank[4]/level-lbs LT 0.05
				propulsion/tank[4]/priority EQ 1
				accelerations/Nz GE 0
			</test>
		</switch>
	</channel>
	<channel name="Inboard Main to Feeder Tank">
		<!-- from tank 1 (left inboard wing tank) to tank 2 (left feeder tank) -->
		<fcs_function name="propulsion/tank[1]/contents-volume-gal">
			<function>
				<quotient>
					<p> propulsion/tank[1]/contents-lbs </p>
					<p> propulsion/tank[1]/density-lbs_per_gal </p>
				</quotient>
			</function>
		</fcs_function>
		<switch name="fuel/from-tank1-to-tank2">
			<default value="0"/>
			<test logic="AND" value="2.0">
				propulsion/tank[1]/priority EQ 1 
				propulsion/tank[1]/contents-volume-gal GT propulsion/tank[1]/unusable-volume-gal
				/consumables/fuel/tank[2]/level-lbs LT 190
				propulsion/tank[2]/priority EQ 1
				accelerations/Nz GE 0
			</test>
		</switch>
		
		<!-- from tank 4 (right inboard wing tank) to tank 3 (right feeder tank) -->
		<fcs_function name="propulsion/tank[4]/contents-volume-gal">
			<function>
				<quotient>
					<p> propulsion/tank[4]/contents-lbs </p>
					<p> propulsion/tank[4]/density-lbs_per_gal </p>
				</quotient>
			</function>
		</fcs_function>
		<switch name="fuel/from-tank4-to-tank3">
			<default value="0"/>
			<test logic="AND" value="2.0">
				propulsion/tank[4]/priority EQ 1 
				propulsion/tank[4]/contents-volume-gal GT propulsion/tank[4]/unusable-volume-gal
				/consumables/fuel/tank[3]/level-lbs LT 190
				propulsion/tank[3]/priority EQ 1
				accelerations/Nz GE 0
			</test>
		</switch>
	</channel>
	
	<!-- ***************************** -->
	<!-- FLOW RATE from/to each TANK    -->
	<!-- ***************************** -->
	
	<channel name="Total flow rates">
		<summer name="fuel/tank0-flow-rate">
			<input>-fuel/from-tank0-to-tank1</input>
			<output>propulsion/tank[0]/external-flow-rate-pps</output>
		</summer>
		<summer name="fuel/tank1-flow-rate">
			<input> fuel/from-tank0-to-tank1</input>
			<input>-fuel/from-tank1-to-tank2</input>
			<output>propulsion/tank[1]/external-flow-rate-pps</output>
		</summer>
		<summer name="fuel/tank2-flow-rate">
			<input> fuel/from-tank1-to-tank2</input>
			<output>propulsion/tank[2]/external-flow-rate-pps</output>
		</summer>
		
		<summer name="fuel/tank5-flow-rate">
			<input>-fuel/from-tank5-to-tank4</input>
			<output>propulsion/tank[5]/external-flow-rate-pps</output>
		</summer>
		<summer name="fuel/tank4-flow-rate">
			<input> fuel/from-tank5-to-tank4</input>
			<input>-fuel/from-tank4-to-tank3</input>
			<output>propulsion/tank[4]/external-flow-rate-pps</output>
		</summer>
		<summer name="fuel/tank3-flow-rate">
			<input> fuel/from-tank4-to-tank3</input>
			<output>propulsion/tank[3]/external-flow-rate-pps</output>
		</summer>
	</channel>
	
</system>
