<?xml version="1.0" encoding="UTF-8"?>
<Mission xmlns="Tethys"
       xmlns:Control="Tethys/Control"
       xmlns:Guidance="Tethys/Guidance" 
       xmlns:Derivation="Tethys/Derivation"
       xmlns:Estimation="Tethys/Estimation"
       xmlns:Dock="Tethys/Dock"       
       xmlns:Trigger="Tethys/Trigger" 
       xmlns:Units="Tethys/Units"
       xmlns:Universal="Tethys/Universal"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="Tethys http://okeanids.mbari.org/tethys/Xml/Tethys.xsd
                           Tethys/Control http://okeanids.mbari.org/tethys/Xml/Control.xsd
                           Tethys/Guidance http://okeanids.mbari.org/tethys/Xml/Guidance.xsd
                           Tethys/Derivation http://okeanids.mbari.org/tethys/Xml/Derivation.xsd
                           Tethys/Dock http://okeanids.mbari.org/tethys/Xml/Dock.xsd
                           Tethys/Estimation http://okeanids.mbari.org/tethys/Xml/Estimation.xsd
                           Tethys/Trigger http://okeanids.mbari.org/tethys/Xml/Trigger.xsd
                           Tethys/Units http://okeanids.mbari.org/tethys/Xml/Units.xsd
                           Tethys/Universal http://okeanids.mbari.org/tethys/Xml/Universal.xsd"
       Id="mapPatch_undock">

    <Description>
        Vehicle yo-yos with patch detect enabled for oil concentration. NOTE:
        oil concentrations may vary strongly with depth! Suggested settings for
        simulaton: Config/sim/[username]/Simulator.cfg: oceanModelData =
        "Resources/BurgerOilfieldSpill.nc:mass_concentration_of_petroleum_hydrocarbons_in_sea_water:kg/m3";
        eastCurrent = 0.05 m/s; // vel y wrto LV northCurrent = 0.005 m/s; //
        vel x wrto LV Config/sim/[username]/workSite.cfg: initLat =
        71.2225805280196 arcdeg; // Initial latitude initLon =
        -163.5093252100575 arcdeg; // Initial longitude
        Config/sim/[username]/sim.cfg: WetLabsBB2FL.loadAtStartup = 0 bool;
        WetLabsSeaOWL_UV_A.loadAtStartup = 1 bool;
        WetLabsSeaOWL_UV_A.simulateSensors = 1 bool; WetLabsSeaOWL_UV_A.serial =
        "SEAOWLA2K-019"; WetLabsSeaOWL_UV_A.scaleFactor700 = 3.204e-7
        1/m/sr/count; WetLabsSeaOWL_UV_A.darkCounts700 = 48 count;
        WetLabsSeaOWL_UV_A.scaleFactorFDOM = 8.096e-3 ppb/count;
        WetLabsSeaOWL_UV_A.darkCountsFDOM = 50 count;
        WetLabsSeaOWL_UV_A.fdomAccuracy = 8.19 ppb;
        WetLabsSeaOWL_UV_A.scaleFactorChl = 2.170e-3 ug/l/count;
        WetLabsSeaOWL_UV_A.darkCountsChl = 50 count;
        WetLabsSeaOWL_UV_A.chlAccuracy = 1.475 ug/l;
        WetLabsSeaOWL_UV_A.scaleFactorOil = 2.8 ppb/count;
        WetLabsSeaOWL_UV_A.darkCountsOil = 50 count;
        WetLabsSeaOWL_UV_A.oilAccuracy = 3.6 ppb; NavChartDb.charts =
        "US1AK90M,US2AK92M,US5AK9NM,US5AK9OM,US5AK9PM,US5AK9QM,US5AK9RM,US5AK9SM,US5AK9TM,US5AK9UM";
    </Description>

<!-- Vehicle safety parameters -->

    <DefineArg Name="MissionTimeout"><Description>
        Timeout for the entire mission
    </Description><Units:hour/><Value>12</Value></DefineArg>

    <DefineArg Name="DetachTimeout"><Description>
        Timeout for detaching from dock.
    </Description><Units:minute/><Value>20</Value></DefineArg>

    <DefineArg Name="TransponderCode"><Description>
        The acoustic address of the asset to be tracked
    </Description><Units:count/><Value>2</Value></DefineArg>

    <DefineArg Name="Speed"><Description>
        Vehicle speed.
    </Description><Units:meter_per_second/><Value>1</Value></DefineArg>

    <DefineArg Name="CommsAtMissionStart"><Description>
        Whether to do comms at start of mission.
    </Description><True/></DefineArg>

<!--debug    
    </Description><False/></DefineArg>
-->

    <DefineArg Name="PeakDetectChl"><Description>
        Chlorophyll patch mapping.
<!--debug      
    </Description><True/></DefineArg>
-->
    </Description><False/></DefineArg>

    <DefineArg Name="PeakDetectSalinity"><Description>
        Salinity patch mapping.
<!--debug      
    </Description><True/></DefineArg>
-->
    </Description><False/></DefineArg>

    <DefineArg Name="PeakDetectOil"><Description>
        Oil patch mapping.
    </Description><True/></DefineArg>

<!--debug    
    </Description><False/></DefineArg>
-->

    <DefineArg Name="DetectTheTrough"><Description>
        Whether to track a trough. If false, track peak; if true, track trough.
        Default is false.
    </Description><False/></DefineArg>

<!--debug    
    </Description><True/></DefineArg>
-->

    <DefineArg Name="MinAltitude"><Description>
        Minimum altitude for the entire mission.
    </Description><Units:meter/><Value>3</Value></DefineArg>

    <DefineArg Name="MaxDepth"><Description>
        Maximum depth for the entire mission.
    </Description><Units:meter/><Value>10</Value></DefineArg>

    <DefineArg Name="MinWaterDepth"><Description>
        Minimum water depth for the entire mission.
    </Description><Units:meter/><Value>10</Value></DefineArg>

    <DefineArg Name="MinOffshore"><Description>
        Minimum offshore distance for the entire mission.
    </Description><Units:meter/><Value>2000</Value></DefineArg>

    <DefineArg Name="MinDistFromPolygonSides"><Description>
        If a operational safety polygon is specified and the vehicle is closer
        than this minimum distance to the polygon sides, turn back.
    </Description><Units:meter/><Value>200</Value></DefineArg>

    <DefineArg Name="NeedCommsTimeInTransit"><Description>
        Maximum time between surfacings for communications during transit
    </Description><Units:minute/><Value>300</Value></DefineArg>

    <DefineArg Name="NeedCommsTimePatchMapping"><Description>
        Maximum time between surfacings for communications during patch mapping.
        This is checked only on every NumRoundsBtnCrossLegSurfacings rounds of
        CrossLeg or every NumRoundsBtnInLegSurfacings InLeg.
    </Description><Units:minute/><Value>300</Value></DefineArg>

    <DefineArg Name="ElapsedTimeSinceLastGPSForCheckingOutsidePolygon"><Description>
        Check whether vehicle is outside of polygon only after the elapsed time
        since last GPS is greater than this parameter.
    </Description><Units:minute/><Value>60</Value></DefineArg>

    <DefineArg Name="CheckNaNTimeout"><Description>
        If the patch peak value is NaN by this time, stop mission.
    </Description><Units:minute/><Value>10</Value></DefineArg>

    <DefineArg Name="TimePastOffPeakThreshold"><Description>
        Time to swim past off-peak threshold point, in order to cover low-value
        areas.
    </Description><Units:minute/><Value>30</Value></DefineArg>

    <DefineArg Name="WaitAfterHittingWall"><Description>
        After the vehicle bounces off the boundary (defined by the shortest
        distance to polygon sides), wait this long before re-checking the
        distance.
    </Description><Units:minute/><Value>15</Value></DefineArg>

    <DefineArg Name="LatPatchMappingStart"><Description>
        Latitude of patch mapping start location. If nan, transit is skipped.
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

<!--debug    
    </Description><Units:degree/><Value>36.810</Value></DefineArg>
-->

    <DefineArg Name="LonPatchMappingStart"><Description>
        Longitude of patch mapping start location. If nan, transit is skipped.
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

<!--debug    
    </Description><Units:degree/><Value>-121.855</Value></DefineArg>
