Keyword KeywordDialog::keyword() { Keyword result; result.name = keywordName(); result.iconResource = ui->listWidget->currentItem()->data(Qt::UserRole).toString(); result.color = ui->colorEdit->text(); return result; }
bool KeywordDialog::isKeywordNameCorrect() { // Make sure keyword is not empty and contains no spaces or colons QString name = keywordName(); if (name.isEmpty()) return false; for (int i = 0; i < name.size(); ++i) if (LineParser::isKeywordSeparator(name.at(i))) return false; return true; }
void checkEgridFile() { size_t numCells = ourFineGridManagerPtr->c_grid()->number_of_cells; // use ERT directly to inspect the EGRID file produced by EclipseWriter auto egridFile = fortio_open_reader("FOO.EGRID", /*isFormated=*/0, ECL_ENDIAN_FLIP); auto eclGrid = eclipseState->getEclipseGrid(); ecl_kw_type *eclKeyword; // yes, that's an assignment! while ((eclKeyword = ecl_kw_fread_alloc(egridFile))) { std::string keywordName(ecl_kw_get_header(eclKeyword)); if (keywordName == "COORD") { std::vector<double> sourceData, resultData; eclGrid->exportCOORD(sourceData); getErtData(eclKeyword, resultData); compareErtData(sourceData, resultData, /*percentTolerance=*/1e-6); } else if (keywordName == "ZCORN") { std::vector<double> sourceData, resultData; eclGrid->exportZCORN(sourceData); getErtData(eclKeyword, resultData); compareErtData(sourceData, resultData, /*percentTolerance=*/1e-6); } else if (keywordName == "ACTNUM") { std::vector<int> sourceData, resultData; eclGrid->exportACTNUM(sourceData); getErtData(eclKeyword, resultData); if (resultData.size() == numCells && sourceData.size() == 0) { sourceData.resize(numCells); std::fill(sourceData.begin(), sourceData.end(), 1); } compareErtData(sourceData, resultData); } ecl_kw_free(eclKeyword); } fortio_fclose(egridFile); }
void doflags(FILE *fp, struct fetchinfo *fi, struct imapscaninfo *i, unsigned long msgnum, struct rfc2045 *mimep) { struct libmail_kwMessageEntry *kme; char buf[256]; #if SMAP if (smapflag) { writes(" FLAGS="); get_message_flags(i->msgs+msgnum, buf, 0); writes(buf); } else #endif { struct libmail_kwMessage *km; writes("FLAGS "); get_message_flags(i->msgs+msgnum, buf, 0); writes("("); writes(buf); if (buf[0]) strcpy(buf, " "); if ((km=i->msgs[msgnum].keywordMsg) != NULL) for (kme=km->firstEntry; kme; kme=kme->next) { writes(buf); strcpy(buf, " "); writes(keywordName(kme->libmail_keywordEntryPtr)); } writes(")"); } i->msgs[msgnum].changedflags=0; }
void checkInitFile() { // use ERT directly to inspect the INIT file produced by EclipseWriter auto initFile = fortio_open_reader("FOO.INIT", /*isFormated=*/0, ECL_ENDIAN_FLIP); ecl_kw_type *eclKeyword; // yes, that's an assignment! while ((eclKeyword = ecl_kw_fread_alloc(initFile))) { std::string keywordName(ecl_kw_get_header(eclKeyword)); if (keywordName == "PORO") { const std::vector<double> &sourceData = deck->getKeyword("PORO")->getSIDoubleData(); std::vector<double> resultData; getErtData(eclKeyword, resultData); compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4); } if (keywordName == "PERMX") { std::vector<double> sourceData = deck->getKeyword("PERMX")->getSIDoubleData(); std::vector<double> resultData; getErtData(eclKeyword, resultData); // convert the data from ERT from Field to SI units (mD to m^2) for (size_t i = 0; i < resultData.size(); ++i) { resultData[i] *= 9.869233e-16; } compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4); } ecl_kw_free(eclKeyword); } fortio_fclose(initFile); }
void checkRestartFile(int timeStepIdx) { size_t numCells = ourFineGridManagerPtr->c_grid()->number_of_cells; Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); int numActivePhases = phaseUsage.num_phases; int waterPhaseIdx = phaseUsage.phase_pos[Opm::BlackoilPhases::Aqua]; int gasPhaseIdx = phaseUsage.phase_pos[Opm::BlackoilPhases::Vapour]; for (int i = 0; i <= timeStepIdx; ++i) { createBlackoilState(i); // use ERT directly to inspect the restart file produced by EclipseWriter auto rstFile = fortio_open_reader("FOO.UNRST", /*isFormated=*/0, ECL_ENDIAN_FLIP); int curSeqnum = -1; ecl_kw_type *eclKeyword; // yes, that's an assignment! while ((eclKeyword = ecl_kw_fread_alloc(rstFile))) { std::string keywordName(ecl_kw_get_header(eclKeyword)); if (keywordName == "SEQNUM") { curSeqnum = *static_cast<int*>(ecl_kw_iget_ptr(eclKeyword, 0)); } if (curSeqnum != i) continue; if (keywordName == "PRESSURE") { std::vector<double> sourceData = blackoilState->pressure(); std::vector<double> resultData; getErtData(eclKeyword, resultData); // convert the data from ERT from Metric to SI units (bar to Pa) for (size_t i = 0; i < resultData.size(); ++i) { resultData[i] *= 1e5; } compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4); } if (keywordName == "SWAT") { std::vector<double> sourceData; std::vector<double> resultData; getErtData(eclKeyword, resultData); // extract the water saturation from the black-oil state sourceData.resize(numCells); for (size_t i = 0; i < sourceData.size(); ++i) { // again, fun with direct index manipulation... sourceData[i] = blackoilState->saturation()[i*numActivePhases + waterPhaseIdx]; } compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4); } if (keywordName == "SGAS") { std::vector<double> sourceData; std::vector<double> resultData; getErtData(eclKeyword, resultData); // extract the water saturation from the black-oil state sourceData.resize(numCells); for (size_t i = 0; i < sourceData.size(); ++i) { // again, fun with direct index manipulation... sourceData[i] = blackoilState->saturation()[i*numActivePhases + gasPhaseIdx]; } compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4); } } fortio_fclose(rstFile); } }
std::pair<std::string, std::string> getKeywordNameAndContentFromAnnotatedData(const std::string annotatedData) { char buffer[annotatedData.size()]; strcpy(buffer, annotatedData.c_str()); char *token = NULL; //begin tokenizing token = strtok(buffer, ":"); if (token == NULL) { DeLOG("Error: Ooops. It looks like the grammar module is expecting a syntax different from the annotated output of lexer\n"); return std::make_pair("invalid", ""); } std::string content; std::string endOfContentDelimeter; if (strlen(token) == 1) { DeLOG("We shouldn't have empty string keyword names.\n"); return std::make_pair("invalid", ""); } std::string keywordName(token+1); if (keywordName.compare("data_line") == 0) { DeLOG("\tIdentified data_line\n"); endOfContentDelimeter = "}"; } else if (keywordName.compare("key_word") == 0) { DeLOG("\tIdentified keyword\n"); token = strtok(NULL, "="); if (token == NULL) { DeLOG("Error: Ooops. It looks like the grammar module is expecting a syntax different from the annotated output of lexer\n"); return std::make_pair("invalid", ""); } endOfContentDelimeter = ">"; } std::string lastToken; std::string secondLastToken; token = strtok(NULL, endOfContentDelimeter.c_str()); //check to see if there are anymore '}'s. Because we allow '{' //within the data part, this needs to be covered if (token == NULL) { DeLOG("Error: Ooops. It looks like the grammar module is expecting a syntax different from the annotated output of lexer"); return std::make_pair("invalid", ""); } if (keywordName.compare("key_word") == 0 && strlen(token) > 1) { //This takes care of leading '<' imediately after the = sign in annotated data. token = (token+1); } size_t count = 0; do { content.append(secondLastToken); if (keywordName.compare("key_word") == 0 && count > 1 && strcmp("}",token) != 0) { content.append(endOfContentDelimeter); } secondLastToken = lastToken; lastToken = std::string(token); token = strtok(NULL, endOfContentDelimeter.c_str()); count++; } while(token != NULL); if (lastToken.compare("}") == 0) { if (keywordName.compare("key_word") == 0 && count > 1) { content.append(endOfContentDelimeter); } } content.append(secondLastToken); //the last Token should be the '}' if (secondLastToken.empty()) { content.append(lastToken); } else if (lastToken.compare("}") != 0) { DeLOG("Warning: The last character in annotated data is expected to be '}'. It appears not to be (grammar module), you should deal wth this.\n"); } return std::make_pair(keywordName, content); }
bool KeywordDialog::isKeywordNameAlreadyUsed() { return m_alreadyUsedKeywordNames.contains(keywordName()); }