bool FuncCallScriptAction::check(const QString &xmlFile, const TypeRule *rule, SymFactory *factory) { Q_UNUSED(rule); Q_UNUSED(factory); // Delete old program if (_program) { delete _program; _program = 0; } // Read the contents of the script file QFile scriptFile(_scriptFile); if (!scriptFile.open(QFile::ReadOnly)) ioError(QString("Error opening file \"%1\" for reading.") .arg(_scriptFile)); _program = new QScriptProgram(scriptFile.readAll(), _scriptFile); // Basic syntax check QScriptSyntaxCheckResult result = QScriptEngine::checkSyntax(_program->sourceCode()); if (result.state() != QScriptSyntaxCheckResult::Valid) { typeRuleError2(xmlFile, srcLine(), -1, QString("Syntax error in file %1 line %2 column %3: %4") .arg(ShellUtil::shortFileName(_scriptFile)) .arg(result.errorLineNumber()) .arg(result.errorColumnNumber()) .arg(result.errorMessage())); } // Check if the function exists ScriptEngine eng(0); ScriptEngine::FuncExistsResult ret = eng.functionExists(_function, *_program); if (ret == ScriptEngine::feRuntimeError) { QString err; if (eng.hasUncaughtException()) { err = QString("Uncaught exception at line %0: %1") .arg(eng.uncaughtExceptionLineNumber()) .arg(eng.lastError()); QStringList bt = eng.uncaughtExceptionBacktrace(); for (int i = 0; i < bt.size(); ++i) err += "\n " + bt[i]; } else err = eng.lastError(); typeRuleError2(xmlFile, srcLine(), -1, QString("Runtime error in file %1: %2") .arg(ShellUtil::shortFileName(_scriptFile)) .arg(err)); } else if (ret == ScriptEngine::feDoesNotExist) { typeRuleError2(xmlFile, srcLine(), -1, QString("Function \"%1\" is not defined in file \"%2\".") .arg(_function) .arg(ShellUtil::shortFileName(_scriptFile))); } return true; }
void EMSL::array(const QString &name, void *data, int size) { if (save) { currAddr.insert(name, stream->device()->pos()); if (stream->writeRawData((const char *)data, size) != size) { ioError(); return; } } else { int addr = currAddr.value(name, -1); if (addr < 0) { varNotExist(name); return; } stream->device()->seek(addr); if (stream->readRawData((char *)data, size) != size) { ioError(); return; } } }
void UdpConnection::endSendMessage() const { #ifdef _DEBUG int bytesWritten = debugInputBuffer.getCurrentPositionAsInt(); if (bytesWritten != debugInputSize) { ioError("Bytes written (" + String::createFrom(bytesWritten) + ") are not equal the count passed at beginReceiveMessage (" + String::createFrom(debugInputSize) + ")!" ERROR_AT); } #endif socket.sendAll(sendBuffer.getPointer(), sendBuffer.getCurrentPositionAsInt(), timeout); }
void PlaylistComponent::onSaveAs() { if (! ensureAskOutOfEditMode()) return; const QString file = inputController_.getFileOrDirName( tr("Save playlist as"), QFileDialog::AcceptSave, QFileDialog::AnyFile); if (! file.isEmpty()) { QtUtilities::makePathTo(file); if (! itemTree_.save(QtUtilities::qStringToString(file))) inputController_.showMessage(ioError(), savingFailed()); } }
//------------------------------------------------------------------------------ /// \brief Does file conversion //------------------------------------------------------------------------------ bool ProcessorMNW2::impl::DoConvertFile (const char * const a_inputFile, const char * const a_outputFile, const int& /*a_nRow*/, const int& /*a_nCol*/) { bool rval(1); CStr inputFile(a_inputFile), outputFile(a_outputFile); try { std::fstream is; is.open((LPCTSTR)a_inputFile, std::ios_base::in); if (is.bad()) throw ioError(); std::fstream os; os.open((LPCTSTR)a_outputFile, std::ios_base::out); if (os.bad()) throw ioError(); ReadComments(is, os); ReadLn1(is, os); ReadWells(is, os); ReadStressPeriods(is, os); } catch (std::exception&) { CStr msg("Error processing file: "); msg += inputFile; msg += "."; ErrorStack::Get().PutError(msg); rval = false; } return rval; } // ProcessorMNW2::impl::DoConvertFile
void PlaylistComponent::saveTemporaryTree(bool * const cancelled) { treeWidget_.assertValidTemporaryTree(); temporaryTree_->nodesChanged(); if (treeAutoCleanup_) temporaryTree_->cleanUp(); const bool backedUp = makeBackup(); QtUtilities::Widgets::HandleErrors handleErrors { [&] { QtUtilities::makePathTo(qItemsFilename_); if (temporaryTree_->save(itemsFilename_)) return QString(); if (backedUp) restoreBackup(); return savingFailed(); } }; if (cancelled == nullptr) handleErrors.nonBlocking(); else handleErrors.blocking(inputController_, ioError(), cancelled); }
//------------------------------------------------------------------------------ /// \brief Reads 3. Data: ITMP /// \brief Reads 4. Data: WELLID Qdes {CapMult} {Cprime} {xyz} //------------------------------------------------------------------------------ void ProcessorMNW2::impl::ReadStressPeriods (std::fstream& a_is, std::fstream& a_os) { CStr str; std::string line; EReadAsciiFile e; e.UseExceptions(); while (!a_is.bad()) { std::getline(a_is, line); if (line.empty()) { return; } int ITMP; a_os << line << "\n"; e.SetLine(line.c_str()); e.ReadData(ITMP); if (ITMP < 1) continue; std::getline(a_is, line); e.SetLine(line.c_str()); e.ReadData(str); if ("GMS_HDF5_01" == str) { CStr fname, path; int sp; e.ReadData(fname); e.ReadData(path); path += "/07. Property"; e.ReadData(sp); std::pair<int, int> myPair(0,1); VEC_INT_PAIR indices(3, myPair); indices[0].second = numMnw2Prop(); indices[1].second = m_MNWMAX; indices[2].first = sp - 1; H5DataSetReader r(fname, path, indices); CAR_DBL2D vals; vals.SetSize(MNW2::NPROP, m_MNWMAX, 0); if (!r.GetData(&vals[0][0], MNW2::NPROP*m_MNWMAX)) { ErrorStack::Get().PutError("Unable to read MNW2 hdf5 data."); throw ioError(""); } for (int i = 0; i<m_MNWMAX; i++) { if (vals.at(MNW2::ACTIVE, i) != 0) { // this well is active // 4a. Data: WELLID Qdes {CapMult} {Cprime} {xyz} CStr ln; ln.Format("'%s' %s", m_wells.at(i).m_WELLID, STR(vals.at(MNW2::QDES, i))); if (m_wells.at(i).m_PUMPCAP > 0) { ln += " "; ln += STR(vals.at(MNW2::CAPMULT, i)); } // don't write Cprime // get AUX for (int j = 0; j<m_nAUX; j++) { ln += " "; ln += STR(vals.at(MNW2::AUX_0+j, i)); } a_os << ln << "\n"; if (m_wells.at(i).m_Qlimit < 0) { double QCUT = vals.at(MNW2::QCUT, i); ln.Format("%s %s", STR(vals.at(MNW2::HLIM, i)), STR(QCUT)); if (QCUT != 0) { CStr ln2; ln2.Format(" %s %s", STR(vals.at(MNW2::QFRCMN, i)), STR(vals.at(MNW2::QFRCMX, i))); ln += ln2; } a_os << ln << "\n"; } } } } } } // ProcessorMNW2::impl::ReadStressPeriods