本文整理汇总了C++中ofstream::open方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::open方法的具体用法?C++ ofstream::open怎么用?C++ ofstream::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofstream
的用法示例。
在下文中一共展示了ofstream::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openFile
/**
Method to open in write mode the file with given name and path
@param file: file stream to open
@param filePath: path to the file to open
@param fileName: name of the path to open
*/
void BasicGenerator::openFile(ofstream &file, const string &filePath, const string &fileName)
{
string fileFullName=filePath+fileName;
file.open(fileFullName.c_str(), ios::out);
}
示例2: main
int main()
{
srand(time(0));
HWND console = GetConsoleWindow();
RECT r;
GetWindowRect(console, &r);
MoveWindow(console, r.left, 100, (w_*72) + 100, 250 + (h_*72), TRUE);
//HWND hwnd = GetConsoleWindow();
//if (hwnd != NULL) { MoveWindow(hwnd, 340, 550, 680, 150, TRUE); }
#ifdef _DEBUG
debug.open("debug.txt");
if (debug.fail())
cout << "Failed to open debug stream";
#endif
int board[h_][w_]; //the main board
bool newGame = true; //whether to start a new game
int endOfGame; //6 = yes, 7 = no
int rowPlayed = 0; //stores the row in which the last disc was played
int colPlayed = 0; //stores the column in which the last disc was played
int whosTurn; //keeps track of who's turn it is (1 = player1/human, 2 = player2/computer)
int turn; //keeps track of how mant discs have been played
int MAX_DEPTH; //max depth of recursion for minimax
int winner = 0; //winner at end of game
int cutCount; //number of terminal nodes cut
clock_t t; //CPU time temp variable
double timeElapsed; //CPU time for computer's turn
double totalTime;
double averageTime; //average CPU time per computer turn
double averageTimeAfter4; //average CPU time per turn not counting turns 1-4
int averageCutCount;
while (newGame)
{
boardInit(board);
system("cls");
whosTurn = preGame();
//whosTurn = cDisc;
printScreen(board);
MAX_DEPTH = TYPICAL_DEPTH;
averageTime = 0;
averageTimeAfter4 = 0;
totalTime = 0;
averageCutCount = 0;
turn = 0;
while (turn < w_*h_)
{
if (MAX_DEPTH > w_*h_ - turn) MAX_DEPTH = w_*h_ - turn;
else MAX_DEPTH = TYPICAL_DEPTH;
if (whosTurn == 1) //player's turn
{
playerTurn(board, rowPlayed, colPlayed);
printScreen(board);
if (winDetect(board, rowPlayed, colPlayed, pDisc))
{
winner = 1;
break;
}
}
else if (whosTurn == 2) //computer's turn
{
cutCount = 0;
t = clock(); //start timer
compTurn(board, rowPlayed, colPlayed, turn, MAX_DEPTH, cutCount);
t = clock() - t;
timeElapsed = (double)t/CLOCKS_PER_SEC;
averageTime += timeElapsed;
if (turn > 3) averageTimeAfter4 += timeElapsed;
printScreen(board);
averageCutCount += cutCount;
if (TIME_STATS)
{
cout << "This Turn:\t\t" << timeElapsed << endl;
cout << "Average Time:\t\t" << averageTime / (turn + 1) << endl;
cout << "Average After 4:\t" << averageTimeAfter4 / (turn - 3) << endl;
cout << "Cut Count:\t\t" << averageCutCount / (turn + 1) << endl;
cout << "Turn: \t\t\t" << turn + 1 << endl;
}
Sleep(1500); //user friendly delay
cout << "COMPUTER PLAYED: ";
printColor(colPlayed+1, GAME_COLOR);
cout << "\n\n";
//cout << "CutCount: " << cutCount << "\n\n";
#ifdef _AB_DEBUG
cout << "CutCount: " << cutCount << "\n\n";
#endif
//.........这里部分代码省略.........
示例3: main
int main() {
/* CSS GENERATOR - BEGIN */
tobeprinted.clear();
tobeprinted += "/*!\n";
tobeprinted += "* Viewport v" + VERSION + " (" + REPO + ")\n";
tobeprinted += "* Copyright 2015 Simone Primarosa. (" + PROFILE + ")\n";
tobeprinted += "* Licensed under GNU General Public License version 3.0 (http://www.gnu.org/licenses/gpl-3.0.html)\n";
tobeprinted += "*/\n";
tobeprinted += "/*! " + FILENAME + ".css v" + VERSION + " | GNU GPL | " + FOLDER + FILENAME + ".css */\n\n";
tobeprinted += ".vh-test, .vw-test, .vmin-test, .vmax-test {position:fixed;z-index:-999999;height:1px; width:1px; overflow:hidden;}\n";
tobeprinted += ".vh-test {height: 100vh;} .vw-test {height: 100vw;} .vmin-test {height: 100vmin;} .vmax-test {height: 100vmax;}\n";
tobeprinted += ".vu-oveflow {overflow: hidden !important;}\n\n";
for(vector<string>::iterator vt = viewtype.begin(); vt != viewtype.end(); vt++) {
for(vector<string>::iterator pr = property.begin(); pr != property.end(); pr++) {
for(int i = 0; i < list_name.size(); i++) {
tobeprinted += "[" + *vt + "-" + *pr + " = \"" + list_name[i] + "\"] {" + *pr + ":" + to_str(list_value[i]) + *vt + ";}\n";
}
}
tobeprinted += "\n";
}
for(int v = 0; v < viewtype.size(); v++) {
for(int k = 128; k <= 2560; k *= 2) {
if(v < 2) tobeprinted += "@media " + media[v] + to_str(k) + "px) {\n";
else tobeprinted += "@media " + media[v] + to_str(k) + "px), " + media[v+2] + to_str(k) + "px) {\n";
for(vector<string>::iterator pr = property.begin(); pr != property.end(); pr++) {
for(int i = 0; i < list_name.size(); i++) {
tobeprinted += " .no-viewport [" + viewtype[v] + "-" + *pr + " = \"" + list_name[i] + "\"] {" + *pr + ":" + to_str(list_value[i]*(k*2/100.0)) + "px;}\n";
}
}
tobeprinted += "}\n";
}
}
fout.open(FILENAME+".css");
fout<<tobeprinted;
fout.close();
fout.open(FILENAME+".min.css");
fout<<doMinify(tobeprinted, false);
fout.close();
/* CSS GENERATOR - END */
/* JS GENERATOR - BEGIN */
tobeprinted.clear();
tobeprinted += "/*!\n";
tobeprinted += "* Viewport v" + VERSION + " (" + REPO + ")\n";
tobeprinted += "* Copyright 2015 Simone Primarosa. (" + PROFILE + ")\n";
tobeprinted += "* Licensed under GNU General Public License version 3.0 (http://www.gnu.org/licenses/gpl-3.0.html)\n";
tobeprinted += "*/\n";
tobeprinted += "/*! " + FILENAME + ".js v" + VERSION + " | GNU GPL | " + FOLDER + FILENAME + ".js */\n\n";
tobeprinted += "(function($) {\n";
tobeprinted += "\"use strict\";\n";
tobeprinted += "$(window).ready(function() {\n\n";
for(vector<string>::iterator vt = viewtype.begin(); vt != viewtype.end(); vt++) {
tobeprinted += " var " + *vt + "_" + "need = false;\n";
}
tobeprinted += "\n";
tobeprinted += " function viewport_init() {\n";
tobeprinted += " var deviceAgent = navigator.userAgent.toLowerCase();\n";
tobeprinted += " var oldIOS = (/ip(ad|hone|od).*os 3_/.test(deviceAgent) || /ip(ad|hone|od).*os 4_/.test(deviceAgent) || /ip(ad|hone|od).*os 5_/.test(deviceAgent) || /ip(ad|hone|od).*os 6_/.test(deviceAgent) || /ip(ad|hone|od).*os 7_/.test(deviceAgent));\n";
tobeprinted += " if(oldIOS) {\n";
for(vector<string>::iterator vt = viewtype.begin(); vt != viewtype.end(); vt++) {
tobeprinted += " " + *vt + "_" + "need = false;\n";
}
tobeprinted += " return;\n";
tobeprinted += " }\n";
tobeprinted += " var html = $(\"html\");\n";
tobeprinted += " html.removeClass(\"no-viewport\");\n";
tobeprinted += " html.addClass(\"vu-overflow\");\n";
for(int i = 0; i < viewtype.size(); i++) {
tobeprinted += " var " + viewtype[i] + "_test = " + "$(\"<div class='" + viewtype[i] + "-test'></div>\").appendTo(html);\n";
tobeprinted += " var " + viewtype[i] + "_calc = (" + viewtype[i] + "_test).height() - " + functions[i] + ";\n";
tobeprinted += " " + viewtype[i] + "_" + "need = (" + viewtype[i] + "_calc >= -1 && " + viewtype[i] + "_calc <= 1) ? false : true;\n";
tobeprinted += " " + viewtype[i] + "_test.remove();\n";
//tobeprinted += " console.log(" + viewtype[i] + "_calc + ' ' + (" + viewtype[i] + "_test).height() + ' ' + " + function[i] + ");\n";
tobeprinted += " if(" + viewtype[i] + "_" + "need == true) {\n";
for(int j = 0; j < property.size(); j++) {
tobeprinted += " window." + viewtype[i] + "_" + noDash(property[j]) + " = " + "$(\"[" + viewtype[i] + "-" + property[j] + "]\");\n";
}
tobeprinted += " }\n";
}
tobeprinted += " html.removeClass(\"vu-overflow\");\n";
tobeprinted += " }\n";
tobeprinted += " function viewport_exec() {\n";
tobeprinted += " var html = $(\"html\");\n";
tobeprinted += " html.addClass(\"vu-overflow\");\n";
for(int i = 0; i < viewtype.size(); i++) {
tobeprinted += " if(" + viewtype[i] + "_" + "need == true) {\n";
tobeprinted += " var " + viewtype[i] + "_value = " + functions[i] + "/100;\n";
for(int j = 0; j < property.size(); j++) {
tobeprinted += " window." + viewtype[i] + "_" + noDash(property[j]) + ".each(function() {$(this).css(\"" + property[j] + "\", " + "$(this).attr(\"" + viewtype[i] + "-" + property[j] + "\") * " + viewtype[i] + "_value" + ");});\n";
}
tobeprinted += " }\n";
}
tobeprinted += " html.removeClass(\"vu-overflow\");\n";
tobeprinted += " }\n";
//.........这里部分代码省略.........
示例4: main
int main(int argc, char** argv) {
// Open trace file.
tout.open("EXEC_TRACE");
std::string qsim_prefix(getenv("QSIM_PREFIX"));
if (!tout) { cout << "Could not open EXEC_TRACE for writing.\n"; exit(1); }
// Create a runnable OSDomain.
OSDomain *cdp = NULL;
if (argc < 3) {
cdp = new OSDomain(MAX_CPUS, qsim_prefix + "/../x86_64_images/vmlinuz", "x86");
//cd.connect_console(cout);
} else {
cdp = new OSDomain(MAX_CPUS, argv[1]);
//cd.connect_console(cout);
cout << "Loaded state. Reading benchmark.\n";
Qsim::load_file(*cdp, argv[2]);
cout << "Loaded benchmark .tar file.\n";
}
OSDomain &cd(*cdp);
cd.set_inst_cb(&cb_obj, &cb_struct::inst_cb);
cd.set_int_cb(&cb_obj, &cb_struct::int_cb);
cd.set_app_end_cb(&cb_obj, &cb_struct::end_cb);
// Init. sync objects
pthread_barrier_init(&cpu_barrier1, NULL, cd.get_n());
pthread_barrier_init(&cpu_barrier2, NULL, cd.get_n());
// Launch threads
start_time = utime();
for (int i = 0; i < cd.get_n(); i++) {
threads[i] = new pthread_t ;
thread_args[i] = new thread_arg_t ;
thread_args[i]->cpu = i;
thread_args[i]->cd = &cd;
thread_args[i]->icount = 0;
pthread_create(threads[i], NULL, cpu_thread_main, thread_args[i]);
}
// Wait for threads to end
for (int i = 0; i < cd.get_n(); i++) pthread_join(*threads[i], NULL);
end_time = utime();
// Print stats.
for (int i = 0; i < cd.get_n(); i++) {
cout << "CPU " << i << ": " << thread_args[i]->icount
<< " instructions.\n";
}
cout << end_time - start_time << "us\n";
// Clean up.
pthread_barrier_destroy(&cpu_barrier1);
pthread_barrier_destroy(&cpu_barrier2);
for (int i = 0; i < cd.get_n(); i++) {
delete threads[i];
delete thread_args[i];
}
tout.close();
return 0;
}
示例5: main
int main(int argc, char* argv[])
{
cerr << "PhraseStatistics v1.1 written by Nicola Bertoldi\n"
<< "modifying PhraseScore v1.4 written by Philipp Koehn\n"
<< "It computes statistics for extracted phrase pairs\n"
<< "if (direct):\n"
<< "src_phrase ||| trg_phrase || freq(src_phrase, trg_phrase) freq(src_phrase) length(src_phrase) length(trg_phrase)\n"
<< "if (inverse)\n"
<< "src_phrase ||| trg_phrase || freq(src_phrase, trg_phrase) freq(trg_phrase) length(src_phrase) length(trg_phrase)\n";
if (argc != 4 && argc != 5) {
cerr << "syntax: statistics extract lex phrase-table [inverse]\n";
exit(1);
}
char* &fileNameExtract = argv[1];
char* &fileNameLex = argv[2];
char* &fileNamePhraseTable = argv[3];
inverseFlag = false;
if (argc > 4) {
inverseFlag = true;
cerr << "using inverse mode\n";
}
// lexical translation table
lexTable.load( fileNameLex );
// sorted phrase extraction file
Moses::InputFileStream extractFile(fileNameExtract);
if (extractFile.fail()) {
cerr << "ERROR: could not open extract file " << fileNameExtract << endl;
exit(1);
}
istream &extractFileP = extractFile;
// output file: phrase translation table
phraseTableFile.open(fileNamePhraseTable);
if (phraseTableFile.fail()) {
cerr << "ERROR: could not open file phrase table file "
<< fileNamePhraseTable << endl;
exit(1);
}
// loop through all extracted phrase translations
int lastForeign = -1;
vector< PhraseAlignment > phrasePairsWithSameF;
int i=0;
string line;
while(getline(extractFileP, line)) {
if (extractFileP.eof()) break;
if (++i % 100000 == 0) cerr << "." << flush;
PhraseAlignment phrasePair;
bool isPhrasePair = phrasePair.create( line.c_str(), i );
if (lastForeign >= 0 && lastForeign != phrasePair.foreign) {
processPhrasePairs( phrasePairsWithSameF );
for(size_t j=0; j<phrasePairsWithSameF.size(); j++)
phrasePairsWithSameF[j].clear();
phrasePairsWithSameF.clear();
phraseTableE.clear();
phraseTableF.clear();
phrasePair.clear(); // process line again, since phrase tables flushed
phrasePair.create( line.c_str(), i );
phrasePairBase = 0;
}
lastForeign = phrasePair.foreign;
if (isPhrasePair)
phrasePairsWithSameF.push_back( phrasePair );
else
phrasePairBase++;
}
processPhrasePairs( phrasePairsWithSameF );
phraseTableFile.close();
}
示例6: main
/*Main{{{*/
Int_t main()
{
gStyle->SetOptFit(1);
gStyle->SetOptStat(0);
Int_t iType = 0;
cout<<"--- Which file ? (1->simple, 2->mult, 3->mult_fsi, 4->fermi, 5->mult_nofermi) "; cin >> iType;
if(iType==1) type_name = "simple";
if(iType==2) type_name = "mult";
if(iType==3) type_name = "mult_fsi";
if(iType==4) type_name = "fermi";
if(iType==5) type_name = "mult_nofermi";
Int_t bin_type = 0;
cout<<"--- Which Bining? (1->t, 2->tp, 3->log(tp) )"; cin>> bin_type;
if(bin_type==1) bin_name ="t";
if(bin_type==2) bin_name ="tp";
if(bin_type==3) bin_name ="logtp";
int BINS = 0;
if(bin_type==1) {BINS= 7;}
if(bin_type==2) {BINS= 9;}
if(bin_type==3) {BINS= 10;}
ifstream inputf;
inputf.open(Form("../asym_extr/results_may9/%s_dvmp_par_%s_%s.dat",bin_name.Data(), type_name.Data(), fit_pars.Data()));
TString com;
double temp;
int t_bin, Q2_bin;
inputf>>com>>com>>com>>com>>com
>>com>>com>>com>>com>>com
>>com>>com>>com>>com>>com
>>com>>com>>com>>com>>com
>>com>>com>>com>>com>>com>>com>>com;
for(int i=1; i<=BINS;i++){
for(int j=0; j<1;j++){
cout<<Form("--- working on IT = %d, IQ = %d", i,j)<<endl;
inputf >> t_bin >> Q2_bin
>> asym_1m1_avg>> asym_1m1_fit>> asym_1m1_err
>> asym_0p1_avg>> asym_0p1_fit>> asym_0p1_err
>> asym_2m1_avg>> asym_2m1_fit>> asym_2m1_err
>> asym_3m1_avg>> asym_3m1_fit>> asym_3m1_err
>> asym_1p1_avg>> asym_1p1_fit>> asym_1p1_err
>> temp >> temp >> Asym >> Astat
>> t_avg >> tp_avg >> xb_avg >> Q2_avg >> W_avg >> dilute_avg;
if(i!=t_bin || j!=Q2_bin){
cout<<Form("Something wrong?! T=%d/%d, Q=%d/%d", i, t_bin, j, Q2_bin)<<endl;
}
outf.open(Form("./database/BIN_%s_dvmp_par_%s_%s_%d_%d.dat",bin_name.Data(), type_name.Data(), fit_pars.Data(),i,j));
outf<<Form("%4s %4s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s",
"#t", "#Q2",
"A1M1_AVG", "A_1M1", "dA_1M1",
"A0P1_AVG", "A_0P1", "dA_0P1",
"A2M1_AVG", "A_2M1", "dA_2M1",
"A3M1_AVG", "A_3M1", "dA_3M1",
"A1P1_AVG", "A_1P1", "dA_1P1",
"Asym", "Astat",
"t", "tp","xb", "Q2", "W", "Dilute"
)
<<endl;
outf<<Form("%4d %4d %10.3e %10.3e %10.4e %10.3e %10.3e %10.4e %10.3e %10.3e %10.4e %10.3e %10.3e %10.4e %10.3e %10.3e %10.4e %10.4e %10.4e %10.4e %10.4e %10.4e %10.4e %10.4e %10.4e",
i, j,
asym_1m1_avg, asym_1m1_fit, asym_1m1_err,
asym_0p1_avg, asym_0p1_fit, asym_0p1_err,
asym_2m1_avg, asym_2m1_fit, asym_2m1_err,
asym_3m1_avg, asym_3m1_fit, asym_3m1_err,
asym_1p1_avg, asym_1p1_fit, asym_1p1_err,
Asym, Astat,
t_avg, tp_avg, xb_avg, Q2_avg, W_avg, dilute_avg
)
<<endl;
outf <<Form("%6s %6s %12s %12s %12s %12s %12s %12s %12s %12s %12s %12s %12s %12s",
"Phi", "PhiS",
"N_U_avg", "N_D_avg", "Asym_avg","dAsym_avg",
"N_U_fit", "N_D_fit", "Asym_fit","dAsym_fit",
"Asym_cal","dAsym_cal",
"GOOD_fit", "GOOD_cal"
)<<endl;
/////////////////////////////
//Load Data from MC Rootfiles to bin on phi and phiS
/////////////////////////////
LoadData(i, j);
outf.close();
}
}
return 0;
}
示例7: RINEXHeaderFile
Application::Application(int argc,char **argv)
{
app = this;
init();
// Process the command line options
// These override anything in the configuration file, default or specified
int longIndex;
int c;
string RINEXHeaderFile("");
while ((c=getopt_long(argc,argv,"hm:",longOptions,&longIndex)) != -1)
{
switch(c)
{
case 0: // long options
{
switch (longIndex)
{
case 0:
configurationFile=optarg;
break;
case 1:
counterPath=optarg;
break;
case 2:
//CGGTSComment=optarg;
break;
case 3:
{
string dbgout = optarg;
if ((string::npos != dbgout.find("stderr"))) {
debugStream = & std::cerr;
}
else {
debugFileName = dbgout;
debugLog.open(debugFileName.c_str(),ios_base::app);
if (!debugLog.is_open()) {
cerr << "Unable to open " << dbgout << endl;
exit(EXIT_FAILURE);
}
debugStream = & debugLog;
}
break;
}
case 4:
TICenabled=false;
break;
case 5:
showHelp();
exit(EXIT_SUCCESS);
break;
case 6:
generateNavigationFile=false;
break;
case 7:
receiverPath=optarg;
break;
case 8:
{
if (1!=sscanf(optarg,"%i",&verbosity)) {
cerr << "Bad value for option --verbosity" << endl;
showHelp();
exit(EXIT_FAILURE);
}
}
break;
case 9:
timingDiagnosticsOn=true;
break;
case 10:
showVersion();
exit(EXIT_SUCCESS);
break;
case 11:
SVDiagnosticsOn=true;
break;
case 12:
shortDebugMessage=true;
break;
}
}
break;
case 'h':
showHelp();
exit(EXIT_SUCCESS);
break;
case 'm':
{
if (1!=sscanf(optarg,"%i",&MJD)) {
cerr << "Bad value for option --mjd" << endl;
showHelp();
exit(EXIT_FAILURE);
//.........这里部分代码省略.........
示例8: correlatedMovement_correlatedInTime
/* Movement of the paddles that is correlated in space and in time
* This method currently operates on a time-schedule of 1 new correlation computation to the grid every 0.1 seconds.
* In principle, this can be easily modified to separate the time-scale of the grid from the time-scale of the correlations
* (e.g. by running one correlation every 0.5 seconds but still sending angles to the grid every 0.1 seconds). The current schedule
* gives the highest rate of correlation computations we can handle, given the nature of the runcorr_3D algorithm and our current computers.
* We define the term "constraining" as the occasion when a paddle is given a new angle to move to that it cannot reach without exceeding the
* limits of its servo (e.g. an amplitude of 60 degrees when the maximum angular distance it can travel in 0.1 seconds is 42.8 degrees). Such
* noncompliant paddles will be "constrained" to move at the greatest allowed servo speed (e.g. 4.28 deg/s instead of 6 deg/s) and thus will
* not reach their target destinations. This was a necessary comprimise in order to maximize the grid's correlation computation rate.
*/
int correlatedMovement_correlatedInTime(int constantArea, float spatial_sigma, float temporal_sigma, float spatial_alpha, float temporal_alpha, float spatial_height, float temporal_height, int typeOfSpatialCorr, int typeOfTemporalCorr, float target_rms, int numberOfSlices){
/* To install mySignalHandler (which prints statistics when you type CTRL-C)
you must make sure that CTRL-C signals are not blocked.
If you are having problems with the signal handler (i.e. CTRL-C signals are blocked)
you can just comment out the following block and the block after this one where the signal handler is actually installed.*/
void (*pfRet)(int);
sigset_t sSet;
int iRet;
iRet = sigemptyset(&sSet);
if (iRet == -1) {perror("ERROR installing signal handler in correlatedMovement_correlatedInTime"); exit(EXIT_FAILURE); }
iRet = sigaddset(&sSet, SIGINT);
if (iRet == -1) {perror("ERROR installing signal handler in correlatedMovement_correlatedInTime"); exit(EXIT_FAILURE); }
iRet = sigprocmask(SIG_UNBLOCK, &sSet, NULL);
if (iRet == -1) {perror("ERROR installing signal handler in correlatedMovement_correlatedInTime"); exit(EXIT_FAILURE); }
// Install mySignalHandler as the handler for CTRL-C signals.
pfRet = signal(SIGINT, mySignalHandler);
if (pfRet == SIG_ERR) {perror("error installing signal handler in correlatedMovement_correlatedInTime"); exit(EXIT_FAILURE); }
// special method selection (for slow or unconventional kernels that need to be inlined)
bool ltfast_on = false;
bool unsharp_on = false;
if (typeOfSpatialCorr == 8 && typeOfTemporalCorr == 8) {
cout << "\n***********************************\n";
cout << "* Running ltfast method *";
cout << "\n***********************************" << endl;
ltfast_on = true;
}
if (typeOfSpatialCorr == 10 && typeOfTemporalCorr == 10) {
cout << "\n************************************\n";
cout << "* Running double unsharp *";
cout << "\n************************************" << endl;
unsharp_on = true;
}
// NOTE: if you're interested, you could re-implement true top hats by inlining them here as well
// UI to avoid accidentally overwriting angle files
ifstream ifile("angleservo_cM_cIT.txt");
int overwriteFile;
if (ifile) {
cout << "WARNING: An angle file for this program already exists. 1: continue and overwrite file, 0: kill program" << endl;
cin >> overwriteFile;
if (!overwriteFile)
exit(0);
}
anglefile.open("angleservo_cM_cIT.txt", ios::out | ios::trunc); // file to plot angles in function of time
// create (bake?) Loaf object using constructor
loaf freshLoaf = loaf(numberOfSlices);
float oldslice[13][11] = {{0}}; // stores the last configuration of paddles that was sent to the grid
float step_size[13][11] = {{0}}; // stores the step size needed to get to the next configuration
float newslice[13][11] = {{0}}; // stores the step size needed to get to the next configuration
float rms;
float correction = 1;
int i = 1; // grid number counter
int SPACING = 1; // number of interpolations needed to keep servo speed under its max value, in worst case
float amplitude; // for steps/speeds calculations and safety checks, below
float diff; // difference between two doubles (used with epsilon in place of == operator, which doesn't perform well on doubles)
float EPSILON = 0.1; // error tolerance for double comparisons (just be within a tenth of a degree)
int halfLoaf = numberOfSlices / (int) 2; // determine where to set middle slice of loaf (assumes numberOfSlices is odd)
// Normalization calculations (complicated because different correlation functions have different methods for normalization)
norm = 0; // master norm parameter that's accessible/used from runcorr_3D
float bound;
if (typeOfSpatialCorr <= 4 || typeOfSpatialCorr == 10 || typeOfSpatialCorr == 0) bound = range_of_corr;
else bound = spatial_sigma;
/* Declare function pointers for the spatial correlation functions
First, we declare a pointer *pfSpatial/TemporalCorr to a function with 2 arguments j and k (or 1 argument t), plus parameters necessary for function operation (currently sigma and height, though more may need to be added if different kernels or a customizable unsharp are to be implemented).
Then we call the function pickSpatialCorr (from pickCorrelations.cpp). This function returns a pointer to the function of choice (determined by 'mode'),
which can then be used by simply calling pfSpatial/TemporalCorr(j, k). */
/* NOTE: We attempted to import sigma, alpha, and height using the pickSpatialCorr/pickTemporalCorr functions, saving them as private global variables in pickCorrelations.cpp.
This allowed us to simply call pfSpatialCorr(j, k) and pfTemporalCorr(t), removing excess arguments from the runcorr and computermscorr functions, and changing the implementation so that (except in the periodic case) the function pointers would only be created once and then would be passed to the necessary methods as arguments.
We found this method to be much cleaner, but unfortunately we introduced a bug somewhere along the line. Rather than spend days trying to track it down, we reverted to our previous version and continued taking data. It might be worth re-implementing this feature, if you have time and want to make the code more streamlined. For reference, our previous attempt should still be in a series of commits on GitHub. ~ Nathan Wei and Kevin Griffin
*/
float (*pfSpatialCorr)(int j, int k, float spatial_sigma, float spatial_alpha, float spatial_height);
float (*pfTemporalCorr)(int t, float temporal_sigma, float temporal_alpha, float temporal_height);
pfSpatialCorr = pickSpatialCorr(typeOfSpatialCorr);
pfTemporalCorr = pickTemporalCorr(typeOfTemporalCorr);
// Correlation function work for finding normalization
// Note: this is different from the previous implementation, which had mysteriously different logic for each function
for (int j = -bound; j <= bound; j++) { // range of neighbors used to compute normalization/convolution
for (int k = -bound; k <= bound; k++) { // j and k refer to the shift
//.........这里部分代码省略.........
示例9: main
//.........这里部分代码省略.........
input_db->printClassData(plog);
// Write out initial visualization data.
int iteration_num = time_integrator->getIntegratorStep();
double loop_time = time_integrator->getIntegratorTime();
if (dump_viz_data)
{
pout << "\n\nWriting visualization files...\n\n";
if (uses_visit)
{
time_integrator->setupPlotData();
visit_data_writer->writePlotData(patch_hierarchy, iteration_num, loop_time);
}
if (uses_exodus)
{
ib_post_processor->postProcessData(loop_time);
ib_pressure_processor->postProcessData(loop_time);
beam_exodus_io->write_timestep(
beam_exodus_filename, *beam_equation_systems, iteration_num / viz_dump_interval + 1, loop_time);
std::ostringstream file_name;
file_name << beam_exodus_filename +"_"
<< std::setw(6)
<< std::setfill('0')
<< std::right
<< iteration_num;
GMVIO(beam_mesh).write_equation_systems(file_name.str()+".gmv",*beam_equation_systems);
}
}
// Open streams to save lift and drag coefficients.
if (SAMRAI_MPI::getRank() == 0)
{
drag_stream.open("C_D.curve", ios_base::out | ios_base::trunc);
lift_stream.open("C_L.curve", ios_base::out | ios_base::trunc);
moment_stream.open("Moment.curve", ios_base::out | ios_base::trunc);
A_x_posn_stream.open("A_x.curve", ios_base::out | ios_base::trunc);
A_y_posn_stream.open("A_y.curve", ios_base::out | ios_base::trunc);
}
// Main time step loop.
double loop_time_end = time_integrator->getEndTime();
double dt = 0.0;
while (!MathUtilities<double>::equalEps(loop_time, loop_time_end) && time_integrator->stepsRemaining())
{
iteration_num = time_integrator->getIntegratorStep();
loop_time = time_integrator->getIntegratorTime();
pout << "\n";
pout << "+++++++++++++++++++++++++++++++++++++++++++++++++++\n";
pout << "At beginning of timestep # " << iteration_num << "\n";
pout << "Simulation time is " << loop_time << "\n";
dt = time_integrator->getMaximumTimeStepSize();
time_integrator->advanceHierarchy(dt);
loop_time += dt;
// ib_pressure_processor->postProcessData(loop_time);
pout << "\n";
pout << "At end of timestep # " << iteration_num << "\n";
pout << "Simulation time is " << loop_time << "\n";
pout << "+++++++++++++++++++++++++++++++++++++++++++++++++++\n";
pout << "\n";
// At specified intervals, write visualization and restart files,
// print out timer data, and store hierarchy data for post
示例10: openStream
void openStream(int mVideoIndex)
{
out.open(mVideoData[mVideoIndex].name + ".txt", ios::out);
}
示例11: main
// Main method
int main(int argc, char* argv[]) {
if (argc != 7) {
// Wrong number of parameters
cerr << "Wrong number of parameters!" << endl << endl;
printUsage();
return -1;
}
// Right number of parameters; parse them
string fileName = "";
int pn = 0;
int gn = 0;
int rn = 0;
int fn = 0;
int kernelType = -1;
try {
// Split arguments
fileName = argv[1];
pn = stoi(argv[2]);
gn = stoi(argv[3]);
rn = stoi(argv[4]);
fn = stoi(argv[5]);
kernelType = stoi(argv[6]);
}
catch (std::invalid_argument e) {
cerr << "Found wrong parameter!" << endl;
printUsage();
return -1;
}
catch (std::out_of_range e) {
cerr << "Found out of range parameter!" << endl;
printUsage();
return -1;
}
if (pn < 1) {
cerr << "The number of people must be positive!" << endl;
printUsage();
return -1;
}
if (gn < 1) {
cerr << "The number of gesture classes must be positive!" << endl;
printUsage();
return -1;
}
if (rn < 1) {
cerr << "The number of repetitions for each gesture must be positive!" << endl;
printUsage();
return -1;
}
if (fn < 1) {
cerr << "The number of features must be positive!" << endl;
printUsage();
return -1;
}
SVM::KernelTypes kernel;
switch (kernelType) {
case 0: kernel = SVM::KernelTypes::LINEAR; break;
case 1: kernel = SVM::KernelTypes::POLY; break;
case 2: kernel = SVM::KernelTypes::RBF; break;
case 3: kernel = SVM::KernelTypes::SIGMOID; break;
case 4: kernel = SVM::KernelTypes::CHI2; break;
case 5: kernel = SVM::KernelTypes::INTER; break;
default: cerr << "Invalid kernel type!" << endl;
printUsage();
return -1;
}
// Open log file
logFile.open(fileName + "_log.txt");
if (!logFile.is_open()) {
cerr << "Unable to create log file!" << endl;
return -1;
}
cout << "Dataset file name: " << fileName << endl;
cout << "Number of people: " << pn << endl;
cout << "Number of gesture classes: " << gn << endl;
cout << "Number of repetitions per gesture: " << rn << endl;
cout << "Number of features: " << fn << endl;
cout << "Kernel type: " << kernelType << endl;
logFile << "Dataset file name: " << fileName << endl;
logFile << "Number of people: " << pn << endl;
logFile << "Number of gesture classes: " << gn << endl;
logFile << "Number of repetitions per gesture: " << rn << endl;
logFile << "Number of features: " << fn << endl;
logFile << "Kernel type: " << kernelType << endl;
// Read dataset
Mat_<float> dataset;
bool res = readDataset(fileName, pn, gn, rn, fn, dataset);
if (!res) {
logFile.close();
return -1;
//.........这里部分代码省略.........
示例12: main
int main()
{
//Open output file
file.open("Result_ADI_Hetero_II.txt", fstream::app|fstream::out);
if (! file)
{
//if fail to open the file
cerr << "can't open output file Result_ADI_Hetero_II.txt!" << endl;
exit(EXIT_FAILURE);
}
file << setprecision(10);
cout << setprecision(10);
//--------------------------------------------------------------
// output header to screen and file
cout << "N\tL\tT\tlambda0\tlambda1\tlambda2\tK\th\tb\tCost";
file << "N\tL\tT\tlambda0\tlambda1\tlambda2\tK\th\tb\tCost";
for (int vv = 0; vv <= VMAX; vv++)
{
cout << "\t" << "s" << vv << "\t" << "S" << vv;
file << "\t" << "s" << vv << "\t" << "S" << vv;
}
cout << endl;
file << endl;
// initialize parameters
//K = 100;
//h = 1.0;
//b = 9.0;
//lambda[0] = 4;
//lambda[1] = 1;
//lambda[2] = 1;
for (lambda[0] = 0; lambda[0] <= 5; lambda[0]++)
{
lambda[1] = 1;
lambda[2] = 5 - lambda[0];
// initialize demand distributions
phi_Init();
for(K = 50; K <= 200; K *= 2)
for(h = 1; h <= 5; h += 2)
for(b = 9; b <= 29; b += 10)
{
cout << N << "\t" << L << "\t" << T << "\t" << lambda[0] << "\t" << lambda[1] << "\t" << lambda[2] << "\t" << K << "\t" << h << "\t" << b << "\t";
file << N << "\t" << L << "\t" << T << "\t" << lambda[0] << "\t" << lambda[1] << "\t" << lambda[2] << "\t" << K << "\t" << h << "\t" << b << "\t";
// initialize memory for saving the value function
for (int i = 0; i <= N; i++)
for (int j = 0; j <= UMAX; j++)
for (int k = 0; k <= VMAX; k++)
f[i][j][k] = -7;
// cost via the DP
double C1 = F(1, 0, 0);
cout << C1 << "\t";
file << C1 << "\t";
//search for optimal (s, S) in period 1
for (int j = -40; j <= 40; j++)
for (int k = 0; k <= VMAX; k++)
F(1, j, k);
for (int vv = 0; vv <= VMAX; vv++)
{
for (int uu = UMAX; uu >= 0; uu--)
{
if (Y[uu][vv] > uu - UMID)
{
S_Opt[vv] = Y[uu][vv];
s_Opt[vv] = uu - UMID;
cout << s_Opt[vv] << "\t" << S_Opt[vv] << "\t";
file << s_Opt[vv] << "\t" << S_Opt[vv] << "\t";
break;
}
}
}
cout << endl;
file << endl;
}
}
file.close();
return 0;
}
示例13: main
void main()
{
int i=0,n=0, chkstate;
Class class1;
Passed pass;
Failed fail;
clrscr();
cout<<"Enter the number of students in the class:";
cin>>n;
fout.open("class.dat", ios::binary);
for(i=1;i<=n;i++)
{
class1.accept();
fout.write((char*)&class1, sizeof(class1));
}
fout.close();
fin.open("class.dat", ios::binary);
fout_pass.open("pass.dat", ios::binary);
fout_fail.open("fail.dat", ios::binary);
while(!fin.eof())
{
fin.read((char*)&class1, sizeof(class1));
chkstate=class1.check();
if(chkstate==1)
{
writepass(class1, pass);
}
else
{
writefail(class1, fail);
}
}
fin.close();
fout_pass.close();
fout_fail.close();
fin.open("pass.dat", ios::binary);
while(!fin.eof())
{
fin.read((char*)&pass, sizeof(pass));
pass.display();
}
fin.close();
fin.open("fail.dat", ios::binary);
while(!fin.eof())
{
fin.read((char*)&fail, sizeof(fail));
fail.display();
}
}
示例14: initPlugin
void StatisticsFileWriter::initPlugin() throw() {
StatisticsFileWriterOptions & o = getOptions<StatisticsFileWriterOptions>();
file.open( o.filename );
oa = new boost::archive::text_oarchive( file, boost::archive::no_header | boost::archive::no_codecvt );
}
示例15: RunProcess
void RunProcess(void)
{
//pair-end alignment
if((!query_a_file.empty()) && (!query_b_file.empty()))
{
cout<<"Pair-end alignment:\n";
cout<<"Query: "<<query_a_file<<" "<<query_b_file<<" Reference: "<<ref_file<<" Output: "<<out_align_file<<" "<<out_align_file_unpair<<endl;
fin_a.open(query_a_file.c_str());
if(!fin_a) {
cerr<<"failed to open file: "<<query_a_file<<endl;
exit(1);
}
fin_b.open(query_b_file.c_str());
if(!fin_b) {
cerr<<"failed to open file: "<<query_b_file<<endl;
exit(1);
}
fout.open(out_align_file.c_str());
if(!fout) {
cerr<<"failed to open file: "<<out_align_file<<endl;
exit(1);
}
fout_unpair.open(out_align_file_unpair.c_str());
if(!fout_unpair) {
cerr<<"failed to open file: "<<out_align_file_unpair<<endl;
exit(1);
}
n_aligned_pairs=n_aligned_a=n_aligned_b=0;
read_a.InitialIndex();
read_b.InitialIndex();
Do_PairAlign();
fin_a.close();
fin_b.close();
fout.close();
fout_unpair.close();
cout<<"Total number of aligned reads: \n"
<<"pairs: "<<n_aligned_pairs<<" ("<<setprecision(2)<<100.0*n_aligned_pairs/read_a._index<<"%)\n"
<<"single a: "<<n_aligned_a<<" ("<<setprecision(2)<<100.0*n_aligned_a/read_a._index<<"%)\n"
<<"single b: "<<n_aligned_b<<" ("<<setprecision(2)<<100.0*n_aligned_b/read_b._index<<"%)\n";
}
//single-read alignment
else
{
if(!query_a_file.empty()) {
fin_a.open(query_a_file.c_str());
if(!fin_a) {
cerr<<"b failed to open file: "<<query_a_file<<endl;
exit(1);
}
}
else
{
cerr<<"missing query file(s)\n";
exit(1);
}
cout<<"Single read alignment:\n";
cout<<"Query: "<<query_a_file<<" Reference: "<<ref_file<<" Output: "<<out_align_file<<endl;
fout.open(out_align_file.c_str());
if(!fout) {
cerr<<"failed to open file: "<<out_align_file<<endl;
exit(1);
}
n_aligned=0;
read_a.InitialIndex();
Do_SingleAlign();
fin_a.close();
fout.close();
cout<<"Total number of aligned reads: "<<n_aligned<<" ("<<setprecision(2)
<<100.0*n_aligned/read_a._index<<"%)\n";
}
cout<<"Done.\n";
cout<<"Finished at "<<Curr_Time();
cout<<"Total time consumed: "<<Cal_AllTime()<<" secs\n";
};