MemSensor::MemSensor(int msec) : Sensor(msec) { #if defined Q_OS_FREEBSD || defined(Q_OS_NETBSD) /* get the page size with "getpagesize" and calculate pageshift from it */ int pagesize = getpagesize(); pageshift = 0; while (pagesize > 1) { pageshift++; pagesize >>= 1; } /* we only need the amount of log(2)1024 for our conversion */ pageshift -= 10; # if defined(Q_OS_FREEBSD) && defined(__FreeBSD_version) && __FreeBSD_version >= 500018 kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY, "kvm_open"); # elif defined Q_OS_FREEBSD connect(&ksp, SIGNAL(receivedStdout(KProcess *, char *, int )), this,SLOT(receivedStdout(KProcess *, char *, int ))); connect(&ksp, SIGNAL(processExited(KProcess *)), this,SLOT(processExited( KProcess * ))); swapTotal = swapUsed = 0; MaxSet = false; readValues(); # endif #else readValues(); #endif }
void ResourceTranslator::loadResourceList(std::istream& p_FileData) { std::vector<char> buffer; p_FileData >> std::noskipws; std::copy(std::istream_iterator<char>(p_FileData), std::istream_iterator<char>(), std::back_inserter(buffer)); tinyxml2::XMLDocument resourceList; tinyxml2::XMLError error = resourceList.Parse(buffer.data(), buffer.size()); if(error != tinyxml2::XML_NO_ERROR) { throw ResourceManagerException("Error parsing resource data. Error code: " + std::to_string(error), __LINE__, __FILE__); } tinyxml2::XMLElement* resourceFile = resourceList.FirstChildElement("Resources"); if(!resourceFile) { throw ResourceManagerException("File was not of Resource .xml type.", __LINE__, __FILE__); } for(const tinyxml2::XMLElement* resourceType = resourceFile->FirstChildElement("ResourceType"); resourceType; resourceType = resourceType->NextSiblingElement("ResourceType")) { const char* type = resourceType->Attribute("Type"); if(!type) continue; m_MappedResources.push_back(std::make_pair(type, std::vector<const std::pair<std::string, std::string>>())); auto& map = m_MappedResources.back().second; for(const tinyxml2::XMLElement* resource = resourceType->FirstChildElement("Resource"); resource; resource = resource->NextSiblingElement("Resource")) { map.push_back(readValues(resource)); } } }
void Options::setValue(OptionId id, Value value) { auto values = readValues(); values[id] = value; if (triggers.count(id)) triggers.at(id)(boost::get<int>(value)); writeValues(values); }
bool Ini::read() { char line[MAXLINE]; uint16_t lc = 1; while(fgets(line, MAXLINE, file)){ char* p = line; strip(p); p = trim(p); if(strlen(p)){ if(*p == '['){ if(allocData()) return true; lsc = lc; if(readSection(p)) return true; } else{ if(readValues(p)) return true; } } lc++; }; if(dc) allocData(); return false; }
void gotoCoords(float newX, float newZ, float newO) { /* This is a work-in-progress!!!! This will go to the specified coordinates and rotate to the specified angle, assuming the PID is working correctly. This is a very systematic function, only use when absolutely necessary! */ while (readValues('o') != 90) { // very low tolerance rotateWithOrientation(1, 25); // very slow, and low rotation to insure accuracy } if (newX < x) { while (readValues('x') > newX) moveWithDirection(1, -25); // Low and slow is the way to go! } else if (newX > x) { while (readValues('x') < newX) moveWithDirection(1, -25); } while (readValues('o') != 0) { rotateWithOrientation(1, 25); } if (newZ < z) { while (readValues('z') > newZ) moveWithDirection(1, -25); // Low and slow is the way to go! } else if (newZ > z) { while (readValues('z') < newZ) moveWithDirection(1, -25); } while (readValues('o') != newO) rotateWithOrientation(1, 25); setCoords(newX, newZ, newO); }
QStringList FileManager::loadValues() { loadFile = QFileDialog::getOpenFileName(this, QObject::tr("LOAD"), "list", QObject::tr("PersonalManager Files (*.pmf)")); readValues(); return loadedList; }
bool MainWindow::doStep() { if ( readValues() ) { ui->label_2->setText(""); multiplyStep(); updateQTableWidgetFromMatrix(*(ui->tableWidget_3), *_matrixC); return true; } else return false; }
void NSDecoder::initDecoder() { readValues(); numValues=0; if (maxValsInBuffer!=0) { startInt=values[0]; //Log::writeToLog("NSDecoder", 1, "initDecoder(): called, startInt=", startInt); } //else //Log::writeToLog("NSDecoder", 1, "initDecoder(): called however src is dry"); while (maxValsInBuffer!=0) { endInt=values[maxValsInBuffer-1]; numValues+=maxValsInBuffer; readValues(); } //Log::writeToLog("NSDecoder", 1, "initDecoder(): called, endInt=", endInt); //Log::writeToLog("NSDecoder", 1, "initDecoder(): called, numValues=", numValues); // done reader->resetPos(); currLoc=0; }
bool NSDecoder::getNextValue(int* value) { if (!valsInBuffer) { readValues(); if (maxValsInBuffer==0) return false; valsInBuffer=true; } *value=values[valuesCurrIndex]; currLoc++; valuesCurrIndex++; if (maxValsInBuffer==valuesCurrIndex) { valsInBuffer=false; valuesCurrIndex=0; } //Log::writeToLog("NSDecoder", 0, "getNext returning pair value", value); return true; }
void main(void) { int * intArrays[COPIES], i, arraySize, value; clrscr(); printf("This program sorts and searches integer values!\n"); printf("please give me number of values you wish to deal with: "); scanf("%d", &arraySize); for(i = 0;i < COPIES; i++) intArrays[i] = (int *) malloc(sizeof(int) * arraySize); readValues(intArrays, arraySize); printf("Enter number to search for? (linear search): "); scanf("%d", &value); if (linearSearch(intArrays[0], arraySize, value) != -1) printf("Found !\n"); else printf("Not Found!\n"); getch(); printValues(intArrays, arraySize); printf("\nSorting Array 1 using bubble....\n"); bubble(intArrays[0], arraySize); printValues(intArrays, arraySize); printf("\nSorting Array 2 using selection....\n"); selection(intArrays[1], arraySize); printValues(intArrays, arraySize); printf("\nSorting Array 3 using insertion....\n"); insertion(intArrays[2], arraySize); printValues(intArrays, arraySize); printf("Enter number to search for? (binary search): "); scanf("%d", &value); if (linearSearch(intArrays[0], arraySize, value) != -1) printf("Found !\n"); else printf("Not Found!\n"); getch(); }
Block* NSDecoder::getNextBlockSingle() { if (!hasNextBlock()) return NULL; if (!valsInBuffer) { readValues(); if (maxValsInBuffer==0) return NULL; valsInBuffer=true; } int value=values[valuesCurrIndex]; outBlock->setBuffer(*startPosPtr+currLoc, 1, (byte*)&value); currLoc++; valuesCurrIndex++; if (maxValsInBuffer==valuesCurrIndex) { valsInBuffer=false; valuesCurrIndex=0; } //Log::writeToLog("NSDecoder", 0, "getNext returning pair value", value); return outBlock; }
SentencesFile::SentencesFile() : PropertiesFile() { int const varCount = 9; char const * keys[varCount] = { "UNKNOWN_MSG", "OPENING_MSG", "OPENING_TIMEOUT_MSG", "OPENED_MSG", "CLOSING_MSG", "CLOSING_TIMEOUT_MSG", "CLOSED_MSG", "FORGOTTEN_OPENED_DOOR_TIMEOUT_MSG" }; char const * const * const values = readValues("sentence.txt", keys, varCount); int i = 0; m_unknownMsg = values[i++]; m_openingMsg = values[i++]; m_openingTimeOutMsg = values[i++]; m_openedMsg = values[i++]; m_closingMsg = values[i++]; m_closingTimeOutMsg = values[i++]; m_closedMsg = values[i++]; m_forgottenOpenedDoorTimeOutMsg = values[i++]; }
void AudioFilter::trigger() { readValues(); }
Options::Value Options::getValue(OptionId id) { if (overrides[id]) return *overrides[id]; return readValues()[id]; }
float readCoordValue(char value) { return readValues(value); }
PropertiesPtr JsonSchema::readProp(cJSON *childProperties, const std::string &attName ) { PropertiesPtr property = std::make_shared<Properties>(attName); cJSON *propertyDescription = cJSON_GetObjectItem(childProperties, "description"); if (propertyDescription) { property->setDescription(propertyDescription->valuestring); } cJSON *propertyType = cJSON_GetObjectItem(childProperties, "type"); if (propertyType) { std::string attType; if (propertyType->type == 4) { attType = propertyType->valuestring; property->setType(attType); } else if (propertyType->type == 5) { attType = cJSON_GetArrayItem(propertyType, 0)->valuestring; property->setType(attType); } readValues(childProperties, property, attType); } cJSON *defaultValue = cJSON_GetObjectItem(childProperties, "default"); if (defaultValue) { if (defaultValue->type == 4) { property->setValue((std::string)defaultValue->valuestring); } else if (defaultValue->type == 3) { if (property->getType() == "number") property->setValue((double)defaultValue->valuedouble); else property->setValue((int)defaultValue->valueint ); } else if (defaultValue->type == 1) { property->setValue((bool)true); } else if (defaultValue->type == 0) { property->setValue((bool)false); } } cJSON *allowedvalues = cJSON_GetObjectItem(childProperties, "enum"); if (allowedvalues) { if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 4) { int size = cJSON_GetArraySize(allowedvalues); int idx = 0; std::vector<std::string> allwdValues; do { allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuestring); } while ( ++idx < size); property->setAllowedValues(allwdValues); } else if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 3) { int size = cJSON_GetArraySize(allowedvalues); int idx = 0; if (property->getType() == "number") { std::vector<double> allwdValues; do { allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuedouble); } while ( ++idx < size); property->setAllowedValues(allwdValues); } else { std::vector<int> allwdValues; do { allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valueint); } while ( ++idx < size); property->setAllowedValues(allwdValues); } } else if (((cJSON_GetArrayItem(allowedvalues, 0)->type) == 1) || ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 0)) { int size = cJSON_GetArraySize(allowedvalues); int idx = 0; std::vector<bool> allwdValues; do { if (cJSON_GetArrayItem(allowedvalues, idx)->type) allwdValues.push_back(true); else allwdValues.push_back(false); } while ( ++idx < size); property->setAllowedValues(allwdValues); } } return property; }
void readInput(char *inputFileName) { int Nkeyword; FILE *inputFile; const char routineName[] = "readInput"; struct Keyword theKeywords[] = { {"ATMOS_FILE", "", FALSE, KEYWORD_REQUIRED, input.atmos_input, setcharValue}, {"ABUND_FILE", "", FALSE, KEYWORD_REQUIRED, input.abund_input, setcharValue}, {"ATOM_FILE", "", FALSE, KEYWORD_REQUIRED, input.atom_input, setcharValue}, {"STARTING_SOLUTION", "", FALSE, KEYWORD_REQUIRED, &input.start, setstartValue}, {"N_EDDINGTON", "0", FALSE, KEYWORD_OPTIONAL, &input.N_Eddington, setintValue}, {"N_MAX_SCATTER", "5", FALSE, KEYWORD_OPTIONAL, &input.NmaxScatter, setintValue}, {"I_SUM", "0", FALSE, KEYWORD_REQUIRED, &input.iSum, setintValue}, {"N_MAX_ITER", "", FALSE, KEYWORD_REQUIRED, &input.NmaxIter, setintValue}, {"ITER_LIMIT", "", FALSE, KEYWORD_REQUIRED, &input.iterLimit, setfloatValue}, {"NG_DELAY", "0", FALSE, KEYWORD_OPTIONAL, &input.Ngdelay, setintValue}, {"NG_ORDER", "0", FALSE, KEYWORD_OPTIONAL, &input.Ngorder, setintValue}, {"NG_PERIOD", "1", FALSE, KEYWORD_OPTIONAL, &input.Ngperiod, setintValue}, {"PRD_TRESHOLD", "0.1", FALSE, KEYWORD_REQUIRED, &input.PRD_treshold, setfloatValue}, {"PRD_N_MAX_ITER", "8", FALSE, KEYWORD_OPTIONAL, &input.PRD_NmaxIter, setintValue}, {"PRD_NG_DELAY", "0", FALSE, KEYWORD_DEFAULT, &input.PRD_Ngdelay, setintValue}, {"PRD_NG_ORDER", "0", FALSE, KEYWORD_DEFAULT, &input.PRD_Ngorder, setintValue}, {"PRD_NG_PERIOD", "0", FALSE, KEYWORD_DEFAULT, &input.PRD_Ngperiod, setintValue}, {"J_FILE", "", FALSE, KEYWORD_REQUIRED, input.JFile, setcharValue}, {"BACKGROUND_FILE", "", FALSE, KEYWORD_REQUIRED, input.backgroundFile, setcharValue}, {"HYDROGEN_ATOM", "", FALSE, KEYWORD_REQUIRED, input.H_atom, setcharValue}, {"HYDROGEN_LTE", "0", FALSE, KEYWORD_DEFAULT, &atmos.H_LTE, setboolValue}, {"H2_FILE", "", FALSE, KEYWORD_REQUIRED, input.H2_molecule, setcharValue}, {"KURUCZ_DATA", "none", FALSE, KEYWORD_OPTIONAL, &input.KuruczData, setcharValue}, {"KURUCZ_PF_DATA", "none", FALSE, KEYWORD_OPTIONAL, &input.pfData, setcharValue}, {"OPACITY_FUDGE", "none", FALSE, KEYWORD_OPTIONAL, &input.fudgeData, setcharValue}, {"METALLICITY", "0.0", FALSE, KEYWORD_DEFAULT, &input.metallicity, setfloatValue}, {"ATOM_OUTPUT", "atom.out", FALSE, KEYWORD_DEFAULT, input.atom_output, setcharValue}, {"ATMOS_OUTPUT", "atmos.out", FALSE, KEYWORD_DEFAULT, input.atmos_output, setcharValue}, {"GEOMETRY_OUTPUT", "geometry.out", FALSE, KEYWORD_OPTIONAL, input.geometry_output, setcharValue}, {"SPECTRUM_OUTPUT", "spectrum.out", FALSE, KEYWORD_DEFAULT, input.spectrum_output, setcharValue}, {"OPACITY_OUTPUT", "none", FALSE, KEYWORD_OPTIONAL, input.opac_output, setcharValue}, {"RADRATE_OUTPUT", "none", FALSE, KEYWORD_OPTIONAL, input.radrateFile, setcharValue}, {"VMICRO_CHAR", "", FALSE, KEYWORD_REQUIRED, &atmos.vmicro_char, setfloatValue}, {"VMACRO_TRESH", "0.1", FALSE, KEYWORD_OPTIONAL, &atmos.vmacro_tresh, setfloatValue}, {"LAMBDA_REF", "500.0", FALSE, KEYWORD_DEFAULT, &atmos.lambda_ref, setfloatValue}, {"VACUUM_TO_AIR", "0", FALSE, KEYWORD_OPTIONAL, &spectrum.vacuum_to_air, setboolValue}, {"PRINT_CPU", "0", FALSE, KEYWORD_OPTIONAL, &stats.printCPU, setboolValue} }; Nkeyword = sizeof(theKeywords) / sizeof(struct Keyword); /* --- Open the input data file -- ------------- */ if ((inputFile = fopen(inputFileName, "r")) == NULL) { Error(UNABLE_TO_OPEN_INPUTFILE, routineName, inputFileName); } readValues(inputFile, Nkeyword, theKeywords); fclose(inputFile); /* --- Lambda_ref should be positive since it is used for the conversion of depthscales in routine convertScales -- ------------- */ if (atmos.lambda_ref <= 0.0) { sprintf(messageStr, "Value of LAMBDA_REF should be larger than 0.0\n"); Error(ERROR_READING_INPUTFILE, routineName, messageStr); } /* --- Convert to MKSA units where necessary -- ------------- */ atmos.vmicro_char *= KM_TO_M; atmos.vmacro_tresh *= KM_TO_M; }
bool LocalErrorHistogramManager::buildFromBstChild(unsigned int bstOffset, unsigned int octreeOffset) { // Add errors to bst parent histogram int numOtNodes = _tsp->numOTNodes(); unsigned int childIndex = bstOffset * numOtNodes + octreeOffset; bool isBstLeaf = _tsp->isBstLeaf(childIndex); if (bstOffset > 0) { // Not BST root std::vector<float> childValues; std::vector<float> parentValues; int bstParent = parentOffset(bstOffset, 2); unsigned int parentIndex = bstParent * numOtNodes + octreeOffset; unsigned int parentInnerNodeIndex = brickToInnerNodeIndex(parentIndex); if (isBstLeaf) { childValues = readValues(childIndex); } else { unsigned int childInnerNodeIndex = brickToInnerNodeIndex(childIndex); auto it = _voxelCache.find(childInnerNodeIndex); if (it != _voxelCache.end()) { childValues = it->second; } else { LERROR("Child " << childIndex << " visited without cache"); return false; } } int bstChildIndex = bstOffset % 2; if (bstChildIndex == 1) { parentValues = readValues(parentIndex); _voxelCache[parentInnerNodeIndex] = parentValues; } else { auto it = _voxelCache.find(parentInnerNodeIndex); if (it != _voxelCache.end()) { parentValues = it->second; } else { LERROR("Parent " << parentIndex << " visited without cache"); return false; } } // Compare values and add errors to parent histogram unsigned int paddedBrickDim = _tsp->paddedBrickDim(); unsigned int brickDim = _tsp->brickDim(); unsigned int padding = (paddedBrickDim - brickDim) / 2; for (int z = 0; z < brickDim; z++) { for (int y = 0; y < brickDim; y++) { for (int x = 0; x < brickDim; x++) { glm::vec3 samplePoint = glm::vec3(x, y, z) + glm::vec3(padding); unsigned int linearSamplePoint = linearCoords(samplePoint); float childValue = childValues[linearSamplePoint]; float parentValue = parentValues[linearSamplePoint]; // Divide by number of child voxels that will be taken into account float rectangleHeight = std::abs(childValue - parentValue) / 2.0; _temporalHistograms[parentInnerNodeIndex].addRectangle(childValue, parentValue, rectangleHeight); } } } bool isLastBstChild = bstOffset > 0 && bstChildIndex == 0; if (isLastBstChild) { buildFromBstChild(bstParent, octreeOffset); } } if (!isBstLeaf) { unsigned int childInnerNodeIndex = brickToInnerNodeIndex(childIndex); _voxelCache.erase(childInnerNodeIndex); } int octreeChildIndex = (octreeOffset - 1) % 8; bool isLastOctreeChild = octreeOffset > 0 && octreeChildIndex == 7; if (isBstLeaf && isLastOctreeChild) { int octreeParent = parentOffset(octreeOffset, 8); buildFromBstChild(bstOffset, octreeParent); } return true; }
Generator::Generator() { read("C:/Users/iman/Documents/Visual Studio 2013/Projects/App/App/Resources/Styles.css"); readValues(); }
Options::Options(const string& path, const string& _overrides) : filename(path), overrides(parseOverrides(_overrides)) { readValues(); }
// the main of readcsv.cpp int main(int argc, char** argv) { if (argc < 2) { std::cerr << *argv << " must be followed by the name of the " "CSV file\n" << "An optional second argument can specify the " "destination of output files.\n" << std::endl; return -3; } // open the input file FILE *fptr = fopen(argv[1], "r"); if (fptr == 0) { std::cerr << *argv << " failed to open file " << argv[1] << " for reading\n" << std::endl; return -4; } // read the first line of the CSV file to extract column names unsigned lbuf = 10240; char *buf = new char[lbuf]; readColumnNames(fptr, buf, lbuf); if (columns.empty()) { std::cerr << *argv << ": the first line of file " << argv[1] << " does not contain any strings\n" << std::endl; fclose(fptr); return -5; } std::cout << "File " << argv[1] << " contains " << columns.size() << " columns." << std::endl; // generate output file pointers int ierr = 0; const char *dest = (argc>2 ? argv[2] : "tmp"); #if defined(__CYGWIN__) || defined(__linux__) || defined(__unix__) || defined(__HOS_AIX__) || defined(__APPLE__) || defined(__FreeBSD__) mkdir(dest, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP); ierr = chdir(dest); #elif defined(_WIN32) _mkdir(dest); ierr = _chdir(dest); #else mkdir(dest); ierr = chdir(dest); #endif if (ierr != 0) { std::cerr << *argv << ": failed to change to directory " << dest << std::endl; return -6; } for (unsigned i = 0; i < columns.size(); ++ i) { columns[i].file = fopen(columns[i].name.c_str(), "wb"); if (columns[i].file == 0) { std::cerr << *argv << " unable to open output file " << columns[i].name << " in directory " << dest << std::endl; ++ ierr; } } if (ierr != 0) { std::cerr << *argv << ": failed to open some output files. " << "Make sure directory " << dest << " is accessible\n" << std::endl; fclose(fptr); for (unsigned i = 0; i < columns.size(); ++ i) if (columns[i].file != 0) fclose(columns[i].file); return -7; } // reading the bulk of the data unsigned long cnt = 0; // number of rows read const long endline1 = ftell(fptr); // end of the first line do { ierr = readValues(fptr, buf, lbuf); if (ierr > 0) { if (cnt > 0) { // need to rewind cnt = 0; fseek(fptr, endline1, SEEK_SET); for (cList::iterator it = columns.begin(); it != columns.end(); ++ it) rewind((*it).file); } else { cnt = 1; } ierr = 0; } else if (ierr == 0) { ++ cnt; if ((cnt % 10000) == 0) std::cout << "... " << cnt << "\n"; } } while (ierr == 0); if (ierr < -1) std::cerr << *argv << " encountered an error (" << ierr << ") after reading " << cnt << " rows from file " << argv[1] << std::endl; else std::cout << *argv << " successfully read " << cnt << " rows from file " << argv[1] << std::endl; fclose(fptr); for (cList::iterator it = columns.begin(); it != columns.end(); ++ it) fclose((*it).file); if (cnt > 0) { // write out the -part.txt file fptr = fopen("-part.txt", "w"); if (fptr == 0) { std::cerr << *argv << " unable to open file -part.txt in " << dest << "\n" << std::endl; return -8; } std::string dname = argv[1]; // data set name unsigned len = dname.rfind('/'); if (len < dname.size()) dname.erase(0, len+1); len = dname.find('.'); if (len < dname.size()) dname.erase(len); fprintf(fptr, "BEGIN HEADER\nDataSet.Name = \"%s\"\n" "DataSet.Description = \"%s %s\"\n" "Number_of_columns = %lu\n" "Number_of_rows = %lu\n" "Timestamp = %lu\nEND HEADER\n", dname.c_str(), argv[0], argv[1], columns.size(), cnt, static_cast<long unsigned int>(time(0))); for (cList::iterator it = columns.begin(); it != columns.end(); ++ it) { switch ((*it).type) { default: case STRING: // ibis::CATEGORY fprintf(fptr, "\nBegin Column\nname = \"%s\"\n" "data_type = \"category\"\nEnd Column\n", (*it).name.c_str()); break; case DOUBLE: // ibis::DOUBLE if ((*it).lo <= (*it).hi) fprintf(fptr, "\nBegin Column\nname = \"%s\"\n" "data_type = \"double\"\nminimum = %.15g\n" "maximum = %.15g\nEnd Column\n", (*it).name.c_str(), (*it).lo, (*it).hi); else fprintf(fptr, "\nBegin Column\nname = \"%s\"\n" "data_type = \"double\"\nEnd Column\n", (*it).name.c_str()); break; case INT: // ibis::INT if ((*it).lo <= (*it).hi) fprintf(fptr, "\nBegin Column\nname = \"%s\"\n" "data_type = \"int\"\nminimum = %ld\n" "maximum = %ld\nEnd Column\n", (*it).name.c_str(), static_cast<long>((*it).lo), static_cast<long>((*it).hi)); else fprintf(fptr, "\nBegin Column\nname = \"%s\"\n" "data_type = \"int\"\nEnd Column\n", (*it).name.c_str()); break; } } fclose(fptr); std::cout << *argv << " outputed " << cnt << " rows to directory " << dest << std::endl; } return 0; } // main