##// END OF EJS Templates
added quick fileName generation for data export, and fixed wrong date reading...
added quick fileName generation for data export, and fixed wrong date reading on cassini data files.

File last commit:

r10:63067c6877ba default
r10:63067c6877ba default
Show More
cassinitools.cpp
277 lines | 8.8 KiB | text/x-c | CppLexer
Added Python Console and some Wrappers....
r5 #include "cassinitools.h"
#include <qlopplots.h>
#include <QPen>
A lot of refactoring:...
r6 #include <QAction>
Added preliminary version of FFT and removed memory leak.
r9 #include <fftw3.h>
Added Python Console and some Wrappers....
r5
CassiniTools* CassiniTools::_self=NULL;
QDockWidget* CassiniTools::m_gui=NULL;
CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL;
CassiniDataFile* CassiniTools::m_dataFile=NULL;
A lot of refactoring:...
r6 int CassiniTools::m_defaultPlot=-1;
Added preliminary version of FFT and removed memory leak.
r9 int CassiniTools::m_fftPlot=-1;
added quick fileName generation for data export, and fixed wrong date reading...
r10 SocExplorerPlotActions* CassiniTools::ExportAction=NULL;
Added Python Console and some Wrappers....
r5
Qt::GlobalColor QLopColours[]= {Qt::black,
Qt::red,
Qt::blue,
Qt::green,
Qt::darkGreen,
Qt::cyan,
Qt::darkRed,
Qt::gray,
Qt::yellow,
Qt::darkBlue,
Qt::darkCyan,
Qt::magenta,
Qt::darkMagenta,
Qt::darkYellow,
Qt::darkGray,
Qt::lightGray};
int QLopColoursCount=16;
#define _INIT() if(Q_UNLIKELY(_self==NULL)){init();}
CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent)
{
m_dataFile = new CassiniDataFile();
connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList)));
m_serviceName="CassiniTools";
m_noGui=noGUI;
}
CassiniTools::~CassiniTools()
{
delete m_dataFile;
delete m_CassiniToolsGUI;
delete m_gui;
}
A lot of refactoring:...
r6 void CassiniTools::makePlot()
{
m_defaultPlot = QLopPlots::addPlot();
Added preliminary version of FFT and removed memory leak.
r9 m_fftPlot = QLopPlots::addPlot();
A lot of refactoring:...
r6 SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot);
if(plot)
{
plot->setTitle(_self->m_serviceName + " plot");
plot->setXaxisTickLabelType(QCPAxis::ltDateTime);
plot->setXaxisDateTimeFormat("hh:mm:ss.zzz");
plot->setContextMenuPolicy(Qt::ActionsContextMenu);
Removed hack from QCustomPlot, moved to QCustomPlotVect class.
r7 SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self);
A lot of refactoring:...
r6 plot->addAction(action);
plot view export works on cassini fgm data.
r8 QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int)));
added quick fileName generation for data export, and fixed wrong date reading...
r10 ExportAction=new SocExplorerPlotActions("export view to "+QString(plot->title()).replace(".TAB","-part.TAB"),plot->PID(),_self);
plot->addAction(ExportAction);
QObject::connect(ExportAction,SIGNAL(triggered(int)),_self,SLOT(export_view_Predefined_FileName(int)));
Added preliminary version of FFT and removed memory leak.
r9 action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self);
plot->addAction(action);
QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int)));
A lot of refactoring:...
r6 }
}
Added Python Console and some Wrappers....
r5 void CassiniTools::init(bool noGUI, QObject *parent)
{
if(Q_UNLIKELY(_self==NULL))
{
_self=new CassiniTools(noGUI,parent);
}
}
CassiniTools *CassiniTools::self()
{
_INIT();
return _self;
}
void CassiniTools::decodeFGMData(const QString &file)
{
_INIT();
m_dataFile->parseFile(file);
}
void CassiniTools::plotFile(const QString &File)
{
Added preliminary version of FFT and removed memory leak.
r9 if(!m_dataFile->isRunning())
Added Python Console and some Wrappers....
r5 {
Added preliminary version of FFT and removed memory leak.
r9 m_dataFile->parseFile(File);
// TODO fixme
SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
if(plot==NULL)
{
makePlot();
plot = QLopPlots::getPlot(m_defaultPlot);
}
if(plot)
added quick fileName generation for data export, and fixed wrong date reading...
r10 {
Added preliminary version of FFT and removed memory leak.
r9 plot->setTitle(File);
added quick fileName generation for data export, and fixed wrong date reading...
r10 ExportAction->setText("export view to "+QString(File).replace(".TAB","-part.TAB"));
}
Added preliminary version of FFT and removed memory leak.
r9 }
Added Python Console and some Wrappers....
r5 }
void CassiniTools::plot_TAB_File(const QString &fileName)
{
A lot of refactoring:...
r6 //TODO fix: accent not accepted
plotFile(fileName);
}
Added Python Console and some Wrappers....
r5
Removed hack from QCustomPlot, moved to QCustomPlotVect class.
r7 void CassiniTools::export_view(int PID)
A lot of refactoring:...
r6 {
Removed hack from QCustomPlot, moved to QCustomPlotVect class.
r7 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
A lot of refactoring:...
r6 if(plot==NULL)
Removed hack from QCustomPlot, moved to QCustomPlotVect class.
r7 return;
A lot of refactoring:...
r6 {
added quick fileName generation for data export, and fixed wrong date reading...
r10 QString fileName = plot->title();
fileName = QFileDialog::getSaveFileName(0,tr("Set filename"),fileName.replace(".TAB","-part.TAB"));
if(fileName!="")
{
QLopDataList vectors;
for(int i=0;i<plot->graphCount();i++)
{
QLopData* vect = new QLopData();
vect->data = plot->getVisibleData(i);
vectors.append(vect);
}
m_dataFile->saveFile(fileName,vectors);
}
}
}
void CassiniTools::export_view_Predefined_FileName(int PID)
{
SocExplorerPlot* plot = QLopPlots::getPlot(PID);
if(plot==NULL)
return;
{
QString fileName = QString(plot->title()).replace(".TAB","-part.TAB");
plot view export works on cassini fgm data.
r8 if(fileName!="")
{
QLopDataList vectors;
for(int i=0;i<plot->graphCount();i++)
{
QLopData* vect = new QLopData();
vect->data = plot->getVisibleData(i);
vectors.append(vect);
}
m_dataFile->saveFile(fileName,vectors);
}
A lot of refactoring:...
r6 }
Added Python Console and some Wrappers....
r5 }
Added preliminary version of FFT and removed memory leak.
r9 void CassiniTools::compute_fft_on_view(int PID)
{
SocExplorerPlot* plot = QLopPlots::getPlot(PID);
if(plot==NULL)
return;
{
QLopDataList vectors;
for(int i=0;i<plot->graphCount();i++)
{
QLopData* vect = new QLopData();
vect->data = plot->getVisibleData(i);
vectors.append(vect);
}
if(vectors.count()==3)
{
QLopData* ch1V=vectors.at(0);
QLopData* ch2V=vectors.at(1);
QLopData* ch3V=vectors.at(2);
QLopData* FFTout=new QLopData();
if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count())
{
double* in;
fftw_complex *out;
fftw_plan p;
FFTout->data = new QVector<QCPData>(ch1V->data->count()/2);
in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count());
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count());
double av=0;
for(int i=0;i<ch1V->data->count();i++)
{
in[i]=sqrt((ch1V->data->at(i).value*ch1V->data->at(i).value) + (ch2V->data->at(i).value*ch2V->data->at(i).value) + (ch3V->data->at(i).value*ch3V->data->at(i).value));
av = av+in[i];
}
av/=ch1V->data->count();
for(int i=0;i<ch1V->data->count();i++)
{
in[i]=in[i]-av;
}
p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE);
fftw_execute(p); /* repeat as needed */
fftw_destroy_plan(p);
fftw_free(in);
for(int i=0;i<ch1V->data->count()/2;i++)
{
// (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count();
(*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count());
(*FFTout->data)[i].key = i;
}
fftw_free(out);
SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot);
if(plot==NULL)
return;
plot->removeAllGraphs();
plot->addGraph();
plot->setXaxisLog();
plot->setYaxisLog();
plot->setAdaptativeSampling(0,true);
QPen pen = plot->getGraphPen(0);
pen.setColor(QLopColours[0%QLopColoursCount]);
plot->setGraphPen(0,pen);
plot->setGraphData(0,FFTout->data,false);
plot->rescaleAxis();
plot->replot();
}
}
}
}
Added Python Console and some Wrappers....
r5 QDockWidget *CassiniTools::getGUI()
{
if(!m_noGui && (m_gui==NULL))
{
m_gui=new QDockWidget("Cassini Tools");
m_CassiniToolsGUI = new CassiniToolsGUI();
m_gui->setWidget(m_CassiniToolsGUI);
m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
}
return m_gui;
}
const QString &CassiniTools::serviceName()
{
_INIT();
return m_serviceName;
}
void CassiniTools::dataReady(QLopDataList data)
{
A lot of refactoring:...
r6 SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
if(plot==NULL)
{
Added preliminary version of FFT and removed memory leak.
r9 makePlot();
plot = QLopPlots::getPlot(m_defaultPlot);
A lot of refactoring:...
r6 }
if(plot)
{
Added preliminary version of FFT and removed memory leak.
r9 plot->removeAllGraphs();
for(int i=0;i<data.count();i++)
{
plot->addGraph();
plot->setAdaptativeSampling(i,true);
plot->setUseFastVector(i,true);
QPen pen = plot->getGraphPen(i);
pen.setColor(QLopColours[i%QLopColoursCount]);
plot->setGraphPen(i,pen);
plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")");
plot->setGraphData(i,data.at(i)->data,false);
}
plot->rescaleAxis();
plot->replot();
A lot of refactoring:...
r6 }
Added Python Console and some Wrappers....
r5 }