# HG changeset patch # User Alexis Jeandet # Date 2015-03-12 23:01:27 # Node ID c56bc5e5916b946bf57ff2b160f9069f48f3a09a # Parent 6e23aedd1ca889ccfd57ce07e1abe7861ce29e69 plot view export works on cassini fgm data. diff --git a/src/Cassini/cassinidatafile.cpp b/src/Cassini/cassinidatafile.cpp --- a/src/Cassini/cassinidatafile.cpp +++ b/src/Cassini/cassinidatafile.cpp @@ -42,181 +42,202 @@ CassiniDataFile::~CassiniDataFile() void CassiniDataFile::parseFile(const QString &fileName) { - this->fileName = fileName; - this->start(); + this->fileName = fileName; + m_Write = false; + this->start(); +} + +void CassiniDataFile::saveFile(const QString &fileName, QLopDataList data) +{ + this->fileName = fileName; + m_Write = true; + m_data = data; + this->start(); } inline double __decodeVal(int ofset,unsigned char* data) { - if(data[ofset]=='-') - return -0.001 * (double)( - (10000 * (int)(data[ofset+1] & 0x0F)) - + (1000 * (int)(data[ofset+2] & 0x0F)) - + (100 * (int)(data[ofset+4] & 0x0F)) - + (10 * (int)(data[ofset+5] & 0x0F)) - + ( (int)(data[ofset+6] & 0x0F)) - ); - else + if(data[ofset]=='-') + return -0.001 * (double)( + (10000 * (int)(data[ofset+1] & 0x0F)) + + (1000 * (int)(data[ofset+2] & 0x0F)) + + (100 * (int)(data[ofset+4] & 0x0F)) + + (10 * (int)(data[ofset+5] & 0x0F)) + + ( (int)(data[ofset+6] & 0x0F)) + ); + else { - if(data[ofset+1]=='-') + if(data[ofset+1]=='-') { - return -0.001 * (double)( - (1000 * (int)(data[ofset+2] & 0x0F)) - + (100 * (int)(data[ofset+4] & 0x0F)) - + (10 * (int)(data[ofset+5] & 0x0F)) - + ( (int)(data[ofset+6] & 0x0F)) - ); + return -0.001 * (double)( + (1000 * (int)(data[ofset+2] & 0x0F)) + + (100 * (int)(data[ofset+4] & 0x0F)) + + (10 * (int)(data[ofset+5] & 0x0F)) + + ( (int)(data[ofset+6] & 0x0F)) + ); } - else + else { - return 0.001 * (double)( - (10000 * (int)(data[ofset+1] & 0x0F)) - + (1000 * (int)(data[ofset+2] & 0x0F)) - + (100 * (int)(data[ofset+4] & 0x0F)) - + (10 * (int)(data[ofset+5] & 0x0F)) - + ( (int)(data[ofset+6] & 0x0F)) - ); + return 0.001 * (double)( + (10000 * (int)(data[ofset+1] & 0x0F)) + + (1000 * (int)(data[ofset+2] & 0x0F)) + + (100 * (int)(data[ofset+4] & 0x0F)) + + (10 * (int)(data[ofset+5] & 0x0F)) + + ( (int)(data[ofset+6] & 0x0F)) + ); } } } inline QDate __decodeDate(int ofset,unsigned char* data) { - int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F)); - int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F)); - int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F)); - return QDate(y,m,d); + int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F)); + int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F)); + int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F)); + return QDate(y,m,d); } inline QTime __decodeTime(int ofset,unsigned char* data) { - int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F)); - int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F)); - int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F)); - int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F)); - return QTime(h,m,s,ms); + int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F)); + int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F)); + int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F)); + int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F)); + return QTime(h,m,s,ms); } double __decodeTimeFromEpochMs(int ofset,unsigned char* data) { - struct tm t; - time_t t_of_day; - t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; - t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); - t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); - t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); - t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); - t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); - int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); - t_of_day = mktime(&t); - return (t_of_day*1000.0)+ms; + struct tm t; + time_t t_of_day; + t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; + t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); + t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); + t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); + t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); + t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); + int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); + t_of_day = mktime(&t); + return (t_of_day*1000.0)+ms; } double __decodeTimeFromEpoch(int ofset,unsigned char* data) { - struct tm t; - time_t t_of_day; - t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; - t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); - t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); - t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); - t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); - t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); - double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); - t_of_day = mktime(&t); - return (double)t_of_day+((double)ms*(double)0.001); + struct tm t; + time_t t_of_day; + t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; + t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); + t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); + t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); + t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); + t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); + double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); + t_of_day = mktime(&t); + return (double)t_of_day+((double)ms*(double)0.001); } double __decodeTimeHMSmS(int ofset,unsigned char* data) { - int h,m,s; - h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); - m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); - s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); - double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); - return (double)((h*3600)+(m*60)+s) + (ms*0.001); + int h,m,s; + h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); + m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); + s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); + double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); + return (double)((h*3600)+(m*60)+s) + (ms*0.001); } double __decodeTimeDHMSmS(int ofset,unsigned char* data) { - int d,h,m,s; - d=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); - h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); - m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); - s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); - double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); - return (double)((d*3600*24)+(h*3600)+(m*60)+s) + (ms*0.001); + int d,h,m,s; + d=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); + h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F)); + m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F)); + s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F)); + double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F)); + return (double)((d*3600*24)+(h*3600)+(m*60)+s) + (ms*0.001); } double __decodeTimeFromEpochDayOnly(int ofset,unsigned char* data) { - struct tm t; - time_t t_of_day; - t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; - t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); - t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); - t.tm_hour=0; - t.tm_min=0; - t.tm_sec=0; - t_of_day = mktime(&t); - return (double)t_of_day; + struct tm t; + time_t t_of_day; + t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900; + t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F)); + t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F)); + t.tm_hour=0; + t.tm_min=0; + t.tm_sec=0; + t_of_day = mktime(&t); + return (double)t_of_day; } void CassiniDataFile::run() { - FILE* dataFile; - dataFile = fopen(fileName.toStdString().c_str(),"r"); + if(!m_Write) + { + readFile(); + } + else + { + writeFile(); + } +} - if(dataFile != NULL) +void CassiniDataFile::readFile() +{ + FILE* dataFile; + dataFile = fopen(fileName.toStdString().c_str(),"r"); + + if(dataFile != NULL) { - fseek(dataFile, 0L, SEEK_END); - int FileSize=ftell(dataFile); - int lineCnt = FileSize/58; - int curLine=0; - int lastLineUpdate=0; - QVector *ch1=new QVector(lineCnt); - QVector *ch2=new QVector(lineCnt); - QVector *ch3=new QVector(lineCnt); - QLopDataList data; - QLopData* ch1V=new QLopData(); - QLopData* ch2V=new QLopData(); - QLopData* ch3V=new QLopData(); - ch1V->data=ch1; - ch2V->data=ch2; - ch3V->data=ch3; - ch1V->name="r"; - ch2V->name="theta"; - ch3V->name="phi"; - ch1V->unit="nT"; - ch2V->unit="nT"; - ch3V->unit="nT"; - data.append(ch1V); - data.append(ch2V); - data.append(ch3V); - QElapsedTimer timr; + fseek(dataFile, 0L, SEEK_END); + int FileSize=ftell(dataFile); + int lineCnt = FileSize/58; + int curLine=0; + int lastLineUpdate=0; + QVector *ch1=new QVector(lineCnt); + QVector *ch2=new QVector(lineCnt); + QVector *ch3=new QVector(lineCnt); + QLopDataList data; + QLopData* ch1V=new QLopData(); + QLopData* ch2V=new QLopData(); + QLopData* ch3V=new QLopData(); + ch1V->data=ch1; + ch2V->data=ch2; + ch3V->data=ch3; + ch1V->name="r"; + ch2V->name="theta"; + ch3V->name="phi"; + ch1V->unit="nT"; + ch2V->unit="nT"; + ch3V->unit="nT"; + data.append(ch1V); + data.append(ch2V); + data.append(ch3V); + QElapsedTimer timr; - double _x=0.0,day=0.0; - char* line; - QCPData data1,data2,data3; - char* fileContent=(char*)malloc(FileSize); - if(Q_UNLIKELY(fileContent==NULL))return; - int threadIndex,numThreads=omp_get_num_threads(); - int updateTriger=(lineCnt/100)/numThreads; - fseek(dataFile, 0L, SEEK_SET); - char* svglocale=NULL; - setlocale(LC_NUMERIC,svglocale); - setlocale(LC_NUMERIC, "en_US"); - if(fread(fileContent,1,FileSize,dataFile)) + double _x=0.0,day=0.0; + char* line; + QCPData data1,data2,data3; + char* fileContent=(char*)malloc(FileSize); + if(Q_UNLIKELY(fileContent==NULL))return; + int threadIndex,numThreads=omp_get_num_threads(); + int updateTriger=(lineCnt/100)/numThreads; + fseek(dataFile, 0L, SEEK_SET); + char* svglocale=NULL; + setlocale(LC_NUMERIC,svglocale); + setlocale(LC_NUMERIC, "en_US"); + if(fread(fileContent,1,FileSize,dataFile)) { - line = fileContent; - QDateTime date; - timr.start(); - day=__decodeTimeFromEpochDayOnly(0,(unsigned char*)line); -//#pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt) -// { + line = fileContent; + QDateTime date; + timr.start(); + day=__decodeTimeFromEpochDayOnly(0,(unsigned char*)line); + //#pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt) + // { #pragma omp parallel for if ((FileSize > 1024*1024*10)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate,curLine) shared(ch1,ch2,ch3,lineCnt,updateTriger) for(int i=0;iupdateTriger)) - { + { lastLineUpdate=0; int test=((curLine*numThreads *100)/ (lineCnt)); emit updateProgress(omp_get_thread_num(),test); - } - } - } -//#pragma omp barrier - free(fileContent); -// } - qDebug()<< lineCnt <<" Points loade in "<< timr.elapsed()<<"ms"; - setlocale(LC_NUMERIC,svglocale); - emit dataReady(data); + } + } + } + //#pragma omp barrier + free(fileContent); + // } + qDebug()<< lineCnt <<" Points loade in "<< timr.elapsed()<<"ms"; + setlocale(LC_NUMERIC,svglocale); + emit dataReady(data); } } +void CassiniDataFile::writeFile() +{ + QFile dataFile(fileName); + dataFile.open(QIODevice::WriteOnly); + QTextStream out(&dataFile); + if(dataFile.isOpen()) + { + if(m_data.count()==3) + { + QLopData* ch1V=m_data.at(0); + QLopData* ch2V=m_data.at(1); + QLopData* ch3V=m_data.at(2); + if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) + { + for(int i=0;idata->count();i++) + { + double key = ch1V->data->at(i).key; + QDateTime date = QDateTime::fromMSecsSinceEpoch(key*1000); + out << date.toString(Qt::ISODate)+QString(".%1").arg(date.time().msec(),3); + out << QString("%1%2%3").arg(ch1V->data->at(i).value, 11, 'f', 3).arg(ch2V->data->at(i).value, 11, 'f', 3).arg(ch3V->data->at(i).value, 11, 'f', 3); + out << "\r\n"; + } + } + dataFile.flush(); + m_data.clear(); + delete ch1V; + delete ch2V; + delete ch3V; + } + } +} + diff --git a/src/Cassini/cassinidatafile.h b/src/Cassini/cassinidatafile.h --- a/src/Cassini/cassinidatafile.h +++ b/src/Cassini/cassinidatafile.h @@ -33,12 +33,17 @@ public: explicit CassiniDataFile(QObject *parent = 0); ~CassiniDataFile(); void parseFile(const QString& fileName); + void saveFile(const QString& fileName,QLopDataList data); void run(); signals: public slots: private : + void readFile(); + void writeFile(); + bool m_Write; QString fileName; + QLopDataList m_data; }; diff --git a/src/Cassini/cassinitools.cpp b/src/Cassini/cassinitools.cpp --- a/src/Cassini/cassinitools.cpp +++ b/src/Cassini/cassinitools.cpp @@ -57,7 +57,7 @@ void CassiniTools::makePlot() plot->setContextMenuPolicy(Qt::ActionsContextMenu); SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self); plot->addAction(action); - QObject::connect(action,SIGNAL(triggered()),_self,SLOT(export_view())); + QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int))); } } @@ -111,6 +111,17 @@ void CassiniTools::export_view(int PID) return; { QString fileName = QFileDialog::getSaveFileName(); + if(fileName!="") + { + QLopDataList vectors; + for(int i=0;igraphCount();i++) + { + QLopData* vect = new QLopData(); + vect->data = plot->getVisibleData(i); + vectors.append(vect); + } + m_dataFile->saveFile(fileName,vectors); + } } } diff --git a/src/Core/Widgets/qcustomplotvect.cpp b/src/Core/Widgets/qcustomplotvect.cpp --- a/src/Core/Widgets/qcustomplotvect.cpp +++ b/src/Core/Widgets/qcustomplotvect.cpp @@ -60,6 +60,16 @@ void QCPGraphVect::setData(QVector *QCPGraphVect::getVisibleData() +{ + QVector* data = new QVector(); + bool mAdaptiveSampling_save = mAdaptiveSampling; + mAdaptiveSampling = false; + getPreparedData(data,NULL); + mAdaptiveSampling = mAdaptiveSampling_save; + return data; +} + void QCPGraphVect::draw(QCPPainter *painter) { if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } diff --git a/src/Core/Widgets/qcustomplotvect.h b/src/Core/Widgets/qcustomplotvect.h --- a/src/Core/Widgets/qcustomplotvect.h +++ b/src/Core/Widgets/qcustomplotvect.h @@ -12,6 +12,7 @@ public: ~QCPGraphVect(); QVector *data() const { return mData; } void setData(QVector *data); + QVector* getVisibleData(); protected: QVector* mData; virtual void draw(QCPPainter *painter); diff --git a/src/SocExplorerPlot.cpp b/src/SocExplorerPlot.cpp --- a/src/SocExplorerPlot.cpp +++ b/src/SocExplorerPlot.cpp @@ -93,8 +93,8 @@ void SocExplorerPlot::addAction(SocExplo QVector *SocExplorerPlot::getVisibleData(int graphIndex) { - QVector *wholeData=((QCPGraphVect*)m_plot->graph(graphIndex))->data(); -// m_plot->xAxis-> + QVector *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData(); + return visibleData; } void SocExplorerPlot::setTitle(QString title)