/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : CTDLog.cc                                                     */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#include "DataLogWriter.h"
#include "CTDLog.h"
#include "CTD.h"
#include "TimeP.h"
#include "Syslog.h"

CtdLog::CtdLog(Ctd *ctd)
  : DataLogWriter(CtdLogName, DataLog::BinaryFormat, AutoTimeStamp) 
{
  Syslog::write("CTDLog.cc -- beginning constructor...\n");
  setMnemonic("ctdlog");

  addField((_cond = new DoubleData("conductivity")));
  addField((_temp = new DoubleData("temperature")));
  addField((_cfreq = new DoubleData("cond_frequency")));
  addField((_tfreq = new DoubleData("temp_frequency")));

  // static names for now, to be changed as soon as a "setname" method
  // is added to the Data class.

  addField((_v1 = new DoubleData("v1")));
  addField((_v2 = new DoubleData("v2")));
  addField((_v3 = new DoubleData("v3")));
  addField((_v4 = new DoubleData("v4")));
  addField((_v5 = new DoubleData("v5")));
  addField((_v6 = new DoubleData("v6")));

  // Set preferred format for ascii printing
  _cond->setAsciiFormat("%8.8e");
  _temp->setAsciiFormat("%8.8e");
  _cfreq->setAsciiFormat("%8.8e");
  _tfreq->setAsciiFormat("%8.8e");
  _v1->setAsciiFormat("%8.8e");
  _v2->setAsciiFormat("%8.8e");
  _v3->setAsciiFormat("%8.8e");
  _v4->setAsciiFormat("%8.8e");
  _v5->setAsciiFormat("%8.8e");
  _v6->setAsciiFormat("%8.8e");

  _ctd = ctd;
  Syslog::write("CTDLog.cc -- constructor succeeded\n");
}


CtdLog::~CtdLog()
{
  delete _cond;
  delete _temp;
  delete _cfreq;
  delete _tfreq;
  delete _v1;
  delete _v2;
  delete _v3;
  delete _v4;
  delete _v5;
  delete _v6;
}


void CtdLog::setFields()
{

  // Set range value
  _cond->setValue(_ctd->read_cond);
  _temp->setValue(_ctd->read_temp);
  _cfreq->setValue(_ctd->read_cfreq);
  _tfreq->setValue(_ctd->read_tfreq);
  
  if (_ctd->NUMVOLTAGES > 0)
    _v1->setValue(_ctd->voltages[0]);
  if (_ctd->NUMVOLTAGES > 1)
    _v2->setValue(_ctd->voltages[1]);
  if (_ctd->NUMVOLTAGES > 2)
    _v3->setValue(_ctd->voltages[2]);
  if (_ctd->NUMVOLTAGES > 3)
    _v4->setValue(_ctd->voltages[3]);
  if (_ctd->NUMVOLTAGES > 4)
    _v5->setValue(_ctd->voltages[4]);
  if (_ctd->NUMVOLTAGES > 5)
    _v6->setValue(_ctd->voltages[5]);
    
}