-->

    <DefineArg Name="Repeat"><Description>
        Maximum number of legs. Set to a large number.
    </Description><Units:count/><Value>100</Value></DefineArg>

    <DefineArg Name="WpMaxDistance"><Description>
        Maximum length of each mapping leg
    </Description><Units:meter/><Value>6000</Value></DefineArg>

    <DefineArg Name="WpTimeoutBase"><Description>
        Maximum duration of each mapping leg
    </Description><Units:second/><Value>6000</Value></DefineArg>

    <DefineArg Name="TransitYoYoMinDepth"><Description>
        Minimum depth while performing the YoYo behavior during transit.
    </Description><Units:meter/><Value>2</Value></DefineArg>

    <DefineArg Name="TransitYoYoMaxDepth"><Description>
        Maximum depth while performing the YoYo behavior during transit.
    </Description><Units:meter/><Value>8</Value></DefineArg>

    <DefineArg Name="PatchMappingYoYoMinDepth"><Description>
        Minimum depth while performing the YoYo behavior during patch mapping.
    </Description><Units:meter/><Value>2</Value></DefineArg>

    <DefineArg Name="PatchMappingYoYoMaxDepth"><Description>
        Maximum depth while performing the YoYo behavior during patch mapping.
    </Description><Units:meter/><Value>8</Value></DefineArg>

    <DefineArg Name="YoYoMinAltitude"><Description>
        Minimum altitude while performing the YoYo behavior (for
        bottom-terminated YoYos).
    </Description><Units:meter/><Value>3</Value></DefineArg>

    <DefineArg Name="YoYoUpPitch"><Description>
        Vehicle up pitch while performing the YoYo behavior.
    </Description><Units:degree/><Value>20</Value></DefineArg>

    <DefineArg Name="YoYoDownPitch"><Description>
        Vehicle down pitch while performing the YoYo behavior.
    </Description><Units:degree/><Value>-20</Value></DefineArg>

    <DefineArg Name="PeakShallowBnd"><Description>
        Shallow depth bound for detecting peak on each descent or ascent
        profile.
    </Description><Units:meter/><Value>2</Value></DefineArg>

    <DefineArg Name="PeakDeepBnd"><Description>
        Deep depth bound for detecting peak on each descent or ascent profile.
    </Description><Units:meter/><Value>8</Value></DefineArg>

    <DefineArg Name="BeginThresholdChl"><Description>
        If non-NaN, sets chlorophyll threshold for starting horizontal patch
        detection
    </Description><Units:microgram_per_liter/><Value>1.0</Value></DefineArg>

    <DefineArg Name="BeginThresholdSalt"><Description>
        If non-NaN, sets salinity threshold for starting horizontal patch
        detection
    </Description><Units:psu/><Value>33.0</Value></DefineArg>

    <DefineArg Name="BeginThresholdOil"><Description>
        If non-NaN, sets threshold for starting horizontal patch detection
    </Description><Units:kilogram_per_cubic_meter/><Value>0.1</Value></DefineArg>

    <DefineArg Name="WpBearing"><Description>
        Bearing being followed in the current leg. Set this to initialize start
        direction of patch mapping.
    </Description><Units:degree/><Value>210</Value></DefineArg>

    <DefineArg Name="OffPeakFraction"><Description>
        When filtered horizontal value is this fraction of the peak, consider it
        outside the patch.
    </Description><Units:percent/><Value>10</Value></DefineArg>

    <DefineArg Name="fractionOfThreshold"><Description>
        On a non-continued flight, if the detected peak is lower than
        BeginThreshold*fractionOfThreshold, the peak is disqualified, and the
        vehicle continues on the current heading until a qualified peak is
        found, or bouncing on a wall, or WpMaxDistance is reached.
    </Description><Units:percent/><Value>10</Value></DefineArg>

    <DefineArg Name="DetectionTimeout"><Description>
        Look for signal for this long. If none found within this timeout, switch
        to the next leg.
    </Description><Units:minute/><Value>30</Value></DefineArg>

    <DefineArg Name="TimeWindowPeakRpt"><Description>
        If greater than zero, report a peak every such time window has elapsed.
        If NaN or zero, this variable is ignored.
    </Description><Units:minute/><Value>NaN</Value></DefineArg>

    <DefineArg Name="LowPassWindowLen"><Description>
        Low-pass window length (based on depth sensor sampling interval 0.4
        second) for low-pass filtering.
    </Description><Units:count/><Value>20</Value></DefineArg>

    <DefineArg Name="MedianFilterLength"><Description>
        Median filter length (only for chlorophyll fluorescence which tends to
        have spikes). The median-filtered signal enters the succeeding low-pass
        filter. If set to 1, then no median filtering, i.e., the raw
        fluorescence signal directly enters the low-pass filter.
    </Description><Units:count/><Value>5</Value></DefineArg>

    <DefineArg Name="NumOfProfilesSlidingwindow"><Description>
        Length of horizontal sliding window. The highest per-yoyo peak (after
        low-pass filtering by a filter of length FilterWidthHorizontal) is
        picked out within this window.
    </Description><Units:count/><Value>50</Value></DefineArg>

    <DefineArg Name="FilterWidthHorizontal"><Description>
        Width of boxcar filter used in horizontal patch detection
    </Description><Units:count/><Value>4</Value></DefineArg>

    <DefineArg Name="MicromodemCommsInterval"><Description></Description><Units:minute/><Value>5</Value></DefineArg>

    <DefineArg Name="TrackingUpdatePeriod"><Description>
        How long to wait between acoustic queries
    </Description><Units:second/><Value>2.5</Value></DefineArg>

    <DefineArg Name="NumberOfPings"><Description>
        Number of return pings to request with each acoustic query (more than 1
        will activate oneway mode)
    </Description><Units:count/><Value>1</Value></DefineArg>

    <DefineArg Name="DepChangeThreshAttitudeFlip"><Description>
        Depth change threshold for determining vehicle attitude flip.
    </Description><Units:meter/><Value>0.5</Value></DefineArg>

    <DefineArg Name="WaterFrame"><Description>
        Set WaterFrame true to drive towards waypoints in the water frame of
        reference
    </Description><True/></DefineArg>

    <DefineArg Name="PatchMode"><Description>
        If true, use center of "in peak" range as the turn-around point. If
        false use maximum horizontal peak location as the turn-around point.
    </Description><False/></DefineArg>

    <DefineArg Name="TurnAngleBase"><Description>
        Zigzag turn angle.
    </Description><Units:degree/><Value>120</Value></DefineArg>

    <DefineArg Name="Reverse"><Description>
        Change in bearing which reverses vehicle direction
    </Description><Units:degree/><Value>180</Value></DefineArg>

    <DefineArg Name="TwoPi"><Description>
        Applied to stop run-up of angles
    </Description><Units:degree/><Value>360</Value></DefineArg>

    <DefineArg Name="MassDefault"><Description>
        Static setting for mass during the mission. Defaults to massDefault
        setting in the Config/Control.cfg file.
    </Description><Control:VerticalControl.massDefault/></DefineArg>

    <DefineArg Name="BuoyancyNeutral"><Description>
        Buoyancy bladder position while performing the YoYo behavior. Defaults
        to buoyancyNeutral setting in the Config/Control.cfg file.
    </Description><Control:VerticalControl.buoyancyNeutral/></DefineArg>

