std::string uhd_device::str_code(uhd::rx_metadata_t metadata) { std::ostringstream ost("UHD: "); switch (metadata.error_code) { case uhd::rx_metadata_t::ERROR_CODE_NONE: ost << "No error"; break; case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT: ost << "No packet received, implementation timed-out"; break; case uhd::rx_metadata_t::ERROR_CODE_LATE_COMMAND: ost << "A stream command was issued in the past"; break; case uhd::rx_metadata_t::ERROR_CODE_BROKEN_CHAIN: ost << "Expected another stream command"; break; case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW: ost << "An internal receive buffer has filled"; break; case uhd::rx_metadata_t::ERROR_CODE_BAD_PACKET: ost << "The packet could not be parsed"; break; default: ost << "Unknown error " << metadata.error_code; } if (metadata.has_time_spec) ost << " at " << metadata.time_spec.get_real_secs() << " sec."; return ost.str(); }
void DetailList::SaveMaterials() { //---------------------------------------------------------------- // Write out the material list: // if( fnTSMats ) { TSMaterialList * ml = new TSMaterialList( fnTSMats ); if( ml ) { // install materials in list: for( int i = 0; i < fnTSMats; i++ ) (*ml)[i] = faTSMats[i]; // get filename and write material list: char outFile[256]; sprintf(outFile, "%s.%s", fBaseName, MAT_LIST_EXT); StatusPrintf( "Writing material list: %s", outFile ); remove( outFile ); FileWStream ost( outFile ); ml->writeItem( ost ); // we no longer need the material list: delete ml; } else StatusPrintf( "Not enough memory to write material list!" ); } }
void HeaderGenerator::generateHeader(const std::string fileToEdit) { // Input the contents of fileToEdit std::ifstream ist; openInputFileOrThrowException(ist, fileToEdit); std::string content = ""; std::string lineInput = ""; while (!ist.eof()) { std::getline(ist, lineInput); if (!ist.eof()) content += (lineInput + '\n'); else // Don't add a blank, new line to the end of the file content += lineInput; } assert(!ist.bad()); ist.close(); // Add the header in front of those contents content = mHeaderContent + content; // Output the contents to fileToEdit std::ofstream ost(fileToEdit, std::fstream::trunc); ost << content; assert(!ost.bad()); assert(!ost.fail()); }
std::string uhd_device::str_code(uhd::async_metadata_t metadata) { std::ostringstream ost("UHD: "); switch (metadata.event_code) { case uhd::async_metadata_t::EVENT_CODE_BURST_ACK: ost << "A packet was successfully transmitted"; break; case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW: ost << "An internal send buffer has emptied"; break; case uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR: ost << "Packet loss between host and device"; break; case uhd::async_metadata_t::EVENT_CODE_TIME_ERROR: ost << "Packet time was too late or too early"; break; case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET: ost << "Underflow occurred inside a packet"; break; case uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST: ost << "Packet loss within a burst"; break; default: ost << "Unknown error " << metadata.event_code; } if (metadata.has_time_spec) ost << " at " << metadata.time_spec.get_real_secs() << " sec."; return ost.str(); }
int main() { MyTree<int>* root = CreateEmptyTree<int>(); LoadFromFile(root, "C:\\input.txt"); Square(root); ofstream ost("C:\\out.txt"); // открытие потока для записи в файл SaveToFile(root, ost); DeleteTree(root); }
void STLTopology :: SaveBinary (const char* filename, const char* aname) const { ofstream ost(filename); PrintFnStart("Write STL binary file '",filename,"'"); if (sizeof(int) != 4 || sizeof(float) != 4) {PrintWarning("for stl-binary compatibility only use 32 bit compilation!!!");} //specific settings for stl-binary format const int namelen = 80; //length of name of header in file const int nospaces = 2; //number of spaces after a triangle //write header: aname int i, j; char buf[namelen+1]; int strend = 0; for(i = 0; i <= namelen; i++) { if (aname[i] == 0) {strend = 1;} if (!strend) {buf[i] = aname[i];} else {buf[i] = 0;} } FIOWriteString(ost,buf,namelen); PrintMessage(5,"header = ",buf); //RWrite Number of facets int nofacets = GetNT(); FIOWriteInt(ost,nofacets); PrintMessage(5,"NO facets = ", nofacets); float f; char spaces[nospaces+1]; for (i = 0; i < nospaces; i++) {spaces[i] = ' ';} spaces[nospaces] = 0; for (i = 1; i <= GetNT(); i++) { const STLTriangle & t = GetTriangle(i); const Vec<3> & n = t.Normal(); f = n(0); FIOWriteFloat(ost,f); f = n(1); FIOWriteFloat(ost,f); f = n(2); FIOWriteFloat(ost,f); for (j = 1; j <= 3; j++) { const Point3d p = GetPoint(t.PNum(j)); f = p.X(); FIOWriteFloat(ost,f); f = p.Y(); FIOWriteFloat(ost,f); f = p.Z(); FIOWriteFloat(ost,f); } FIOWriteString(ost,spaces,nospaces); } PrintMessage(5,"done"); }
Cpointls::Cpointls(Cpointls& ptls) { this->xy.resize(0); for (std::vector<std::vector<ioType> >::iterator ii=ptls.xy.begin();ii!=ptls.xy.end();ii++) this->xy.push_back((*ii)); std::stringstream ost(std::stringstream::in | std::stringstream::out); ost<<"Copy of "<<ptls.pointlsFileName; ost>>pointlsFileName; ost.clear(); }
std::string smpl_buf::str_status() const { std::ostringstream ost("Sample buffer: "); ost << "length = " << buf_len; ost << ", time_start = " << time_start; ost << ", time_end = " << time_end; ost << ", data_start = " << data_start; ost << ", data_end = " << data_end; return ost.str(); }
std::string SampleBuffer::str_status(long long ts) const { std::ostringstream ost("Sample buffer: "); ost << "ts = " << ts; ost << ", len = " << this->len; ost << ", time_start = " << time_start; ost << ", time_end = " << time_end; ost << ", data_start = " << data_start; ost << ", data_end = " << data_end; return ost.str(); }
display ( std::string name ) { m_display = XOpenDisplay ( name.c_str() ); if ( ! m_display ) { std::string ost("Could not open display"); } else { std::cout << "opened a display\n"; } }
QString StatementList::prints() const { QString tgt; OStream ost(&tgt); for (auto it = m_list.begin(); it != m_list.end(); it++) { ost << *it; if (std::next(it) != m_list.end()) { ost << ",\t"; } } return tgt; }
QString LocationSet::prints() const { QString tgt; OStream ost(&tgt); for (const_iterator it = begin(); it != end(); ++it) { if (it != begin()) { ost << ", "; } ost << *it; } return tgt; }
/** * matchBeforeBrace checks to see if the wildcard string 'name' matches * up with the name of the id. * Rules: * # may only be used once in the wildcard, but substitutes for any * number of characters. * * ? may be used any number of times in the wildcard, and * must substitute exactly for characters. * * If bracesInName, then the Id name itself includes braces. */ bool matchBeforeBrace( Id id, const string& name, bool bracesInName, unsigned int index ) { if ( name == "#" ) return 1; string ename = id()->name(); if ( bracesInName ) { string::size_type pos = ename.rfind( '[' ); if ( pos == string::npos ) return 0; if ( pos == 0 ) return 0; if ( index != Id::AnyIndex ) { ostringstream ost( "ost" ); ost << "[" << index << "]"; if ( ost.str() != ename.substr( pos ) ) return 0; } ename = ename.substr( 0, pos ); } if ( name == ename ) return 1; string::size_type pre = name.find( "#" ); string::size_type post = name.rfind( "#" ); // # may only be used once in the wildcard, but substitutes for any // number of characters. if ( pre != string::npos && post == pre ) { unsigned int epos = ename.length() - ( name.length() - post - 1 ); return ( name.substr( 0, pre ) == ename.substr( 0, pre ) && name.substr( post + 1 ) == ename.substr( epos ) ); } // ? may be used any number of times in the wildcard, and // must substitute exactly for characters. if ( name.length() != ename.length() ) return 0; for ( unsigned int i = 0; i < name.length(); i++ ) if ( name[i] != '?' && name[i] != ename[i] ) return 0; return 1; }
Cpointls::Cpointls(double* xyarray,int *nrow,int *ncol) { // better code? : fittedparamnbr=(*ncol)-1; this->xy.resize(*nrow); for (int ii=0;ii<(*nrow);ii++) { this->xy[ii].resize(0); for (int jj=0;jj<(*ncol);jj++) { this->xy[ii].push_back(xyarray[ii*(*ncol)+jj]); #ifdef NO_R_CONSOLE #else // Rprintf("%d %d %f \n",ii,jj,this->xy[ii].back()); #endif } } std::stringstream ost(std::stringstream::in | std::stringstream::out); ost>>pointlsFileName; ost.clear(); }
void SaveToFile(MyTree<T> *root, string filename) { ofstream ost(filename); // открытие потока для записи в файл MyStack<MyTree<T>*> st = CreateEmptyStack<MyTree<T>*>(); // стек с ещё не обработанными эл-тами дерева Push(st, root); // есть ещё необработанные? пишем в файл while (!isEmpty(st)) { MyTree<T>* tmp = Pop(st); // заносим в стек эл-ты, если они существуют // иначе просто возвращаем false (заглушка) (tmp->left != nullptr) ? Push(st, tmp->left) : false; (tmp->right != nullptr) ? Push(st, tmp->right) : false; ost << tmp->data << ' '; } }
int main() { cout << "Please enter input file name: "; string name; cin >> name; ifstream ist(name.c_str()); if (!ist) error("cannot open input file ", name); cout << "Please enter name of output file: "; cin >> name; ofstream ost(name.c_str()); if (!ost) error("cannot open outputfile ", name); vector<Reading> temps; int hour; double temperature; while (ist >> hour >> temperature) { if (hour < 0 || 23 < hour) error("hour out of range ", hour); temps.push_back(Reading(hour, temperature)); } for (int i=0; i<temps.size(); i++) { ost << "(" << temps[i].hour << ", " << temps[i].temperature << ")" << endl; } }
void write(Fileread&file) { string name = "/Users/joekirk/Desktop/test.axsf"; ofstream ost(name.c_str()); if (!ost) cout << "cannot open file " << name; ost << "AMNISTEPS " << file.frames.size() << endl; ost << endl; ost << "CRYSTAL" << endl; ost << endl; ost << "PRIMVEC" << endl; for (int i = 0; i < file.cellvectors.size(); ++i) { ost << file.cellvectors[i].x << "\t" << file.cellvectors[i].y << "\t" << file.cellvectors[i].z << endl; } for (int i = 0; i <file.frames.size(); ++i) { ost << endl; ost << "PRIMCOORD " << i+1 << endl; ost << file.modelsize << " " << 1 << endl;; for (int j=0; j < file.modelsize; ++j) ost << " " << file.atomtypes[j] << "\t" << file.frames[i][j].x << "\t" <<file.frames[i][j].y <<"\t" << file.frames[i][j].z << endl; } }
void TetrahedralityParam::writeOrderParameter() { int nSelected = 0; for (int i = 0; i < nBins_; ++i) { nSelected = nSelected + int(Q_histogram_[i]*deltaQ_); } std::ofstream osq((getOutputFileName() + "Q").c_str()); if (osq.is_open()) { osq << "# Tetrahedrality Parameters\n"; osq << "# selection: (" << selectionScript_ << ")\n"; osq << "# \n"; // Normalize by number of frames and write it out: for (int i = 0; i < nBins_; ++i) { RealType Qval = MinQ_ + (i + 0.5) * deltaQ_; osq << Qval; osq << "\t" << (RealType) (Q_histogram_[i]/deltaQ_)/nSelected; osq << "\n"; } osq.close(); }else { sprintf(painCave.errMsg, "TetrahedralityParam: unable to open %s\n", (getOutputFileName() + "q").c_str()); painCave.isFatal = 1; simError(); } DumpReader reader(info_, dumpFilename_); int nFrames = reader.getNFrames(); if (nFrames == 1) { std::vector<StuntDouble*>::iterator iter; std::ofstream osd((getOutputFileName() + "dxyz").c_str()); if (osd.is_open()) { osd << Distorted_.size() << "\n"; osd << "\n"; for (iter = Distorted_.begin(); iter != Distorted_.end(); ++iter) { Vector3d position; position = (*iter)->getPos(); osd << "O " << "\t"; for (unsigned int z = 0; z < position.size(); z++) { osd << position[z] << " " << "\t"; } osd << "\n"; } osd.close(); } std::ofstream ost((getOutputFileName() + "txyz").c_str()); if (ost.is_open()) { ost << Tetrahedral_.size() << "\n"; ost << "\n"; for (iter = Tetrahedral_.begin(); iter != Tetrahedral_.end(); ++iter) { Vector3d position; position = (*iter)->getPos(); ost << "O " << "\t"; for (unsigned int z = 0; z < position.size(); z++) { ost << position[z] << " " << "\t"; } ost << "\n"; } ost.close(); } } }
/* Setup configuration values * Don't query the existence of the Log.Level because it's a * mandatory value. That is, if it doesn't exist, the configuration * table will crash or will have already crashed. Everything else we * can survive without and use default values if the database entries * are empty. */ bool trx_setup_config(struct trx_config *config) { std::string refstr, fillstr, divstr; if (!testConfig()) return false; if (config->log_level == "") config->log_level = gConfig.getStr("Log.Level"); if (!config->port) { if (gConfig.defines("TRX.Port")) config->port = gConfig.getNum("TRX.Port"); else config->port = DEFAULT_TRX_PORT; } if (config->addr == "") { if (gConfig.defines("TRX.IP")) config->addr = gConfig.getStr("TRX.IP"); else config->addr = DEFAULT_TRX_IP; } if (!config->extref) { if (gConfig.defines("TRX.Reference")) config->extref = gConfig.getNum("TRX.Reference"); else config->extref = DEFAULT_EXTREF; } if (!config->diversity) { if (gConfig.defines("TRX.Diversity")) config->diversity = gConfig.getNum("TRX.Diversity"); else config->diversity = DEFAULT_DIVERSITY; } /* Diversity only supported on 2 channels */ if (config->diversity) config->chans = 2; refstr = config->extref ? "Enabled" : "Disabled"; divstr = config->diversity ? "Enabled" : "Disabled"; switch (config->filler) { case Transceiver::FILLER_DUMMY: fillstr = "Dummy bursts"; break; case Transceiver::FILLER_ZERO: fillstr = "Disabled"; break; case Transceiver::FILLER_RAND: fillstr = "Normal busrts with random payload"; break; } std::ostringstream ost(""); ost << "Config Settings" << std::endl; ost << " Log Level............... " << config->log_level << std::endl; ost << " Device args............. " << config->dev_args << std::endl; ost << " TRX Base Port........... " << config->port << std::endl; ost << " TRX Address............. " << config->addr << std::endl; ost << " Channels................ " << config->chans << std::endl; ost << " Samples-per-Symbol...... " << config->sps << std::endl; ost << " External Reference...... " << refstr << std::endl; ost << " C0 Filler Table......... " << fillstr << std::endl; ost << " Diversity............... " << divstr << std::endl; ost << " Tuning offset........... " << config->offset << std::endl; ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl; ost << " Swap channels........... " << config->swap_channels << std::endl; std::cout << ost << std::endl; return true; }
Profiler::~Profiler() { //////////////////////// // get symbol info from eip, and put them into statistics //////////////////////// const auto result0 = SymInitialize(GetCurrentProcess(), nullptr, true); char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)] = { 0 }; PSYMBOL_INFO func_info = (PSYMBOL_INFO)buffer; func_info->SizeOfStruct = sizeof(SYMBOL_INFO); func_info->MaxNameLen = MAX_SYM_NAME; func_info->Flags = SYMFLAG_FUNCTION; std::unordered_map<std::string, unsigned> statistics; for (auto eip : s_records) { auto result = SymFromAddr(GetCurrentProcess(), eip, nullptr, func_info); std::string func_name = func_info->Name; auto iter = statistics.find(func_name); if (iter == statistics.end()) iter = statistics.emplace(func_name, 0).first; ++(iter->second); } //////////////////////// // sort the statistics //////////////////////// typedef std::pair<std::string, unsigned> pair_t; std::vector <pair_t> sorted_pairs(statistics.begin(), statistics.end()); std::make_heap(sorted_pairs.begin(), sorted_pairs.end()); std::sort(sorted_pairs.begin(), sorted_pairs.end(), [](const pair_t& pair1, const pair_t& pair2){ return (pair1.second > pair2.second) || ((pair1.second == pair2.second) && (pair1.first.compare(pair2.first) > 0)); }); //////////////////////// // output statistics //////////////////////// typedef std::pair<std::string, unsigned> pair_t; std::fstream ost(s_path.c_str(), std::ios_base::out); const auto total_count = s_init_count - s_count; for (auto& info : sorted_pairs) { ost << std::setw(8) << std::setprecision(3) << std::fixed << std::right << (100.f * info.second) / total_count << " % " /*count*/ << info.first /*name*/ << "\n"; } ost << "\nOverall " << total_count << " samples collected.\n\n"; ost.close(); system("sh report_gen.sh"); //////////////////////// // Reset count //////////////////////// s_count = 0; }