/** \file
 *
 *  Contains the TempGradientCalculator class declaration.
 *
 *  TempGradientCalculator.h should only be included by TempGradientCalculator.cpp
 *  Other classes should include TempGradientCalculatorIF.h
 *
 *  Copyright (c) 2007,2008,2009,2010 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef TEMPGRADIENTCALCULATOR_H_
#define TEMPGRADIENTCALCULATOR_H_

#include "component/SyncComponent.h"

class ConfigReader;
class UniversalDataReader;
class UniversalDataWriter;

/*
 *
 */
class TempGradientCalculator : public SyncDerivationComponent
{
public:
    TempGradientCalculator( const Module* module );
    virtual ~TempGradientCalculator();

    /// Initialize function
    void initialize( void );

    /// The actual "payload" of the component
    void run( void );

    void captureTempGradPeakCalcTempHoriGrad( float, float );

private:

    void readConfig();

    static const int MAX_CONSEC_DEPTHS = 50;
    //    static const int MAX_PROFILES = 1000; // Saves up to 1000 profiles.
    static const int MAX_PROFILES = 10; // Saves up to 1000 profiles.

    float dep_[MAX_CONSEC_DEPTHS], depBin_, binsizeDep_, tempDepBin_[3], depBinEnd_[3], tempGrad_, depTempGrad_;
    float tempGradPk_, depTempGradPk_, lastDepTempGradPk_, tempGradMaxabs_, depMax_, depMin_, threshDepChangeAbs_, extensionDep_;
    float depTarget_, lastDepTarget_;
    float tempAvgLayer_, tempAvgLayerArray_[MAX_PROFILES], tempAvgLayerLP_[MAX_PROFILES], depShallowBndForAvg_, depDeepBndForAvg_, tempAvgLayerSumInWindow_, tempHoriGrad_;
    int numAvg_, binCnt_, pkDetected_, stateDepth_[2], numConsecutiveDepths_, cntProfileAvgLayer_, numAvgLayer_, flagDepthShallow_, flagDepthDeep_, numProfilesLP_, numProfilesGap_;
    friend class TempGradientCalculator_Test;

    // Accessors
    UniversalDataReader* depthReader_;
    UniversalDataReader* tempReader_;
    UniversalDataWriter* tempGradientWriter_;
    DataWriter* thermoclineDepthWriter_;
    DataWriter* targetDepthWriter_;
    DataWriter* tempHoriGradWriter_;
    ConfigReader* binsizeDepCfgReader_;
    ConfigReader* numConsecutiveDepthsCfgReader_;
    ConfigReader* threshDepChangeAbsCfgReader_;
    ConfigReader* extensionDepCfgReader_;
    ConfigReader* depShallowBndForAvgCfgReader_;
    ConfigReader* depDeepBndForAvgCfgReader_;
    ConfigReader* numProfilesLPCfgReader_;
    ConfigReader* numProfilesGapCfgReader_;

};

#endif /*TEMPGRADIENTCALCULATOR_H_*/