<!-- Internal variable settings -->

    <DefineOutput Name="PeakFoundNotContinuedFlightLowEnabled"><Description>
        Initialized to True.
    </Description><True/></DefineOutput>

    <DefineOutput Name="PeakFoundNotContinuedFlightHighEnabled"><Description>
        Initialized to True.
    </Description><True/></DefineOutput>

    <DefineOutput Name="PeakFoundContinuedFlightLowEnabled"><Description>
        Initialized to True.
    </Description><True/></DefineOutput>

    <DefineOutput Name="PeakFoundContinuedFlightHighEnabled"><Description>
        Initialized to True.
    </Description><True/></DefineOutput>

    <DefineOutput Name="LegNotContinuedFlightEnabled"><Description>
        Initialized to True.
    </Description><True/></DefineOutput>

    <DefineOutput Name="LegContinuedFlightLowEnabled"><Description>
        Initialized to True.
    </Description><True/></DefineOutput>

    <DefineOutput Name="LegContinuedFlightHighEnabled"><Description>
        Initialized to True.
    </Description><True/></DefineOutput>

    <DefineOutput Name="PatchDetectOn"><Description>
        Mission sets this to true when looking for the patch peak. Initialized
        to True.
    </Description><True/></DefineOutput>

    <DefineOutput Name="ZigDone"><Description>
        Mission sets this to true when the zig transect has been completed.
        Initialized to False.
    </Description><False/></DefineOutput>

    <DefineOutput Name="LegContinuedFlight"><Description>
        Initialized to False.
    </Description><False/></DefineOutput>

    <DefineOutput Name="MissionStartCommsCompleted"><Description>
        Initialized to False.
    </Description><False/></DefineOutput>

    <DefineOutput Name="Turn"><Description>
        Initialized to NaN.
    </Description><Units:degree/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="WpBearingAfterLastWallHit"><Description>
        Initialized to NaN.
    </Description><Units:degree/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="WpTimeout"><Description>
        Initialized to NaN.
    </Description><Units:second/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="SideLastHit"><Units:count/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakChl"><Units:microgram_per_liter/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakChlPriorToContinuedFlight"><Units:microgram_per_liter/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakSalinity"><Units:psu/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakSalinityPriorToContinuedFlight"><Units:psu/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakOil"><Units:kilogram_per_cubic_meter/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakOilPriorToContinuedFlight"><Units:kilogram_per_cubic_meter/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakDepth"><Units:meter/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakLatitude"><Units:degree/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakLongitude"><Units:degree/><Value>NaN</Value></DefineOutput>

    <DefineOutput Name="PatchPeakDistance"><Units:meter/><Value>0</Value></DefineOutput>

    <DefineOutput Name="StoppedForNaNPatchPeak"><Description>
        Mission stopped because patch peak value is NaN. Initialized to False.
    </Description><False/></DefineOutput>

    <DefineOutput Name="StoppedPolygonNotDefined"><Description>
        Mission stopped because the bounding polygon is not defined. Initialized
        to False.
    </Description><False/></DefineOutput>

    <DefineOutput Name="StoppedForBeingOutsideOfPolygon"><Description>
        Mission stopped because the vehicle is outside of the polygon.
        Initialized to False.
    </Description><False/></DefineOutput>

    <DefineOutput Name="ElapsedSinceStart"><Description>
        The mission sets this variable to reset the timer.
    </Description><Units:hour/><Value>0</Value></DefineOutput>

    <DefineOutput Name="ElapsedSinceLastTurn"><Description>
        The mission sets this variable to reset the timer.
    </Description><Units:hour/><Value>0</Value></DefineOutput>

    <DefineOutput Name="ElapsedSinceEndOfTransit"><Description>
        The mission sets this variable to reset the timer.
    </Description><Units:hour/><Value>0</Value></DefineOutput>

<!-- The timeout -->

    <Timeout Duration="MissionTimeout"/>

<!-- And now the mission -->

<!-- Uncomment to speed up simulation
    <Guidance:SetSpeed>
        <Parallel/>
        <Setting><Guidance:SetSpeed.period/><Units:millisecond/><Value>800</Value></Setting>
    </Guidance:SetSpeed>
-->

    <Guidance:AltitudeEnvelope>
        <Parallel/>
        <Setting><Guidance:AltitudeEnvelope.minAltitude/><Arg Name="MinAltitude"/></Setting>
    </Guidance:AltitudeEnvelope>

    <Guidance:DepthEnvelope>
        <Parallel/>
        <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="MaxDepth"/></Setting>
    </Guidance:DepthEnvelope>

<!-- GPS Update.  Don't go too long w/o a GPS fix. -->

    <Insert Filename="Insert/NeedComms.xml" Id="NeedComms"/>

    <Guidance:OffshoreEnvelope>
        <Parallel/>
        <Setting><Guidance:OffshoreEnvelope.minOffshore/><Arg Name="MinOffshore"/></Setting>
    </Guidance:OffshoreEnvelope>

    <Guidance:WaterDepthEnvelope>
        <Parallel/>
        <Setting><Guidance:WaterDepthEnvelope.minWaterDepth/><Arg Name="MinWaterDepth"/></Setting>
    </Guidance:WaterDepthEnvelope>

    <Guidance:Pitch>
        <Parallel/>
        <Setting><Guidance:Pitch.massPosition/><Arg Name="MassDefault"/></Setting>
    </Guidance:Pitch>

    <Guidance:Buoyancy>
        <Parallel/>
        <Setting><Guidance:Buoyancy.position /><Arg Name="BuoyancyNeutral"/></Setting>
    </Guidance:Buoyancy>

    <Insert Filename="Insert/MicromodemComms.xml" Id="MicromodemComms">
        <RedefineArg Name="CommsInterval"><Arg Name="MicromodemCommsInterval"/></RedefineArg>
    </Insert>

