bool SaveOBJ(ofstream& fout, const double* const& points, const int* const& triangles, const unsigned int& nPoints, const unsigned int& nTriangles, const Material& material, IVHACD::IUserLogger& logger, int convexPart, int vertexOffset) { if (fout.is_open()) { fout.setf(std::ios::fixed, std::ios::floatfield); fout.setf(std::ios::showpoint); fout.precision(6); size_t nV = nPoints * 3; size_t nT = nTriangles * 3; fout << "o convex_" << convexPart << std::endl; if (nV > 0) { for (size_t v = 0; v < nV; v += 3) { fout << "v " << points[v + 0] << " " << points[v + 1] << " " << points[v + 2] << std::endl; } } if (nT > 0) { for (size_t f = 0; f < nT; f += 3) { fout << "f " << triangles[f + 0]+vertexOffset << " " << triangles[f + 1]+vertexOffset << " " << triangles[f + 2]+vertexOffset << " " << std::endl; } } return true; } else { logger.Log("Can't open file\n"); return false; } }
int main() { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); int i,j,t; double tmp; cin>>t; while(t > 0) { cin>>n>>tmp; m = tmp * 100.00000000 + 0.5; for( i = 1 ; i <= n ; ++ i) { cin>>w[ i ]>>v[ i ]; v[ i ] = v[ i ] * 100 + 0.5; } for( i = 1 ; i <= n ; ++ i) for( j = int( m ) ;j >= int(v[ i ]) ; -- j) if( f[ j ] < f[ j - int(v[ i ]) ] + w[ i ] ) f[ j ] = f[ j - int(v[ i ]) ] + w[ i ]; cout<<f[ int(m) ]<<"\n"; for( i = int( m ) ; i >= 0 ; -- i ) f[ i ] = 0; --t; } return 0; }
void setPrintPrecision(int print_precision, ofstream& out) { cout.setf(std::ios::scientific); cout.precision(print_precision); out.setf(std::ios::fixed); out.precision(print_precision); out.setf(ios::showpoint); }
void percentDiff(double valA, double valB, ofstream& foutA) { double result; result = ( fabs(valA - valB) / ( (valA + valB) / 2) ) * 100; foutA.setf(ios::fixed); foutA.setf(ios::showpoint); foutA.precision(2); foutA << setw(15) << result << " %" << endl; foutA.precision(6); } // end of percent diff
/* Example: After applying work(): 1: MPI_Bcast= (void buffer= 1198516368, int count= 80, MPI_Datatype datatype= 1247288704, int root= 0, MPI_Comm comm= 6604320, )S=[ 1367981215084679 ] E=[ 1367981215086238 ] D=[ 1559 ] */ void work() { string s; int count = 0; double startTime, endTime, durTime; getline(fin ,s); while (fin) { count++; fout << count << ": "; char *str = (char *) s.c_str(); char *p = strtok(str, " "); startTime = atof(p); p = strtok(NULL, " "); string funcName(p); fout << funcName << "= "; p = strtok(NULL, " "); string funcArgs(p); fout << funcArgs ; fout.setf(ios::fixed); fout << "S=[ " << startTime << " ] "; p = strtok(NULL, " "); string ret_value(p); fout.setf(ios::fixed); fout << "R=[ " << ret_value << " ] "; p = strtok(NULL, " "); durTime = atof(p); endTime = startTime + durTime; fout << "E=[ " << endTime << " ] "; fout << "D=[ " << durTime << " ] "; fout << std::endl; getline(fin ,s); } }
// This function is called when the application exits VOID Fini(INT32 code, VOID *v) { if (icount1 != icount2 || icount1 != icount3 || icount1 != icount4 || icount1 != icount5 || thenCount!=0) { // Write to a file since cout and cerr maybe closed by the application OutFile.open(KnobOutputFile.Value().c_str()); OutFile.setf(ios::showbase); if (thenCount!=0) { OutFile << "****ERROR thenCount was expected to be 0 not: " << thenCount << endl; } else { OutFile << "Count1 " << icount1 << endl; OutFile << "Count2 " << icount2 << endl; OutFile << "Count3 " << icount3 << endl; OutFile << "Count4 " << icount3 << endl; OutFile << "Count5 " << icount3 << endl; OutFile << "***ERROR - mismatch in icounts " << endl; } OutFile.close(); exit (1); } }
static void TryOpen(ofstream& f, const char* name){ f.open(name); f.setf(ios::showbase); if (f.fail()){ ErrorExit("cannot open output file: " << name, MetasimError_FileOp); } }
// This function is called when the application exits VOID Fini(INT32 code, VOID *v) { // Write to a file since cout and cerr maybe closed by the application OutFile.setf(ios::showbase); OutFile << "Count " << icount << endl; OutFile.close(); }
int main(int argc, CHAR *argv[]) { char * s = getenv("LD_ASSUME_KERNEL"); if (s == 0) printf("LD_ASSUME_KERNEL not set\n"); else if (strcmp(s,"2.4.1") != 0) printf("LD_ASSUME_KERNEL is wrong: %s\n",s); PIN_InitSymbols(); if( PIN_Init(argc,argv) ) { return Usage(); } TraceFile.open(KnobOutputFile.Value().c_str()); TraceFile << hex; TraceFile.setf(ios::showbase); IMG_AddInstrumentFunction(ImageLoad, 0); PIN_StartProgramProbed(); return 0; }
/** Put a table of node values. This table is as compact as possible while still maintaining readability */ void NodeList::PutTable( ofstream& s ) { s.precision(4); s.setf( ios::right, ios::adjustfield ); s << GNU_COMMENT << " NodeList\n" << GNU_COMMENT << "=========\n"; s << GNU_COMMENT << ' ' << setw( 6) << "Id(1) " << setw(13) << "x(2) " << setw(13) << "fluxS(3) " << setw(13) << "fluxD(4) " << setw(13) << "fluxE(5) " << setw(13) << "left id(6) " << setw(13) << "right id(6) " << '\n'; SetLineStyle( '-' ); PutLine( s, 106 ); for( int i=0; i<n; i++ ){ node[i].PutTable( s ); } s.flush(); }
int main(int argc, char* argv[]) { if ( PIN_Init(argc, argv) ) return Usage(); PIN_InitSymbols(); // Initialize trace trace.open(KnobOutputFile.Value().c_str()); trace << hex; trace.setf(ios::showbase); // Intialize stack tracing code IMG_AddInstrumentFunction(I_ImageLoad, 0); TRACE_AddInstrumentFunction(I_Trace, 0); // Initialize memory tracing code INS_AddInstrumentFunction(Instruction, 0); IMG_AddInstrumentFunction(Image, 0); // Initialize cleanup code PIN_AddFiniFunction(Fini, 0); PIN_StartProgram(); assert(false && "Control should never reach here!"); return 0; }
//Output values for neural network void outputNet(neuNet network, ofstream &output) { output.setf(ios::fixed,ios::floatfield); output.precision(3); output << network.input.size() << " "; //output number of inputs output << network.hidden.size() << " "; //output number of hidden nodes output << network.output.size() << endl; //output number of outputs //output weights of input-hidden node edges for (int i = 0; i < network.hid_in.size(); ++i) { for (int j = 0; j < network.hid_in[i].size(); ++j) { //if-else to prevent placing space at end of line if (j != network.hid_in[i].size()-1) output << "input hidden: " << network.hid_in[i][j] << " "; else output << "input hidden: " << network.hid_in[i][j]; } output << endl; } //output weights of hidden node-output edges for (int i = 0; i < network.out_hid.size(); ++i) { for (int j = 0; j < network.out_hid[i].size(); ++j) { //if-else to prevent placing space at end of line if (j != network.out_hid[i].size()-1) output << "output weight: " << network.out_hid[i][j] << " "; else output << "output weight: " << network.out_hid[i][j]; } output << endl; } }
void write(ofstream& out, Car c[], int size) { for(int i=0; i < size; i++) { Car CAR = c[i]; out.setf(ios::fixed); out.setf(ios::showpoint); out.precision(2); out << CAR.make << " " << CAR.model << " " << CAR.year << " " << CAR.price << " " << CAR.miles << " " << CAR.getValue() << endl; } return; }
void init_log(const VolModel model, const RunMode runmode, ofstream& log_stream) { string logfile = "./log_" + get_model_name(model) + "_" + get_run_mode(runmode); cout<<"log file is: "<<logfile<<endl; log_stream.open(logfile.c_str()); log_stream.setf(ios::fixed); log_stream<<setprecision(10); }
void processing(ifstream& inFile, ofstream& outFile) { //variable declarations char letter; double number, avg, sum(0); //sets precision and decimal place outFile.setf(ios::fixed); outFile.setf(ios::showpoint); outFile.precision(2); outFile << "********************************************" << endl << "Student Name: "; //outputs name to result.txt while(letter != '\n') { inFile.get(letter); outFile.put(letter); } outFile << "Test Scores: "; //outputs scores and finds their sum inFile >> number; while(! inFile.eof( )) { sum += number; outFile << number << setw(8); inFile >> number; } //calculates average avg = sum / 5.0; outFile << endl << "Average Score: " << avg << endl << "********************************************" << endl; }
//Uses iostream, fstream, and iomanip: void make_neat(ifstream& messy_file, ofstream& neat_file, int number_after_decimalpoint, int field_width) { neat_file.setf(ios::fixed); neat_file.setf(ios::showpoint); neat_file.setf(ios::showpos); neat_file.precision(number_after_decimalpoint); cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.setf(ios::showpos); cout.precision(number_after_decimalpoint); double next; while (messy_file >> next) { cout << setw(field_width) << next << endl; neat_file << setw(field_width) << next << endl; } }
// This function is called when the application exits VOID Fini(INT32 code, VOID *v) { // Write to a file since cout and cerr maybe closed by the application OutFile.setf(ios::showbase); OutFile << "Count " << ins_count[cDYN] << endl; OutFile.close(); cout << "Dynamic:\t" << ins_count[cDYN] << endl; cout << "Integer:\t" << ins_count[cINT] << endl; cout << "Float:\t" << ins_count[cFL] << endl; cout << "Load:\t" << ins_count[cLD] << endl; cout << "Store:\t" << ins_count[cST] << endl; cout << "Branch:\t" << ins_count[cBR] << endl; cout << "Other:\t" << ins_count[cMISC] << endl; }
int main(int argc, char * argv[]) { PIN_Init(argc, argv); out.open(KnobOutputFile.Value().c_str()); out << hex; out.setf(ios::showbase); INS_AddInstrumentFunction(Instruction, 0); PIN_AddFiniFunction(Fini, 0); // Never returns PIN_StartProgram(); return 0; }
int main(int argc, char * argv[]) { // Initialize pin & symbol manager if (PIN_Init(argc, argv)) return Usage(); PIN_InitSymbols(); // Register ImageLoad to be called to instrument instructions IMG_AddInstrumentFunction(ImageLoad, 0); PIN_AddFiniFunction(Fini, 0); // Write to a file since cout and cerr maybe closed by the application OutFile.open(KnobOutputFile.Value().c_str()); OutFile.setf(ios::showbase); // Start the program, never returns PIN_StartProgram(); return 0; }
// This function is called when the application exits VOID Fini(INT32 code, VOID *v) { // Write to a file since cout and cerr maybe closed by the application OutFile.setf(ios::showbase); OutFile << "Count Mem Reads " << icountMemRead << endl; OutFile << "Count Mem Read2s " << icountMemRead2 << endl; OutFile << "Count Mem Writes " << icountMemWrite << endl; OutFile << "Count Mem Ops " << icountMemOp << endl; OutFile << "Count Mem callbacks " << icountMemCall << endl; OutFile << "Errors " << errors << endl; OutFile.close(); // If we have errors then terminate abnormally if (errors) { cout << "Test memory_addr_callback is terminated cause found " << errors << " errors " << endl; PIN_ExitProcess(errors); } }
int main(int argc, CHAR *argv[]) { PIN_InitSymbols(); if( PIN_Init(argc,argv) ) { return Usage(); } TraceFile.open(KnobOutputFile.Value().c_str()); TraceFile << hex; TraceFile.setf(ios::showbase); IMG_AddInstrumentFunction(ImageLoad, 0); PIN_StartProgramProbed(); return 0; }
void TimeData::PutParam( ofstream& s ) { s.precision(4); s.setf( ios::left, ios::adjustfield ); s << GNU_COMMENT << " TimeData:: Control Parameters:\n" << GNU_COMMENT << "-------------------------------\n"; s << GNU_COMMENT << " .step_control.x = " << setw(7) << step_control.x << '\n' << GNU_COMMENT << " .step_control.c = " << setw(7) << step_control.c << '\n' << GNU_COMMENT << " .step_control.p1 = " << setw(7) << step_control.p1 << '\n' << GNU_COMMENT << " .step_control.p2 = " << setw(7) << step_control.p2 << '\n'; s << GNU_COMMENT << " coord_max = " << setw(8) << coord_max << '\n' << GNU_COMMENT << " n_max = " << setw(8) << n_max << endl; }
// argc, argv are the entire command line, including pin -t <toolname> -- ... int main(int argc, char * argv[]) { OutFile.open(KnobOutputFile.Value().c_str()); OutFile << std::hex; OutFile.setf(ios::showbase); // Initialize pin PIN_Init(argc, argv); // Register Instruction to be called to instrument instructions INS_AddInstrumentFunction(Instruction, 0); // Register Fini to be called when the application exits PIN_AddFiniFunction(Fini, 0); // Start the program, never returns PIN_StartProgram(); return 0; }
/** * Function to write Undergraduate student's data to an output file * stream that has been opened */ void Undergraduate::write_to_stream (ofstream & outputfile) { // Left align the data outputfile.setf(ios::left); outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS); outputfile << "Undergraduate"; outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS); outputfile << Student::get_lastname(); outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS); outputfile << get_firstname(); outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS); outputfile << get_ssn(); outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS); outputfile << get_phone(); outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS); outputfile << get_age(); outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS); outputfile << get_major(); outputfile.width(MAXIMUM_NUMBER_OF_CHARACTERS); outputfile << get_minor() << endl; //outputfile << endl; }
int main(int argc, CHAR *argv[]) { PIN_InitSymbols(); if( PIN_Init(argc,argv) ) { return Usage(); } TraceFile.open(KnobOutputFile.Value().c_str()); TraceFile << hex; TraceFile.setf(ios::showbase); PIN_InitLock(&lock); IMG_AddInstrumentFunction(ImageLoad, 0); PIN_AddApplicationStartFunction(AppStart, 0); PIN_AddThreadAttachProbedFunction(AttachedThreadStart, 0); PIN_StartProgramProbed(); return 0; }
int main(int argc, char *argv[]) { // Initialize Pin PIN_InitSymbols(); if (PIN_Init(argc,argv)) { return Usage(); } OutFile.open(KnobOutputFile.Value().c_str()); OutFile << hex; OutFile.setf(ios::showbase); OutFile << CurrentTime() << "started!" << endl; OutFile.flush(); // Register the instrumentation callback IMG_AddInstrumentFunction(ImgLoad, 0); // Start the application PIN_StartProgramProbed(); // never returns return 0; }
/** Put a table of node values. This table is as compact as possible while still maintaining readability */ void Node::PutTable( ofstream& s ) { s.precision(4); s.setf( ios::right, ios::adjustfield ); s << setw( 6) << id << ' ' << setw(12) << x << ' ' << setw(12) << flux.S << ' ' << setw(12) << flux.D << ' ' << setw(12) << flux.E << ' '; if( left != 0 ){ s << setw(12) << left->id << ' '; } else { s << setw(12) << "0 (bdy)" << ' '; } if( right != 0 ){ s << setw(12) << right->id << ' '; } else { s << setw(12) << "0 (bdy)" << ' '; } s << '\n'; }
// This function is called when the application starts VOID Init() { outFile.open(OUTPUT_FILE); outFile << hex; outFile.setf(ios::showbase); outFile << "----=Start of Flow Graph=----" << endl; // Routine in ExceptList will not appear ExceptList.push_back(".plt"); ExceptList.push_back("__do_global_ctors_aux"); ExceptList.push_back("__do_global_dtors_aux"); ExceptList.push_back("lstat"); ExceptList.push_back("fstat"); ExceptList.push_back("__fstat"); ExceptList.push_back("__lstat"); ExceptList.push_back("__stat"); ExceptList.push_back("_start"); ExceptList.push_back("_init"); ExceptList.push_back("_fini"); ExceptList.push_back("__libc_csu_init"); ExceptList.push_back("call_gmon_start"); ExceptList.push_back("frame_dummy"); }
int main(int argc, char * argv[]) { // Initialize pin if (PIN_Init(argc, argv)) {return Usage();} OutFile.open(KnobOutputFile.Value().c_str()); OutFile.setf(ios::showbase); PIN_InitSymbols(); // Register ImageLoad to be called to instrument instructions IMG_AddInstrumentFunction(Image, 0); // Register Instruction to be called to instrument instructions INS_AddInstrumentFunction(Instruction, 0); // Register Fini to be called when the application exits PIN_AddFiniFunction(Fini, 0); // Start the program, never returns PIN_StartProgram(); return 0; }
int main( void ) { const string stateNames[states] = { "Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida", "Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine", "Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire", "New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island", "South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin", "Wyoming"}; int totalVotes; int required; int worstRep; const long populations[states]={4447100, 626932, 5130632, 2673400, 33871648, 4301261, 3405565, 783600, 15982378, 8186453, 1211537, 1293953, 12419293, 6080485, 2926324, 2688418, 4041769, 4468976, 1274923, 5296486, 6349097, 9938444, 4919479, 2844658, 5595211, 902195, 1711263, 1998257, 1235786, 8414350, 1819046, 18976457, 8049313, 642200, 11353140, 3450654, 3421399, 12281054, 1048319, 4012012, 754844, 5689283, 20851820, 2233169, 608827, 7078515, 5894121, 1808344, 5363675, 493782}; double powertype[maxVotes]; int votes[states]; int votetype[maxVotes]; state UnitedStates[states];//create the united states for(int loop=0; loop<states; loop++) { votes[loop]=1; UnitedStates[loop].votes=votes[loop]; UnitedStates[loop].name=stateNames[loop]; UnitedStates[loop].population=populations[loop]; }//initiallize each phase //initialization phase of the program - sets all states to 1 vote and tells the population values int checkSanity=0; do { checkSanity++; for(int loop=0; loop < maxVotes; loop++) { votetype[loop]=0; powertype[loop]=0; }//initialize power for(int loop=0; loop<states; loop++) { UnitedStates[loop].power=0; votetype[votes[loop]]++; }//initiallize each phase totalVotes=voteSum(votetype); required=totalVotes-totalVotes/2; calculateBanzhaf(votetype,required,powertype); required=totalVotes-totalVotes/3; calculateBanzhafOveride(votetype,required,powertype); for(int loop=0; loop<states; loop++) { UnitedStates[loop].power=powertype[UnitedStates[loop].votes]; }//input power with each state if (checkSanity%10==9) { for(int loop=0; loop<states; loop++) { cout.setf(ios::fixed); printState(UnitedStates[loop]); } cout<<"Votes = "<<totalVotes<<endl; }//sanity checker dataout.open("VotePow.txt", ios::app); worstRep=worst(UnitedStates); UnitedStates[worstRep].votes++; votes[worstRep]++; dataout.close(); }while(totalVotes<435); dataout.open("VotePow.txt", ios::app); for(int loop=0; loop<states; loop++) { if (loop%10==0) { cin.ignore(80,'\n'); printHeader(); printHeaderFile(); }//every 10 lines cout.setf(ios::fixed); dataout.setf(ios::fixed); printState(UnitedStates[loop]); printStateFile(UnitedStates[loop]); } dataout.close(); return 0; }