void MainWindow::convertFractionToBinary() { bits = ui->spinBoxBits->value(); fraction_input = ui->lineEditFraction->text().toDouble(); qDebug() << "Fraction = " << qSetRealNumberPrecision( 24 ) << fraction_input; double substraction = 0; double remain = fraction_input; QString bitVektor = ""; int registerValue = 0; double calculatedValue = 0; for (int i= 1;i <= bits;i++) { substraction = qPow(2,(-1 * i)); if (remain >= substraction) { remain = remain - substraction; bitVektor.append("1"); registerValue += qPow(2,bits- i); // fixed recalc calculatedValue += substraction; } else { bitVektor.append("0"); } } error = 100 - (calculatedValue * 100) / fraction_input; ui->lineEditBitResult->setText(bitVektor); ui->lineEditBitRegister->setText(QString::number(registerValue)); ui->labelError->setText(QString::number(calculatedValue)); ui->labelErrorPercent->setText(QString::number(error,'f',4)); }
QString format_si_value(double v, QString unit, int prefix, unsigned int precision, bool sign) { if (prefix < 0) { int exp = -FirstSIPrefixPower; prefix = 0; while ((fabs(v) * pow(10.0, exp)) > 999.0 && prefix < (int)(countof(SIPrefixes) - 1)) { prefix++; exp -= 3; } } assert(prefix >= 0); assert(prefix < (int)countof(SIPrefixes)); const double multiplier = pow(10.0, (int)- prefix * 3 - FirstSIPrefixPower); QString s; QTextStream ts(&s); if (sign) ts << forcesign; ts << fixed << qSetRealNumberPrecision(precision) << (v * multiplier) << " " << SIPrefixes[prefix] << unit; return s; }
ExcitonWriter::ExcitonWriter(World &world, const QString &name, QObject *parent) : QObject(parent), m_world(world), m_stream(name,&m_world.parameters(),this) { m_stream << qSetRealNumberPrecision(m_world.parameters().outputPrecision) //<< qSetFieldWidth(m_world.parameters().outputWidth) << right << scientific << "1_s" << ' ' << "1_x" << ' ' << "1_y" << ' ' << "1_z" << ' ' << "1_type" << ' ' << "1_address" << ' ' << "1_lifetime" << ' ' << "1_pathlength" << ' ' << "2_s" << ' ' << "2_x" << ' ' << "2_y" << ' ' << "2_z" << ' ' << "2_type" << ' ' << "2_address" << ' ' << "2_lifetime" << ' ' << "2_pathlength" << ' ' << "step" << ' ' << "recombined" << newline << flush; }
QString txEmissionsBase::saveSourceData() const { QDir reportDir; const QString fullPath = reportDir.relativeFilePath(m_fullReportsPath) + QDir::separator() + "SourceData_" + m_calculationOptions->defStandardName( m_calculationOptions->val_standard() ) + "_" + m_currTime + ".dat"; QFile srcData(fullPath); if ( !srcData.open(QFile::WriteOnly) ) { throw txError("Can not open file " + fullPath + "!"); } QTextStream fout(&srcData); fout << right << qSetFieldWidth(COLUMNWIDTH); for ( ptrdiff_t i=0; i<SRCDATACAPTIONS_EMISSIONS.size(); i++ ) { fout << SRCDATACAPTIONS_EMISSIONS[i]; } fout << qSetFieldWidth(0) << "\n" << fixed << qSetFieldWidth(COLUMNWIDTH) << qSetRealNumberPrecision(PRECISION+1); for ( ptrdiff_t i=0; i<m_numberOfPoints; i++ ) { fout << qSetFieldWidth(COLUMNWIDTH); fout << i + 1; fout << ma_n[i] << ma_Me_brutto[i] << ma_Ne_brutto[i] << ma_N_fan[i] << ma_w[i] << ma_t0[i] << ma_B0[i] << ma_Ra[i] << ma_dPn[i] << ma_Gair[i] << ma_Gfuel[i] << ma_CNOx[i] << ma_gNOx[i] << ma_CCO[i] << ma_CCH[i] << ma_CCO2in[i] << ma_CCO2out[i] << ma_CO2[i] << ma_Ka1m[i] << ma_KaPerc[i] << ma_FSN[i] << ma_Pr[i] << ma_ts[i] << ma_tauf[i] << ma_qmdw[i] << ma_qmdew[i] << ma_rd[i]; fout << qSetFieldWidth(0) << "\n"; } srcData.close(); return "libtoxic: Source data file \"" + fullPath + "\" created.\n"; }
static void writeData( const NifModel * nif, const QModelIndex & iData, QTextStream & obj, int ofs[1], Transform t ) { // copy vertices QVector<Vector3> verts = nif->getArray<Vector3>( iData, "Vertices" ); foreach ( Vector3 v, verts ) { v = t * v; obj << "v " << qSetRealNumberPrecision(17) << v[0] << " " << v[1] << " " << v[2] << "\r\n"; }
QString txPointsOfCycle::createReports() { const QString filenamePoints = m_commonParameters->val_srcFileNamePoints(); QFile dataFile(filenamePoints); if ( !dataFile.open(QFile::WriteOnly) ) { throw txError("Can not open file " + filenamePoints + "!"); } QTextStream fout(&dataFile); fout << right << qSetFieldWidth(COLUMNWIDTH); for ( ptrdiff_t i=0; i<SRCDATACAPTIONS_EMISSIONS.size(); i++ ) { fout << SRCDATACAPTIONS_EMISSIONS[i]; } fout << qSetFieldWidth(0) << "\n" << fixed; for ( ptrdiff_t i=0; i<m_numberOfPoints; i++ ) { fout << qSetFieldWidth(COLUMNWIDTH) << qSetRealNumberPrecision(0); fout << (i + 1) << ma_n[i]; fout << qSetRealNumberPrecision(PRECISION); fout << ma_Me_brutto[i] << ma_Ne_brutto[i] << ma_N_fan[i]; fout << qSetRealNumberPrecision(PRECISION+1); fout << ma_w[i]; fout << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0" << "0"; fout << qSetFieldWidth(0) << "\n"; } dataFile.close(); return "libtoxic: File \"" + filenamePoints + "\" rewrited.\n"; }
void MemoryMap::operationProgress() { MemoryMapNode* node = _shared->lastNode; const BaseType* nodeType = node ? node->type() : 0; int queueSize = _shared->queue.size(); QChar indicator = '='; if (_prevQueueSize < queueSize) indicator = '+'; else if (_prevQueueSize > queueSize) indicator = '-'; float prob = node ? node->probability() : 1.0; int depth = 0; for (MemoryMapNode* n = node; n; n = n->parent()) ++depth; Console::out() << right << qSetFieldWidth(5) << elapsedTime() << qSetFieldWidth(0) << " Proc: " << Console::color(ctBold) << qSetFieldWidth(6) << _shared->processed << qSetFieldWidth(0) << Console::color(ctReset) << ", addr: " << qSetFieldWidth(6) << _vmemAddresses.size() << qSetFieldWidth(0) << ", objs: " << qSetFieldWidth(6) << _vmemMap.size() << qSetFieldWidth(0) << ", vmem: " << qSetFieldWidth(6) << _vmemMap.nodeCount() << qSetFieldWidth(0) << ", pmem: " << qSetFieldWidth(6) << _pmemMap.nodeCount() << qSetFieldWidth(0) << ", q: " << qSetFieldWidth(5) << queueSize << qSetFieldWidth(0) << " " << indicator << ", d: " << qSetFieldWidth(2) << depth << qSetFieldWidth(0) << ", p: " << qSetRealNumberPrecision(5) << fixed; if (prob < 0.4) Console::out() << Console::color(ctMissed); else if (prob < 0.7) Console::out() << Console::color(ctDeferred); else Console::out() << Console::color(ctMatched); Console::out() << prob << Console::color(ctReset); // << ", min_prob: " << (queueSize ? _shared->queue.smallest()->probability() : 0); if (nodeType) { Console::out() << ", " << Console::prettyNameInColor(nodeType) << " "; if (node->parent()) Console::out() << Console::color(ctMember); else Console::out() << Console::color(ctVariable); Console::out() << node->name() << Console::color(ctReset); } Console::out() << left << endl; _prevQueueSize = queueSize; }
QString MOPACInputDialog::generateInputDeck() { // Generate an input deck based on the settings of the dialog QString buffer; QTextStream mol(&buffer); mol << " AUX LARGE "; mol << "CHARGE=" << m_charge << ' '; switch (m_multiplicity) { case 2: mol << "DOUBLET "; break; case 3: mol << "TRIPLET "; break; case 4: mol << "QUARTET "; break; case 5: mol << "QUINTET "; break; case 1: default: mol << "SINGLET "; } mol << getCalculationType(m_calculationType) << ' '; mol << getTheoryType(m_theoryType) << '\n'; mol << m_title << "\n\n"; // Now to output the actual molecular coordinates QString optimizationFlag; if (m_calculationType == SP) optimizationFlag = " 0 "; // we could actually obey constraints easily else optimizationFlag = " 1 "; // Cartesian coordinates if (m_molecule && m_coordType == CARTESIAN) { QList<Atom *> atoms = m_molecule->atoms(); foreach (Atom *atom, atoms) { mol << qSetFieldWidth(4) << right << QString(OpenBabel::etab.GetSymbol(atom->atomicNumber())) << qSetFieldWidth(15) << qSetRealNumberPrecision(5) << forcepoint << fixed << right << atom->pos()->x() << optimizationFlag << atom->pos()->y() << optimizationFlag << atom->pos()->z() << optimizationFlag << qSetFieldWidth(0) << '\n'; }
QString txReducedPower::saveSourceData() const { QDir reportDir; const QString fullPath = reportDir.relativeFilePath(m_fullReportsPath) + QDir::separator() + "SourceData_R85_" + m_currTime + ".dat"; QFile srcData(fullPath); if ( !srcData.open(QFile::WriteOnly) ) { throw txError("Can not open file " + fullPath + "!"); } QTextStream fout(&srcData); fout << right << qSetFieldWidth(COLUMNWIDTH); for ( ptrdiff_t i=0; i<SRCDATACAPTIONS_REDPOWER.size(); i++ ) { fout << SRCDATACAPTIONS_REDPOWER[i]; } fout << qSetFieldWidth(0) << "\n" << fixed << qSetFieldWidth(COLUMNWIDTH) << qSetRealNumberPrecision(PRECISION+1); for ( ptrdiff_t i=0; i<m_numberOfPoints; i++ ) { fout << qSetFieldWidth(COLUMNWIDTH); fout << i + 1; fout << ma_n[i] << ma_Me_brutto[i] << ma_t0[i] << ma_B0[i] << ma_Ra[i] << ma_S[i] << ma_pk[i] << ma_Gfuel[i] << ma_N_k[i] << ma_N_fan[i] << ma_t_cool[i] << ma_t_oil[i] << ma_tk[i] << ma_tks[i] << ma_t_fuel[i] << ma_pks[i] << ma_Gair[i]; fout << qSetFieldWidth(0) << "\n"; } srcData.close(); return "libtoxic: Source data file \"" + fullPath + "\" created.\n"; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); eps = 0.001; maximumNumberOfIterations = 50; stream.setString(&outputString); stream << qSetFieldWidth(5); stream << qSetRealNumberPrecision(4); QShortcut *fOpen = new QShortcut(QKeySequence("Ctrl+O"),this); QObject::connect(fOpen,SIGNAL(activated()),this,SLOT(on_action_Open_triggered())); QShortcut *Exit = new QShortcut(QKeySequence("Ctrl+E"),this); QObject::connect(Exit,SIGNAL(activated()),this,SLOT(on_action_Exit_triggered())); }
void FileOut::start() { file.open(QFile::Truncate | QFile::WriteOnly); //file.reset(); stream.reset(); stream.setDevice(&file); stream << qSetFieldWidth(9); stream << qSetRealNumberPrecision(5); stream << fixed; Logger(Debug) << this << "opening file"; stream << "time"; stream << "\t" << QString::fromStdString(Flow::getNames()[0]) << " [m^3/dt]"; for (int i = 1; i < Flow::getNames().size(); ++i) { stream << "\t" << QString::fromStdString(Flow::getNames()[i]) << " [g/m^3]"; } stream << "\n"; }
CarrierWriter::CarrierWriter(World &world, const QString &name, QObject *parent) : QObject(parent), m_world(world), m_stream(name,&m_world.parameters(),this) { m_stream << qSetRealNumberPrecision(m_world.parameters().outputPrecision) //<< qSetFieldWidth(m_world.parameters().outputWidth) << right << scientific << "s" << ' ' << "x" << ' ' << "y" << ' ' << "z" << ' ' << "type" << ' ' << "address" << ' ' << "lifetime" << ' ' << "pathlength" << ' ' << "step" << newline << flush; }
//! Processes all data in one row of input & writes appropriate data to output //! @param ts QTextStream already associated with an output file //! @param infile QFile object representing input (raw data) file //! @param colCount Interpret data in infile as having this many "columns" //! @param colSize Array of column sizes with colSize[n] = bytes in column n //! @param byteSwap Swap endianness of source data. True or false. //! @param vMin If device outputs between 1.1v and 5.5v, this is the 1.1v //! @param vMax If device outputs between 1.1v and 5.5v, this is the 5.1v //! @see dataToCsv() void inline Window::csvProcessRow(QTextStream &ts, QFile &infile, int colCount, QByteArray &colSize, bool byteSwap, double vMin, double vMax) { static raw2quint64 raw; raw.ui64 = 0; for(int col = 0; col < colCount; ++col) { // For each column in this row int readError = infile.read(raw.bytes, colSize[col]); if(readError == -1) { statusBarMessage->setText(tr("Error reading data file.")); return; // TODO: Get rid of multiple returns } if(byteSwap) raw.ui64 = qbswap(raw.ui64) >> ((8 - colSize[col]) << 3); // TODO: Get rid of this check against a GUI checkbox if(dataCheckBox.at(col)->isChecked()) ts << raw.ui64 << ','; else { double colVal = rawIntToVoltage(raw.ui64, colSize[col], vMin, vMax); ts << qSetRealNumberPrecision(15) << colVal << ','; } } ts << endl; }
void XYZWriter::write() { if (m_world.parameters().outputXyzMode == 0) { int num = 0; if (m_world.parameters().outputXyzE == true) { num += m_world.numElectronAgents(); } if (m_world.parameters().outputXyzH == true) { num += m_world.numHoleAgents(); } if (m_world.parameters().outputXyzD == true) { num += m_world.numDefects(); } if (m_world.parameters().outputXyzT == true) { num += m_world.numTraps(); } m_stream << qSetFieldWidth(0) << num << newline; m_stream << m_world.parameters().currentStep << newline; m_stream << qSetRealNumberPrecision(m_world.parameters().outputPrecision) << qSetFieldWidth(0) << right << scientific; if (m_world.parameters().outputXyzE == true) { Grid &grid = m_world.electronGrid(); QList<ChargeAgent*> &charges = m_world.electrons(); foreach( ChargeAgent* pCharge, charges) { ChargeAgent &charge = *pCharge; int site = charge.getCurrentSite(); m_stream << 'E' << ' ' << grid.getIndexX(site) << ' ' << grid.getIndexY(site) << ' ' << grid.getIndexZ(site) << ' ' << site << ' ' << &charge << ' ' << charge.lifetime() << ' ' << charge.pathlength() << '\n'; }
void PaletteEditor::saveGradientAction() { QString saveFile( QFileDialog::getSaveFileName(this, tr("Save gradient to a cpt file"), QFileInfo(m_lastBrowseDir).absoluteFilePath(), tr("CPT Gradient Files (*.cpt)")) ); if (saveFile.isEmpty()) return; QFileInfo file( saveFile ); QString openDir( file.absoluteFilePath() ); logInfo(QString("PaletteEditor::saveGradientAction : saving gradient to %1").arg(saveFile)); if (openDir != m_lastBrowseDir) m_lastBrowseDir = openDir; QFile data(file.absoluteFilePath()); if (!data.open(QFile::ReadWrite)) { QMessageBox msgBox; msgBox.setText(tr("Error: Couldn't open file %1").arg(file.filePath())); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); return; } QTextStream os(&data); os << "# COLOR_MODEL = RGB" << endl << scientific << qSetRealNumberPrecision(6) << qSetFieldWidth(4); p_stops = m_gradientStops->getStops(); qStableSort(p_stops.begin(), p_stops.end(), GradientStop::lessThanGradientStopComparison); GradientStops::const_iterator i = p_stops.constBegin(); os << left << (*i).first << right << (*i).second.red() << (*i).second.green() << (*i).second.blue() << ' '; ++i; for ( ; i != p_stops.constEnd(); ++i) { os << left << (*i).first << right << (*i).second.red() << (*i).second.green() << (*i).second.blue() << endl; if (i + 1 != p_stops.constEnd()) os << left << (*i).first << right << (*i).second.red() << (*i).second.green() << (*i).second.blue() << ' '; } os << "B 0 0 0" << endl << "F 255 255 255" << endl << "N 255 0 0" << endl; data.close(); if (data.error() != QFile::NoError) { QMessageBox msgBox; msgBox.setText(tr("Error: Couldn't write to file %1").arg(file.filePath())); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); } }
bool Test::loadFileASC(const QString &fileName) { QFile file(fileName); bool result = false; qint64 fsize = QFileInfo(fileName).size(); qDebug() << "File size: " << fsize; if (file.exists()) { if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(0, tr("Error"), tr("Cannot read file %1<br><b>Reason:</b> %2.") .arg(fileName).arg(file.errorString())); emit newInfo(tr("<b>File:</b> %1<br><b>Error:</b> %2").arg(fileName) .arg(file.errorString())); return result; } QElapsedTimer timer;/////////////////////////// timer.start(); QTextStream in(&file); result = readHeaderASC(in); if (result) { const qint64 INITIAL_LAP = 2000; //NOTE: make LAP_PERCENT a preference ??? const qint64 LAP_PERCENT = 35; //NOTE: make MIN_DURATION a preference ??? const int MIN_DURATION = 1200; m_fileName = fileName; qint64 nlines; QProgressDialog progress("", tr("Cancel"), 0, fsize, 0); progress.setWindowModality(Qt::WindowModal); progress.setMinimumDuration(MIN_DURATION); qint64 posIni = in.pos(); progress.setValue(posIni); qint64 lap = INITIAL_LAP; char sep; int channels = magnitudes.size(); double number; nlines = 0; in >> number >> sep; while (in.status() == QTextStream::Ok) { time.push_back(number); for (int cha = 0; cha < channels; ++cha) { in >> number >> sep; magnitudes[cha].data.push_back(number); } ++nlines; if (nlines % lap == 0) { if (progress.wasCanceled()) { emit newInfo(tr("<br><b>File load canceled by user!</b> ")); result = false; break; } if (posIni) { qint64 pos = in.pos(); qDebug() << "Setting lap at pos " << pos; qint64 lineSize = (pos - posIni) / nlines + 1; //+1 for better estimation qDebug() << "lineSize " << lineSize; qint64 newlap = fsize / lineSize; qDebug() << "Estimated total lines " << newlap; newlap = newlap /LAP_PERCENT; lap = newlap > 1000 ? newlap : 1000;//NOTE: this 1000 in a define/preference?????? qDebug() << "New lap " << lap; posIni = 0; } progress.setValue(in.pos()); } in >> number >> sep; } if (result) { qDebug() << "nlines = " << nlines; progress.setValue(in.pos()); qDebug().nospace() << qSetRealNumberPrecision(10) << "Time[" << nlines-1 << "]= " << time[nlines-1]; for (int i = 0; i < channels; ++i) { qDebug().nospace() << qSetRealNumberPrecision(10) << magnitudes[i].m_title <<"[" << nlines-1 << "]= " << magnitudes[i].data[nlines-1]; } showInfo(); } } else { //prueba qDebug() << "Error in header, no data procesed"; emit newInfo(tr("<b>File:</b> %1<br><b>Error in header:</b> no data procesed").arg(fileName)); } qDebug() << "TIME ELAPSED" << timer.elapsed() << " milliseconds"; file.close(); } else {
void MainWindow::on_pushButton_clicked() { ui->firstMethodOutput->setPlainText(""); ui->secondMethodOutput->setPlainText(""); errorMessageString=""; QVector<double> X1; QVector<double> nev1; double nevSumm1; double nevSumm2; QVector<double> X2; QVector<double> nev2; if(ui->firstMethod->currentText()=="Successive Approximation") { X1=successiveApproximations(matrix,rightRow); nev1=nevyazka(matrix,rightRow,X1); nevSumm1=nevyazkaSumm(matrix,rightRow,X1); } if(ui->firstMethod->currentText()=="Simple Iteration") { X1=simpleIterations(matrix,rightRow); nev1=nevyazka(matrix,rightRow,X1); nevSumm1=nevyazkaSumm(matrix,rightRow,X1); } if(ui->firstMethod->currentText()=="Zeidel's Method") { X1=zeydel(matrix,rightRow); nev1=nevyazka(matrix,rightRow,X1); nevSumm1=nevyazkaSumm(matrix,rightRow,X1); } if(ui->firstMethod->currentText()=="Nekrasov's Method") { X1=nekrasov(matrix,rightRow); nev1=nevyazka(matrix,rightRow,X1); nevSumm1=nevyazkaSumm(matrix,rightRow,X1); } if(ui->secondMethod->currentText()=="Successive Approximation") { X2=successiveApproximations(matrix,rightRow); nev2=nevyazka(matrix,rightRow,X2); nevSumm2=nevyazkaSumm(matrix,rightRow,X2); } if(ui->secondMethod->currentText()=="Simple Iteration") { X2=simpleIterations(matrix,rightRow); nev2=nevyazka(matrix,rightRow,X2); nevSumm2=nevyazkaSumm(matrix,rightRow,X2); } if(ui->secondMethod->currentText()=="Zeidel's Method") { X2=zeydel(matrix,rightRow); nev2=nevyazka(matrix,rightRow,X2); nevSumm2=nevyazkaSumm(matrix,rightRow,X2); } if(ui->secondMethod->currentText()=="Nekrasov's Method") { X2=nekrasov(matrix,rightRow); nev2=nevyazka(matrix,rightRow,X2); nevSumm2=nevyazkaSumm(matrix,rightRow,X2); } QTextStream firstStream; QTextStream secondStream; QString firstString; QString secondString; firstStream.setString(&firstString); secondStream.setString(&secondString); if(errorMessageString.isEmpty()) { firstStream << "Solution Vector:" << endl; for(int i=0;i<X1.size();i++) { firstStream << qSetRealNumberPrecision(5)<< X1[i] << " "; } firstStream << endl; firstStream << "Mistake Vector:" << endl; for(int i=0;i<nev1.size();i++) { firstStream << qSetRealNumberPrecision(5) << nev1[i] << " "; } firstStream << endl; firstStream << "Residual: "; firstStream << nevSumm1; firstStream << endl; ui->firstMethodOutput->setPlainText(firstString); } else { ui->firstMethodOutput->setPlainText(errorMessageString); } if(ui->secondMethod->currentText()!="Don't Compare" && errorMessageString.isEmpty()) { secondStream << "Solution Vector:" << endl; for(int i=0;i<X2.size();i++) { secondStream << qSetRealNumberPrecision(5)<< X2[i] << " "; } secondStream<<endl; secondStream << "Mistake Vector:" << endl; for(int i=0;i<nev2.size();i++) { secondStream << qSetRealNumberPrecision(5) << nev2[i] << " "; } secondStream << endl; secondStream << "Residual: "; secondStream << nevSumm2; secondStream << endl; ui->secondMethodOutput->setPlainText(secondString); if(nevSumm2<nevSumm1) { QMessageBox::information(this,"Accuracy","Second method is more accurate"); }else if(nevSumm2==nevSumm1) { QMessageBox::information(this,"Accuracy","Same Accuracy on both methods"); }else { QMessageBox::information(this,"Accuracy","First method is more accurate"); } }else if (ui->secondMethod->currentText()!="Don't Compare") { ui->secondMethodOutput->setPlainText(errorMessageString); } }
static void dumpHeader() { static bool fullOnce = false; QmcMetric *metric; bool instFlag = false; QString noneStr = "none"; QString srcStr = "Source"; QString metricStr = "Metric"; QString instStr = "Inst"; QString normStr = "Normal"; QString unitStr = "Units"; QString columnStr = "Column"; const char *timeStr; int m; int i; int c; int v; int p; int len = 0; if (niceFlag) { struct timeval pos = { 0, 0 }; timeStr = dumpTime(pos); len = strlen(timeStr); } if (fullFlag) { fullOnce = true; for (m = 0, v = 1; m < metrics.size(); m++) { metric = metrics[m]; for (i = 0; i < metric->numValues(); i++, v++) { cout << '[' << qSetFieldWidth(2) << v << qSetFieldWidth(0) << "] " << metric->spec(sourceFlag, true, i) << endl; } } cout << endl; } if (fullOnce) { if (timeFlag) { if (len < columnStr.length()) { columnStr.remove(len, columnStr.length() - len); } cout << qSetFieldWidth(len) << columnStr << qSetFieldWidth(0) << delimiter; } for (m = 0, v = 1; m < metrics.size(); m++) { metric = metrics[m]; for (i = 0; i < metric->numValues(); i++) { cout << qSetFieldWidth(width) << v << qSetFieldWidth(0); if (v < numValues) { cout << delimiter; v++; } } } cout << endl; } if (niceFlag && sourceFlag) { if (timeFlag) { if (len < srcStr.length()) { srcStr.remove(len, srcStr.length() - len); } cout << qSetFieldWidth(len) << srcStr << qSetFieldWidth(0) << delimiter; } for (m = 0, v = 1; m < metrics.size(); m++) { metric = metrics[m]; QString const& str = metric->context()->source().host(); strncpy(buffer, (const char *)str.toAscii(), width); buffer[width] = '\0'; for (i = 0; i < metric->numValues(); i++) { cout << qSetFieldWidth(width) << buffer << qSetFieldWidth(0); if (v < numValues) { cout << delimiter; v++; } } } cout << endl; } if (metricFlag || (sourceFlag && !niceFlag)) { if (timeFlag) { if (niceFlag) { if (len < metricStr.length()) { metricStr.remove(len, metricStr.length() - len); } cout << qSetFieldWidth(len) << metricStr << qSetFieldWidth(0); cout << delimiter; } else cout << "Time" << delimiter; } for (m = 0, v = 1; m < metrics.size(); m++) { metric = metrics[m]; if (niceFlag && !instFlag && metric->hasInstances()) instFlag = true; for (i = 0; i < metric->numValues(); i++) { if (niceFlag) { QString const &str = metric->spec(false, false, i); p = str.length() - width; if (p > 0) { for (c = (p - 1 > 0 ? p - 1 : 0); c < str.length(); c++) { if (str[c] == '.') { c++; break; } } if (c < str.length()) cout << qSetFieldWidth(width) << ((const char *)str.toAscii() + c) << qSetFieldWidth(0); else cout << qSetFieldWidth(width) << ((const char *)str.toAscii() + p) << qSetFieldWidth(0); } else { cout << qSetFieldWidth(width) << str << qSetFieldWidth(0); } } else cout << metric->spec(sourceFlag, true, i); if (v < numValues) { cout << delimiter; v++; } } } cout << endl; } if (instFlag) { if (timeFlag) { if (niceFlag) { if (len < instStr.length()) { instStr.remove(len, instStr.length() - len); } cout << qSetFieldWidth(len) << instStr << qSetFieldWidth(0) << delimiter; } else { cout << qSetFieldWidth(len) << errStr << qSetFieldWidth(0) << delimiter; } } for (m = 0, v = 1; m < metrics.size(); m++) { metric = metrics[m]; for (i = 0; i < metric->numValues(); i++) { if (metric->hasInstances()) { QString const &str = metric->instName(i); strncpy(buffer, (const char *)str.toAscii(), width); buffer[width] = '\0'; cout << qSetFieldWidth(width) << buffer << qSetFieldWidth(0); } else cout << qSetFieldWidth(width) << "n/a" << qSetFieldWidth(0); if (v < numValues) { cout << delimiter; v++; } } } cout << endl; } if (normFlag) { if (timeFlag) { if (niceFlag) { if (len < normStr.length()) { normStr.remove(len, normStr.length() - len); } cout << qSetFieldWidth(len) << normStr << qSetFieldWidth(0) << delimiter; } else cout << errStr << delimiter; } for (m = 0, v = 1; m < metrics.size(); m++) { metric = metrics[m]; for (i = 0; i < metric->numValues(); i++) { if (shortFlag) cout << qSetRealNumberPrecision(precision) << qSetFieldWidth(width) << metric->scale() << qSetFieldWidth(0); else if (descFlag) cout << qSetFieldWidth(width) << QmcMetric::formatNumber(metric->scale()) << qSetFieldWidth(0); else cout << fixed << qSetRealNumberPrecision(precision) << qSetFieldWidth(width) << metric->scale() << qSetFieldWidth(0); if (v < numValues) { cout << delimiter; v++; } } } cout << endl; } if (unitFlag) { if (timeFlag) { if (niceFlag) { if (len < unitStr.length()) { unitStr.remove(len, unitStr.length() - len); } cout << qSetFieldWidth(len) << unitStr << qSetFieldWidth(0) << delimiter; } else cout << noneStr << delimiter; } for (m = 0, v = 1; m < metrics.size(); m++) { metric = metrics[m]; QString const &str = (niceFlag ? metric->desc().shortUnits() : metric->desc().units()); for (i = 0; i < metric->numValues(); i++) { if (niceFlag) if (str.length() > width) cout << qSetFieldWidth(width) << ((const char *)str.toAscii() + str.length() - width) << qSetFieldWidth(0); else cout << qSetFieldWidth(width) << str << qSetFieldWidth(0); else cout << str; if (v < numValues) { cout << delimiter; v++; } } } cout << endl; } }
QString txReducedPower::saveCheckoutData() const { QDir reportDir; const QString fullPath = reportDir.relativeFilePath(m_fullReportsPath) + QDir::separator() + "CheckoutData_R85_" + m_currTime + ".dat"; QFile choutData(fullPath); if ( !choutData.open(QFile::WriteOnly) ) { throw txError("Can not open file " + fullPath + "!"); } QTextStream fout(&choutData); fout << right << qSetFieldWidth(COLUMNWIDTH); for ( ptrdiff_t i=0; i<SRCDATACAPTIONS_REDPOWER.size(); i++ ) { fout << SRCDATACAPTIONS_REDPOWER[i]; } fout << "Ne_b[kW]" << "ge_b[g/kWh]" << "qcs[mg/cyc.l]" << "fm[-]" << "pa[kPa]" << "ps[kPa]" << "fa[-]" << "alphad[-]" << "Ne_r[kW]" << "Ne_nr[kW]" << "Me_nr[Nm]" << "ge_nr[g/kWh]"; fout << qSetFieldWidth(0) << "\n" << fixed << qSetFieldWidth(COLUMNWIDTH) << qSetRealNumberPrecision(PRECISION+1); for ( ptrdiff_t i=0; i<m_numberOfPoints; i++ ) { fout << qSetFieldWidth(COLUMNWIDTH) << qSetRealNumberPrecision(PRECISION); fout << (i + 1) << ma_n[i] << ma_Me_brutto[i] << ma_t0[i] << ma_B0[i] << ma_Ra[i] << ma_S[i] << ma_pk[i] << ma_Gfuel[i] << ma_N_k[i] << ma_N_fan[i] << ma_t_cool[i] << ma_t_oil[i] << ma_tk[i] << ma_tks[i] << ma_t_fuel[i] << ma_pks[i] << ma_Gair[i] << ma_Ne_brutto[i] << ma_ge_brutto[i] << ma_qcs[i] << ma_fm[i] << ma_pa[i] << ma_ps[i]; fout << qSetRealNumberPrecision(PRECISION+2); fout << ma_fa[i] << ma_alphad[i]; fout << qSetRealNumberPrecision(PRECISION); fout << ma_Ne_reduced[i] << ma_Ne_netto_reduced[i] << ma_Me_netto_reduced[i] << ma_ge_netto_reduced[i]; fout << qSetFieldWidth(0) << "\n"; } choutData.close(); return "libtoxic: Checkout data file \"" + fullPath + "\" created.\n"; }
QTextStream& operator <<(QTextStream &out, const QDPoint& p) { out << qSetRealNumberPrecision(10) << p.x()<< " " << qSetRealNumberPrecision(10) << p.y()<< " " << qSetRealNumberPrecision(10) << p.z(); return out; }