<!-- If we're executing here or below, lets' get science data! -->

    <Insert Filename="Insert/Science.xml">
        <RedefineArg Name="PeakDetectChlActive"><Arg Name="PeakDetectChl"/></RedefineArg>
        <RedefineArg Name="PeakDetectSalinityActive"><Arg Name="PeakDetectSalinity"/></RedefineArg>
        <RedefineArg Name="PeakDetectOilActive"><Arg Name="PeakDetectOil"/></RedefineArg>
        <RedefineArg Name="DetectTrough"><Arg Name="DetectTheTrough"/></RedefineArg>
        <RedefineArg Name="TimeWindowPeakReport"><Arg Name="TimeWindowPeakRpt"/></RedefineArg>
        <RedefineArg Name="LowPassWindowLength"><Arg Name="LowPassWindowLen"/></RedefineArg>
        <RedefineArg Name="MedianFilterLen"><Arg Name="MedianFilterLength"/></RedefineArg>
        <RedefineArg Name="PeakShallowBound"><Arg Name="PeakShallowBnd"/></RedefineArg>
        <RedefineArg Name="PeakDeepBound"><Arg Name="PeakDeepBnd"/></RedefineArg>
        <RedefineArg Name="DepChangeThreshForAttitudeFlip"><Arg Name="DepChangeThreshAttitudeFlip"/></RedefineArg>
    </Insert>

    <Guidance:SetSpeed>
        <Parallel/>
        <Setting><Guidance:SetSpeed.speed/><Arg Name="Speed"/></Setting>
    </Guidance:SetSpeed>

    <Aggregate Id="SyslogWpMaxDistanceReached">

        <When>
            <Called/>
        </When>

        <Break><Arg Name="LegContinuedFlight"/>
            <Or><Not><Arg Name="LegNotContinuedFlightEnabled"/></Not></Or>
        </Break>

        <Aggregate Id="SyslogWpMaxDistanceReachedChl">

            <Break>
                <Not><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Maximum leg distance reached. Turn onto a new heading. The patch peak is <Arg Name="PatchPeakChl"/><Units:microgram_per_liter/>at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/></Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakChl"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogWpMaxDistanceReachedSalt">

            <Break>
                <Not><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Maximum leg distance reached. Turn onto a new heading. The patch peak is <Arg Name="PatchPeakSalinity"/><Units:psu/> at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/></Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakSalinity"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogWpMaxDistanceReachedOil">

            <Break>
                <Not><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Maximum leg distance reached. Turn onto a new heading. The patch peak is <Arg Name="PatchPeakOil"/><Units:kilogram_per_cubic_meter/> at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakOil"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="SyslogContinuedFlightCompletedPatchValueLow">

        <When>
            <Called/>
        </When>

        <Aggregate Id="SyslogContinuedFlightCompletedPatchValueLowChl">

            <Break>
                <Not><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Continued flight completed. The patch peak <Arg Name="PatchPeakChl"/><Units:microgram_per_liter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than (<Arg Name="PatchPeakChlPriorToContinuedFlight"/><Units:microgram_per_liter/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakChl"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogContinuedFlightCompletedPatchValueLowSalt">

            <Break>
                <Not><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Continued flight completed. The patch peak <Arg Name="PatchPeakSalinity"/><Units:psu/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than (<Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Units:psu/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakSalinity"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogContinuedFlightCompletedPatchValueLowOil">

            <Break>
                <Not><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Continued flight completed. The patch peak <Arg Name="PatchPeakOil"/><Units:kilogram_per_cubic_meter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than (<Arg Name="PatchPeakOilPriorToContinuedFlight"/><Units:kilogram_per_cubic_meter/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakOil"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="SyslogContinuedFlightCompletedPatchValueHigh">

        <When>
            <Called/>
        </When>

        <Aggregate Id="SyslogContinuedFlightCompletedPatchValueHighChl">

            <Break>
                <Not><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Continued flight completed. The patch peak <Arg Name="PatchPeakChl"/><Units:microgram_per_liter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is higher than (<Arg Name="PatchPeakChlPriorToContinuedFlight"/><Units:microgram_per_liter/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Maintain heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakChl"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogContinuedFlightCompletedPatchValueHighSalt">

            <Break>
                <Not><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Continued flight completed. The patch peak <Arg Name="PatchPeakSalinity"/><Units:psu/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is higher than (<Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Units:psu/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Maintain heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakSalinity"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogContinuedFlightCompletedPatchValueHighOil">

            <Break>
                <Not><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Continued flight completed. The patch peak <Arg Name="PatchPeakOil"/><Units:kilogram_per_cubic_meter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is higher than (<Arg Name="PatchPeakOilPriorToContinuedFlight"/><Units:kilogram_per_cubic_meter/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Maintain heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakOil"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="SyslogPeakFoundContinuedFlightPatchValueLow">

        <When>
            <Called/>
        </When>

        <Aggregate Id="SyslogPeakFoundContinuedFlightPatchValueLowChl">

            <Break>
                <Not><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the continued flight is completed. The patch peak <Arg Name="PatchPeakChl"/><Units:microgram_per_liter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than (<Arg Name="PatchPeakChlPriorToContinuedFlight"/><Units:microgram_per_liter/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakChl"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogPeakFoundContinuedFlightPatchValueLowSalinity">

            <Break>
                <Not><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the continued flight is completed. The patch peak <Arg Name="PatchPeakSalinity"/><Units:psu/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than (<Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Units:psu/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakSalinity"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogPeakFoundContinuedFlightPatchValueLowOil">

            <Break>
                <Not><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the continued flight is completed. The patch peak <Arg Name="PatchPeakOil"/><Units:kilogram_per_cubic_meter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than (<Arg Name="PatchPeakOilPriorToContinuedFlight"/><Units:kilogram_per_cubic_meter/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakOil"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="SyslogPeakFoundContinuedFlightPatchValueHigh">

        <When>
            <Called/>
        </When>

        <Aggregate Id="SyslogPeakFoundContinuedFlightPatchValueHighChl">

            <Break>
                <Not><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the continued flight is completed. The patch peak <Arg Name="PatchPeakChl"/><Units:microgram_per_liter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is higher than (<Arg Name="PatchPeakChlPriorToContinuedFlight"/><Units:microgram_per_liter/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Maintain heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakChl"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogPeakFoundContinuedFlightPatchValueHighSalinity">

            <Break>
                <Not><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the continued flight is completed. The patch peak <Arg Name="PatchPeakSalinity"/><Units:psu/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is higher than (<Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Units:psu/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Maintain heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakSalinity"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogPeakFoundContinuedFlightPatchValueHighOil">

            <Break>
                <Not><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the continued flight is completed. The patch peak <Arg Name="PatchPeakOil"/><Units:kilogram_per_cubic_meter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is higher than (<Arg Name="PatchPeakOilPriorToContinuedFlight"/><Units:kilogram_per_cubic_meter/> * <Arg Name="OffPeakFraction"/><Units:percent/>). Maintain heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakOil"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="SyslogPeakFoundNotContinuedFlightLow">

        <When>
            <Called/>
        </When>

        <Aggregate Id="SyslogPeakFoundNotContinuedFlightLowChl">

            <Break>
                <Not><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the maximum leg distance is reached. The patch peak <Arg Name="PatchPeakChl"/><Units:microgram_per_liter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than <Arg Name="BeginThresholdChl"/><Units:microgram_per_liter/>. Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakChl"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogPeakFoundNotContinuedFlightLowSalinity">

            <Break>
                <Not><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the maximum leg distance is reached. The patch peak <Arg Name="PatchPeakSalinity"/><Units:psu/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than <Arg Name="BeginThresholdSalt"/><Units:psu/>. Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakSalinity"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogPeakFoundNotContinuedFlightLowOil">

            <Break>
                <Not><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the maximum leg distance is reached. The patch peak <Arg Name="PatchPeakOil"/><Units:kilogram_per_cubic_meter/> (at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>) is lower than <Arg Name="BeginThresholdOil"/><Units:kilogram_per_cubic_meter/>. Turn onto a new heading.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakOil"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="SyslogPeakFoundNotContinuedFlightHigh">

        <When>
            <Called/>
        </When>

        <Aggregate Id="SyslogPeakFoundNotContinuedFlightHighChl">

            <Break>
                <Not><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the maximum leg distance is reached. The patch peak is <Arg Name="PatchPeakChl"/><Units:microgram_per_liter/> at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>. Will continue flight for <Arg Name="TimePastOffPeakThreshold"/><Units:minute/>.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakChl"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogPeakFoundNotContinuedFlightHighSalinity">

            <Break>
                <Not><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the maximum leg distance is reached. The patch peak is <Arg Name="PatchPeakSalinity"/><Units:psu/> at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>. Will continue flight for <Arg Name="TimePastOffPeakThreshold"/><Units:minute/>.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakSalinity"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

        <Aggregate Id="SyslogPeakFoundNotContinuedFlightHighOil">

            <Break>
                <Not><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">The patch peak is found before the maximum leg distance is reached. The patch peak is <Arg Name="PatchPeakOil"/><Units:kilogram_per_cubic_meter/> at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>. Will continue flight for <Arg Name="TimePastOffPeakThreshold"/><Units:minute/>.</Syslog>

            <SendData Service="Express"><Arg Name="PatchPeakOil"/><Arg Name="PatchPeakDepth"/><Arg Name="PatchPeakLatitude"/><Arg Name="PatchPeakLongitude"/>
            </SendData>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="SyslogHittingWall">

        <When>
            <Called/>
        </When>

        <Aggregate Id="SyslogHittingWallChl">

            <Break>
                <Not><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Latitude = <Universal:latitude/><Units:degree/>, longitude = <Universal:longitude/><Units:degree/>. Shortest distance <Derivation:ShortestDistanceToPolygonSidesCalculator.shortest_distance_to_polygon_sides/><Units:meter/> to side <Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Units:count/>: less than MinDistFromPolygonSides <Arg Name="MinDistFromPolygonSides"/><Units:meter/> and vehicle is inside polygon, or larger than MinDistFromPolygonSides <Arg Name="MinDistFromPolygonSides"/><Units:meter/> but vehicle outside of polygon on a fresh GPS fix. The patch peak is <Arg Name="PatchPeakChl"/><Units:microgram_per_liter/>at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>.</Syslog>

        </Aggregate>

        <Aggregate Id="SyslogHittingWallSalinity">

            <Break>
                <Not><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Latitude = <Universal:latitude/><Units:degree/>, longitude = <Universal:longitude/><Units:degree/>. Shortest distance <Derivation:ShortestDistanceToPolygonSidesCalculator.shortest_distance_to_polygon_sides/><Units:meter/> to side <Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Units:count/>: less than MinDistFromPolygonSides <Arg Name="MinDistFromPolygonSides"/><Units:meter/> and vehicle is inside polygon, or larger than MinDistFromPolygonSides <Arg Name="MinDistFromPolygonSides"/><Units:meter/> but vehicle outside of polygon on a fresh GPS fix. The patch peak is <Arg Name="PatchPeakSalinity"/><Units:psu/>at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>.</Syslog>

        </Aggregate>

        <Aggregate Id="SyslogHittingWallOil">

            <Break>
                <Not><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Not>
            </Break>

            <Syslog Severity="Important">Latitude = <Universal:latitude/><Units:degree/>, longitude = <Universal:longitude/><Units:degree/>. Shortest distance <Derivation:ShortestDistanceToPolygonSidesCalculator.shortest_distance_to_polygon_sides/><Units:meter/> to side <Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Units:count/>: less than MinDistFromPolygonSides <Arg Name="MinDistFromPolygonSides"/><Units:meter/> and vehicle is inside polygon, or larger than MinDistFromPolygonSides <Arg Name="MinDistFromPolygonSides"/><Units:meter/> but vehicle outside of polygon on a fresh GPS fix. The patch peak is <Arg Name="PatchPeakOil"/><Units:kilogram_per_cubic_meter/>at <Arg Name="PatchPeakLatitude"/><Units:degree/>,<Arg Name="PatchPeakLongitude"/><Units:degree/>, distance = <Arg Name="PatchPeakDistance"/><Units:meter/>.</Syslog>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="Wait">

        <When>
            <Called/>
        </When>

        <Syslog Severity="Important">Continue flight for <Arg Name="TimePastOffPeakThreshold"/><Units:minute/> before the next leg.</Syslog>

        <Guidance:Wait>
            <Sequence/>
            <Setting><Guidance:Wait.duration/><Arg Name="TimePastOffPeakThreshold"/></Setting>
        </Guidance:Wait>

    </Aggregate>

    <Aggregate Id="Detach">

        <Sequence/>

        <Timeout Duration="DetachTimeout">
            <Syslog Severity="Important">Timed out trying to detach from dock. Stopping mission.</Syslog>
            <Guidance:Execute>
                <Sequence/>
                <Setting><Guidance:Execute.command/><String>stop</String></Setting>
            </Guidance:Execute>
        </Timeout>

        <Syslog Severity="Important">Detaching from dock.</Syslog>

<!-- Turn on tracking so we get some ranges to see how far we are from the dock -->

        <Estimation:TrackAcousticContact>
            <Parallel/>
            <Setting><Estimation:TrackAcousticContact.contactLabelSetting/><Arg Name="TransponderCode"/></Setting>
            <Setting><Estimation:TrackAcousticContact.numberOfSamplesSetting/><Arg Name="NumberOfPings"/></Setting>
            <Setting><Estimation:TrackAcousticContact.updatePeriodSetting/><Arg Name="TrackingUpdatePeriod"/></Setting>
        </Estimation:TrackAcousticContact>

<!-- Time to leave the dock! -->

        <Dock:Undock>
            <Sequence/>
        </Dock:Undock>

    </Aggregate>

    <Aggregate Id="MissionStartComms">

        <Sequence/>

        <When>
            <Arg Name="CommsAtMissionStart"/>
            <And><Not><Arg Name="MissionStartCommsCompleted"/></Not></And>
        </When>

        <Call Id="MissionStartComms" RefId="NeedComms"/>

        <Assign><Sequence/><Arg Name="MissionStartCommsCompleted"/><True/></Assign>

    </Aggregate>

    <Aggregate Id="MissionStartSettings">

        <Assign><Sequence/><Arg Name="ElapsedSinceStart"/><Units:hour/><Value>0</Value></Assign>

        <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

        <Assign><Sequence/><Arg Name="Turn"/><Arg Name="TurnAngleBase"/></Assign>

        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

    </Aggregate>

    <Aggregate Id="TransitToPatchMappingStartLocation">

        <Sequence/>

        <Break>
            <IsNaN><Arg Name="LatPatchMappingStart"/>
            </IsNaN>
            <Or><IsNaN><Arg Name="LonPatchMappingStart"/>
            </IsNaN></Or>
        </Break>

        <Assign><Sequence/><Arg Name="NeedComms:DiveInterval"/><Arg Name="NeedCommsTimeInTransit"/></Assign>

        <Guidance:DepthEnvelope>
            <Parallel/>
            <Setting><Guidance:DepthEnvelope.minDepth/><Arg Name="TransitYoYoMinDepth"/></Setting>
            <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="TransitYoYoMaxDepth"/></Setting>
        </Guidance:DepthEnvelope>

        <Guidance:AltitudeEnvelope>
            <Description>
                Another altitude envelope for the YoYo behavior. This envelope
                should fall within the limits of the standard safety envelopes
                in Insert/StandardEnvelopes.xml in order to avoid commanding
                high pitch angles for bottom-terminated YoYos.
            </Description>
            <Parallel/>
            <Setting><Guidance:AltitudeEnvelope.minAltitude/><Arg Name="YoYoMinAltitude"/></Setting>
            <Setting><Guidance:AltitudeEnvelope.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
        </Guidance:AltitudeEnvelope>

        <Guidance:YoYo>
            <Parallel/>
            <Setting><Guidance:YoYo.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
            <Setting><Guidance:YoYo.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
        </Guidance:YoYo>

        <Guidance:Waypoint>
            <Sequence/>
            <Setting><Guidance:Waypoint.latitude/><Arg Name="LatPatchMappingStart"/></Setting>
            <Setting><Guidance:Waypoint.longitude/><Arg Name="LonPatchMappingStart"/></Setting>
        </Guidance:Waypoint>

        <Assign><Sequence/><Arg Name="NeedComms:DiveInterval"/><Arg Name="NeedCommsTimePatchMapping"/></Assign>

        <Assign><Sequence/><Arg Name="ElapsedSinceEndOfTransit"/><Units:hour/><Value>0</Value></Assign>

    </Aggregate>

    <Aggregate Id="PolygonNotDefined">

        <Sequence/>

        <When>
            <Not><Derivation:ShortestDistanceToPolygonSidesCalculator.loadAtStartup/></Not>
        </When>

        <Break><Arg Name="StoppedPolygonNotDefined"/>
        </Break>

        <Syslog Severity="Important">Bounding polygon is not defined. Stopping mission.</Syslog>

        <Guidance:Execute>
            <Sequence/>
            <Setting><Guidance:Execute.command/><String>stop</String></Setting>
        </Guidance:Execute>

        <Assign><Sequence/><Arg Name="StoppedPolygonNotDefined"/><True/></Assign>

    </Aggregate>

    <Aggregate Id="PatchPeakIsNaN">

        <Sequence/>

        <When>
            <Elapsed><Arg Name="ElapsedSinceStart"/></Elapsed>
            <Gt><Arg Name="CheckNaNTimeout"/></Gt>
            <And><IsNaN><Arg Name="LatPatchMappingStart"/>
            </IsNaN><Or><IsNaN><Arg Name="LonPatchMappingStart"/>
            </IsNaN></Or></And>
            <Or><Elapsed><Arg Name="ElapsedSinceEndOfTransit"/></Elapsed><Gt><Arg Name="CheckNaNTimeout"/></Gt><And><Not><IsNaN><Arg Name="LatPatchMappingStart"/>
            </IsNaN><Or><IsNaN><Arg Name="LonPatchMappingStart"/>
            </IsNaN></Or></Not></And></Or>
        </When>

        <Break><Arg Name="PeakDetectChl"/>
            <And><Arg Name="PatchPeakChl"/><Ge><Units:microgram_per_liter/><Value>0.0</Value></Ge></And>
            <Or><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Ge><Units:psu/><Value>0.0</Value></Ge></And></Or>
            <Or><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Ge><Units:kilogram_per_cubic_meter/><Value>0.0</Value></Ge></And></Or>
            <Or><Arg Name="StoppedForNaNPatchPeak"/></Or>
        </Break>

        <Syslog Severity="Important">Patch peak value is NaN. Stopping mission.</Syslog>

        <Guidance:Execute>
            <Sequence/>
            <Setting><Guidance:Execute.command/><String>stop</String></Setting>
        </Guidance:Execute>

        <Assign><Sequence/><Arg Name="StoppedForNaNPatchPeak"/><True/></Assign>

    </Aggregate>

    <Aggregate Id="PatchMapping">

        <Sequence Repeat="Repeat"/>

        <Assign><Sequence/><Arg Name="PeakFoundNotContinuedFlightLowEnabled"/><True/></Assign>

        <Assign><Sequence/><Arg Name="PeakFoundNotContinuedFlightHighEnabled"/><True/></Assign>

        <Assign><Sequence/><Arg Name="PeakFoundContinuedFlightLowEnabled"/><True/></Assign>

        <Assign><Sequence/><Arg Name="PeakFoundContinuedFlightHighEnabled"/><True/></Assign>

        <Assign><Sequence/><Arg Name="LegNotContinuedFlightEnabled"/><True/></Assign>

        <Assign><Sequence/><Arg Name="LegContinuedFlightLowEnabled"/><True/></Assign>

        <Assign><Sequence/><Arg Name="LegContinuedFlightHighEnabled"/><True/></Assign>

        <Assign><Sequence/><Arg Name="ZigDone"/><False/></Assign>

        <Assign><Sequence/><Arg Name="PatchDetectOn"/><True/></Assign>

        <Guidance:DepthEnvelope>
            <Parallel/>
            <Setting><Guidance:DepthEnvelope.minDepth/><Arg Name="PatchMappingYoYoMinDepth"/></Setting>
            <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="PatchMappingYoYoMaxDepth"/></Setting>
        </Guidance:DepthEnvelope>

        <Guidance:AltitudeEnvelope>
            <Description>
                Another altitude envelope for the YoYo behavior. This envelope
                should fall within the limits of the standard safety envelopes
                in Insert/StandardEnvelopes.xml in order to avoid commanding
                high pitch angles for bottom-terminated YoYos.
            </Description>
            <Parallel/>
            <Setting><Guidance:AltitudeEnvelope.minAltitude/><Arg Name="YoYoMinAltitude"/></Setting>
            <Setting><Guidance:AltitudeEnvelope.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
        </Guidance:AltitudeEnvelope>

        <Guidance:YoYo>
            <Parallel/>
            <Setting><Guidance:YoYo.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
            <Setting><Guidance:YoYo.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
        </Guidance:YoYo>

        <Aggregate Id="OutsideOfPolygon">

            <Parallel/>

            <Break>
                <Derivation:ShortestDistanceToPolygonSidesCalculator.inside_polygon/>
                <Or><Elapsed><Universal:time_fix/></Elapsed><Le><Arg Name="ElapsedTimeSinceLastGPSForCheckingOutsidePolygon"/></Le></Or>
                <Or><Arg Name="StoppedForBeingOutsideOfPolygon"/></Or>
            </Break>

            <Syslog Severity="Important">Latitude = <Universal:latitude/><Units:degree/>, longitude = <Universal:longitude/><Units:degree/>. The vehicle is outside of the polygon. Stopping mission.</Syslog>

            <Guidance:Execute>
                <Sequence/>
                <Setting><Guidance:Execute.command/><String>stop</String></Setting>
            </Guidance:Execute>

            <Assign><Sequence/><Arg Name="StoppedForBeingOutsideOfPolygon"/><True/></Assign>

        </Aggregate>

        <Aggregate Id="HitWallTerminateZigSide0Side2">

            <Sequence/>

            <When>
                <Elapsed><Arg Name="ElapsedSinceLastTurn"/></Elapsed>
                <Gt><Arg Name="WaitAfterHittingWall"/></Gt>
                <And><Derivation:ShortestDistanceToPolygonSidesCalculator.shortest_distance_to_polygon_sides/><Le><Arg Name="MinDistFromPolygonSides"/></Le><Or><Not><Derivation:ShortestDistanceToPolygonSidesCalculator.inside_polygon/></Not></Or></And>
                <And><Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Eq><Units:count/><Value>0</Value></Eq><Or><Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Eq><Units:count/><Value>2</Value></Eq></Or></And>
                <And><Not><Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Eq><Arg Name="SideLastHit"/></Eq><And><Arg Name="WpBearing"/><Eq><Arg Name="WpBearingAfterLastWallHit"/></Eq></And></Not></And>
            </When>

            <Break><Arg Name="ZigDone"/>
            </Break>

            <Assign><Sequence/><Arg Name="SideLastHit"/><Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/></Assign>

            <Call Id="SyslogHittingWallZigSide0Side2" RefId="SyslogHittingWall"/>

            <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
            </Mod></Assign>

            <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

            <Assign><Sequence/><Arg Name="WpBearingAfterLastWallHit"/><Arg Name="WpBearing"/></Assign>

            <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

            <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

            <Assign><Sequence/><Arg Name="PatchPeakChlPriorToContinuedFlight"/><Units:microgram_per_liter/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Units:psu/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="PatchPeakOilPriorToContinuedFlight"/><Units:kilogram_per_cubic_meter/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

            <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

        </Aggregate>

        <Aggregate Id="HitWallTerminateZigSide1Side3">

            <Sequence/>

            <When>
                <Elapsed><Arg Name="ElapsedSinceLastTurn"/></Elapsed>
                <Gt><Arg Name="WaitAfterHittingWall"/></Gt>
                <And><Derivation:ShortestDistanceToPolygonSidesCalculator.shortest_distance_to_polygon_sides/><Le><Arg Name="MinDistFromPolygonSides"/></Le><Or><Not><Derivation:ShortestDistanceToPolygonSidesCalculator.inside_polygon/></Not></Or></And>
                <And><Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Eq><Units:count/><Value>1</Value></Eq><Or><Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Eq><Units:count/><Value>3</Value></Eq></Or></And>
                <And><Not><Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/><Eq><Arg Name="SideLastHit"/></Eq><And><Arg Name="WpBearing"/><Eq><Arg Name="WpBearingAfterLastWallHit"/></Eq></And></Not></And>
            </When>

            <Break><Arg Name="ZigDone"/>
            </Break>

            <Assign><Sequence/><Arg Name="SideLastHit"/><Derivation:ShortestDistanceToPolygonSidesCalculator.side_shortest_distance/></Assign>

            <Call Id="SyslogHittingWallZigSide1Side3" RefId="SyslogHittingWall"/>

            <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Reverse"/></Add><Mod><Arg Name="TwoPi"/>
            </Mod></Assign>

            <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

            <Assign><Sequence/><Arg Name="WpBearingAfterLastWallHit"/><Arg Name="WpBearing"/></Assign>

            <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

            <Assign><Sequence/><Arg Name="PatchPeakChlPriorToContinuedFlight"/><Units:microgram_per_liter/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Units:psu/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="PatchPeakOilPriorToContinuedFlight"/><Units:kilogram_per_cubic_meter/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

            <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

        </Aggregate>

        <Aggregate Id="ChlPatchDetectionZig">

            <Sequence/>

            <When>
                <Arg Name="PeakDetectChl"/>
            </When>

            <Break><Arg Name="ZigDone"/>
            </Break>

            <Trigger:PeakDetectHorizontal Id="PatchTrackTrigger">
                <Sequence/>
                <Break><Arg Name="ZigDone"/>
                </Break>
                <Setting><Trigger:PeakDetectHorizontal.patchTracking/><True/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectFrom/><Arg Name="Science:PeakChl"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectTrough/><Arg Name="Science:DetectTrough"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.depthFrom/><Arg Name="Science:PeakChlDepth"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.latitudeFrom/><Arg Name="Science:PeakChlLatitude"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.longitudeFrom/><Arg Name="Science:PeakChlLongitude"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.beginThreshold/><Arg Name="BeginThresholdChl"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.offPeakFraction/><Arg Name="OffPeakFraction"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.filterWidth/><Arg Name="FilterWidthHorizontal"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.numProfilesSlidingwindow/><Arg Name="NumOfProfilesSlidingwindow"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectTimeout/><Arg Name="DetectionTimeout"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.centerPeak/><Arg Name="PatchMode"/></Setting>
                <OutputArg Name="PatchPeakChl"><Trigger:PeakDetectHorizontal.peakDetect/></OutputArg>
                <OutputArg Name="PatchPeakDepth"><Trigger:PeakDetectHorizontal.peakDepth/></OutputArg>
                <OutputArg Name="PatchPeakLatitude"><Trigger:PeakDetectHorizontal.peakLatitude/></OutputArg>
                <OutputArg Name="PatchPeakLongitude"><Trigger:PeakDetectHorizontal.peakLongitude/></OutputArg>
                <OutputArg Name="PatchPeakDistance"><Trigger:PeakDetectHorizontal.peakDistance/></OutputArg>
            </Trigger:PeakDetectHorizontal>

            <Aggregate Id="PeakFoundTerminateZig">

                <Sequence/>

                <Break><Arg Name="ZigDone"/>
                </Break>

                <Aggregate Id="NotInContinuedFlight">

                    <Sequence/>

                    <Break><Arg Name="LegContinuedFlight"/>
                    </Break>

                    <Aggregate Id="PeakFoundNotContinuedFlightLow">

                        <Break><Arg Name="PatchPeakChl"/>
                            <Gt><Arg Name="BeginThresholdChl"/></Gt>
                            <Or><Arg Name="PatchPeakChl"/><Lt><Arg Name="BeginThresholdChl"/><Mult><Arg Name="fractionOfThreshold"/></Mult></Lt><And><Not><Arg Name="PatchPeakChlPriorToContinuedFlight"/><Ge><Arg Name="BeginThresholdChl"/></Ge></Not></And></Or>
                            <Or><Not><Arg Name="PeakFoundNotContinuedFlightLowEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundNotContinuedFlightHighEnabled"/><False/></Assign>

                        <Call Id="PeakFoundNotContinuedFlightLow" RefId="SyslogPeakFoundNotContinuedFlightLow"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
                        </Mod></Assign>

                        <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

                        <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                    <Aggregate Id="PeakFoundNotContinuedFlightHigh">

                        <Break><Arg Name="PatchPeakChl"/>
                            <Le><Arg Name="BeginThresholdChl"/></Le>
                            <Or><Not><Arg Name="PeakFoundNotContinuedFlightHighEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundNotContinuedFlightLowEnabled"/><False/></Assign>

                        <Call Id="PeakFoundNotContinuedFlightHigh" RefId="SyslogPeakFoundNotContinuedFlightHigh"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="PatchPeakChlPriorToContinuedFlight"/><Arg Name="PatchPeakChl"/></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="TimePastOffPeakThreshold"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><True/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                </Aggregate>

                <Aggregate Id="InContinuedFlight">

                    <Sequence/>

                    <Break>
                        <Not><Arg Name="LegContinuedFlight"/></Not>
                    </Break>

                    <Aggregate Id="PeakFoundContinuedFlightPatchValueLow">

                        <Break><Arg Name="PatchPeakChl"/>
                            <Gt><Arg Name="PatchPeakChlPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Gt>
                            <Or><Not><Arg Name="PeakFoundContinuedFlightLowEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundContinuedFlightHighEnabled"/><False/></Assign>

                        <Call Id="PeakFoundContinuedFlightLow" RefId="SyslogPeakFoundContinuedFlightPatchValueLow"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
                        </Mod></Assign>

                        <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

                        <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                    <Aggregate Id="PeakFoundContinuedFlightPatchValueHigh">

                        <Break><Arg Name="PatchPeakChl"/>
                            <Le><Arg Name="PatchPeakChlPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Le>
                            <Or><Not><Arg Name="PeakFoundContinuedFlightHighEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundContinuedFlightLowEnabled"/><False/></Assign>

                        <Call Id="PeakFoundContinuedFlightHigh" RefId="SyslogPeakFoundContinuedFlightPatchValueHigh"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                </Aggregate>

            </Aggregate>

        </Aggregate>

        <Aggregate Id="SalinityPatchDetectionZig">

            <Sequence/>

            <When>
                <Arg Name="PeakDetectSalinity"/>
            </When>

            <Break><Arg Name="ZigDone"/>
            </Break>

            <Trigger:PeakDetectHorizontal Id="PatchTrackTrigger">
                <Sequence/>
                <Break><Arg Name="ZigDone"/>
                </Break>
                <Setting><Trigger:PeakDetectHorizontal.patchTracking/><True/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectFrom/><Arg Name="Science:PeakSalt"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectTrough/><Arg Name="Science:DetectTrough"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.depthFrom/><Arg Name="Science:PeakSaltDepth"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.latitudeFrom/><Arg Name="Science:PeakSaltLatitude"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.longitudeFrom/><Arg Name="Science:PeakSaltLongitude"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.beginThreshold/><Arg Name="BeginThresholdSalt"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.offPeakFraction/><Arg Name="OffPeakFraction"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.filterWidth/><Arg Name="FilterWidthHorizontal"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.numProfilesSlidingwindow/><Arg Name="NumOfProfilesSlidingwindow"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectTimeout/><Arg Name="DetectionTimeout"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.centerPeak/><Arg Name="PatchMode"/></Setting>
                <OutputArg Name="PatchPeakSalinity"><Trigger:PeakDetectHorizontal.peakDetect/></OutputArg>
                <OutputArg Name="PatchPeakDepth"><Trigger:PeakDetectHorizontal.peakDepth/></OutputArg>
                <OutputArg Name="PatchPeakLatitude"><Trigger:PeakDetectHorizontal.peakLatitude/></OutputArg>
                <OutputArg Name="PatchPeakLongitude"><Trigger:PeakDetectHorizontal.peakLongitude/></OutputArg>
                <OutputArg Name="PatchPeakDistance"><Trigger:PeakDetectHorizontal.peakDistance/></OutputArg>
            </Trigger:PeakDetectHorizontal>

            <Aggregate Id="PeakFoundTerminateZig">

                <Sequence/>

                <Break><Arg Name="ZigDone"/>
                </Break>

                <Aggregate Id="NotInContinuedFlight">

                    <Sequence/>

                    <Break><Arg Name="LegContinuedFlight"/>
                    </Break>

                    <Aggregate Id="PeakFoundNotContinuedFlightLow">

                        <Break><Arg Name="PatchPeakSalinity"/>
                            <Gt><Arg Name="BeginThresholdSalt"/></Gt>
                            <Or><Arg Name="PatchPeakSalinity"/><Lt><Arg Name="BeginThresholdSalt"/><Mult><Arg Name="fractionOfThreshold"/></Mult></Lt><And><Not><Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Ge><Arg Name="BeginThresholdSalt"/></Ge></Not></And></Or>
                            <Or><Not><Arg Name="PeakFoundNotContinuedFlightLowEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundNotContinuedFlightHighEnabled"/><False/></Assign>

                        <Call Id="PeakFoundNotContinuedFlightLow" RefId="SyslogPeakFoundNotContinuedFlightLow"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
                        </Mod></Assign>

                        <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

                        <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                    <Aggregate Id="PeakFoundNotContinuedFlightHigh">

                        <Break><Arg Name="PatchPeakSalinity"/>
                            <Le><Arg Name="BeginThresholdSalt"/></Le>
                            <Or><Not><Arg Name="PeakFoundNotContinuedFlightHighEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundNotContinuedFlightLowEnabled"/><False/></Assign>

                        <Call Id="PeakFoundNotContinuedFlightHigh" RefId="SyslogPeakFoundNotContinuedFlightHigh"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Arg Name="PatchPeakSalinity"/></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="TimePastOffPeakThreshold"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><True/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                </Aggregate>

                <Aggregate Id="InContinuedFlight">

                    <Sequence/>

                    <Break>
                        <Not><Arg Name="LegContinuedFlight"/></Not>
                    </Break>

                    <Aggregate Id="PeakFoundContinuedFlightPatchValueLow">

                        <Break><Arg Name="PatchPeakSalinity"/>
                            <Gt><Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Gt>
                            <Or><Not><Arg Name="PeakFoundContinuedFlightLowEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundContinuedFlightHighEnabled"/><False/></Assign>

                        <Call Id="PeakFoundContinuedFlightLow" RefId="SyslogPeakFoundContinuedFlightPatchValueLow"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
                        </Mod></Assign>

                        <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

                        <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                    <Aggregate Id="PeakFoundContinuedFlightPatchValueHigh">

                        <Break><Arg Name="PatchPeakSalinity"/>
                            <Le><Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Le>
                            <Or><Not><Arg Name="PeakFoundContinuedFlightHighEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundContinuedFlightLowEnabled"/><False/></Assign>

                        <Call Id="PeakFoundContinuedFlightHigh" RefId="SyslogPeakFoundContinuedFlightPatchValueHigh"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                </Aggregate>

            </Aggregate>

        </Aggregate>

        <Aggregate Id="OilPatchDetectionZig">

            <Sequence/>

            <When>
                <Arg Name="PeakDetectOil"/>
            </When>

            <Break><Arg Name="ZigDone"/>
            </Break>

            <Trigger:PeakDetectHorizontal Id="PatchTrackTrigger">
                <Sequence/>
                <Break><Arg Name="ZigDone"/>
                </Break>
                <Setting><Trigger:PeakDetectHorizontal.patchTracking/><True/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectFrom/><Arg Name="Science:PeakOil"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectTrough/><Arg Name="Science:DetectTrough"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.depthFrom/><Arg Name="Science:PeakOilDepth"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.latitudeFrom/><Arg Name="Science:PeakOilLatitude"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.longitudeFrom/><Arg Name="Science:PeakOilLongitude"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.beginThreshold/><Arg Name="BeginThresholdOil"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.offPeakFraction/><Arg Name="OffPeakFraction"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.filterWidth/><Arg Name="FilterWidthHorizontal"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.numProfilesSlidingwindow/><Arg Name="NumOfProfilesSlidingwindow"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.detectTimeout/><Arg Name="DetectionTimeout"/></Setting>
                <Setting><Trigger:PeakDetectHorizontal.centerPeak/><Arg Name="PatchMode"/></Setting>
                <OutputArg Name="PatchPeakOil"><Trigger:PeakDetectHorizontal.peakDetect/></OutputArg>
                <OutputArg Name="PatchPeakDepth"><Trigger:PeakDetectHorizontal.peakDepth/></OutputArg>
                <OutputArg Name="PatchPeakLatitude"><Trigger:PeakDetectHorizontal.peakLatitude/></OutputArg>
                <OutputArg Name="PatchPeakLongitude"><Trigger:PeakDetectHorizontal.peakLongitude/></OutputArg>
                <OutputArg Name="PatchPeakDistance"><Trigger:PeakDetectHorizontal.peakDistance/></OutputArg>
            </Trigger:PeakDetectHorizontal>

            <Aggregate Id="PeakFoundTerminateZig">

                <Sequence/>

                <Break><Arg Name="ZigDone"/>
                </Break>

                <Aggregate Id="NotInContinuedFlight">

                    <Sequence/>

                    <Break><Arg Name="LegContinuedFlight"/>
                    </Break>

                    <Aggregate Id="PeakFoundNotContinuedFlightLow">

                        <Break><Arg Name="PatchPeakOil"/>
                            <Gt><Arg Name="BeginThresholdOil"/></Gt>
                            <Or><Arg Name="PatchPeakOil"/><Lt><Arg Name="BeginThresholdOil"/><Mult><Arg Name="fractionOfThreshold"/></Mult></Lt><And><Not><Arg Name="PatchPeakOilPriorToContinuedFlight"/><Ge><Arg Name="BeginThresholdOil"/></Ge></Not></And></Or>
                            <Or><Not><Arg Name="PeakFoundNotContinuedFlightLowEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundNotContinuedFlightHighEnabled"/><False/></Assign>

                        <Call Id="PeakFoundNotContinuedFlightLow" RefId="SyslogPeakFoundNotContinuedFlightLow"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
                        </Mod></Assign>

                        <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

                        <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                    <Aggregate Id="PeakFoundNotContinuedFlightHigh">

                        <Break><Arg Name="PatchPeakOil"/>
                            <Le><Arg Name="BeginThresholdOil"/></Le>
                            <Or><Not><Arg Name="PeakFoundNotContinuedFlightHighEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundNotContinuedFlightLowEnabled"/><False/></Assign>

                        <Call Id="PeakFoundNotContinuedFlightHigh" RefId="SyslogPeakFoundNotContinuedFlightHigh"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="PatchPeakOilPriorToContinuedFlight"/><Arg Name="PatchPeakOil"/></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="TimePastOffPeakThreshold"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><True/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                </Aggregate>

                <Aggregate Id="InContinuedFlight">

                    <Sequence/>

                    <Break>
                        <Not><Arg Name="LegContinuedFlight"/></Not>
                    </Break>

                    <Aggregate Id="PeakFoundContinuedFlightPatchValueLow">

                        <Break><Arg Name="PatchPeakOil"/>
                            <Gt><Arg Name="PatchPeakOilPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Gt>
                            <Or><Not><Arg Name="PeakFoundContinuedFlightLowEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundContinuedFlightHighEnabled"/><False/></Assign>

                        <Call Id="PeakFoundContinuedFlightLow" RefId="SyslogPeakFoundContinuedFlightPatchValueLow"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
                        </Mod></Assign>

                        <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

                        <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                    <Aggregate Id="PeakFoundContinuedFlightPatchValueHigh">

                        <Break><Arg Name="PatchPeakOil"/>
                            <Le><Arg Name="PatchPeakOilPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Le>
                            <Or><Not><Arg Name="PeakFoundContinuedFlightHighEnabled"/></Not></Or>
                        </Break>

                        <Assign><Sequence/><Arg Name="PeakFoundContinuedFlightLowEnabled"/><False/></Assign>

                        <Call Id="PeakFoundContinuedFlightHigh" RefId="SyslogPeakFoundContinuedFlightPatchValueHigh"/>

                        <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                        <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                        <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                    </Aggregate>

                </Aggregate>

            </Aggregate>

        </Aggregate>

        <Aggregate Id="Zig">

            <Description>
                Completes transect's maximum distance.
            </Description>

            <Sequence/>

            <Break><Arg Name="ZigDone"/>
            </Break>

            <Aggregate Id="LegContinuedFlight">

                <Break>
                    <Not><Arg Name="LegContinuedFlight"/></Not>
                    <Or><Not><Arg Name="LegContinuedFlightLowEnabled"/><Or><Arg Name="LegContinuedFlightHighEnabled"/></Or></Not></Or>
                </Break>

                <Assign><Sequence/><Arg Name="PatchDetectOn"/><True/></Assign>

                <Syslog Severity="Important">Bearing = <Arg Name="WpBearing"/><Units:degree/></Syslog>

                <Aggregate Id="ZigCompleteMaxDist">

                    <Guidance:Waypoint Id="ZigMaxDist">
                        <Sequence/>
                        <Break><Arg Name="ZigDone"/>
                        </Break>
                        <Timeout Duration="WpTimeout"/>
                        <Setting><Guidance:Waypoint.distanceDelta/><Arg Name="WpMaxDistance"/></Setting>
                        <Setting><Guidance:Waypoint.distanceDeltaBearing/><Arg Name="WpBearing"/></Setting>
                        <Setting><Guidance:Waypoint.waterFrame/><Arg Name="WaterFrame"/></Setting>
                    </Guidance:Waypoint>

                </Aggregate>

                <Aggregate Id="LegContinuedFlightPatchValueLow">

                    <Break>
                        <Not><Arg Name="LegContinuedFlight"/></Not>
                        <Or><Arg Name="LegContinuedFlight"/><And><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Gt><Arg Name="PatchPeakChlPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Gt></And><Or><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Gt><Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Gt></And></Or><Or><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Gt><Arg Name="PatchPeakOilPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Gt></And></Or></And></Or>
                        <Or><Not><Arg Name="LegContinuedFlightLowEnabled"/></Not></Or>
                    </Break>

                    <Assign><Sequence/><Arg Name="LegNotContinuedFlightEnabled"/><False/></Assign>

                    <Assign><Sequence/><Arg Name="LegContinuedFlightHighEnabled"/><False/></Assign>

                    <Call Id="ContinuedFlightCompletedPatchValueLow" RefId="SyslogContinuedFlightCompletedPatchValueLow"/>

                    <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                    <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
                    </Mod></Assign>

                    <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

                    <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

                    <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                    <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                    <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                </Aggregate>

                <Aggregate Id="LegContinuedFlightPatchValueHigh">

                    <Break>
                        <Not><Arg Name="LegContinuedFlight"/></Not>
                        <Or><Arg Name="LegContinuedFlight"/><And><Arg Name="PeakDetectChl"/><And><Arg Name="PatchPeakChl"/><Le><Arg Name="PatchPeakChlPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Le></And><Or><Arg Name="PeakDetectSalinity"/><And><Arg Name="PatchPeakSalinity"/><Le><Arg Name="PatchPeakSalinityPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Le></And></Or><Or><Arg Name="PeakDetectOil"/><And><Arg Name="PatchPeakOil"/><Le><Arg Name="PatchPeakOilPriorToContinuedFlight"/><Mult><Arg Name="OffPeakFraction"/></Mult></Le></And></Or></And></Or>
                        <Or><Not><Arg Name="LegContinuedFlightHighEnabled"/></Not></Or>
                    </Break>

                    <Assign><Sequence/><Arg Name="LegNotContinuedFlightEnabled"/><False/></Assign>

                    <Assign><Sequence/><Arg Name="LegContinuedFlightLowEnabled"/><False/></Assign>

                    <Call Id="ContinuedFlightCompletedPatchValueHigh" RefId="SyslogContinuedFlightCompletedPatchValueHigh"/>

                    <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                    <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                    <Assign><Sequence/><Arg Name="LegContinuedFlight"/><False/></Assign>

                    <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

                </Aggregate>

            </Aggregate>

            <Aggregate Id="LegNotContinuedFlight">

                <Break><Arg Name="LegContinuedFlight"/>
                    <Or><Not><Arg Name="LegNotContinuedFlightEnabled"/></Not></Or>
                </Break>

                <Assign><Sequence/><Arg Name="LegContinuedFlightLowEnabled"/><False/></Assign>

                <Assign><Sequence/><Arg Name="LegContinuedFlightHighEnabled"/><False/></Assign>

                <Assign><Sequence/><Arg Name="PatchDetectOn"/><True/></Assign>

                <Syslog Severity="Important">Bearing = <Arg Name="WpBearing"/><Units:degree/></Syslog>

                <Aggregate Id="ZigCompleteMaxDist">

                    <Guidance:Waypoint Id="ZigMaxDist">
                        <Sequence/>
                        <Break><Arg Name="ZigDone"/>
                        </Break>
                        <Timeout Duration="WpTimeout"/>
                        <Setting><Guidance:Waypoint.distanceDelta/><Arg Name="WpMaxDistance"/></Setting>
                        <Setting><Guidance:Waypoint.distanceDeltaBearing/><Arg Name="WpBearing"/></Setting>
                        <Setting><Guidance:Waypoint.waterFrame/><Arg Name="WaterFrame"/></Setting>
                    </Guidance:Waypoint>

                </Aggregate>

                <Call Id="MaxLegDistReached" RefId="SyslogWpMaxDistanceReached"/>

                <Assign><Sequence/><Arg Name="PatchDetectOn"/><False/></Assign>

                <Assign><Sequence/><Arg Name="WpBearing"/><Arg Name="WpBearing"/><Add><Arg Name="Turn"/></Add><Mod><Arg Name="TwoPi"/>
                </Mod></Assign>

                <Assign><Sequence/><Arg Name="ElapsedSinceLastTurn"/><Units:hour/><Value>0</Value></Assign>

                <Assign><Sequence/><Arg Name="Turn"/><Arg Name="Turn"/><Sub><Arg Name="Turn"/></Sub><Sub><Arg Name="Turn"/></Sub></Assign>

                <Assign><Sequence/><Arg Name="WpTimeout"/><Arg Name="WpTimeoutBase"/></Assign>

                <Assign><Sequence/><Arg Name="ZigDone"/><True/></Assign>

            </Aggregate>

        </Aggregate>

    </Aggregate>

</Mission>
