////////////////////////////////////////////////////////////////////////////////
//
// PURPOSE:  DropWeight Log Class.
// AUTHOR:   Rob McEwen.
// DATE:     04/2/6
// COMMENTS: 
//
////////////////////////////////////////////////////////////////////////////////
//
#include "AdaptiveSamplerLog.h"
#include "AdaptiveSampler.h"
//#include "Syslog.h"

AdaptiveSamplerLog::AdaptiveSamplerLog(AdaptiveSampler *adaptiveSampler, 
		     DataLog::FileFormat fileFormat)
  : DataLogWriter(AdaptiveSamplerLogName, fileFormat, AutoTimeStamp)
{
  _adaptiveSampler= adaptiveSampler;
  setMnemonic("asp.data");

  for( int i=0; i<NGULPERS; i++)
  {
     sprintf(strName, "asp.Gulper%d", i);
     addField( (_gulper[i] = new ShortData( strName )) );
  }

  for(i=0; i<MAXSTOREDDEPTHS; i++)
  {
     sprintf(strName, "asp.tempdep%d", i);
     addField((_tempDep[i] = new DoubleData(strName)));
  }

  for(i=0; i<MAXSTOREDPROFILES; i++)
  {
     sprintf(strName, "asp.tempdiff%d", i);
     addField((_temp_diff[i] = new DoubleData(strName)));

     sprintf(strName, "asp.tempdifflp%d", i);
     addField((_temp_diff_lp[i] = new DoubleData(strName)));
  }

  addField((_gnum= new ShortData("asp.num")));
  addField((_depthCheck= new ShortData("asp.dchk")));
  addField((_salCheck  = new ShortData("asp.schk")));
  addField((_tempCheck = new ShortData("asp.tchk")));
  addField((_fl676Check = new ShortData("asp.fl676chk")));
  addField((_bb470Check = new ShortData("asp.bb470chk")));
  addField((_bb676Check = new ShortData("asp.bb676chk")));
  addField((_lat = new DoubleData("asp.lat")));
  addField((_lon = new DoubleData("asp.lon")));
  addField((_sal = new DoubleData("asp.sal")));
  addField((_temp= new DoubleData("asp.temp")));
  addField((_depth = new DoubleData("asp.depth")));
  addField((_fl676 = new DoubleData("asp.fl676")));
  addField((_bb470 = new DoubleData("asp.bb470")));
  addField((_bb676 = new DoubleData("asp.bb676")));
  addField((_fl676_bkgnd = new DoubleData("asp.fl676bkgnd")));
  addField((_bb470_bkgnd = new DoubleData("asp.bb470bkgnd")));
  addField((_bb676_bkgnd = new DoubleData("asp.bb676bkgnd")));
  addField((_fl676_lp = new DoubleData("asp.fl676lp")));
  addField((_bb470_lp = new DoubleData("asp.bb470lp")));
  addField((_bb676_lp = new DoubleData("asp.bb676lp")));
  addField((_peak_baseline = new DoubleData("asp.peakbaseline")));
  addField((_peak_saved = new DoubleData("asp.peaksaved")));
  addField((_peakCheck = new ShortData("asp.peakcheck")));
  addField((_pk_ctrl = new ShortData("asp.pkctrl")));
  addField((_upwellingCheck = new ShortData("asp.upwellingcheck")));
  addField((_frontCheck = new ShortData("asp.frontcheck")));
  addField((_flMaxOnPrecedingProfile = new DoubleData("asp.flmaxonprecedingprofile")));
  addField((_dep_flMaxOnPrecedingProfile = new DoubleData("asp.depflmaxonprecedingprofile")));
  addField((_flMaxOnProfile_avg = new DoubleData("asp.flmaxonprofileavg")));

  _lat->setAsciiFormat("%5.8f");       
  _lon->setAsciiFormat("%5.8f");       
}


