本文整理汇总了C++中ofstream类的典型用法代码示例。如果您正苦于以下问题:C++ ofstream类的具体用法?C++ ofstream怎么用?C++ ofstream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ofstream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: searchForMovement
void searchForMovement(Mat thresholdImage, Mat &cameraFeed){
ofstream fil_X,fil_Xk,fil_Y,fil_Yk;
fil_X.open("X.txt", ios::app);
fil_Xk.open("Xk.txt", ios::app);
fil_Y.open("Y.txt", ios::app);
fil_Yk.open("Yk.txt", ios::app);
static unsigned int time = 0;
bool objectDetected = false;
Mat temp;
thresholdImage.copyTo(temp);
//these two vectors needed for output of findContours
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
//find contours of filtered image using openCV findContours function
//findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );// retrieves all contours
findContours(temp,contours,hierarchy,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE );// retrieves external contours
//if contours vector is not empty, we have found some objects
if(contours.size()>0)objectDetected=true;
else objectDetected = false;
if(objectDetected){
//the largest contour is found at the end of the contours vector
//we will simply assume that the biggest contour is the object we are looking for.
vector< vector<Point> > largestContourVec;
largestContourVec.push_back(contours.at(contours.size()-1));
//make a bounding rectangle around the largest contour then find its centroid
//this will be the object's final estimated position.
objectBoundingRectangle = boundingRect(largestContourVec.at(0));
int xpos = objectBoundingRectangle.x+objectBoundingRectangle.width/2;
int ypos = objectBoundingRectangle.y+objectBoundingRectangle.height/2;
//update the objects positions by changing the 'theObject' array values
theObject[0] = xpos , theObject[1] = ypos;
}
//make some temp x and y variables so we dont have to type out so much
int x = theObject[0];
int y = theObject[1];
static int flagg = 0;
if(flagg<5)
flagg=flagg+1;
if (flagg == 3)
{
Prior = (Mat_<float>(4, 1) << x, y, 0, 0);
}
float KalX; float KalY;
KalX = x;
KalY = y;
Kalman_Filter(&KalX, &KalY);
KalX = (int)KalX;
KalY = (int)KalY;
/*
fil_X <<","<< x << ", " << time;// .open("X.txt");
fil_Xk <<","<< KalX <<", "<<time;// .open("Xk.txt");
fil_Y << "," << y << ", " << time;
fil_Yk << "," << KalY << ", " << time;
time++;*/
//draw some crosshairs around the object for kalman filter
circle(cameraFeed, Point(KalX, KalY), 25, Scalar(0, 0,255), 2);
line(cameraFeed, Point(KalX, KalY), Point(KalX, KalY - 25), Scalar(0, 0, 255), 2);
line(cameraFeed, Point(KalX, KalY), Point(KalX, KalY + 25), Scalar(0, 0,255), 2);
line(cameraFeed, Point(KalX, KalY), Point(KalX - 25, KalY), Scalar(0, 0,255), 2);
line(cameraFeed, Point(KalX, KalY), Point(KalX + 25, KalY), Scalar(0, 0,255), 2);
//draw some crosshairs around the object
circle(cameraFeed,Point(x,y),20,Scalar(0,255,0),2);
line(cameraFeed,Point(x,y),Point(x,y-25),Scalar(0,255,0),2);
line(cameraFeed,Point(x,y),Point(x,y+25),Scalar(0,255,0),2);
line(cameraFeed,Point(x,y),Point(x-25,y),Scalar(0,255,0),2);
line(cameraFeed,Point(x,y),Point(x+25,y),Scalar(0,255,0),2);
//write the position of the object to the screen
//putText(cameraFeed,"Tracking object at (" + intToString(x)+","+intToString(y)+")",Point(x,y),1,1,Scalar(255,0,0),2);
//putText(cameraFeed, "Tracking object at (" + intToString(KalX) + "," + intToString(KalY) + ")", Point(KalX, KalY), 1, 1, Scalar(255, 0, 0), 2);
}
开发者ID:pruthvip,项目名称:Projects,代码行数:92,代码来源:Source.cpp
示例2: writeToFile
int pkmGaussianMixtureModel::writeToFile(ofstream &fileStream, bool writeClusterNums, bool writeWeights, bool writeMeans, bool writeCovs, bool verbose)
{
if(!fileStream.is_open())
return -1;
// use the best-model
CvEM myModel = emModel[bestModel];
const CvMat **modelCovs = myModel.get_covs();
const CvMat *modelMus = myModel.get_means();
const CvMat *modelWeights = myModel.get_weights();
int numClusters = myModel.get_nclusters();
// output the total number of clusters
if(writeClusterNums)
{
if(verbose)
fileStream << "Number of Clusters: " << numClusters << "\n";
else
fileStream << numClusters << "\n";
}
if(writeWeights)
{
// output the weights of each cluster
if(verbose)
fileStream << "Weight of Clusters\n";
for (int k = 0; k < numClusters; k++)
{
const double *weightPtr = (const double *)(modelWeights->data.ptr + k*modelWeights->step);
double weight = weightPtr[0];
if(verbose)
fileStream << k << ": " << weight << "\n";
else
fileStream << weight << " ";
}
fileStream << "\n";
}
if(writeMeans)
{
// output the means of each cluster
if(verbose)
fileStream << "Means of Clusters\n";
for (int k = 0; k < numClusters; k++)
{
if(verbose)
fileStream << "Cluster " << k << ":\n";
for (int i = 0; i < m_nVariables; i++)
{
if(verbose)
fileStream << i << ": " << cvmGet(modelMus, k, i) << " ";
else
fileStream << cvmGet(modelMus, k, i) << " ";
}
fileStream << "\n";
}
}
if(writeCovs)
{
// output the covariances of each cluster
if(verbose)
fileStream << "Covariances of Clusters\n";
for (int k = 0; k < numClusters; k++)
{
const CvMat * covar = modelCovs[k];
if(verbose)
fileStream << "Cluster " << k << ":\n";
for (int i = 0; i < m_nVariables; i++)
{
for (int j = 0; j < m_nVariables; j++)
{
if(verbose)
fileStream << i << "," << j << ": " << cvmGet(covar, i, j) << " ";
else
fileStream << cvmGet(covar, i, j) << " ";
}
}
fileStream << "\n";
}
}
return 0;
}
开发者ID:pkmital,项目名称:pkmMatrix,代码行数:83,代码来源:pkmGaussianMixtureModel.cpp
示例3: closeStreams
void closeStreams(ifstream & fin_par, ofstream & fout_par)
{
fin_par.close();
fout_par.close();
}
开发者ID:adamrooski,项目名称:CS2,代码行数:5,代码来源:CS02Lab21.cpp
示例4: writeInstance
bool nNFileWriter::writeInstance(ofstream &file, nMeshInstance *dp)
{
if(!dp)
{
nGine::instance()->getLogger()->addDebugLog("Unable to write... nothings");
return true;
}
dp->CPUload();
uint64_t flags = 0;
if(dp->getCoords(0).x != n::inf())
flags++;
flags = flags<<1;
if(!dp->getNormal(0).isNull())
flags++;
//flags = flags<<1;
file.write((const char*)&flags, 8);
uint32_t count = dp->getVertexCount();
uint32_t tCount = dp->getTriangleCount();
uint32_t mCount = dp->getMaterialCount();
file.write((const char*)&count, 4);
file.write((const char*)&tCount, 4);
file.write((const char*)&mCount, 4);
nGine::instance()->getLogger()->addDebugLog(nLogger::numToString((int)count) + " vertices, " + nLogger::numToString((int)tCount) + " triangles, " + nLogger::numToString((int)mCount) + " materials to write");
for(unsigned int i = 0; i != mCount; i++)
{
float nid = (float)((uint16_t)-1);
nMaterial *mat = dp->getMaterial(i);
char shininess = mat->getShininess();
uint16_t blend = mat->getBlendFactor() * (double)nid;
file.write((char*)&shininess, 1);
file.write((char*)&blend, 2);
float dat[] = {mat->getDiffuseColor().x, mat->getDiffuseColor().y, mat->getDiffuseColor().z, mat->getAmbientColor().x, mat->getAmbientColor().y, mat->getAmbientColor().z, mat->getSpecularColor().x, mat->getSpecularColor().y, mat->getSpecularColor().z};
for(unsigned int j = 0; j != 9; j++)
{
uint16_t d = (uint16_t)(dat[j] * nid);
file.write((const char*)&d, 2);
}
for(unsigned int j = 0; j != 4; j++)
if(!mat->getTexture((nMaterial::nTextureRole)j))
file.write("\0", 1);
else
{
string tName = mat->getTexture((nMaterial::nTextureRole)j)->getName();
if(tName.length() > nGine::instance()->appPath().length() && tName.substr(0, nGine::instance()->appPath().length()) == nGine::instance()->appPath())
tName = tName.substr(nGine::instance()->appPath().length());
if(tName.length() > nGine::instance()->getRessourcesManager()->getTextureManager()->getTextureDir().length() && tName.substr(0, nGine::instance()->getRessourcesManager()->getTextureManager()->getTextureDir().length()) == nGine::instance()->getRessourcesManager()->getTextureManager()->getTextureDir())
tName = tName.substr(nGine::instance()->getRessourcesManager()->getTextureManager()->getTextureDir().length());
char l = tName.length();
file.write(&l, 1);
file<<tName;
}
}
for(unsigned int i = 0; i != count; i++)
{
float X = dp->getPosition(i).x;
float Y = dp->getPosition(i).y;
float Z = dp->getPosition(i).z;
uint32_t *x = (uint32_t*)&X;
uint32_t *y = (uint32_t*)&Y;
uint32_t *z = (uint32_t*)&Z;
file.write((const char*)x, 4);
file.write((const char*)y, 4);
file.write((const char*)z, 4);
}
if(!dp->getNormal(0).isNull())
for(unsigned int i = 0; i != count; i++)
{
float X = dp->getNormal(i).x;
float Y = dp->getNormal(i).y;
float Z = dp->getNormal(i).z;
uint32_t *x = (uint32_t*)&X;
uint32_t *y = (uint32_t*)&Y;
uint32_t *z = (uint32_t*)&Z;
file.write((const char*)x, 4);
file.write((const char*)y, 4);
file.write((const char*)z, 4);
}
if(dp->getCoords(0).x != n::inf())
for(unsigned int i = 0; i != count; i++)
{
float U = dp->getCoords(i).x;
float V = dp->getCoords(i).y;
uint32_t *u = (uint32_t*)&U;
uint32_t *v = (uint32_t*)&V;
file.write((const char*)u, 4);
file.write((const char*)v, 4);
}
nMaterial *mat = 0;
uint32_t nid = (uint32_t)-1;
for(unsigned int i = 0; i != tCount; i++)
{
//.........这里部分代码省略.........
开发者ID:gan74,项目名称:nGine,代码行数:101,代码来源:nNFileWriter.cpp
示例5: main
int main(int argc, char* argv[]) {
cerr << "Score v2.5 written by Philipp Koehn" << endl
<< "Modified by Ventsislav Zhechev, Autodesk Development Sàrl" << endl
<< "scoring methods for extracted rules" << endl
;
if (argc < 4) {
cerr << "syntax: score extract lex phrase-table [--Inverse] [--Hierarchical] [--OnlyDirect] [--LogProb] [--NegLogProb] [--NoLex] [--GoodTuring] [--WordAlignment file]\n";
exit(1);
}
char* fileNameExtract = argv[1];
char* fileNameLex = argv[2];
char* fileNamePhraseTable = argv[3];
char* fileNameWordAlignment;
for(int i=4; i<argc; ++i) {
if (strcmp(argv[i],"inverse") == 0 || strcmp(argv[i],"--Inverse") == 0) {
inverseFlag = true;
cerr << "using inverse mode\n";
}
else if (strcmp(argv[i],"--Hierarchical") == 0) {
hierarchicalFlag = true;
cerr << "processing hierarchical rules\n";
}
else if (strcmp(argv[i],"--OnlyDirect") == 0) {
onlyDirectFlag = true;
cerr << "outputing in correct phrase table format (no merging with inverse)\n";
}
else if (strcmp(argv[i],"--WordAlignment") == 0) {
wordAlignmentFlag = true;
fileNameWordAlignment = argv[++i];
cerr << "outputing word alignment in file " << fileNameWordAlignment << endl;
}
else if (strcmp(argv[i],"--NoLex") == 0) {
lexFlag = false;
cerr << "not computing lexical translation score\n";
}
else if (strcmp(argv[i],"--GoodTuring") == 0) {
goodTuringFlag = true;
cerr << "using Good Turing discounting\n";
}
else if (strcmp(argv[i],"--LogProb") == 0) {
logProbFlag = true;
cerr << "using log-probabilities\n";
}
else if (strcmp(argv[i],"--NegLogProb") == 0) {
logProbFlag = true;
negLogProb = -1;
cerr << "using negative log-probabilities\n";
}
else {
cerr << "ERROR: unknown option " << argv[i] << endl;
exit(1);
}
}
// lexical translation table
if (lexFlag)
lexTable.load(fileNameLex);
// compute count of counts for Good Turing discounting
if (goodTuringFlag)
computeCountOfCounts(fileNameExtract);
// sorted phrase extraction file
Bz2LineReader extractFile(fileNameExtract);
// output file: phrase translation table
Bz2LineWriter phraseTableFile(fileNamePhraseTable);
// output word alignment file
if (!inverseFlag && wordAlignmentFlag) {
wordAlignmentFile.open(fileNameWordAlignment);
if (wordAlignmentFile.fail()) {
cerr << "ERROR: could not open word alignment file "
<< fileNameWordAlignment << endl;
exit(1);
}
}
// loop through all extracted phrase translations
int lastSource = -1;
vector< PhraseAlignment > phrasePairsWithSameF;
int i=0;
string lastLine = "";
PhraseAlignment *lastPhrasePair = NULL;
for (string line = extractFile.readLine(); !line.empty(); line = extractFile.readLine()) {
if (line.empty()) break;
if ((++i)%10000000 == 0) cerr << "[p. score:" << i << "]" << flush;
else if (i % 100000 == 0) cerr << "." << flush;
// identical to last line? just add count
if (lastSource >= 0 && line == lastLine) {
lastPhrasePair->addToCount(line);
continue;
}
lastLine = line;
// create new phrase pair
PhraseAlignment phrasePair;
//.........这里部分代码省略.........
开发者ID:svetakrasikova,项目名称:ADSKMosesTraining,代码行数:101,代码来源:score.cpp
示例6: iter
void
makeEleMuComparisonPlots (int whichobservable, int whichjet, int whichlepton)
{
//Open the file and form the name
string fileSystematics;
string suffix="/gpfs/cms/data/2011/Systematics/postApproval/";
//string suffix="/tmp/";
if (whichlepton==1) suffix=suffix+"ele/";
if (whichlepton==2) suffix=suffix+"muo/";
// setTDRStyle ();
gStyle->SetErrorX(0);
gStyle->SetPadGridX(0);
gStyle->SetPadGridY(0);
bool absoluteNormalization = true;
int lepton = 3; //1 -> electron, 2-> muon , 3 -> combined reults!
bool addLumiUncertainties = true;
double lumiError = 0.025;
int use_case = whichobservable;
int whichjet = whichjet;
string version = "_v2_32";
//string s = "/afs/infn.it/ts/user/marone/html/ZJets/FinalPlotsForAN/v41/SVDBayes/";
string s="/afs/infn.it/ts/user/marone/html/ZJets/FinalPlotsForAN/v57_3_postApproval/ele/";
// string s = "/gpfs/cms/users/schizzi/EleMuComparisonPlots/PostUnfolding/";
string eleplotpath = "/gpfs/cms/users/schizzi/Systematics/ele/";
string muoplotpath = "/gpfs/cms/users/schizzi/Systematics/muo/";
gStyle->SetOptStat (0);
TCanvas *plots = new TCanvas ("plots", "EB", 200, 100, 600, 800);
//DATA:
//string elepathFile ="/gpfs/cms/data/2011/Unfolding/testReferenceMu.root";
//string muopathFile ="/gpfs/cms/data/2011/Unfolding/testMu.root";
string elepathFile ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV57_3Sherpa.root";
string muopathFile ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV57_3.root";
if (whichlepton==2){
elepathFile ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV57_3SherpaMu.root";
muopathFile ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV57_3Mu.root";
s="/afs/infn.it/ts/user/marone/html/ZJets/FinalPlotsForAN/v57_3_postApproval/muo/";
}
//string elepathFile ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV57_3NoSQRT.root";
//string muopathFile ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV57_3NoMCToy.root";
TFile *histof = TFile::Open (elepathFile.c_str ());
histof->cd ("");
TDirectory *dir = gDirectory;
TList *mylist = (TList *) dir->GetListOfKeys ();
TIter iter (mylist);
TObject *tobj = 0;
TFile *histofmuo = TFile::Open (muopathFile.c_str ());
string stringmatch;
string systPathFile;
string systPathFileMuo;
histof->cd ("");
int i = 0; // solo di servizio quando debuggo...
while ((tobj = iter.Next ()))
{
string name = tobj->GetName ();
if (use_case == 1)
{ // Jet Multiplicity
stringmatch = "JetMultiplicityUnfolded";
systPathFile = eleplotpath + "systematicsEff_jetMult" + version + ".txt";
systPathFileMuo = muoplotpath + "systematicsEff_jetMult" + version + ".txt";
fileSystematics = suffix+"systematicsUnfMCToy_jetMult" + version + ".txt";
}
if (use_case == 2)
{ // Jet Pt
if (whichjet == 1)
{
stringmatch = "jReco_leading";
systPathFile = eleplotpath + "systematicsEff_jet1Pt" + version + ".txt";
systPathFileMuo = muoplotpath + "systematicsEff_jet1Pt" + version + ".txt";
fileSystematics = suffix+"systematicsUnfMCToy_jet1Pt" + version + ".txt";
}
if (whichjet == 2)
{
stringmatch = "jReco_subleading";
systPathFile = eleplotpath + "systematicsEff_jet2Pt" + version + ".txt";
systPathFileMuo = muoplotpath + "systematicsEff_jet2Pt" + version + ".txt";
fileSystematics = suffix+"systematicsUnfMCToy_jet2Pt" + version + ".txt";
}
if (whichjet == 3)
{
stringmatch = "jReco_subsubleading";
systPathFile = eleplotpath + "systematicsEff_jet3Pt" + version + ".txt";
systPathFileMuo = muoplotpath + "systematicsEff_jet3Pt" + version + ".txt";
fileSystematics = suffix+"systematicsUnfMCToy_jet3Pt" + version + ".txt";
//.........这里部分代码省略.........
开发者ID:cms-ts,项目名称:Histo,代码行数:101,代码来源:makeEleMuComparisonPlots.C
示例7: EditDDs
//------------------------------------------------------------------------------------
int EditDDs(void) throw(Exception)
{
try {
if(CI.Verbose) oflog << "BEGIN EditDDs()"
<< " at total time " << fixed << setprecision(3)
<< double(clock()-totaltime)/double(CLOCKS_PER_SEC) << " seconds."
<< endl;
if(!CI.OutputTDDFile.empty()) {
tddofs.open(CI.OutputTDDFile.c_str(),ios::out);
if(tddofs.is_open()) {
oflog << "Opened file " << CI.OutputTDDFile
<< " for triple difference and cycle slip output." << endl;
tddofs << "# " << Title << endl;
tddofs << "TDS site site sat sat freq iter cnt week sow "
<< "dcnt TD(m) slip(cy) frac\n";
tddofs << "SED site site sat sat freq iter cnt week sow "
<< "DDres(m) TDres(m)\n";
}
else {
oflog << "Warning - Failed to open file " << CI.OutputTDDFile << endl;
}
}
if(CI.Verbose) {
oflog << " TUR site site sat sat iter N Average StdDev SigYX"
<< " Median M-est MAD\n";
oflog << " SUR site site sat sat iter N Average StdDev SigYX"
<< " Median M-est MAD\n";
}
int i,j,k;
map<DDid,DDData>::iterator it;
// -------------------------------------------------------------------
// delete DD buffers that are too small, or that user wants to exclude
// also compute maxCount, the largest value of Count seen in all baselines
maxCount = 0;
vector<DDid> DDdelete;
for(it = DDDataMap.begin(); it != DDDataMap.end(); it++) {
// is it too small?
if(it->second.count.size() < CI.MinDDSeg) {
DDdelete.push_back(it->first);
continue;
}
// prepare 'mark' vector
mark.assign(it->second.count.size(),1);
ngood = mark.size();
nbad = 0;
// remove points where bias had to be reset multiple times
k = EditDDResets(it->first, it->second);
if(k || ngood < CI.MinDDSeg) {
DDdelete.push_back(it->first);
continue;
}
// remove isolated points
k = EditDDIsolatedPoints(it->first, it->second);
if(k || ngood < CI.MinDDSeg) {
DDdelete.push_back(it->first);
continue;
}
// find and remove slips
if(CI.Frequency != 2) { // L1
k = EditDDSlips(it->first, it->second,1);
if(k || ngood < CI.MinDDSeg) {
DDdelete.push_back(it->first);
continue;
}
}
if(CI.Frequency != 1) { // L2
k = EditDDSlips(it->first, it->second,2);
if(k || ngood < CI.MinDDSeg) {
DDdelete.push_back(it->first);
continue;
}
}
// find and remove outliers
if(CI.Frequency != 2) { // L1
k = EditDDOutliers(it->first, it->second,1);
if(k || ngood < CI.MinDDSeg) {
DDdelete.push_back(it->first);
continue;
}
}
if(CI.Frequency != 1) { // L2
k = EditDDOutliers(it->first, it->second,2);
if(k || ngood < CI.MinDDSeg) {
DDdelete.push_back(it->first);
continue;
}
}
// output raw data with mark
//.........这里部分代码省略.........
开发者ID:ianmartin,项目名称:GPSTk,代码行数:101,代码来源:EditDDs.cpp
示例8: process_request
/* Process the requests from the clients, and return the feedback */
string process_request(char* p_cmd, int sock, int type)
{
string rt;
string rcmd; // REAL CMD
string args;
if (type == FTP_CONTROL_TYPE)
{
cout << FTP_LOG_HEAD << " Get a control cmd: " << p_cmd << ", at " << sock << endl;
int i;
for (i = 0; i<CMD_MAX_LENGTH; i++)
{
if (p_cmd[i] != ' ' && p_cmd[i] != '\0' && p_cmd[i] != '\n')
rcmd += p_cmd[i];
else
break;
}
for (int j = i+1; j<CMD_MAX_LENGTH; j++)
{
if (p_cmd[j] != '\0' && p_cmd[i] != '\n')
args += p_cmd[j];
else
break;
}
//cout << "REAL CMD:" << rcmd << ", args:" << args << endl;
if (rcmd == FTP_CMD_USER)
{
/* Request a password */
rt = FTP_RSP_R_PASS;
strcpy(clients[sock].user, rcmd.c_str());
}
else if (rcmd == FTP_CMD_PASS)
{
/* Get the user, then match them. */
/* In the future, this should be put into the database. */
if (args == "super123")
{
clients[sock].is_logged = true;
clients[sock].set_password(args.c_str());
rt = FTP_RSP_P_PASS;
}
else
rt = FTP_RSP_E_PASS;
}
else if (rcmd == FTP_CMD_LIST)
{
if (clients[sock].is_logged)
{
rt = FTP_RSP_LIST;
DIR* dir;
struct dirent* ptr;
dir = opendir(FTP_DIR);
while ((ptr = readdir(dir)) != NULL)
{
/* Strcmp will return a true value while dismatching. */
#ifdef __linux
if (!strcmp(ptr->d_name, "."))
continue;
else if (!strcmp(ptr->d_name, ".."))
continue;
struct stat file_stat;
string file_path(FTP_DIR);
file_path += ptr->d_name;
stat(file_path.c_str(), &file_stat);
rt += ptr->d_type;
rt += " ";
rt += ptr->d_name;
string temp;
temp += ptr->d_type;
temp += " ";
temp += ptr->d_name;
// TODO-- This place, the file name may be greater than 50 place.
for (int pos = temp.length(); pos<40; pos++)
rt += " ";
rt += byte2std(file_stat.st_size);
rt += "\n";
#endif
}
closedir(dir);
}
else
rt = FTP_RSP_R_LOG;
}
else if (rcmd == FTP_CMD_PUT)
{
if (clients[sock].is_logged)
{
rt = FTP_RSP_RF_START;
string file_path(FTP_DIR);
file_path += args;
//strcpy(file_name[sock], args.c_str()); --real use
strcpy(file_name_temp, args.c_str());
//ofs[sock].open(file_path.c_str(), ios::binary);
ofs_temp.open(file_path.c_str(), ios::binary);
}
else
rt = FTP_RSP_R_LOG;
}
else if (rcmd == FTP_CMD_GET)
{
//.........这里部分代码省略.........
开发者ID:SevenHe,项目名称:Linux,代码行数:101,代码来源:old_FTPServer.cpp
示例9: main
/**
* Define an optimization problem that finds a set of muscle controls to maximize
* the forward velocity of the forearm/hand segment mass center.
*/
int main()
{
try {
std::clock_t startTime = std::clock();
// Ensures all components are printed out to the model file.
Object::setSerializeAllDefaults(true);
// Create a new OpenSim model from file
Model osimModel("jumper10dof24musc_withArms.osim");
// The number of parameters is the number of actuators
const Set<Actuator> &actuatorSet = osimModel.getActuators();
int numActuators = actuatorSet.getSize();
optLog << "numActuators = " << numActuators << endl;
int numParameters = numActuators;
/* Define initial values for controllerParameters. Each controller has two parameters, an
initial time, and a duration for bang-bang control. There are as many controls as
there are actuators because we assume symmetry (but each controller has two parameters).
controllerParameters = [ti_0 duration_0 ti_1 duration_1 ... ]' */
// initialize controller parameters
Vector controllerParameters(numParameters, 0.05);
// initialize initial times for each excitation
controllerParameters[0] = 0.107863; //hamstrings
controllerParameters[2] = 0.00069462; //bifmesh
controllerParameters[4] = 0.296889; //glut_max
controllerParameters[6] = 0.0533121; //iliopsoas
controllerParameters[8] = 0.166427; //rect_fem
controllerParameters[10] = 0.277592; //vasti
controllerParameters[12] = 0.344144; //gastroc
controllerParameters[14] = 0.315376; //soleus
controllerParameters[16] = 0.0857591; //tib_ant
controllerParameters[18] = 0.149644; //ercspn
controllerParameters[20] = 0.468741; //intobl
controllerParameters[22] = 0.455184; //extobl
controllerParameters[24] = 0.2; //arm_flex
// initialize durations
controllerParameters[1] = 0.429072; //hamstrings
controllerParameters[3] = 0.120626; //bifemsh
controllerParameters[5] = 0.39246; //glut_max
controllerParameters[7] = 0.0303192; //iliopsoas
controllerParameters[9] = 0.370385; //rect_fem
controllerParameters[11] = 0.3; //vasti
controllerParameters[13] = 0.343613; //gastroc
controllerParameters[15] = 0.350808; //soleus
controllerParameters[17] = 0.0277077; //tib_ant
controllerParameters[19] = 0.243332; //ercspn
controllerParameters[21] = 0.160016; //intobl
controllerParameters[23] = 0.15192; //extobl
controllerParameters[25] = 0.01; //arm_flex
// Add prescribed controllers to each muscle. Need to only loop numActuators/2 times since we are enforcing symmetry.
// It is assumed that all actuators are listed for one side of the model first, then the other side, in the same order.
for(int i=0; i < numActuators/2; i++) {
// make a piecewise constant function for both sides
PiecewiseConstantFunction bangBangControl;
bangBangControl.addPoint(initialTime,0);
bangBangControl.addPoint(controllerParameters[2*i],1);
bangBangControl.addPoint(controllerParameters[2*i]+controllerParameters[2*i+1],0);
// add controller to right side
PrescribedController *actuatorController_r = new PrescribedController();
Set<Actuator> actuator_r;
actuator_r.insert(0,osimModel.getActuators().get(i));
actuatorController_r->setName(actuatorSet.get(i).getName());
actuatorController_r->setActuators(*actuator_r.clone());
actuatorController_r->prescribeControlForActuator(osimModel.getActuators().get(i).getName(), bangBangControl.clone());
osimModel.addController(actuatorController_r);
// add controller to left side
PrescribedController *actuatorController_l = new PrescribedController();
Set<Actuator> actuator_l;
actuator_l.insert(0,osimModel.getActuators().get(i + numActuators/2));
actuatorController_l->setName(actuatorSet.get(i + numActuators/2).getName());
actuatorController_l->setActuators(*actuator_l.clone());
actuatorController_l->prescribeControlForActuator(osimModel.getActuators().get(i + numActuators/2).getName(), bangBangControl.clone());
osimModel.addController(actuatorController_l);
}
// Create the OptimizationSystem. Initialize the objective function value "f".
JumpingOptimizationSystem sys(numParameters, osimModel);
Real f = NaN;
// Set lower and upper bounds.
Vector lower_bounds(numParameters, initialTime);
Vector upper_bounds(numParameters, finalTime);
// Limit the duration of the "bang" to be at least a certain value
for (int i = 1; i<numParameters; i+=2) {
lower_bounds[i] = 0.0001;
}
//.........这里部分代码省略.........
开发者ID:mitkof6,项目名称:skyjump,代码行数:101,代码来源:JumpingOptimizationWithArms.cpp
示例10: Print
void Print(const Graph& mGraph, const vector<Graph::Primitive*>& mPrimitives)
{
#ifdef EXTRACT_PRIMITIVES
Vec2 v0, v1;
double x0, y0, x1, y1;
int j0, j1, index;
const int numPrimitives = (int)mPrimitives.size();
int i;
for (i = 0; i < numPrimitives; ++i)
{
Graph::Primitive* primitive = mPrimitives[i];
int numElements = (int)primitive->Sequence.size();
switch (primitive->Type)
{
case Graph::PT_ISOLATED_VERTEX:
v0 = primitive->Sequence[0].first;
x0 = v0.X();
y0 = v0.Y();
index = primitive->Sequence[0].second;
fout.open("./isolated_vert_PlanarGraph.txt",ios::out|ios::app);
fout<<index+1<<" ";
fout.close();
//SetThickPixel(x0, y0, 1, mColors[i]);
break;
case Graph::PT_FILAMENT:
for (j0 = 0, j1 = 1; j1 < numElements; ++j0, ++j1)
{
v0 = primitive->Sequence[j0].first;
x0 = (int)v0.X();
y0 = (int)v0.Y();
v1 = primitive->Sequence[j1].first;
x1 = (int)v1.X();
y1 = (int)v1.Y();
int index2 = primitive->Sequence[j1].second;
fout.open("./Filaments_PlanarGraph.txt",ios::out|ios::app);
if (j0==0)
{
int index1 = primitive->Sequence[j0].second;
fout<<index1+1<<" "<<index2+1<<" ";
} //DrawLine(x0, y0, x1, y1, mColors[i]);
else
{
fout<<index2+1<<" ";
};
}
fout<<endl;
fout.close();
break;
case Graph::PT_MINIMAL_CYCLE:
// if (fout.is_open())
{
//cout<<"File is open\n";
//fout << numElements<<"\n";
//cout << "Number of points in the cycle: "<<numElements<<"\n";
fout.open("./Cycles_PlanarGraph.txt",ios::out|ios::app);
for (j0 = numElements - 1, j1 = 0; j1 < numElements; j0 = j1++)
{
v0 = primitive->Sequence[j0].first;
x0 = (int)v0.X();
y0 = (int)v0.Y();
v1 = primitive->Sequence[j1].first;
x1 = (int)v1.X();
y1 = (int)v1.Y();
index = primitive->Sequence[j0].second;
fout<<index+1<<" ";
// cout<<index+1<<" ";
//DrawLine(x0, y0, x1, y1, mColors[i]);
}
fout<<endl;
// cout<<endl;
fout.close();
break;
}
}
}
#endif
}
开发者ID:mosquitoboat,项目名称:forceTile,代码行数:93,代码来源:mcb.cpp
示例11: fini_stride
/* finishing... */
VOID fini_stride(INT32 code, VOID* v){
int i;
UINT64 cum;
if(interval_size == -1){
output_file_stride.open("stride_full_int_pin.out", ios::out|ios::trunc);
}
else{
output_file_stride.open("stride_phases_int_pin.out", ios::out|ios::app);
}
output_file_stride << numReadInstrsAnalyzed;
/* local read distribution */
cum = 0;
for(i = 0; i < MAX_DISTR; i++){
cum += localReadDistrib[i];
if( (i == 0) || (i == 8) || (i == 64) || (i == 512) || (i == 4096) || (i == 32768) || (i == 262144) ){
if(cum > 0)
output_file_stride << " " << cum;
else
output_file_stride << " 0";
}
if(i == 262144)
break;
}
/* global read distribution */
cum = 0;
for(i = 0; i < MAX_DISTR; i++){
cum += globalReadDistrib[i];
if( (i == 0) || (i == 8) || (i == 64) || (i == 512) || (i == 4096) || (i == 32768) || (i == 262144) ){
if(cum > 0)
output_file_stride << " " << cum;
else
output_file_stride << " 0";
}
if(i == 262144)
break;
}
output_file_stride << " " << numWriteInstrsAnalyzed;
/* local write distribution */
cum = 0;
for(i = 0; i < MAX_DISTR; i++){
cum += localWriteDistrib[i];
if( (i == 0) || (i == 8) || (i == 64) || (i == 512) || (i == 4096) || (i == 32768) || (i == 262144) ){
if(cum > 0)
output_file_stride << " " << cum;
else
output_file_stride << " 0";
}
if(i == 262144)
break;
}
/* global write distribution */
cum = 0;
for(i = 0; i < MAX_DISTR; i++){
cum += globalWriteDistrib[i];
if( (i == 0) || (i == 8) || (i == 64) || (i == 512) || (i == 4096) || (i == 32768) ){
if(cum > 0)
output_file_stride << " " << cum;
else
output_file_stride << " 0";
}
if(i == 262144){
if(cum > 0)
output_file_stride << " " << cum << endl;
else
output_file_stride << " 0" << endl;
break;
}
}
output_file_stride << "number of instructions: " << total_ins_count_for_hpc_alignment << endl;
output_file_stride.close();
}
开发者ID:itkovian,项目名称:MICA,代码行数:75,代码来源:mica_stride.cpp
示例12: TraceInit
bool TraceInit(const char* filename)
{
traceFile.open(filename);
return traceFile.is_open();
}
开发者ID:arlesfarias,项目名称:Project_M,代码行数:5,代码来源:Error.cpp
示例13: TraceClose
void TraceClose()
{
traceFile.close();
}
开发者ID:arlesfarias,项目名称:Project_M,代码行数:4,代码来源:Error.cpp
示例14:
extern "C" __declspec( dllexport ) void Init2()
{
outfile.open("dynamic_secondary_dll.out");
outfile << hex << showbase;
}
开发者ID:FengXingYuXin,项目名称:SHMA,代码行数:5,代码来源:dynamic_secondary_dll.cpp
示例15: parseCommandLine_format
int parseCommandLine_format(int argc, char *argv[])
{
int index, c;
static struct option longOptions[] =
{
{"file", required_argument, 0, 'f' },
{"out", required_argument, 0, 'o' },
{"lineWidth", required_argument, 0, 'w' },
{"minLen", required_argument, 0, 'm' },
{"maxLen", required_argument, 0, 'M' },
{"fastq", no_argument, 0, 'q' },
{"filterN", no_argument, 0, 'n' },
{"noComment", no_argument, 0, 'c' },
{"pacbio", no_argument, 0, 'p' },
{"help", no_argument, 0, 'h' },
{"version", no_argument, 0, 'v' },
{0,0,0,0}
};
while ( (c = getopt_long ( argc, argv, "f:o:w:m:M:qncphv", longOptions, &index))!= -1 )
{
switch (c)
{
case 'f':
_format_IN_FILE = optarg;
break;
case 'o':
_format_OUT_FILE = optarg;
break;
case 'w':
_format_LINE_WIDTH = str2type<int>(optarg);
break;
case 'm':
_format_MIN_LEN = str2type<long long>(optarg);
break;
case 'M':
_format_MAX_LEN = str2type<long long>(optarg);
break;
case 'q':
_format_isFastq = true;
break;
case 'n':
_format_filterN = true;
break;
case 'c':
_format_noComment = false;
break;
case 'p':
_format_pacbio = true;
break;
case 'h':
printHelp_format();
return 0;
break;
case 'v':
cout << "Version: " << FASTUTILS_VERSION << endl;
cout << "Build Date: " << BUILD_DATE << endl;
return 0;
break;
default:
cerr << "[ERROR] run \"fastUtils shuffle -h\" to get a list of acceptable arguments." << endl;
cerr << endl;
return 0;
}
}
if(_format_IN_FILE == "")
{
cerr << endl;
cerr<< "[ERROR] option -f is required" << endl;
cerr << endl;
return 0;
}
if(_format_LINE_WIDTH < 0)
_format_LINE_WIDTH = 0;
if(_format_MIN_LEN < 0)
_format_MIN_LEN = 0;
if(_format_MAX_LEN < 0)
_format_MAX_LEN = LLONG_MAX;
if(_format_MIN_LEN > _format_MAX_LEN)
{
cerr << endl;
cerr<< "[ERROR] minLen cannot be greater than maxLen" << endl;
cerr << endl;
return 0;
}
if(_format_OUT_FILE == "")
{
_format_pout = &cout;
}
else
{
_format_fout.open(_format_OUT_FILE.c_str());
if(_format_fout.is_open()==false)
{
cerr<< "[ERROR] could not open file: " << _format_OUT_FILE << endl;
return 0;
}
//.........这里部分代码省略.........
开发者ID:sfu-compbio,项目名称:utils,代码行数:101,代码来源:format.cpp
示例16: main
int main(int argc, char* argv[])
{
//At start state all spins =+1, in case we want random start uncomment random.
char *outfilename;
long idum;
int **spin_matrix, n_spins, mcs, flips;
double w[17], average[5], initial_temp, final_temp, E, M, temp_step;
// Read in output file, abort if there are too few command-line arguments
if( argc <= 1 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Read in initial values such as size of lattice, temp and cycles
read_input(n_spins, mcs, initial_temp, final_temp, temp_step);
spin_matrix = (int**) matrix(n_spins, n_spins, sizeof(int));
idum = -1; // random starting point<<{this is used to initialize the method ran1 found in lib.cpp}
for ( double temperature = initial_temp; temperature <= final_temp; temperature+=temp_step){
flips=0;
// setup array for possible energy changes
for( int de =-8; de <= 8; de++) w[de+8] = 0;
for( int de =-8; de <= 8; de+=4) w[de+8] = exp(-de/temperature);
// initialise array for expectation values
for( int i = 0; i < 5;i++) average[i] = 0.;//{it is used to stor the following values E,E^2, M,M^2, |M|,flips}
//the initialization calculate E and M we start with giving a start temperature and the size of the grid.
//we send the info n_spins, temp, the spin:matrix and the adresse of E and M to updated the initial
//values of the E & M of the system.
if(temperature == initial_temp)
{
// initialise energy and magnetization
E = M = 0.;
initialize(n_spins, temperature, spin_matrix, E, M);
}
// start Monte Carlo computation
//int cycles ;
for (int cycles = 1; cycles <= mcs; cycles++)
{
Metropolis(n_spins, idum, spin_matrix, E, M, w, flips);
// update expectation values
//NB:for each Metro cycle we get a possible state, note the temp is unchanged so those are just possible states
//for the one giving temp. The simulation should bring the system to the most possible
// E and M giving spesified temperature as it stablise.
average[0] += E; average[1] += E*E;
average[2] += M; average[3] += M*M; average[4] += fabs(M);
//output(n_spins, cycles, temperature ,average, flips,E); //this line is used in case we want to store the averages as function of mcs
}
// print results
cout << "Your flips prosent is "<< (double)flips/n_spins/n_spins/mcs <<"\n";
output(n_spins, mcs, temperature,average, flips,E);//This line in case u want to save the data as function of tempirature
}
free_matrix((void **) spin_matrix); // free memory
ofile.close(); // close output file
return 0;
}
开发者ID:muniry2015,项目名称:Fys3150,代码行数:66,代码来源:main.cpp
|
请发表评论