/*****************************************************************************
 *                                                                           *
 *      MGS SPACECRAFT TEAM DERIVED CHANNEL DEVELOPMENT                      *
 *                                                                           *
 * ------------------------------------------------------------------------- *
 *                                                                           *
 *      Revision 1.0  PREPARED BY:  Owen G. Short                            *
 *      DATE:                                                                *
 *      Comments:                                                            *
 *                                                                           *
 *                                                                           *
 * ------------------------------------------------------------------------- *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *****************************************************************************/

MISSION = "MGS";


/*****************************************************************************
 *                                                                           *
 * A-0001 "CS_TRI_A_PWR" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load to 0.80                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2001
Description:            CS Triad A Estimated Power
Mnemonic:               CS_TRI_A_E_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2001" PARENTS = "A-0001";

FUNCT CHAN = "A-0001"

IF (GET_DN() == 1)             /* Check channel status              */
    DERIVE ("V-2001",  0.80);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2001",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0002 "CS_TRI_B_PWR" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load to 0.80                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2002
Description:            CS Triad B Estimated Power
Mnemonic:               CS_TRI_B_E_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2002" PARENTS = "A-0002";

FUNCT CHAN = "A-0002"

IF (GET_DN() == 1)             /* Check channel status              */
    DERIVE ("V-2002",  0.80);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2002",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0003 "GYRO1_SP_MTR" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2003
Description:            Gyro 1 Spin Motor Estimated Power
Mnemonic:               GYRO1_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2003" PARENTS = "A-0003""A-0160";

FUNCT CHAN = "A-0003"

IF (GET_DN() == 1 && EU_VALID("A-0160") == 0)             /* Check channel status              */
    DERIVE ("V-2003", GET_LAD_EU("A-0160") * 28.0 / 1000.0);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2003",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0004 "GYRO2_SP_MTR" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2004
Description:            Gyro 2 Spin Motor Estimated Power
Mnemonic:               GYRO2_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2004" PARENTS = "A-0004""A-0161";

FUNCT CHAN = "A-0004"

IF (GET_DN() == 1 && EU_VALID("A-0161") == 0)             /* Check channel status              */
    DERIVE ("V-2004", GET_LAD_EU("A-0161") * 28.0 / 1000.0);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2004",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0005 "GYRO3_SP_MTR" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2005
Description:            Gyro 3 Spin Motor Estimated Power
Mnemonic:               GYRO3_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2005" PARENTS = "A-0005""A-0162";

FUNCT CHAN = "A-0005"

IF (GET_DN() == 1 && EU_VALID("A-0162") == 0)             /* Check channel status              */
    DERIVE ("V-2005", GET_LAD_EU("A-0162") * 28.0 / 1000.0);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2005",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0013 "MHSA1_PWR" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2006
Description:            MHSA 1 Estimated Power
Mnemonic:               MHSA1_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2006" PARENTS = "A-0013";

FUNCT CHAN = "A-0013"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2006",  1.50);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2006",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0014 "MHSA2_PWR" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2007
Description:            MHSA 2 Estimated Power
Mnemonic:               MHSA2_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2007" PARENTS = "A-0014";

FUNCT CHAN = "A-0014"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2007",  1.50);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2007",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0120 "SS1_DC_CNV_V" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load to 1.20                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2008
Description:            Sun Sensor 1 Estimated Power
Mnemonic:               SS1_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2008" PARENTS = "A-0120";

FUNCT CHAN = "A-0120"

IF (GET_EU() > 9.0)            /* 9 volts is threshold for on status */
    DERIVE ("V-2008",  1.20);  /* If on, set on power consumption    */
ELSE
    DERIVE ("V-2008",  0.00);  /* If off, set off power consumption  */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0121 "SS2_DC_CNV_V" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 7-26-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load to 1.20                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2009
Description:            Sun Sensor 2 Estimated Power
Mnemonic:               SS2_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2009" PARENTS = "A-0121";

FUNCT CHAN = "A-0121"

IF (GET_EU() > 9.0)            /* 9 volts is threshold for on status */
    DERIVE ("V-2009",  1.20);  /* If on, set on power consumption    */
ELSE
    DERIVE ("V-2009",  0.00);  /* If off, set off power consumption  */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0130 "IMU_XA-Z2_TQ" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-12-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*
DISCONTINUOUS IMU TORQUER MEASUREMENTS
Dmd will calculate an EU from one of two calibration curves based on
the IMU RATE telemetry point (high rate or low rate).
NOTE - TEST_TYPE for this channel cannot be set to EU since no DNEU
conversion exists.  If alarms are desired, either alarm on DN or establish
a new V-XXXX derived channel to alarm on.
*/

CHILD = "A-0130" PARENTS = "A-0011";

FUNCT CHAN = "A-0130"

FLT  torque;

IF (DN_VALID("A-0011") == 0)
    IF (GET_LAD_DN("A-0011") == 1)
        torque = 1.73963E+01 + (GET_DN() * -1.38617E-01);
    ELSE
        torque = 5.83300E-01 + (GET_DN() * -4.64784E-03);
    ENDIF
PUT_EU(torque);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0131 "IMU_XB-Z3_TQ" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-12-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*
DISCONTINUOUS IMU TORQUER MEASUREMENTS
Dmd will calculate an EU from one of two calibration curves based on
the IMU RATE telemetry point (high rate or low rate).
NOTE - TEST_TYPE for this channel cannot be set to EU since no DNEU
conversion exists.  If alarms are desired, either alarm on DN or establish
a new V-XXXX derived channel to alarm on.
*/

CHILD = "A-0131" PARENTS = "A-0011";

FUNCT CHAN = "A-0131"

FLT  torque;

IF (DN_VALID("A-0011") == 0)
    IF (GET_LAD_DN("A-0011") == 1)
        torque = 1.73963E+01 + (GET_DN() * -1.38617E-01);
    ELSE
        torque = 5.83300E-01 + (GET_DN() * -4.64784E-03);
    ENDIF
PUT_EU(torque);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0132 "IMU_YA-X1_TQ" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-12-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*
DISCONTINUOUS IMU TORQUER MEASUREMENTS
Dmd will calculate an EU from one of two calibration curves based on
the IMU RATE telemetry point (high rate or low rate).
NOTE - TEST_TYPE for this channel cannot be set to EU since no DNEU
conversion exists.  If alarms are desired, either alarm on DN or establish
a new V-XXXX derived channel to alarm on.
*/

CHILD = "A-0132" PARENTS = "A-0011";

FUNCT CHAN = "A-0132"

FLT  torque;

IF (DN_VALID("A-0011") == 0)
    IF (GET_LAD_DN("A-0011") == 1)
        torque = 1.73963E+01 + (GET_DN() * -1.38617E-01);
    ELSE
        torque = 5.83300E-01 + (GET_DN() * -4.64784E-03);
    ENDIF
PUT_EU(torque);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0133 "IMU_YB-X3_TQ" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-12-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*
DISCONTINUOUS IMU TORQUER MEASUREMENTS
Dmd will calculate an EU from one of two calibration curves based on
the IMU RATE telemetry point (high rate or low rate).
NOTE - TEST_TYPE for this channel cannot be set to EU since no DNEU
conversion exists.  If alarms are desired, either alarm on DN or establish
a new V-XXXX derived channel to alarm on.
*/

CHILD = "A-0133" PARENTS = "A-0011";

FUNCT CHAN = "A-0133"

FLT  torque;

IF (DN_VALID("A-0011") == 0)
    IF (GET_LAD_DN("A-0011") == 1)
        torque = 1.73963E+01 + (GET_DN() * -1.38617E-01);
    ELSE
        torque = 5.83300E-01 + (GET_DN() * -4.64784E-03);
    ENDIF
PUT_EU(torque);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0134 "IMU_ZA+Y1_TQ" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-12-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*
DISCONTINUOUS IMU TORQUER MEASUREMENTS
Dmd will calculate an EU from one of two calibration curves based on
the IMU RATE telemetry point (high rate or low rate).
NOTE - TEST_TYPE for this channel cannot be set to EU since no DNEU
conversion exists.  If alarms are desired, either alarm on DN or establish
a new V-XXXX derived channel to alarm on.
*/

CHILD = "A-0134" PARENTS = "A-0011";

FUNCT CHAN = "A-0134"

FLT  torque;

IF (DN_VALID("A-0011") == 0)
    IF (GET_LAD_DN("A-0011") == 1)
        torque = 1.73963E+01 + (GET_DN() * -1.38617E-01);
    ELSE
        torque = 5.83300E-01 + (GET_DN() * -4.64784E-03);
    ENDIF
PUT_EU(torque);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0135 "IMU_ZB+Y2_TQ" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-12-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*
DISCONTINUOUS IMU TORQUER MEASUREMENTS
Dmd will calculate an EU from one of two calibration curves based on
the IMU RATE telemetry point (high rate or low rate).
NOTE - TEST_TYPE for this channel cannot be set to EU since no DNEU
conversion exists.  If alarms are desired, either alarm on DN or establish
a new V-XXXX derived channel to alarm on.
*/

CHILD = "A-0135" PARENTS = "A-0011";

FUNCT CHAN = "A-0135"

FLT  torque;

IF (DN_VALID("A-0011") == 0)
    IF (GET_LAD_DN("A-0011") == 1)
        torque = 1.73963E+01 + (GET_DN() * -1.38617E-01);
    ELSE
        torque = 5.83300E-01 + (GET_DN() * -4.64784E-03);
    ENDIF
PUT_EU(torque);
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * A-0170 "RWA_X_MTR_I" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 7-24-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2010
Description:            RWA X Motor Estimated Power
Mnemonic:               RWA_X_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2010" PARENTS = "A-0170";

FUNCT CHAN = "A-0170"

/* Derive Reaction Wheel Estimated Power from Reaction Wheel Currents,
   Assume a 10.2 volts power supply */

DERIVE ("V-2010", (GET_EU() * 10.2));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0171 "RWA_Y_MTR_I" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 7-24-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2011
Description:            RWA Y Motor Estimated Power
Mnemonic:               RWA_Y_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2011" PARENTS = "A-0171";

FUNCT CHAN = "A-0171"

/* Derive Reaction Wheel Estimated Power from Reaction Wheel Currents,
   Assume a 10.2 volts power supply */

DERIVE ("V-2011", (GET_EU() * 10.2));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0172 "RWA_Z_MTR_I" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 7-24-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2012
Description:            RWA Z Motor Estimated Power
Mnemonic:               RWA_Z_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2012" PARENTS = "A-0172";

FUNCT CHAN = "A-0172"

/* Derive Reaction Wheel Estimated Power from Reaction Wheel Currents,
   Assume a 10.2 volts power supply */

DERIVE ("V-2012", (GET_EU() * 10.2));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * A-0173 "RWA_S_MTR_I" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 7-24-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2013
Description:            RWA S Motor Estimated Power
Mnemonic:               RWA_S_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2013" PARENTS = "A-0173";

FUNCT CHAN = "A-0173"

/* Derive Reaction Wheel Estimated Power from Reaction Wheel Currents,
   Assume a 10.2 volts power supply */

DERIVE ("V-2013", (GET_EU() * 10.2));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0011 "EDF_SIDE1_ST" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load value                       *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2015
Description:            EDF Side 1 Estimated Power
Mnemonic:               EDF_SIDE1_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2015" PARENTS = "C-0011";

FUNCT CHAN = "C-0011"

IF (GET_DN() == 1)             /* Check channel status (1 = On)     */
    DERIVE ("V-2015",  4.80);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2015",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0012 "EDF_SIDE2_ST" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2016
Description:            EDF Side 2 Estimated Power
Mnemonic:               EDF_SIDE2_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2016" PARENTS = "C-0012";

FUNCT CHAN = "C-0012"

IF (GET_DN() == 1)             /* Check channel status (1 = On)     */
    DERIVE ("V-2016",  4.80);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2016",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0017 "M_PHASE_R3S1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-25-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-1007
Description:            Mission Phase SCU1
Mnemonic:               MSN_PHS_SCU1
Subsystem:              CDH
Data_Type:              STATUS
States:                 FAILED,INNR_CRZ,OUTR_CRZ,FAILED,MAPPING,FAILED,FAILED,AEROBRKE

*/

CHILD = "V-1007" PARENTS = "C-0013""C-0015""C-0017";

FUNCT CHAN = "C-0017"

UINT mp_state;

IF (DN_VALID("C-0013") == 0 && DN_VALID("C-0015") == 0)
    mp_state = (GET_LAD_DN("C-0013") * 4) + (GET_LAD_DN("C-0015") * 2) + GET_DN();
    DERIVE ("V-1007", mp_state);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0018 "M_PHASE_R3S2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-25-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-1008
Description:            Mission Phase SCU2
Mnemonic:               MSN_PHS_SCU2
Subsystem:              CDH
Data_Type:              STATUS
States:                 FAILED,INNR_CRZ,OUTR_CRZ,FAILED,MAPPING,FAILED,FAILED,AEROBRKE

*/

CHILD = "V-1008" PARENTS = "C-0014""C-0016""C-0018";

FUNCT CHAN = "C-0018"

UINT mp_state;

IF (DN_VALID("C-0014") == 0 && DN_VALID("C-0016") == 0)
    mp_state = (GET_LAD_DN("C-0014") * 4) + (GET_LAD_DN("C-0016") * 2) + GET_DN();
     DERIVE ("V-1008", mp_state);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0024 "PDS_A_PWR_ON" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2025
Description:            PDS Side A Estimated Power
Mnemonic:               PDS_A_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2025" PARENTS = "C-0024";

FUNCT CHAN = "C-0024"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2025",  2.60);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2025",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0025 "PDS_A_PWR_ON" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2026
Description:            PDS Side B Estimated Power
Mnemonic:               PDS_B_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2026" PARENTS = "C-0025";

FUNCT CHAN = "C-0025"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2026",  2.60);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2026",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * C-0035 "SCU1SCPK2_ST" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load value                       *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-1001
Description:            SCU1 SCP1 Power Status
Mnemonic:               SCU1SCP1_ST
Subsystem:              CDH
Data_Type:              STATUS
States:                 ON,OFF

Derived Channel:        V-1002
Description:            SCU1 SCP2 Power Status
Mnemonic:               SCU1SCP2_ST
Subsystem:              CDH
Data_Type:              STATUS
States:                 ON,OFF

Derived Channel:        V-2017
Description:            SCP1 Estimated Power
Mnemonic:               SCP1_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2018
Description:            SCP2 Estimated Power
Mnemonic:               SCP1_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-1001" PARENTS = "C-0034""C-0035";
CHILD = "V-1002" PARENTS = "C-0034""C-0035";
CHILD = "V-2017" PARENTS = "C-0034""C-0035";
CHILD = "V-2018" PARENTS = "C-0034""C-0035";

FUNCT CHAN = "C-0035"

/* Derive SCP1 and SCP2 Power Status from SCU1 K1 and K2 relay position
      K1     K2      SCP1      SCP2
      0      0       On        On
      0      1       On        Off
      1      0       Off       On
      1      1       On        On
*/

IF (DN_VALID("C-0034") == 0)
    IF    (GET_LAD_DN("C-0034") == 0 && GET_DN() == 0)
        DERIVE ("V-1001",0);
        DERIVE ("V-1002",0);
        DERIVE ("V-2017", 2.60);  /* If on, set on power consumption  */
        DERIVE ("V-2018", 2.60);  /* If on, set on power consumption  */
    ELSEIF(GET_LAD_DN("C-0034") == 0 && GET_DN() == 1)
        DERIVE ("V-1001",0);
        DERIVE ("V-1002",1);
        DERIVE ("V-2017", 2.60);  /* If on, set on power consumption  */
        DERIVE ("V-2018", 0.00);  /* If off, zero power consumption   */
    ELSEIF(GET_LAD_DN("C-0034") == 1 && GET_DN() == 0)
        DERIVE ("V-1001",1);
        DERIVE ("V-1002",0);
        DERIVE ("V-2017", 0.00);  /* If off, zero power consumption   */
        DERIVE ("V-2018", 2.60);  /* If on, set on power consumption  */
    ELSEIF(GET_LAD_DN("C-0034") == 1 && GET_DN() == 1)
        DERIVE ("V-1001",0);
        DERIVE ("V-1002",0);
        DERIVE ("V-2017", 2.60);  /* If on, set on power consumption  */
        DERIVE ("V-2018", 2.60);  /* If on, set on power consumption  */
    ELSE
        RETURN;
    ENDIF
ELSE
    RETURN;
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * C-0037 "SCU2SCPK2_ST" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-1003
Description:            SCU2 SCP1 Power Status
Mnemonic:               SCU2SCP1_ST
Subsystem:              CDH
Data_Type:              STATUS
States:                 ON,OFF

Derived Channel:        V-1004
Description:            SCU2 SCP2 Power Status
Mnemonic:               SCU2SCP2_ST
Subsystem:              CDH
Data_Type:              STATUS
States:                 ON,OFF

*/

CHILD = "V-1003" PARENTS = "C-0036""C-0037";
CHILD = "V-1004" PARENTS = "C-0036""C-0037";

FUNCT CHAN = "C-0037"

/* Derive SCP1 and SCP2 Power Status from SCU2 K1 and K2 relay position
      K1     K2      SCP1      SCP2
      0      0       On        On
      0      1       On        Off
      1      0       Off       On
      1      1       On        On
*/

IF (DN_VALID("C-0036") == 0)
    IF    (GET_LAD_DN("C-0036") == 0 && GET_DN() == 0)
        DERIVE ("V-1003",0);
        DERIVE ("V-1004",0);
    ELSEIF(GET_LAD_DN("C-0036") == 0 && GET_DN() == 1)
        DERIVE ("V-1003",0);
        DERIVE ("V-1004",1);
    ELSEIF(GET_LAD_DN("C-0036") == 1 && GET_DN() == 0)
        DERIVE ("V-1003",1);
        DERIVE ("V-1004",0);
    ELSEIF(GET_LAD_DN("C-0036") == 1 && GET_DN() == 1)
        DERIVE ("V-1003",0);
        DERIVE ("V-1004",0);
    ELSE
        RETURN;
    ENDIF
ELSE
    RETURN;
ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * C-0070 "SSR2BmodeABD" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 1-31-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        C-0071
Description:            SSR 2B MODE Derived from bits from channels C-0069 and C-0070
Mnemonic:               SSR_2B_MODE
Subsystem:              CDH
Data_Type:              STATUS
States:                 INVALID,invalid,invalid,REF_FAST,REF_SLOW,SCRUB_1PD,SCRUB_ASE,PLAYBACK,DIS_SCRUB,LOW_PWR,ENA_SCRUB,IGNR_MAP,CLR_PART,CMD_BIT,SERIAL_TLM,RECORD

*/

CHILD = "C-0071" PARENTS = "C-0069""C-0070";

FUNCT CHAN = "C-0070"

UINT c70, c69, c71;
STATIC UINT c70_old=0, c69_old=0;

IF (DN_VALID("C-0069") == 0)
    c70 = (GET_DN() & 0xD);
    c69 = (GET_LAD_DN("C-0069") & 0x1);
    IF (c70 != c70_old || c69 != c69_old)
        c70_old = c70;
        c69_old = c69;
        c71 = 0;
    ELSE
        c71 = c70 + (c69 * 2);
    ENDIF
ENDIF

DERIVE ("C-0071", c71);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0080 "XSUSIDE1" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load value                       *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2019
Description:            XSU Side 1 Estimated Power
Mnemonic:               XSU_SIDE1_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2019" PARENTS = "C-0080";

FUNCT CHAN = "C-0080"

IF (GET_DN() == 1)             /* Check channel status (1 = On)     */
    DERIVE ("V-2019",  2.00);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2019",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0081 "XSUSIDE2" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2020
Description:            XSU Side 2 Estimated Power
Mnemonic:               XSU_SIDE2_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2020" PARENTS = "C-0081";

FUNCT CHAN = "C-0081"

IF (GET_DN() == 1)             /* Check channel status (1 = On)     */
    DERIVE ("V-2020",  5.60);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2020",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * C-0142 "SSR_1A_I" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2021
Description:            SSR 1A Estimated Power
Mnemonic:               SSR_1A_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2021" PARENTS = "C-0142""C-0043""E-0140";

FUNCT CHAN = "C-0142"

FLT  PSE_28_BUS_V;

/*
Variable Description

PSE_28_BUS_V = PSE +28 Volt Regulated Bus Voltage (E-0140)

*/

/* Extract Trigger Channel PSE +28 Volt Regulated Bus Voltage */

IF (EU_VALID("E-0140") == 0)
    PSE_28_BUS_V = GET_LAD_EU("E-0140");
ELSE
    PSE_28_BUS_V = 28.0;
ENDIF

/* Derive SSR 1A  Estimated Power from SSR current measurement,
   Assume 1.0 volt drop from main bus to load. */
IF (DN_VALID("C-0043") == 0)
    IF (GET_LAD_DN("C-0043") == 0)  /* SSR is on, derive power from current. */
        DERIVE ("V-2021", (GET_EU() * (PSE_28_BUS_V - 1.0) / 1000.0));
    ELSE                            /* SSR is off, set power to zero. */
        DERIVE ("V-2021", 0.00);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0144 "SSR_1B_I" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2022
Description:            SSR 1B Estimated Power
Mnemonic:               SSR_1B_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2022" PARENTS = "C-0144""C-0053""E-0140";

FUNCT CHAN = "C-0144"

FLT  PSE_28_BUS_V;

/*
Variable Description

PSE_28_BUS_V = PSE +28 Volt Regulated Bus Voltage (E-0140)

*/

/* Extract Trigger Channel PSE +28 Volt Regulated Bus Voltage */

IF (EU_VALID("E-0140") == 0)
    PSE_28_BUS_V = GET_LAD_EU("E-0140");
ELSE
    PSE_28_BUS_V = 28.0;
ENDIF

/* Derive SSR 1B  Estimated Power from SSR current measurement,
   Assume 1.0 volt drop from main bus to load. */
IF (DN_VALID("C-0053") == 0)
    IF (GET_LAD_DN("C-0053") == 0)  /* SSR is on, derive power from current. */
        DERIVE ("V-2022", (GET_EU() * (PSE_28_BUS_V - 1.0) / 1000.0));
    ELSE                            /* SSR is off, set power to zero. */
        DERIVE ("V-2022", 0.00);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0146 "SSR_2A_I" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2023
Description:            SSR 2A Estimated Power
Mnemonic:               SSR_2A_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2023" PARENTS = "C-0146""C-0063""E-0140";

FUNCT CHAN = "C-0146"

FLT  PSE_28_BUS_V;

/*
Variable Description

PSE_28_BUS_V = PSE +28 Volt Regulated Bus Voltage (E-0140)

*/

/* Extract Trigger Channel PSE +28 Volt Regulated Bus Voltage */

IF (EU_VALID("E-0140") == 0)
    PSE_28_BUS_V = GET_LAD_EU("E-0140");
ELSE
    PSE_28_BUS_V = 28.0;
ENDIF

/* Derive SSR 2A  Estimated Power from SSR current measurement,
   Assume 1.0 volt drop from main bus to load. */
IF (DN_VALID("C-0063") == 0)
    IF (GET_LAD_DN("C-0063") == 0)  /* SSR is on, derive power from current. */
        DERIVE ("V-2023", (GET_EU() * (PSE_28_BUS_V - 1.0) / 1000.0));
    ELSE                            /* SSR is off, set power to zero. */
        DERIVE ("V-2023", 0.00);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * C-0148 "SSR_2B_I" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2024
Description:            SSR 2B Estimated Power
Mnemonic:               SSR_2B_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2024" PARENTS = "C-0148""C-0073""E-0140";

FUNCT CHAN = "C-0148"

FLT  PSE_28_BUS_V;

/*
Variable Description

PSE_28_BUS_V = PSE +28 Volt Regulated Bus Voltage (E-0140)

*/

/* Extract Trigger Channel PSE +28 Volt Regulated Bus Voltage */

IF (EU_VALID("E-0140") == 0)
    PSE_28_BUS_V = GET_LAD_EU("E-0140");
ELSE
    PSE_28_BUS_V = 28.0;
ENDIF

/* Derive SSR 2B  Estimated Power from SSR current measurement,
   Assume 1.0 volt drop from main bus to load. */
IF (DN_VALID("C-0073") == 0)
    IF (GET_LAD_DN("C-0073") == 0)  /* SSR is on, derive power from current. */
        DERIVE ("V-2024", (GET_EU() * (PSE_28_BUS_V - 1.0) / 1000.0));
    ELSE                            /* SSR is off, set power to zero. */
        DERIVE ("V-2024", 0.00);
    ENDIF
ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * E-0005 "BAT1_TRK_ON" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 8-11-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2028
Description:            Battery 1 Alternate Trickle Charge Estimated Power
Mnemonic:               BAT1_TRK_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2028" PARENTS = "E-0005""E-0004""E-0140";

FUNCT CHAN = "E-0005"

IF (DN_VALID("E-0004") == 0 && EU_VALID("E-0140") == 0)
    IF (GET_DN() == 0 && GET_LAD_DN("E-0004") == 0) /* Check channel status */
        DERIVE ("V-2028",  (0.20 * GET_LAD_EU("E-0140")));  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-2028",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0015 "BAT2_TRK_ON" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 8-11-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2029
Description:            Battery 1 Alternate Trickle Charge Estimated Power
Mnemonic:               BAT2_TRK_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2029" PARENTS = "E-0015""E-0014""E-0140";

FUNCT CHAN = "E-0015"

IF (DN_VALID("E-0014") == 0 && EU_VALID("E-0140") == 0)
    IF (GET_DN() == 0 && GET_LAD_DN("E-0014") == 0) /* Check channel status */
        DERIVE ("V-2029",  (0.20 * GET_LAD_EU("E-0140")));  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-2029",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0103 "BAT1_HALF_V" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 9-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2150
Description:            Battery 1 2nd Half Voltage
Mnemonic:               BAT1_HALF2_V
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  volts

Derived Channel:        V-2152
Description:            Battery 1 Cell Imbalance
Mnemonic:               BAT1_CELLIMB
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  volts

*/

CHILD = "V-2150" PARENTS = "E-0103""E-0101";
CHILD = "V-2152" PARENTS = "E-0103""E-0101";

FUNCT CHAN = "E-0103"

FLT HALF2,IMBAL;

IF (EU_VALID("E-0101") == 0)
   IF ((GET_LAD_DN("E-0101")  > 0) && (GET_LAD_DN("E-0101") < 255) && (GET_DN() > 0) && (GET_DN() < 255))
	HALF2 = GET_LAD_EU("E-0101") - GET_EU();
        IMBAL = ABS(GET_EU() - HALF2);
   ELSE
	HALF2 = 9999.99;
	IMBAL = 9999.99;
   ENDIF
   DERIVE ("V-2150", HALF2);
   DERIVE ("V-2152", IMBAL);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0108 "BAT1_PRESS_1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2201
Description:            Battery 1 Estimated State of Charge Based on Pressure
                        V-2201 Channel uses a Smoothing Filter. This function performs data smoothing
                        for up to 32 samples of the trigger channel. The channel smoothing
                        filter uses the ccl_parameter to define the smoothing sample size. If
                        the ccl_parameter is less than or equal to zero, a default value of 10
                        samples will be used, if greater than 32, a value of 32 will be used.
Mnemonic:               BAT1_P1_SOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "V-2201" PARENTS = "E-0108""T-0200""T-0201";

FUNCT CHAN = "E-0108"

UINT i, samples;
FLT average, summation, soc, temp_ave;
STATIC UINT pointer=0, count=0, old_samples=0;
STATIC FLT datapoints[32];

/* Determine smoothing sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart smoothing function */
IF (samples != old_samples)
    count = 0;
    pointer = 0;
    old_samples = samples;
ENDIF

/* count number of received data points up to samples to average on */
IF (count++ > samples)
    count = samples;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
summation = 0.0;
FOR (i = 0; i <= count-1; i++)
    summation = summation + datapoints[i];
ENDFOR

/* compute average and derive channel  */
average = summation/(FLT)count;

/* compute state of charge using power provided PSI/AH curve */
IF (DN_VALID("T-0200") == 0 && DN_VALID("T-0201") == 0)
    temp_ave = (GET_LAD_EU("T-0200") + GET_LAD_EU("T-0201")) / 2.0;
    soc = (average / (28.413 + (temp_ave * 0.039529) + (temp_ave**2 * 0.0035825))) / 0.2;
    DERIVE ("V-2201", soc);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0109 "BAT1_PRESS_2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2202
Description:            Battery 1 Estimated State of Charge Based on Pressure
                        V-2202 Channel uses a Smoothing Filter. This function performs data smoothing
                        for up to 32 samples of the trigger channel. The channel smoothing
                        filter uses the ccl_parameter to define the smoothing sample size. If
                        the ccl_parameter is less than or equal to zero, a default value of 10
                        samples will be used, if greater than 32, a value of 32 will be used.
Mnemonic:               BAT1_P2_SOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

Derived Channel:        V-2211
Description:            Battery 1 Average State of Charge Based on Pressure (V-2201+V-2202)/2
Mnemonic:               BAT1_AVE_SOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "V-2202" PARENTS = "E-0109""E-0108""V-2201""T-0200""T-0201";
CHILD = "V-2211" PARENTS = "E-0109""E-0108""V-2201""T-0200""T-0201";


FUNCT CHAN = "E-0109"

UINT i, samples;
FLT average, summation, soc, soc_ave, temp_ave;
STATIC UINT pointer=0, count=0, old_samples=0;
STATIC FLT datapoints[32];

/* Determine smoothing sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart smoothing function */
IF (samples != old_samples)
    count = 0;
    pointer = 0;
    old_samples = samples;
ENDIF

/* count number of received data points up to samples to average on */
IF (count++ > samples)
    count = samples;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
summation = 0.0;
FOR (i = 0; i <= count-1; i++)
    summation = summation + datapoints[i];
ENDFOR

/* compute average and derive channel  */
average = summation/(FLT)count;


/* compute state of charge using power provided PSI/AH curve */
IF (DN_VALID("T-0200") == 0 && DN_VALID("T-0201") == 0)
    temp_ave = (GET_LAD_EU("T-0200") + GET_LAD_EU("T-0201")) / 2.0;
    soc = (average / (28.413 + (temp_ave * 0.039529) + (temp_ave**2 * 0.0035825))) / 0.2;
    DERIVE ("V-2202", soc);
    IF (DN_VALID("V-2201") == 0)
         soc_ave = (soc + GET_LAD_DN("V-2201")) / 2.0;
         DERIVE ("V-2211", soc_ave);
    ENDIF
ENDIF


ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0113 "BAT2_HALF_V" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 9-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2151
Description:            Battery 2 2nd Half Voltage
Mnemonic:               BAT2_HALF2_V
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  volts

Derived Channel:        V-2153
Description:            Battery 2 Cell Imbalance
Mnemonic:               BAT2_CELLIMB
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  volts

*/

CHILD = "V-2151" PARENTS = "E-0113""E-0111";
CHILD = "V-2153" PARENTS = "E-0113""E-0111";

FUNCT CHAN = "E-0113"

FLT HALF2,IMBAL;

IF (EU_VALID("E-0111") == 0)
   IF ((GET_LAD_DN("E-0111")  > 0) && (GET_LAD_DN("E-0111") < 255) && (GET_DN() > 0) && (GET_DN() < 255))
	HALF2 = GET_LAD_EU("E-0111") - GET_EU();
        IMBAL = ABS(GET_EU() - HALF2);
   ELSE
	HALF2 = 9999.99;
	IMBAL = 9999.99;
   ENDIF
   DERIVE ("V-2151", HALF2);
   DERIVE ("V-2153", IMBAL);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0115 "BAT2_CHRG_I" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 9-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2170
Description:            Battery Total Charge Current
Mnemonic:               BAT_T_CHRG_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

*/

CHILD = "V-2170" PARENTS = "E-0115""E-0105";

FUNCT CHAN = "E-0115"

IF (EU_VALID("E-0105") == 0)
   DERIVE ("V-2170", (GET_EU() + GET_LAD_EU("E-0105")));
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * E-0116 "BAT2_DCHG_I" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 7-21-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2000
Description:            BVR transfer efficiency
Mnemonic:               BVR_XFER_EFF
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-2171
Description:            Battery Total Discharge Current
Mnemonic:               BAT_T_DCHG_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

*/

CHILD = "V-2000" PARENTS = "E-0101""E-0105""E-0106""E-0111""E-0115""E-0116"
                           "E-0130""E-0140""E-0141";

CHILD = "V-2171" PARENTS = "E-0116""E-0106";

FUNCT CHAN = "E-0116"

FLT BVR_EFF, MB_P, B1_D_P, B2_D_P, B1_C_P, B2_C_P, BT_D_I, BT_C_I ;
FLT MB_I, MB_V, SA_OUT_I ;
FLT B1_D_I, B2_D_I, B1_C_I, B2_C_I, B1_HI_V, B2_HI_V ;

/*
Variable Description

BVR_EFF   = BVR transfer efficiency
MB_V      = Regulated Main Bus Voltage (E-0140)
MB_I      = Regulated Main Bus Current (E-0141)
MB_P      = Regulated Main Bus Power (Watts)
B1_HI_V   = Battery 1 High Voltage (E-0101)
B2_HI_V   = Battery 2 High Voltage (E-0111)
B1_C_I    = Battery 1 Charge Current (E-0105)
B2_C_I    = Battery 2 Charge Current (E-0115)
B1_D_I    = Battery 1 Discharge Current (E-0106)
B2_D_I    = Battery 2 Discharge Current (E-0116)
B1_C_P    = Battery 1 Charge Power (Watts)
B2_C_P    = Battery 2 Charge Power (Watts)
B1_D_P    = Battery 1 Discharge Power (Watts)
B2_D_P    = Battery 2 Discharge Power (Watts)
BT_C_I    = Battery 1 and 2 Total Charge Current (Amps)
BT_D_I    = Battery 1 and 2 Total Discharge Current (Amps)
SA_OUT_I  = Solar Array Output Current (E-0130)

*/

B2_D_I = GET_EU();

IF (EU_VALID("E-0106") == 0)
    B1_D_I = GET_LAD_EU("E-0106");
ELSE
    B1_D_I = 0.0;
ENDIF

IF (EU_VALID("E-0105") == 0)
    B1_C_I = GET_LAD_EU("E-0105");
ELSE
    B1_C_I = 0.0;
ENDIF

IF (EU_VALID("E-0115") == 0)
    B2_C_I = GET_LAD_EU("E-0115");
ELSE
    B2_C_I = 0.0;
ENDIF

IF (EU_VALID("E-0101") == 0)
    B1_HI_V = GET_LAD_EU("E-0101");
ELSE
    B1_HI_V = 0.0;
ENDIF

IF (EU_VALID("E-0111") == 0)
    B2_HI_V = GET_LAD_EU("E-0111");
ELSE
    B2_HI_V = 0.0;
ENDIF

IF (EU_VALID("E-0130") == 0)
    SA_OUT_I = GET_LAD_EU("E-0130");
ELSE
    SA_OUT_I = 1.0;
ENDIF

IF (EU_VALID("E-0140") == 0)
    MB_V = GET_LAD_EU("E-0140");
ELSE
    MB_V = 0.0;
ENDIF

IF (EU_VALID("E-0141") == 0)
    MB_I = GET_LAD_EU("E-0141");
ELSE
    MB_I = 0.0;
ENDIF

/* Compute main bus power */

MB_P = MB_V * MB_I;

/* Compute battery charge and discharge power */

B1_C_P = B1_HI_V * B1_C_I;
B2_C_P = B2_HI_V * B2_C_I;

B1_D_P = B1_HI_V * B1_D_I;
B2_D_P = B2_HI_V * B2_D_I;

/* Compute total battery charge/discharge current */

BT_C_I = B1_C_I + B2_C_I;
BT_D_I = B1_D_I + B2_D_I;

/* Compute BVR efficiency,
   BVR efficiency can only be calculated when batteries are discharging and
   solar array current is zero.  If the BVR efficiency can not be calculated,
   the BVR effiency will be set to 0.0  */

/* Check solar array current, battery discharge power and main bus power,
   if within limits, compute BVR efficiency. */

IF ((SA_OUT_I < 1.0) && (B1_D_P > 30.0) && (B2_D_P > 30.0) && (MB_P > 60.0))

    BVR_EFF = (MB_P / (B1_D_P + B2_D_P)) * 100.0;

ELSE

    BVR_EFF = 0.0;

ENDIF

DERIVE ("V-2000", BVR_EFF);

/* Compute total battery discharge current */

IF (EU_VALID("E-0106") == 0)
   DERIVE ("V-2171", (GET_EU() + GET_LAD_EU("E-0106")));
ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * E-0118 "BAT2_PRESS_1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2203
Description:            Battery 1 Estimated State of Charge Based on Pressure
                        V-2203 Channel uses a Smoothing Filter. This function performs data smoothing
                        for up to 32 samples of the trigger channel. The channel smoothing
                        filter uses the ccl_parameter to define the smoothing sample size. If
                        the ccl_parameter is less than or equal to zero, a default value of 10
                        samples will be used, if greater than 32, a value of 32 will be used.
Mnemonic:               BAT2_P1_SOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "V-2203" PARENTS = "E-0118""T-0202""T-0203";

FUNCT CHAN = "E-0118"

UINT i, samples;
FLT average, summation, soc, temp_ave;
STATIC UINT pointer=0, count=0, old_samples=0;
STATIC FLT datapoints[32];

/* Determine smoothing sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart smoothing function */
IF (samples != old_samples)
    count = 0;
    pointer = 0;
    old_samples = samples;
ENDIF

/* count number of received data points up to samples to average on */
IF (count++ > samples)
    count = samples;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
summation = 0.0;
FOR (i = 0; i <= count-1; i++)
    summation = summation + datapoints[i];
ENDFOR

/* compute average and derive channel  */
average = summation/(FLT)count;

/* compute state of charge using power provided PSI/AH curve */
IF (DN_VALID("T-0202") == 0 && DN_VALID("T-0203") == 0)
    temp_ave = (GET_LAD_EU("T-0202") + GET_LAD_EU("T-0203")) / 2.0;
    soc = (average / (29.546 + (temp_ave * 0.031940) + (temp_ave**2 * 0.0022279))) / 0.2;
    DERIVE ("V-2203", soc);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0119 "BAT2_PRESS_2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2204
Description:            Battery 2 Estimated State of Charge Based on Pressure
                        V-2204 Channel uses a Smoothing Filter. This function performs data smoothing
                        for up to 32 samples of the trigger channel. The channel smoothing
                        filter uses the ccl_parameter to define the smoothing sample size. If
                        the ccl_parameter is less than or equal to zero, a default value of 10
                        samples will be used, if greater than 32, a value of 32 will be used.
Mnemonic:               BAT2_P2_SOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

Derived Channel:        V-2212
Description:            Battery 2 Average State of Charge Based on Pressure (V-2203+V-2204)/2
Mnemonic:               BAT2_AVE_SOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "V-2204" PARENTS = "E-0119""E-0118""V-2203""T-0202""T-0203";
CHILD = "V-2212" PARENTS = "E-0119""E-0118""V-2203""T-0202""T-0203";

FUNCT CHAN = "E-0119"

UINT i, samples;
FLT average, summation, soc, soc_ave, temp_ave;
STATIC UINT pointer=0, count=0, old_samples=0;
STATIC FLT datapoints[32];

/* Determine smoothing sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart smoothing function */
IF (samples != old_samples)
    count = 0;
    pointer = 0;
    old_samples = samples;
ENDIF

/* count number of received data points up to samples to average on */
IF (count++ > samples)
    count = samples;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
summation = 0.0;
FOR (i = 0; i <= count-1; i++)
    summation = summation + datapoints[i];
ENDFOR

/* compute average and derive channel  */
average = summation/(FLT)count;

/* compute state of charge using power provided PSI/AH curve */
IF (DN_VALID("T-0202") == 0 && DN_VALID("T-0203") == 0)
    temp_ave = (GET_LAD_EU("T-0202") + GET_LAD_EU("T-0203")) / 2.0;
    soc = (average / (29.546 + (temp_ave * 0.031940) + (temp_ave**2 * 0.0022279))) / 0.2;
    DERIVE ("V-2204", soc);
    IF (DN_VALID("V-2203") == 0)
         soc_ave = (soc + GET_LAD_DN("V-2203")) / 2.0;
         DERIVE ("V-2212", soc_ave);
    ENDIF
ENDIF


ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0132 "SA-Y_I" TRIGGER CHANNEL CODE                                      *
 *                                                                           *
 * BASELINED:            OGS 9-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2180
Description:            Solar Array Partial Shunt Current
Mnemonic:               SA_PAR_SH_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2190
Description:            Total Solar Array Current
Mnemonic:               TOTAL_SA_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

*/

CHILD = "V-2180" PARENTS = "E-0132""E-0131""E-0130";
CHILD = "V-2190" PARENTS = "E-0132""E-0131";

FUNCT CHAN = "E-0132"

IF ((EU_VALID("E-0131") == 0) && (EU_VALID("E-0130") == 0))
   DERIVE ("V-2180", (GET_EU() + GET_LAD_EU("E-0131") - GET_LAD_EU("E-0130")));
ENDIF

IF (EU_VALID("E-0131") == 0)
   DERIVE ("V-2190", (GET_EU() + GET_LAD_EU("E-0131")));
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * E-0137 "SA_PAR_SH_V" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 9-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2181
Description:            Solar Array Partial Shunt Power
Mnemonic:               SA_PAR_SH_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2181" PARENTS = "E-0137""E-0132""E-0131""E-0130";

FUNCT CHAN = "E-0137"

IF ((EU_VALID("E-0132") == 0) && (EU_VALID("E-0131") == 0) && (EU_VALID("E-0132") == 0))
   DERIVE ("V-2181", GET_EU() * (GET_LAD_EU("E-0132") + GET_LAD_EU("E-0131") - GET_LAD_EU("E-0130")));
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * E-0140 "PSE+28_BUS_V" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 7-24-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2101
Description:            AACS Estimated Current
Mnemonic:               AACS_EST_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2102
Description:            AACS Estimated Power
Mnemonic:               AACS_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2103
Description:            C&DH Estimated Current
Mnemonic:               CDH_EST_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2104
Description:            C&DH Estimated Power
Mnemonic:               CDH_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2105
Description:            Power Estimated Current
Mnemonic:               PWR_EST_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2106
Description:            Power Estimated Power
Mnemonic:               PWR_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2107
Description:            Telecom Estimated Current
Mnemonic:               TLCM_EST_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2108
Description:            Telecom Estimated Power
Mnemonic:               TLCM_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2109
Description:            Propulsion Estimated Current
Mnemonic:               PROP_EST_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2110
Description:            Propulsion Estimated Power
Mnemonic:               PROP_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2111
Description:            Mechanism Estimated Current
Mnemonic:               MECH_EST_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2112
Description:            Mechanism Estimated Power
Mnemonic:               MECH_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2115
Description:            Payload Estimated Current
Mnemonic:               PYLD_EST_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2116
Description:            Payload Estimated Power
Mnemonic:               PYLD_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2117
Description:            Total Bus Hardware Estimated Current
Mnemonic:               BUS_HRDWR_EI
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2118
Description:            Total Bus Hardware Estimated Power
Mnemonic:               BUS_HRDWR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2119
Description:            Total Bus Heater Estimated Current
Mnemonic:               BUS_HTR_EI
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2120
Description:            Total Bus Heater Estimated Power
Mnemonic:               BUS_HTR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2121
Description:            Total Payload Heater Estimated Current
Mnemonic:               PYLD_HTR_EI
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2122
Description:            Total Payload Heater Estimated Power
Mnemonic:               PYLD_HTR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2160
Description:            PSE +28 Bus Power
Mnemonic:               PSE+28_BUS_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2161
Description:            PSE S/C Bus Current
Mnemonic:               PSE_SC_BUS_I
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

Derived Channel:        V-2162
Description:            PSE S/C Bus Power
Mnemonic:               PSE_SC_BUS_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2163
Description:            PSE Payload Power
Mnemonic:               PSE_PL_BUS_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2164
Description:            Solar Array Output Power
Mnemonic:               SA_OUTPUT_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2101" PARENTS = "E-0140""V-2001""V-2002""V-2003""V-2004""V-2005"
                                   "V-2006""V-2007""V-2008""V-2009"
                                   "V-2010""V-2011""V-2012""V-2013";

CHILD = "V-2102" PARENTS = "E-0140""V-2001""V-2002""V-2003""V-2004""V-2005"
                                   "V-2006""V-2007""V-2008""V-2009"
                                   "V-2010""V-2011""V-2012""V-2013";

CHILD = "V-2103" PARENTS = "E-0140""V-2017""V-2018""V-2019""V-2020"
                                   "V-2021""V-2022""V-2023""V-2024"
                                   "V-2025""V-2026";

CHILD = "V-2104" PARENTS = "E-0140""V-2017""V-2018""V-2019""V-2020"
                                   "V-2021""V-2022""V-2023""V-2024"
                                   "V-2025""V-2026";

CHILD = "V-2105" PARENTS = "E-0140""V-2028""V-2029";

CHILD = "V-2106" PARENTS = "E-0140""V-2028""V-2029";

CHILD = "V-2107" PARENTS = "E-0140""V-2030""V-2031""V-2032""V-2033""V-2034"
                                   "V-2035""V-2036";

CHILD = "V-2108" PARENTS = "E-0140""V-2030""V-2031""V-2032""V-2033""V-2034"
                                   "V-2035""V-2036";

CHILD = "V-2109" PARENTS = "E-0140""V-2051""V-2052""V-2053""V-2054""V-2055""V-2056"
                                   "V-2057""V-2058""V-2059""V-2060""V-2061""V-2062";

CHILD = "V-2110" PARENTS = "E-0140""V-2051""V-2052""V-2053""V-2054""V-2055""V-2056"
                                   "V-2057""V-2058""V-2059""V-2060""V-2061""V-2062";

CHILD = "V-2111" PARENTS = "E-0140""V-2070""V-2071""V-2072""V-2073""V-2074""V-2075"
                                   "V-2076""V-2077""V-2078";

CHILD = "V-2112" PARENTS = "E-0140""V-2070""V-2071""V-2072""V-2073""V-2074""V-2075"
                                   "V-2076""V-2077""V-2078";

CHILD = "V-2115" PARENTS = "E-0140""V-2040""V-2041""V-2042""V-2043""V-2044"
                                   "V-2045""V-2046""V-2047""V-2048";

CHILD = "V-2116" PARENTS = "E-0140""V-2040""V-2041""V-2042""V-2043""V-2044"
                                   "V-2045""V-2046""V-2047""V-2048";

CHILD = "V-2117" PARENTS = "E-0140""V-2101""V-2102""V-2103""V-2104""V-2105"
                                   "V-2106""V-2107""V-2108""V-2109""V-2110"
                                   "V-2111""V-2112""V-2115""V-2116";

CHILD = "V-2118" PARENTS = "E-0140""V-2101""V-2102""V-2103""V-2104""V-2105"
                                   "V-2106""V-2107""V-2108""V-2109""V-2110"
                                   "V-2111""V-2112""V-2115""V-2116";

CHILD = "V-2119" PARENTS = "E-0140""E-0141""E-0142""V-2117";

CHILD = "V-2120" PARENTS = "E-0140""E-0141""V-2117";

CHILD = "V-2121" PARENTS = "E-0140""E-0142""V-2115";

CHILD = "V-2122" PARENTS = "E-0140""E-0142""V-2115";

CHILD = "V-2160" PARENTS = "E-0140""E-0141";

CHILD = "V-2161" PARENTS = "E-0140""E-0141""E-0142";

CHILD = "V-2162" PARENTS = "E-0140""E-0141""E-0142";

CHILD = "V-2163" PARENTS = "E-0140""E-0142";

CHILD = "V-2164" PARENTS = "E-0140""E-0130";

FUNCT CHAN = "E-0140"

FLT  AACS_EST_I,AACS_EST_P,PWR_EST_I,PWR_EST_P;
FLT  CDH_EST_I,CDH_EST_P,PYLD_EST_I,PYLD_EST_P;
FLT  TLCM_EST_I,TLCM_EST_P,PROP_EST_I,PROP_EST_P;
FLT  MECH_EST_I,MECH_EST_P,BUS_EST_I,BUS_EST_P;
FLT  BUS_HTR_I,BUS_HTR_P,PYLD_HTR_I,PYLD_HTR_P;
FLT  PSE_28_BUS_V,V_DROP,V_DROP2HGA;

/*
Variable Description

PSE_28_BUS_V = PSE +28 Volt Regulated Bus Voltage (E-0140)
V_DROP       = Voltage Drop Constant from Bus to Load (Volts)
V_DROP2HGA   = Voltage Drop Constant from Bus to Load on HGA Boom (Volts)
AACS_EST_I   = Total AACS Estimated Current (Amps)
AACS_EST_P   = Total AACS Estimated Power (Watts)
CDH_EST_I    = Total C&DH Estimated Current (Amps)
CDH_EST_P    = Total C&DH Estimated Power (Watts)
PWR_EST_I    = Total Power Estimated Current (Amps)
PWR_EST_P    = Total Power Estimated Power (Watts)
TLCM_EST_I   = Total Telecom Estimated Current (Amps)
TLCM_EST_P   = Total Telecom Estimated Power (Watts)
MECH_EST_I   = Total Mechanism Estimated Current (Amps)
MECH_EST_P   = Total Mechanism Estimated Power (Watts)
PROP_EST_I   = Total Propulsion Estimated Current (Amps)
PROP_EST_P   = Total Propulsion Estimated Power (Watts)
PYLD_EST_I   = Total Payload Estimated Current (Amps)
PYLD_EST_P   = Total Payload Estimated Power (Watts)
BUS_EST_I    = Total Bus Hardarwe Estimated Current (Amps)
BUS_EST_P    = Total Bus Hardarwe Estimated Power (Watts)
BUS_HTR_I    = Total Bus Heater Estimated Current (Amps)
BUS_HTR_P    = Total Bus Heater Estimated Power (Watts)
PYLD_HTR_I    = Total Payload Heater Estimated Current (Amps)
PYLD_HTR_P    = Total Payload Heater Estimated Power (Watts)

*/

/* Set Constants */

V_DROP = 1.0;
V_DROP2HGA = 1.0;

/* Extract Trigger Channel PSE +28 Volt Regulated Bus Voltage */

PSE_28_BUS_V = GET_EU();

/* COMPUTE S/C +28 Volt Bus Power */

IF (EU_VALID("E-0141") == 0)
    DERIVE ("V-2160", (GET_LAD_EU("E-0141") * PSE_28_BUS_V));
ENDIF


/* COMPUTE S/C Bus Current and Power */

IF ((EU_VALID("E-0141") == 0) && (EU_VALID("E-0142") == 0))
    DERIVE ("V-2161", (GET_LAD_EU("E-0141") - GET_LAD_EU("E-0142")));
    DERIVE ("V-2162", (GET_LAD_EU("E-0141") - GET_LAD_EU("E-0142")) * PSE_28_BUS_V);
ENDIF

/* COMPUTE Payload Bus Power */

IF (EU_VALID("E-0142") == 0)
    DERIVE ("V-2163", (GET_LAD_EU("E-0142") * PSE_28_BUS_V));
ENDIF

/* COMPUTE Solar Array Output Power */

IF (EU_VALID("E-0130") == 0)
    DERIVE ("V-2164", (GET_LAD_EU("E-0130") * PSE_28_BUS_V));
ENDIF

/*  COMPUTE AACS ESTIMATED LOAD CURRENT & POWER */

/* Initialize AACS_EST_P to 0.0 */
AACS_EST_P = 0.0;

/* Add Always On (AON) power consuming AACS equipment (IMU AC/DC)  */
AACS_EST_P = AACS_EST_P + 23.90;    /* IMU AO Load (watts) */

/* Add CSA Triad A & B Estimated Power to AACS Power Summation */
IF (DN_VALID("V-2001") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2001");
ENDIF
IF (DN_VALID("V-2002") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2002");
ENDIF

/* Add Gyro 1, 2, 3 Estimated Power to AACS Power Summation */
IF (DN_VALID("V-2003") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2003");
ENDIF
IF (DN_VALID("V-2004") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2004");
ENDIF
IF (DN_VALID("V-2005") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2005");
ENDIF

/* Add MHSA 1 and 2 Estimated Power to AACS Power Summation */
IF (DN_VALID("V-2006") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2006");
ENDIF
IF (DN_VALID("V-2007") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2007");
ENDIF

/* Add SSA 1 and 2 Estimated Power to AACS Power Summation */
IF (DN_VALID("V-2008") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2008");
ENDIF
IF (DN_VALID("V-2009") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2009");
ENDIF

/* Add X,Y,Z,S Reaction Wheel Estimated Power to AACS Power Summation */
IF (DN_VALID("V-2010") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2010");
ENDIF
IF (DN_VALID("V-2011") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2011");
ENDIF
IF (DN_VALID("V-2012") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2012");
ENDIF
IF (DN_VALID("V-2013") == 0)
    AACS_EST_P = AACS_EST_P + GET_LAD_DN("V-2013");
ENDIF

/* Compute AACS Estimated Current */
AACS_EST_I = AACS_EST_P / (PSE_28_BUS_V - V_DROP);

/* Derive AACS Estimated Load Power & Current */
DERIVE ("V-2101", AACS_EST_I);
DERIVE ("V-2102", AACS_EST_P);



/*  COMPUTE C&DH ESTIMATED LOAD CURRENT & POWER */

/* Initialize CDH_EST_P to 0.0 */
CDH_EST_P = 0.0;

/* Add Always On (AON) power consuming C&DH equipment (CIU, CIX, RXO)  */
CDH_EST_P = CDH_EST_P + 5.60;    /* CIU AO Load (watts) */
CDH_EST_P = CDH_EST_P + 1.40;    /* CIX AO Load (watts) */
CDH_EST_P = CDH_EST_P + 4.60;    /* RXO AO Load (watts) */
CDH_EST_P = CDH_EST_P + 1.40;    /* SCUs 1&2    (watts) */


/* Add EDF 1 & 2 Estimated Power to C&DH Power Summation */
IF (DN_VALID("V-2015") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2015");
ENDIF
IF (DN_VALID("V-2016") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2016");
ENDIF

/* Add SCP 1 & 2 Estimated Power to C&DH Power Summation */
IF (DN_VALID("V-2017") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2017");
ENDIF
IF (DN_VALID("V-2018") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2018");
ENDIF

/* Add XSU 1 & 2 Estimated Power to C&DH Power Summation */
IF (DN_VALID("V-2019") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2019");
ENDIF
IF (DN_VALID("V-2020") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2020");
ENDIF

/* Add SSR 1A, 1B, 2A, 2B  Estimated Power to C&DH Power Summation */
IF (DN_VALID("V-2021") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2021");
ENDIF
IF (DN_VALID("V-2022") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2022");
ENDIF
IF (DN_VALID("V-2023") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2023");
ENDIF
IF (DN_VALID("V-2024") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2024");
ENDIF

/* Add PDS A & B Estimated Power to C&DH Power Summation */
IF (DN_VALID("V-2025") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2025");
ENDIF
IF (DN_VALID("V-2026") == 0)
    CDH_EST_P = CDH_EST_P + GET_LAD_DN("V-2026");
ENDIF

/* Compute C&DH Estimated Current */
CDH_EST_I = CDH_EST_P / (PSE_28_BUS_V - V_DROP);

/* Derive C&DH Estimated Load Power & Current */
DERIVE ("V-2103", CDH_EST_I);
DERIVE ("V-2104", CDH_EST_P);


/*  COMPUTE PAYLOAD ESTIMATED LOAD CURRENT & POWER */

/* Initialize PYLD_EST_P to 0.0 */
PYLD_EST_P = 0.0;

/* Add Always On (AON) power consuming Payload equipment  */

/* Add MAG A & B Estimated Power to Payload Power Summation */
IF (DN_VALID("V-2040") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2040");
ENDIF
IF (DN_VALID("V-2041") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2041");
ENDIF

/* Add MR Estimated Power to Payload Power Summation */
IF (DN_VALID("V-2042") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2042");
ENDIF

/* Add MOC A & B Estimated Power to Payload Power Summation */
IF (DN_VALID("V-2043") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2043");
ENDIF
IF (DN_VALID("V-2044") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2044");
ENDIF

/* Add MOC Bakeout Heater Estimated Power to Payload Power Summation */
IF (DN_VALID("V-2045") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2045");
ENDIF

/* Add MOLA Estimated Power to Payload Power Summation */
IF (DN_VALID("V-2046") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2046");
ENDIF

/* Add TES Estimated Power to Payload Power Summation */
IF (DN_VALID("V-2047") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2047");
ENDIF

/* Add USO Estimated Power to Payload Power Summation */
IF (DN_VALID("V-2048") == 0)
    PYLD_EST_P = PYLD_EST_P + GET_LAD_DN("V-2048");
ENDIF

/* Compute Payload Estimated Current */
PYLD_EST_I = PYLD_EST_P / (PSE_28_BUS_V - V_DROP);

/* Derive Payload Estimated Load Power & Current */
DERIVE ("V-2115", PYLD_EST_I);
DERIVE ("V-2116", PYLD_EST_P);


/*  COMPUTE POWER ESTIMATED LOAD CURRENT & POWER */

/* Initialize PWR_EST_P to 0.0 */
PWR_EST_P = 0.0;

/* Add Always On (AON) power consuming Power equipment  */
PWR_EST_P = PWR_EST_P + 7.20;    /* PSE (+BCA) Load (watts) */

/* Add BATERY 1 & 2 Estimated Trickle Power to Payload Power Summation */
IF (DN_VALID("V-2028") == 0)
    PWR_EST_P = PWR_EST_P + GET_LAD_DN("V-2028");
ENDIF
IF (DN_VALID("V-2029") == 0)
    PWR_EST_P = PWR_EST_P + GET_LAD_DN("V-2029");
ENDIF

/* Compute Power Estimated Current */
PWR_EST_I = PWR_EST_P / (PSE_28_BUS_V - V_DROP);

/* Derive Power Estimated Load Power & Current */
DERIVE ("V-2105", PWR_EST_I);
DERIVE ("V-2106", PWR_EST_P);



/*  COMPUTE MECHANISM ESTIMATED LOAD CURRENT & POWER */

/* Initialize MECH_EST_P to 0.0 */
MECH_EST_P = 0.0;

/* Add Always On (AON) power consuming Power equipment  */

/* Add HGA Mechanism Loads */
IF (DN_VALID("V-2070") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2070");
ENDIF
IF (DN_VALID("V-2071") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2071");
ENDIF
IF (DN_VALID("V-2072") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2072");
ENDIF

/* Add SAM Mechanism Loads */
IF (DN_VALID("V-2073") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2073");
ENDIF
IF (DN_VALID("V-2074") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2074");
ENDIF
IF (DN_VALID("V-2075") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2075");
ENDIF

/* Add SAP Mechanism Loads */
IF (DN_VALID("V-2076") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2076");
ENDIF
IF (DN_VALID("V-2077") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2077");
ENDIF
IF (DN_VALID("V-2078") == 0)
    MECH_EST_P = MECH_EST_P + GET_LAD_DN("V-2078");
ENDIF

/* Compute Mechanism Estimated Current */
MECH_EST_I = MECH_EST_P / (PSE_28_BUS_V - V_DROP);

/* Derive Power Estimated Load Power & Current */
DERIVE ("V-2111", MECH_EST_I);
DERIVE ("V-2112", MECH_EST_P);


/*  COMPUTE TLCM ESTIMATED LOAD CURRENT & POWER */

/* Initialize TLCM_EST_P to 0.0 */
TLCM_EST_P = 0.0;

/* Add Always On (AON) power consuming TLCM equipment (MOT 1 & 2 Receivers)  */
TLCM_EST_P = TLCM_EST_P + 8.90;    /* MOT1 Receiver Load (watts) */
TLCM_EST_P = TLCM_EST_P + 8.90;    /* MOT2 Receiver Load (watts) */

/* Add MOT 1 & 2 Exciter Estimated Power to TLCM Power Summation */
IF (DN_VALID("V-2030") == 0)
    TLCM_EST_P = TLCM_EST_P + GET_LAD_DN("V-2030");
ENDIF
IF (DN_VALID("V-2031") == 0)
    TLCM_EST_P = TLCM_EST_P + GET_LAD_DN("V-2031");
ENDIF

/* Add TWTA 1 & 2 Filament Estimated Power to TLCM Power Summation */
IF (DN_VALID("V-2032") == 0)
    TLCM_EST_P = TLCM_EST_P + GET_LAD_DN("V-2032");
ENDIF
IF (DN_VALID("V-2034") == 0)
    TLCM_EST_P = TLCM_EST_P + GET_LAD_DN("V-2034");
ENDIF

/* Add TWTA 1 & 2 High Voltage Estimated Power to TLCM Power Summation */
IF (DN_VALID("V-2033") == 0)
    TLCM_EST_P = TLCM_EST_P + GET_LAD_DN("V-2033");
ENDIF
IF (DN_VALID("V-2035") == 0)
    TLCM_EST_P = TLCM_EST_P + GET_LAD_DN("V-2035");
ENDIF

/* Add KaBLE Estimated Power to TLCM Power Summation */
IF (DN_VALID("V-2036") == 0)
    TLCM_EST_P = TLCM_EST_P + GET_LAD_DN("V-2036");
ENDIF

/* Compute Telecom Estimated Current */
TLCM_EST_I = TLCM_EST_P / (PSE_28_BUS_V - V_DROP - V_DROP2HGA);

/* Derive Telecom Estimated Load Power & Current */
DERIVE ("V-2107", TLCM_EST_I);
DERIVE ("V-2108", TLCM_EST_P);



/*  COMPUTE PROP ESTIMATED LOAD CURRENT & POWER */

/* Initialize PROP_EST_P to 0.0 */
PROP_EST_P = 0.0;

/* Add Always On (AON) power consuming PROP equipment */
PROP_EST_P = PROP_EST_P + 1.20;    /* Pressure Transducer Load (watts) */

/* Add Cat-Bed Heater Estimated Power to PROP Power Summation */
IF (DN_VALID("V-2051") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2051");
ENDIF
IF (DN_VALID("V-2052") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2052");
ENDIF
IF (DN_VALID("V-2053") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2053");
ENDIF
IF (DN_VALID("V-2054") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2054");
ENDIF
IF (DN_VALID("V-2055") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2055");
ENDIF
IF (DN_VALID("V-2056") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2056");
ENDIF
IF (DN_VALID("V-2057") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2057");
ENDIF
IF (DN_VALID("V-2058") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2058");
ENDIF
IF (DN_VALID("V-2059") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2059");
ENDIF
IF (DN_VALID("V-2060") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2060");
ENDIF
IF (DN_VALID("V-2061") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2061");
ENDIF
IF (DN_VALID("V-2062") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2062");
ENDIF

/* Add Main Engine Flange Heater Estimated Power to PROP Power Summation */
IF (DN_VALID("V-2063") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2063");
ENDIF
IF (DN_VALID("V-2064") == 0)
    PROP_EST_P = PROP_EST_P + GET_LAD_DN("V-2064");
ENDIF

/* Compute Propulsion Estimated Current */
PROP_EST_I = PROP_EST_P / (PSE_28_BUS_V - V_DROP);

/* Derive Propulsion Estimated Load Power & Current */
DERIVE ("V-2109", PROP_EST_I);
DERIVE ("V-2110", PROP_EST_P);


/* COMPUTE BUS HARDWARE ESTIMATED LOAD CURRENT & POWER */

BUS_EST_P = AACS_EST_P + CDH_EST_P + PWR_EST_P + TLCM_EST_P + MECH_EST_P + PROP_EST_P;
BUS_EST_I = AACS_EST_I + CDH_EST_I + PWR_EST_I + TLCM_EST_I + MECH_EST_I + PROP_EST_I;

/* Derive Total Bus Hardware Estimated Load Power & Current */
DERIVE ("V-2117", BUS_EST_I);
DERIVE ("V-2118", BUS_EST_P);


/* COMPUTE BUS and Payload HEATER ESTIMATED LOAD CURRENT & POWER */

IF (EU_VALID("E-0141") == 0)
     BUS_HTR_I = GET_LAD_EU("E-0141") - GET_LAD_EU("E-0142") - BUS_EST_I;
     BUS_HTR_P = BUS_HTR_I * PSE_28_BUS_V;
ENDIF
IF (EU_VALID("E-0142") == 0)
     PYLD_HTR_I = GET_LAD_EU("E-0142") - PYLD_EST_I;
     PYLD_HTR_P = PYLD_HTR_I * PSE_28_BUS_V;
ENDIF

/* Derive Bus and Payload Estimated Heater Load Power & Current */
DERIVE ("V-2119", BUS_HTR_I);
DERIVE ("V-2120", BUS_HTR_P);
DERIVE ("V-2121", PYLD_HTR_I);
DERIVE ("V-2122", PYLD_HTR_P);


ENDFUNCT





/*****************************************************************************
 *                                                                           *
 * E-0141 "PSE+28_BUS_I" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-11-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2200
Description:            PSE +28 Bus Current Smoothing Filter
                        V-2200 Channel Smoothing Filter. This function performs data smoothing
                        for up to 32 samples of the trigger channel. The channel smoothing
                        filter uses the ccl_parameter to define the smoothing sample size. If
                        the ccl_parameter is less than or equal to zero, a default value of 10
                        samples will be used, if greater than 32, a value of 32 will be used.
Mnemonic:               PSE+28_I_SF
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  amps

*/

CHILD = "V-2200" PARENTS = "E-0141";

FUNCT CHAN = "E-0141"

UINT i, samples;
FLT average, summation;
STATIC UINT pointer=0, count=0, old_samples=0;
STATIC FLT datapoints[32];

/* Determine smoothing sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart smoothing function */
IF (samples != old_samples)
    count = 0;
    pointer = 0;
    old_samples = samples;
ENDIF

/* count number of received data points up to samples to average on */
IF (count++ > samples)
    count = samples;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
summation = 0.0;
FOR (i = 0; i <= count-1; i++)
    summation = summation + datapoints[i];
ENDFOR

/* compute average and derive channel  */
average = summation/(FLT)count;
DERIVE ("V-2200", average);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0000 "AACS_STATE" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 04-05-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0005
Description:            Current Actuator Select
Mnemonic:               CRNT_ACT_SEL
Subsystem:              AACS
Data_Type:              STATUS
States:                 RWA_SELECTED,REA_SELECTED

Derived Channel:        V-0006
Description:            PID Torque Current Units
Mnemonic:               PIDTRQ_UNITS
Subsystem:              AACS
Data_Type:              ASCII
Units:


*/

CHILD = "V-0005" PARENTS = "F-0000";
CHILD = "V-0006" PARENTS = "F-0000";

FUNCT CHAN = "F-0000"


IF (DN_VALID("F-0901") == 0 && DN_VALID("F-0902") == 0)
    IF (GET_DN() > 2 )
        DERIVE ("V-0005",GET_LAD_DN("F-0901"));
        IF (GET_LAD_DN("F-0901") == 0)
             DERIVE ("V-0006","Nm");
        ELSE
             DERIVE ("V-0006","sec");
        ENDIF
    ELSE
        DERIVE ("V-0005",GET_LAD_DN("F-0902"));
        IF (GET_LAD_DN("F-0902") == 0)
             DERIVE ("V-0006","Nm");
        ELSE
             DERIVE ("V-0006","sec");
        ENDIF
    ENDIF
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * F-0040 "CSA_AS_1" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0150
Description:            1st 10hz Reading of S Accel Data
Mnemonic:               S_ACCEL_1
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0151
Description:            1st 10hz Reading of S Accel Data
Mnemonic:               S_ACC_1_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "V-0150" PARENTS = "F-0040""F-0648";
CHILD = "V-0151" PARENTS = "F-0040""F-0648";

FUNCT CHAN = "F-0040"

INT counts;

IF (DN_VALID("F-0648") == 0)
    IF(GET_LAD_DN("F-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("V-0150",(10.0 * 3.334102E-04 * (FLT)counts) + 0.0205029 + 0.0000153);
        DERIVE ("V-0151",counts);
    ELSE
        DERIVE ("V-0150", 0.0);
        DERIVE ("V-0151", 0);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0051 "CSAwdNONZERO" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-4-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0001
Description:            CSA Slit Crossing 6 Bits
Mnemonic:               CSAslit_BITS
Subsystem:              AACS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-0002
Description:            CSA Slit Crossing Time
Mnemonic:               CSAslit_TIME
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mSEC

Derived Channel:        V-0003
Description:            CSA Slit Crossing ID
Mnemonic:               CSAslit_XING
Subsystem:              AACS
Data_Type:              ASCII
Units:

*/

CHILD = "V-0001" PARENTS = "F-0051""F-0210";
CHILD = "V-0002" PARENTS = "F-0051""F-0210";
CHILD = "V-0003" PARENTS = "F-0051""F-0210";

FUNCT CHAN = "F-0051"

UINT csa_wrd_nz,csa_6bits;
FLT  csa_time;

csa_wrd_nz = GET_DN();

IF (DN_VALID("F-0210") == 0)
    /* Check Bit 8 of IMU Status Word (Gyro/Accel Format) If 0  */
    IF (((GET_LAD_DN("F-0210") & 0x0080) >> 7) == 0)
        /* Extract 6 Slit Bits From CSAwrdNONZERO */
        csa_6bits = ((csa_wrd_nz & 0xFC00) >> 10);
        /* Extract 8 Time Bits From CSAwrdNONZERO and convert to mSec */
        csa_time = (csa_wrd_nz & 0x00FF) * 0.625;
    ELSE /* Accel Format Selected */
        csa_6bits = 0;
        csa_time = 0.0;
    ENDIF
ELSE /* IMU Status Word Invalid */
    csa_6bits = 0;
    csa_time = 0.0;
ENDIF

DERIVE ("V-0001",csa_6bits);
DERIVE ("V-0002",csa_time);
IF     (csa_6bits == 31)
    DERIVE("V-0003","SLIT_A2");
ELSEIF (csa_6bits == 47)
    DERIVE("V-0003","SLIT_A1");
ELSEIF (csa_6bits == 55)
    DERIVE("V-0003","SLIT_B3");
ELSEIF (csa_6bits == 59)
    DERIVE("V-0003","SLIT_B2");
ELSEIF (csa_6bits == 61)
    DERIVE("V-0003","SLIT_B1");
ELSEIF (csa_6bits == 62)
    DERIVE("V-0003","SLIT_A3");
ELSE
    DERIVE("V-0003","INVALID");
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * F-0110 "GY_X3_AX_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0101
Description:            Gyro X1/X3 Derived Counts
Mnemonic:               GY_X1_X3_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

*/

CHILD = "V-0101" PARENTS = "F-0110";

FUNCT CHAN = "F-0110"

IF (GET_DN() > 32767)
     DERIVE ("V-0101",GET_DN() - 65536);
ELSE
     DERIVE ("V-0101",GET_DN());
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0120 "GY_X3_AX_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0102
Description:            Gyro X3/AX Derived Counts
Mnemonic:               GY_X3_AX_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0152
Description:            1st 10hz Reading of X Accel Data
Mnemonic:               X_ACCEL_1
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0153
Description:            1st 10hz Reading of X Accel Data
Mnemonic:               X_ACC_1_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "V-0102" PARENTS = "F-0120";
CHILD = "V-0152" PARENTS = "F-0120""F-0648";
CHILD = "V-0153" PARENTS = "F-0120""F-0648";

FUNCT CHAN = "F-0120"

INT counts;

IF (GET_DN() > 32767)
     DERIVE ("V-0102",GET_DN() - 65536);
ELSE
     DERIVE ("V-0102",GET_DN());
ENDIF

IF (DN_VALID("F-0648") == 0)
    IF(GET_LAD_DN("F-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("V-0152",(10.0 * 3.356370E-04 * (FLT)counts) - 0.0170694 - (0.0000778353 * 10.0));
        DERIVE ("V-0153",counts);
    ELSE
        DERIVE ("V-0152", 0.0);
        DERIVE ("V-0153", 0);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0130 "GY_Y1_Y2_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0103
Description:            Gyro Y1/Y2 Derived Counts
Mnemonic:               GY_Y1_Y2_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

*/

CHILD = "V-0103" PARENTS = "F-0130";

FUNCT CHAN = "F-0130"

IF (GET_DN() > 32767)
     DERIVE ("V-0103",GET_DN() - 65536);
ELSE
     DERIVE ("V-0103",GET_DN());
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0140 "GY_Y2_AY_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0104
Description:            Gyro Y2/AY Derived Counts
Mnemonic:               GY_Y2_AY_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0154
Description:            1st 10hz Reading of Y Accel Data
Mnemonic:               Y_ACCEL_1
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0155
Description:            1st 10hz Reading of Y Accel Data
Mnemonic:               Y_ACC_1_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "V-0104" PARENTS = "F-0140";
CHILD = "V-0154" PARENTS = "F-0140""F-0648";
CHILD = "V-0155" PARENTS = "F-0140""F-0648";

FUNCT CHAN = "F-0140"

INT counts;

IF (GET_DN() > 32767)
     DERIVE ("V-0104",GET_DN() - 65536);
ELSE
     DERIVE ("V-0104",GET_DN());
ENDIF

IF (DN_VALID("F-0648") == 0)
    IF(GET_LAD_DN("F-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("V-0154",(10.0 * 3.343948E-04 * (FLT)counts) - 0.0322749 - 0.0000305);
        DERIVE ("V-0155",counts);
    ELSE
        DERIVE ("V-0154", 0.0);
        DERIVE ("V-0155", 0);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0150 "GY_Z2_Z3_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0105
Description:            Gyro Z2/Z3 Derived Counts
Mnemonic:               GY_Z2_Z3_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

*/

CHILD = "V-0105" PARENTS = "F-0150";

FUNCT CHAN = "F-0150"

IF (GET_DN() > 32767)
     DERIVE ("V-0105",GET_DN() - 65536);
ELSE
     DERIVE ("V-0105",GET_DN());
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0160 "GY_Z3_AZ_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0106
Description:            Gyro Z3/AZ Derived Counts
Mnemonic:               GY_Z3_AZ_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0160
Description:            1st 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_1
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0170
Description:            1st 10hz Reading of Z Accel Data
Mnemonic:               Z_ACC_1_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "V-0106" PARENTS = "F-0160";
CHILD = "V-0160" PARENTS = "F-0160""F-0648";
CHILD = "V-0170" PARENTS = "F-0160""F-0648";

FUNCT CHAN = "F-0160"

INT counts;
STATIC INT cycles=0;

/* Note - SCP Frame built in 1st 10hz, for accel
          data to be time synchronized use
          GET_LAD_DN only for the 1st gyro accel value
*/
IF (cycles == 0)
    cycles = 1;
    RETURN;
ENDIF

IF (DN_VALID("F-0160") == 0)
    IF (GET_LAD_DN("F-0160") > 32767)
         counts = GET_LAD_DN("F-0160") - 65536;
    ELSE
         counts = GET_LAD_DN("F-0160");
    ENDIF
ENDIF

DERIVE ("V-0106",counts);

IF (DN_VALID("F-0648") == 0)
    IF(GET_LAD_DN("F-0648") == 1)
        DERIVE ("V-0160",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (0.0000778353 * 10.0));
        DERIVE ("V-0170",counts);
    ELSE
        DERIVE ("V-0160", 0.0);
        DERIVE ("V-0170", 0);
    ENDIF
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * F-0161 "GY_Z3_AZ_2" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0161
Description:            2nd 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_2
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0171
Description:            2nd 10hz Reading of Z Accel Data
Mnemonic:               Z_ACC_2_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "V-0161" PARENTS = "F-0161""F-0648";
CHILD = "V-0171" PARENTS = "F-0161""F-0648";

FUNCT CHAN = "F-0161"

INT counts;

IF (DN_VALID("F-0648") == 0)

    IF(GET_LAD_DN("F-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("V-0161",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (0.0000778353 * 10.0));
        DERIVE ("V-0171",counts);
    ELSE
        DERIVE ("V-0161", 0.0);
        DERIVE ("V-0171", 0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * F-0162 "GY_Z3_AZ_3" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0162
Description:            3rd 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_3
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0172
Description:            3rd 10hz Reading of Z Accel Data
Mnemonic:               Z_ACC_3_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "V-0162" PARENTS = "F-0162""F-0648";
CHILD = "V-0172" PARENTS = "F-0162""F-0648";

FUNCT CHAN = "F-0162"

INT counts;

IF (DN_VALID("F-0648") == 0)

    IF(GET_LAD_DN("F-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("V-0162",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (0.0000778353 * 10.0));
        DERIVE ("V-0172",counts);
    ELSE
        DERIVE ("V-0162", 0.0);
        DERIVE ("V-0172", 0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * F-0163 "GY_Z3_AZ_4" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0163
Description:            4th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_4
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0173
Description:            4th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACC_4_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "V-0163" PARENTS = "F-0163""F-0648";
CHILD = "V-0173" PARENTS = "F-0163""F-0648";

FUNCT CHAN = "F-0163"

INT counts;

IF (DN_VALID("F-0648") == 0)

    IF(GET_LAD_DN("F-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("V-0163",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (0.0000778353 * 10.0));
        DERIVE ("V-0173",counts);
    ELSE
        DERIVE ("V-0163", 0.0);
        DERIVE ("V-0173", 0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * F-0164 "GY_Z3_AZ_5" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0164
Description:            5th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_5
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0174
Description:            5th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACC_5_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "V-0164" PARENTS = "F-0164""F-0648";
CHILD = "V-0174" PARENTS = "F-0164""F-0648";

FUNCT CHAN = "F-0164"

INT counts;

IF (DN_VALID("F-0648") == 0)

    IF(GET_LAD_DN("F-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("V-0164",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (0.0000778353 * 10.0));
        DERIVE ("V-0174",counts);
    ELSE
        DERIVE ("V-0164", 0.0);
        DERIVE ("V-0174", 0);
    ENDIF

ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0190 "HGA_AZ_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0080
Description:            HGA AZIMUTH FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               HGA_AZang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0080" PARENTS = "F-0190";

FUNCT CHAN = "F-0190"

/* Derive flight software computed control frame position in degrees */
DERIVE ("V-0080",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0192 "HGA_AZ_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0070
Description:            HGA AZIMUTH POSITION (CONTROL FRAME)
Mnemonic:               HGA_AZpos_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0070" PARENTS = "F-0192";

FUNCT CHAN = "F-0192"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * -0.02197266) + 180.0;
IF (cf_pos < -100.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 260.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("V-0070", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0195 "HGA_EL_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0081
Description:            HGA ELEVATION FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               HGA_ELang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0081" PARENTS = "F-0195";

FUNCT CHAN = "F-0195"

/* Derive flight software computed control frame position in degrees */
DERIVE ("V-0081",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0197 "HGA_EL_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0071
Description:            HGA ELEVATION POSITION (CONTROL FRAME)
Mnemonic:               HGA_ELpos_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0071" PARENTS = "F-0197";

FUNCT CHAN = "F-0197"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * -0.02197266) - 95.0;
IF (cf_pos < -180.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 180.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("V-0071", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0200 "HGA_STATS" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-21-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2070
Description:            HGA GDE Estimated Power
Mnemonic:               HGA_GDE_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2071
Description:            HGA Motors Estimated Power
Mnemonic:               HGA_MTR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2072
Description:            HGA Encoder Estimated Power
Mnemonic:               HGA_ENC_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2070" PARENTS = "F-0200""F-0201""F-0192""F-0197""F-0621""F-0623""F-0629""F-0631";
CHILD = "V-2071" PARENTS = "F-0200""F-0201""F-0192""F-0197""F-0621""F-0623""F-0629""F-0631";
CHILD = "V-2072" PARENTS = "F-0200""F-0201""F-0192""F-0197""F-0621""F-0623""F-0629""F-0631";

FUNCT CHAN = "F-0200"

FLT HGA_GDE_PWR, HGA_MTR_PWR, HGA_ENC_PWR;

/* Check GDE telemetry validity */
IF ((DN_VALID("F-0631") != 0) || (DN_VALID("F-0192") != 0) || (DN_VALID("F-0197") != 0) || (DN_VALID("F-0201") != 0))
	RETURN;
ENDIF

/* Check Power Status of GDE */
IF (GET_LAD_DN("F-0201") == 1)
	/* GDE is powered off */
	HGA_GDE_PWR = 0.00;
	HGA_MTR_PWR = 0.00;
	HGA_ENC_PWR = 0.00;
ELSE
	/* GDE is powered on, baseline power at zero rate */
	HGA_GDE_PWR = 0.30;
	HGA_MTR_PWR = 0.00;
	HGA_ENC_PWR = 1.20;
	/* Check status of azimuth motor */
	IF (GET_LAD_DN("F-0623") == 0) /* Stop command in effect, no-powered hold */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.00;
		HGA_MTR_PWR = HGA_MTR_PWR + 0.00;
	ELSEIF ((GET_LAD_DN("F-0623") == 1) && (GET_LAD_DN("F-0621") == 1)) /* Rate mode in effect, and moving */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.62;
		HGA_MTR_PWR = HGA_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("F-0623") == 2) && (GET_LAD_DN("F-0621") == 1)) /* Step mode in effect, and moving */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.62;
		HGA_MTR_PWR = HGA_MTR_PWR + 2.70;
	ENDIF
	/* Check status of elevation motor */
	IF (GET_LAD_DN("F-0631") == 0) /* Stop command in effect, no-powered hold */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.00;
		HGA_MTR_PWR = HGA_MTR_PWR + 0.00;
	ELSEIF ((GET_LAD_DN("F-0631") == 1) && (GET_LAD_DN("F-0629") == 1)) /* Rate mode in effect, and moving */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.62;
		HGA_MTR_PWR = HGA_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("F-0631") == 2) && (GET_LAD_DN("F-0629") == 1)) /* Step mode in effect, and moving */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.62;
		HGA_MTR_PWR = HGA_MTR_PWR + 2.70;
	ENDIF
ENDIF

DERIVE ("V-2070", HGA_GDE_PWR);
DERIVE ("V-2071", HGA_MTR_PWR);
DERIVE ("V-2072", HGA_ENC_PWR);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0241 "MHSA_DETA_Q1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0010
Description:            MHSA Detector A Quadrant 1 Detector Voltage Counts
Mnemonic:               MHSA_A1_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0011
Description:            MHSA Detector A Quadrant 1 Detector Over-Range Flag
Mnemonic:               MHSA_A1_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0010" PARENTS = "F-0241";
CHILD = "V-0011" PARENTS = "F-0241";

FUNCT CHAN = "F-0241"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF

/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0010",volt_counts);
DERIVE ("V-0011",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0242 "MHSA_DETA_Q2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0012
Description:            MHSA Detector A Quadrant 2 Detector Voltage Counts
Mnemonic:               MHSA_A2_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0013
Description:            MHSA Detector A Quadrant 2 Detector Over-Range Flag
Mnemonic:               MHSA_A2_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0012" PARENTS = "F-0242";
CHILD = "V-0013" PARENTS = "F-0242";

FUNCT CHAN = "F-0242"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0012",volt_counts);
DERIVE ("V-0013",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0243 "MHSA_DETA_Q3" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0014
Description:            MHSA Detector A Quadrant 3 Detector Voltage Counts
Mnemonic:               MHSA_A3_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0015
Description:            MHSA Detector A Quadrant 3 Detector Over-Range Flag
Mnemonic:               MHSA_A3_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0014" PARENTS = "F-0243";
CHILD = "V-0015" PARENTS = "F-0243";

FUNCT CHAN = "F-0243"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0014",volt_counts);
DERIVE ("V-0015",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0244 "MHSA_DETA_Q4" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0016
Description:            MHSA Detector A Quadrant 4 Detector Voltage Counts
Mnemonic:               MHSA_A4_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0017
Description:            MHSA Detector A Quadrant 4 Detector Over-Range Flag
Mnemonic:               MHSA_A4_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0016" PARENTS = "F-0244";
CHILD = "V-0017" PARENTS = "F-0244";

FUNCT CHAN = "F-0244"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0016",volt_counts);
DERIVE ("V-0017",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0245 "MHSA_DETB_Q1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0018
Description:            MHSA Detector B Quadrant 1 Detector Voltage Counts
Mnemonic:               MHSA_B1_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0019
Description:            MHSA Detector B Quadrant 1 Detector Over-Range Flag
Mnemonic:               MHSA_B1_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0018" PARENTS = "F-0245";
CHILD = "V-0019" PARENTS = "F-0245";

FUNCT CHAN = "F-0245"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0018",volt_counts);
DERIVE ("V-0019",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0246 "MHSA_DETB_Q2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0020
Description:            MHSA Detector B Quadrant 2 Detector Voltage Counts
Mnemonic:               MHSA_B2_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0021
Description:            MHSA Detector B Quadrant 2 Detector Over-Range Flag
Mnemonic:               MHSA_B2_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0020" PARENTS = "F-0246";
CHILD = "V-0021" PARENTS = "F-0246";

FUNCT CHAN = "F-0246"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0020",volt_counts);
DERIVE ("V-0021",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0247 "MHSA_DETB_Q3" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0022
Description:            MHSA Detector B Quadrant 3 Detector Voltage Counts
Mnemonic:               MHSA_B3_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0023
Description:            MHSA Detector B Quadrant 3 Detector Over-Range Flag
Mnemonic:               MHSA_B3_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0022" PARENTS = "F-0247";
CHILD = "V-0023" PARENTS = "F-0247";

FUNCT CHAN = "F-0247"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0022",volt_counts);
DERIVE ("V-0023",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0248 "MHSA_DETB_Q4" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0024
Description:            MHSA Detector B Quadrant 4 Detector Voltage Counts
Mnemonic:               MHSA_B4_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0025
Description:            MHSA Detector B Quadrant 4 Detector Over-Range Flag
Mnemonic:               MHSA_B4_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0024" PARENTS = "F-0248";
CHILD = "V-0025" PARENTS = "F-0248";

FUNCT CHAN = "F-0248"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0024",volt_counts);
DERIVE ("V-0025",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0251 "MHSA_DETS_Q1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0026
Description:            MHSA Detector S Quadrant 1 Detector Voltage Counts
Mnemonic:               MHSA_S1_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0027
Description:            MHSA Detector S Quadrant 1 Detector Over-Range Flag
Mnemonic:               MHSA_S1_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0026" PARENTS = "F-0251";
CHILD = "V-0027" PARENTS = "F-0251";

FUNCT CHAN = "F-0251"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0026",volt_counts);
DERIVE ("V-0027",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0252 "MHSA_DETS_Q2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0028
Description:            MHSA Detector S Quadrant 2 Detector Voltage Counts
Mnemonic:               MHSA_S2_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0029
Description:            MHSA Detector S Quadrant 2 Detector Over-Range Flag
Mnemonic:               MHSA_S2_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0028" PARENTS = "F-0252";
CHILD = "V-0029" PARENTS = "F-0252";

FUNCT CHAN = "F-0252"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0028",volt_counts);
DERIVE ("V-0029",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0253 "MHSA_DETS_Q3" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0030
Description:            MHSA Detector S Quadrant 3 Detector Voltage Counts
Mnemonic:               MHSA_S3_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0031
Description:            MHSA Detector S Quadrant 3 Detector Over-Range Flag
Mnemonic:               MHSA_S3_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0030" PARENTS = "F-0253";
CHILD = "V-0031" PARENTS = "F-0253";

FUNCT CHAN = "F-0253"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0030",volt_counts);
DERIVE ("V-0031",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0254 "MHSA_DETS_Q4" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0032
Description:            MHSA Detector S Quadrant 4 Detector Voltage Counts
Mnemonic:               MHSA_S4_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0033
Description:            MHSA Detector S Quadrant 4 Detector Over-Range Flag
Mnemonic:               MHSA_S4_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "V-0032" PARENTS = "F-0254";
CHILD = "V-0033" PARENTS = "F-0254";

FUNCT CHAN = "F-0254"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("V-0032",volt_counts);
DERIVE ("V-0033",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0277 "MOM_UNL_STAT" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 04-15-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0091
Description:            Emergency Unload State
Mnemonic:               MOM_UN_EMERG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,WARMUP,FIRE,END

Derived Channel:        V-0092
Description:            Spin Unload State
Mnemonic:               MOM_UN_SPIN
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,WARMUP,FIRE,END

Derived Channel:        V-0093
Description:            Yaw Unload State
Mnemonic:               MOM_UN_YAW
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,WARMUP,FIRE,END

Derived Channel:        V-0094
Description:            Off Axis Unload State
Mnemonic:               MOM_UN_OFFAX
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,WARMUP,FIRE,END

*/

CHILD = "V-0091" PARENTS = "F-0277";
CHILD = "V-0092" PARENTS = "F-0277";
CHILD = "V-0093" PARENTS = "F-0277";
CHILD = "V-0094" PARENTS = "F-0277";

FUNCT CHAN = "F-0277"

UINT mom_word,mom_axis,mom_state,mom_seq;

mom_word = GET_DN();

/* extract mom axis */
mom_axis = ((mom_word & 0x0F00) >> 8);

/* extract mom state */
mom_state = ((mom_word & 0x00F0) >> 4);

/* extract mom seq */
mom_seq = ((mom_word & 0x000F) >> 0);

IF (mom_axis == 1)
    IF(mom_state == 0)
         DERIVE ("V-0091",0);
    ELSEIF(mom_state == 1)
         DERIVE ("V-0091",1);
    ELSEIF(mom_state == 2)
         DERIVE ("V-0091",2);
    ELSE
         DERIVE ("V-0091",0);
    ENDIF
    DERIVE ("V-0092",0);
    DERIVE ("V-0093",0);
    DERIVE ("V-0094",0);
ELSEIF (mom_axis == 2)
    IF(mom_state == 0)
         DERIVE ("V-0092",0);
    ELSEIF(mom_state == 1)
         DERIVE ("V-0092",1);
    ELSEIF(mom_state == 2)
         DERIVE ("V-0092",2);
    ELSE
         DERIVE ("V-0092",0);
    ENDIF
    DERIVE ("V-0091",0);
    DERIVE ("V-0093",0);
    DERIVE ("V-0094",0);
ELSEIF (mom_axis == 3)
    IF(mom_state == 0)
         DERIVE ("V-0093",0);
    ELSEIF(mom_state == 1)
         DERIVE ("V-0093",1);
    ELSEIF(mom_state == 2)
         DERIVE ("V-0093",2);
    ELSE
         DERIVE ("V-0093",0);
    ENDIF
    DERIVE ("V-0091",0);
    DERIVE ("V-0092",0);
    DERIVE ("V-0094",0);
ELSEIF (mom_axis == 4)
    IF(mom_state == 0)
         DERIVE ("V-0094",0);
    ELSEIF(mom_state == 1)
         DERIVE ("V-0094",1);
    ELSEIF(mom_state == 2)
         DERIVE ("V-0094",2);
    ELSE
         DERIVE ("V-0094",0);
    ENDIF
    DERIVE ("V-0091",0);
    DERIVE ("V-0092",0);
    DERIVE ("V-0093",0);
ELSE
    DERIVE ("V-0091",0);
    DERIVE ("V-0092",0);
    DERIVE ("V-0093",0);
    DERIVE ("V-0094",0);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0290 "POS_ERR_X" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-9-97                                          *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0290
Description:            Position Error X in Degrees
Mnemonic:               POS_ERR_Xdeg
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

Derived Channel:        V-0300
Description:            MIN DRAG PASS Position Error X in Degrees
Mnemonic:               MINposERR_X
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

Derived Channel:        V-0301
Description:            MAX DRAG PASS Position Error X in Degrees
Mnemonic:               MAXposERR_X
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

*/

CHILD = "V-0290" PARENTS = "F-0290";
CHILD = "V-0300" PARENTS = "F-0290""F-0000";
CHILD = "V-0301" PARENTS = "F-0290""F-0000";

FUNCT CHAN = "F-0290"

FLT pos_err;
STATIC FLT max_err=0.0,min_err=0.0;

pos_err = GET_EU() * 57.29577951;
DERIVE ("V-0290",pos_err);

IF (DN_VALID("V-0300") != 0)
    min_err = 0.0;
    max_err = 0.0;
    DERIVE ("V-0300",min_err);
    DERIVE ("V-0301",max_err);
ELSEIF (DN_VALID("F-0000") == 0)
    IF (GET_LAD_DN("F-0000") == 7 && pos_err > max_err)
        max_err = pos_err;
        DERIVE ("V-0301",max_err);
    ENDIF
    IF (GET_LAD_DN("F-0000") == 7 && pos_err < min_err)
        min_err = pos_err;
        DERIVE ("V-0300",min_err);
    ENDIF
ENDIF


ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0291 "POS_ERR_Y" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-9-97                                          *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0291
Description:            Position Error Y in Degrees
Mnemonic:               POS_ERR_Ydeg
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

Derived Channel:        V-0302
Description:            MIN DRAG PASS Position Error Y in Degrees
Mnemonic:               MINposERR_Y
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

Derived Channel:        V-0303
Description:            MAX DRAG PASS Position Error Y in Degrees
Mnemonic:               MAXposERR_Y
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

*/

CHILD = "V-0291" PARENTS = "F-0291";
CHILD = "V-0302" PARENTS = "F-0291""F-0000";
CHILD = "V-0303" PARENTS = "F-0291""F-0000";

FUNCT CHAN = "F-0291"

FLT pos_err;
STATIC FLT max_err=0.0,min_err=0.0;

pos_err = GET_EU() * 57.29577951;
DERIVE ("V-0291",pos_err);

IF (DN_VALID("V-0302") != 0)
    min_err = 0.0;
    max_err = 0.0;
    DERIVE ("V-0302",min_err);
    DERIVE ("V-0303",max_err);
ELSEIF (DN_VALID("F-0000") == 0)
    IF (GET_LAD_DN("F-0000") == 7 && pos_err > max_err)
        max_err = pos_err;
        DERIVE ("V-0303",max_err);
    ENDIF
    IF (GET_LAD_DN("F-0000") == 7 && pos_err < min_err)
        min_err = pos_err;
        DERIVE ("V-0302",min_err);
    ENDIF
ENDIF


ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0292 "POS_ERR_Z" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-9-97                                          *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0292
Description:            Position Error Z in Degrees
Mnemonic:               POS_ERR_Zdeg
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

Derived Channel:        V-0304
Description:            MIN DRAG PASS Position Error Z in Degrees
Mnemonic:               MINposERR_Z
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

Derived Channel:        V-0305
Description:            MAX DRAG PASS Position Error Z in Degrees
Mnemonic:               MAXposERR_Z
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

*/

CHILD = "V-0292" PARENTS = "F-0292";
CHILD = "V-0304" PARENTS = "F-0292""F-0000";
CHILD = "V-0305" PARENTS = "F-0292""F-0000";

FUNCT CHAN = "F-0292"

FLT pos_err;
STATIC FLT max_err=0.0,min_err=0.0;

pos_err = GET_EU() * 57.29577951;
DERIVE ("V-0292",pos_err);

IF (DN_VALID("V-0304") != 0)
    min_err = 0.0;
    max_err = 0.0;
    DERIVE ("V-0304",min_err);
    DERIVE ("V-0305",max_err);
ELSEIF (DN_VALID("F-0000") == 0)
    IF (GET_LAD_DN("F-0000") == 7 && pos_err > max_err)
        max_err = pos_err;
        DERIVE ("V-0305",max_err);
    ENDIF
    IF (GET_LAD_DN("F-0000") == 7 && pos_err < min_err)
        min_err = pos_err;
        DERIVE ("V-0304",min_err);
    ENDIF
ENDIF


ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0318 "QUAT_F_I2B_4" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 12-19-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0076
Description:            CSA Right Ascension Angle
Mnemonic:               CSA_RA_ANG
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0077
Description:            CSA Declination Angle
Mnemonic:               CSA_DEC_ANG
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0078
Description:            CSA Right Ascension Angle (Hours Minutes)
Mnemonic:               CSA_RA_HHMM
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  hhmm.f

Derived Channel:        V-0079
Description:            CSA Declination Angle (Degrees Minutes)
Mnemonic:               CSA_DEC_DDMM
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  ddmm

*/

CHILD = "V-0076" PARENTS = "F-0315""F-0316""F-0317""F-0318";
CHILD = "V-0077" PARENTS = "F-0315""F-0316""F-0317""F-0318";
CHILD = "V-0078" PARENTS = "F-0315""F-0316""F-0317""F-0318";
CHILD = "V-0079" PARENTS = "F-0315""F-0316""F-0317""F-0318";

FUNCT CHAN = "F-0318"

UINT i;
INT RA_HR,DEC_DEG,DEC_MIN;
FLT Q[5],V1[4],V2[4];
FLT MAG,RA_ANG,DEC_ANG,RA_MIN;

V1[0] = 0.0;
V1[1] = -.8002339;
V1[2] = -.5743962;
V1[3] = -.1723217;

Q[0] = 0.0;
Q[1] = GET_LAD_EU("F-0315");
Q[2] = GET_LAD_EU("F-0316");
Q[3] = GET_LAD_EU("F-0317");
Q[4] = GET_EU() * -1.0;

MAG = SQRT(Q[1]*Q[1] + Q[2]*Q[2] + Q[3]*Q[3] + Q[4]*Q[4]);

FOR (i=1; i<=4; i++)
    Q[i] = Q[i]/MAG;
ENDFOR

MAG = SQRT(V1[1]*V1[1] + V1[2]*V1[2] + V1[3]*V1[3]);

FOR (i=1; i<=3; i++)
    V1[i] = V1[i]/MAG;
ENDFOR

V2[1] = (Q[1]*Q[1]-Q[2]*Q[2]-Q[3]*Q[3]+Q[4]*Q[4])*V1[1] + 2.0*(Q[1]*Q[2]+Q[3]*Q[4])*V1[2] + 2.0*(Q[1]*Q[3]-Q[2]*Q[4])*V1[3];
V2[2] = (-Q[1]*Q[1]+Q[2]*Q[2]-Q[3]*Q[3]+Q[4]*Q[4])*V1[2] + 2.0*(Q[1]*Q[2]-Q[3]*Q[4])*V1[1] + 2.0*(Q[2]*Q[3]+Q[1]*Q[4])*V1[3];
V2[3] = (-Q[1]*Q[1]-Q[2]*Q[2]+Q[3]*Q[3]+Q[4]*Q[4])*V1[3] + 2.0*(Q[1]*Q[3]+Q[2]*Q[4])*V1[1] + 2.0*(Q[2]*Q[3]-Q[1]*Q[4])*V1[2];

RA_ANG = ATAN2(V2[2],V2[1]) * 180.0 / PI;
DEC_ANG = ASIN(V2[3])* 180.0 / PI;

IF (RA_ANG < 0.0)
    RA_ANG = RA_ANG + 360.0;
ENDIF

DERIVE ("V-0076",RA_ANG);
DERIVE ("V-0077",DEC_ANG);

RA_HR = RA_ANG / 15;
RA_MIN = (RA_ANG - RA_HR*15) * 60.0 / 15.0;

DEC_DEG = DEC_ANG;
DEC_MIN = (DEC_ANG - DEC_DEG) * 60;

DERIVE ("V-0078",(RA_HR * 100) + RA_MIN);
DERIVE ("V-0079",(DEC_DEG * 100) + DEC_MIN);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0335 "RTE_FLTBDY_Z" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 6-18-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0111
Description:            X Rate Error Rad/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_X
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  r/s

Derived Channel:        V-0112
Description:            Y Rate Error Rad/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_Y
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  r/s

Derived Channel:        V-0113
Description:            Z Rate Error Rad/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_Z
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  r/s

Derived Channel:        V-0114
Description:            X Rate Error Deg/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_X
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg/s

Derived Channel:        V-0115
Description:            Y Rate Error Deg/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_Y
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg/s

Derived Channel:        V-0116
Description:            Z Rate Error Deg/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_Z
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg/s

*/

CHILD = "V-0111" PARENTS = "F-0330""F-0331""F-0332""F-0333""F-0334""F-0335";
CHILD = "V-0112" PARENTS = "F-0330""F-0331""F-0332""F-0333""F-0334""F-0335";
CHILD = "V-0113" PARENTS = "F-0330""F-0331""F-0332""F-0333""F-0334""F-0335";
CHILD = "V-0114" PARENTS = "F-0330""F-0331""F-0332""F-0333""F-0334""F-0335";
CHILD = "V-0115" PARENTS = "F-0330""F-0331""F-0332""F-0333""F-0334""F-0335";
CHILD = "V-0116" PARENTS = "F-0330""F-0331""F-0332""F-0333""F-0334""F-0335";

FUNCT CHAN = "F-0335"

/* Check telemetry validity */
IF (DN_VALID("F-0330") != 0)
        RETURN;
ENDIF

DERIVE ("V-0111",(GET_LAD_EU("F-0333") - GET_LAD_EU("F-0330")));
DERIVE ("V-0112",(GET_LAD_EU("F-0334") - GET_LAD_EU("F-0331")));
DERIVE ("V-0113",(GET_LAD_EU("F-0335") - GET_LAD_EU("F-0332")));

DERIVE ("V-0114",(GET_LAD_EU("F-0333") - GET_LAD_EU("F-0330")) * 57.29577951);
DERIVE ("V-0115",(GET_LAD_EU("F-0334") - GET_LAD_EU("F-0331")) * 57.29577951);
DERIVE ("V-0116",(GET_LAD_EU("F-0335") - GET_LAD_EU("F-0332")) * 57.29577951);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0345 "RWA_RAW_X" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 10-6-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0040
Description:            RWA X Derived Wheel Speed
Mnemonic:               RWA_X_D_SPD
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0041
Description:            RWA X Power On Condition
Mnemonic:               RWA_X_POWER
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        V-0042
Description:            RWA X Power Limited Condition
Mnemonic:               RWA_X_P_LMTD
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,PWR_LIMITED


*/

CHILD = "V-0040" PARENTS = "F-0345";
CHILD = "V-0041" PARENTS = "F-0345";
CHILD = "V-0042" PARENTS = "F-0345";

FUNCT CHAN = "F-0345"

UINT sign_bit,power_bit,limit_bit,rwa_raw_data;
INT  rwa_speed;

rwa_raw_data = GET_DN();

/* extract sign bit */
sign_bit = ((rwa_raw_data & 0x8000) >> 15);

/* extract power on bit */
power_bit = ((rwa_raw_data & 0x1000) >> 12);

/* extract power limit bit */
limit_bit = ((rwa_raw_data & 0x0800) >> 11);

/* extract 11 speed bits bit */
rwa_speed = (rwa_raw_data & 0x07FF) ;

/* Convert to RPM */
rwa_speed = rwa_speed * 5;

/* compute signed rwa speed */
IF (sign_bit == 1)
    rwa_speed = -1 * rwa_speed;
ENDIF

/* derive channels */
DERIVE ("V-0040",rwa_speed);
DERIVE ("V-0041",power_bit);
DERIVE ("V-0042",limit_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0346 "RWA_RAW_Y" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 10-6-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0044
Description:            RWA Y Derived Wheel Speed
Mnemonic:               RWA_Y_D_SPD
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0045
Description:            RWA Y Power On Condition
Mnemonic:               RWA_Y_POWER
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        V-0046
Description:            RWA Y Power Limited Condition
Mnemonic:               RWA_Y_P_LMTD
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,PWR_LIMITED


*/

CHILD = "V-0044" PARENTS = "F-0346";
CHILD = "V-0045" PARENTS = "F-0346";
CHILD = "V-0046" PARENTS = "F-0346";

FUNCT CHAN = "F-0346"

UINT sign_bit,power_bit,limit_bit,rwa_raw_data;
INT  rwa_speed;

rwa_raw_data = GET_DN();

/* extract sign bit */
sign_bit = ((rwa_raw_data & 0x8000) >> 15);

/* extract power on bit */
power_bit = ((rwa_raw_data & 0x1000) >> 12);

/* extract power limit bit */
limit_bit = ((rwa_raw_data & 0x0800) >> 11);

/* extract 11 speed bits bit */
rwa_speed = (rwa_raw_data & 0x07FF);

/* Convert to RPM */
rwa_speed = rwa_speed * 5;

/* compute signed rwa speed */
IF (sign_bit == 1)
    rwa_speed = -1 * rwa_speed;
ENDIF

/* derive channels */
DERIVE ("V-0044",rwa_speed);
DERIVE ("V-0045",power_bit);
DERIVE ("V-0046",limit_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0347 "RWA_RAW_Z" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 10-6-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0048
Description:            RWA Z Derived Wheel Speed
Mnemonic:               RWA_Z_D_SPD
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0049
Description:            RWA Z Power On Condition
Mnemonic:               RWA_Z_POWER
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        V-0050
Description:            RWA Z Power Limited Condition
Mnemonic:               RWA_Z_P_LMTD
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,PWR_LIMITED


*/

CHILD = "V-0048" PARENTS = "F-0347";
CHILD = "V-0049" PARENTS = "F-0347";
CHILD = "V-0050" PARENTS = "F-0347";

FUNCT CHAN = "F-0347"

UINT sign_bit,power_bit,limit_bit,rwa_raw_data;
INT  rwa_speed;

rwa_raw_data = GET_DN();

/* extract sign bit */
sign_bit = ((rwa_raw_data & 0x8000) >> 15);

/* extract power on bit */
power_bit = ((rwa_raw_data & 0x1000) >> 12);

/* extract power limit bit */
limit_bit = ((rwa_raw_data & 0x0800) >> 11);

/* extract 11 speed bits bit */
rwa_speed = (rwa_raw_data & 0x07FF);

/* Convert to RPM */
rwa_speed = rwa_speed * 5;

/* compute signed rwa speed */
IF (sign_bit == 1)
    rwa_speed = -1 * rwa_speed;
ENDIF

/* derive channels */
DERIVE ("V-0048",rwa_speed);
DERIVE ("V-0049",power_bit);
DERIVE ("V-0050",limit_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0348 "RWA_RAW_S" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 10-6-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0052
Description:            RWA S Derived Wheel Speed
Mnemonic:               RWA_S_D_SPD
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        V-0053
Description:            RWA S Power On Condition
Mnemonic:               RWA_S_POWER
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        V-0054
Description:            RWA S Power Limited Condition
Mnemonic:               RWA_S_P_LMTD
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,PWR_LIMITED


*/

CHILD = "V-0052" PARENTS = "F-0348";
CHILD = "V-0053" PARENTS = "F-0348";
CHILD = "V-0054" PARENTS = "F-0348";

FUNCT CHAN = "F-0348"

UINT sign_bit,power_bit,limit_bit,rwa_raw_data;
INT  rwa_speed;

rwa_raw_data = GET_DN();

/* extract sign bit */
sign_bit = ((rwa_raw_data & 0x8000) >> 15);

/* extract power on bit */
power_bit = ((rwa_raw_data & 0x1000) >> 12);

/* extract power limit bit */
limit_bit = ((rwa_raw_data & 0x0800) >> 11);

/* extract 11 speed bits bit */
rwa_speed = (rwa_raw_data & 0x07FF);

/* Convert to RPM */
rwa_speed = rwa_speed * 5;

/* compute signed rwa speed */
IF (sign_bit == 1)
    rwa_speed = -1 * rwa_speed;
ENDIF

/* derive channels */
DERIVE ("V-0052",rwa_speed);
DERIVE ("V-0053",power_bit);
DERIVE ("V-0054",limit_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0532 "THrOnT_12" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 01-14-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3401
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_01
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3402
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_02
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3403
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_03
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3404
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_04
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3405
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_05
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3406
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_06
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3407
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_07
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3408
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_08
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3409
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_09
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3410
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_10
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3411
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_11
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3412
Description:            True Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueOnT_12
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3413
Description:            Total Thruster On Time Adusted For Phantom On Time
Mnemonic:               TrueTotalOnT
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3425
Description:            Propelant Used Summation
Mnemonic:               PROPused_SUM
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  kg

Derived Channel:        V-3431
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_01
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3432
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_02
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3433
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_03
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3434
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_04
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3435
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_05
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3436
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_06
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3437
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_07
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3438
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_08
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3439
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_09
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3440
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_10
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3441
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_11
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3442
Description:            Thruster Delta On Time From Last Tlm Update
Mnemonic:               THRdeltON_12
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3451
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_01
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3452
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_02
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3453
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_03
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3454
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_04
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3455
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_05
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3456
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_06
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3457
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_07
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3458
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_08
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3459
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_09
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3460
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_10
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3461
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_11
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

Derived Channel:        V-3462
Description:            Thruster Duty Cycle From Last Update
Mnemonic:               THRdutyCY_12
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  percnt

*/

CHILD = "V-3401" PARENTS = "F-521""F-532""H-0017";
CHILD = "V-3402" PARENTS = "F-522""F-532""H-0017";
CHILD = "V-3403" PARENTS = "F-523""F-532""H-0017";
CHILD = "V-3404" PARENTS = "F-524""F-532""H-0017";
CHILD = "V-3405" PARENTS = "F-525""F-532""H-0017";
CHILD = "V-3406" PARENTS = "F-526""F-532""H-0017";
CHILD = "V-3407" PARENTS = "F-527""F-532""H-0017";
CHILD = "V-3408" PARENTS = "F-528""F-532""H-0017";
CHILD = "V-3409" PARENTS = "F-529""F-532""H-0017";
CHILD = "V-3410" PARENTS = "F-530""F-532""H-0017";
CHILD = "V-3411" PARENTS = "F-531""F-532""H-0017";
CHILD = "V-3412" PARENTS = "F-532""H-0017";
CHILD = "V-3413" PARENTS = "F-521""F-522""F-523""F-524""F-525""F-526""F-527""F-528""F-529""F-530""F-531""F-532""H-0017";
CHILD = "V-3425" PARENTS = "F-521""F-522""F-523""F-524""F-525""F-526""F-527""F-528""F-529""F-530""F-531""F-532""H-0017""P-104""P-106""T-180""T-183";
CHILD = "V-3431" PARENTS = "F-521""F-532""H-0017";
CHILD = "V-3432" PARENTS = "F-522""F-532""H-0017";
CHILD = "V-3433" PARENTS = "F-523""F-532""H-0017";
CHILD = "V-3434" PARENTS = "F-524""F-532""H-0017";
CHILD = "V-3435" PARENTS = "F-525""F-532""H-0017";
CHILD = "V-3436" PARENTS = "F-526""F-532""H-0017";
CHILD = "V-3437" PARENTS = "F-527""F-532""H-0017";
CHILD = "V-3438" PARENTS = "F-528""F-532""H-0017";
CHILD = "V-3439" PARENTS = "F-529""F-532""H-0017";
CHILD = "V-3440" PARENTS = "F-530""F-532""H-0017";
CHILD = "V-3441" PARENTS = "F-531""F-532""H-0017";
CHILD = "V-3442" PARENTS = "F-532""H-0017";
CHILD = "V-3451" PARENTS = "F-521""F-532""H-0017";
CHILD = "V-3452" PARENTS = "F-522""F-532""H-0017";
CHILD = "V-3453" PARENTS = "F-523""F-532""H-0017";
CHILD = "V-3454" PARENTS = "F-524""F-532""H-0017";
CHILD = "V-3455" PARENTS = "F-525""F-532""H-0017";
CHILD = "V-3456" PARENTS = "F-526""F-532""H-0017";
CHILD = "V-3457" PARENTS = "F-527""F-532""H-0017";
CHILD = "V-3458" PARENTS = "F-528""F-532""H-0017";
CHILD = "V-3459" PARENTS = "F-529""F-532""H-0017";
CHILD = "V-3460" PARENTS = "F-530""F-532""H-0017";
CHILD = "V-3461" PARENTS = "F-531""F-532""H-0017";
CHILD = "V-3462" PARENTS = "F-532""H-0017";

FUNCT CHAN = "F-0532"

INT DELTA_TIME;
FLT THRTRON,THRSUM,P_F,T_F,ISP,THRUST,FUDGE;
STATIC INT FIRST_FLAG=0,FUEL_FLAG=0,LAST_TIME=0;
STATIC FLT LAST_ON_T[13]=0.0;
STATIC FLT FUEL_USED=0.0,LAST_THRSUM=0.0;


IF (DN_VALID("F-0521") == 0 && DN_VALID("F-0532") == 0)

    IF (FIRST_FLAG == 0)
        LAST_ON_T[1] = GET_LAD_EU("F-0521");
        LAST_ON_T[2] = GET_LAD_EU("F-0522");
        LAST_ON_T[3] = GET_LAD_EU("F-0523");
        LAST_ON_T[4] = GET_LAD_EU("F-0524");
        LAST_ON_T[5] = GET_LAD_EU("F-0525");
        LAST_ON_T[6] = GET_LAD_EU("F-0526");
        LAST_ON_T[7] = GET_LAD_EU("F-0527");
        LAST_ON_T[8] = GET_LAD_EU("F-0528");
        LAST_ON_T[9] = GET_LAD_EU("F-0529");
        LAST_ON_T[10] = GET_LAD_EU("F-0530");
        LAST_ON_T[11] = GET_LAD_EU("F-0531");
        LAST_ON_T[12] = GET_LAD_EU("F-0532");
        FIRST_FLAG = 1;
    ENDIF

    DELTA_TIME = GET_LAD_DN("H-0017") - LAST_TIME;
    IF (DELTA_TIME <= 0)
        DELTA_TIME = 100000;
    ENDIF
    LAST_TIME = GET_LAD_DN("H-0017");



    THRTRON = GET_LAD_EU("F-0521");
    THRSUM = THRTRON - 27.74;
    DERIVE ("V-3401",THRTRON - 27.74);
    DERIVE ("V-3431",THRTRON - LAST_ON_T[1]);
    DERIVE ("V-3451",(THRTRON - LAST_ON_T[1])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[1] = THRTRON;

    THRTRON = GET_LAD_EU("F-0522");
    THRSUM = THRSUM + THRTRON - 27.74;
    DERIVE ("V-3402",THRTRON - 27.74);
    DERIVE ("V-3432",THRTRON - LAST_ON_T[2]);
    DERIVE ("V-3452",(THRTRON - LAST_ON_T[2])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[2] = THRTRON;

    THRTRON = GET_LAD_EU("F-0523");
    THRSUM = THRSUM + THRTRON - 29.28;
    DERIVE ("V-3403",THRTRON - 29.28);
    DERIVE ("V-3433",THRTRON - LAST_ON_T[3]);
    DERIVE ("V-3453",(THRTRON - LAST_ON_T[3])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[3] = THRTRON;

    THRTRON = GET_LAD_EU("F-0524");
    THRSUM = THRSUM + THRTRON - 29.28;
    DERIVE ("V-3404",THRTRON - 29.28);
    DERIVE ("V-3434",THRTRON - LAST_ON_T[4]);
    DERIVE ("V-3454",(THRTRON - LAST_ON_T[4])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[4] = THRTRON;

    THRTRON = GET_LAD_EU("F-0525");
    THRSUM = THRSUM + THRTRON - 15.14;
    DERIVE ("V-3405",THRTRON - 15.14);
    DERIVE ("V-3435",THRTRON - LAST_ON_T[5]);
    DERIVE ("V-3455",(THRTRON - LAST_ON_T[5])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[5] = THRTRON;

    THRTRON = GET_LAD_EU("F-0526");
    THRSUM = THRSUM + THRTRON - 15.14;
    DERIVE ("V-3406",THRTRON - 15.14);
    DERIVE ("V-3436",THRTRON - LAST_ON_T[6]);
    DERIVE ("V-3456",(THRTRON - LAST_ON_T[6])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[6] = THRTRON;

    THRTRON = GET_LAD_EU("F-0527");
    THRSUM = THRSUM + THRTRON - 30.04;
    DERIVE ("V-3407",THRTRON - 30.04);
    DERIVE ("V-3437",THRTRON - LAST_ON_T[7]);
    DERIVE ("V-3457",(THRTRON - LAST_ON_T[7])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[7] = THRTRON;

    THRTRON = GET_LAD_EU("F-0528");
    THRSUM = THRSUM + THRTRON - 30.04;
    DERIVE ("V-3408",THRTRON - 30.04);
    DERIVE ("V-3438",THRTRON - LAST_ON_T[8]);
    DERIVE ("V-3458",(THRTRON - LAST_ON_T[8])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[8] = THRTRON;

    THRTRON = GET_LAD_EU("F-0529");
    THRSUM = THRSUM + THRTRON - 23.17;
    DERIVE ("V-3409",THRTRON - 23.17);
    DERIVE ("V-3439",THRTRON - LAST_ON_T[9]);
    DERIVE ("V-3459",(THRTRON - LAST_ON_T[9])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[9] = THRTRON;

    THRTRON = GET_LAD_EU("F-0530");
    THRSUM = THRSUM + THRTRON - 35.09;
    DERIVE ("V-3410",THRTRON - 35.09);
    DERIVE ("V-3440",THRTRON - LAST_ON_T[10]);
    DERIVE ("V-3460",(THRTRON - LAST_ON_T[10])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[10] = THRTRON;

    THRTRON = GET_LAD_EU("F-0531");
    THRSUM = THRSUM + THRTRON - 23.17;
    DERIVE ("V-3411",THRTRON - 23.17);
    DERIVE ("V-3441",THRTRON - LAST_ON_T[11]);
    DERIVE ("V-3461",(THRTRON - LAST_ON_T[11])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[11] = THRTRON;

    THRTRON = GET_LAD_EU("F-0532");
    THRSUM = THRSUM + THRTRON - 35.09;
    DERIVE ("V-3412",THRTRON - 35.09);
    DERIVE ("V-3442",THRTRON - LAST_ON_T[12]);
    DERIVE ("V-3462",(THRTRON - LAST_ON_T[12])/(FLT)DELTA_TIME*100.0);
    LAST_ON_T[12] = THRTRON;

    DERIVE ("V-3413",THRSUM);

    IF (FUEL_FLAG == 0 || DN_VALID("V-3425") != 0)
        FUEL_FLAG = 1;
        LAST_THRSUM = THRSUM;
        FUEL_USED = 0.0;
        DERIVE ("V-3425",FUEL_USED);
    ELSEIF (EU_VALID("P-0104") == 0 && EU_VALID("P-0106") == 0 && EU_VALID("T-0180") == 0 && EU_VALID("T-0183") == 0)
        P_F = (GET_LAD_EU("P-0104") + GET_LAD_EU("P-0106")) / 2.0;
        T_F = (GET_LAD_EU("T-0180") + GET_LAD_EU("T-0183")) / 2.0;
        FUDGE = 0.8;
        ISP = FUDGE * ((P_F / (0.027258 + 0.0042958 * P_F)) - (0.1563 * ( 20.0 - T_F)));
        THRUST = 0.0026 * P_F + 0.14;
        FUEL_USED = FUEL_USED + ((THRSUM - LAST_THRSUM) * THRUST / ISP) * 0.4536;
        DERIVE ("V-3425",FUEL_USED);
        LAST_THRSUM = THRSUM;
    ENDIF

ENDIF

ENDFUNCT




/*****************************************************************************
 *                                                                           *
 * F-0360 "SAM_AZ_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0082
Description:            SAM AZIMUTH FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               SAM_AZang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0082" PARENTS = "F-0360";

FUNCT CHAN = "F-0360"

/* Derive flight software computed control frame position in degrees */
DERIVE ("V-0082",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0362 "SAM_AZ_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:             OGS 11-15-96 Corrected true bias value of 28.95     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0072
Description:            SAM AZIMUTH TRUE POSITION (CONTROL FRAME)
Mnemonic:               SAM_AZ_TRUE
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0072" PARENTS = "F-0362";

FUNCT CHAN = "F-0362"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * 0.02197266) - 28.95;
IF (cf_pos < -150.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 210.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("V-0072", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0377 "SAM_EL_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0083
Description:            SAM ELEVATION FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               SAM_ELang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0083" PARENTS = "F-0377";

FUNCT CHAN = "F-0377"

/* Derive flight software computed control frame position in degrees */
DERIVE ("V-0083",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0379 "SAM_EL_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:             OGS 11-15-96 Corrected true bias value of 31.38     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0073
Description:            SAM ELEVATION TRUE POSITION (CONTROL FRAME)
Mnemonic:               SAM_EL_TRUE
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0073" PARENTS = "F-0379";

FUNCT CHAN = "F-0379"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * 0.02197266) + 31.38;
IF (cf_pos < -150.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 210.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("V-0073", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0385 "SAM_STATS" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-21-95                                         *
 * MODIFIED:             OGS 8-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2073
Description:            SAM GDE Estimated Power
Mnemonic:               SAM_GDE_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2074
Description:            SAM Motors Estimated Power
Mnemonic:               SAM_MTR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2075
Description:            SAM Encoder Estimated Power
Mnemonic:               SAM_ENC_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2073" PARENTS = "F-0385""F-0388""F-0362""F-0379""F-0801""F-0803""F-0809""F-0811";
CHILD = "V-2074" PARENTS = "F-0385""F-0388""F-0362""F-0379""F-0801""F-0803""F-0809""F-0811";
CHILD = "V-2075" PARENTS = "F-0385""F-0388""F-0362""F-0379""F-0801""F-0803""F-0809""F-0811";

FUNCT CHAN = "F-0385"

FLT SAM_GDE_PWR, SAM_MTR_PWR, SAM_ENC_PWR;

/* Check GDE telemetry validity */
IF ((DN_VALID("F-0811") != 0) || (DN_VALID("F-0362") != 0) || (DN_VALID("F-0379") != 0) || (DN_VALID("F-0388") != 0))
	RETURN;
ENDIF

/* Check Power Status of GDE */
IF (GET_LAD_DN("F-0388") == 1)
	/* GDE is powered off */
	SAM_GDE_PWR = 0.00;
	SAM_MTR_PWR = 0.00;
	SAM_ENC_PWR = 0.00;
ELSE
	/* GDE is powered on, baseline power at zero rate */
	SAM_GDE_PWR = 0.30;
	SAM_MTR_PWR = 0.00;
	SAM_ENC_PWR = 1.20;
	/* Check status of azimuth motor */
	IF (GET_LAD_DN("F-0803") == 0) /* Stop command in effect, powered hold */
		SAM_GDE_PWR = SAM_GDE_PWR + 1.43;
		SAM_MTR_PWR = SAM_MTR_PWR + 7.92;
	ELSEIF ((GET_LAD_DN("F-0803") == 1) && (GET_LAD_DN("F-0801") == 1)) /* Rate mode in effect, and moving */
		SAM_GDE_PWR = SAM_GDE_PWR + 0.62;
		SAM_MTR_PWR = SAM_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("F-0803") == 2) && (GET_LAD_DN("F-0801") == 1)) /* Step mode in effect, and moving */
		SAM_GDE_PWR = SAM_GDE_PWR + 0.62;
		SAM_MTR_PWR = SAM_MTR_PWR + 2.70;
	ENDIF
	/* Check status of elevation motor */
	IF (GET_LAD_DN("F-0811") == 0) /* Stop command in effect, powered hold */
		SAM_GDE_PWR = SAM_GDE_PWR + 1.43;
		SAM_MTR_PWR = SAM_MTR_PWR + 7.92;
	ELSEIF ((GET_LAD_DN("F-0811") == 1) && (GET_LAD_DN("F-0809") == 1)) /* Rate mode in effect, and moving */
		SAM_GDE_PWR = SAM_GDE_PWR + 0.62;
		SAM_MTR_PWR = SAM_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("F-0811") == 2) && (GET_LAD_DN("F-0809") == 1)) /* Step mode in effect, and moving */
		SAM_GDE_PWR = SAM_GDE_PWR + 0.62;
		SAM_MTR_PWR = SAM_MTR_PWR + 2.70;
	ENDIF
ENDIF

DERIVE ("V-2073", SAM_GDE_PWR);
DERIVE ("V-2074", SAM_MTR_PWR);
DERIVE ("V-2075", SAM_ENC_PWR);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0390 "SAP_AZ_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0084
Description:            SAP AZIMUTH FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               SAP_AZang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0084" PARENTS = "F-0390";

FUNCT CHAN = "F-0390"

/* Derive flight software computed control frame position in degrees */
DERIVE ("V-0084",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0392 "SAP_AZ_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:             OGS 11-15-96 Corrected true bias value of 33.29     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0074
Description:            SAP AZIMUTH TRUE POSITION (CONTROL FRAME)
Mnemonic:               SAP_AZ_TRUE
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0074" PARENTS = "F-0392";

FUNCT CHAN = "F-0392"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * 0.02197266) - 33.29;
IF (cf_pos < -210.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 150.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("V-0074", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0407 "SAP_EL_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0085
Description:            SAP ELEVATION FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               SAP_ELang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0085" PARENTS = "F-0407";

FUNCT CHAN = "F-0407"

/* Derive flight software computed control frame position in degrees */
DERIVE ("V-0085",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0409 "SAP_EL_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:             OGS 11-15-96 Corrected true bias value of 29.34     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0075
Description:            SAP ELEVATION TRUE POSITION (CONTROL FRAME)
Mnemonic:               SAP_EL_TRUE
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0075" PARENTS = "F-0409";

FUNCT CHAN = "F-0409"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * 0.02197266) + 29.34;
IF (cf_pos < -210.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 150.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("V-0075", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0415 "SAP_STATS" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-21-95                                         *
 * MODIFIED:             OGS 7-26-97  Update load values                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2076
Description:            SAP GDE Estimated Power
Mnemonic:               SAP_GDE_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2077
Description:            SAP Motors Estimated Power
Mnemonic:               SAP_MTR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        V-2078
Description:            SAP Encoder Estimated Power
Mnemonic:               SAP_ENC_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2076" PARENTS = "F-0415""F-0418""F-0392""F-0409""F-0821""F-0823""F-0829""F-0831";
CHILD = "V-2077" PARENTS = "F-0415""F-0418""F-0392""F-0409""F-0821""F-0823""F-0829""F-0831";
CHILD = "V-2078" PARENTS = "F-0415""F-0418""F-0392""F-0409""F-0821""F-0823""F-0829""F-0831";

FUNCT CHAN = "F-0415"

FLT SAP_GDE_PWR, SAP_MTR_PWR, SAP_ENC_PWR;

/* Check GDE telemetry validity */
IF ((DN_VALID("F-0831") != 0) || (DN_VALID("F-0392") != 0) || (DN_VALID("F-0409") != 0) || (DN_VALID("F-0418") != 0))
	RETURN;
ENDIF

/* Check Power Status of GDE */
IF (GET_LAD_DN("F-0418") == 1)
	/* GDE is powered off */
	SAP_GDE_PWR = 0.00;
	SAP_MTR_PWR = 0.00;
	SAP_ENC_PWR = 0.00;
ELSE
	/* GDE is powered on, baseline power at zero rate */
	SAP_GDE_PWR = 0.30;
	SAP_MTR_PWR = 0.00;
	SAP_ENC_PWR = 1.20;
	/* Check status of azimuth motor */
	IF (GET_LAD_DN("F-0823") == 0) /* Stop command in effect, powered hold */
		SAP_GDE_PWR = SAP_GDE_PWR + 1.43;
		SAP_MTR_PWR = SAP_MTR_PWR + 7.92;
	ELSEIF ((GET_LAD_DN("F-0823") == 1) && (GET_LAD_DN("F-0821") == 1)) /* Rate mode in effect, and moving */
		SAP_GDE_PWR = SAP_GDE_PWR + 0.62;
		SAP_MTR_PWR = SAP_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("F-0823") == 2) && (GET_LAD_DN("F-0821") == 1)) /* Step mode in effect, and moving */
		SAP_GDE_PWR = SAP_GDE_PWR + 0.62;
		SAP_MTR_PWR = SAP_MTR_PWR + 2.70;
	ENDIF
	/* Check status of elevation motor */
	IF (GET_LAD_DN("F-0831") == 0) /* Stop command in effect, powered hold */
		SAP_GDE_PWR = SAP_GDE_PWR + 1.43;
		SAP_MTR_PWR = SAP_MTR_PWR + 7.92;
	ELSEIF ((GET_LAD_DN("F-0831") == 1) && (GET_LAD_DN("F-0829") == 1)) /* Rate mode in effect, and moving */
		SAP_GDE_PWR = SAP_GDE_PWR + 0.62;
		SAP_MTR_PWR = SAP_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("F-0831") == 2) && (GET_LAD_DN("F-0829") == 1)) /* Step mode in effect, and moving */
		SAP_GDE_PWR = SAP_GDE_PWR + 0.62;
		SAP_MTR_PWR = SAP_MTR_PWR + 2.70;
	ENDIF
ENDIF

DERIVE ("V-2076", SAP_GDE_PWR);
DERIVE ("V-2077", SAP_MTR_PWR);
DERIVE ("V-2078", SAP_ENC_PWR);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0440 "SSA_RAW_RET" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 10-18-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0061
Description:            Reticle A Counts Converted From Gray Code
Mnemonic:               SSA_RETICL_A
Subsystem:              AACS
Data_Type:              UNSIGNED
Units:                  counts

Derived Channel:        V-0062
Description:            Reticle B Counts Converted From Gray Code
Mnemonic:               SSA_RETICL_B
Subsystem:              AACS
Data_Type:              UNSIGNED
Units:                  counts

*/

CHILD = "V-0061" PARENTS = "F-0440";
CHILD = "V-0062" PARENTS = "F-0440";

FUNCT CHAN = "F-0440"

UINT i, ssa_gray, ssa_count_a, ssa_count_b;
UINT bit[8];

ssa_gray = (GET_DN() & 0XFF00) >> 8;

FOR (i=0; i<=7; i++)
    bit[i] = (ssa_gray & (2**(7-i))) >> (7-i);
ENDFOR

FOR (i=0; i<7; i++)
    IF (bit[i] == 1)
        bit[i+1] = ~bit[i+1] & 1;
    ENDIF
ENDFOR

ssa_count_a = 0;
FOR (i=0; i<=7; i++)
    ssa_count_a = ssa_count_a + (bit[i] << (7-i));
ENDFOR


ssa_gray = (GET_DN() & 0X00FF);

FOR (i=0; i<=7; i++)
    bit[i] = (ssa_gray & (2**(7-i))) >> (7-i);
ENDFOR

FOR (i=0; i<7; i++)
    IF (bit[i] == 1)
        bit[i+1] = ~bit[i+1] & 1;
    ENDIF
ENDFOR

ssa_count_b = 0;
FOR (i=0; i<=7; i++)
    ssa_count_b = ssa_count_b + (bit[i] << (7-i));
ENDFOR

DERIVE ("V-0061",ssa_count_a);
DERIVE ("V-0062",ssa_count_b);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0470 "SAP_NORM_Z" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-18-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0068
Description:            SAM Sun Incidence Angle
Mnemonic:               SAM_SUN_INC
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0069
Description:            SAP Sun Incidence Angle
Mnemonic:               SAP_SUN_INC
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0068" PARENTS = "F-0470""F-0471""F-0472""F-0411""F-0412""F-0413""F-0381""F-0382""F-0383";
CHILD = "V-0069" PARENTS = "F-0470""F-0471""F-0472""F-0411""F-0412""F-0413""F-0381""F-0382""F-0383";

FUNCT CHAN = "F-0470"

FLT SA_ANG, SUN_MAG, SA_MAG, SUN_X, SUN_Y, SUN_Z, SA_X, SA_Y, SA_Z;

IF (DN_VALID("F-0472") == 0 && DN_VALID("F-0413") == 0 && DN_VALID("F-0383") == 0)

    SUN_X = GET_LAD_EU("F-0470");
    SUN_Y = GET_LAD_EU("F-0471");
    SUN_Z = GET_LAD_EU("F-0472");
    SUN_MAG = SQRT(SUN_X*SUN_X + SUN_Y*SUN_Y + SUN_Z*SUN_Z);
    SA_X = GET_LAD_EU("F-0381");
    SA_Y = GET_LAD_EU("F-0382");
    SA_Z = GET_LAD_EU("F-0383");
    SA_MAG = SQRT(SA_X*SA_X + SA_Y*SA_Y + SA_Z*SA_Z);
    SA_ANG = ASIN((SUN_X*SA_X + SUN_Y*SA_Y + SUN_Z*SA_Z) / (SUN_MAG * SA_MAG)) * 180.0 / PI;
    DERIVE ("V-0068", SA_ANG);

    SA_X = GET_LAD_EU("F-0411");
    SA_Y = GET_LAD_EU("F-0412");
    SA_Z = GET_LAD_EU("F-0413");
    SA_MAG = SQRT(SA_X*SA_X + SA_Y*SA_Y + SA_Z*SA_Z);
    SA_ANG = ASIN((SUN_X*SA_X + SUN_Y*SA_Y + SUN_Z*SA_Z) / (SUN_MAG * SA_MAG)) * 180.0 / PI;
    DERIVE ("V-0069", SA_ANG);

ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-0472 "SUNVEC_RAW_Z" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 6-18-96                                         *
 * MODIFIED:             OGS 10-23-97                                        *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0110
Description:            Angular difference between ephemeris sun and measured sun
Mnemonic:               EPH_SUN_DIF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0120
Description:            SAM HINGE ANGLE (DEGREES) (Measured Sun)
Mnemonic:               SAM_HNG_ANGm
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0121
Description:            SAP HINGE ANGLE (DEGREES) (Measured Sun)
Mnemonic:               SAP_HNG_ANGm
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0122
Description:            SAM PANEL TORSION     (DEGREES) (Measured Sun)
Mnemonic:               SAM_TOR_ANGm
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0123
Description:            SAP PANEL TORSION     (DEGREES) (Measured Sun)
Mnemonic:               SAP_TOR_ANGm
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg


Derived Channel:        V-0124
Description:            SAM HINGE ANGLE (DEGREES) (Ephem Sun)
Mnemonic:               SAM_HNG_ANGe
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0125
Description:            SAP HINGE ANGLE (DEGREES) (Ephem Sun)
Mnemonic:               SAP_HNG_ANGe
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0126
Description:            SAM PANEL TORSION     (DEGREES) (Ephem Sun)
Mnemonic:               SAM_TOR_ANGe
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0127
Description:            SAP PANEL TORSION     (DEGREES) (Ephem Sun)
Mnemonic:               SAP_TOR_ANGe
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0128
Description:            SUN PHASE DIFFERENCE  (DEGREES)
Mnemonic:               SUNphaseDIFF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        V-0129
Description:            SUN X DIFFERENCE  (DEGREES)
Mnemonic:               SUN_X_DIFF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "V-0110" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0120" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0121" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0122" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0123" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0124" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0125" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0126" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0127" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0128" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";
CHILD = "V-0129" PARENTS = "F-0085""F-0086""F-0360""F-0377""F-0390""F-0407""F-0440""F-0444""F-0470""F-0471""F-0472""F-0873";

FUNCT CHAN = "F-0472"

FLT eph_sun_bz;
FLT raw_sun_x,raw_sun_y,raw_sun_z;
FLT head_x_ret,head_y_ret,head_z_ret,length,sam_az,sam_el;
FLT dcm_11,dcm_12,dcm_13,dcm_21,dcm_22,dcm_23,dcm_31,dcm_32,dcm_33;
FLT sun_x,sun_y,sun_z,head_x_bod,head_y_bod,head_z_bod,hinge_angle,torsion_angle;
UINT i, ssa_gray, ssa_count_a, ssa_count_b;
UINT bit[8];

IF (DN_VALID("F-0086") == 0)

    eph_sun_bz = SQRT(1.0 - GET_LAD_EU("F-0085")**2 - GET_LAD_EU("F-0086")**2);
    IF (GET_EU() < 0.0)
        eph_sun_bz = eph_sun_bz * -1.0;
    ENDIF

    length = SQRT(GET_LAD_EU("F-0470")**2 + GET_LAD_EU("F-0471")**2 + GET_EU()**2);
    sun_x = GET_LAD_EU("F-0470")/length;
    sun_y = GET_LAD_EU("F-0471")/length;
    sun_z = GET_EU()/length;

    DERIVE ("V-0110",(180.0/PI * ACOS(sun_x*GET_LAD_EU("F-0085") + sun_y*GET_LAD_EU("F-0086") + sun_z*eph_sun_bz)));

ENDIF


/* Check telemetry validity */
IF ((DN_VALID("F-0360") != 0) || (DN_VALID("F-0377") != 0) || (DN_VALID("F-0440") != 0) ||
    (DN_VALID("F-0873") != 0) || (DN_VALID("F-0444") != 0) || (DN_VALID("F-0390") != 0) ||
    (DN_VALID("F-0407") != 0) || (DN_VALID("F-0085") != 0) || (DN_VALID("F-0086") != 0))
        RETURN;
ENDIF

ssa_gray = (GET_LAD_DN("F-0440") & 0XFF00) >> 8;

FOR (i=0; i<=7; i++)
    bit[i] = (ssa_gray & (2**(7-i))) >> (7-i);
ENDFOR

FOR (i=0; i<7; i++)
    IF (bit[i] == 1)
        bit[i+1] = ~bit[i+1] & 1;
    ENDIF
ENDFOR

ssa_count_a = 0;
FOR (i=0; i<=7; i++)
    ssa_count_a = ssa_count_a + (bit[i] << (7-i));
ENDFOR


ssa_gray = (GET_LAD_DN("F-0440") & 0X00FF);

FOR (i=0; i<=7; i++)
    bit[i] = (ssa_gray & (2**(7-i))) >> (7-i);
ENDFOR

FOR (i=0; i<7; i++)
    IF (bit[i] == 1)
        bit[i+1] = ~bit[i+1] & 1;
    ENDIF
ENDFOR

ssa_count_b = 0;
FOR (i=0; i<=7; i++)
    ssa_count_b = ssa_count_b + (bit[i] << (7-i));
ENDFOR

IF (GET_LAD_DN("F-0873")==4 && GET_LAD_DN("F-0444")==3)
    raw_sun_x = -0.350625 + (0.00275 * (FLT)ssa_count_a);
    raw_sun_y = -0.350625 + (0.00275 * (FLT)ssa_count_b);
    IF(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)) < 0)
        raw_sun_z = 0;
    ELSE
        raw_sun_z = SQRT(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)));
    ENDIF

    raw_sun_x = -1.4553 * raw_sun_x;
    raw_sun_y = 1.4553 * raw_sun_y;
    raw_sun_z = raw_sun_z;

    length = SQRT(raw_sun_x**2 + raw_sun_y**2 + raw_sun_z**2);

    head_x_ret = raw_sun_x / length;
    head_y_ret = raw_sun_y / length;
    head_z_ret = raw_sun_z / length;

    sam_az = GET_LAD_EU("F-0360");
    sam_el = GET_LAD_EU("F-0377");

    dcm_11 = SIN(sam_az) * SIN(sam_el);
    dcm_12 = COS(sam_az);
    dcm_13 = -COS(sam_el) * SIN(sam_az);
    dcm_21 = COS(sam_el);
    dcm_22 = 0.0;
    dcm_23 = SIN(sam_el);
    dcm_31 = SIN(sam_el) * COS(sam_az);
    dcm_32 = -SIN(sam_az);
    dcm_33 = -COS(sam_az) * COS(sam_el);

    sun_x = GET_LAD_EU("F-0470");
    sun_y = GET_LAD_EU("F-0471");
    sun_z = GET_EU();

    head_x_bod = dcm_11*sun_x + dcm_12*sun_y + dcm_13*sun_z;
    head_y_bod = dcm_21*sun_x + dcm_22*sun_y + dcm_23*sun_z;
    head_z_bod = dcm_31*sun_x + dcm_32*sun_y + dcm_33*sun_z;

    hinge_angle = 180.0/PI * (ATAN2(head_z_ret,head_x_ret) - ATAN2(head_z_bod,head_x_bod));
    torsion_angle = 180.0/PI * (ASIN(head_y_ret) - ASIN(head_y_bod));

ELSE
    hinge_angle = -1.0;
    torsion_angle = -1.0;
ENDIF

DERIVE ("V-0120",hinge_angle);
DERIVE ("V-0122",torsion_angle);


IF (GET_LAD_DN("F-0873")==5 && GET_LAD_DN("F-0444")==3)
    raw_sun_x = -0.350625 + (0.00275 * (FLT)ssa_count_a);
    raw_sun_y = -0.350625 + (0.00275 * (FLT)ssa_count_b);
    IF(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)) < 0)
        raw_sun_z = 0;
    ELSE
        raw_sun_z = SQRT(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)));
    ENDIF

    raw_sun_x = -1.4553 * raw_sun_x;
    raw_sun_y = 1.4553 * raw_sun_y;
    raw_sun_z = raw_sun_z;

    length = SQRT(raw_sun_x**2 + raw_sun_y**2 + raw_sun_z**2);

    head_x_ret = raw_sun_x / length;
    head_y_ret = raw_sun_y / length;
    head_z_ret = raw_sun_z / length;

    sam_az = GET_LAD_EU("F-0390");
    sam_el = GET_LAD_EU("F-0407");

    dcm_11 = -SIN(sam_az) * SIN(sam_el);
    dcm_12 = -COS(sam_az);
    dcm_13 = -COS(sam_el) * SIN(sam_az);
    dcm_21 = -COS(sam_el);
    dcm_22 = 0.0;
    dcm_23 = SIN(sam_el);
    dcm_31 = -SIN(sam_el) * COS(sam_az);
    dcm_32 = SIN(sam_az);
    dcm_33 = -COS(sam_az) * COS(sam_el);

    sun_x = GET_LAD_EU("F-0470");
    sun_y = GET_LAD_EU("F-0471");
    sun_z = GET_EU();

    head_x_bod = dcm_11*sun_x + dcm_12*sun_y + dcm_13*sun_z;
    head_y_bod = dcm_21*sun_x + dcm_22*sun_y + dcm_23*sun_z;
    head_z_bod = dcm_31*sun_x + dcm_32*sun_y + dcm_33*sun_z;

    hinge_angle = 180.0/PI * (ATAN2(head_z_ret,head_x_ret) - ATAN2(head_z_bod,head_x_bod));
    torsion_angle = 180.0/PI * (ASIN(head_y_ret) - ASIN(head_y_bod));

ELSE
    hinge_angle = -1.0;
    torsion_angle = -1.0;
ENDIF

DERIVE ("V-0121",hinge_angle);
DERIVE ("V-0123",torsion_angle);

IF (GET_LAD_DN("F-0873")==4 && GET_LAD_DN("F-0444")==3)
    raw_sun_x = -0.350625 + (0.00275 * (FLT)ssa_count_a);
    raw_sun_y = -0.350625 + (0.00275 * (FLT)ssa_count_b);
    IF(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)) < 0)
        raw_sun_z = 0;
    ELSE
        raw_sun_z = SQRT(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)));
    ENDIF

    raw_sun_x = -1.4553 * raw_sun_x;
    raw_sun_y = 1.4553 * raw_sun_y;
    raw_sun_z = raw_sun_z;

    length = SQRT(raw_sun_x**2 + raw_sun_y**2 + raw_sun_z**2);

    head_x_ret = raw_sun_x / length;
    head_y_ret = raw_sun_y / length;
    head_z_ret = raw_sun_z / length;

    sam_az = GET_LAD_EU("F-0360");
    sam_el = GET_LAD_EU("F-0377");

    dcm_11 = SIN(sam_az) * SIN(sam_el);
    dcm_12 = COS(sam_az);
    dcm_13 = -COS(sam_el) * SIN(sam_az);
    dcm_21 = COS(sam_el);
    dcm_22 = 0.0;
    dcm_23 = SIN(sam_el);
    dcm_31 = SIN(sam_el) * COS(sam_az);
    dcm_32 = -SIN(sam_az);
    dcm_33 = -COS(sam_az) * COS(sam_el);

/*
    sun_x = GET_LAD_EU("F-0470");
    sun_y = GET_LAD_EU("F-0471");
    sun_z = GET_EU();
*/
    sun_x = GET_LAD_EU("F-0085");
    sun_y = GET_LAD_EU("F-0086");
    sun_z = eph_sun_bz;

    head_x_bod = dcm_11*sun_x + dcm_12*sun_y + dcm_13*sun_z;
    head_y_bod = dcm_21*sun_x + dcm_22*sun_y + dcm_23*sun_z;
    head_z_bod = dcm_31*sun_x + dcm_32*sun_y + dcm_33*sun_z;

    hinge_angle = 180.0/PI * (ATAN2(head_z_ret,head_x_ret) - ATAN2(head_z_bod,head_x_bod));
    torsion_angle = 180.0/PI * (ASIN(head_y_ret) - ASIN(head_y_bod));

ELSE
    hinge_angle = -1.0;
    torsion_angle = -1.0;
ENDIF

DERIVE ("V-0124",hinge_angle);
DERIVE ("V-0126",torsion_angle);


IF (GET_LAD_DN("F-0873")==5 && GET_LAD_DN("F-0444")==3)
    raw_sun_x = -0.350625 + (0.00275 * (FLT)ssa_count_a);
    raw_sun_y = -0.350625 + (0.00275 * (FLT)ssa_count_b);
    IF(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)) < 0)
        raw_sun_z = 0;
    ELSE
        raw_sun_z = SQRT(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)));
    ENDIF

    raw_sun_x = -1.4553 * raw_sun_x;
    raw_sun_y = 1.4553 * raw_sun_y;
    raw_sun_z = raw_sun_z;

    length = SQRT(raw_sun_x**2 + raw_sun_y**2 + raw_sun_z**2);

    head_x_ret = raw_sun_x / length;
    head_y_ret = raw_sun_y / length;
    head_z_ret = raw_sun_z / length;

    sam_az = GET_LAD_EU("F-0390");
    sam_el = GET_LAD_EU("F-0407");

    dcm_11 = -SIN(sam_az) * SIN(sam_el);
    dcm_12 = -COS(sam_az);
    dcm_13 = -COS(sam_el) * SIN(sam_az);
    dcm_21 = -COS(sam_el);
    dcm_22 = 0.0;
    dcm_23 = SIN(sam_el);
    dcm_31 = -SIN(sam_el) * COS(sam_az);
    dcm_32 = SIN(sam_az);
    dcm_33 = -COS(sam_az) * COS(sam_el);

/*
    sun_x = GET_LAD_EU("F-0470");
    sun_y = GET_LAD_EU("F-0471");
    sun_z = GET_EU();
*/
    sun_x = GET_LAD_EU("F-0085");
    sun_y = GET_LAD_EU("F-0086");
    sun_z = eph_sun_bz;

    head_x_bod = dcm_11*sun_x + dcm_12*sun_y + dcm_13*sun_z;
    head_y_bod = dcm_21*sun_x + dcm_22*sun_y + dcm_23*sun_z;
    head_z_bod = dcm_31*sun_x + dcm_32*sun_y + dcm_33*sun_z;

    hinge_angle = 180.0/PI * (ATAN2(head_z_ret,head_x_ret) - ATAN2(head_z_bod,head_x_bod));
    torsion_angle = 180.0/PI * (ASIN(head_y_ret) - ASIN(head_y_bod));

ELSE
    hinge_angle = -1.0;
    torsion_angle = -1.0;
ENDIF


DERIVE ("V-0125",hinge_angle);
DERIVE ("V-0127",torsion_angle);
DERIVE ("V-0128", 180.0/PI * (ATAN2(eph_sun_bz,GET_LAD_EU("F-0086")) - ATAN2(GET_EU(),GET_LAD_EU("F-0471"))));
DERIVE ("V-0129", 180.0/PI * (ACOS(GET_LAD_EU("F-0085")) - ACOS(GET_LAD_EU("F-0470"))));


ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * F-0482 "SYST_MO_Z" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 12-18-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-0065
Description:            Magnitude of Cyclic Momentum
Mnemonic:               SYS_MOM_MAG
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  Nmsec

*/

CHILD = "V-0065" PARENTS = "F-0481""F-0482";

FUNCT CHAN = "F-0482"

FLT MOM_Y, MOM_Z;

IF (EU_VALID("F-0481") == 0)
    MOM_Y = GET_LAD_EU("F-0481");
    MOM_Z = GET_EU();
    DERIVE ("V-0065", SQRT(MOM_Y*MOM_Y + MOM_Z*MOM_Z));
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * F-1030 "CV_DATA_WORD" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 09-26-95                                        *
 * MODIFIED:             OGS 03-04-96  (Modified 1, 2, 3 Word MRO)           *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-1011
Description:            CV Message Class Description
Mnemonic:               CV_CLASS
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        V-1013
Description:            CV Message Sub Class Description
Mnemonic:               CV_SUB_CLASS
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        V-1015
Description:            CV Message String Part 1
Mnemonic:               CV_MSG_PART1
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        V-1016
Description:            CV Message String Part 2
Mnemonic:               CV_MSG_PART2
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        V-1017
Description:            CV Message String Part 3
Mnemonic:               CV_MSG_PART3
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        V-1018
Description:            CV Message String Part 4
Mnemonic:               CV_MSG_PART4
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        V-1019
Description:            CV Message String Part 5
Mnemonic:               CV_MSG_PART5
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        V-1021
Description:            Command Error Code
Mnemonic:               CMD_ERR_CODE
Subsystem:              CDH
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-1022
Description:            Command Error Code Description
Mnemonic:               CMD_ERR_DESC
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        V-1024
Description:            Last CHECKSUM Value
Mnemonic:               L_CHKSUM_VAL
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        V-1025
Description:            Last CHECKSUM Physical Memory Address (MSH)
Mnemonic:               L_CHKSUM_MSH
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        V-1026
Description:            Last CHECKSUM Physical Memory Address (LSH)
Mnemonic:               L_CHKSUM_LSH
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        V-1027
Description:            Last 1, 2 or 3 Word Memory Readout Address
Mnemonic:               L_MEM_ADDR
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        V-1028
Description:            Last Memory Readout Word 1
Mnemonic:               L_MEM_WORD1
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        V-1029
Description:            Last Memory Readout Word 2
Mnemonic:               L_MEM_WORD2
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        V-1030
Description:            Last Memory Readout Word 3
Mnemonic:               L_MEM_WORD3
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

*/

CHILD = "V-1011" PARENTS = "F-1030";
CHILD = "V-1013" PARENTS = "F-1030";
CHILD = "V-1015" PARENTS = "F-1030";
CHILD = "V-1016" PARENTS = "F-1030";
CHILD = "V-1017" PARENTS = "F-1030";
CHILD = "V-1018" PARENTS = "F-1030";
CHILD = "V-1019" PARENTS = "F-1030";
CHILD = "V-1021" PARENTS = "F-1030";
CHILD = "V-1022" PARENTS = "F-1030";
CHILD = "V-1024" PARENTS = "F-1030";
CHILD = "V-1025" PARENTS = "F-1030";
CHILD = "V-1026" PARENTS = "F-1030";
CHILD = "V-1027" PARENTS = "F-1030";
CHILD = "V-1028" PARENTS = "F-1030";
CHILD = "V-1029" PARENTS = "F-1030";
CHILD = "V-1030" PARENTS = "F-1030";

FUNCT CHAN = "F-1030"

UINT cv_word, byte_val, script_add, i, err, err_num, load_num, load_stat, null_data;
INT  cmd_err_code, length;
ASCII cv_message;
STATIC INT n_words=0, n_save=0, word_cnt=0, stcmd_err_code=0;
STATIC UINT addr_0_2=0, mem_data_type=0, physical_page=0, class=0, sub_class=0;
STATIC ASCII class_def="            ",sub_class_def="            ",stcmd_sub_class="            ";

cv_word = GET_DN();
null_data = 0xFFFFFFFF;



IF (n_words < 1)   /* Check if in middle of multiple CV word */

    n_words = 0;
    word_cnt = 1;
    cmd_err_code = -1;
    sub_class_def = "            ";
    cv_message    = "            ";

    /* Extract Class Type and Sub Class Type from CV Monitor Channel */
    class = ((cv_word & 0xC000) >> 14);

    IF (class == 0)
        class_def = "REAL_TIME_CV";
        cv_message = "Command Sequence Number (14 LSBs) = 0x";
        byte_val = ((cv_word & 0x3000) >> 12);
        cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        byte_val = ((cv_word & 0x0F00) >> 8);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF
        byte_val = ((cv_word & 0x00F0) >> 4);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF
        byte_val = (cv_word & 0x000F);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF

    ELSEIF (class == 2)
        sub_class = ((cv_word & 0x3C00) >> 10);
        IF (sub_class == 0)
            class_def = "REPLY_MSG_CV";
            sub_class_def = "RPLY_MSG_BEG";
            cv_message = "Word 1, Type = ";
            mem_data_type = ((cv_word & 0x0200) >> 9);
            IF (mem_data_type == 0)
                cv_message = ASCII_APPEND (cv_message,"Memory, ");
            ELSEIF (mem_data_type == 1)
                cv_message = ASCII_APPEND (cv_message,"IPR, ");
            ENDIF
            n_words = (cv_word & 0x0007);
            n_save = n_words;
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_words));
            cv_message = ASCII_APPEND (cv_message," Words Follow, Physical Pg#=");
            physical_page = ((cv_word & 0x00F8) >> 3);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(physical_page));
            err = ((cv_word & 0x0100) >> 8);
            IF (err == 1)
                cmd_err_code = 64;
            ENDIF
            cv_message = ASCII_APPEND (cv_message,", E=");
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err));
        ELSEIF (sub_class == 1)
            class_def = "REPLY_MSG_CV";
            sub_class_def = "RPLY_MSG_END";
            cv_message = "Word ";
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_save+2));
            cv_message = ASCII_APPEND (cv_message,", Type = ");
            mem_data_type = ((cv_word & 0x0200) >> 9);
            IF (mem_data_type == 0)
                cv_message = ASCII_APPEND (cv_message,"Memory, ");
            ELSEIF (mem_data_type == 1)
                cv_message = ASCII_APPEND (cv_message,"IPR, ");
            ENDIF
            n_words = (cv_word & 0x0007);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_words));
            cv_message = ASCII_APPEND (cv_message," Words, Physical Pg#=");
            physical_page = ((cv_word & 0x00F8) >> 3);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(physical_page));
            cv_message = ASCII_APPEND (cv_message,", E=");
            err = ((cv_word & 0x0100) >> 8);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err));
            IF (err == 1)
                cmd_err_code = 64;
            ENDIF
            n_words = 0;
            n_save = 0;
        ELSEIF (sub_class == 2)
            class_def = "  R/T_S/S_CE";
            sub_class_def = "RT_S_CMD_ERR";
            cv_message = "Word 1, Command Sequence Number (10 LSBs) = ";
            script_add = (cv_word & 0x03FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 3)
            class_def = "STORED_SS_CV";
            sub_class_def = "ST_S_CMD_ERR";
            cv_message = "Word 1, Script Address (High 8 Bits)  = ";
            script_add = (cv_word & 0x00FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 4)
            class_def = "STORED_SS_CV";
            sub_class_def = "ST_S_CMD_ERR";
            cv_message = "Word 2, Script Address (Low 8 Bits)  = ";
            script_add = (cv_word & 0x00FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 5)
            IF (ASCII_COMP(class_def,"STORED_SS_CV") == 0)
                sub_class_def = "ST_S_CMD_ERR";
                cv_message = "Word 3, Last Command Error Code = 0x";
            ELSEIF (ASCII_COMP(class_def,"  R/T_S/S_CE") == 0)
                sub_class_def = "RT_S_CMD_ERR";
                cv_message = "Word 2, Last Command Error Code = 0x";
            ELSEIF (ASCII_COMP(class_def,"INTRNL_SS_CV") == 0)
                sub_class_def = "IN_S_CMD_ERR";
                cv_message = "Word 2, Last Command Error Code = 0x";
            ELSE
                sub_class_def = "CMD_ERR_CODE";
                cv_message = "Last Command Error Code = 0x";
            ENDIF
            cmd_err_code = (cv_word & 0x03FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((cmd_err_code & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 6)
            class_def = "MISSING_BLCK";
            sub_class_def = "MSNG_BLK_BGN";
            cv_message = "Word 1, Missing Blocks, Load# = ";
            load_num = ((cv_word & 0x00F0) >> 4);
            load_stat = ((cv_word & 0x0008) >> 3);
            n_words = (cv_word & 0x0007);
            n_save = n_words;
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(load_num));
            cv_message = ASCII_APPEND (cv_message,", S = ");
            IF (load_stat == 1)
                cv_message = ASCII_APPEND (cv_message,"1 (cmplt), ");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"0 (incmplt), ");
            ENDIF
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_words));
            cv_message = ASCII_APPEND (cv_message," Words Follow");
        ELSEIF (sub_class == 7)
            class_def = "MISSING_BLCK";
            sub_class_def = "MSNG_BLK_END";
            cv_message = "Word ";
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_save+2));
            cv_message = ", Missing Blocks, Load# = ";
            load_num = ((cv_word & 0x00F0) >> 4);
            load_stat = ((cv_word & 0x0008) >> 3);
            n_words = (cv_word & 0x0007);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(load_num));
            cv_message = ASCII_APPEND (cv_message,", Status = ");
            IF (load_stat = 1)
                cv_message = ASCII_APPEND (cv_message,"comp, ");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"incomp, ");
            ENDIF
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_words));
            cv_message = ASCII_APPEND (cv_message," Words");
            n_words = 0;
            n_save = 0;
        ELSEIF (sub_class == 8)
            class_def = "MEM_CHECKSUM";
            sub_class_def = "CHECKSUM_BGN";
            DERIVE("V-1024",null_data);
            DERIVE("V-1025",null_data);
            DERIVE("V-1026",null_data);
            cv_message = "Word 1, M=";
            err_num = ((cv_word & 0x0200) >> 9);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", R=");
            err_num = ((cv_word & 0x0100) >> 8);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", E=");
            err_num = ((cv_word & 0x0080) >> 7);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", S=");
            err_num = ((cv_word & 0x0040) >> 6);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", I=");
            err_num = ((cv_word & 0x0020) >> 5);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", C=");
            err_num = ((cv_word & 0x0010) >> 4);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            n_words = (cv_word & 0x0007);
            n_save = n_words;
        ELSEIF (sub_class == 9)
            class_def = "MEM_CHECKSUM";
            sub_class_def = "CHECKSUM_END";
            cv_message = "Word ";
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_save+2));
            cv_message = ASCII_APPEND (cv_message,", M=");
            err_num = ((cv_word & 0x0200) >> 9);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", R=");
            err_num = ((cv_word & 0x0100) >> 8);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", E=");
            err_num = ((cv_word & 0x0080) >> 7);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", S=");
            err_num = ((cv_word & 0x0040) >> 6);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", I=");
            err_num = ((cv_word & 0x0020) >> 5);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", C=");
            err_num = ((cv_word & 0x0010) >> 4);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            n_words = (cv_word & 0x0007);
            n_words = 0;
            n_save = 0;
        ELSEIF (sub_class == 10)
            class_def = "INTRNL_SS_CV";
            sub_class_def = "IN_S_CMD_ERR";
            cv_message = "Word 1, Software Subsystem ID = ";
            script_add = (cv_word & 0x03FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 11)
            class_def = " MINI_SEQ_CV";
            sub_class_def = "MINI_SEQ_BEG";
            cv_message = "Mini Sequence Begin CV Message";
        ELSEIF (sub_class == 12)
            class_def = " MINI_SEQ_CV";
            sub_class_def = "MINI_SEQ_END";
            cv_message = "Mini Sequence End CV Message, CMD Error Code = 0x";
            cmd_err_code = (cv_word & 0x003F);
            FOR (i=0; i<=3; i++)
                byte_val = ((cmd_err_code & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ENDIF

    ELSEIF (class == 1)
        class_def = "STORD_CMD_CV";
        IF ( ((cv_word & 0x2000) >> 13) == 0 )
            sub_class = ((cv_word & 0x1C00) >> 10);
            cmd_err_code = ((cv_word & 0x03F8) >> 3);
            addr_0_2 = ((cv_word & 0x0007) << 13);
            byte_val = (cv_word & 0x0007);
            cv_message = "Word 1 Address Bits 0..2 = 0x";
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
            stcmd_err_code = cmd_err_code;
            IF (sub_class == 0)
                sub_class_def = "BUS_CMD_EXEC";
            ELSEIF (sub_class == 1)
                sub_class_def = "PYL_CMD_EXEC";
            ELSEIF (sub_class == 2)
                sub_class_def = "SCRIPT_BEGIN";
            ELSEIF (sub_class == 3)
                sub_class_def = "  SCRIPT_END";
            ELSEIF (sub_class == 4)
                sub_class_def = "SCRP_END_ERR";
            ELSEIF (sub_class == 5)
                sub_class_def = "SCRIPT_ERROR";
            ELSEIF (sub_class == 6)
                sub_class_def = "SCRIPT_STOPD";
            ELSE
                sub_class_def = "   UNDEFINED";
            ENDIF
            stcmd_sub_class = sub_class_def;
            cv_message = ASCII_APPEND (cv_message,", CEC = 0x");
            FOR (i=0; i<=3; i++)
                byte_val = ((cmd_err_code & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSE
            cv_message = "Script Address Word 2 Bits 3..15 + Word 1 Bits 0..2 = 0x";
            script_add = ((cv_word & 0x1FFF) + addr_0_2);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
            cmd_err_code = stcmd_err_code;
            stcmd_err_code = -1;
            sub_class_def = stcmd_sub_class;
            stcmd_sub_class = "            ";
        ENDIF

    ELSEIF (class == 3)
        cv_message = "Command Sequence Number  (8 LSBs) = 0x";
        byte_val = ((cv_word & 0x00F0) >> 4);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF
        byte_val = (cv_word & 0x000F);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF
        cmd_err_code = ((cv_word & 0x3F00) >> 8);
        IF (cmd_err_code == 0)
            class_def = "     IDLE_CV";
            cmd_err_code = -1;
        ELSE
            class_def = " RT_ERROR_CV";
            cv_message = ASCII_APPEND (cv_message,", CEC = 0x");
            FOR (i=0; i<=3; i++)
                byte_val = ((cmd_err_code & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ENDIF
    ENDIF

ELSE

    n_words-- ;
    word_cnt++;
    cmd_err_code = -1;

    IF (class == 2 && sub_class == 0)
        sub_class_def = "RPLY_MSG_CNT";
        cv_message = "Word ";
        cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(word_cnt));
        IF (mem_data_type == 0 && word_cnt == 2)
            /* cv_message = ASCII_APPEND (cv_message,", Logical Memory Address = 0x"); (fixed 3-4-96) */
            cv_message = ASCII_APPEND (cv_message,", Memory Address = 0x");
            DERIVE("V-1027",null_data);
            DERIVE("V-1028",null_data);
            DERIVE("V-1029",null_data);
            DERIVE("V-1030",null_data);
        ELSEIF (mem_data_type == 1 && word_cnt == 2)
            cv_message = ASCII_APPEND (cv_message,", CIU/CIX Buffer Address = 0x");
        ELSEIF (mem_data_type == 0 && word_cnt > 2)
            cv_message = ASCII_APPEND (cv_message,", Memory Data = 0x");
            IF (word_cnt == 3)
                 DERIVE("V-1028",cv_word);
            ELSEIF (word_cnt == 4)
                 DERIVE("V-1029",cv_word);
            ELSEIF (word_cnt == 5)
                 DERIVE("V-1030",cv_word);
            ENDIF
        ELSEIF (mem_data_type == 1 && word_cnt > 2)
            cv_message = ASCII_APPEND (cv_message,", IPR Data = 0x");
        ENDIF
        IF (word_cnt == 2)
            /* script_add = ((cv_word & 0x07FF) + (physical_page << 11)); (fixed 3-4-96) */
            script_add = cv_word;
            DERIVE("V-1027",cv_word);
        ELSE
            script_add = cv_word;
        ENDIF
        FOR (i=0; i<=3; i++)
            byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
            IF (byte_val < 10)
                cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
            ELSEIF (byte_val == 10)
                cv_message = ASCII_APPEND (cv_message,"A");
            ELSEIF (byte_val == 11)
                cv_message = ASCII_APPEND (cv_message,"B");
            ELSEIF (byte_val == 12)
                cv_message = ASCII_APPEND (cv_message,"C");
            ELSEIF (byte_val == 13)
                cv_message = ASCII_APPEND (cv_message,"D");
            ELSEIF (byte_val == 14)
                cv_message = ASCII_APPEND (cv_message,"E");
            ELSEIF (byte_val == 15)
                cv_message = ASCII_APPEND (cv_message,"F");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"?");
            ENDIF
        ENDFOR

    ELSEIF (class == 2 && sub_class == 6)
        sub_class_def = "MSNG_BLK_CNT";
        cv_message = "Word ";
        cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(word_cnt));
        IF (word_cnt == 2)
            cv_message = ASCII_APPEND (cv_message,", Table Address = 0x");
        ELSE
            cv_message = ASCII_APPEND (cv_message,", Scoreboard Word ");
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(word_cnt - 2));
            cv_message = ASCII_APPEND (cv_message," = 0x");
        ENDIF
        script_add = cv_word;
        FOR (i=0; i<=3; i++)
            byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
            IF (byte_val < 10)
                cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
            ELSEIF (byte_val == 10)
                cv_message = ASCII_APPEND (cv_message,"A");
            ELSEIF (byte_val == 11)
                cv_message = ASCII_APPEND (cv_message,"B");
            ELSEIF (byte_val == 12)
                cv_message = ASCII_APPEND (cv_message,"C");
            ELSEIF (byte_val == 13)
                cv_message = ASCII_APPEND (cv_message,"D");
            ELSEIF (byte_val == 14)
                cv_message = ASCII_APPEND (cv_message,"E");
            ELSEIF (byte_val == 15)
                cv_message = ASCII_APPEND (cv_message,"F");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"?");
            ENDIF
        ENDFOR
    ELSEIF (class == 2 && sub_class == 8)
        sub_class_def = "CHECKSUM_CNT";
        cv_message = "Word ";
        cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(word_cnt));
        IF (word_cnt == 2)
            cv_message = ASCII_APPEND (cv_message,", Checksum Value = 0x");
            DERIVE("V-1024",cv_word);
        ELSEIF (word_cnt == 3)
            cv_message = ASCII_APPEND (cv_message,", Physical Memory Address (MHS) = 0x");
            DERIVE("V-1025",cv_word);
        ELSEIF (word_cnt == 4)
            cv_message = ASCII_APPEND (cv_message,", Physical Memory Address (LHS) = 0x");
            DERIVE("V-1026",cv_word);
        ENDIF
        script_add = cv_word;
        FOR (i=0; i<=3; i++)
            byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
            IF (byte_val < 10)
                cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
            ELSEIF (byte_val == 10)
                cv_message = ASCII_APPEND (cv_message,"A");
            ELSEIF (byte_val == 11)
                cv_message = ASCII_APPEND (cv_message,"B");
            ELSEIF (byte_val == 12)
                cv_message = ASCII_APPEND (cv_message,"C");
            ELSEIF (byte_val == 13)
                cv_message = ASCII_APPEND (cv_message,"D");
            ELSEIF (byte_val == 14)
                cv_message = ASCII_APPEND (cv_message,"E");
            ELSEIF (byte_val == 15)
                cv_message = ASCII_APPEND (cv_message,"F");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"?");
            ENDIF
        ENDFOR
    ENDIF

ENDIF


DERIVE("V-1011",class_def);
DERIVE("V-1013",sub_class_def);

/* Pad cv_message with blanks */
length = ASCII_LENGTH(cv_message);
FOR (i=length; i<=61; i=i+12)
    cv_message = ASCII_APPEND (cv_message,"            ");
ENDFOR

DERIVE("V-1015",ASCII_SLICE(cv_message, 0,12));
DERIVE("V-1016",ASCII_SLICE(cv_message,12,12));
DERIVE("V-1017",ASCII_SLICE(cv_message,24,12));
DERIVE("V-1018",ASCII_SLICE(cv_message,36,12));
DERIVE("V-1019",ASCII_SLICE(cv_message,48,12));
IF (cmd_err_code < 0)
    DERIVE("V-1021",0);
    DERIVE("V-1022","      CMD_OK");
ELSE
    DERIVE("V-1021",cmd_err_code);
    IF (cmd_err_code >= 0 && cmd_err_code < 16)
        IF (cmd_err_code == 0)
            DERIVE("V-1022","      CMD_OK");
        ELSEIF (cmd_err_code == 1)
            DERIVE("V-1022"," SEQ_NUM_ERR");
        ELSEIF (cmd_err_code == 2)
            DERIVE("V-1022","  UPLINK_ERR");
        ELSEIF (cmd_err_code == 3)
            DERIVE("V-1022","BLCK_CRC_ERR");
        ELSEIF (cmd_err_code == 4)
            DERIVE("V-1022","UNEXP_CMDfrm");
        ELSEIF (cmd_err_code == 5)
            DERIVE("V-1022","CIU_CMD_EXPT");
        ELSEIF (cmd_err_code == 6)
            DERIVE("V-1022","ILLGL_DATAfr");
        ELSEIF (cmd_err_code == 7)
            DERIVE("V-1022","UNEXP_DATAfr");
        ELSEIF (cmd_err_code == 8)
            DERIVE("V-1022","2MANY_DATAfr");
        ELSEIF (cmd_err_code == 9)
            DERIVE("V-1022","U/L_STAT_ERR");
        ELSEIF (cmd_err_code == 10)
            DERIVE("V-1022","CIU_CMD_REJD");
        ELSEIF (cmd_err_code == 11)
            DERIVE("V-1022","INVL_CMD_TYP");
        ELSEIF (cmd_err_code == 12)
            DERIVE("V-1022","INVL_CMD_NUM");
        ELSEIF (cmd_err_code == 14)
            DERIVE("V-1022","INVL_SUBTYPE");
        ELSEIF (cmd_err_code == 15)
            DERIVE("V-1022","INVL_SUB_NUM");
        ELSE
            DERIVE("V-1022","*NOT_DEFINED");
        ENDIF
    ELSEIF (cmd_err_code >= 16 && cmd_err_code < 32)
        IF (cmd_err_code == 16)
            DERIVE("V-1022","INSUF_DATA_W");
        ELSEIF (cmd_err_code == 17)
            DERIVE("V-1022","EXCES_DATA_W");
        ELSEIF (cmd_err_code == 18)
            DERIVE("V-1022"," S/S_Q_ERROR");
        ELSEIF (cmd_err_code == 19)
            DERIVE("V-1022","CMD_NOT_ACTV");
        ELSEIF (cmd_err_code == 20)
            DERIVE("V-1022","StrCMD!ALLOW");
        ELSEIF (cmd_err_code == 21)
            DERIVE("V-1022","PLS_DIS_Q_ER");
        ELSEIF (cmd_err_code == 22)
            DERIVE("V-1022","INV_WORD_CNT");
        ELSEIF (cmd_err_code == 23)
            DERIVE("V-1022","INV_LOAD_ADD");
        ELSEIF (cmd_err_code == 24)
            DERIVE("V-1022","S/S_CMD_REJC");
        ELSEIF (cmd_err_code == 25)
            DERIVE("V-1022","ILGL_CMD_SRC");
        ELSEIF (cmd_err_code == 26)
            DERIVE("V-1022","ILGL_BLK_NUM");
        ELSEIF (cmd_err_code == 27)
            DERIVE("V-1022","Mload_NO_PRG");
        ELSEIF (cmd_err_code == 28)
            DERIVE("V-1022","Mload_INCMPL");
        ELSEIF (cmd_err_code == 30)
            DERIVE("V-1022","SERIAL_IO_TO");
        ELSEIF (cmd_err_code == 31)
            DERIVE("V-1022","INVL_BUF_IND");
        ELSE
            DERIVE("V-1022","*NOT_DEFINED");
        ENDIF
    ELSEIF (cmd_err_code >= 32 && cmd_err_code < 48)
        IF (cmd_err_code == 32)
            DERIVE("V-1022","StrdCMD2LATE");
        ELSEIF (cmd_err_code == 33)
            DERIVE("V-1022","ScrpBUF_FAIL");
        ELSEIF (cmd_err_code == 34)
            DERIVE("V-1022","FineTimeExpc");
        ELSEIF (cmd_err_code == 35)
            DERIVE("V-1022","ILLEG_DW_CNT");
        ELSEIF (cmd_err_code == 36)
            DERIVE("V-1022","ILLEG_ADDRES");
        ELSEIF (cmd_err_code == 37)
            DERIVE("V-1022","TimeTag_EXPC");
        ELSEIF (cmd_err_code == 38)
            DERIVE("V-1022","ILLEGwordCNT");
        ELSEIF (cmd_err_code == 39)
            DERIVE("V-1022","SCRIPT!FOUND");
        ELSEIF (cmd_err_code == 40)
            DERIVE("V-1022","SCRPTalrdyAC");
        ELSEIF (cmd_err_code == 41)
            DERIVE("V-1022"," LOADnotACTV");
        ELSEIF (cmd_err_code == 42)
            DERIVE("V-1022","MODEtag!EXPC");
        ELSEIF (cmd_err_code == 43)
            DERIVE("V-1022","MODEtagEXPEC");
        ELSEIF (cmd_err_code == 44)
            DERIVE("V-1022","INVL_ARGMENT");
        ELSEIF (cmd_err_code == 45)
            DERIVE("V-1022","2MANYactSCRT");
        ELSEIF (cmd_err_code == 46)
            DERIVE("V-1022","EPHMloadWARN");
        ELSEIF (cmd_err_code == 47)
            DERIVE("V-1022","STRXloadWARN");
        ELSE
            DERIVE("V-1022","*NOT_DEFINED");
        ENDIF
    ENDIF
    IF (cmd_err_code >= 48 )
        IF (cmd_err_code == 48)
            DERIVE("V-1022","CNTGNCY_MODE");
        ELSEIF (cmd_err_code == 49)
            DERIVE("V-1022","ACTscriptRNG");
        ELSEIF (cmd_err_code == 50)
            DERIVE("V-1022","PWRcmdREJECT");
        ELSEIF (cmd_err_code == 51)
            DERIVE("V-1022","INVredmanDEV");
        ELSEIF (cmd_err_code == 52)
            DERIVE("V-1022","    CENSORED");
        ELSEIF (cmd_err_code == 53)
            DERIVE("V-1022","MiniSeq_STOP");
        ELSEIF (cmd_err_code == 62)
            DERIVE("V-1022"," REPLY_WORDS");
        ELSEIF (cmd_err_code == 63)
            DERIVE("V-1022","CV_Q_OVERFLW");
        ELSEIF (cmd_err_code == 64 )
            DERIVE("V-1022","MEM_READ_ERR");
        ELSE
            DERIVE("V-1022","*NOT_DEFINED");
        ENDIF
    ENDIF

ENDIF


ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-1115 "POBimgCIU246" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 05-08-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3001
Description:            Uplink Processor 1 Indicator
Mnemonic:               UPLNK_PROC_1
Subsystem:              TLCM
Data_Type:              STATUS
States:                 BOTH,CDU1,CDU2,BOTH

Derived Channel:        V-3002
Description:            Uplink Processor 2 Indicator
Mnemonic:               UPLNK_PROC_2
Subsystem:              TLCM
Data_Type:              STATUS
States:                 BOTH,CDU1,CDU2,BOTH



*/

CHILD = "V-3001" PARENTS = "F-1115";
CHILD = "V-3002" PARENTS = "F-1115";

FUNCT CHAN = "F-1115"

DERIVE ("V-3001", ((GET_DN() & 0x1000) >> 12) + ((GET_DN() & 0x0800) >> 10));
DERIVE ("V-3002", ((GET_DN() & 0x0010) >>  4) + ((GET_DN() & 0x0001) <<  1));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-1414 "SCP_FRAME_ID" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 05-15-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-1414
Description:            QUERY SCP TELEMETRY SYNC FLAG (IDEOSYCRACY WITH CHANNEL ORDER BETWEEN RT/QUERY)
Mnemonic:               QRY_SCP_SYNC
Subsystem:              CDH
Data_Type:              STATUS
States:                 Cannot_Detrm,IN_SYNC,NO_SYNC

Derived Channel:        V-1415
Description:            REAL TIME SCP TELEMETRY SYNC FLAG
Mnemonic:               RT_SCP_SYNC
Subsystem:              CDH
Data_Type:              STATUS
States:                 Cannot_Detrm,IN_SYNC,NO_SYNC

*/

CHILD = "V-1414" PARENTS = "H-0025""H-0026""C-0002""F-1414";

FUNCT CHAN = "F-1414"

UINT queryID,currID,mode,sync,edffr,cscp;

IF (DN_VALID("H-0025")==0 && DN_VALID("H-0026")==0 && DN_VALID("C-0002")==0 && DN_VALID("F-1414")==0)

    currID = GET_DN();
    mode = GET_LAD_DN("H-0025");
    edffr = GET_LAD_DN("H-0026");
    cscp = GET_LAD_DN("C-0002");
    sync = 0;

    IF (mode==0 OR mode==1)    /*emerg or missn*/
      sync=sync+1;
      IF ((edffr != currID) AND (edffr != currID+32))
        sync=sync+1;
      ENDIF
    ELSEIF (mode==2)              /*engineering*/
      IF (cscp == 1)  /*SCP1 ctl*/
        sync=sync+1;
        IF (edffr != (currID*2))
          sync=sync+1;
        ENDIF
      ELSEIF (cscp == 0)  /*SCP2 ctl*/
        sync=sync+1;
        IF (edffr != (currID*2 + 1))
          sync=sync+1;
        ENDIF
      ENDIF
    ENDIF

    DERIVE("V-1415",sync);


    queryID = GET_LAD_DN("F-1414");
    sync = 0;

    IF (mode==0 OR mode==1)    /*emerg or missn*/
      sync=sync+1;
      IF ((edffr != queryID) AND (edffr != queryID+32))
        sync=sync+1;
      ENDIF
    ELSEIF (mode==2)              /*engineering*/
      IF (cscp == 1)  /*SCP1 ctl*/
        sync=sync+1;
        IF (edffr != (queryID*2 + 1))
          sync=sync+1;
        ENDIF
      ELSEIF (cscp == 0)  /*SCP2 ctl*/
        sync=sync+1;
        IF (queryID==31)
            queryID = -1;
        ENDIF
        IF (edffr != (queryID*2 + 2))
          sync=sync+1;
        ENDIF
      ENDIF
    ENDIF

    DERIVE("V-1414",sync);

ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-2001 "BAT1_ASOC" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2205
Description:            Battery 1 State of Charge Based battery 1 ASOC (in coulombs (amp-sec))
Mnemonic:               BAT1_PerASOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "V-2205" PARENTS = "F-2001";

FUNCT CHAN = "F-2001"

/* Divide by 720.00 to get percent sate of chage (full battery =72000 coulombs) */
DERIVE ("V-2205", GET_EU() / 720.00);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-2002 "BAT1_TSOC" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2206
Description:            Battery 1 State of Charge Based battery 1 TSOC (in coulombs (amp-sec))
Mnemonic:               BAT1_PerTSOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "V-2206" PARENTS = "F-2002";

FUNCT CHAN = "F-2002"

/* Divide by 720.00 to get percent sate of chage (full battery =72000 coulombs) */
DERIVE ("V-2206", GET_EU() / 720.00);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-2051 "BAT2_ASOC" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2207
Description:            Battery 2 State of Charge Based battery 2 ASOC (in coulombs (amp-sec))
Mnemonic:               BAT2_PerASOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "V-2207" PARENTS = "F-2051";

FUNCT CHAN = "F-2051"

/* Divide by 720.00 to get percent sate of chage (full battery =72000 coulombs) */
DERIVE ("V-2207", GET_EU() / 720.00);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * F-2052 "BAT2_TSOC" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2208
Description:            Battery 2 State of Charge Based battery 2 TSOC (in coulombs (amp-sec))
Mnemonic:               BAT2_PerTSOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "V-2208" PARENTS = "F-2052";

FUNCT CHAN = "F-2052"

/* Divide by 720.00 to get percent sate of chage (full battery =72000 coulombs) */
DERIVE ("V-2208", GET_EU() / 720.00);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0000 "AACS_STATE" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 04-05-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0005
Description:            Current Actuator Select
Mnemonic:               CRNT_ACT_SEL
Subsystem:              AACS
Data_Type:              STATUS
States:                 RWA_SELECTED,REA_SELECTED

Derived Channel:        U-0006
Description:            PID Torque Current Units
Mnemonic:               PIDTRQ_UNITS
Subsystem:              AACS
Data_Type:              ASCII
Units:


*/

CHILD = "U-0005" PARENTS = "N-0000";
CHILD = "U-0006" PARENTS = "N-0000";

FUNCT CHAN = "N-0000"


IF (DN_VALID("N-0901") == 0 && DN_VALID("N-0902") == 0)
    IF (GET_DN() > 2 )
        DERIVE ("U-0005",GET_LAD_DN("N-0901"));
        IF (GET_LAD_DN("N-0901") == 0)
             DERIVE ("U-0006","Nm");
        ELSE
             DERIVE ("U-0006","sec");
        ENDIF
    ELSE
        DERIVE ("U-0005",GET_LAD_DN("N-0902"));
        IF (GET_LAD_DN("N-0902") == 0)
             DERIVE ("U-0006","Nm");
        ELSE
             DERIVE ("U-0006","sec");
        ENDIF
    ENDIF
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0040 "CSA_AS_1" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0150
Description:            1st 10hz Reading of S Accel Data
Mnemonic:               S_ACCEL_1
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        U-0151
Description:            1st 10hz Reading of S Accel Data
Mnemonic:               S_ACC_1_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "U-0150" PARENTS = "N-0040""N-0648";
CHILD = "U-0151" PARENTS = "N-0040""N-0648";

FUNCT CHAN = "N-0040"

INT counts;

IF (DN_VALID("N-0648") == 0)
    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0150",(10.0 * 3.334102E-04 * (FLT)counts) + 0.0205029 + 0.0000153);
        DERIVE ("U-0151",counts);
    ELSE
        DERIVE ("U-0150", 0.0);
        DERIVE ("U-0151", 0);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0051 "CSAwdNONZERO" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-4-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0001
Description:            CSA Slit Crossing 6 Bits
Mnemonic:               CSAslit_BITS
Subsystem:              AACS
Data_Type:              UNSIGNED
Units:

Derived Channel:        U-0002
Description:            CSA Slit Crossing Time
Mnemonic:               CSAslit_TIME
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mSEC

Derived Channel:        U-0003
Description:            CSA Slit Crossing ID
Mnemonic:               CSAslit_XING
Subsystem:              AACS
Data_Type:              ASCII
Units:

*/

CHILD = "U-0001" PARENTS = "N-0051""N-0210";
CHILD = "U-0002" PARENTS = "N-0051""N-0210";
CHILD = "U-0003" PARENTS = "N-0051""N-0210";

FUNCT CHAN = "N-0051"

UINT csa_wrd_nz,csa_6bits;
FLT  csa_time;

csa_wrd_nz = GET_DN();

IF (DN_VALID("N-0210") == 0)
    /* Check Bit 8 of IMU Status Word (Gyro/Accel Format) If 0  */
    IF (((GET_LAD_DN("N-0210") & 0x0080) >> 7) == 0)
        /* Extract 6 Slit Bits From CSAwrdNONZERO */
        csa_6bits = ((csa_wrd_nz & 0xFC00) >> 10);
        /* Extract 8 Time Bits From CSAwrdNONZERO and convert to mSec */
        csa_time = (csa_wrd_nz & 0x00FF) * 0.625;
    ELSE /* Accel Format Selected */
        csa_6bits = 0;
        csa_time = 0.0;
    ENDIF
ELSE /* IMU Status Word Invalid */
    csa_6bits = 0;
    csa_time = 0.0;
ENDIF

DERIVE ("U-0001",csa_6bits);
DERIVE ("U-0002",csa_time);
IF     (csa_6bits == 31)
    DERIVE("U-0003","     SLIT_A2");
ELSEIF (csa_6bits == 47)
    DERIVE("U-0003","     SLIT_A1");
ELSEIF (csa_6bits == 55)
    DERIVE("U-0003","     SLIT_B3");
ELSEIF (csa_6bits == 59)
    DERIVE("U-0003","     SLIT_B2");
ELSEIF (csa_6bits == 61)
    DERIVE("U-0003","     SLIT_B1");
ELSEIF (csa_6bits == 62)
    DERIVE("U-0003","     SLIT_A3");
ELSE
    DERIVE("U-0003","     INVALID");
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0110 "GY_X3_AX_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0101
Description:            Gyro X1/X3 Derived Counts
Mnemonic:               GY_X1_X3_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

*/

CHILD = "U-0101" PARENTS = "N-0110";

FUNCT CHAN = "N-0110"

IF (GET_DN() > 32767)
     DERIVE ("U-0101",GET_DN() - 65536);
ELSE
     DERIVE ("U-0101",GET_DN());
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0120 "GY_X3_AX_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0102
Description:            Gyro X3/AX Derived Counts
Mnemonic:               GY_X3_AX_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0152
Description:            1st 10hz Reading of X Accel Data
Mnemonic:               X_ACCEL_1
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        U-0153
Description:            1st 10hz Reading of X Accel Data
Mnemonic:               X_ACC_1_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "U-0102" PARENTS = "N-0120";
CHILD = "U-0152" PARENTS = "N-0120""N-0648""F-0001";
CHILD = "U-0153" PARENTS = "N-0120""N-0648""F-0001";

FUNCT CHAN = "N-0120"

INT counts;

IF (GET_DN() > 32767)
     DERIVE ("U-0102",GET_DN() - 65536);
ELSE
     DERIVE ("U-0102",GET_DN());
ENDIF

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0001") == 0)
    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0152",(10.0 * 3.356370E-04 * (FLT)counts) - 0.0170694 - (GET_LAD_EU("F-0001") * 10.0));
        DERIVE ("U-0153",counts);
    ELSE
        DERIVE ("U-0152", 0.0);
        DERIVE ("U-0153", 0);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0129 "GY_X3_AX_10" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0230
Description:            1st 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_01_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0231
Description:            2nd 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_02_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0232
Description:            3rd 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_03_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0233
Description:            4th 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_04_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0234
Description:            5th 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_05_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0235
Description:            6th 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_06_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0236
Description:            7th 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_07_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0237
Description:            8th 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_08_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0238
Description:            9th 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_09_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0239
Description:            10th 10hz Reading of Gyro X3 AX Counts
Mnemonic:               GyX3AX_10_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0156
Description:            10 Sample X Accel Average
Mnemonic:               X_ACC_AVE_10
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0156
Description:            10 Sample X Accel Average
Mnemonic:               X_ACC_AVE_10
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

*/

CHILD = "U-0230" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0231" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0232" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0233" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0234" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0235" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0236" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0237" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0238" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0239" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129";
CHILD = "U-0156" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129""N-648""F-1";
CHILD = "V-0156" PARENTS = "N-120""N-121""N-122""N-123""N-124""N-125""N-126""N-127""N-128""N-129""N-648""F-1";

FUNCT CHAN = "N-0129"

INT counts,total_counts;
FLT acc_ave;


IF (DN_VALID("N-0121") == 0)

    counts = GET_LAD_DN("N-0120");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0230",counts);
    total_counts = counts;

    counts = GET_LAD_DN("N-0121");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0231",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0122");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0232",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0123");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0233",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0124");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0234",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0125");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0235",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0126");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0236",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0127");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0237",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0128");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0238",counts);
    total_counts = total_counts + counts;

    counts = GET_DN();
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0239",counts);
    total_counts = total_counts + counts;

ENDIF

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0001") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        acc_ave = (3.356370E-04 * (FLT)total_counts) - 0.0170694 - (GET_LAD_EU("F-0001") * 10.0);
        DERIVE ("U-0156",acc_ave);
        DERIVE ("V-0156",acc_ave);
    ELSE
        acc_ave = 0.0;
        DERIVE ("U-0156", 0.0);
        DERIVE ("V-0156", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0130 "GY_Y1_Y2_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0103
Description:            Gyro Y1/Y2 Derived Counts
Mnemonic:               GY_Y1_Y2_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

*/

CHILD = "U-0103" PARENTS = "N-0130";

FUNCT CHAN = "N-0130"

IF (GET_DN() > 32767)
     DERIVE ("U-0103",GET_DN() - 65536);
ELSE
     DERIVE ("U-0103",GET_DN());
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0139 "GY_Y1_Y2_10" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0220
Description:            1st 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_01_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0221
Description:            2nd 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_02_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0222
Description:            3rd 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_03_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0223
Description:            4th 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_04_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0224
Description:            5th 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_05_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0225
Description:            6th 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_06_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0226
Description:            7th 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_07_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0227
Description:            8th 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_08_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0228
Description:            9th 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_09_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0229
Description:            10th 10hz Reading of Gyro Y1 Y2 Counts
Mnemonic:               GyY1Y2_10_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "U-0220" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0221" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0222" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0223" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0224" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0225" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0226" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0227" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0228" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";
CHILD = "U-0229" PARENTS = "N-130""N-131""N-132""N-133""N-134""N-135""N-136""N-137""N-138""N-139";

FUNCT CHAN = "N-0139"

INT counts;

IF (DN_VALID("N-0131") == 0)

    counts = GET_LAD_DN("N-0130");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0220",counts);

    counts = GET_LAD_DN("N-0131");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0221",counts);

    counts = GET_LAD_DN("N-0132");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0222",counts);

    counts = GET_LAD_DN("N-0133");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0223",counts);

    counts = GET_LAD_DN("N-0134");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0224",counts);

    counts = GET_LAD_DN("N-0135");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0225",counts);

    counts = GET_LAD_DN("N-0136");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0226",counts);

    counts = GET_LAD_DN("N-0137");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0227",counts);

    counts = GET_LAD_DN("N-0138");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0228",counts);

    counts = GET_DN();
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0229",counts);

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0140 "GY_Y2_AY_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0104
Description:            Gyro Y2/AY Derived Counts
Mnemonic:               GY_Y2_AY_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0154
Description:            1st 10hz Reading of Y Accel Data
Mnemonic:               Y_ACCEL_1
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        U-0155
Description:            1st 10hz Reading of Y Accel Data
Mnemonic:               Y_ACC_1_CNTS
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

*/

CHILD = "U-0104" PARENTS = "N-0140";
CHILD = "U-0154" PARENTS = "N-0140""N-0648";
CHILD = "U-0155" PARENTS = "N-0140""N-0648";

FUNCT CHAN = "N-0140"

INT counts;

IF (GET_DN() > 32767)
     DERIVE ("U-0104",GET_DN() - 65536);
ELSE
     DERIVE ("U-0104",GET_DN());
ENDIF

IF (DN_VALID("N-0648") == 0)
    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0154",(10.0 * 3.343948E-04 * (FLT)counts) - 0.0322749 - 0.0000305);
        DERIVE ("U-0155",counts);
    ELSE
        DERIVE ("U-0154", 0.0);
        DERIVE ("U-0155", 0);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0150 "GY_Z2_Z3_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0105
Description:            Gyro Z2/Z3 Derived Counts
Mnemonic:               GY_Z2_Z3_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

*/

CHILD = "U-0105" PARENTS = "N-0150";

FUNCT CHAN = "N-0150"

IF (GET_DN() > 32767)
     DERIVE ("U-0105",GET_DN() - 65536);
ELSE
     DERIVE ("U-0105",GET_DN());
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0160 "GY_Z3_AZ_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0106
Description:            Gyro Z3/AZ Derived Counts
Mnemonic:               GY_Z3_AZ_CNT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0160
Description:            1st 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_1
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

*/

CHILD = "U-0106" PARENTS = "N-0160";
CHILD = "U-0160" PARENTS = "N-0160""N-0648""F-0003";

FUNCT CHAN = "N-0160"

INT counts;
STATIC INT cycles=0;

/* Note - SCP Frame built in 1st 10hz, for accel
          data to be time synchronized use
          GET_LAD_DN only for the 1st gyro accel value
*/
IF (cycles == 0)
    cycles = 1;
    RETURN;
ENDIF

IF (DN_VALID("N-0160") == 0)
    IF (GET_LAD_DN("N-0160") > 32767)
         counts = GET_LAD_DN("N-0160") - 65536;
    ELSE
         counts = GET_LAD_DN("N-0160");
    ENDIF
ENDIF

DERIVE ("U-0106",counts);

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)
    IF(GET_LAD_DN("N-0648") == 1)
        DERIVE ("U-0160",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0160", 0.0);
    ENDIF
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0161 "GY_Z3_AZ_2" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0161
Description:            2nd 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_2
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mm/sec

*/

CHILD = "U-0161" PARENTS = "N-0161""N-0648""F-0003";

FUNCT CHAN = "N-0161"

INT counts;

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0161",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0161", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0162 "GY_Z3_AZ_3" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0162
Description:            3rd 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_3
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mm/sec


*/

CHILD = "U-0162" PARENTS = "N-0162""N-0648""F-0003";

FUNCT CHAN = "N-0162"

INT counts;

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0162",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0162", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0163 "GY_Z3_AZ_4" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0163
Description:            4th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_4
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mm/sec

*/

CHILD = "U-0163" PARENTS = "N-0163""N-0648""F-0003";

FUNCT CHAN = "N-0163"

INT counts;

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0163",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0163", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0164 "GY_Z3_AZ_5" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0164
Description:            5th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_5
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mm/sec

*/

CHILD = "U-0164" PARENTS = "N-0164""N-0648""F-0003";

FUNCT CHAN = "N-0164"

INT counts;

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0164",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0164", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0165 "GY_Z3_AZ_6" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0165
Description:            6th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_6
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mm/sec

*/

CHILD = "U-0165" PARENTS = "N-0165""N-0648""F-0003";

FUNCT CHAN = "N-0165"

INT counts;

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0165",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0165", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0166 "GY_Z3_AZ_7" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0166
Description:            7th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_7
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mm/sec

*/

CHILD = "U-0166" PARENTS = "N-0166""N-0648""F-0003";

FUNCT CHAN = "N-0166"

INT counts;

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0166",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0166", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0167 "GY_Z3_AZ_8" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0167
Description:            8th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_8
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mm/sec

*/

CHILD = "U-0167" PARENTS = "N-0167""N-0648""F-0003";

FUNCT CHAN = "N-0167"

INT counts;

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0167",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0167", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0168 "GY_Z3_AZ_9" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0168
Description:            9th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_9
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  mm/sec

*/

CHILD = "U-0168" PARENTS = "N-0168""N-0648""F-0003";

FUNCT CHAN = "N-0168"

INT counts;

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0168",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0168", 0.0);
    ENDIF

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-0169 "GY_Z3_AZ_10" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 03-29-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0169
Description:            10th 10hz Reading of Z Accel Data
Mnemonic:               Z_ACCEL_10
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        U-0170
Description:            1st 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_01_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0171
Description:            2nd 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_02_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0172
Description:            3rd 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_03_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0173
Description:            4th 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_04_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0174
Description:            5th 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_05_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0175
Description:            6th 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_06_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0176
Description:            7th 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_07_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0177
Description:            8th 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_08_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0178
Description:            9th 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_09_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0179
Description:            10th 10hz Reading of Gyro Z3 AZ Counts
Mnemonic:               GyZ3AZ_10_CT
Subsystem:              AACS
Data_Type:              SIGNED
Units:                  counts

Derived Channel:        U-0180
Description:            10 Sample Z Accel Average
Mnemonic:               Z_ACC_AVE_10
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0180
Description:            10 Sample Z Accel Average
Mnemonic:               Z_ACC_AVE_10
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        U-0181
Description:            10 Sample Z Accel Average Peak
Mnemonic:               Z_ACC_PK_10
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

Derived Channel:        V-0181
Description:            10 Sample Z Accel Average Peak
Mnemonic:               Z_ACC_PK_10
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  m/s^2

*/

CHILD = "U-0169" PARENTS = "N-0169""N-0648";
CHILD = "U-0170" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0171" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0172" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0173" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0174" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0175" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0176" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0177" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0178" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0179" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169";
CHILD = "U-0180" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169""N-0648""F-0003";
CHILD = "V-0180" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169""N-0648""F-0003";
CHILD = "U-0181" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169""N-0648""F-0003";
CHILD = "V-0181" PARENTS = "N-160""N-161""N-162""N-163""N-164""N-165""N-166""N-167""N-168""N-169""N-0648""F-0003";

FUNCT CHAN = "N-0169"

INT counts,total_counts;
FLT acc_ave;
STATIC FLT peak_acc=-1.0;


total_counts = 0;

IF (DN_VALID("N-0161") == 0)

    counts = GET_LAD_DN("N-0160");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0170",counts);
    total_counts = counts;

    counts = GET_LAD_DN("N-0161");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0171",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0162");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0172",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0163");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0173",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0164");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0174",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0165");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0175",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0166");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0176",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0167");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0177",counts);
    total_counts = total_counts + counts;

    counts = GET_LAD_DN("N-0168");
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0178",counts);
    total_counts = total_counts + counts;

    counts = GET_DN();
    IF (counts > 32767)
         counts = counts - 65536;
    ENDIF
    DERIVE ("U-0179",counts);
    total_counts = total_counts + counts;

ENDIF

IF (DN_VALID("N-0648") == 0 && DN_VALID("F-0003") == 0)

    IF(GET_LAD_DN("N-0648") == 1)
        acc_ave = (3.287629E-04 * (FLT)total_counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0);
        DERIVE ("U-0180",acc_ave);
        DERIVE ("V-0180",acc_ave);
    ELSE
        acc_ave = 0.0;
        DERIVE ("U-0180", 0.0);
        DERIVE ("V-0180", 0.0);
    ENDIF

    /* chech for lad flush and reset peak accel */
    IF (DN_VALID("V-0181") != 0)
        peak_acc = -1.0;
    ENDIF

    /* find peak acceleration */
    IF (acc_ave > peak_acc)
        DERIVE ("V-0181",acc_ave);
        DERIVE ("U-0181",acc_ave);
        peak_acc = acc_ave;
    ENDIF

    IF(GET_LAD_DN("N-0648") == 1)
        IF (GET_DN() > 32767)
             counts = GET_DN() - 65536;
        ELSE
             counts = GET_DN();
        ENDIF
        DERIVE ("U-0169",(10.0 * 3.287629E-04 * (FLT)counts) - 0.0177561 - (GET_LAD_EU("F-0003") * 10.0));
    ELSE
        DERIVE ("U-0169", 0.0);
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0190 "HGA_AZ_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0080
Description:            HGA AZIMUTH FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               HGA_AZang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0080" PARENTS = "N-0190";

FUNCT CHAN = "N-0190"

/* Derive flight software computed control frame position in degrees */
DERIVE ("U-0080",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0192 "HGA_AZ_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0070
Description:            HGA AZIMUTH POSITION (CONTROL FRAME)
Mnemonic:               HGA_AZpos_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0070" PARENTS = "N-0192";

FUNCT CHAN = "N-0192"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * -0.02197266) + 180.0;
IF (cf_pos < -100.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 260.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("U-0070", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0195 "HGA_EL_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0081
Description:            HGA ELEVATION FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               HGA_ELang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0081" PARENTS = "N-0195";

FUNCT CHAN = "N-0195"

/* Derive flight software computed control frame position in degrees */
DERIVE ("U-0081",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0197 "HGA_EL_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0071
Description:            HGA ELEVATION POSITION (CONTROL FRAME)
Mnemonic:               HGA_ELpos_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0071" PARENTS = "N-0197";

FUNCT CHAN = "N-0197"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * -0.02197266) - 95.0;
IF (cf_pos < -180.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 180.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("U-0071", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0200 "HGA_STATS" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-21-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-2070
Description:            HGA GDE Estimated Power
Mnemonic:               HGA_GDE_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        U-2071
Description:            HGA Motors Estimated Power
Mnemonic:               HGA_MTR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        U-2072
Description:            HGA Encoder Estimated Power
Mnemonic:               HGA_ENC_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "U-2070" PARENTS = "N-0200""N-0201""N-0192""N-0197""N-0621""N-0623""N-0629""N-0631";
CHILD = "U-2071" PARENTS = "N-0200""N-0201""N-0192""N-0197""N-0621""N-0623""N-0629""N-0631";
CHILD = "U-2072" PARENTS = "N-0200""N-0201""N-0192""N-0197""N-0621""N-0623""N-0629""N-0631";

FUNCT CHAN = "N-0200"

FLT HGA_GDE_PWR, HGA_MTR_PWR, HGA_ENC_PWR;

/* Check GDE telemetry validity */
IF ((DN_VALID("N-0631") != 0) || (DN_VALID("N-0192") != 0) || (DN_VALID("N-0197") != 0) || (DN_VALID("N-0201") != 0))
	RETURN;
ENDIF

/* Check Power Status of GDE */
IF (GET_LAD_DN("N-0201") == 1)
	/* GDE is powered off */
	HGA_GDE_PWR = 0.00;
	HGA_MTR_PWR = 0.00;
	HGA_ENC_PWR = 0.00;
ELSE
	/* GDE is powered on, baseline power at zero rate */
	HGA_GDE_PWR = 0.30;
	HGA_MTR_PWR = 0.00;
	HGA_ENC_PWR = 1.20;
	/* Check status of azimuth motor */
	IF (GET_LAD_DN("N-0623") == 0) /* Stop command in effect, no-powered hold */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.00;
		HGA_MTR_PWR = HGA_MTR_PWR + 0.00;
	ELSEIF ((GET_LAD_DN("N-0623") == 1) && (GET_LAD_DN("N-0621") == 1)) /* Rate mode in effect, and moving */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.62;
		HGA_MTR_PWR = HGA_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("N-0623") == 2) && (GET_LAD_DN("N-0621") == 1)) /* Step mode in effect, and moving */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.62;
		HGA_MTR_PWR = HGA_MTR_PWR + 2.70;
	ENDIF
	/* Check status of elevation motor */
	IF (GET_LAD_DN("N-0631") == 0) /* Stop command in effect, no-powered hold */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.00;
		HGA_MTR_PWR = HGA_MTR_PWR + 0.00;
	ELSEIF ((GET_LAD_DN("N-0631") == 1) && (GET_LAD_DN("N-0629") == 1)) /* Rate mode in effect, and moving */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.62;
		HGA_MTR_PWR = HGA_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("N-0631") == 2) && (GET_LAD_DN("N-0629") == 1)) /* Step mode in effect, and moving */
		HGA_GDE_PWR = HGA_GDE_PWR + 0.62;
		HGA_MTR_PWR = HGA_MTR_PWR + 2.70;
	ENDIF
ENDIF

DERIVE ("U-2070", HGA_GDE_PWR);
DERIVE ("U-2071", HGA_MTR_PWR);
DERIVE ("U-2072", HGA_ENC_PWR);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0241 "MHSA_DETA_Q1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0010
Description:            MHSA Detector A Quadrant 1 Detector Voltage Counts
Mnemonic:               MHSA_A1_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0011
Description:            MHSA Detector A Quadrant 1 Detector Over-Range Flag
Mnemonic:               MHSA_A1_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0010" PARENTS = "N-0241";
CHILD = "U-0011" PARENTS = "N-0241";

FUNCT CHAN = "N-0241"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0010",volt_counts);
DERIVE ("U-0011",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0242 "MHSA_DETA_Q2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0012
Description:            MHSA Detector A Quadrant 2 Detector Voltage Counts
Mnemonic:               MHSA_A2_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0013
Description:            MHSA Detector A Quadrant 2 Detector Over-Range Flag
Mnemonic:               MHSA_A2_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0012" PARENTS = "N-0242";
CHILD = "U-0013" PARENTS = "N-0242";

FUNCT CHAN = "N-0242"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0012",volt_counts);
DERIVE ("U-0013",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0243 "MHSA_DETA_Q3" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0014
Description:            MHSA Detector A Quadrant 3 Detector Voltage Counts
Mnemonic:               MHSA_A3_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0015
Description:            MHSA Detector A Quadrant 3 Detector Over-Range Flag
Mnemonic:               MHSA_A3_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0014" PARENTS = "N-0243";
CHILD = "U-0015" PARENTS = "N-0243";

FUNCT CHAN = "N-0243"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0014",volt_counts);
DERIVE ("U-0015",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0244 "MHSA_DETA_Q4" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0016
Description:            MHSA Detector A Quadrant 4 Detector Voltage Counts
Mnemonic:               MHSA_A4_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0017
Description:            MHSA Detector A Quadrant 4 Detector Over-Range Flag
Mnemonic:               MHSA_A4_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0016" PARENTS = "N-0244";
CHILD = "U-0017" PARENTS = "N-0244";

FUNCT CHAN = "N-0244"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0016",volt_counts);
DERIVE ("U-0017",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0245 "MHSA_DETB_Q1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0018
Description:            MHSA Detector B Quadrant 1 Detector Voltage Counts
Mnemonic:               MHSA_B1_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0019
Description:            MHSA Detector B Quadrant 1 Detector Over-Range Flag
Mnemonic:               MHSA_B1_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0018" PARENTS = "N-0245";
CHILD = "U-0019" PARENTS = "N-0245";

FUNCT CHAN = "N-0245"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0018",volt_counts);
DERIVE ("U-0019",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0246 "MHSA_DETB_Q2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0020
Description:            MHSA Detector B Quadrant 2 Detector Voltage Counts
Mnemonic:               MHSA_B2_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0021
Description:            MHSA Detector B Quadrant 2 Detector Over-Range Flag
Mnemonic:               MHSA_B2_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0020" PARENTS = "N-0246";
CHILD = "U-0021" PARENTS = "N-0246";

FUNCT CHAN = "N-0246"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0020",volt_counts);
DERIVE ("U-0021",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0247 "MHSA_DETB_Q3" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0022
Description:            MHSA Detector B Quadrant 3 Detector Voltage Counts
Mnemonic:               MHSA_B3_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0023
Description:            MHSA Detector B Quadrant 3 Detector Over-Range Flag
Mnemonic:               MHSA_B3_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0022" PARENTS = "N-0247";
CHILD = "U-0023" PARENTS = "N-0247";

FUNCT CHAN = "N-0247"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0022",volt_counts);
DERIVE ("U-0023",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0248 "MHSA_DETB_Q4" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0024
Description:            MHSA Detector B Quadrant 4 Detector Voltage Counts
Mnemonic:               MHSA_B4_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0025
Description:            MHSA Detector B Quadrant 4 Detector Over-Range Flag
Mnemonic:               MHSA_B4_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0024" PARENTS = "N-0248";
CHILD = "U-0025" PARENTS = "N-0248";

FUNCT CHAN = "N-0248"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0024",volt_counts);
DERIVE ("U-0025",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0251 "MHSA_DETS_Q1" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0026
Description:            MHSA Detector S Quadrant 1 Detector Voltage Counts
Mnemonic:               MHSA_S1_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0027
Description:            MHSA Detector S Quadrant 1 Detector Over-Range Flag
Mnemonic:               MHSA_S1_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0026" PARENTS = "N-0251";
CHILD = "U-0027" PARENTS = "N-0251";

FUNCT CHAN = "N-0251"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0026",volt_counts);
DERIVE ("U-0027",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0252 "MHSA_DETS_Q2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0028
Description:            MHSA Detector S Quadrant 2 Detector Voltage Counts
Mnemonic:               MHSA_S2_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0029
Description:            MHSA Detector S Quadrant 2 Detector Over-Range Flag
Mnemonic:               MHSA_S2_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0028" PARENTS = "N-0252";
CHILD = "U-0029" PARENTS = "N-0252";

FUNCT CHAN = "N-0252"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0028",volt_counts);
DERIVE ("U-0029",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0253 "MHSA_DETS_Q3" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0030
Description:            MHSA Detector S Quadrant 3 Detector Voltage Counts
Mnemonic:               MHSA_S3_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0031
Description:            MHSA Detector S Quadrant 3 Detector Over-Range Flag
Mnemonic:               MHSA_S3_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0030" PARENTS = "N-0253";
CHILD = "U-0031" PARENTS = "N-0253";

FUNCT CHAN = "N-0253"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0030",volt_counts);
DERIVE ("U-0031",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0254 "MHSA_DETS_Q4" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 10-5-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0032
Description:            MHSA Detector S Quadrant 4 Detector Voltage Counts
Mnemonic:               MHSA_S4_VOLT
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0033
Description:            MHSA Detector S Quadrant 4 Detector Over-Range Flag
Mnemonic:               MHSA_S4_OVRG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,OVER_RANGE

*/

CHILD = "U-0032" PARENTS = "N-0254";
CHILD = "U-0033" PARENTS = "N-0254";

FUNCT CHAN = "N-0254"

UINT sign_bit,range_bit,mhsa_word;
INT  volt_counts;

mhsa_word = GET_DN();

/* extract sign bit */
sign_bit = ((mhsa_word & 0x8000) >> 15);

/* extract range bit */
range_bit = ((mhsa_word & 0x4000) >> 14);

/* extract volt counts */
IF (range_bit == 1)
    volt_counts = ((mhsa_word & 0x3FFF) * 2) + 16383;
ELSE
    volt_counts = (mhsa_word & 0x3FFF);
ENDIF


/* compute signed voltage */
IF (sign_bit == 1)
    volt_counts = -1 * volt_counts;
ENDIF

/* derive channels */
DERIVE ("U-0032",volt_counts);
DERIVE ("U-0033",range_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0277 "MOM_UNL_STAT" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 04-15-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0091
Description:            Emergency Unload State
Mnemonic:               MOM_UN_EMERG
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,WARMUP,FIRE,END

Derived Channel:        U-0092
Description:            Spin Unload State
Mnemonic:               MOM_UN_SPIN
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,WARMUP,FIRE,END

Derived Channel:        U-0093
Description:            Yaw Unload State
Mnemonic:               MOM_UN_YAW
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,WARMUP,FIRE,END

Derived Channel:        U-0094
Description:            Off Axis Unload State
Mnemonic:               MOM_UN_OFFAX
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,WARMUP,FIRE,END

*/

CHILD = "U-0091" PARENTS = "N-0277";
CHILD = "U-0092" PARENTS = "N-0277";
CHILD = "U-0093" PARENTS = "N-0277";
CHILD = "U-0094" PARENTS = "N-0277";

FUNCT CHAN = "N-0277"

UINT mom_word,mom_axis,mom_state,mom_seq;

mom_word = GET_DN();

/* extract mom axis */
mom_axis = ((mom_word & 0x0F00) >> 8);

/* extract mom state */
mom_state = ((mom_word & 0x00F0) >> 4);

/* extract mom seq */
mom_seq = ((mom_word & 0x000F) >> 0);

IF (mom_axis == 1)
    IF(mom_state == 0)
         DERIVE ("U-0091",0);
    ELSEIF(mom_state == 1)
         DERIVE ("U-0091",1);
    ELSEIF(mom_state == 2)
         DERIVE ("U-0091",2);
    ELSE
         DERIVE ("U-0091",0);
    ENDIF
    DERIVE ("U-0092",0);
    DERIVE ("U-0093",0);
    DERIVE ("U-0094",0);
ELSEIF (mom_axis == 2)
    IF(mom_state == 0)
         DERIVE ("U-0092",0);
    ELSEIF(mom_state == 1)
         DERIVE ("U-0092",1);
    ELSEIF(mom_state == 2)
         DERIVE ("U-0092",2);
    ELSE
         DERIVE ("U-0092",0);
    ENDIF
    DERIVE ("U-0091",0);
    DERIVE ("U-0093",0);
    DERIVE ("U-0094",0);
ELSEIF (mom_axis == 3)
    IF(mom_state == 0)
         DERIVE ("U-0093",0);
    ELSEIF(mom_state == 1)
         DERIVE ("U-0093",1);
    ELSEIF(mom_state == 2)
         DERIVE ("U-0093",2);
    ELSE
         DERIVE ("U-0093",0);
    ENDIF
    DERIVE ("U-0091",0);
    DERIVE ("U-0092",0);
    DERIVE ("U-0094",0);
ELSEIF (mom_axis == 4)
    IF(mom_state == 0)
         DERIVE ("U-0094",0);
    ELSEIF(mom_state == 1)
         DERIVE ("U-0094",1);
    ELSEIF(mom_state == 2)
         DERIVE ("U-0094",2);
    ELSE
         DERIVE ("U-0094",0);
    ENDIF
    DERIVE ("U-0091",0);
    DERIVE ("U-0092",0);
    DERIVE ("U-0093",0);
ELSE
    DERIVE ("U-0091",0);
    DERIVE ("U-0092",0);
    DERIVE ("U-0093",0);
    DERIVE ("U-0094",0);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0290 "POS_ERR_X" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-9-97                                          *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0290
Description:            Position Error X in Degrees
Mnemonic:               POS_ERR_Xdeg
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

*/

CHILD = "U-0290" PARENTS = "N-0290";

FUNCT CHAN = "N-0290"

DERIVE ("U-0290",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0291 "POS_ERR_Y" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-9-97                                          *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0291
Description:            Position Error Y in Degrees
Mnemonic:               POS_ERR_Ydeg
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

*/

CHILD = "U-0291" PARENTS = "N-0291";

FUNCT CHAN = "N-0291"

DERIVE ("U-0291",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0292 "POS_ERR_Z" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-9-97                                          *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0292
Description:            Position Error Z in Degrees
Mnemonic:               POS_ERR_Zdeg
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  degrees

*/

CHILD = "U-0292" PARENTS = "N-0292";

FUNCT CHAN = "N-0292"

DERIVE ("U-0292",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0335 "RTE_FLTBDY_Z" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 6-18-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0111
Description:            X Rate Error Rad/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_X
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  r/s

Derived Channel:        U-0112
Description:            Y Rate Error Rad/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_Y
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  r/s

Derived Channel:        U-0113
Description:            Z Rate Error Rad/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_Z
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  r/s

Derived Channel:        U-0114
Description:            X Rate Error Deg/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_X
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg/s

Derived Channel:        U-0115
Description:            Y Rate Error Deg/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_Y
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg/s

Derived Channel:        U-0116
Description:            Z Rate Error Deg/Sec (Difference between filtered body rate and commanded rate)
Mnemonic:               RTE_FB-CMD_Z
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg/s

*/

CHILD = "U-0111" PARENTS = "N-0330""N-0331""N-0332""N-0333""N-0334""N-0335";
CHILD = "U-0112" PARENTS = "N-0330""N-0331""N-0332""N-0333""N-0334""N-0335";
CHILD = "U-0113" PARENTS = "N-0330""N-0331""N-0332""N-0333""N-0334""N-0335";
CHILD = "U-0114" PARENTS = "N-0330""N-0331""N-0332""N-0333""N-0334""N-0335";
CHILD = "U-0115" PARENTS = "N-0330""N-0331""N-0332""N-0333""N-0334""N-0335";
CHILD = "U-0116" PARENTS = "N-0330""N-0331""N-0332""N-0333""N-0334""N-0335";

FUNCT CHAN = "N-0335"

/* Check telemetry validity */
IF (DN_VALID("N-0330") != 0)
        RETURN;
ENDIF

DERIVE ("U-0111",(GET_LAD_EU("N-0333") - GET_LAD_EU("N-0330")));
DERIVE ("U-0112",(GET_LAD_EU("N-0334") - GET_LAD_EU("N-0331")));
DERIVE ("U-0113",(GET_LAD_EU("N-0335") - GET_LAD_EU("N-0332")));

DERIVE ("U-0114",(GET_LAD_EU("N-0333") - GET_LAD_EU("N-0330")) * 57.29577951);
DERIVE ("U-0115",(GET_LAD_EU("N-0334") - GET_LAD_EU("N-0331")) * 57.29577951);
DERIVE ("U-0116",(GET_LAD_EU("N-0335") - GET_LAD_EU("N-0332")) * 57.29577951);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0345 "RWA_RAW_X" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 10-6-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0040
Description:            RWA X Derived Wheel Speed
Mnemonic:               RWA_X_D_SPD
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0041
Description:            RWA X Power On Condition
Mnemonic:               RWA_X_POWER
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        U-0042
Description:            RWA X Power Limited Condition
Mnemonic:               RWA_X_P_LMTD
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,PWR_LIMITED


*/

CHILD = "U-0040" PARENTS = "N-0345";
CHILD = "U-0041" PARENTS = "N-0345";
CHILD = "U-0042" PARENTS = "N-0345";

FUNCT CHAN = "N-0345"

UINT sign_bit,power_bit,limit_bit,rwa_raw_data;
INT  rwa_speed;

rwa_raw_data = GET_DN();

/* extract sign bit */
sign_bit = ((rwa_raw_data & 0x8000) >> 15);

/* extract power on bit */
power_bit = ((rwa_raw_data & 0x1000) >> 12);

/* extract power limit bit */
limit_bit = ((rwa_raw_data & 0x0800) >> 11);

/* extract 11 speed bits bit */
rwa_speed = (rwa_raw_data & 0x07FF) ;

/* Convert to RPM */
rwa_speed = rwa_speed * 5;

/* compute signed rwa speed */
IF (sign_bit == 1)
    rwa_speed = -1 * rwa_speed;
ENDIF

/* derive channels */
DERIVE ("U-0040",rwa_speed);
DERIVE ("U-0041",power_bit);
DERIVE ("U-0042",limit_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0346 "RWA_RAW_Y" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 10-6-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0044
Description:            RWA Y Derived Wheel Speed
Mnemonic:               RWA_Y_D_SPD
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0045
Description:            RWA Y Power On Condition
Mnemonic:               RWA_Y_POWER
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        U-0046
Description:            RWA Y Power Limited Condition
Mnemonic:               RWA_Y_P_LMTD
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,PWR_LIMITED


*/

CHILD = "U-0044" PARENTS = "N-0346";
CHILD = "U-0045" PARENTS = "N-0346";
CHILD = "U-0046" PARENTS = "N-0346";

FUNCT CHAN = "N-0346"

UINT sign_bit,power_bit,limit_bit,rwa_raw_data;
INT  rwa_speed;

rwa_raw_data = GET_DN();

/* extract sign bit */
sign_bit = ((rwa_raw_data & 0x8000) >> 15);

/* extract power on bit */
power_bit = ((rwa_raw_data & 0x1000) >> 12);

/* extract power limit bit */
limit_bit = ((rwa_raw_data & 0x0800) >> 11);

/* extract 11 speed bits bit */
rwa_speed = (rwa_raw_data & 0x07FF);

/* Convert to RPM */
rwa_speed = rwa_speed * 5;

/* compute signed rwa speed */
IF (sign_bit == 1)
    rwa_speed = -1 * rwa_speed;
ENDIF

/* derive channels */
DERIVE ("U-0044",rwa_speed);
DERIVE ("U-0045",power_bit);
DERIVE ("U-0046",limit_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0347 "RWA_RAW_Z" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 10-6-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0048
Description:            RWA Z Derived Wheel Speed
Mnemonic:               RWA_Z_D_SPD
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0049
Description:            RWA Z Power On Condition
Mnemonic:               RWA_Z_POWER
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        U-0050
Description:            RWA Z Power Limited Condition
Mnemonic:               RWA_Z_P_LMTD
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,PWR_LIMITED


*/

CHILD = "U-0048" PARENTS = "N-0347";
CHILD = "U-0049" PARENTS = "N-0347";
CHILD = "U-0050" PARENTS = "N-0347";

FUNCT CHAN = "N-0347"

UINT sign_bit,power_bit,limit_bit,rwa_raw_data;
INT  rwa_speed;

rwa_raw_data = GET_DN();

/* extract sign bit */
sign_bit = ((rwa_raw_data & 0x8000) >> 15);

/* extract power on bit */
power_bit = ((rwa_raw_data & 0x1000) >> 12);

/* extract power limit bit */
limit_bit = ((rwa_raw_data & 0x0800) >> 11);

/* extract 11 speed bits bit */
rwa_speed = (rwa_raw_data & 0x07FF);

/* Convert to RPM */
rwa_speed = rwa_speed * 5;

/* compute signed rwa speed */
IF (sign_bit == 1)
    rwa_speed = -1 * rwa_speed;
ENDIF

/* derive channels */
DERIVE ("U-0048",rwa_speed);
DERIVE ("U-0049",power_bit);
DERIVE ("U-0050",limit_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0348 "RWA_RAW_S" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 10-6-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0052
Description:            RWA S Derived Wheel Speed
Mnemonic:               RWA_S_D_SPD
Subsystem:              AACS
Data_Type:              SIGNED
Units:

Derived Channel:        U-0053
Description:            RWA S Power On Condition
Mnemonic:               RWA_S_POWER
Subsystem:              AACS
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        U-0054
Description:            RWA S Power Limited Condition
Mnemonic:               RWA_S_P_LMTD
Subsystem:              AACS
Data_Type:              STATUS
States:                 OK,PWR_LIMITED


*/

CHILD = "U-0052" PARENTS = "N-0348";
CHILD = "U-0053" PARENTS = "N-0348";
CHILD = "U-0054" PARENTS = "N-0348";

FUNCT CHAN = "N-0348"

UINT sign_bit,power_bit,limit_bit,rwa_raw_data;
INT  rwa_speed;

rwa_raw_data = GET_DN();

/* extract sign bit */
sign_bit = ((rwa_raw_data & 0x8000) >> 15);

/* extract power on bit */
power_bit = ((rwa_raw_data & 0x1000) >> 12);

/* extract power limit bit */
limit_bit = ((rwa_raw_data & 0x0800) >> 11);

/* extract 11 speed bits bit */
rwa_speed = (rwa_raw_data & 0x07FF);

/* Convert to RPM */
rwa_speed = rwa_speed * 5;

/* compute signed rwa speed */
IF (sign_bit == 1)
    rwa_speed = -1 * rwa_speed;
ENDIF

/* derive channels */
DERIVE ("U-0052",rwa_speed);
DERIVE ("U-0053",power_bit);
DERIVE ("U-0054",limit_bit);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0360 "SAM_AZ_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0082
Description:            SAM AZIMUTH FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               SAM_AZang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0082" PARENTS = "N-0360";

FUNCT CHAN = "N-0360"

/* Derive flight software computed control frame position in degrees */
DERIVE ("U-0082",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0362 "SAM_AZ_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:             OGS 11-15-96 Corrected true bias value of 28.95     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0072
Description:            SAM AZIMUTH TRUE POSITION (CONTROL FRAME)
Mnemonic:               SAM_AZ_TRUE
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0072" PARENTS = "N-0362";

FUNCT CHAN = "N-0362"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * 0.02197266) - 28.95;
IF (cf_pos < -150.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 210.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("U-0072", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0377 "SAM_EL_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0083
Description:            SAM ELEVATION FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               SAM_ELang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0083" PARENTS = "N-0377";

FUNCT CHAN = "N-0377"

/* Derive flight software computed control frame position in degrees */
DERIVE ("U-0083",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0379 "SAM_EL_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:             OGS 11-15-96 Corrected true bias value of 31.38     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0073
Description:            SAM ELEVATION TRUE POSITION (CONTROL FRAME)
Mnemonic:               SAM_EL_TRUE
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0073" PARENTS = "N-0379";

FUNCT CHAN = "N-0379"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * 0.02197266) + 31.38;
IF (cf_pos < -150.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 210.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("U-0073", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0385 "SAM_STATS" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-21-95                                         *
 * MODIFIED:             OGS 8-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-2073
Description:            SAM GDE Estimated Power
Mnemonic:               SAM_GDE_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        U-2074
Description:            SAM Motors Estimated Power
Mnemonic:               SAM_MTR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        U-2075
Description:            SAM Encoder Estimated Power
Mnemonic:               SAM_ENC_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "U-2073" PARENTS = "N-0385""N-0388""N-0362""N-0379""N-0801""N-0803""N-0809""N-0811";
CHILD = "U-2074" PARENTS = "N-0385""N-0388""N-0362""N-0379""N-0801""N-0803""N-0809""N-0811";
CHILD = "U-2075" PARENTS = "N-0385""N-0388""N-0362""N-0379""N-0801""N-0803""N-0809""N-0811";

FUNCT CHAN = "N-0385"

FLT SAM_GDE_PWR, SAM_MTR_PWR, SAM_ENC_PWR;

/* Check GDE telemetry validity */
IF ((DN_VALID("N-0811") != 0) || (DN_VALID("N-0362") != 0) || (DN_VALID("N-0379") != 0) || (DN_VALID("N-0388") != 0))
	RETURN;
ENDIF

/* Check Power Status of GDE */
IF (GET_LAD_DN("N-0388") == 1)
	/* GDE is powered off */
	SAM_GDE_PWR = 0.00;
	SAM_MTR_PWR = 0.00;
	SAM_ENC_PWR = 0.00;
ELSE
	/* GDE is powered on, baseline power at zero rate */
	SAM_GDE_PWR = 0.30;
	SAM_MTR_PWR = 0.00;
	SAM_ENC_PWR = 1.20;
	/* Check status of azimuth motor */
	IF (GET_LAD_DN("N-0803") == 0) /* Stop command in effect, powered hold */
		SAM_GDE_PWR = SAM_GDE_PWR + 1.43;
		SAM_MTR_PWR = SAM_MTR_PWR + 7.92;
	ELSEIF ((GET_LAD_DN("N-0803") == 1) && (GET_LAD_DN("N-0801") == 1)) /* Rate mode in effect, and moving */
		SAM_GDE_PWR = SAM_GDE_PWR + 0.62;
		SAM_MTR_PWR = SAM_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("N-0803") == 2) && (GET_LAD_DN("N-0801") == 1)) /* Step mode in effect, and moving */
		SAM_GDE_PWR = SAM_GDE_PWR + 0.62;
		SAM_MTR_PWR = SAM_MTR_PWR + 2.70;
	ENDIF
	/* Check status of elevation motor */
	IF (GET_LAD_DN("N-0811") == 0) /* Stop command in effect, powered hold */
		SAM_GDE_PWR = SAM_GDE_PWR + 1.43;
		SAM_MTR_PWR = SAM_MTR_PWR + 7.92;
	ELSEIF ((GET_LAD_DN("N-0811") == 1) && (GET_LAD_DN("N-0809") == 1)) /* Rate mode in effect, and moving */
		SAM_GDE_PWR = SAM_GDE_PWR + 0.62;
		SAM_MTR_PWR = SAM_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("N-0811") == 2) && (GET_LAD_DN("N-0809") == 1)) /* Step mode in effect, and moving */
		SAM_GDE_PWR = SAM_GDE_PWR + 0.62;
		SAM_MTR_PWR = SAM_MTR_PWR + 2.70;
	ENDIF
ENDIF

DERIVE ("U-2073", SAM_GDE_PWR);
DERIVE ("U-2074", SAM_MTR_PWR);
DERIVE ("U-2075", SAM_ENC_PWR);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0390 "SAP_AZ_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0084
Description:            SAP AZIMUTH FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               SAP_AZang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0084" PARENTS = "N-0390";

FUNCT CHAN = "N-0390"

/* Derive flight software computed control frame position in degrees */
DERIVE ("U-0084",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0392 "SAP_AZ_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:             OGS 11-15-96 Corrected true bias value of 33.29     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0074
Description:            SAP AZIMUTH TRUE POSITION (CONTROL FRAME)
Mnemonic:               SAP_AZ_TRUE
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0074" PARENTS = "N-0392";

FUNCT CHAN = "N-0392"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * 0.02197266) - 33.29;
IF (cf_pos < -210.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 150.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("U-0074", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0407 "SAP_EL_ANG" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0085
Description:            SAP ELEVATION FSW COMPUTED ANGLE IN DEGREES (CONTROL FRAME)
Mnemonic:               SAP_ELang_CF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0085" PARENTS = "N-0407";

FUNCT CHAN = "N-0407"

/* Derive flight software computed control frame position in degrees */
DERIVE ("U-0085",(GET_EU() * 57.29577951));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0409 "SAP_EL_POS" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-11-95                                        *
 * MODIFIED:             OGS 11-15-96 Corrected true bias value of 29.34     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0075
Description:            SAP ELEVATION TRUE POSITION (CONTROL FRAME)
Mnemonic:               SAP_EL_TRUE
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0075" PARENTS = "N-0409";

FUNCT CHAN = "N-0409"

FLT  cf_pos;
UINT enc_14bits;

/* Mask 14 bits of 16 bit word */
enc_14bits = ((GET_DN() & 0xfffc) >> 2 );

/* Derive encoder frame position in degrees */
PUT_EU(enc_14bits * 0.02197266);

/* Derive control frame position in degrees */
cf_pos = (enc_14bits * 0.02197266) + 29.34;
IF (cf_pos < -210.0)
     cf_pos = cf_pos + 360.0;
ELSEIF (cf_pos > 150.0)
     cf_pos = cf_pos - 360.0;
ENDIF
DERIVE ("U-0075", cf_pos);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0415 "SAP_STATS" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-21-95                                         *
 * MODIFIED:             OGS 7-26-97                                         *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-2076
Description:            SAP GDE Estimated Power
Mnemonic:               SAP_GDE_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        U-2077
Description:            SAP Motors Estimated Power
Mnemonic:               SAP_MTR_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

Derived Channel:        U-2078
Description:            SAP Encoder Estimated Power
Mnemonic:               SAP_ENC_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "U-2076" PARENTS = "N-0415""N-0418""N-0392""N-0409""N-0821""N-0823""N-0829""N-0831";
CHILD = "U-2077" PARENTS = "N-0415""N-0418""N-0392""N-0409""N-0821""N-0823""N-0829""N-0831";
CHILD = "U-2078" PARENTS = "N-0415""N-0418""N-0392""N-0409""N-0821""N-0823""N-0829""N-0831";

FUNCT CHAN = "N-0415"

FLT SAP_GDE_PWR, SAP_MTR_PWR, SAP_ENC_PWR;

/* Check GDE telemetry validity */
IF ((DN_VALID("N-0831") != 0) || (DN_VALID("N-0392") != 0) || (DN_VALID("N-0409") != 0) || (DN_VALID("N-0418") != 0))
	RETURN;
ENDIF

/* Check Power Status of GDE */
IF (GET_LAD_DN("N-0418") == 1)
	/* GDE is powered off */
	SAP_GDE_PWR = 0.00;
	SAP_MTR_PWR = 0.00;
	SAP_ENC_PWR = 0.00;
ELSE
	/* GDE is powered on, baseline power at zero rate */
	SAP_GDE_PWR = 0.30;
	SAP_MTR_PWR = 0.00;
	SAP_ENC_PWR = 1.20;
	/* Check status of azimuth motor */
	IF (GET_LAD_DN("N-0823") == 0) /* Stop command in effect, powered hold */
		SAP_GDE_PWR = SAP_GDE_PWR + 1.43;
		SAP_MTR_PWR = SAP_MTR_PWR + 7.92;
	ELSEIF ((GET_LAD_DN("N-0823") == 1) && (GET_LAD_DN("N-0821") == 1)) /* Rate mode in effect, and moving */
		SAP_GDE_PWR = SAP_GDE_PWR + 0.62;
		SAP_MTR_PWR = SAP_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("N-0823") == 2) && (GET_LAD_DN("N-0821") == 1)) /* Step mode in effect, and moving */
		SAP_GDE_PWR = SAP_GDE_PWR + 0.62;
		SAP_MTR_PWR = SAP_MTR_PWR + 2.70;
	ENDIF
	/* Check status of elevation motor */
	IF (GET_LAD_DN("N-0831") == 0) /* Stop command in effect, powered hold */
		SAP_GDE_PWR = SAP_GDE_PWR + 1.43;
		SAP_MTR_PWR = SAP_MTR_PWR + 7.92;
	ELSEIF ((GET_LAD_DN("N-0831") == 1) && (GET_LAD_DN("N-0829") == 1)) /* Rate mode in effect, and moving */
		SAP_GDE_PWR = SAP_GDE_PWR + 0.62;
		SAP_MTR_PWR = SAP_MTR_PWR + 2.70;
	ELSEIF ((GET_LAD_DN("N-0831") == 2) && (GET_LAD_DN("N-0829") == 1)) /* Step mode in effect, and moving */
		SAP_GDE_PWR = SAP_GDE_PWR + 0.62;
		SAP_MTR_PWR = SAP_MTR_PWR + 2.70;
	ENDIF
ENDIF

DERIVE ("U-2076", SAP_GDE_PWR);
DERIVE ("U-2077", SAP_MTR_PWR);
DERIVE ("U-2078", SAP_ENC_PWR);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0440 "SSA_RAW_RET" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 10-18-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0061
Description:            Reticle A Counts Converted From Gray Code
Mnemonic:               SSA_RETICL_A
Subsystem:              AACS
Data_Type:              UNSIGNED
Units:                  counts

Derived Channel:        U-0062
Description:            Reticle B Counts Converted From Gray Code
Mnemonic:               SSA_RETICL_B
Subsystem:              AACS
Data_Type:              UNSIGNED
Units:                  counts

*/

CHILD = "U-0061" PARENTS = "N-0440";
CHILD = "U-0062" PARENTS = "N-0440";

FUNCT CHAN = "N-0440"

UINT i, ssa_gray, ssa_count_a, ssa_count_b;
UINT bit[8];

ssa_gray = (GET_DN() & 0XFF00) >> 8;

FOR (i=0; i<=7; i++)
    bit[i] = (ssa_gray & (2**(7-i))) >> (7-i);
ENDFOR

FOR (i=0; i<7; i++)
    IF (bit[i] == 1)
        bit[i+1] = ~bit[i+1] & 1;
    ENDIF
ENDFOR

ssa_count_a = 0;
FOR (i=0; i<=7; i++)
    ssa_count_a = ssa_count_a + (bit[i] << (7-i));
ENDFOR


ssa_gray = (GET_DN() & 0X00FF);

FOR (i=0; i<=7; i++)
    bit[i] = (ssa_gray & (2**(7-i))) >> (7-i);
ENDFOR

FOR (i=0; i<7; i++)
    IF (bit[i] == 1)
        bit[i+1] = ~bit[i+1] & 1;
    ENDIF
ENDFOR

ssa_count_b = 0;
FOR (i=0; i<=7; i++)
    ssa_count_b = ssa_count_b + (bit[i] << (7-i));
ENDFOR

DERIVE ("U-0061",ssa_count_a);
DERIVE ("U-0062",ssa_count_b);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0470 "SAP_NORM_Z" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 12-18-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0068
Description:            SAM Sun Incidence Angle
Mnemonic:               SAM_SUN_INC
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0069
Description:            SAP Sun Incidence Angle
Mnemonic:               SAP_SUN_INC
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0068" PARENTS = "N-0470""N-0471""N-0472""N-0411""N-0412""N-0413""N-0381""N-0382""N-0383";
CHILD = "U-0069" PARENTS = "N-0470""N-0471""N-0472""N-0411""N-0412""N-0413""N-0381""N-0382""N-0383";

FUNCT CHAN = "N-0470"

FLT SA_ANG, SUN_MAG, SA_MAG, SUN_X, SUN_Y, SUN_Z, SA_X, SA_Y, SA_Z;

IF (DN_VALID("N-0472") == 0 && DN_VALID("N-0413") == 0 && DN_VALID("N-0383") == 0)

    SUN_X = GET_LAD_EU("N-0470");
    SUN_Y = GET_LAD_EU("N-0471");
    SUN_Z = GET_LAD_EU("N-0472");
    SUN_MAG = SQRT(SUN_X*SUN_X + SUN_Y*SUN_Y + SUN_Z*SUN_Z);
    SA_X = GET_LAD_EU("N-0381");
    SA_Y = GET_LAD_EU("N-0382");
    SA_Z = GET_LAD_EU("N-0383");
    SA_MAG = SQRT(SA_X*SA_X + SA_Y*SA_Y + SA_Z*SA_Z);
    SA_ANG = ASIN((SUN_X*SA_X + SUN_Y*SA_Y + SUN_Z*SA_Z) / (SUN_MAG * SA_MAG)) * 180.0 / PI;
    DERIVE ("U-0068", SA_ANG);

    SA_X = GET_LAD_EU("N-0411");
    SA_Y = GET_LAD_EU("N-0412");
    SA_Z = GET_LAD_EU("N-0413");
    SA_MAG = SQRT(SA_X*SA_X + SA_Y*SA_Y + SA_Z*SA_Z);
    SA_ANG = ASIN((SUN_X*SA_X + SUN_Y*SA_Y + SUN_Z*SA_Z) / (SUN_MAG * SA_MAG)) * 180.0 / PI;
    DERIVE ("U-0069", SA_ANG);

ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-0472 "SUNVEC_RAW_Z" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 6-18-96                                         *
 * MODIFIED:             OGS 10-23-97                                        *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0110
Description:            Angular difference between ephemeris sun and measured sun
Mnemonic:               EPH_SUN_DIF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0120
Description:            SAM HINGE ANGLE (DEGREES) (Measured Sun)
Mnemonic:               SAM_HNG_ANGm
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0121
Description:            SAP HINGE ANGLE (DEGREES) (Measured Sun)
Mnemonic:               SAP_HNG_ANGm
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0122
Description:            SAM PANEL TORSION     (DEGREES) (Measured Sun)
Mnemonic:               SAM_TOR_ANGm
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0123
Description:            SAP PANEL TORSION     (DEGREES) (Measured Sun)
Mnemonic:               SAP_TOR_ANGm
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg


Derived Channel:        U-0124
Description:            SAM HINGE ANGLE (DEGREES) (Ephem Sun)
Mnemonic:               SAM_HNG_ANGe
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0125
Description:            SAP HINGE ANGLE (DEGREES) (Ephem Sun)
Mnemonic:               SAP_HNG_ANGe
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0126
Description:            SAM PANEL TORSION     (DEGREES) (Ephem Sun)
Mnemonic:               SAM_TOR_ANGe
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0127
Description:            SAP PANEL TORSION     (DEGREES) (Ephem Sun)
Mnemonic:               SAP_TOR_ANGe
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0128
Description:            SUN PHASE DIFFERENCE  (DEGREES)
Mnemonic:               SUNphaseDIFF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

Derived Channel:        U-0129
Description:            SUN X DIFFERENCE  (DEGREES)
Mnemonic:               SUN_X_DIFF
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  deg

*/

CHILD = "U-0110" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0120" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0121" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0122" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0123" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0124" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0125" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0126" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0127" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0128" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";
CHILD = "U-0129" PARENTS = "N-0085""N-0086""N-0360""N-0377""N-0390""N-0407""N-0440""N-0444""N-0470""N-0471""N-0472""N-0873";

FUNCT CHAN = "N-0472"

FLT eph_sun_bz;
FLT raw_sun_x,raw_sun_y,raw_sun_z;
FLT head_x_ret,head_y_ret,head_z_ret,length,sam_az,sam_el;
FLT dcm_11,dcm_12,dcm_13,dcm_21,dcm_22,dcm_23,dcm_31,dcm_32,dcm_33;
FLT sun_x,sun_y,sun_z,head_x_bod,head_y_bod,head_z_bod,hinge_angle,torsion_angle;
UINT i, ssa_gray, ssa_count_a, ssa_count_b;
UINT bit[8];

IF (DN_VALID("N-0086") == 0)

    eph_sun_bz = SQRT(1.0 - GET_LAD_EU("N-0085")**2 - GET_LAD_EU("N-0086")**2);
    IF (GET_EU() < 0.0)
        eph_sun_bz = eph_sun_bz * -1.0;
    ENDIF

    length = SQRT(GET_LAD_EU("N-0470")**2 + GET_LAD_EU("N-0471")**2 + GET_EU()**2);
    sun_x = GET_LAD_EU("N-0470")/length;
    sun_y = GET_LAD_EU("N-0471")/length;
    sun_z = GET_EU()/length;

    DERIVE ("U-0110",(180.0/PI * ACOS(sun_x*GET_LAD_EU("N-0085") + sun_y*GET_LAD_EU("N-0086") + sun_z*eph_sun_bz)));

ENDIF


/* Check telemetry validity */
IF ((DN_VALID("N-0360") != 0) || (DN_VALID("N-0377") != 0) || (DN_VALID("N-0440") != 0) ||
    (DN_VALID("N-0873") != 0) || (DN_VALID("N-0444") != 0) || (DN_VALID("N-0390") != 0) ||
    (DN_VALID("N-0407") != 0) || (DN_VALID("N-0085") != 0) || (DN_VALID("N-0086") != 0))
        RETURN;
ENDIF

ssa_gray = (GET_LAD_DN("N-0440") & 0XFF00) >> 8;

FOR (i=0; i<=7; i++)
    bit[i] = (ssa_gray & (2**(7-i))) >> (7-i);
ENDFOR

FOR (i=0; i<7; i++)
    IF (bit[i] == 1)
        bit[i+1] = ~bit[i+1] & 1;
    ENDIF
ENDFOR

ssa_count_a = 0;
FOR (i=0; i<=7; i++)
    ssa_count_a = ssa_count_a + (bit[i] << (7-i));
ENDFOR


ssa_gray = (GET_LAD_DN("N-0440") & 0X00FF);

FOR (i=0; i<=7; i++)
    bit[i] = (ssa_gray & (2**(7-i))) >> (7-i);
ENDFOR

FOR (i=0; i<7; i++)
    IF (bit[i] == 1)
        bit[i+1] = ~bit[i+1] & 1;
    ENDIF
ENDFOR

ssa_count_b = 0;
FOR (i=0; i<=7; i++)
    ssa_count_b = ssa_count_b + (bit[i] << (7-i));
ENDFOR

IF (GET_LAD_DN("N-0873")==4 && GET_LAD_DN("N-0444")==3)
    raw_sun_x = -0.350625 + (0.00275 * (FLT)ssa_count_a);
    raw_sun_y = -0.350625 + (0.00275 * (FLT)ssa_count_b);
    IF(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)) < 0)
        raw_sun_z = 0;
    ELSE
        raw_sun_z = SQRT(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)));
    ENDIF

    raw_sun_x = -1.4553 * raw_sun_x;
    raw_sun_y = 1.4553 * raw_sun_y;
    raw_sun_z = raw_sun_z;

    length = SQRT(raw_sun_x**2 + raw_sun_y**2 + raw_sun_z**2);

    head_x_ret = raw_sun_x / length;
    head_y_ret = raw_sun_y / length;
    head_z_ret = raw_sun_z / length;

    sam_az = GET_LAD_EU("N-0360");
    sam_el = GET_LAD_EU("N-0377");

    dcm_11 = SIN(sam_az) * SIN(sam_el);
    dcm_12 = COS(sam_az);
    dcm_13 = -COS(sam_el) * SIN(sam_az);
    dcm_21 = COS(sam_el);
    dcm_22 = 0.0;
    dcm_23 = SIN(sam_el);
    dcm_31 = SIN(sam_el) * COS(sam_az);
    dcm_32 = -SIN(sam_az);
    dcm_33 = -COS(sam_az) * COS(sam_el);

    sun_x = GET_LAD_EU("N-0470");
    sun_y = GET_LAD_EU("N-0471");
    sun_z = GET_EU();

    head_x_bod = dcm_11*sun_x + dcm_12*sun_y + dcm_13*sun_z;
    head_y_bod = dcm_21*sun_x + dcm_22*sun_y + dcm_23*sun_z;
    head_z_bod = dcm_31*sun_x + dcm_32*sun_y + dcm_33*sun_z;

    hinge_angle = 180.0/PI * (ATAN2(head_z_ret,head_x_ret) - ATAN2(head_z_bod,head_x_bod));
    torsion_angle = 180.0/PI * (ASIN(head_y_ret) - ASIN(head_y_bod));

ELSE
    hinge_angle = -1.0;
    torsion_angle = -1.0;
ENDIF

DERIVE ("U-0120",hinge_angle);
DERIVE ("U-0122",torsion_angle);


IF (GET_LAD_DN("N-0873")==5 && GET_LAD_DN("N-0444")==3)
    raw_sun_x = -0.350625 + (0.00275 * (FLT)ssa_count_a);
    raw_sun_y = -0.350625 + (0.00275 * (FLT)ssa_count_b);
    IF(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)) < 0)
        raw_sun_z = 0;
    ELSE
        raw_sun_z = SQRT(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)));
    ENDIF

    raw_sun_x = -1.4553 * raw_sun_x;
    raw_sun_y = 1.4553 * raw_sun_y;
    raw_sun_z = raw_sun_z;

    length = SQRT(raw_sun_x**2 + raw_sun_y**2 + raw_sun_z**2);

    head_x_ret = raw_sun_x / length;
    head_y_ret = raw_sun_y / length;
    head_z_ret = raw_sun_z / length;

    sam_az = GET_LAD_EU("N-0390");
    sam_el = GET_LAD_EU("N-0407");

    dcm_11 = -SIN(sam_az) * SIN(sam_el);
    dcm_12 = -COS(sam_az);
    dcm_13 = -COS(sam_el) * SIN(sam_az);
    dcm_21 = -COS(sam_el);
    dcm_22 = 0.0;
    dcm_23 = SIN(sam_el);
    dcm_31 = -SIN(sam_el) * COS(sam_az);
    dcm_32 = SIN(sam_az);
    dcm_33 = -COS(sam_az) * COS(sam_el);

    sun_x = GET_LAD_EU("N-0470");
    sun_y = GET_LAD_EU("N-0471");
    sun_z = GET_EU();

    head_x_bod = dcm_11*sun_x + dcm_12*sun_y + dcm_13*sun_z;
    head_y_bod = dcm_21*sun_x + dcm_22*sun_y + dcm_23*sun_z;
    head_z_bod = dcm_31*sun_x + dcm_32*sun_y + dcm_33*sun_z;

    hinge_angle = 180.0/PI * (ATAN2(head_z_ret,head_x_ret) - ATAN2(head_z_bod,head_x_bod));
    torsion_angle = 180.0/PI * (ASIN(head_y_ret) - ASIN(head_y_bod));

ELSE
    hinge_angle = -1.0;
    torsion_angle = -1.0;
ENDIF

DERIVE ("U-0121",hinge_angle);
DERIVE ("U-0123",torsion_angle);

IF (GET_LAD_DN("N-0873")==4 && GET_LAD_DN("N-0444")==3)
    raw_sun_x = -0.350625 + (0.00275 * (FLT)ssa_count_a);
    raw_sun_y = -0.350625 + (0.00275 * (FLT)ssa_count_b);
    IF(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)) < 0)
        raw_sun_z = 0;
    ELSE
        raw_sun_z = SQRT(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)));
    ENDIF

    raw_sun_x = -1.4553 * raw_sun_x;
    raw_sun_y = 1.4553 * raw_sun_y;
    raw_sun_z = raw_sun_z;

    length = SQRT(raw_sun_x**2 + raw_sun_y**2 + raw_sun_z**2);

    head_x_ret = raw_sun_x / length;
    head_y_ret = raw_sun_y / length;
    head_z_ret = raw_sun_z / length;

    sam_az = GET_LAD_EU("N-0360");
    sam_el = GET_LAD_EU("N-0377");

    dcm_11 = SIN(sam_az) * SIN(sam_el);
    dcm_12 = COS(sam_az);
    dcm_13 = -COS(sam_el) * SIN(sam_az);
    dcm_21 = COS(sam_el);
    dcm_22 = 0.0;
    dcm_23 = SIN(sam_el);
    dcm_31 = SIN(sam_el) * COS(sam_az);
    dcm_32 = -SIN(sam_az);
    dcm_33 = -COS(sam_az) * COS(sam_el);

/*
    sun_x = GET_LAD_EU("N-0470");
    sun_y = GET_LAD_EU("N-0471");
    sun_z = GET_EU();
*/
    sun_x = GET_LAD_EU("N-0085");
    sun_y = GET_LAD_EU("N-0086");
    sun_z = eph_sun_bz;

    head_x_bod = dcm_11*sun_x + dcm_12*sun_y + dcm_13*sun_z;
    head_y_bod = dcm_21*sun_x + dcm_22*sun_y + dcm_23*sun_z;
    head_z_bod = dcm_31*sun_x + dcm_32*sun_y + dcm_33*sun_z;

    hinge_angle = 180.0/PI * (ATAN2(head_z_ret,head_x_ret) - ATAN2(head_z_bod,head_x_bod));
    torsion_angle = 180.0/PI * (ASIN(head_y_ret) - ASIN(head_y_bod));

ELSE
    hinge_angle = -1.0;
    torsion_angle = -1.0;
ENDIF

DERIVE ("U-0124",hinge_angle);
DERIVE ("U-0126",torsion_angle);


IF (GET_LAD_DN("N-0873")==5 && GET_LAD_DN("N-0444")==3)
    raw_sun_x = -0.350625 + (0.00275 * (FLT)ssa_count_a);
    raw_sun_y = -0.350625 + (0.00275 * (FLT)ssa_count_b);
    IF(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)) < 0)
        raw_sun_z = 0;
    ELSE
        raw_sun_z = SQRT(0.200704 - (1.117898 * (raw_sun_x**2 + raw_sun_y**2)));
    ENDIF

    raw_sun_x = -1.4553 * raw_sun_x;
    raw_sun_y = 1.4553 * raw_sun_y;
    raw_sun_z = raw_sun_z;

    length = SQRT(raw_sun_x**2 + raw_sun_y**2 + raw_sun_z**2);

    head_x_ret = raw_sun_x / length;
    head_y_ret = raw_sun_y / length;
    head_z_ret = raw_sun_z / length;

    sam_az = GET_LAD_EU("N-0390");
    sam_el = GET_LAD_EU("N-0407");

    dcm_11 = -SIN(sam_az) * SIN(sam_el);
    dcm_12 = -COS(sam_az);
    dcm_13 = -COS(sam_el) * SIN(sam_az);
    dcm_21 = -COS(sam_el);
    dcm_22 = 0.0;
    dcm_23 = SIN(sam_el);
    dcm_31 = -SIN(sam_el) * COS(sam_az);
    dcm_32 = SIN(sam_az);
    dcm_33 = -COS(sam_az) * COS(sam_el);

/*
    sun_x = GET_LAD_EU("N-0470");
    sun_y = GET_LAD_EU("N-0471");
    sun_z = GET_EU();
*/
    sun_x = GET_LAD_EU("N-0085");
    sun_y = GET_LAD_EU("N-0086");
    sun_z = eph_sun_bz;

    head_x_bod = dcm_11*sun_x + dcm_12*sun_y + dcm_13*sun_z;
    head_y_bod = dcm_21*sun_x + dcm_22*sun_y + dcm_23*sun_z;
    head_z_bod = dcm_31*sun_x + dcm_32*sun_y + dcm_33*sun_z;

    hinge_angle = 180.0/PI * (ATAN2(head_z_ret,head_x_ret) - ATAN2(head_z_bod,head_x_bod));
    torsion_angle = 180.0/PI * (ASIN(head_y_ret) - ASIN(head_y_bod));

ELSE
    hinge_angle = -1.0;
    torsion_angle = -1.0;
ENDIF


DERIVE ("U-0125",hinge_angle);
DERIVE ("U-0127",torsion_angle);
DERIVE ("U-0128", 180.0/PI * (ATAN2(eph_sun_bz,GET_LAD_EU("N-0086")) - ATAN2(GET_EU(),GET_LAD_EU("N-0471"))));
DERIVE ("U-0129", 180.0/PI * (ACOS(GET_LAD_EU("N-0085")) - ACOS(GET_LAD_EU("N-0470"))));


ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * N-0482 "SYST_MO_Z" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 12-18-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-0065
Description:            Magnitude of Cyclic Momentum
Mnemonic:               SYS_MOM_MAG
Subsystem:              AACS
Data_Type:              FLOAT
Units:                  Nmsec

*/

CHILD = "U-0065" PARENTS = "N-0481""N-0482";

FUNCT CHAN = "N-0482"

FLT MOM_Y, MOM_Z;

IF (EU_VALID("N-0481") == 0)
    MOM_Y = GET_LAD_EU("N-0481");
    MOM_Z = GET_EU();
    DERIVE ("U-0065", SQRT(MOM_Y*MOM_Y + MOM_Z*MOM_Z));
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * N-1030 "CV_DATA_WORD" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 09-26-95                                        *
 * MODIFIED:             OGS 03-04-96  (Modified 1, 2, 3 Word MRO)           *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-1011
Description:            CV Message Class Description
Mnemonic:               CV_CLASS
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        U-1013
Description:            CV Message Sub Class Description
Mnemonic:               CV_SUB_CLASS
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        U-1015
Description:            CV Message String Part 1
Mnemonic:               CV_MSG_PART1
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        U-1016
Description:            CV Message String Part 2
Mnemonic:               CV_MSG_PART2
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        U-1017
Description:            CV Message String Part 3
Mnemonic:               CV_MSG_PART3
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        U-1018
Description:            CV Message String Part 4
Mnemonic:               CV_MSG_PART4
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        U-1019
Description:            CV Message String Part 5
Mnemonic:               CV_MSG_PART5
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        U-1021
Description:            Command Error Code
Mnemonic:               CMD_ERR_CODE
Subsystem:              CDH
Data_Type:              UNSIGNED
Units:

Derived Channel:        U-1022
Description:            Command Error Code Description
Mnemonic:               CMD_ERR_DESC
Subsystem:              CDH
Data_Type:              ASCII
Units:

Derived Channel:        U-1024
Description:            Last CHECKSUM Value
Mnemonic:               L_CHKSUM_VAL
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        U-1025
Description:            Last CHECKSUM Physical Memory Address (MSH)
Mnemonic:               L_CHKSUM_MSH
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        U-1026
Description:            Last CHECKSUM Physical Memory Address (LSH)
Mnemonic:               L_CHKSUM_LSH
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        U-1027
Description:            Last 1, 2 or 3 Word Memory Readout Address
Mnemonic:               L_MEM_ADDR
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        U-1028
Description:            Last Memory Readout Word 1
Mnemonic:               L_MEM_WORD1
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        U-1029
Description:            Last Memory Readout Word 2
Mnemonic:               L_MEM_WORD2
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

Derived Channel:        U-1030
Description:            Last Memory Readout Word 3
Mnemonic:               L_MEM_WORD3
Subsystem:              CDH
Data_Type:              DIGITAL
Units:

*/

CHILD = "U-1011" PARENTS = "N-1030";
CHILD = "U-1013" PARENTS = "N-1030";
CHILD = "U-1015" PARENTS = "N-1030";
CHILD = "U-1016" PARENTS = "N-1030";
CHILD = "U-1017" PARENTS = "N-1030";
CHILD = "U-1018" PARENTS = "N-1030";
CHILD = "U-1019" PARENTS = "N-1030";
CHILD = "U-1021" PARENTS = "N-1030";
CHILD = "U-1022" PARENTS = "N-1030";
CHILD = "U-1024" PARENTS = "N-1030";
CHILD = "U-1025" PARENTS = "N-1030";
CHILD = "U-1026" PARENTS = "N-1030";
CHILD = "U-1027" PARENTS = "N-1030";
CHILD = "U-1028" PARENTS = "N-1030";
CHILD = "U-1029" PARENTS = "N-1030";
CHILD = "U-1030" PARENTS = "N-1030";

FUNCT CHAN = "N-1030"

UINT cv_word, byte_val, script_add, i, err, err_num, load_num, load_stat, null_data;
INT  cmd_err_code, length;
ASCII cv_message;
STATIC INT n_words=0, n_save=0, word_cnt=0, stcmd_err_code=0;
STATIC UINT addr_0_2=0, mem_data_type=0, physical_page=0, class=0, sub_class=0;
STATIC ASCII class_def="            ",sub_class_def="            ",stcmd_sub_class="            ";

cv_word = GET_DN();
null_data = 0xFFFFFFFF;



IF (n_words < 1)   /* Check if in middle of multiple CV word */

    n_words = 0;
    word_cnt = 1;
    cmd_err_code = -1;
    sub_class_def = "            ";
    cv_message    = "            ";

    /* Extract Class Type and Sub Class Type from CV Monitor Channel */
    class = ((cv_word & 0xC000) >> 14);

    IF (class == 0)
        class_def = "REAL_TIME_CV";
        cv_message = "Command Sequence Number (14 LSBs) = 0x";
        byte_val = ((cv_word & 0x3000) >> 12);
        cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        byte_val = ((cv_word & 0x0F00) >> 8);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF
        byte_val = ((cv_word & 0x00F0) >> 4);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF
        byte_val = (cv_word & 0x000F);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF

    ELSEIF (class == 2)
        sub_class = ((cv_word & 0x3C00) >> 10);
        IF (sub_class == 0)
            class_def = "REPLY_MSG_CV";
            sub_class_def = "RPLY_MSG_BEG";
            cv_message = "Word 1, Type = ";
            mem_data_type = ((cv_word & 0x0200) >> 9);
            IF (mem_data_type == 0)
                cv_message = ASCII_APPEND (cv_message,"Memory, ");
            ELSEIF (mem_data_type == 1)
                cv_message = ASCII_APPEND (cv_message,"IPR, ");
            ENDIF
            n_words = (cv_word & 0x0007);
            n_save = n_words;
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_words));
            cv_message = ASCII_APPEND (cv_message," Words Follow, Physical Pg#=");
            physical_page = ((cv_word & 0x00F8) >> 3);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(physical_page));
            err = ((cv_word & 0x0100) >> 8);
            IF (err == 1)
                cmd_err_code = 64;
            ENDIF
            cv_message = ASCII_APPEND (cv_message,", E=");
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err));
        ELSEIF (sub_class == 1)
            class_def = "REPLY_MSG_CV";
            sub_class_def = "RPLY_MSG_END";
            cv_message = "Word ";
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_save+2));
            cv_message = ASCII_APPEND (cv_message,", Type = ");
            mem_data_type = ((cv_word & 0x0200) >> 9);
            IF (mem_data_type == 0)
                cv_message = ASCII_APPEND (cv_message,"Memory, ");
            ELSEIF (mem_data_type == 1)
                cv_message = ASCII_APPEND (cv_message,"IPR, ");
            ENDIF
            n_words = (cv_word & 0x0007);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_words));
            cv_message = ASCII_APPEND (cv_message," Words, Physical Pg#=");
            physical_page = ((cv_word & 0x00F8) >> 3);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(physical_page));
            cv_message = ASCII_APPEND (cv_message,", E=");
            err = ((cv_word & 0x0100) >> 8);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err));
            IF (err == 1)
                cmd_err_code = 64;
            ENDIF
            n_words = 0;
            n_save = 0;
        ELSEIF (sub_class == 2)
            class_def = "  R/T_S/S_CE";
            sub_class_def = "RT_S_CMD_ERR";
            cv_message = "Word 1, Command Sequence Number (10 LSBs) = ";
            script_add = (cv_word & 0x03FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 3)
            class_def = "STORED_SS_CV";
            sub_class_def = "ST_S_CMD_ERR";
            cv_message = "Word 1, Script Address (High 8 Bits)  = ";
            script_add = (cv_word & 0x00FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 4)
            class_def = "STORED_SS_CV";
            sub_class_def = "ST_S_CMD_ERR";
            cv_message = "Word 2, Script Address (Low 8 Bits)  = ";
            script_add = (cv_word & 0x00FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 5)
            IF (ASCII_COMP(class_def,"STORED_SS_CV") == 0)
                sub_class_def = "ST_S_CMD_ERR";
                cv_message = "Word 3, Last Command Error Code = 0x";
            ELSEIF (ASCII_COMP(class_def,"  R/T_S/S_CE") == 0)
                sub_class_def = "RT_S_CMD_ERR";
                cv_message = "Word 2, Last Command Error Code = 0x";
            ELSEIF (ASCII_COMP(class_def,"INTRNL_SS_CV") == 0)
                sub_class_def = "IN_S_CMD_ERR";
                cv_message = "Word 2, Last Command Error Code = 0x";
            ELSE
                sub_class_def = "CMD_ERR_CODE";
                cv_message = "Last Command Error Code = 0x";
            ENDIF
            cmd_err_code = (cv_word & 0x03FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((cmd_err_code & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 6)
            class_def = "MISSING_BLCK";
            sub_class_def = "MSNG_BLK_BGN";
            cv_message = "Word 1, Missing Blocks, Load# = ";
            load_num = ((cv_word & 0x00F0) >> 4);
            load_stat = ((cv_word & 0x0008) >> 3);
            n_words = (cv_word & 0x0007);
            n_save = n_words;
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(load_num));
            cv_message = ASCII_APPEND (cv_message,", S = ");
            IF (load_stat == 1)
                cv_message = ASCII_APPEND (cv_message,"1 (cmplt), ");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"0 (incmplt), ");
            ENDIF
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_words));
            cv_message = ASCII_APPEND (cv_message," Words Follow");
        ELSEIF (sub_class == 7)
            class_def = "MISSING_BLCK";
            sub_class_def = "MSNG_BLK_END";
            cv_message = "Word ";
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_save+2));
            cv_message = ", Missing Blocks, Load# = ";
            load_num = ((cv_word & 0x00F0) >> 4);
            load_stat = ((cv_word & 0x0008) >> 3);
            n_words = (cv_word & 0x0007);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(load_num));
            cv_message = ASCII_APPEND (cv_message,", Status = ");
            IF (load_stat = 1)
                cv_message = ASCII_APPEND (cv_message,"comp, ");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"incomp, ");
            ENDIF
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_words));
            cv_message = ASCII_APPEND (cv_message," Words");
            n_words = 0;
            n_save = 0;
        ELSEIF (sub_class == 8)
            class_def = "MEM_CHECKSUM";
            sub_class_def = "CHECKSUM_BGN";
            DERIVE("U-1024",null_data);
            DERIVE("U-1025",null_data);
            DERIVE("U-1026",null_data);
            cv_message = "Word 1, M=";
            err_num = ((cv_word & 0x0200) >> 9);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", R=");
            err_num = ((cv_word & 0x0100) >> 8);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", E=");
            err_num = ((cv_word & 0x0080) >> 7);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", S=");
            err_num = ((cv_word & 0x0040) >> 6);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", I=");
            err_num = ((cv_word & 0x0020) >> 5);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", C=");
            err_num = ((cv_word & 0x0010) >> 4);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            n_words = (cv_word & 0x0007);
            n_save = n_words;
        ELSEIF (sub_class == 9)
            class_def = "MEM_CHECKSUM";
            sub_class_def = "CHECKSUM_END";
            cv_message = "Word ";
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(n_save+2));
            cv_message = ASCII_APPEND (cv_message,", M=");
            err_num = ((cv_word & 0x0200) >> 9);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", R=");
            err_num = ((cv_word & 0x0100) >> 8);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", E=");
            err_num = ((cv_word & 0x0080) >> 7);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", S=");
            err_num = ((cv_word & 0x0040) >> 6);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", I=");
            err_num = ((cv_word & 0x0020) >> 5);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            cv_message = ASCII_APPEND (cv_message,", C=");
            err_num = ((cv_word & 0x0010) >> 4);
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(err_num));
            n_words = (cv_word & 0x0007);
            n_words = 0;
            n_save = 0;
        ELSEIF (sub_class == 10)
            class_def = "INTRNL_SS_CV";
            sub_class_def = "IN_S_CMD_ERR";
            cv_message = "Word 1, Software Subsystem ID = ";
            script_add = (cv_word & 0x03FF);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSEIF (sub_class == 11)
            class_def = " MINI_SEQ_CV";
            sub_class_def = "MINI_SEQ_BEG";
            cv_message = "Mini Sequence Begin CV Message";
        ELSEIF (sub_class == 12)
            class_def = " MINI_SEQ_CV";
            sub_class_def = "MINI_SEQ_END";
            cv_message = "Mini Sequence End CV Message, CMD Error Code = 0x";
            cmd_err_code = (cv_word & 0x003F);
            FOR (i=0; i<=3; i++)
                byte_val = ((cmd_err_code & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ENDIF

    ELSEIF (class == 1)
        class_def = "STORD_CMD_CV";
        IF ( ((cv_word & 0x2000) >> 13) == 0 )
            sub_class = ((cv_word & 0x1C00) >> 10);
            cmd_err_code = ((cv_word & 0x03F8) >> 3);
            addr_0_2 = ((cv_word & 0x0007) << 13);
            byte_val = (cv_word & 0x0007);
            cv_message = "Word 1 Address Bits 0..2 = 0x";
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
            stcmd_err_code = cmd_err_code;
            IF (sub_class == 0)
                sub_class_def = "BUS_CMD_EXEC";
            ELSEIF (sub_class == 1)
                sub_class_def = "PYL_CMD_EXEC";
            ELSEIF (sub_class == 2)
                sub_class_def = "SCRIPT_BEGIN";
            ELSEIF (sub_class == 3)
                sub_class_def = "  SCRIPT_END";
            ELSEIF (sub_class == 4)
                sub_class_def = "SCRP_END_ERR";
            ELSEIF (sub_class == 5)
                sub_class_def = "SCRIPT_ERROR";
            ELSEIF (sub_class == 6)
                sub_class_def = "SCRIPT_STOPD";
            ELSE
                sub_class_def = "   UNDEFINED";
            ENDIF
            stcmd_sub_class = sub_class_def;
            cv_message = ASCII_APPEND (cv_message,", CEC = 0x");
            FOR (i=0; i<=3; i++)
                byte_val = ((cmd_err_code & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ELSE
            cv_message = "Script Address Word 2 Bits 3..15 + Word 1 Bits 0..2 = 0x";
            script_add = ((cv_word & 0x1FFF) + addr_0_2);
            FOR (i=0; i<=3; i++)
                byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
            cmd_err_code = stcmd_err_code;
            stcmd_err_code = -1;
            sub_class_def = stcmd_sub_class;
            stcmd_sub_class = "            ";
        ENDIF

    ELSEIF (class == 3)
        cv_message = "Command Sequence Number  (8 LSBs) = 0x";
        byte_val = ((cv_word & 0x00F0) >> 4);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF
        byte_val = (cv_word & 0x000F);
        IF (byte_val < 10)
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
        ELSEIF (byte_val == 10)
            cv_message = ASCII_APPEND (cv_message,"A");
        ELSEIF (byte_val == 11)
            cv_message = ASCII_APPEND (cv_message,"B");
        ELSEIF (byte_val == 12)
            cv_message = ASCII_APPEND (cv_message,"C");
        ELSEIF (byte_val == 13)
            cv_message = ASCII_APPEND (cv_message,"D");
        ELSEIF (byte_val == 14)
            cv_message = ASCII_APPEND (cv_message,"E");
        ELSEIF (byte_val == 15)
            cv_message = ASCII_APPEND (cv_message,"F");
        ELSE
            cv_message = ASCII_APPEND (cv_message,"?");
        ENDIF
        cmd_err_code = ((cv_word & 0x3F00) >> 8);
        IF (cmd_err_code == 0)
            class_def = "     IDLE_CV";
            cmd_err_code = -1;
        ELSE
            class_def = " RT_ERROR_CV";
            cv_message = ASCII_APPEND (cv_message,", CEC = 0x");
            FOR (i=0; i<=3; i++)
                byte_val = ((cmd_err_code & (0xF000/((0x10)**i))) >> (3-i)*4   );
                IF (byte_val < 10)
                    cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
                ELSEIF (byte_val == 10)
                    cv_message = ASCII_APPEND (cv_message,"A");
                ELSEIF (byte_val == 11)
                    cv_message = ASCII_APPEND (cv_message,"B");
                ELSEIF (byte_val == 12)
                    cv_message = ASCII_APPEND (cv_message,"C");
                ELSEIF (byte_val == 13)
                    cv_message = ASCII_APPEND (cv_message,"D");
                ELSEIF (byte_val == 14)
                    cv_message = ASCII_APPEND (cv_message,"E");
                ELSEIF (byte_val == 15)
                    cv_message = ASCII_APPEND (cv_message,"F");
                ELSE
                    cv_message = ASCII_APPEND (cv_message,"?");
                ENDIF
            ENDFOR
        ENDIF
    ENDIF

ELSE

    n_words-- ;
    word_cnt++;
    cmd_err_code = -1;

    IF (class == 2 && sub_class == 0)
        sub_class_def = "RPLY_MSG_CNT";
        cv_message = "Word ";
        cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(word_cnt));
        IF (mem_data_type == 0 && word_cnt == 2)
            /* cv_message = ASCII_APPEND (cv_message,", Logical Memory Address = 0x"); (fixed 3-4-96) */
            cv_message = ASCII_APPEND (cv_message,", Memory Address = 0x");
            DERIVE("U-1027",null_data);
            DERIVE("U-1028",null_data);
            DERIVE("U-1029",null_data);
            DERIVE("U-1030",null_data);
        ELSEIF (mem_data_type == 1 && word_cnt == 2)
            cv_message = ASCII_APPEND (cv_message,", CIU/CIX Buffer Address = 0x");
        ELSEIF (mem_data_type == 0 && word_cnt > 2)
            cv_message = ASCII_APPEND (cv_message,", Memory Data = 0x");
            IF (word_cnt == 3)
                 DERIVE("U-1028",cv_word);
            ELSEIF (word_cnt == 4)
                 DERIVE("U-1029",cv_word);
            ELSEIF (word_cnt == 5)
                 DERIVE("U-1030",cv_word);
            ENDIF
        ELSEIF (mem_data_type == 1 && word_cnt > 2)
            cv_message = ASCII_APPEND (cv_message,", IPR Data = 0x");
        ENDIF
        IF (word_cnt == 2)
            /* script_add = ((cv_word & 0x07FF) + (physical_page << 11)); (fixed 3-4-96) */
            script_add = cv_word;
            DERIVE("U-1027",cv_word);
        ELSE
            script_add = cv_word;
        ENDIF
        FOR (i=0; i<=3; i++)
            byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
            IF (byte_val < 10)
                cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
            ELSEIF (byte_val == 10)
                cv_message = ASCII_APPEND (cv_message,"A");
            ELSEIF (byte_val == 11)
                cv_message = ASCII_APPEND (cv_message,"B");
            ELSEIF (byte_val == 12)
                cv_message = ASCII_APPEND (cv_message,"C");
            ELSEIF (byte_val == 13)
                cv_message = ASCII_APPEND (cv_message,"D");
            ELSEIF (byte_val == 14)
                cv_message = ASCII_APPEND (cv_message,"E");
            ELSEIF (byte_val == 15)
                cv_message = ASCII_APPEND (cv_message,"F");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"?");
            ENDIF
        ENDFOR

    ELSEIF (class == 2 && sub_class == 6)
        sub_class_def = "MSNG_BLK_CNT";
        cv_message = "Word ";
        cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(word_cnt));
        IF (word_cnt == 2)
            cv_message = ASCII_APPEND (cv_message,", Table Address = 0x");
        ELSE
            cv_message = ASCII_APPEND (cv_message,", Scoreboard Word ");
            cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(word_cnt - 2));
            cv_message = ASCII_APPEND (cv_message," = 0x");
        ENDIF
        script_add = cv_word;
        FOR (i=0; i<=3; i++)
            byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
            IF (byte_val < 10)
                cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
            ELSEIF (byte_val == 10)
                cv_message = ASCII_APPEND (cv_message,"A");
            ELSEIF (byte_val == 11)
                cv_message = ASCII_APPEND (cv_message,"B");
            ELSEIF (byte_val == 12)
                cv_message = ASCII_APPEND (cv_message,"C");
            ELSEIF (byte_val == 13)
                cv_message = ASCII_APPEND (cv_message,"D");
            ELSEIF (byte_val == 14)
                cv_message = ASCII_APPEND (cv_message,"E");
            ELSEIF (byte_val == 15)
                cv_message = ASCII_APPEND (cv_message,"F");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"?");
            ENDIF
        ENDFOR
    ELSEIF (class == 2 && sub_class == 8)
        sub_class_def = "CHECKSUM_CNT";
        cv_message = "Word ";
        cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(word_cnt));
        IF (word_cnt == 2)
            cv_message = ASCII_APPEND (cv_message,", Checksum Value = 0x");
            DERIVE("U-1024",cv_word);
        ELSEIF (word_cnt == 3)
            cv_message = ASCII_APPEND (cv_message,", Physical Memory Address (MHS) = 0x");
            DERIVE("U-1025",cv_word);
        ELSEIF (word_cnt == 4)
            cv_message = ASCII_APPEND (cv_message,", Physical Memory Address (LHS) = 0x");
            DERIVE("U-1026",cv_word);
        ENDIF
        script_add = cv_word;
        FOR (i=0; i<=3; i++)
            byte_val = ((script_add & (0xF000/((0x10)**i))) >> (3-i)*4   );
            IF (byte_val < 10)
                cv_message = ASCII_APPEND (cv_message,ANY_TO_ASCII(byte_val));
            ELSEIF (byte_val == 10)
                cv_message = ASCII_APPEND (cv_message,"A");
            ELSEIF (byte_val == 11)
                cv_message = ASCII_APPEND (cv_message,"B");
            ELSEIF (byte_val == 12)
                cv_message = ASCII_APPEND (cv_message,"C");
            ELSEIF (byte_val == 13)
                cv_message = ASCII_APPEND (cv_message,"D");
            ELSEIF (byte_val == 14)
                cv_message = ASCII_APPEND (cv_message,"E");
            ELSEIF (byte_val == 15)
                cv_message = ASCII_APPEND (cv_message,"F");
            ELSE
                cv_message = ASCII_APPEND (cv_message,"?");
            ENDIF
        ENDFOR
    ENDIF

ENDIF


DERIVE("U-1011",class_def);
DERIVE("U-1013",sub_class_def);

/* Pad cv_message with blanks */
length = ASCII_LENGTH(cv_message);
FOR (i=length; i<=61; i=i+12)
    cv_message = ASCII_APPEND (cv_message,"            ");
ENDFOR

DERIVE("U-1015",ASCII_SLICE(cv_message, 0,12));
DERIVE("U-1016",ASCII_SLICE(cv_message,12,12));
DERIVE("U-1017",ASCII_SLICE(cv_message,24,12));
DERIVE("U-1018",ASCII_SLICE(cv_message,36,12));
DERIVE("U-1019",ASCII_SLICE(cv_message,48,12));
IF (cmd_err_code < 0)
    DERIVE("U-1021",0);
    DERIVE("U-1022","      CMD_OK");
ELSE
    DERIVE("U-1021",cmd_err_code);
    IF (cmd_err_code >= 0 && cmd_err_code < 16)
        IF (cmd_err_code == 0)
            DERIVE("U-1022","      CMD_OK");
        ELSEIF (cmd_err_code == 1)
            DERIVE("U-1022"," SEQ_NUM_ERR");
        ELSEIF (cmd_err_code == 2)
            DERIVE("U-1022","  UPLINK_ERR");
        ELSEIF (cmd_err_code == 3)
            DERIVE("U-1022","BLCK_CRC_ERR");
        ELSEIF (cmd_err_code == 4)
            DERIVE("U-1022","UNEXP_CMDfrm");
        ELSEIF (cmd_err_code == 5)
            DERIVE("U-1022","CIU_CMD_EXPT");
        ELSEIF (cmd_err_code == 6)
            DERIVE("U-1022","ILLGL_DATAfr");
        ELSEIF (cmd_err_code == 7)
            DERIVE("U-1022","UNEXP_DATAfr");
        ELSEIF (cmd_err_code == 8)
            DERIVE("U-1022","2MANY_DATAfr");
        ELSEIF (cmd_err_code == 9)
            DERIVE("U-1022","U/L_STAT_ERR");
        ELSEIF (cmd_err_code == 10)
            DERIVE("U-1022","CIU_CMD_REJD");
        ELSEIF (cmd_err_code == 11)
            DERIVE("U-1022","INVL_CMD_TYP");
        ELSEIF (cmd_err_code == 12)
            DERIVE("U-1022","INVL_CMD_NUM");
        ELSEIF (cmd_err_code == 14)
            DERIVE("U-1022","INVL_SUBTYPE");
        ELSEIF (cmd_err_code == 15)
            DERIVE("U-1022","INVL_SUB_NUM");
        ELSE
            DERIVE("U-1022","*NOT_DEFINED");
        ENDIF
    ELSEIF (cmd_err_code >= 16 && cmd_err_code < 32)
        IF (cmd_err_code == 16)
            DERIVE("U-1022","INSUF_DATA_W");
        ELSEIF (cmd_err_code == 17)
            DERIVE("U-1022","EXCES_DATA_W");
        ELSEIF (cmd_err_code == 18)
            DERIVE("U-1022"," S/S_Q_ERROR");
        ELSEIF (cmd_err_code == 19)
            DERIVE("U-1022","CMD_NOT_ACTV");
        ELSEIF (cmd_err_code == 20)
            DERIVE("U-1022","StrCMD!ALLOW");
        ELSEIF (cmd_err_code == 21)
            DERIVE("U-1022","PLS_DIS_Q_ER");
        ELSEIF (cmd_err_code == 22)
            DERIVE("U-1022","INV_WORD_CNT");
        ELSEIF (cmd_err_code == 23)
            DERIVE("U-1022","INV_LOAD_ADD");
        ELSEIF (cmd_err_code == 24)
            DERIVE("U-1022","S/S_CMD_REJC");
        ELSEIF (cmd_err_code == 25)
            DERIVE("U-1022","ILGL_CMD_SRC");
        ELSEIF (cmd_err_code == 26)
            DERIVE("U-1022","ILGL_BLK_NUM");
        ELSEIF (cmd_err_code == 27)
            DERIVE("U-1022","Mload_NO_PRG");
        ELSEIF (cmd_err_code == 28)
            DERIVE("U-1022","Mload_INCMPL");
        ELSEIF (cmd_err_code == 30)
            DERIVE("U-1022","SERIAL_IO_TO");
        ELSEIF (cmd_err_code == 31)
            DERIVE("U-1022","INVL_BUF_IND");
        ELSE
            DERIVE("U-1022","*NOT_DEFINED");
        ENDIF
    ELSEIF (cmd_err_code >= 32 && cmd_err_code < 48)
        IF (cmd_err_code == 32)
            DERIVE("U-1022","StrdCMD2LATE");
        ELSEIF (cmd_err_code == 33)
            DERIVE("U-1022","ScrpBUF_FAIL");
        ELSEIF (cmd_err_code == 34)
            DERIVE("U-1022","FineTimeExpc");
        ELSEIF (cmd_err_code == 35)
            DERIVE("U-1022","ILLEG_DW_CNT");
        ELSEIF (cmd_err_code == 36)
            DERIVE("U-1022","ILLEG_ADDRES");
        ELSEIF (cmd_err_code == 37)
            DERIVE("U-1022","TimeTag_EXPC");
        ELSEIF (cmd_err_code == 38)
            DERIVE("U-1022","ILLEGwordCNT");
        ELSEIF (cmd_err_code == 39)
            DERIVE("U-1022","SCRIPT!FOUND");
        ELSEIF (cmd_err_code == 40)
            DERIVE("U-1022","SCRPTalrdyAC");
        ELSEIF (cmd_err_code == 41)
            DERIVE("U-1022"," LOADnotACTV");
        ELSEIF (cmd_err_code == 42)
            DERIVE("U-1022","MODEtag!EXPC");
        ELSEIF (cmd_err_code == 43)
            DERIVE("U-1022","MODEtagEXPEC");
        ELSEIF (cmd_err_code == 44)
            DERIVE("U-1022","INVL_ARGMENT");
        ELSEIF (cmd_err_code == 45)
            DERIVE("U-1022","2MANYactSCRT");
        ELSEIF (cmd_err_code == 46)
            DERIVE("U-1022","EPHMloadWARN");
        ELSEIF (cmd_err_code == 47)
            DERIVE("U-1022","STRXloadWARN");
        ELSE
            DERIVE("U-1022","*NOT_DEFINED");
        ENDIF
    ENDIF
    IF (cmd_err_code >= 48 )
        IF (cmd_err_code == 48)
            DERIVE("U-1022","CNTGNCY_MODE");
        ELSEIF (cmd_err_code == 49)
            DERIVE("U-1022","ACTscriptRNG");
        ELSEIF (cmd_err_code == 50)
            DERIVE("U-1022","PWRcmdREJECT");
        ELSEIF (cmd_err_code == 51)
            DERIVE("U-1022","INVredmanDEV");
        ELSEIF (cmd_err_code == 52)
            DERIVE("U-1022","    CENSORED");
        ELSEIF (cmd_err_code == 53)
            DERIVE("U-1022","MiniSeq_STOP");
        ELSEIF (cmd_err_code == 62)
            DERIVE("U-1022"," REPLY_WORDS");
        ELSEIF (cmd_err_code == 63)
            DERIVE("U-1022","CV_Q_OVERFLW");
        ELSEIF (cmd_err_code == 64 )
            DERIVE("U-1022","MEM_READ_ERR");
        ELSE
            DERIVE("U-1022","*NOT_DEFINED");
        ENDIF
    ENDIF

ENDIF


ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-1115 "POBimgCIU246" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 05-08-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-3001
Description:            Uplink Processor 1 Indicator
Mnemonic:               UPLNK_PROC_1
Subsystem:              TLCM
Data_Type:              STATUS
States:                 BOTH,CDU1,CDU2,BOTH

Derived Channel:        U-3002
Description:            Uplink Processor 2 Indicator
Mnemonic:               UPLNK_PROC_2
Subsystem:              TLCM
Data_Type:              STATUS
States:                 BOTH,CDU1,CDU2,BOTH



*/

CHILD = "U-3001" PARENTS = "N-1115";
CHILD = "U-3002" PARENTS = "N-1115";

FUNCT CHAN = "N-1115"

DERIVE ("U-3001", ((GET_DN() & 0x1000) >> 12) + ((GET_DN() & 0x0800) >> 10));
DERIVE ("U-3002", ((GET_DN() & 0x0010) >>  4) + ((GET_DN() & 0x0001) <<  1));

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-1414 "SCP_FRAME_ID" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 05-15-95                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*


Derived Channel:        U-1414
Description:            QUERY SCP TELEMETRY SYNC FLAG (IDEOSYCRACY WITH CHANNEL ORDER BETWEEN RT/QUERY)
Mnemonic:               QRY_SCP_SYNC
Subsystem:              CDH
Data_Type:              STATUS
States:                 Cannot_Detrm,IN_SYNC,NO_SYNC

Derived Channel:        U-1415
Description:            REAL TIME SCP TELEMETRY SYNC FLAG
Mnemonic:               RT_SCP_SYNC
Subsystem:              CDH
Data_Type:              STATUS
States:                 Cannot_Detrm,IN_SYNC,NO_SYNC



*/

CHILD = "U-1414" PARENTS = "H-0026""H-0025""C-0002""N-1414";

FUNCT CHAN = "N-1414"

UINT currID,mode,sync,edffr,cscp;

IF (DN_VALID("H-0025")==0 && DN_VALID("H-0026")==0 && DN_VALID("C-0002")==0)

    currID = GET_DN();
    mode   = GET_LAD_DN("H-0025");
    edffr  = GET_LAD_DN("H-0026");
    cscp   = GET_LAD_DN("C-0002");
    sync   = 0;

    IF (mode==0 OR mode==1)    /*emerg or missn*/
      sync=sync+1;
      IF ((edffr != currID) AND (edffr != currID+32))
        sync=sync+1;
      ENDIF
    ELSEIF (mode==2)              /*engineering*/
      IF (cscp == 1)  /*SCP1 ctl*/
        sync=sync+1;
        IF (edffr != (currID*2 + 1))
          sync=sync+1;
        ENDIF
      ELSEIF (cscp == 0)  /*SCP2 ctl*/
        sync=sync+1;
        IF (edffr != (currID*2))
          sync=sync+1;
        ENDIF
      ENDIF
    ENDIF

    DERIVE("U-1414",sync);
    DERIVE("U-1415",sync);

ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-2001 "BAT1_ASOC" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-2205
Description:            Battery 1 State of Charge Based battery 1 ASOC (in coulombs (amp-sec))
Mnemonic:               BAT1_PerASOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "U-2205" PARENTS = "N-2001";

FUNCT CHAN = "N-2001"

/* Divide by 720.00 to get percent sate of chage (full battery =72000 coulombs) */
DERIVE ("U-2205", GET_EU() / 720.00);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-2002 "BAT1_TSOC" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-2206
Description:            Battery 1 State of Charge Based battery 1 TSOC (in coulombs (amp-sec))
Mnemonic:               BAT1_PerTSOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "U-2206" PARENTS = "N-2002";

FUNCT CHAN = "N-2002"

/* Divide by 720.00 to get percent sate of chage (full battery =72000 coulombs) */
DERIVE ("U-2206", GET_EU() / 720.00);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-2051 "BAT2_ASOC" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-2207
Description:            Battery 2 State of Charge Based battery 2 ASOC (in coulombs (amp-sec))
Mnemonic:               BAT2_PerASOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "U-2207" PARENTS = "N-2051";

FUNCT CHAN = "N-2051"

/* Divide by 720.00 to get percent sate of chage (full battery =72000 coulombs) */
DERIVE ("U-2207", GET_EU() / 720.00);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * N-2052 "BAT2_TSOC" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 2-13-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        U-2208
Description:            Battery 2 State of Charge Based battery 2 TSOC (in coulombs (amp-sec))
Mnemonic:               BAT2_PerTSOC
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  SOC

*/

CHILD = "U-2208" PARENTS = "N-2052";

FUNCT CHAN = "N-2052"

/* Divide by 720.00 to get percent sate of chage (full battery =72000 coulombs) */
DERIVE ("U-2208", GET_EU() / 720.00);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * I-0003 "MAG_A_PWR" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load value                       *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2040
Description:            MAG A Estimated Power
Mnemonic:               MAG_A_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2040" PARENTS = "I-0003";

FUNCT CHAN = "I-0003"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2040",  3.22);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2040",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * I-0004 "MAG_B_PWR" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2041
Description:            MAG B Estimated Power
Mnemonic:               MAG_B_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2041" PARENTS = "I-0004";

FUNCT CHAN = "I-0004"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2041",  4.63);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2041",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * I-0006 "MR_TRANS_ST" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2042
Description:            MR Estimated Power
Mnemonic:               MR_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2042" PARENTS = "I-0006""I-0005";

FUNCT CHAN = "I-0006"

IF (DN_VALID("I-0005") == 0)
    IF (GET_DN() == 0 && GET_LAD_DN("I-0005") == 0)  /* Check channel status (0 = On) */
        DERIVE ("V-2042", 10.00);  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-2042",  0.00);  /* If off, set off power consumption */
    ENDIF
ELSE
    RETURN;
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * I-0010 "MOC_A_PWR" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2043
Description:            MOC A Estimated Power
Mnemonic:               MOC_A_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2043" PARENTS = "I-0010";

FUNCT CHAN = "I-0010"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2043", 13.50);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2043",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * I-0011 "MOC_B_PWR" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2044
Description:            MOC B Estimated Power
Mnemonic:               MOC_B_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2044" PARENTS = "I-0011";

FUNCT CHAN = "I-0011"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2044", 13.50);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2044",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * I-0014 "MOLA_PWR" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load value                       *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3900
Description:            MOLA Derived Power Status
Mnemonic:               MOLA_PWR_ST
Subsystem:              PYLD
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        V-2046
Description:            MOLA Estimated Power
Mnemonic:               MOLA_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-3900" PARENTS = "I-0014""I-0012""I-0013";
CHILD = "V-2046" PARENTS = "I-0014""I-0012""I-0013";

FUNCT CHAN = "I-0014"


IF (DN_VALID("I-0012") == 0 && DN_VALID("I-0013") == 0)
    IF (GET_DN() == 0 && GET_LAD_DN("I-0012") == 0 && GET_LAD_DN("I-0013") == 0)
        DERIVE ("V-3900", 1);  /* If on, set on state                   */
        DERIVE ("V-2046", 30.94);  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-3900", 0);  /* If off, set off state                 */
        DERIVE ("V-2046",  0.00);  /* If off, set off power consumption */
    ENDIF
ELSE
    RETURN;
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * I-0015 "TES_PWR" TRIGGER CHANNEL CODE                                     *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load value                       *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2047
Description:            TES Estimated Power
Mnemonic:               TES_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2047" PARENTS = "I-0015";

FUNCT CHAN = "I-0015"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2047", 15.55);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2047",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * L-0032 "MOT1_EXCITER" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2030
Description:            MOT1 Exciter Estimated Power
Mnemonic:               MOT1_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2030" PARENTS = "L-0032";

FUNCT CHAN = "L-0032"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2030",  4.10);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2030",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * L-0042 "MOT2_EXCITER" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2031
Description:            MOT2 Exciter Estimated Power
Mnemonic:               MOT2_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2031" PARENTS = "L-0042";

FUNCT CHAN = "L-0042"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2031",  4.10);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2031",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * L-0060 "TWTA1_FILMNT" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2032
Description:            TWTA1 Filament Estimated Power
Mnemonic:               TWTA1_FIL_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2032" PARENTS = "L-0060";

FUNCT CHAN = "L-0060"

IF (GET_DN() == 1)             /* Check channel status (1 = On)     */
    DERIVE ("V-2032",  4.00);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2032",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * L-0061 "TWTA1_FILMNT" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2033
Description:            TWTA1 High Volatage Estimated Power
Mnemonic:               TWTA1_HV_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2033" PARENTS = "L-0061""L-0060";

FUNCT CHAN = "L-0061"

IF (DN_VALID("L-0060") == 0)
    IF (GET_DN() == 0 && GET_LAD_DN("L-0060") == 1)
        DERIVE ("V-2033", 55.10);  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-2033",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * L-0070 "TWTA2_FILMNT" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2034
Description:            TWTA2 Filament Estimated Power
Mnemonic:               TWTA2_FIL_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2034" PARENTS = "L-0070";

FUNCT CHAN = "L-0070"

IF (GET_DN() == 1)             /* Check channel status (1 = On)     */
    DERIVE ("V-2034",  4.00);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2034",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * L-0071 "TWTA2_FILMNT" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2035
Description:            TWTA2 High Volatage Estimated Power
Mnemonic:               TWTA2_HV_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2035" PARENTS = "L-0071""L-0070";

FUNCT CHAN = "L-0071"

IF (DN_VALID("L-0070") == 0)
    IF (GET_DN() == 0 && GET_LAD_DN("L-0070") == 1)
        DERIVE ("V-2035", 55.10);  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-2035",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * L-0080 "USO_PWR" TRIGGER CHANNEL CODE                                     *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load value                       *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2048
Description:            USO Estimated Power
Mnemonic:               USO_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2048" PARENTS = "L-0080";

FUNCT CHAN = "L-0080"

IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
    DERIVE ("V-2048",  2.60);  /* If on, set on power consumption   */
ELSE
    DERIVE ("V-2048",  0.00);  /* If off, set off power consumption */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * L-0090 "KaBLE_STAT" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Modified load value                     *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2036
Description:            KaBLE Estimated Power
Mnemonic:               KaBLE_EST_P
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2036" PARENTS = "L-0090""L-0091";

FUNCT CHAN = "L-0090"

IF (DN_VALID("L-0091") == 0)
    IF ((GET_DN() == 1) && (GET_LAD_DN("L-0091") == 0))  /* Check channel status (1=On/0=En) */
        DERIVE ("V-2036", 19.90);  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-2036",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0025 "ME_FLNG_A_ON" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2063
Description:            Main Engine Flange A Heater Estimated Power
Mnemonic:               ME_FLNG_A_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2063" PARENTS = "P-0025""P-0024";

FUNCT CHAN = "P-0025"

IF (DN_VALID("P-0024") == 0 )
    IF (GET_DN() == 0  && GET_LAD_DN("P-0024") == 0) /* Check channel status (0 = On) */
        DERIVE ("V-2063", 12.80);  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-2063",  0.00);  /* If off, set off power consumption */
    ENDIF
ELSE
    RETURN;
ENDIF
ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0027 "ME_FLNG_B_ON" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2064
Description:            Main Engine Flange B Heater Estimated Power
Mnemonic:               ME_FLNG_B_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2064" PARENTS = "P-0027""P-0026";

FUNCT CHAN = "P-0027"

IF (DN_VALID("P-0026") == 0 )
    IF (GET_DN() == 0  && GET_LAD_DN("P-0026") == 0) /* Check channel status (0 = On) */
        DERIVE ("V-2064", 12.80);  /* If on, set on power consumption   */
    ELSE
        DERIVE ("V-2064",  0.00);  /* If off, set off power consumption */
    ENDIF
ELSE
    RETURN;
ENDIF
ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0031 "THR_CB_01_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2051
Description:            Thruster 01 Cat-Bed Estimated Power
Mnemonic:               THR_CB_01_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2051" PARENTS = "P-0031""P-0044";

FUNCT CHAN = "P-0031"

IF (DN_VALID("P-0044") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0044") == 0)
            DERIVE ("V-2051",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2051",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2051",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0032 "THR_CB_02_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2052
Description:            Thruster 02 Cat-Bed Estimated Power
Mnemonic:               THR_CB_02_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2052" PARENTS = "P-0032""P-0043";

FUNCT CHAN = "P-0032"

IF (DN_VALID("P-0043") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0043") == 0)
            DERIVE ("V-2052",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2052",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2052",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0033 "THR_CB_03_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2053
Description:            Thruster 03 Cat-Bed Estimated Power
Mnemonic:               THR_CB_03_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2053" PARENTS = "P-0033""P-0044";

FUNCT CHAN = "P-0033"

IF (DN_VALID("P-0044") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0044") == 0)
            DERIVE ("V-2053",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2053",  1.92 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2053",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0034 "THR_CB_04_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2054
Description:            Thruster 04 Cat-Bed Estimated Power
Mnemonic:               THR_CB_04_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2054" PARENTS = "P-0034""P-0043";

FUNCT CHAN = "P-0034"

IF (DN_VALID("P-0043") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0043") == 0)
            DERIVE ("V-2054",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2054",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2054",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0035 "THR_CB_05_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2055
Description:            Thruster 05 Cat-Bed Estimated Power
Mnemonic:               THR_CB_05_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2055" PARENTS = "P-0035""P-0044";

FUNCT CHAN = "P-0035"

IF (DN_VALID("P-0044") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0044") == 0)
            DERIVE ("V-2055",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2055",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2055",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0036 "THR_CB_06_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2056
Description:            Thruster 06 Cat-Bed Estimated Power
Mnemonic:               THR_CB_06_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2056" PARENTS = "P-0036""P-0043";

FUNCT CHAN = "P-0036"

IF (DN_VALID("P-0043") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0043") == 0)
            DERIVE ("V-2056",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2056",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2056",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0037 "THR_CB_07_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2057
Description:            Thruster 07 Cat-Bed Estimated Power
Mnemonic:               THR_CB_07_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2057" PARENTS = "P-0037""P-0044";

FUNCT CHAN = "P-0037"

IF (DN_VALID("P-0044") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0044") == 0)
            DERIVE ("V-2057",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2057",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2057",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0038 "THR_CB_08_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2058
Description:            Thruster 08 Cat-Bed Estimated Power
Mnemonic:               THR_CB_08_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2058" PARENTS = "P-0038""P-0043";

FUNCT CHAN = "P-0038"

IF (DN_VALID("P-0043") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0043") == 0)
            DERIVE ("V-2058",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2058",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2058",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0039 "THR_CB_09_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2059
Description:            Thruster 09 Cat-Bed Estimated Power
Mnemonic:               THR_CB_09_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2059" PARENTS = "P-0039""P-0044";

FUNCT CHAN = "P-0039"

IF (DN_VALID("P-0044") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0044") == 0)
            DERIVE ("V-2059",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2059",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2059",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0040 "THR_CB_10_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2060
Description:            Thruster 10 Cat-Bed Estimated Power
Mnemonic:               THR_CB_10_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2060" PARENTS = "P-0040""P-0043";

FUNCT CHAN = "P-0040"

IF (DN_VALID("P-0043") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0043") == 0)
            DERIVE ("V-2060",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2060",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2060",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0041 "THR_CB_11_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2061
Description:            Thruster 11 Cat-Bed Estimated Power
Mnemonic:               THR_CB_11_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2061" PARENTS = "P-0041""P-0043";

FUNCT CHAN = "P-0041"

IF (DN_VALID("P-0043") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0043") == 0)
            DERIVE ("V-2061",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2061",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2061",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * P-0042 "THR_CB_12_EN" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:             OGS 7-26-97 Update load values                      *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2062
Description:            Thruster 12 Cat-Bed Estimated Power
Mnemonic:               THR_CB_12_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2062" PARENTS = "P-0042""P-0044";

FUNCT CHAN = "P-0042"

IF (DN_VALID("P-0044") == 0)
    IF (GET_DN() == 0)             /* Check channel status (0 = On)     */
        IF (GET_LAD_DN("P-0044") == 0)
            DERIVE ("V-2062",  3.86 );  /* If on, set on power consumption   */
        ELSE
            DERIVE ("V-2062",  1.93 );  /* If on, set on power consumption   */
        ENDIF
    ELSE
        DERIVE ("V-2062",  0.00);  /* If off, set off power consumption */
    ENDIF
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * P-0106 "N2H4_OUT_PRS" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 6-25-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3420
Description:            Thruster Isp
Mnemonic:               THR_Isp
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  sec

Derived Channel:        V-3421
Description:            Thruster Thrust in lbf
Mnemonic:               THR_Thrust
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  lbf

Derived Channel:        V-3422
Description:            Thruster Thrust in newtons
Mnemonic:               THR_Thrust_N
Subsystem:              PROP
Data_Type:              FLOAT
Units:                  N


*/

CHILD = "V-3420" PARENTS = "P-0104""P-0106""T-0180""T-0183";
CHILD = "V-3421" PARENTS = "P-0104""P-0106""T-0180""T-0183";
CHILD = "V-3422" PARENTS = "P-0104""P-0106""T-0180""T-0183";

FUNCT CHAN = "P-0106"

FLT P_F,T_F,ISP,THRUST,FUDGE;

/*
Variable Description

P_F       = Average Fuel Tank Pressure
T_F       = Average Fuel Tank Temperature
ISP       = Thruster Computed Isp in seconds
THRUST    = Thruster Computed Thrust in lbf
FUDGE     = Fudge Factor to Degrade Isp for Pulse Mode Operations

*/

IF (EU_VALID("T-0180") == 0 && EU_VALID("T-0183") == 0 && EU_VALID("P-0104") == 0)
    P_F = (GET_LAD_EU("P-0104") + GET_EU()) / 2.0;
    T_F = (GET_LAD_EU("T-0180") + GET_LAD_EU("T-0183")) / 2.0;
    FUDGE = 0.8;
    ISP = FUDGE * ((P_F / (0.027258 + 0.0042958 * P_F)) - (0.1563 * ( 20.0 - T_F)));
    THRUST = 0.0026 * P_F + 0.14;
    DERIVE ("V-3420", ISP);
    DERIVE ("V-3421", THRUST);
    DERIVE ("V-3422", THRUST * 4.45);
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0053 "MOC_BKOT_SW2" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 8-01-95                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2501
Description:            MOC Bakeout Heater Power Status
Mnemonic:               MOC_BKOT_HTR
Subsystem:              THRM
Data_Type:              STATUS
States:                 OFF,ON

Derived Channel:        V-2045
Description:            MOC Bakeout Heater Power Estimate
Mnemonic:               MOC_BKOT_EP
Subsystem:              PWR
Data_Type:              FLOAT
Units:                  watts

*/

CHILD = "V-2501" PARENTS = "T-0053""T-0052";
CHILD = "V-2045" PARENTS = "T-0053""T-0052";

FUNCT CHAN = "T-0053"

/* Derive MOC Bakeout Heater Status from MOC Bakeout Switches 1 & 2
      SW1       SW2     BKOT_HTR
       0         0         ON
       0         1         OFF
       1         0         OFF
       1         1         ON
*/

IF (DN_VALID("T-0052") == 0)
    IF    (GET_LAD_DN("T-0052") == 0 && GET_DN() == 0)
        DERIVE ("V-2501",1);
        DERIVE ("V-2045", 52.60);  /* If on, set on power consumption  */
    ELSEIF(GET_LAD_DN("T-0052") == 1 && GET_DN() == 1)
        DERIVE ("V-2501",1);
        DERIVE ("V-2045", 52.60);  /* If on, set on power consumption  */
    ELSEIF(GET_LAD_DN("T-0052") == 0 && GET_DN() == 1)
        DERIVE ("V-2501",0);
        DERIVE ("V-2045",  0.00);  /* If on, set on power consumption  */
    ELSEIF(GET_LAD_DN("T-0052") == 1 && GET_DN() == 0)
        DERIVE ("V-2501",0);
        DERIVE ("V-2045",  0.00);  /* If on, set on power consumption  */
    ELSE
        RETURN;
    ENDIF
ELSE
    RETURN;
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0103 "MHSA_S1_T" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the MHSA_S1_T
if the heater status A-0013 MHSA1_PWR indicates 1 "OFF"

*/

CHILD = "T-0103" PARENTS = "A-0013";

FUNCT CHAN = "T-0103"

IF (DN_VALID("A-0013") == 0)
    IF (GET_LAD_DN("A-0013") == 1)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0104 "MHSA_S2_T" TRIGGER CHANNEL CODE                                   *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the MHSA_S2_T
if the heater status A-0014 MHSA2_PWR indicates 1 "OFF"

*/

CHILD = "T-0104" PARENTS = "A-0014";

FUNCT CHAN = "T-0104"

IF (DN_VALID("A-0014") == 0)
    IF (GET_LAD_DN("A-0014") == 1)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0106 "RWA_X_BRG_T" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the RWA_X_BRG_T
if the heater status F-0763 RWA_X_PWR_ST indicates 0 "OFF"

*/

CHILD = "T-0106" PARENTS = "F-0763";

FUNCT CHAN = "T-0106"

IF (DN_VALID("F-0763") == 0)
    IF (GET_LAD_DN("F-0763") == 0)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0107 "RWA_Y_BRG_T" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the RWA_Y_BRG_T
if the heater status F-0773 RWA_Y_PWR_ST indicates 0 "OFF"

*/

CHILD = "T-0107" PARENTS = "F-0773";

FUNCT CHAN = "T-0107"

IF (DN_VALID("F-0773") == 0)
    IF (GET_LAD_DN("F-0773") == 0)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0108 "RWA_Z_BRG_T" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the RWA_Z_BRG_T
if the heater status F-0783 RWA_Z_PWR_ST indicates 0 "OFF"

*/

CHILD = "T-0108" PARENTS = "F-0783";

FUNCT CHAN = "T-0108"

IF (DN_VALID("F-0783") == 0)
    IF (GET_LAD_DN("F-0783") == 0)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0109 "RWA_S_BRG_T" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the RWA_S_BRG_T
if the heater status F-0793 RWA_S_PWR_ST indicates 0 "OFF"

*/

CHILD = "T-0109" PARENTS = "F-0793";

FUNCT CHAN = "T-0109"

IF (DN_VALID("F-0793") == 0)
    IF (GET_LAD_DN("F-0793") == 0)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * T-0164 "PRES_CNTL1_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 01-30-97                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2502
Description:            Delta-T Temperature
Mnemonic:               DELTA_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  Deg-C

*/

CHILD = "V-2502" PARENTS = "T-0164""T-0165""T-0166""T-0168""T-0169""T-0174""T-0175""T-0186""T-0188""T-0189""T-0266""T-0267""T-0178""T-0179""T-0180""T-0181""T-0182""T-0183";

FUNCT CHAN = "T-0164"

STATIC INT PASSES=0;
FLT MIN_VAL,MAX_VAL;

IF (DN_VALID("T-0165") == 0 && DN_VALID("T-0166") == 0)

    MIN_VAL = MIN(GET_EU(),GET_LAD_EU("T-0165"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0168"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0169"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0174"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0175"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0186"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0188"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0189"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0266"));
    MIN_VAL = MIN(MIN_VAL,GET_LAD_EU("T-0267"));

    MAX_VAL = MAX(GET_LAD_EU("T-0178"),GET_LAD_EU("T-0179"));
    MAX_VAL = MAX(MAX_VAL,GET_LAD_EU("T-0180"));
    MAX_VAL = MAX(MAX_VAL,GET_LAD_EU("T-0181"));
    MAX_VAL = MAX(MAX_VAL,GET_LAD_EU("T-0182"));
    MAX_VAL = MAX(MAX_VAL,GET_LAD_EU("T-0183"));

    DERIVE ("V-2502",(MIN_VAL - MAX_VAL));

ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0210 "SA+Y_INR_F_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 4-30-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2510
Description:            Solar Array +Y INNER FRONT Heating Rate
Mnemonic:               SA+Y_IF_HR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2520
Description:            Solar Array +Y INNER FRONT Peak Heating Rate
Mnemonic:               SA+Y_IF_PKHR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2530
Description:            Solar Array +Y INNER FRONT Peak Temperature
Mnemonic:               SA+Y_IF_PK_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC

*/

CHILD = "V-2510" PARENTS = "H-0017""T-0210";
CHILD = "V-2520" PARENTS = "H-0017""T-0210";
CHILD = "V-2530" PARENTS = "H-0017""T-0210";

FUNCT CHAN = "T-0210"

INT i,samples;
FLT slope,s1sqr,sumxy,sumx,sumy,sumxx,x_bar,y_bar;
STATIC INT pointer=0,old_samples=0,epoch=0,cycles=0;
STATIC FLT peak_temp=-200.0;
STATIC FLT datapoints[32]=0.0,timepoints[32]=0.0;

/* Determine sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart function */
IF (samples != old_samples  || (DN_VALID("V-2520") != 0) )
    pointer = 0;
    cycles = 0;
    old_samples = samples;
    epoch = GET_LAD_DN("H-0017") - 4;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();
timepoints[pointer] = (FLT)(GET_LAD_DN("H-0017") - epoch);

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
sumxy = 0.0;
sumx = 0.0;
sumxx = 0.0;
sumy = 0.0;
FOR (i = 0; i <= samples-1; i++)
    sumxy = sumxy + (timepoints[i] * datapoints[i]);
    sumx = sumx + timepoints[i];
    sumxx = sumxx + timepoints[i]**2;
    sumy = sumy + datapoints[i];
ENDFOR

/* compute slope */
slope = (samples * sumxy - sumx*sumy) / (samples * sumxx - sumx**2);
slope = slope * 60.0;

IF (cycles++ > samples)
    cycles = samples;
    DERIVE ("V-2510",slope);
    IF (slope > GET_LAD_DN("V-2520"))
        DERIVE ("V-2520",slope);
    ENDIF
ELSE
    DERIVE ("V-2510",0.0);
    DERIVE ("V-2520",0.0);
ENDIF

/* find peak temperature */
IF (GET_EU() > peak_temp)
    peak_temp = GET_EU();
    DERIVE ("V-2530",peak_temp);
ENDIF





ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0211 "SA+Y_INR_B_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 4-30-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2511
Description:            Solar Array +Y INNER BACK Heating Rate
Mnemonic:               SA+Y_IB_HR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2521
Description:            Solar Array +Y INNER BACK Peak Heating Rate
Mnemonic:               SA+Y_IB_PKHR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2531
Description:            Solar Array +Y INNER BACK Peak Temperature
Mnemonic:               SA+Y_IB_PK_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC

*/

CHILD = "V-2511" PARENTS = "H-0017""T-0211";
CHILD = "V-2521" PARENTS = "H-0017""T-0211";
CHILD = "V-2531" PARENTS = "H-0017""T-0211";

FUNCT CHAN = "T-0211"

INT i,samples;
FLT slope,s1sqr,sumxy,sumx,sumy,sumxx,x_bar,y_bar;
STATIC INT pointer=0,old_samples=0,epoch=0,cycles=0;
STATIC FLT peak_temp=-200.0;
STATIC FLT datapoints[32]=0.0,timepoints[32]=0.0;

/* Determine sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart function */
IF (samples != old_samples  || (DN_VALID("V-2521") != 0) )
    pointer = 0;
    cycles = 0;
    old_samples = samples;
    epoch = GET_LAD_DN("H-0017") - 4;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();
timepoints[pointer] = (FLT)(GET_LAD_DN("H-0017") - epoch);

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
sumxy = 0.0;
sumx = 0.0;
sumxx = 0.0;
sumy = 0.0;
FOR (i = 0; i <= samples-1; i++)
    sumxy = sumxy + (timepoints[i] * datapoints[i]);
    sumx = sumx + timepoints[i];
    sumxx = sumxx + timepoints[i]**2;
    sumy = sumy + datapoints[i];
ENDFOR

/* compute slope */
slope = (samples * sumxy - sumx*sumy) / (samples * sumxx - sumx**2);
slope = slope * 60.0;

IF (cycles++ > samples)
    cycles = samples;
    DERIVE ("V-2511",slope);
    IF (slope > GET_LAD_DN("V-2521"))
        DERIVE ("V-2521",slope);
    ENDIF
ELSE
    DERIVE ("V-2511",0.0);
    DERIVE ("V-2521",0.0);
ENDIF

/* find peak temperature */
IF (GET_EU() > peak_temp)
    peak_temp = GET_EU();
    DERIVE ("V-2531",peak_temp);
ENDIF


ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0212 "SA+Y_OUT_F_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 4-30-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2512
Description:            Solar Array +Y OUTER FRONT Heating Rate
Mnemonic:               SA+Y_OF_HR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2522
Description:            Solar Array +Y OUTER FRONT Peak Heating Rate
Mnemonic:               SA+Y_OF_PKHR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2532
Description:            Solar Array +Y OUTER FRONT Peak Temperature
Mnemonic:               SA+Y_OF_PK_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC

*/

CHILD = "V-2512" PARENTS = "H-0017""T-0212";
CHILD = "V-2522" PARENTS = "H-0017""T-0212";
CHILD = "V-2532" PARENTS = "H-0017""T-0212";

FUNCT CHAN = "T-0212"

INT i,samples;
FLT slope,s1sqr,sumxy,sumx,sumy,sumxx,x_bar,y_bar;
STATIC INT pointer=0,old_samples=0,epoch=0,cycles=0;
STATIC FLT peak_temp=-200.0;
STATIC FLT datapoints[32]=0.0,timepoints[32]=0.0;

/* Determine sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart function */
IF (samples != old_samples  || (DN_VALID("V-2522") != 0) )
    pointer = 0;
    cycles = 0;
    old_samples = samples;
    epoch = GET_LAD_DN("H-0017") - 4;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();
timepoints[pointer] = (FLT)(GET_LAD_DN("H-0017") - epoch);

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
sumxy = 0.0;
sumx = 0.0;
sumxx = 0.0;
sumy = 0.0;
FOR (i = 0; i <= samples-1; i++)
    sumxy = sumxy + (timepoints[i] * datapoints[i]);
    sumx = sumx + timepoints[i];
    sumxx = sumxx + timepoints[i]**2;
    sumy = sumy + datapoints[i];
ENDFOR

/* compute slope */
slope = (samples * sumxy - sumx*sumy) / (samples * sumxx - sumx**2);
slope = slope * 60.0;

IF (cycles++ > samples)
    cycles = samples;
    DERIVE ("V-2512",slope);
    IF (slope > GET_LAD_DN("V-2522"))
        DERIVE ("V-2522",slope);
    ENDIF
ELSE
    DERIVE ("V-2512",0.0);
    DERIVE ("V-2522",0.0);
ENDIF

/* find peak temperature */
IF (GET_EU() > peak_temp)
    peak_temp = GET_EU();
    DERIVE ("V-2532",peak_temp);
ENDIF


ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0213 "SA+Y_OUT_B_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 4-30-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2513
Description:            Solar Array +Y OUTER BACK Heating Rate
Mnemonic:               SA+Y_OB_HR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2523
Description:            Solar Array +Y OUTER BACK Peak Heating Rate
Mnemonic:               SA+Y_OB_PKHR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2533
Description:            Solar Array +Y OUTER BACK Peak Temperature
Mnemonic:               SA+Y_OB_PK_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC

*/

CHILD = "V-2513" PARENTS = "H-0017""T-0213";
CHILD = "V-2523" PARENTS = "H-0017""T-0213";
CHILD = "V-2533" PARENTS = "H-0017""T-0213";

FUNCT CHAN = "T-0213"

INT i,samples;
FLT slope,s1sqr,sumxy,sumx,sumy,sumxx,x_bar,y_bar;
STATIC INT pointer=0,old_samples=0,epoch=0,cycles=0;
STATIC FLT peak_temp=-200.0;
STATIC FLT datapoints[32]=0.0,timepoints[32]=0.0;

/* Determine sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart function */
IF (samples != old_samples  || (DN_VALID("V-2523") != 0) )
    pointer = 0;
    cycles = 0;
    old_samples = samples;
    epoch = GET_LAD_DN("H-0017") - 4;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();
timepoints[pointer] = (FLT)(GET_LAD_DN("H-0017") - epoch);

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
sumxy = 0.0;
sumx = 0.0;
sumxx = 0.0;
sumy = 0.0;
FOR (i = 0; i <= samples-1; i++)
    sumxy = sumxy + (timepoints[i] * datapoints[i]);
    sumx = sumx + timepoints[i];
    sumxx = sumxx + timepoints[i]**2;
    sumy = sumy + datapoints[i];
ENDFOR

/* compute slope */
slope = (samples * sumxy - sumx*sumy) / (samples * sumxx - sumx**2);
slope = slope * 60.0;

IF (cycles++ > samples)
    cycles = samples;
    DERIVE ("V-2513",slope);
    IF (slope > GET_LAD_DN("V-2523"))
        DERIVE ("V-2523",slope);
    ENDIF
ELSE
    DERIVE ("V-2513",0.0);
    DERIVE ("V-2523",0.0);
ENDIF

/* find peak temperature */
IF (GET_EU() > peak_temp)
    peak_temp = GET_EU();
    DERIVE ("V-2533",peak_temp);
ENDIF


ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0214 "SA-Y_INR_F_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 4-30-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2514
Description:            Solar Array -Y INNER FRONT Heating Rate
Mnemonic:               SA-Y_IF_HR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2524
Description:            Solar Array -Y INNER FRONT Peak Heating Rate
Mnemonic:               SA-Y_IF_PKHR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2534
Description:            Solar Array -Y INNER FRONT Peak Temperature
Mnemonic:               SA-Y_IF_PK_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC

*/

CHILD = "V-2514" PARENTS = "H-0017""T-0214";
CHILD = "V-2524" PARENTS = "H-0017""T-0214";
CHILD = "V-2534" PARENTS = "H-0017""T-0214";

FUNCT CHAN = "T-0214"

INT i,samples;
FLT slope,s1sqr,sumxy,sumx,sumy,sumxx,x_bar,y_bar;
STATIC INT pointer=0,old_samples=0,epoch=0,cycles=0;
STATIC FLT peak_temp=-200.0;
STATIC FLT datapoints[32]=0.0,timepoints[32]=0.0;

/* Determine sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart function */
IF (samples != old_samples  || (DN_VALID("V-2524") != 0) )
    pointer = 0;
    cycles = 0;
    old_samples = samples;
    epoch = GET_LAD_DN("H-0017") - 4;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();
timepoints[pointer] = (FLT)(GET_LAD_DN("H-0017") - epoch);

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
sumxy = 0.0;
sumx = 0.0;
sumxx = 0.0;
sumy = 0.0;
FOR (i = 0; i <= samples-1; i++)
    sumxy = sumxy + (timepoints[i] * datapoints[i]);
    sumx = sumx + timepoints[i];
    sumxx = sumxx + timepoints[i]**2;
    sumy = sumy + datapoints[i];
ENDFOR

/* compute slope */
slope = (samples * sumxy - sumx*sumy) / (samples * sumxx - sumx**2);
slope = slope * 60.0;

IF (cycles++ > samples)
    cycles = samples;
    DERIVE ("V-2514",slope);
    IF (slope > GET_LAD_DN("V-2524"))
        DERIVE ("V-2524",slope);
    ENDIF
ELSE
    DERIVE ("V-2514",0.0);
    DERIVE ("V-2524",0.0);
ENDIF

/* find peak temperature */
IF (GET_EU() > peak_temp)
    peak_temp = GET_EU();
    DERIVE ("V-2534",peak_temp);
ENDIF


ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0215 "SA-Y_INR_B_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 4-30-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2515
Description:            Solar Array -Y INNER BACK Heating Rate
Mnemonic:               SA-Y_IB_HR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2525
Description:            Solar Array -Y INNER BACK Peak Heating Rate
Mnemonic:               SA-Y_IB_PKHR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2535
Description:            Solar Array -Y INNER BACK Peak Temperature
Mnemonic:               SA-Y_IB_PK_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC

*/

CHILD = "V-2515" PARENTS = "H-0017""T-0215";
CHILD = "V-2525" PARENTS = "H-0017""T-0215";
CHILD = "V-2535" PARENTS = "H-0017""T-0215";

FUNCT CHAN = "T-0215"

INT i,samples;
FLT slope,s1sqr,sumxy,sumx,sumy,sumxx,x_bar,y_bar;
STATIC INT pointer=0,old_samples=0,epoch=0,cycles=0;
STATIC FLT peak_temp=-200.0;
STATIC FLT datapoints[32]=0.0,timepoints[32]=0.0;

/* Determine sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart function */
IF (samples != old_samples  || (DN_VALID("V-2525") != 0) )
    pointer = 0;
    cycles = 0;
    old_samples = samples;
    epoch = GET_LAD_DN("H-0017") - 4;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();
timepoints[pointer] = (FLT)(GET_LAD_DN("H-0017") - epoch);

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
sumxy = 0.0;
sumx = 0.0;
sumxx = 0.0;
sumy = 0.0;
FOR (i = 0; i <= samples-1; i++)
    sumxy = sumxy + (timepoints[i] * datapoints[i]);
    sumx = sumx + timepoints[i];
    sumxx = sumxx + timepoints[i]**2;
    sumy = sumy + datapoints[i];
ENDFOR

/* compute slope */
slope = (samples * sumxy - sumx*sumy) / (samples * sumxx - sumx**2);
slope = slope * 60.0;

IF (cycles++ > samples)
    cycles = samples;
    DERIVE ("V-2515",slope);
    IF (slope > GET_LAD_DN("V-2525"))
        DERIVE ("V-2525",slope);
    ENDIF
ELSE
    DERIVE ("V-2515",0.0);
    DERIVE ("V-2525",0.0);
ENDIF

/* find peak temperature */
IF (GET_EU() > peak_temp)
    peak_temp = GET_EU();
    DERIVE ("V-2535",peak_temp);
ENDIF


ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0216 "SA-Y_OUT_F_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 4-30-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2516
Description:            Solar Array -Y OUTER FRONT Heating Rate
Mnemonic:               SA-Y_OF_HR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2526
Description:            Solar Array -Y OUTER FRONT Peak Heating Rate
Mnemonic:               SA-Y_OF_PKHR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2536
Description:            Solar Array -Y OUTER FRONT Peak Temperature
Mnemonic:               SA-Y_OF_PK_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC

*/

CHILD = "V-2516" PARENTS = "H-0017""T-0216";
CHILD = "V-2526" PARENTS = "H-0017""T-0216";
CHILD = "V-2536" PARENTS = "H-0017""T-0216";

FUNCT CHAN = "T-0216"

INT i,samples;
FLT slope,s1sqr,sumxy,sumx,sumy,sumxx,x_bar,y_bar;
STATIC INT pointer=0,old_samples=0,epoch=0,cycles=0;
STATIC FLT peak_temp=-200.0;
STATIC FLT datapoints[32]=0.0,timepoints[32]=0.0;

/* Determine sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart function */
IF (samples != old_samples  || (DN_VALID("V-2526") != 0) )
    pointer = 0;
    cycles = 0;
    old_samples = samples;
    epoch = GET_LAD_DN("H-0017") - 4;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();
timepoints[pointer] = (FLT)(GET_LAD_DN("H-0017") - epoch);

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
sumxy = 0.0;
sumx = 0.0;
sumxx = 0.0;
sumy = 0.0;
FOR (i = 0; i <= samples-1; i++)
    sumxy = sumxy + (timepoints[i] * datapoints[i]);
    sumx = sumx + timepoints[i];
    sumxx = sumxx + timepoints[i]**2;
    sumy = sumy + datapoints[i];
ENDFOR

/* compute slope */
slope = (samples * sumxy - sumx*sumy) / (samples * sumxx - sumx**2);
slope = slope * 60.0;

IF (cycles++ > samples)
    cycles = samples;
    DERIVE ("V-2516",slope);
    IF (slope > GET_LAD_DN("V-2526"))
        DERIVE ("V-2526",slope);
    ENDIF
ELSE
    DERIVE ("V-2516",0.0);
    DERIVE ("V-2526",0.0);
ENDIF

/* find peak temperature */
IF (GET_EU() > peak_temp)
    peak_temp = GET_EU();
    DERIVE ("V-2536",peak_temp);
ENDIF


ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0217 "SA-Y_OUT_B_T" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 4-30-97                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-2517
Description:            Solar Array -Y OUTER BACK Heating Rate
Mnemonic:               SA-Y_OB_HR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2527
Description:            Solar Array -Y OUTER BACK Peak Heating Rate
Mnemonic:               SA-Y_OB_PKHR
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC/min

Derived Channel:        V-2537
Description:            Solar Array -Y OUTER BACK Peak Temperature
Mnemonic:               SA-Y_IF_OB_T
Subsystem:              THRM
Data_Type:              FLOAT
Units:                  degC

*/

CHILD = "V-2517" PARENTS = "H-0017""T-0217";
CHILD = "V-2527" PARENTS = "H-0017""T-0217";
CHILD = "V-2537" PARENTS = "H-0017""T-0217";

FUNCT CHAN = "T-0217"

INT i,samples;
FLT slope,s1sqr,sumxy,sumx,sumy,sumxx,x_bar,y_bar;
STATIC INT pointer=0,old_samples=0,epoch=0,cycles=0;
STATIC FLT peak_temp=-200.0;
STATIC FLT datapoints[32]=0.0,timepoints[32]=0.0;

/* Determine sample window */
IF (GET_PARM() <= 0)
    samples = 10;
ELSEIF (GET_PARM() >= 32)
    samples = 32;
ELSE
    samples = GET_PARM();
ENDIF

/* Check for changes to the sample window, if changed, restart function */
IF (samples != old_samples  || (DN_VALID("V-2527") != 0) )
    pointer = 0;
    cycles = 0;
    old_samples = samples;
    epoch = GET_LAD_DN("H-0017") - 4;
ENDIF

/* add incomming value to data array */
datapoints[pointer] = GET_EU();
timepoints[pointer] = (FLT)(GET_LAD_DN("H-0017") - epoch);

/* set data pointer in array */
IF (pointer++ >= samples)
    pointer = 0;
ENDIF

/* sum data  */
sumxy = 0.0;
sumx = 0.0;
sumxx = 0.0;
sumy = 0.0;
FOR (i = 0; i <= samples-1; i++)
    sumxy = sumxy + (timepoints[i] * datapoints[i]);
    sumx = sumx + timepoints[i];
    sumxx = sumxx + timepoints[i]**2;
    sumy = sumy + datapoints[i];
ENDFOR

/* compute slope */
slope = (samples * sumxy - sumx*sumy) / (samples * sumxx - sumx**2);
slope = slope * 60.0;

IF (cycles++ > samples)
    cycles = samples;
    DERIVE ("V-2517",slope);
    IF (slope > GET_LAD_DN("V-2527"))
        DERIVE ("V-2527",slope);
    ENDIF
ELSE
    DERIVE ("V-2517",0.0);
    DERIVE ("V-2527",0.0);
ENDIF

/* find peak temperature */
IF (GET_EU() > peak_temp)
    peak_temp = GET_EU();
    DERIVE ("V-2537",peak_temp);
ENDIF


ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0221 "ER_HTR" TRIGGER CHANNEL CODE                                      *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the ER_SENSOR_T
if the heater status T-0050 ER_HTR indicates 1 "DISBALE"

*/

CHILD = "T-0221" PARENTS = "T-0050";

FUNCT CHAN = "T-0221"

IF (DN_VALID("T-0050") == 0)
    IF (GET_LAD_DN("T-0050") == 1)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0223 "MAG_+Y_T" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the MAG_+Y_T
if the heater status T-0051 MAG_SENS_HTR indicates 1 "OFF"

*/

CHILD = "T-0223" PARENTS = "T-0051";

FUNCT CHAN = "T-0223"

IF (DN_VALID("T-0051") == 0)
    IF (GET_LAD_DN("T-0051") == 1)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT

/*****************************************************************************
 *                                                                           *
 * T-0224 "MAG_-Y_T" TRIGGER CHANNEL CODE                                    *
 *                                                                           *
 * BASELINED:            OGS 6-20-96                                         *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

No-Derived Channels

This code is designed to disable the alarms for the MAG_-Y_T
if the heater status T-0051 MAG_SENS_HTR indicates 1 "OFF"

*/

CHILD = "T-0224" PARENTS = "T-0051";

FUNCT CHAN = "T-0224"

IF (DN_VALID("T-0051") == 0)
    IF (GET_LAD_DN("T-0051") == 1)
        RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
    ENDIF
ELSE
    RETURN NO_ALM_ACT; /* Disable trigger channels alarms */
ENDIF

ENDFUNCT


/**************************** PDS DERIVED CHANNELS ***************************/

/*****************************************************************************
 *                                                                           *
 * D-0001 "ERR_CODE_1" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3701
Description:            LAST_MSG_C_1
Mnemonic:               LAST_MSG_C_1
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

Derived Channel:        V-3709
Description:            LAST_ERR_C_1
Mnemonic:               LAST_ERR_C_1
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

Derived Channel:        V-3814
Description:            ERR1_DECODE
Mnemonic:               ERR1_DECODE
Subsystem:              PDS
Data_Type:              STATUS
States:                 CSN_ROLLOVR,SEE_ERR_LST,NO_ERROR,PDS_MODE_CNG

*/

CHILD = "V-3701" PARENTS = "D-0001";
CHILD = "V-3709" PARENTS = "D-0001";
CHILD = "V-3814" PARENTS = "D-0001";

FUNCT CHAN = "D-0001"

UINT dn,state, err, wd1, wd2;

dn = GET_DN();

IF (dn != 0)
   IF ( ( 51<=dn && dn<=71 ) || ( 73<=dn && dn<=79 ) || ( 82<=dn && dn<=84 ) || ( dn==87 ) || ( dn==90) || ( dn==92) || ( 99<=dn && dn<=111 ) )
        /* Red Alarm State */
        DERIVE ("V-3709", dn);
   ELSEIF ( ( 80<=dn && dn<=81 ) || ( 85<=dn && dn<=86 ) || ( 88<=dn && dn<=89 ) || ( 91==dn ) || ( 93<=dn && dn<=98 ) )
        /* yellow alarm state */
        DERIVE("V-3701", dn);
   ELSE
        /* out of range alarm state (red alarm) */
        DERIVE ("V-3709", dn);
   ENDIF
ENDIF

/* PDS ERROR code 1 decode */

IF (dn == 0x43)
    state = 0;
ELSEIF (dn == 0)
    state = 2;
ELSEIF (dn == 0x51)
    state = 3;
ELSE
    state = 1;
ENDIF

DERIVE ("V-3814", state);

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * D-0002 "ERR_CODE_2" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3702
Description:            LAST_MSG_C_2
Mnemonic:               LAST_MSG_C_2
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

Derived Channel:        V-3710
Description:            LAST_ERR_C_2
Mnemonic:               LAST_ERR_C_2
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

*/

CHILD = "V-3702" PARENTS = "D-0002";
CHILD = "V-3710" PARENTS = "D-0002";

FUNCT CHAN = "D-0002"

UINT dn;

dn = GET_DN();

IF (dn != 0)
   IF ( ( 51<=dn && dn<=71 ) || ( 73<=dn && dn<=79 ) || ( 82<=dn && dn<=84 ) || ( dn==87 ) || ( dn==90) || ( dn==92) || ( 99<=dn && dn<=111 ) )
        /* Red Alarm State */
        DERIVE ("V-3710", dn);
   ELSEIF ( ( 80<=dn && dn<=81 ) || ( 85<=dn && dn<=86 ) || ( 88<=dn && dn<=89 ) || ( 91==dn ) || ( 93<=dn && dn<=98 ) )
        /* yellow alarm state */
        DERIVE("V-3702", dn);
   ELSE
        /* out of range alarm state (red alarm) */
        DERIVE ("V-3710", dn);
   ENDIF
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * D-0003 "ERR_CODE_3" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3703
Description:            LAST_MSG_C_3
Mnemonic:               LAST_MSG_C_3
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

Derived Channel:        V-3711
Description:            LAST_ERR_C_3
Mnemonic:               LAST_ERR_C_3
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

*/

CHILD = "V-3703" PARENTS = "D-0003";
CHILD = "V-3711" PARENTS = "D-0003";

FUNCT CHAN = "D-0003"

UINT dn;

dn = GET_DN();

IF (dn != 0)
   IF ( ( 51<=dn && dn<=71 ) || ( 73<=dn && dn<=79 ) || ( 82<=dn && dn<=84 ) || ( dn==87 ) || ( dn==90) || ( dn==92) || ( 99<=dn && dn<=111 ) )
        /* Red Alarm State */
        DERIVE ("V-3711", dn);
   ELSEIF ( ( 80<=dn && dn<=81 ) || ( 85<=dn && dn<=86 ) || ( 88<=dn && dn<=89 ) || ( 91==dn ) || ( 93<=dn && dn<=98 ) )
        /* yellow alarm state */
        DERIVE("V-3703", dn);
   ELSE
        /* out of range alarm state */
        DERIVE ("V-3711", dn);
   ENDIF
ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * D-0004 "ERR_CODE_4" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3704
Description:            LAST_MSG_C_4
Mnemonic:               LAST_MSG_C_4
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

Derived Channel:        V-3712
Description:            LAST_ERR_C_4
Mnemonic:               LAST_ERR_C_4
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

*/

CHILD = "V-3704" PARENTS = "D-0004";
CHILD = "V-3712" PARENTS = "D-0004";

FUNCT CHAN = "D-0004"

UINT dn;

dn = GET_DN();

IF (dn != 0)
   IF ( ( 51<=dn && dn<=71 ) || ( 73<=dn && dn<=79 ) || ( 82<=dn && dn<=84 ) || ( dn==87 ) || ( dn==90) || ( dn==92) || ( 99<=dn && dn<=111 ) )
        /* Red Alarm State */
        DERIVE ("V-3712", dn);
   ELSEIF ( ( 80<=dn && dn<=81 ) || ( 85<=dn && dn<=86 ) || ( 88<=dn && dn<=89 ) || ( 91==dn ) || ( 93<=dn && dn<=98 ) )
        /* yellow alarm state */
        DERIVE("V-3704", dn);
   ELSE
        /* out of range alarm state */
        DERIVE ("V-3712", dn);
   ENDIF
ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * D-0005 "ERR_CODE_5" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3705
Description:            LAST_MSG_C_5
Mnemonic:               LAST_MSG_C_5
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

Derived Channel:        V-3713
Description:            LAST_ERR_C_5
Mnemonic:               LAST_ERR_C_5
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

*/

CHILD = "V-3705" PARENTS = "D-0005";
CHILD = "V-3713" PARENTS = "D-0005";

FUNCT CHAN = "D-0005"

UINT dn;

dn = GET_DN();

IF (dn != 0)
   IF ( ( 51<=dn && dn<=71 ) || ( 73<=dn && dn<=79 ) || ( 82<=dn && dn<=84 ) || ( dn==87 ) || ( dn==90) || ( dn==92) || ( 99<=dn && dn<=111 ) )
        /* Red Alarm State */
        DERIVE ("V-3713", dn);
   ELSEIF ( ( 80<=dn && dn<=81 ) || ( 85<=dn && dn<=86 ) || ( 88<=dn && dn<=89 ) || ( 91==dn ) || ( 93<=dn && dn<=98 ) )
        /* yellow alarm state */
        DERIVE("V-3705", dn);
   ELSE
        /* out of range alarm state */
        DERIVE ("V-3713", dn);
   ENDIF
ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * D-0006 "ERR_CODE_6" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3706
Description:            LAST_MSG_C_6
Mnemonic:               LAST_MSG_C_6
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

Derived Channel:        V-3714
Description:            LAST_ERR_C_6
Mnemonic:               LAST_ERR_C_6
Subsystem:              PDS
Data_Type:              DIGITAL
Units:

*/

CHILD = "V-3706" PARENTS = "D-0006";
CHILD = "V-3714" PARENTS = "D-0006";

FUNCT CHAN = "D-0006"

UINT dn;

dn = GET_DN();

IF (dn != 0)
   IF ( ( 51<=dn && dn<=71 ) || ( 73<=dn && dn<=79 ) || ( 82<=dn && dn<=84 ) || ( dn==87 ) || ( dn==90) || ( dn==92) || ( 99<=dn && dn<=111 ) )
        /* Red Alarm State */
        DERIVE ("V-3714", dn);
   ELSEIF ( ( 80<=dn && dn<=81 ) || ( 85<=dn && dn<=86 ) || ( 88<=dn && dn<=89 ) || ( 91==dn ) || ( 93<=dn && dn<=98 ) )
        /* yellow alarm state */
        DERIVE("V-3706", dn);
   ELSE
        /* out of range alarm state */
        DERIVE ("V-3714", dn);
   ENDIF
ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * C-0125 "PDS_A_+5_V" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3707
Description:            PDS_A_5V_OUT
Mnemonic:               PDS_A_5V_OUT
Subsystem:              PDS
Data_Type:              STATUS
States:                 OK,HIGH

*/

CHILD = "V-3707" PARENTS = "C-0022""C-0125";

FUNCT CHAN = "C-0125"

UINT dn22, state;
FLT eu125;

eu125 = GET_EU();
state = 0;  /* non alarm state */

IF (DN_VALID("C-0022") == 0)
    dn22 = GET_LAD_DN("C-0022");
    IF ( dn22 == 0 )   /* PDS OFF */
        IF (eu125 > (FLT) GET_PARM()/10. )
           state = 1; /* out of voltage lim, PDS off */
        ENDIF
        DERIVE ("V-3707", state);
    /*  RETURN NO_ALM_ACT; */
    ENDIF
    DERIVE("V-3707",state);
ENDIF


ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * C-0126 "PDS_B_+5_V" TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3708
Description:            PDS_B_5V_OUT
Mnemonic:               PDS_B_5V_OUT
Subsystem:              PDS
Data_Type:              STATUS
States:                 OK,HIGH

*/

CHILD = "V-3708" PARENTS = "C-0023""C-0126";

FUNCT CHAN = "C-0126"

UINT dn23, state;
FLT eu126;

eu126 = GET_EU();
state = 0;  /* non alarm state */

IF (DN_VALID("C-0022") == 0)
    dn23 = GET_LAD_DN("C-0023");
    IF ( dn23 == 0 )   /* PDS OFF */
        IF (eu126 > (FLT) GET_PARM()/10. )
           state = 1; /* out of voltage lim, PDS off */
        ENDIF
        DERIVE ("V-3708", state);
    /*  RETURN NO_ALM_ACT; */
    ENDIF
    DERIVE("V-3708",state);
ENDIF

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * D-0102 "CMD ACCT 10" TRIGGER CHANNEL CODE                                 *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3717
Description:            sw_rec_GRS
Mnemonic:               sw_rec_GRS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3718
Description:            sw_rej_GRS
Mnemonic:               sw_rej_GRS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3719
Description:            mw_rec_GRS
Mnemonic:               mw_rec_GRS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3720
Description:            mw_rej_GRS
Mnemonic:               mw_rej_GRS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3721
Description:            swBIUtrGRS
Mnemonic:               swBIUtrGRS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3722
Description:            swBIUrjGRS
Mnemonic:               swBIUrjGRS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3723
Description:            mwBIUtrGRS
Mnemonic:               mwBIUtrGRS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3724
Description:            mwBIUrjGRS
Mnemonic:               mwBIUrjGRS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3725
Description:            sw_rec_MOLA
Mnemonic:               sw_rec_MOLA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3726
Description:            sw_rej_MOLA
Mnemonic:               sw_rej_MOLA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3727
Description:            mw_rec_MOLA
Mnemonic:               mw_rec_MOLA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3728
Description:            mw_rej_MOLA
Mnemonic:               mw_rej_MOLA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3729
Description:            swBIUtrMOLA
Mnemonic:               swBIUtrMOLA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3730
Description:            swBIUrjMOLA
Mnemonic:               swBIUrjMOLA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3731
Description:            mwBIUtrMOLA
Mnemonic:               mwBIUtrMOLA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3732
Description:            mwBIUrjMOLA
Mnemonic:               mwBIUrjMOLA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3733
Description:            sw_rec_TES
Mnemonic:               sw_rec_TES
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3734
Description:            sw_rej_TES
Mnemonic:               sw_rej_TES
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3735
Description:            mw_rec_TES
Mnemonic:               mw_rec_TES
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3736
Description:            mw_rej_TES
Mnemonic:               mw_rej_TES
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3737
Description:            swBIUtrTES
Mnemonic:               swBIUtrTES
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3738
Description:            swBIUrjTES
Mnemonic:               swBIUrjTES
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3739
Description:            mwBIUtrTES
Mnemonic:               mwBIUtrTES
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3740
Description:            mwBIUrjTES
Mnemonic:               mwBIUrjTES
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3741
Description:            sw_rec_PMIRR
Mnemonic:               sw_rec_PMIRR
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3742
Description:            sw_rej_PMIRR
Mnemonic:               sw_rej_PMIRR
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3743
Description:            mw_rec_PMIRR
Mnemonic:               mw_rec_PMIRR
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3744
Description:            mw_rej_PMIRR
Mnemonic:               mw_rej_PMIRR
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3745
Description:            swBIUtrPMIRR
Mnemonic:               swBIUtrPMIRR
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3746
Description:            swBIUrjPMIRR
Mnemonic:               swBIUrjPMIRR
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3747
Description:            mwBIUtrPMIRR
Mnemonic:               mwBIUtrPMIRR
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3748
Description:            mwBIUrjPMIRR
Mnemonic:               mwBIUrjPMIRR
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3749
Description:            sw_recMAGERA
Mnemonic:               sw_recMAGERA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3750
Description:            sw_rejMAGERA
Mnemonic:               sw_rejMAGERA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3751
Description:            mw_recMAGERA
Mnemonic:               mw_recMAGERA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3752
Description:            mw_rejMAGERA
Mnemonic:               mw_rejMAGERA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3753
Description:            swBIUtMAGERA
Mnemonic:               swBIUtMAGERA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3754
Description:            swBIUrMAGERA
Mnemonic:               swBIUrMAGERA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3755
Description:            mwBIUtMAGERA
Mnemonic:               mwBIUtMAGERA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3756
Description:            mwBIUrMAGERA
Mnemonic:               mwBIUrMAGERA
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3757
Description:            sw_recMAGERB
Mnemonic:               sw_recMAGERB
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3758
Description:            sw_rejMAGERB
Mnemonic:               sw_rejMAGERB
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3759
Description:            mw_recMAGERB
Mnemonic:               mw_recMAGERB
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3760
Description:            mw_rejMAGERB
Mnemonic:               mw_rejMAGERB
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3761
Description:            swBIUtMAGERB
Mnemonic:               swBIUtMAGERB
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3762
Description:            swBIUrMAGERB
Mnemonic:               swBIUrMAGERB
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3763
Description:            mwBIUtMAGERB
Mnemonic:               mwBIUtMAGERB
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3764
Description:            mwBIUrMAGERB
Mnemonic:               mwBIUrMAGERB
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3765
Description:            sw_rec_MOC_A
Mnemonic:               sw_rec_MOC_A
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3766
Description:            sw_rej_MOC_A
Mnemonic:               sw_rej_MOC_A
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3767
Description:            mw_rec_MOC_A
Mnemonic:               mw_rec_MOC_A
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3768
Description:            mw_rej_MOC_A
Mnemonic:               mw_rej_MOC_A
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3769
Description:            swBIUtrMOC_A
Mnemonic:               swBIUtrMOC_A
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3770
Description:            swBIUrjMOC_A
Mnemonic:               swBIUrjMOC_A
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3771
Description:            mwBIUtrMOC_A
Mnemonic:               mwBIUtrMOC_A
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3772
Description:            mwBIUrjMOC_A
Mnemonic:               mwBIUrjMOC_A
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3773
Description:            sw_rec_MOC_B
Mnemonic:               sw_rec_MOC_B
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3774
Description:            sw_rej_MOC_B
Mnemonic:               sw_rej_MOC_B
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3775
Description:            mw_rec_MOC_B
Mnemonic:               mw_rec_MOC_B
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3776
Description:            mw_rej_MOC_B
Mnemonic:               mw_rej_MOC_B
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3777
Description:            swBIUtrMOC_B
Mnemonic:               swBIUtrMOC_B
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3778
Description:            swBIUrjMOC_B
Mnemonic:               swBIUrjMOC_B
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3779
Description:            mwBIUtrMOC_B
Mnemonic:               mwBIUtrMOC_B
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3780
Description:            mwBIUrjMOC_B
Mnemonic:               mwBIUrjMOC_B
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3781
Description:            sw_rec_BDCST
Mnemonic:               sw_rec_BDCST
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3782
Description:            sw_rej_BDCST
Mnemonic:               sw_rej_BDCST
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3783
Description:            mw_rec_BDCST
Mnemonic:               mw_rec_BDCST
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3784
Description:            mw_rej_BDCST
Mnemonic:               mw_rej_BDCST
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3785
Description:            swBIUtrBDCST
Mnemonic:               swBIUtrBDCST
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3786
Description:            swBIUrjBDCST
Mnemonic:               swBIUrjBDCST
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3787
Description:            mwBIUtrBDCST
Mnemonic:               mwBIUtrBDCST
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3788
Description:            mwBIUrjBDCST
Mnemonic:               mwBIUrjBDCST
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3789
Description:            sw_rec_UNKWN
Mnemonic:               sw_rec_UNKWN
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3790
Description:            mw_rej_UNKWN
Mnemonic:               mw_rej_UNKWN
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3791
Description:            swBIUrjUNKWN
Mnemonic:               swBIUrjUNKWN
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3792
Description:            mwBIUrjUNKWN
Mnemonic:               mwBIUrjUNKWN
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3793
Description:            sw_rec_PDS
Mnemonic:               sw_rec_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3794
Description:            sw_rej_PDS
Mnemonic:               sw_rej_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3795
Description:            mw_rec_PDS
Mnemonic:               mw_rec_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3796
Description:            mw_rej_PDS
Mnemonic:               mw_rej_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3797
Description:            swBIUrjPDS
Mnemonic:               swBIUrjPDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3798
Description:            mwBIUrjUNKWN
Mnemonic:               mwBIUrjUNKWN
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3799
Description:            acc_mode_PDS
Mnemonic:               acc_mode_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3800
Description:            rej_mode_PDS
Mnemonic:               rej_mode_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3801
Description:            acc_go2N_PDS
Mnemonic:               acc_go2N_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3802
Description:            rej_go2N_PDS
Mnemonic:               rej_go2N_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3803
Description:            rej_unkn_PDS
Mnemonic:               rej_unkn_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3804
Description:            acc_updt_PDS
Mnemonic:               acc_updt_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3805
Description:            rej_updt_PDS
Mnemonic:               rej_updt_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3806
Description:            acc_mld_PDS
Mnemonic:               acc_mld_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3807
Description:            rej_mld_PDS
Mnemonic:               rej_mld_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3808
Description:            acc_mro_PDS
Mnemonic:               acc_mro_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3809
Description:            rej_mro_PDS
Mnemonic:               rej_mro_PDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3810
Description:            swBIUtrPDS
Mnemonic:               swBIUtrPDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3811
Description:            mwBIUtrPDS
Mnemonic:               mwBIUtrPDS
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3815
Description:            accMACRO_on
Mnemonic:               accMACRO_on
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3816
Description:            rejMACRO_on
Mnemonic:               rejMACRO_on
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3817
Description:            accMACROoff
Mnemonic:               accMACROoff
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3818
Description:            rejMACROoff
Mnemonic:               rejMACROoff
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3819
Description:            accMACROuld
Mnemonic:               accMACROuld
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3820
Description:            rejMACROuld
Mnemonic:               rejMACROuld
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3821
Description:            accMACRO_Ld
Mnemonic:               accMACRO_Ld
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

Derived Channel:        V-3822
Description:            rejMACRO_Ld
Mnemonic:               rejMACRO_Ld
Subsystem:              PDS
Data_Type:              UNSIGNED
Units:

*/

/*  PDS  Command Accountability Matrix Decoding */

CHILD="V-3717" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3718" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3719" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3720" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3721" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3722" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3723" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3724" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3725" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3726" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3727" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3728" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3729" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3730" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3731" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3732" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3733" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3734" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3735" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3736" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3737" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3738" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3739" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3740" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3741" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3742" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3743" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3744" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3745" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3746" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3747" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3748" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3749" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3750" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3751" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3752" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3753" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3754" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3755" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3756" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3757" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3758" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3759" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3760" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3761" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3762" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3763" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3764" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3765" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3766" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3767" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3768" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3769" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3770" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3771" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3772" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3773" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3774" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3775" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3776" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3777" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3778" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3779" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3780" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3781" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3782" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3783" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3784" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3785" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3786" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3787" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3788" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3789" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3790" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3791" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3792" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3793" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3794" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3795" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3796" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3797" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3798" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3799" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3800" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3801" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3802" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3803" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3804" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3805" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3806" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3807" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3808" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3809" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3810" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3811" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3815" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3816" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3817" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3818" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3819" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3820" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3821" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";
CHILD="V-3822" PARENTS="D-0197""D-0092""D-0093""D-0094""D-0095""D-0096""D-0097""D-0098""D-0099""D-0100""D-0101""D-0102";

FUNCT CHAN="D-0102"

UINT index;


IF (DN_VALID("D-0197") == 0 && DN_VALID("D-0092") == 0 && DN_VALID("D-0093") == 0 && DN_VALID("D-0094") == 0 && DN_VALID("D-0095") == 0
                            && DN_VALID("D-0096") == 0 && DN_VALID("D-0097") == 0 && DN_VALID("D-0098") == 0 && DN_VALID("D-0099") == 0
                            && DN_VALID("D-0100") == 0 && DN_VALID("D-0101") == 0 )

index=GET_LAD_DN("D-0197");

IF (index==0)
    DERIVE("V-3717", GET_LAD_DN("D-0092"));
    DERIVE("V-3725", GET_LAD_DN("D-0093"));
    DERIVE("V-3733", GET_LAD_DN("D-0094"));
    DERIVE("V-3741", GET_LAD_DN("D-0095"));
    DERIVE("V-3749", GET_LAD_DN("D-0096"));
    DERIVE("V-3757", GET_LAD_DN("D-0097"));
    DERIVE("V-3773", GET_LAD_DN("D-0098"));
    DERIVE("V-3765", GET_LAD_DN("D-0099"));
    DERIVE("V-3781", GET_LAD_DN("D-0100"));
    DERIVE("V-3793", GET_LAD_DN("D-0101"));
    DERIVE("V-3719", GET_DN());
ELSEIF (index==1)
    DERIVE("V-3727", GET_LAD_DN("D-0092"));
    DERIVE("V-3735", GET_LAD_DN("D-0093"));
    DERIVE("V-3743", GET_LAD_DN("D-0094"));
    DERIVE("V-3751", GET_LAD_DN("D-0095"));
    DERIVE("V-3759", GET_LAD_DN("D-0096"));
    DERIVE("V-3775", GET_LAD_DN("D-0097"));
    DERIVE("V-3767", GET_LAD_DN("D-0098"));
    DERIVE("V-3783", GET_LAD_DN("D-0099"));
    DERIVE("V-3795", GET_LAD_DN("D-0100"));
    DERIVE("V-3718", GET_LAD_DN("D-0101"));
    DERIVE("V-3726", GET_DN());
ELSEIF (index==2)
    DERIVE("V-3734", GET_LAD_DN("D-0092"));
    DERIVE("V-3742", GET_LAD_DN("D-0093"));
    DERIVE("V-3750", GET_LAD_DN("D-0094"));
    DERIVE("V-3758", GET_LAD_DN("D-0095"));
    DERIVE("V-3774", GET_LAD_DN("D-0096"));
    DERIVE("V-3766", GET_LAD_DN("D-0097"));
    DERIVE("V-3782", GET_LAD_DN("D-0098"));
    DERIVE("V-3794", GET_LAD_DN("D-0099"));
    DERIVE("V-3789", GET_LAD_DN("D-0100"));
    DERIVE("V-3720", GET_LAD_DN("D-0101"));
    DERIVE("V-3728", GET_DN());
ELSEIF (index==3)
    DERIVE("V-3736", GET_LAD_DN("D-0092"));
    DERIVE("V-3744", GET_LAD_DN("D-0093"));
    DERIVE("V-3752", GET_LAD_DN("D-0094"));
    DERIVE("V-3760", GET_LAD_DN("D-0095"));
    DERIVE("V-3776", GET_LAD_DN("D-0096"));
    DERIVE("V-3768", GET_LAD_DN("D-0097"));
    DERIVE("V-3784", GET_LAD_DN("D-0098"));
    DERIVE("V-3796", GET_LAD_DN("D-0099"));
    DERIVE("V-3790", GET_LAD_DN("D-0100"));
    DERIVE("V-3799", GET_LAD_DN("D-0101"));
    DERIVE("V-3801", GET_DN());
ELSEIF (index==4)
    /*DERIVE("      ", GET_LAD_DN("D-0092"));*/
    DERIVE("V-3821", GET_LAD_DN("D-0093"));
    DERIVE("V-3815", GET_LAD_DN("D-0094"));
    DERIVE("V-3817", GET_LAD_DN("D-0095"));
    DERIVE("V-3819", GET_LAD_DN("D-0096"));
    /*DERIVE("      ", GET_LAD_DN("D-0097"));*/
    /*DERIVE("      ", GET_LAD_DN("D-0098"));*/
    /*DERIVE("      ", GET_LAD_DN("D-0099"));*/
    DERIVE("V-3804", GET_LAD_DN("D-0100"));
    DERIVE("V-3806", GET_LAD_DN("D-0101"));
    /*DERIVE("      ", GET_DN());*/
ELSEIF (index==5)
    DERIVE("V-3808", GET_LAD_DN("D-0092"));
    DERIVE("V-3800", GET_LAD_DN("D-0093"));
    DERIVE("V-3802", GET_LAD_DN("D-0094"));
    /*DERIVE("      ", GET_LAD_DN("D-0095"));*/
    DERIVE("V-3822", GET_LAD_DN("D-0096"));
    DERIVE("V-3816", GET_LAD_DN("D-0097"));
    DERIVE("V-3818", GET_LAD_DN("D-0098"));
    DERIVE("V-3820", GET_LAD_DN("D-0099"));
    /*DERIVE("      ", GET_LAD_DN("D-0100"));*/
    /*DERIVE("      ", GET_LAD_DN("D-0101"));*/
    /*DERIVE("      ", GET_DN());*/
ELSEIF (index==6)
    DERIVE("V-3805", GET_LAD_DN("D-0092"));
    DERIVE("V-3807", GET_LAD_DN("D-0093"));
    /*DERIVE("      ", GET_LAD_DN("D-0094"));*/
    DERIVE("V-3809", GET_LAD_DN("D-0095"));
    DERIVE("V-3803", GET_LAD_DN("D-0096"));
    DERIVE("V-3721", GET_LAD_DN("D-0097"));
    DERIVE("V-3729", GET_LAD_DN("D-0098"));
    DERIVE("V-3737", GET_LAD_DN("D-0099"));
    DERIVE("V-3745", GET_LAD_DN("D-0100"));
    DERIVE("V-3753", GET_LAD_DN("D-0101"));
    DERIVE("V-3761", GET_DN());
ELSEIF (index==7)
    DERIVE("V-3777", GET_LAD_DN("D-0092"));
    DERIVE("V-3769", GET_LAD_DN("D-0093"));
    DERIVE("V-3785", GET_LAD_DN("D-0094"));
    DERIVE("V-3810", GET_LAD_DN("D-0095"));
    /*DERIVE("      ", GET_LAD_DN("D-0096"));*/
    DERIVE("V-3723", GET_LAD_DN("D-0097"));
    DERIVE("V-3731", GET_LAD_DN("D-0098"));
    DERIVE("V-3739", GET_LAD_DN("D-0099"));
    DERIVE("V-3747", GET_LAD_DN("D-0100"));
    DERIVE("V-3755", GET_LAD_DN("D-0101"));
    DERIVE("V-3763", GET_DN());
ELSEIF (index==8)
    DERIVE("V-3779", GET_LAD_DN("D-0092"));
    DERIVE("V-3771", GET_LAD_DN("D-0093"));
    DERIVE("V-3787", GET_LAD_DN("D-0094"));
    DERIVE("V-3811", GET_LAD_DN("D-0095"));
    /*DERIVE("      ", GET_LAD_DN("D-0096"));*/
    DERIVE("V-3722", GET_LAD_DN("D-0097"));
    DERIVE("V-3730", GET_LAD_DN("D-0098"));
    DERIVE("V-3738", GET_LAD_DN("D-0099"));
    DERIVE("V-3746", GET_LAD_DN("D-0100"));
    DERIVE("V-3754", GET_LAD_DN("D-0101"));
    DERIVE("V-3762", GET_DN());
ELSEIF (index==9)
    DERIVE("V-3778", GET_LAD_DN("D-0092"));
    DERIVE("V-3770", GET_LAD_DN("D-0093"));
    DERIVE("V-3786", GET_LAD_DN("D-0094"));
    DERIVE("V-3797", GET_LAD_DN("D-0095"));
    DERIVE("V-3791", GET_LAD_DN("D-0096"));
    DERIVE("V-3724", GET_LAD_DN("D-0097"));
    DERIVE("V-3732", GET_LAD_DN("D-0098"));
    DERIVE("V-3740", GET_LAD_DN("D-0099"));
    DERIVE("V-3748", GET_LAD_DN("D-0100"));
    DERIVE("V-3756", GET_LAD_DN("D-0101"));
    DERIVE("V-3764", GET_DN());
ELSEIF (index==10)
    DERIVE("V-3780", GET_LAD_DN("D-0092"));
    DERIVE("V-3772", GET_LAD_DN("D-0093"));
    DERIVE("V-3788", GET_LAD_DN("D-0094"));
    DERIVE("V-3798", GET_LAD_DN("D-0095"));
    DERIVE("V-3792", GET_LAD_DN("D-0096"));
    /*DERIVE("      ", GET_LAD_DN("D-0097"));*/
    /*DERIVE("      ", GET_LAD_DN("D-0098"));*/
    /*DERIVE("      ", GET_LAD_DN("D-0099"));*/
    /*DERIVE("      ", GET_LAD_DN("D-0100"));*/
    /*DERIVE("      ", GET_LAD_DN("D-0101"));*/
    /*DERIVE("      ", GET_DN());*/
ENDIF

ENDIF

ENDFUNCT



/*****************************************************************************
 *                                                                           *
 * D-0007 "PDS_MODE"   TRIGGER CHANNEL CODE                                  *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3812
Description:            PDS_MODE
Mnemonic:               PDS_MODE
Subsystem:              PDS
Data_Type:              STATUS
States:                 ram_LRC,MRC,HRC,ram_EOM,RTL,RTM,RTH,MBR,TEST,prom_EOM,prom_LRC

*/

CHILD = "V-3812" PARENTS = "D-0007";

FUNCT CHAN = "D-0007"

UINT state, mode;

mode = GET_DN();

IF (mode==512)
      state = 0;
ELSEIF (mode==768)
      state = 1;
ELSEIF (mode==1024)
      state = 2;
ELSEIF (mode==0)
      state = 3;
ELSEIF (mode==1280)
      state = 4;
ELSEIF (mode==1536)
      state = 5;
ELSEIF (mode==1792)
      state = 6;
ELSEIF (mode==256)
      state = 7;
ELSEIF (mode==2048)
      state = 8;
ELSEIF (mode==6)
      state = 9;
ELSEIF (mode==9)
      state = 10;
ELSE
      state = 11;
ENDIF

DERIVE ("V-3812", state);

ENDFUNCT


/*****************************************************************************
 *                                                                           *
 * D-0000 "PDS_MINPKTID" TRIGGER CHANNEL CODE                                *
 *                                                                           *
 * BASELINED:            OGS 05-01-96                                        *
 * MODIFIED:                                                                 *
 *                                                                           *
 *****************************************************************************/

/*

Derived Channel:        V-3813
Description:            PDS_MINI_PKT
Mnemonic:               PDS_MINI_PKT
Subsystem:              PDS
Data_Type:              STATUS
States:                 PDS_NOMINAL,PDS_RESET,PDS_MRO,unknown

*/

CHILD = "V-3813" PARENTS = "D-0000";

FUNCT CHAN = "D-0000"

UINT state, pkt;

pkt  = GET_DN();

IF (pkt == 3)
      state = 0;
ELSEIF (pkt == 23)
      state = 1;
ELSEIF (pkt == 26)
      state = 2;
ELSE
      state = 3;
ENDIF

DERIVE ("V-3813", state);

ENDFUNCT




/****************************  END PDS DERIVED CHANNELS ***********************/


/*
     File:          mon.ccl
     Description:   CCL algorithms for Multimission Monitor Channels.

	D. Hurley, 11/17/93, initial creation.  Taken mostly from momon.cpt.
		with additions for MON 5-9 algorithms not contained in the
		original file.  Also made edits needed for V19 redesign of
		CCL.
     01/20/94, Daniel Hurley, to include algorithm for M-0214 which was
                    initially missed.
     01/21/94, Daniel Hurley, to correct type definitions in algorithms.
     05/25/94, Daniel Hurley, to correct error in handling negative numbers
                    for SNR values (M-0119, M-0130, M-0214, M-0219, M-0230,
                    M-0114, and M-0136).
     06/09/94, Daniel Hurley, to add parent/child information.
     09/10/95, Daniel Hurley, to make changes for expanded MON 5-15 block.
     10/17/95, Daniel Hurley, for MPF (removed MON 5-9 algorithms).

MISSION = "MGS";

*/

/*
   Create EUs with the form year.doy from days since epoch channels.
   M-0040 (MST DAYS)
*/

FUNCT CHAN = "M-0040"

	INT year, chkvalue, days, olddays;
	FLT eu;

/**************	Get year and DOY from days since epoch		 *************/
								
days = GET_DN();

FOR(year = 1958;TRUE;)
	olddays= days;
	IF(((year % 4) == 0 && (year % 100) != 0) || (year % 400) == 0)
		chkvalue= 366;
	ELSE
		chkvalue= 365;
	ENDIF
	IF (days < chkvalue)
		days= olddays;
		BREAK;
	ELSE
		days -= chkvalue;
	ENDIF
	year++;
ENDFOR

eu= year + (days+1) * 0.001;

PUT_EU(eu);

return RE_ALM;

ENDFUNCT

/*
   Create EUs with the form hhmmss.ms from msec of day channels.
   M-0041 (MST MILSEC)
*/

FUNCT CHAN = "M-0041"

	INT msecs, hr, mn, sc, ms, remainder;
	FLT eu;

/**************	Get hr, mn, sc, and msc from msecs of day	 *************/

msecs = GET_DN();

hr = msecs / 3600000;		/* 3600000 =1000 ms/sc *60 sc/mn *60 mn/hr */
remainder = msecs % 3600000;

mn = remainder / 60000;		/* 60000 =1000 ms/sc *60 sc/mn */
remainder = remainder % 60000;

sc = remainder / 1000;		/* 1000 =1000 ms/sc */
ms = remainder % 1000;

eu = (hr * 10000.0) + (mn * 100.0) + (sc * 1.0) + (ms * 0.001);

PUT_EU(eu);

return RE_ALM;

ENDFUNCT

/*
   Create EUs with the form year.doy from days since epoch channels.
   M-0043 (RCT DAYS)
*/

FUNCT CHAN = "M-0043"

	INT year, chkvalue, days, olddays;
	FLT eu;

/**************	Get year and DOY from days since epoch		 *************/
								
days = GET_DN();

FOR(year = 1958;TRUE;)
	olddays= days;
	IF(((year % 4) == 0 && (year % 100) != 0) || (year % 400) == 0)
		chkvalue= 366;
	ELSE
		chkvalue= 365;
	ENDIF
	IF (days < chkvalue)
		days= olddays;
		BREAK;
	ELSE
		days -= chkvalue;
	ENDIF
	year++;
ENDFOR

eu= year + (days+1) * 0.001;

PUT_EU(eu);

return RE_ALM;

ENDFUNCT

/*
   Create EUs with the form hhmmss.ms from msec of day channels.
   M-0044 (RCT MILSEC)
*/

FUNCT CHAN = "M-0044"

	INT msecs, hr, mn, sc, ms, remainder;
	FLT eu;

/**************	Get hr, mn, sc, and msc from msecs of day	 *************/

msecs = GET_DN();

hr = msecs / 3600000;		/* 3600000 =1000 ms/sc *60 sc/mn *60 mn/hr */
remainder = msecs % 3600000;

mn = remainder / 60000;		/* 60000 =1000 ms/sc *60 sc/mn */
remainder = remainder % 60000;

sc = remainder / 1000;		/* 1000 =1000 ms/sc */
ms = remainder % 1000;

eu = (hr * 10000.0) + (mn * 100.0) + (sc * 1.0) + (ms * 0.001);

PUT_EU(eu);

return RE_ALM;

ENDFUNCT

/*
    M-0109 (SUBCAR1 FREQ) is fixed point binary format with the binary point
    between bits 8 and 9 of the second word (ie bits 24 and 25).
*/

FUNCT CHAN = "M-0109"

     UINT dn;
    FLT eu;

dn = GET_DN();

/* convert from binary fixed point to floating point (dn/2**8) */

eu = (FLT)dn * 0.00390625;

PUT_EU (eu);

return RE_ALM;

ENDFUNCT

/*
    Create EU in base ten for M-0119 (BBA1 SNR) which is fixed point
    two's complement binary format with the binary point between bits 9 and 10.
*/

FUNCT CHAN = "M-0119"

     UINT dn;
     INT num;
     FLT eu;

dn = GET_DN();

/* undo two's complement */

IF (dn > 32768)
    num = dn - 65536;
ELSE
    num = (INT)dn;
ENDIF

/* convert from binary fixed point to floating point (num/2**7) */

eu = (FLT)num * 0.0078125;

PUT_EU (eu);

return RE_ALM;

ENDFUNCT

/*
    Create EU in base ten for M-0130 (MCD1 SNR) which is fixed point
    two's complement binary format with the binary point between bits 9 and 10.
*/

FUNCT CHAN = "M-0130"

     UINT dn;
     INT num;
     FLT eu;

dn = GET_DN();

/* undo two's complement */

IF (dn > 32768)
    num = dn - 65536;
ELSE
    num = (INT)dn;
ENDIF

/* convert from binary fixed point to floating point (num/2**7) */

eu = (FLT)num * 0.0078125;

PUT_EU (eu);

return RE_ALM;

ENDFUNCT

/*
    M-0209 (SUBCAR2 FREQ) is fixed point binary format with the binary point
    between bits 8 and 9 of the second word (ie bits 24 and 25).
*/

FUNCT CHAN = "M-0209"

     UINT dn;
    FLT eu;

dn = GET_DN();

/* convert from binary fixed point to floating point (dn/2**8) */

eu = (FLT)dn * 0.00390625;

PUT_EU (eu);

return RE_ALM;

ENDFUNCT

/*
    Create EU in base ten for M-0214 (SSA2 SNR) which is fixed point
    two's complement binary format with the binary point between bits 9 and 10.
*/

FUNCT CHAN = "M-0214"

     UINT dn;
     INT num;
     FLT eu;

dn = GET_DN();

/* undo two's complement */

IF (dn > 32768)
    num = dn - 65536;
ELSE
    num = (INT)dn;
ENDIF

/* convert from binary fixed point to floating point (num/2**7) */

eu = (FLT)num * 0.0078125;

PUT_EU (eu);

return RE_ALM;

ENDFUNCT

/*
    Create EU in base ten for M-0219 (BBA2 SNR) which is fixed point
    two's complement binary format with the binary point between bits 9 and 10.
*/

FUNCT CHAN = "M-0219"

     UINT dn;
     INT num;
     FLT eu;

dn = GET_DN();

/* undo two's complement */

IF (dn > 32768)
    num = dn - 65536;
ELSE
    num = (INT)dn;
ENDIF

/* convert from binary fixed point to floating point (num/2**7) */

eu = (FLT)num * 0.0078125;

PUT_EU (eu);

return RE_ALM;

ENDFUNCT

/*
    Create EU in base ten for M-0230 (MCD2 SNR) which is fixed point
    two's complement binary format with the binary point between bits 9 and 10.
*/

FUNCT CHAN = "M-0230"

     UINT dn;
     INT num;
     FLT eu;

dn = GET_DN();

/* undo two's complement */

IF (dn > 32768)
    num = dn - 65536;
ELSE
    num = (INT)dn;
ENDIF

/* convert from binary fixed point to floating point (num/2**7) */

eu = (FLT)num * 0.0078125;

PUT_EU (eu);

return RE_ALM;

ENDFUNCT

/*

*/

CHILD = "M-0625" PARENTS = "M-0624";

FUNCT CHAN = "M-0625"

     UINT dn_32, dn_16;
     INT parm, parm_low, parm_hi;
     FLT eu;

/* Get all 48 bits of the Doppler Reference Frequency. */

dn_16 = GET_DN();
dn_32 = GET_LAD_DN("M-0624");

/* Get the CCL parameter, save the first 10 bits, and shift remaining bits
     over. */

parm = GET_PARM();

parm_low = (parm & 1023);
parm_hi = (parm >> 10);

/* Subtract CCL parameter from Doppler Reference Frequency. */

dn_32 = dn_32 - parm_hi;

/* Convert first 32 bits of frequency to Hz. */

dn_32 = (dn_32 << 10);

/* Subtract remaining bits of CCL parameter from frequency. */

dn_32 = dn_32 - parm_low;

/* Combine both parts of frequency for EU. */

/* Convert last 16 bits to Hz (units are 2**-6 Hz) and add in first 32 bits. */

eu = (FLT)dn_16 * 0.015625 + (FLT)dn_32;        /* eu = dn/2**6 */

PUT_EU (eu);

return RE_ALM;

ENDFUNCT

/*****************************************************************************/
/* CCL algorithms for new expanded MON 5-15 channels. */

/*
   Create EUs with the form hhmmss.ms from csec of day channels.
   Also create a new ASCII channel with the format hh:mm:ss.cc.
   M-0662 (SBR MOV CSC)
*/

CHILD = "M-0663" PARENTS = "M-0662";

FUNCT CHAN = "M-0662"

	INT csecs, hr, mn, sc, cs, remainder;
	FLT eu;
     ASCII time, part;

/**************	Get hr, mn, sc, and csc from csecs of day	 *************/

csecs = GET_DN();

hr = csecs / 360000;		/* 360000 =100 cs/sc *60 sc/mn *60 mn/hr */
remainder = csecs % 360000;

mn = remainder / 6000;		/* 6000 =100 cs/sc *60 sc/mn */
remainder = remainder % 6000;

sc = remainder / 100;		/* 100 =100 cs/sc */
cs = remainder % 100;

eu = (hr * 10000.0) + (mn * 100.0) + (sc * 1.0) + (cs * 0.01);

PUT_EU(eu);

part = ANY_TO_ASCII(hr);

IF (ASCII_LENGTH(part) == 1)
     time = ASCII_APPEND("0", part);
ELSE
     time = part;
ENDIF

part = ANY_TO_ASCII(mn);

IF (ASCII_LENGTH(part) == 1)
     part = ASCII_APPEND(":0", part);
ELSE
     part = ASCII_APPEND(":", part);
ENDIF

time = ASCII_APPEND(time, part);

part = ANY_TO_ASCII(sc);

IF (ASCII_LENGTH(part) == 1)
     part = ASCII_APPEND(":0", part);
ELSE
     part = ASCII_APPEND(":", part);
ENDIF

time = ASCII_APPEND(time, part);

part = ANY_TO_ASCII(cs);

IF (ASCII_LENGTH(part) == 2)
     part = ASCII_APPEND(".", part);
ELSE
     part = ASCII_APPEND(".0", part);
ENDIF

time = ASCII_APPEND(time, part);

DERIVE("M-0663", time);

return RE_ALM;

ENDFUNCT

/*
   Create EUs with the form hhmmss.ms from csec of day channels.
   Also create a new ASCII channel with the format hh:mm:ss.cc.
   M-0672 (SBR FIX CSC)
*/

CHILD = "M-0673" PARENTS = "M-0672";

FUNCT CHAN = "M-0672"

	INT csecs, hr, mn, sc, cs, remainder;
	FLT eu;
     ASCII time, part;

/**************	Get hr, mn, sc, and csc from csecs of day	 *************/

csecs = GET_DN();

hr = csecs / 360000;		/* 360000 =100 cs/sc *60 sc/mn *60 mn/hr */
remainder = csecs % 360000;

mn = remainder / 6000;		/* 6000 =100 cs/sc *60 sc/mn */
remainder = remainder % 6000;

sc = remainder / 100;		/* 100 =100 cs/sc */
cs = remainder % 100;

eu = (hr * 10000.0) + (mn * 100.0) + (sc * 1.0) + (cs * 0.01);

PUT_EU(eu);

part = ANY_TO_ASCII(hr);

IF (ASCII_LENGTH(part) == 1)
     time = ASCII_APPEND("0", part);
ELSE
     time = part;
ENDIF

part = ANY_TO_ASCII(mn);

IF (ASCII_LENGTH(part) == 1)
     part = ASCII_APPEND(":0", part);
ELSE
     part = ASCII_APPEND(":", part);
ENDIF

time = ASCII_APPEND(time, part);

part = ANY_TO_ASCII(sc);

IF (ASCII_LENGTH(part) == 1)
     part = ASCII_APPEND(":0", part);
ELSE
     part = ASCII_APPEND(":", part);
ENDIF

time = ASCII_APPEND(time, part);

part = ANY_TO_ASCII(cs);

IF (ASCII_LENGTH(part) == 2)
     part = ASCII_APPEND(".", part);
ELSE
     part = ASCII_APPEND(".0", part);
ENDIF

time = ASCII_APPEND(time, part);

DERIVE("M-0673", time);

return RE_ALM;

ENDFUNCT

/*
   Create EUs which contain the logical receiver numbers.
   M-0702 AA5 PER ID
*/

FUNCT CHAN = "M-0702"

     INT  num, val;

num = GET_DN();

IF (num == 511)
     val = 1;
ELSEIF (num == 512)
     val = 2;
ELSEIF (num == 513)
     val = 3;
ELSEIF (num == 514)
     val = 4;
ELSEIF (num == 515)
     val = 5;
ELSEIF (num == 516)
     val = 6;
ELSEIF (num == 517)
     val = 7;
ELSEIF (num == 518)
     val = 8;
ELSE
     val = 99;
ENDIF

PUT_EU(val);

return RE_ALM;

ENDFUNCT

/*
   Create EUs which contain the logical receiver numbers.
   M-0703 AA5 CON ID
*/

FUNCT CHAN = "M-0703"

     INT  num, val;

num = GET_DN();

IF (num == 521)
     val = 1;
ELSEIF (num == 522)
     val = 2;
ELSEIF (num == 523)
     val = 3;
ELSEIF (num == 524)
     val = 4;
ELSEIF (num == 525)
     val = 5;
ELSEIF (num == 526)
     val = 6;
ELSEIF (num == 527)
     val = 7;
ELSEIF (num == 528)
     val = 8;
ELSE
     val = 99;
ENDIF

PUT_EU(val);

return RE_ALM;

ENDFUNCT

/*
   Create EUs with the form hhmmss from sec of day channels.
   M-0706 (AA5 PER SEC)
*/

FUNCT CHAN = "M-0706"

	INT secs, hr, mn, sc, remainder;
	FLT eu;

/**************	Get hr, mn, and sc from secs of day	 *************/

secs = GET_DN();

hr = secs / 3600;		/* 3600 =60 sc/mn *60 mn/hr */
remainder = secs % 3600;

mn = remainder / 60;		/* 60 =60 sc/mn */
sc = remainder % 60;

eu = (hr * 10000.0) + (mn * 100.0) + (sc * 1.0);

PUT_EU(eu);

return RE_ALM;

ENDFUNCT

/*
   Create EUs with the form hhmmss from sec of day channels.
   M-0707 (AA5 CON SEC)
*/

FUNCT CHAN = "M-0707"

	INT secs, hr, mn, sc, remainder;
	FLT eu;

/**************	Get hr, mn, and sc from secs of day	 *************/

secs = GET_DN();

hr = secs / 3600;		/* 3600 =60 sc/mn *60 mn/hr */
remainder = secs % 3600;

mn = remainder / 60;		/* 60 =60 sc/mn */
sc = remainder % 60;

eu = (hr * 10000.0) + (mn * 100.0) + (sc * 1.0);

PUT_EU(eu);

return RE_ALM;

ENDFUNCT

/*
   Derive ASCII channel containing Status Qualification Value. This is for
   entries which have values greater than 15 and therefore, Status channels
   can not be used.
   M-0714 AA5 CL LCK
*/

CHILD = "M-0715" PARENTS = "M-0714";

FUNCT CHAN = "M-0714"

     INT  num;
     ASCII val;

num = GET_DN();

IF (num == 0)
     val = "NONE";
ELSEIF (num == 1)
     val = "OFF LINE";
ELSEIF (num == 5)
     val = "IN/LOCK";
ELSEIF (num == 6)
     val = "OUT/LOCK";
ELSEIF (num == 17)
     val = "ACQ'ING";
ELSE
     val = ASCII_APPEND("**", ANY_TO_ASCII(num));
ENDIF

DERIVE("M-0715", val);

return;

ENDFUNCT

/*
   Create EUs which contain the logical receiver numbers.
   M-0752 AB5 PER ID
*/

FUNCT CHAN = "M-0752"

     INT  num, val;

num = GET_DN();

IF (num == 511)
     val = 1;
ELSEIF (num == 512)
     val = 2;
ELSEIF (num == 513)
     val = 3;
ELSEIF (num == 514)
     val = 4;
ELSEIF (num == 515)
     val = 5;
ELSEIF (num == 516)
     val = 6;
ELSEIF (num == 517)
     val = 7;
ELSEIF (num == 518)
     val = 8;
ELSE
     val = 99;
ENDIF

PUT_EU(val);

return RE_ALM;

ENDFUNCT

/*
   Create EUs which contain the logical receiver numbers.
   M-0753 AB5 CON ID
*/

FUNCT CHAN = "M-0753"

     INT  num, val;

num = GET_DN();

IF (num == 521)
     val = 1;
ELSEIF (num == 522)
     val = 2;
ELSEIF (num == 523)
     val = 3;
ELSEIF (num == 524)
     val = 4;
ELSEIF (num == 525)
     val = 5;
ELSEIF (num == 526)
     val = 6;
ELSEIF (num == 527)
     val = 7;
ELSEIF (num == 528)
     val = 8;
ELSE
     val = 99;
ENDIF

PUT_EU(val);

return RE_ALM;

ENDFUNCT

/*
   Create EUs with the form hhmmss from sec of day channels.
   M-0756 (AB5 PER SEC)
*/

FUNCT CHAN = "M-0756"

	INT secs, hr, mn, sc, remainder;
	FLT eu;

/**************	Get hr, mn, and sc from secs of day	 *************/

secs = GET_DN();

hr = secs / 3600;		/* 3600 =60 sc/mn *60 mn/hr */
remainder = secs % 3600;

mn = remainder / 60;		/* 60 =60 sc/mn */
sc = remainder % 60;

eu = (hr * 10000.0) + (mn * 100.0) + (sc * 1.0);

PUT_EU(eu);

return RE_ALM;

ENDFUNCT

/*
   Create EUs with the form hhmmss from sec of day channels.
   M-0757 (AB5 CON SEC)
*/

FUNCT CHAN = "M-0757"

	INT secs, hr, mn, sc, remainder;
	FLT eu;

/**************	Get hr, mn, and sc from secs of day	 *************/

secs = GET_DN();

hr = secs / 3600;		/* 3600 =60 sc/mn *60 mn/hr */
remainder = secs % 3600;

mn = remainder / 60;		/* 60 =60 sc/mn */
sc = remainder % 60;

eu = (hr * 10000.0) + (mn * 100.0) + (sc * 1.0);

PUT_EU(eu);

return RE_ALM;

ENDFUNCT

/*
   Derive ASCII channel containing Status Qualification Value. This is for
   entries which have values greater than 15 and therefore, Status channels
   can not be used.
   M-0764 AB5 CL LCK
*/

CHILD = "M-0765" PARENTS = "M-0764";

FUNCT CHAN = "M-0764"

     INT  num;
     ASCII val;

num = GET_DN();

IF (num == 0)
     val = "NONE";
ELSEIF (num == 1)
     val = "OFF LINE";
ELSEIF (num == 5)
     val = "IN/LOCK";
ELSEIF (num == 6)
     val = "OUT/LOCK";
ELSEIF (num == 17)
     val = "ACQ'ING";
ELSE
     val = ASCII_APPEND("**", ANY_TO_ASCII(num));
ENDIF

DERIVE("M-0765", val);

return;

ENDFUNCT

/*****************************************************************************/
/* CCL algorithms that were in MON 5-9 and are now MON 5-15 channels. */

/*
    Create EU in base ten for M-0114 (SSA1 SNR) which is fixed point
    two's complement binary format with the binary point between bits 9 and 10.
*/

FUNCT CHAN = "M-0114"

     UINT dn;
     INT num;
     FLT eu;

dn = GET_DN();

/* undo two's complement */

IF (dn > 32768)
    num = dn - 65536;
ELSE
    num = (INT)dn;
ENDIF

/* convert from binary fixed point to floating point (num/2**7) */

eu = (FLT)num * 0.0078125;

PUT_EU (eu);

return RE_ALM;

ENDFUNCT
