////////////////////////////////////////////////////////////////////////////////
//
// PURPOSE:  Dvl Log Class.
// AUTHOR:   Rob McEwen.
// DATE:     01/3/9
// COMMENTS: 
//
////////////////////////////////////////////////////////////////////////////////
//

#include "DvlSideLog.h"
#include "SimulatedDvlSide.h"


DvlSideLog::DvlSideLog(SimulatedDvlSide *dvlSide, DataLog::FileFormat fileFormat)
  : DataLogWriter(DvlSideLogName, fileFormat, AutoTimeStamp)
{
  m_dvl = dvlSide;
  setMnemonic("dvlSide.data");

  addField(m_dvlPingTime   = new DoubleData("dvlSide.PingTime") );
  m_dvlPingTime->setAsciiFormat("%.2f");

  addField(m_dvlBotVel_x   = new DoubleData("dvlSide.BotVelx") );
  addField(m_dvlBotVel_y   = new DoubleData("dvlSide.BotVely") );
  addField(m_dvlBotVel_z   = new DoubleData("dvlSide.BotVelz") );
  addField(m_dvlBotVel_e   = new DoubleData("dvlSide.BotVele") );
  addField(m_dvlBotVelStat = new ShortData ("dvlSide.BotVelStat") );

  addField(m_dvlWatVel_x   = new DoubleData("dvlSide.WatVelx") );
  addField(m_dvlWatVel_y   = new DoubleData("dvlSide.WatVely") );
  addField(m_dvlWatVel_z   = new DoubleData("dvlSide.WatVelz") );
  addField(m_dvlWatVel_e   = new DoubleData("dvlSide.WatVele") );
  addField(m_dvlWatVelStat = new ShortData ("dvlSide.WatVelStat") );

  addField(m_dvlTemp    = new DoubleData("dvlSide.Temp") );
  addField(m_dvlPitch   = new DoubleData("dvlSide.Pitch") );
  addField(m_dvlRoll    = new DoubleData("dvlSide.Roll") );
  addField(m_dvlHeading = new DoubleData("dvlSide.Heading") );
  addField(m_dvlRange   = new DoubleData("dvlSide.Range") );

  addField(m_dvlBeam1 =   new DoubleData("dvlSide.Beam1") );
  m_dvlBeam1->setAsciiFormat("%4.6f");
  addField(m_dvlBeam2 =   new DoubleData("dvlSide.Beam2") );
  m_dvlBeam2->setAsciiFormat("%4.6f");
  addField(m_dvlBeam3 =   new DoubleData("dvlSide.Beam3") );
  m_dvlBeam3->setAsciiFormat("%4.6f");
  addField(m_dvlBeam4 =   new DoubleData("dvlSide.Beam4") );
  m_dvlBeam3->setAsciiFormat("%4.6f");
  //
  // Setup units and longname fields for logging
  //
  m_dvlPingTime->setUnits("Seconds");

  m_dvlBotVel_x->setUnits("meters/second");
  m_dvlBotVel_y->setUnits("meters/second");
  m_dvlBotVel_z->setUnits("meters/second");
  m_dvlBotVel_e->setUnits("meters/second");
  m_dvlBotVelStat->setUnits("Unitless");

  m_dvlWatVel_x->setUnits("meters/second");
  m_dvlWatVel_y->setUnits("meters/second");
  m_dvlWatVel_z->setUnits("meters/second");
  m_dvlWatVel_e->setUnits("meters/second");
  m_dvlWatVelStat->setUnits("Unitless");

  m_dvlTemp->setUnits("Celsius");
  m_dvlPitch->setUnits("Degrees");
  m_dvlRoll->setUnits("Degrees");
  m_dvlHeading->setUnits("Degrees");
  m_dvlRange->setUnits("meters");
  m_dvlBeam1->setUnits("meters");
  m_dvlBeam2->setUnits("meters");
  m_dvlBeam3->setUnits("meters");
  m_dvlBeam4->setUnits("meters");

  m_dvlPingTime->setLongName("Time of First Ping");

  m_dvlBotVel_x->setLongName("Velocity component along x-axis with respect to the bottom");
  m_dvlBotVel_y->setLongName("Velocity component along y-axis with respect to the bottom");
  m_dvlBotVel_z->setLongName("Velocity component along z-axis with respect to the bottom");
  m_dvlBotVel_e->setLongName("Velocity error component with respect to the bottom");
  m_dvlBotVelStat->setLongName("Status code for velocity with respect to the bottom");

  m_dvlWatVel_x->setLongName("Velocity component along x-axis with respect to a water layer");
  m_dvlWatVel_y->setLongName("Velocity component along y-axis with respect to a water layer");
  m_dvlWatVel_z->setLongName("Velocity component along z-axis with respect to a water layer");
  m_dvlWatVel_e->setLongName("Velocity error component with respect to a water layer");
  m_dvlWatVelStat->setLongName("Status code for velocity with respect to the water");

  m_dvlTemp->setLongName("DVL internal temperature");
  m_dvlPitch->setLongName("DVL Pitch");
  m_dvlRoll->setLongName("DVL Roll");
  m_dvlHeading->setLongName("DVL Heading");
  m_dvlRange->setLongName("DVL altitude above bottom");
  m_dvlBeam1->setLongName("Range of Dvl Beam 1");
  m_dvlBeam2->setLongName("Range of Dvl Beam 2");
  m_dvlBeam3->setLongName("Range of Dvl Beam 3");
  m_dvlBeam4->setLongName("Range of Dvl Beam 4");
}


