示例#1
0
void Vector<scalar, CPU>::save(std::string fname)
{
    QFile file(fname.c_str());
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        qDebug() << "Vector (CPU): Problem with opening [" << fname.c_str() <<"] to save vector data";
       return;
    }

    QTextStream out (&file);
    out.setRealNumberNotation(QTextStream::ScientificNotation);
    for (int i = 0; i < size; i++)
        out << data[i] << "\n";
    file.close();
}
示例#2
0
void RadMainWindow :: stc1FFTTest (void)
{
    QString fName = QFileDialog::getOpenFileName (this, tr("Open File"), QDir::currentPath(), tr("All files (*.*)"));
    if (fName.isEmpty())
        return;

    QVector<double> v001;
    QFile f001 (fName);
    f001.open (QIODevice::ReadOnly);
    QString rfftStr;

    QTextStream fstr (&f001);
    rfftStr = fstr.readLine();// >> rfftStr;
    //qDebug () << __PRETTY_FUNCTION__ << rfftStr;
    QStringList fftStrList = rfftStr.split(QString("\t"));
    //fstr >> v001;
    int n = fftStrList.size();
    qDebug () << __PRETTY_FUNCTION__ << n;
    QFile fftc ("stc1c.dat");
    fftc.open (QIODevice::WriteOnly);
    QTextStream fftcStr (&fftc);
    for (int i=0; i<n; i++)
    {
        bool ok;
        Q_UNUSED (ok);
        //QStringList fftstr = fftStrList[i].split(QString(" "));
        QByteArray fftBuf (fftStrList[i].mid(0, fftStrList[i].count()-1).toUtf8());
        if (i<=10)
            qDebug () << __PRETTY_FUNCTION__ << fftBuf;
        QTextStream strBuf (fftBuf);
        double x, y;// = fftstr[0].toDouble (&ok);
        QString sp;
        strBuf >> x >> sp >> y ;
///        strBuf >> y;
        if (sp.contains("-"))
            y *= -1.0;
        if (i<=10)
            qDebug () << __PRETTY_FUNCTION__ << x << sp << y;
        fftcStr << x << " " << y << endl;
        v001.append (x);
        v001.append (y);
    }

//    for (int i=0; i<v001.size(); i++)
//        qDebug () << __PRETTY_FUNCTION__ << v001[i];

    int n2 = FFT_Transform::pow2roundup(v001.size()/2);//1024;
    complex<double> * x = new complex<double>[n2];
    //double * x = new double [n2];
    for (int i=0; i<n2; i++)
        x[i] = complex<double>(0.0, 0.0);

    for (int i=0; i<n; i++)
    {
        x[i] = complex<double>(v001[2*i], v001[2*i+1]);
        fftcStr << real (x[i]) << " " << imag (x[i]) << endl;
    }
    FFT_Transform fft;// = new FFT_Transform;
    complex<double> * xfft = new complex<double> [n2];
    xfft = fft (x, n2, n2, FFTW_BACKWARD, FFTW_ESTIMATE );//| FFTW_MEASURE);
    QString fSaveName = QFileDialog::getSaveFileName (this, tr("Save File"), QDir::currentPath(), tr("All files (*.*)"));
    if (fSaveName.isEmpty())
    {
        delete [] xfft;
        delete [] x;
        return;
    }
    QFile fSave(fSaveName);
    fSave.open (QIODevice::WriteOnly);
    QTextStream fftRes (&fSave);
    complex<double> * xfftrev = new complex<double> [n2];
    xfftrev = fft (xfft, n2, n2, FFTW_FORWARD, FFTW_ESTIMATE );//| FFTW_MEASURE);
    fftRes.setRealNumberNotation (QTextStream::FixedNotation);

    for (int i=0; i<n2; i++)
    {
        double r = real (xfft[i])/n2;
        double im = imag (xfft[i])/n2;
        fftRes << qSetFieldWidth(10) << qSetRealNumberPrecision(16) << real (x[i]) << " "
               << qSetFieldWidth(10) << qSetRealNumberPrecision(16) << imag (x[i]) << "i ";
        scientific (fftRes);
        fftRes
               << qSetFieldWidth(10) << qSetRealNumberPrecision(16) << r << " "
               << qSetFieldWidth(10) << qSetRealNumberPrecision(16) << im << "i ";
        fixed (fftRes);
        fftRes
               << qSetFieldWidth(10) << qSetRealNumberPrecision(16) << real (xfftrev[i]) << " "
               << qSetFieldWidth(10) << qSetRealNumberPrecision(16) << imag (xfftrev[i]) << "i"
               << endl;
    }
    delete [] xfft;
    delete [] x;
}