##// END OF EJS Templates
Fixed bug 388...
Fixed bug 388 Added cassini FGM download from Time table files. Fixed smal issue on export function. Some Work on QLop database.

File last commit:

r14:0e9217f77498 default
r14:0e9217f77498 default
Show More
cassinitools.cpp
346 lines | 11.5 KiB | text/x-c | CppLexer
added missing GPL headers...
r11 /*------------------------------------------------------------------------------
-- This file is a part of the QLop Software
-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------*/
/*-- Author : Alexis Jeandet
-- Mail : alexis.jeandet@member.fsf.org
----------------------------------------------------------------------------*/
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 missing GPL headers...
r11 #include <omp.h>
Fixed bug #388...
r14 #include <qlopdatabase.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
Fixed bug #388...
r14
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)));
Fixed bug #388...
r14 connect(m_dataFile,SIGNAL(fileWritten()),this,SLOT(fileWritten()));
Added Python Console and some Wrappers....
r5 m_serviceName="CassiniTools";
m_noGui=noGUI;
added missing GPL headers...
r11 fftw_init_threads();
Added Python Console and some Wrappers....
r5 }
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)));
Spec file ready for rpm packaging....
r13 QString fileName = QString(plot->title()).replace(".TAB","");
fileName = generateFileName(fileName,".TAB");
ExportAction=new SocExplorerPlotActions("export view to "+fileName,plot->PID(),_self);
added quick fileName generation for data export, and fixed wrong date reading...
r10 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);
Spec file ready for rpm packaging....
r13 QString fileName = QString(File).replace(".TAB","-part");
fileName = generateFileName(fileName,".TAB");
ExportAction->setText("export view to "+fileName);
added quick fileName generation for data export, and fixed wrong date reading...
r10 }
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++)
{
Spec file ready for rpm packaging....
r13 QLopQCPDataVector* vect = new QLopQCPDataVector();
added quick fileName generation for data export, and fixed wrong date reading...
r10 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;
{
Spec file ready for rpm packaging....
r13 QString fileName = QString(plot->title()).replace(".TAB","-part");
fileName = generateFileName(fileName,".TAB");
plot view export works on cassini fgm data.
r8 if(fileName!="")
{
QLopDataList vectors;
for(int i=0;i<plot->graphCount();i++)
{
Spec file ready for rpm packaging....
r13 QLopQCPDataVector* vect = new QLopQCPDataVector();
plot view export works on cassini fgm data.
r8 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)
{
added missing GPL headers...
r11
QElapsedTimer timr;
Added preliminary version of FFT and removed memory leak.
r9 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
if(plot==NULL)
return;
{
added missing GPL headers...
r11 timr.start();
Added preliminary version of FFT and removed memory leak.
r9 QLopDataList vectors;
for(int i=0;i<plot->graphCount();i++)
{
Spec file ready for rpm packaging....
r13 QLopQCPDataVector* vect = new QLopQCPDataVector();
Added preliminary version of FFT and removed memory leak.
r9 vect->data = plot->getVisibleData(i);
vectors.append(vect);
}
if(vectors.count()==3)
{
Spec file ready for rpm packaging....
r13 QLopQCPDataVector* ch1V=(QLopQCPDataVector*)vectors.at(0);
QLopQCPDataVector* ch2V=(QLopQCPDataVector*)vectors.at(1);
QLopQCPDataVector* ch3V=(QLopQCPDataVector*)vectors.at(2);
QLopQCPDataVector* FFTout=new QLopQCPDataVector();
Added preliminary version of FFT and removed memory leak.
r9 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;
}
added missing GPL headers...
r11 fftw_plan_with_nthreads(4);
Added preliminary version of FFT and removed memory leak.
r9 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++)
{
Fixed bug #388...
r14 // (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count();
Added preliminary version of FFT and removed memory leak.
r9 (*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 missing GPL headers...
r11 qDebug()<< ch1V->data->count() <<" Points loaded in "<< timr.elapsed()<<"ms";
Added preliminary version of FFT and removed memory leak.
r9 }
}
}
}
Spec file ready for rpm packaging....
r13 QString CassiniTools::generateFileName(const QString &baseName, const QString &extension)
{
QString fileName = baseName+extension;
int i=0;
while(QFile::exists(fileName))
{
fileName = baseName+QString::number(i++)+extension;
}
return fileName;
}
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)
{
Fixed bug #388...
r14 static QLopDataList prevData=QLopDataList();
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)
{
Fixed bug #388...
r14 QLopDataBase::removeData(prevData);
Added preliminary version of FFT and removed memory leak.
r9 plot->removeAllGraphs();
Fixed bug #388...
r14 // QLopDataBase::re
Added preliminary version of FFT and removed memory leak.
r9 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+")");
Spec file ready for rpm packaging....
r13 plot->setGraphData(i,((QLopQCPDataVector*)data.at(i))->data,false);
Added preliminary version of FFT and removed memory leak.
r9 }
plot->rescaleAxis();
plot->replot();
Fixed bug #388...
r14 prevData = data;
QLopDataBase::addData(data);
A lot of refactoring:...
r6 }
Added Python Console and some Wrappers....
r5 }
Fixed bug #388...
r14 void CassiniTools::fileWritten()
{
SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
if(plot==NULL)
{
makePlot();
plot = QLopPlots::getPlot(m_defaultPlot);
}
if(plot)
{
QString fileName = QString(plot->title()).replace(".TAB","-part");
fileName = generateFileName(fileName,".TAB");
ExportAction->setText("export view to "+fileName);
}
}