AdaptiveSamplerLog::~AdaptiveSamplerLog()
{
  for( int i=0; i<NGULPERS; i++)
    delete _gulper[i];

  for(i=0; i<MAXSTOREDDEPTHS; i++)
    delete _tempDep[i];

  for(i=0; i<MAXSTOREDPROFILES; i++)
    {
      delete _temp_diff[i];
      delete _temp_diff_lp[i];
    }

  delete _gnum, _depthCheck, _tempCheck, _salCheck, _fl676Check, _bb470Check, _bb676Check, _peakCheck, _pk_ctrl, _upwellingCheck, _frontCheck;
  delete _lat, _lon, _sal, _temp, _depth, _fl676, _bb470, _bb676;
  delete _fl676_bkgnd, _bb470_bkgnd, _bb676_bkgnd, _fl676_lp, _bb470_lp, _bb676_lp;
  delete _peak_baseline, _peak_saved, _dep_flMaxOnPrecedingProfile, _flMaxOnPrecedingProfile, _flMaxOnProfile_avg;
}


void AdaptiveSamplerLog::setFields()
{
   for( int i=0; i<NGULPERS; i++) 
      _gulper[i]->setValue( _adaptiveSampler->_output->data.gulperState[i] );

   _gnum->setValue(_adaptiveSampler->_gnum);

   //Syslog::write("AdaptiveSamplerLog:: Got here - 1!");

   if( _adaptiveSampler->_nav )
   {
      _lat->setValue(_adaptiveSampler->_position.latitude);
      _lon->setValue(_adaptiveSampler->_position.longitude);
   }
   //Syslog::write("AdaptiveSamplerLog:: Got here - 2!");
   _sal->setValue(_adaptiveSampler->_salinity);
   _temp->setValue(_adaptiveSampler->_temperature);
   _depth->setValue(_adaptiveSampler->_depth);
   _fl676->setValue(_adaptiveSampler->_fl676);
   _bb470->setValue(_adaptiveSampler->_bb470);
   _bb676->setValue(_adaptiveSampler->_bb676);
   _salCheck->setValue(_adaptiveSampler->_salCheck);
   _tempCheck->setValue(_adaptiveSampler->_tempCheck);
   _depthCheck->setValue(_adaptiveSampler->_depthCheck);
   _fl676Check->setValue(_adaptiveSampler->_fl676Check);
   _bb470Check->setValue(_adaptiveSampler->_bb470Check);
   _bb676Check->setValue(_adaptiveSampler->_bb676Check);
   _fl676_bkgnd->setValue(_adaptiveSampler->_fl676_bkgnd);
   _bb470_bkgnd->setValue(_adaptiveSampler->_bb470_bkgnd);
   _bb676_bkgnd->setValue(_adaptiveSampler->_bb676_bkgnd);
   _fl676_lp->setValue(_adaptiveSampler->_fl676_lp[0]);
   _bb470_lp->setValue(_adaptiveSampler->_bb470_lp[0]);
   _bb676_lp->setValue(_adaptiveSampler->_bb676_lp);
   _peak_baseline->setValue(_adaptiveSampler->_peak_baseline);
   _peak_saved->setValue(_adaptiveSampler->_peak_saved);
   _peakCheck->setValue(_adaptiveSampler->_peakCheck);
   _pk_ctrl->setValue(_adaptiveSampler->_pk_ctrl);
   _upwellingCheck->setValue(_adaptiveSampler->_upwellingCheck);
   _frontCheck->setValue(_adaptiveSampler->_frontCheck);

   _flMaxOnPrecedingProfile->setValue(_adaptiveSampler->_flMaxOnPrecedingProfile);
   _dep_flMaxOnPrecedingProfile->setValue(_adaptiveSampler->_dep_flMaxOnPrecedingProfile);
   _flMaxOnProfile_avg->setValue(_adaptiveSampler->_flMaxOnProfile_avg);

   for(i=0; i<=3; i++)
     _tempDep[i]->setValue(_adaptiveSampler->_tempDep[i]);

   for(i=0; i<MAXSTOREDPROFILES; i++)
     {
       _temp_diff[i]->setValue(_adaptiveSampler->_temp_diff[i]);
       _temp_diff_lp[i]->setValue(_adaptiveSampler->_temp_diff_lp[i]);
     }

   //Syslog::write("AdaptiveSamplerLog:: Finished!");
}