DvlSideLog::~DvlSideLog()
{
  delete m_dvlPingTime;
	
  delete m_dvlBotVel_x;
  delete m_dvlBotVel_y;
  delete m_dvlBotVel_z;
  delete m_dvlBotVel_e;
  delete m_dvlBotVelStat;

  delete m_dvlWatVel_x;
  delete m_dvlWatVel_y;
  delete m_dvlWatVel_z;
  delete m_dvlWatVel_e;
  delete m_dvlWatVelStat;

  delete m_dvlTemp;
  delete m_dvlPitch;
  delete m_dvlRoll;
  delete m_dvlHeading;
  delete m_dvlRange;
  delete m_dvlBeam1;
  delete m_dvlBeam2;
  delete m_dvlBeam3;
  delete m_dvlBeam4;
}


void DvlSideLog::setFields()
{
  m_dvlPingTime->setValue( *(m_dvl->dvlPingTime) );

  m_dvlBotVel_x->setValue( m_dvl->bottomTrackVelocity[0] );
  m_dvlBotVel_y->setValue( m_dvl->bottomTrackVelocity[1] );
  m_dvlBotVel_z->setValue( m_dvl->bottomTrackVelocity[2] );
  m_dvlBotVel_e->setValue( m_dvl->bottomTrackVelocity[3] );
  m_dvlBotVelStat->setValue( (short) *(m_dvl->bottomStatus) );

  m_dvlWatVel_x->setValue( m_dvl->waterMassVelocity[0] );
  m_dvlWatVel_y->setValue( m_dvl->waterMassVelocity[1] );
  m_dvlWatVel_z->setValue( m_dvl->waterMassVelocity[2] );
  m_dvlWatVel_e->setValue( m_dvl->waterMassVelocity[3] );
  m_dvlWatVelStat->setValue( (short) *(m_dvl->waterStatus) );

  m_dvlTemp->   setValue( *(m_dvl->dvlTemp) );
  m_dvlPitch->  setValue( *(m_dvl->dvlPitch) );
  m_dvlRoll->   setValue( *(m_dvl->dvlRoll) );
  m_dvlHeading->setValue( *(m_dvl->dvlHeading) );
  m_dvlRange->  setValue( *(m_dvl->dvlRange) );

  m_dvlBeam1->  setValue( m_dvl->beamRange[0] );
  m_dvlBeam2->  setValue( m_dvl->beamRange[1] );
  m_dvlBeam3->  setValue( m_dvl->beamRange[2] );
  m_dvlBeam4->  setValue( m_dvl->beamRange[3] );
}

