mergedata.cpp

Go to the documentation of this file.
00001 
00002 #include "PreCompiled.h"
00003 #include "mergedata.h"
00004 #include <QFileDialog>
00005 
00006 #include <QTextStream>
00007 #include <QMessageBox>
00008 
00009 
00010 
00011 MergeData::MergeData():
00012 m_howmanypoints(0)
00013 {
00014 
00015 }
00016 
00017 MergeData::~MergeData()
00018 {
00019 
00020 }
00021 
00022 
00023 
00024 
00025 
00026 bool MergeData::Einlesen (const QStringList &dateinamen)
00027 {
00028         for (int i=0;i<dateinamen.size();i++)
00029         {
00030                 QFileInfo aFileInfo(dateinamen.at(i));
00031                 QString path = aFileInfo.absolutePath();
00032                 QDir::setCurrent(path);
00033                 QFile input(dateinamen.at(i));
00034 
00035                 if ( input.open ( QFile::ReadOnly ) )
00036                 {
00037                         QTextStream in ( &input );
00038                         //Check the first line for a string-flag
00039                         QString firstline = in.readLine();
00040                         if(m_howmanypoints==0)
00041                         {
00042                                 m_howmanypoints = firstline.toLong();
00043                         }
00044                         else
00045                         {
00046                                 if(!(m_howmanypoints == firstline.toLong()))
00047                                 {
00048                                         return true;
00049                                 
00050                                 }
00051                         }
00052 
00053                         if(i==0)
00054                         {
00055                                 m_mergedvalues.resize(m_howmanypoints);
00056                                 for(int j=0; j<m_howmanypoints; j++)
00057                                         m_mergedvalues[j].resize(6);
00058                         }
00059                         int zeile = 0;
00060                         while ( !in.atEnd() )
00061                         {
00062                                 QString line = in.readLine();
00063                                 QStringList fields = line.split ( QLatin1Char(','),QString::SkipEmptyParts );
00064                                 if(fields.size()<5)
00065                                         return true;
00066 
00067                                         m_mergedvalues[zeile][0] = fields[0].toFloat();
00068                                         m_mergedvalues[zeile][1] = fields[1].toFloat();
00069                                         m_mergedvalues[zeile][2] = fields[2].toFloat();
00070                                         m_mergedvalues[zeile][3] += fields[3].toFloat();
00071                                         m_mergedvalues[zeile][4] += fields[4].toFloat();
00072                                         m_mergedvalues[zeile][5] += fields[5].toFloat();
00073 
00074                                 zeile++;
00075                         }
00076                 }
00077                 input.close();
00078         }
00079 
00080         return true;
00081 }
00082 
00083 
00084 bool MergeData::WriteOutput(const QString &dateiname)
00085 {
00086         QFile anOutputFile(dateiname);
00087         if (!anOutputFile.open(QIODevice::WriteOnly | QIODevice::Text))
00088                 return false;
00089         QTextStream out(&anOutputFile);
00090 
00091 
00092         for(unsigned int i=0; i<m_mergedvalues.size(); i++)
00093         {
00094                 out <<  m_mergedvalues[i][0]  << " " 
00095                         <<  m_mergedvalues[i][1]  << " " 
00096                         <<  m_mergedvalues[i][2]  << " " 
00097                         <<  m_mergedvalues[i][3]  << " " 
00098                         <<  m_mergedvalues[i][4]  << " " 
00099                         <<  m_mergedvalues[i][5]  << endl;
00100         }
00101 
00102         anOutputFile.close();
00103         return true;
00104 }
00105 
00106 

Generated on Wed Nov 23 19:00:22 2011 for FreeCAD by  doxygen 1.6.1