本文整理汇总了C++中ifstream类的典型用法代码示例。如果您正苦于以下问题:C++ ifstream类的具体用法?C++ ifstream怎么用?C++ ifstream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ifstream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getline
bool CLevel::LoadVersion1( ifstream& File ) {
bool StopReadingFile = false;
filebuf *pbuf = File.rdbuf();
// go to the beginning
pbuf->pubseekpos (0,ios::in);
// For each line of characters to read
for (int y = 0 ; y < ARENA_HEIGHT ; y++)
{
// Buffer where we'll store one line of characters. We'll read the two EOL characters as well.
string Line;
int ReadBytes;
// Read one line of characters (including the EOL chars)
if (File.good())
{
getline( File, Line );
ReadBytes = Line.size();
}
else
{
ReadBytes = 0;
}
// Check if all the characters were read
if (ReadBytes < ARENA_WIDTH)
{
// Log there is a problem
theLog.WriteLine ("Options => !!! Level file is incorrect (Line: %d, Length: %d).", y+1, ReadBytes);
// Close the level file
File.close();
// Stop loading levels
StopReadingFile = true;
break;
}
// For each character representing a block in this line
for (int x = 0 ; x < ARENA_WIDTH ; x++)
{
// According to the character value, store the corresponding block type in the current position and level
switch(Line.c_str()[x])
{
case '*' : m_ArenaData[x][y] = BLOCKTYPE_HARDWALL; break;
case '-' : m_ArenaData[x][y] = BLOCKTYPE_RANDOM; break;
case ' ' : m_ArenaData[x][y] = BLOCKTYPE_FREE; break;
case '1' : m_ArenaData[x][y] = BLOCKTYPE_WHITEBOMBER; break;
case '2' : m_ArenaData[x][y] = BLOCKTYPE_BLACKBOMBER; break;
case '3' : m_ArenaData[x][y] = BLOCKTYPE_REDBOMBER; break;
case '4' : m_ArenaData[x][y] = BLOCKTYPE_BLUEBOMBER; break;
case '5' : m_ArenaData[x][y] = BLOCKTYPE_GREENBOMBER; break;
case 'R' : m_ArenaData[x][y] = BLOCKTYPE_MOVEBOMB_RIGHT; break;
case 'D' : m_ArenaData[x][y] = BLOCKTYPE_MOVEBOMB_DOWN; break;
case 'L' : m_ArenaData[x][y] = BLOCKTYPE_MOVEBOMB_LEFT; break;
case 'U' : m_ArenaData[x][y] = BLOCKTYPE_MOVEBOMB_UP; break;
default :
{
// Log there is a problem
theLog.WriteLine ("Options => !!! Level file is incorrect (unknown character %c).", Line[x]);
// Close the level file
File.close();
// Stop loading levels
StopReadingFile = true;
break;
}
}
}
// If there was a problem
if (StopReadingFile)
{
// Stop reading this level file
break;
}
}
m_NumberOfItemsInWalls[ITEM_BOMB] = INITIAL_ITEMBOMB;
m_NumberOfItemsInWalls[ITEM_FLAME] = INITIAL_ITEMFLAME;
m_NumberOfItemsInWalls[ITEM_KICK] = INITIAL_ITEMKICK;
m_NumberOfItemsInWalls[ITEM_ROLLER] = INITIAL_ITEMROLLER;
m_NumberOfItemsInWalls[ITEM_SKULL] = INITIAL_ITEMSKULL;
m_NumberOfItemsInWalls[ITEM_THROW] = INITIAL_ITEMTHROW;
m_NumberOfItemsInWalls[ITEM_PUNCH] = INITIAL_ITEMPUNCH;
m_NumberOfItemsInWalls[ITEM_REMOTE] = INITIAL_ITEMREMOTE;
m_InitialBomberSkills[ BOMBERSKILL_FLAME ] = INITIAL_FLAMESIZE;
m_InitialBomberSkills[ BOMBERSKILL_BOMBS ] = INITIAL_BOMBS;
m_InitialBomberSkills[ BOMBERSKILL_BOMBITEMS ] = 0;
m_InitialBomberSkills[ BOMBERSKILL_FLAMEITEMS ] = 0;
m_InitialBomberSkills[ BOMBERSKILL_ROLLERITEMS ] = 0;
m_InitialBomberSkills[ BOMBERSKILL_KICKITEMS ] = 0;
m_InitialBomberSkills[ BOMBERSKILL_THROWITEMS ] = 0;
m_InitialBomberSkills[ BOMBERSKILL_PUNCHITEMS ] = 0;
m_InitialBomberSkills[ BOMBERSKILL_REMOTEITEMS ] = 0;
//.........这里部分代码省略.........
示例2: operator
void operator ()(ifstream& f)
{
if (!f.is_open()) {
throw contract_exception();
}
}
示例3: parsefile
void parsefile(ifstream &file, ifstream &file2, ifstream &file3,ifstream &file4, ifstream &file5){
for (int i=0; i<600; i++) {
for(int j=0; j<600; j++){
zbuffer[i][j] = std::numeric_limits<int>::min();
}
}
double Ax;
double Ay;
double Az;
double Atexturex;
double Atexturey;
double Avecteurx;
double Avecteury;
double Avecteurz;
double Bx;
double By;
double Bz;
double Btexturex;
double Btexturey;
double Bvecteurx;
double Bvecteury;
double Bvecteurz;
double Cx;
double Cy;
double Cz;
double Ctexturex;
double Ctexturey;
double Cvecteurx;
double Cvecteury;
double Cvecteurz;
file.open("african_head.obj");
file2.open("african_head.obj");
file3.open("african_head.obj");
file4.open("african_head.obj");
getLineCoordV(file);
getLineCoordVt(file3);
getLineCoordVn(file4);
int nombre1;
int nombre2;
int nombre3;
int nombre1vt;
int nombre2vt;
int nombre3vt;
int nombre1vn;
int nombre2vn;
int nombre3vn;
std::string myString;
while (!file2.eof())
{
getline(file2, myString);
if ((myString[0] == 'f') && (myString[1] == ' ')) {
myString.erase(myString.begin(),myString.begin()+2);
int i = 0;
while (myString[i] == ' ') {
i++;
}
while (myString[i] != '/') {
char c = myString[i];
// PREMIER SOMMET
sommet1.push_back(c);
i++;
}
i++;
while (myString[i] != '/') {
char c = myString[i];
// Texture PREMIER SOMMET
couleursommet1.push_back(c);
i++;
}
i++;
while (myString[i] != ' ') {
char c = myString[i];
// Vecteur PREMIER SOMMET
vecteursommet1.push_back(c);
i++;
}
while (myString[i] == ' ') {
i++;
}
while (myString[i] != '/') {
char c = myString[i];
//.........这里部分代码省略.........
示例4: while
/*************************************************************************************************
map<string, int> Bayesian::parseTaxMap(string newTax) {
try{
map<string, int> parsed;
newTax = newTax.substr(0, newTax.length()-1); //get rid of last ';'
//parse taxonomy
string individual;
while (newTax.find_first_of(';') != -1) {
individual = newTax.substr(0,newTax.find_first_of(';'));
newTax = newTax.substr(newTax.find_first_of(';')+1, newTax.length());
parsed[individual] = 1;
}
//get last one
parsed[newTax] = 1;
return parsed;
}
catch(exception& e) {
m->errorOut(e, "Bayesian", "parseTax");
exit(1);
}
}
**************************************************************************************************/
void Bayesian::readProbFile(ifstream& in, ifstream& inNum, string inName, string inNumName) {
try{
#ifdef USE_MPI
int pid, num, num2, processors;
vector<unsigned long long> positions;
vector<unsigned long long> positions2;
MPI_Status status;
MPI_File inMPI;
MPI_File inMPI2;
MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
MPI_Comm_size(MPI_COMM_WORLD, &processors);
int tag = 2001;
char inFileName[1024];
strcpy(inFileName, inNumName.c_str());
char inFileName2[1024];
strcpy(inFileName2, inName.c_str());
MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
MPI_File_open(MPI_COMM_WORLD, inFileName2, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI2); //comm, filename, mode, info, filepointer
if (pid == 0) {
positions = m->setFilePosEachLine(inNumName, num);
positions2 = m->setFilePosEachLine(inName, num2);
for(int i = 1; i < processors; i++) {
MPI_Send(&num, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
MPI_Send(&positions[0], (num+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
MPI_Send(&num2, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
MPI_Send(&positions2[0], (num2+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
}
}else{
MPI_Recv(&num, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
positions.resize(num+1);
MPI_Recv(&positions[0], (num+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
MPI_Recv(&num2, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
positions2.resize(num2+1);
MPI_Recv(&positions2[0], (num2+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
}
//read version
int length = positions2[1] - positions2[0];
char* buf5 = new char[length];
MPI_File_read_at(inMPI2, positions2[0], buf5, length, MPI_CHAR, &status);
delete buf5;
//read numKmers
length = positions2[2] - positions2[1];
char* buf = new char[length];
MPI_File_read_at(inMPI2, positions2[1], buf, length, MPI_CHAR, &status);
string tempBuf = buf;
if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
delete buf;
istringstream iss (tempBuf,istringstream::in);
iss >> numKmers;
//initialze probabilities
wordGenusProb.resize(numKmers);
for (int j = 0; j < wordGenusProb.size(); j++) { wordGenusProb[j].resize(genusNodes.size()); }
//.........这里部分代码省略.........
示例5: while
/*************************************************************************************************
map<string, int> Bayesian::parseTaxMap(string newTax) {
try{
map<string, int> parsed;
newTax = newTax.substr(0, newTax.length()-1); //get rid of last ';'
//parse taxonomy
string individual;
while (newTax.find_first_of(';') != -1) {
individual = newTax.substr(0,newTax.find_first_of(';'));
newTax = newTax.substr(newTax.find_first_of(';')+1, newTax.length());
parsed[individual] = 1;
}
//get last one
parsed[newTax] = 1;
return parsed;
}
catch(exception& e) {
m->errorOut(e, "Bayesian", "parseTax");
exit(1);
}
}
**************************************************************************************************/
void Bayesian::readProbFile(ifstream& in, ifstream& inNum, string inName, string inNumName) {
try {
//read version
string line = m->getline(in);
m->gobble(in);
in >> numKmers;
m->gobble(in);
//initialze probabilities
wordGenusProb.resize(numKmers);
for (int j = 0; j < wordGenusProb.size(); j++) {
wordGenusProb[j].resize(genusNodes.size());
}
int kmer, name, count;
count = 0;
vector<int> num;
num.resize(numKmers);
float prob;
vector<float> zeroCountProb;
zeroCountProb.resize(numKmers);
for (int j = 0; j < numKmers; j++) {
diffPair tempDiffPair;
WordPairDiffArr.push_back(tempDiffPair);
}
//read version
string line2 = m->getline(inNum);
m->gobble(inNum);
float probTemp;
while (inNum) {
inNum >> zeroCountProb[count] >> num[count] >> probTemp;
WordPairDiffArr[count].prob = probTemp;
count++;
m->gobble(inNum);
}
inNum.close();
while(in) {
in >> kmer;
//set them all to zero value
for (int i = 0; i < genusNodes.size(); i++) {
wordGenusProb[kmer][i] = log(zeroCountProb[kmer] / (float) (genusTotals[i]+1));
}
//get probs for nonzero values
for (int i = 0; i < num[kmer]; i++) {
in >> name >> prob;
wordGenusProb[kmer][name] = prob;
}
m->gobble(in);
}
in.close();
}
catch(exception& e) {
m->errorOut(e, "Bayesian", "readProbFile");
exit(1);
}
}
示例6: checkReleaseDate
bool Bayesian::checkReleaseDate(ifstream& file1, ifstream& file2, ifstream& file3, ifstream& file4) {
try {
bool good = true;
vector<string> lines;
lines.push_back(m->getline(file1));
lines.push_back(m->getline(file2));
lines.push_back(m->getline(file3));
lines.push_back(m->getline(file4));
//before we added this check
if ((lines[0][0] != '#') || (lines[1][0] != '#') || (lines[2][0] != '#') || (lines[3][0] != '#')) {
good = false;
}
else {
//rip off #
for (int i = 0; i < lines.size(); i++) {
lines[i] = lines[i].substr(1);
}
//get mothurs current version
string version = m->getVersion();
vector<string> versionVector;
m->splitAtChar(version, versionVector, '.');
//check each files version
for (int i = 0; i < lines.size(); i++) {
vector<string> linesVector;
m->splitAtChar(lines[i], linesVector, '.');
if (versionVector.size() != linesVector.size()) {
good = false;
break;
}
else {
for (int j = 0; j < versionVector.size(); j++) {
int num1, num2;
convert(versionVector[j], num1);
convert(linesVector[j], num2);
//if mothurs version is newer than this files version, then we want to remake it
if (num1 > num2) {
good = false;
break;
}
}
}
if (!good) {
break;
}
}
}
if (!good) {
file1.close();
file2.close();
file3.close();
file4.close();
}
else {
file1.seekg(0);
file2.seekg(0);
file3.seekg(0);
file4.seekg(0);
}
return good;
}
catch(exception& e) {
m->errorOut(e, "Bayesian", "checkReleaseDate");
exit(1);
}
}
示例7: processPrimitivesWFN
/* ********************************************************************************************* */
void processPrimitivesWFN(ifstream &ifil,const int npr,int* &pricen,int* &primty,solreal* &prexp)
{
alloc1DIntArray("pricen",npr,pricen);
alloc1DIntArray("primty",npr,primty);
alloc1DRealArray("prexp",npr,prexp);
int count=0;
int pos;
/* Getting the primitive centers */
pos=ifil.tellg();
ifil.seekg(pos+20);
for (int i=0; i<npr; i++) {
ifil >> pricen[i];
pricen[i]--;
count++;
if (count==20) {
pos=ifil.tellg();
ifil.seekg(pos+20);
count=0;
}
//cout << pricen[i] << " ";
}
if ((npr%20)==0) {
pos=ifil.tellg();
ifil.seekg(pos-20);
}
/* Getting the primitive types */
pos=ifil.tellg();
ifil.seekg(pos+20);
count=0;
for (int i=0; i<npr; i++) {
ifil >> primty[i];
primty[i]--;
count++;
if (count==20) {
pos=ifil.tellg();
ifil.seekg(pos+20);
count=0;
}
//cout << primty[i] << " ";
}
if ((npr%20)==0) {
pos=ifil.tellg();
ifil.seekg(pos-20);
}
/* Getting the primitive exponents */
string line;
int nolines;
nolines=floor(npr/5);
if ((npr%5)>0) {nolines++;}
count=0;
for (int i=0; i<nolines; i++) {
pos=ifil.tellg();
getline(ifil,line);
if (line.length()==0) {getline(ifil,line); pos++;}
line.erase(0,10);
for (int j=0; j<5; j++) {
if (count<npr) {
if ((line[10]=='D')||(line[10]=='d')) {
line[10]='e';
}
prexp[count]=(solreal)atof((line.substr(0,14)).c_str());
count++;
line.erase(0,14);
}
}
}
}
示例8: unserialize
bool Entity_CollisionType_Puzzle_Barrier::unserialize(ifstream& file)
{
if(!file.is_open()) return false;
int Entity_CollisionType_Puzzle_Barrier_version;
file.read((char*) &Entity_CollisionType_Puzzle_Barrier_version, sizeof(int));
if(Entity_CollisionType_Puzzle_Barrier_version==1){
file.read((char*) &x, sizeof(x));
file.read((char*) &y, sizeof(y));
file.read((char*) &w, sizeof(w));
file.read((char*) &h, sizeof(h));
bounds.x = x-(w/2);
bounds.y = y-(h/2);
bounds.w = w;
bounds.h = h;
return true;
}
else if(Entity_CollisionType_Puzzle_Barrier_version==2){
file.read((char*) &x, sizeof(x));
file.read((char*) &y, sizeof(y));
file.read((char*) &w, sizeof(w));
file.read((char*) &h, sizeof(h));
file.read((char*) &tied_respawn_zone_index, sizeof(tied_respawn_zone_index));
bounds.x = x-(w/2);
bounds.y = y-(h/2);
bounds.w = w;
bounds.h = h;
return true;
}
else if(Entity_CollisionType_Puzzle_Barrier_version==3){
file.read((char*) &x, sizeof(x));
file.read((char*) &y, sizeof(y));
file.read((char*) &w, sizeof(w));
file.read((char*) &h, sizeof(h));
file.read((char*) &tied_respawn_zone_index, sizeof(tied_respawn_zone_index));
file.read((char*) &index, sizeof(index));
bounds.x = x-(w/2);
bounds.y = y-(h/2);
bounds.w = w;
bounds.h = h;
return true;
}
else return false;
}
示例9: initFromFileForMicroFluidic
void CellPositionInitialiser::initFromFileForMicroFluidic(Agent *ag, ifstream& input, ifstream& geo) {
cerr << "# starting all cells at a position based on a microfluidic file (initFromFileForMicroFluidic) " << endl;
//go to the beginning of the file
input.seekg(0,ios::beg);
geo.seekg(0,ios::beg);
// some local variables.
string line = "";
istringstream iss;
string line2 = "";
istringstream iss2;
string from = ",";
string to = " ";
size_t lookHere;
size_t foundHere;
int voxel_index = 0;
int num_cells = 0;
int value = 0;
vector<double> coordinate(3);
// get the database of the agent
Database *db = ag->getDatabase();
// get cell_positions
TVectorData<TVectorData<double>* > *cell_positions =
(TVectorData<TVectorData<double>* >*) db->getDataItem("cellpositions");
// get environment grid
Grid *g = (Grid *) db->getDataItem("environment");
// get cell_voxel_positions
TVectorData<int> *cell_voxel_positions = (TVectorData<int>* ) db->getDataItem("cell_voxel_positions");
// get number cells_per_voxel
TVectorData<int> *number_cells_per_voxel = (TVectorData<int>* ) db->getDataItem("number_cells_per_voxel");
number_cells_per_voxel->reserveSize(g->getNumberOfVoxels());
for (int i=0; i<g->getNumberOfVoxels(); i++)
number_cells_per_voxel->at(i) = 0;
// iterate over the input
while (getline(input,line)) {
lookHere = 0;
// remove comma delimiters and change them to empty spaces
while ((foundHere = line.find(from, lookHere)) != string::npos) {
line.replace(foundHere,from.size(),to);
lookHere = foundHere + to.size();
}
// remove comma delimiters from geometry file
getline(geo,line2);
lookHere = 0;
while ((foundHere = line2.find(from, lookHere)) != string::npos) {
line2.replace(foundHere,from.size(),to);
lookHere = foundHere + to.size();
}
iss.clear(); // cell input
iss.str(line);
iss2.clear(); // geometry input
iss2.str(line2);
while (iss2 >> value) {
iss >> num_cells;
// if we have a real voxel
if (value == 1) {
// get the center coordinate of the voxel that we currently are dealing with
g->getCenterOfVoxel(voxel_index++, coordinate);
// add cells to the system
for (int i=0; i<num_cells; i++) {
// add a position to the cell positions vector
TVectorData<double> *pos = new TVectorData<double>("position", "tvectordata_double");
pos->reserveSize(3);
pos->at(0) = coordinate[0]; pos->at(1) = coordinate[1]; pos->at(2) = coordinate[2];
cell_positions->addElementToEnd(pos);
// add an entry to the cell_voxel_positions vector
cell_voxel_positions->addElementToEnd(voxel_index-1);
// update number cells per voxel
number_cells_per_voxel->at(voxel_index-1) = number_cells_per_voxel->at(voxel_index-1) + 1;
}
}
}
}
// set the numberofcells to the correct value
IntegerData *nc = (IntegerData*) db->getDataItem("numberofcells");
nc->setInteger(cell_positions->size());
this->cellnumber = cell_positions->size();
// initialise all the remaining vectors
this->doTheRest(ag);
}
示例10: ifstream
int
csdb_generator::read_from (const char *srcfile)
{
inf_ = new ifstream(srcfile);
char *ptr;
while (inf_->good() && !inf_->eof()) {
linecounter_++;
switch (read_line ()) {
case -1: // bogus line
fail ("unknown field tag");
break;
case 0: // comment or blank line
break;
case 1: // start
entry_.desc_ = 0;
entry_.loc_name_ = 0;
entry_.codeset_id_ = 0;
entry_.num_sets_ = 0;
entry_.max_bytes_ = 0;
in_entry_ = 1;
break;
case 2: // end
if (entry_.codeset_id_ == 0)
fail ("entry missing rgy_value");
if (entry_.num_sets_ == 0)
fail ("entry does not include at least one char_value");
if (entry_.max_bytes_ == 0)
fail ("entry does not define max_bytes");
write_entry ();
delete [] const_cast<char *> (entry_.desc_);
delete [] const_cast<char *> (entry_.loc_name_);
count_++;
in_entry_ = 0;
break;
case 3: // description
if (entry_.desc_ != 0)
fail ("duplicate description");
entry_.desc_ = ACE_OS::strdup(line_data_);
break;
case 4: // loc_name
if (entry_.loc_name_ != 0)
fail ("duplicate loc_name");
entry_.loc_name_ = ACE_OS::strdup(line_data_);
break;
case 5: // rgy_value
if (entry_.codeset_id_ != 0)
fail ("duplicate rgy_value");
entry_.codeset_id_ = ACE_OS::strtoul(line_data_,&ptr,16);
if (*ptr != 0 || entry_.codeset_id_ == 0)
{
char emsg [100];
ACE_OS::sprintf (emsg,"invalid rgy_value, '%s'",line_data_);
fail (emsg);
}
break;
case 6: // char_values
if (entry_.num_sets_ != 0)
fail ("duplicate char_values");
ptr = line_data_;
do {
if (*ptr == ':')
ptr++;
ACE_CDR::UShort tmp =
static_cast<ACE_CDR::UShort> (ACE_OS::strtoul(ptr,&ptr,16));
if (*ptr != 0 && *ptr != ':')
{
char *emsg = new char [100];
ACE_OS::sprintf (emsg,"invalid symbol \'%c\' in char_values",*ptr);
fail (emsg);
}
if (entry_.num_sets_ < max_charsets_)
entry_.char_sets_[entry_.num_sets_++] = tmp;
else entry_.num_sets_++;
} while (*ptr == ':');
if (entry_.num_sets_ > max_charsets_)
{
char *emsg = new char [200];
ACE_OS::sprintf (emsg,"max of %d char_values exceeded.\nIncrease ACE_Codeset_Registry::max_charsets_ to at least %d and rebuild mkcsregdb",max_charsets_,entry_.num_sets_);
fail (emsg);
}
break;
case 7: // max_bytes
if (entry_.max_bytes_ != 0)
fail ("duplicate max_bytes");
entry_.max_bytes_ =
static_cast<ACE_CDR::UShort> (ACE_OS::strtol(line_data_,&ptr,10));
if (*ptr != 0)
fail ("invalid max_bytes");
break;
}
}
return 0;
}
示例11: closefiles
//********************************************************************************************************************
//********************************************************************************************************************
void closefiles(ifstream& files, ofstream& outfile, ofstream& errorfile) {
files.close();
outfile.close();
errorfile.close();
}
示例12: load
void load(ifstream &f,mint &elementos, mdouble &nodos, mdouble &contorno){
nodos.clear();
elementos.clear();
contorno.clear();
/// VARIABLES
int n,o,p;
char t[100];
double x;
/// CARGAMOS LAS VARIABLES GENERALES DEL PROBLEMA
f.getline(t,100);
e = atof(t); /// TOLERANCIA
f.getline(t,100);
iteraciones = atoi(t); /// ITERACIONES MAXIMAS
f.getline(t,100);
dt = atof(t); /// PASO DE TIEMPO
f.getline(t,100);
Re = atof(t); /// NUMERO DE REYNOLDS
/// LEEMOS LA CANTIDAD DE NODOS
f.getline(t,100);
n = atoi(t);
/// ASIGNAMOS LOS NODOS
for(int i=0;i<n;i++){
vector<double> nod;
/// COORDENADA X
f.getline(t,100);
x = atof(t);
nod.push_back(x);
/// COORDENADA Y
f.getline(t,100);
x = atof(t);
nod.push_back(x);
nodos.push_back(nod);
}
/// LEEMOS LA CANTIDAD DE ELEMENTOS
f.getline(t,100);
n = atoi(t);
/// LEEMOS LA CANTIDAD DE NODOS POR ELEMENTO
f.getline(t,100);
o = atoi(t);
/// LEEMOS LOS INDICES DE LOS ELEMENTOS
for(int i=0;i<n;i++){
vector<int> e;
f.getline(t,100);
char *ptr;
/// LOS NUMEROS DE LOS NODOS ESTAN SEPARADOS POR UN ESPACIO
ptr = strtok(t," ");
p = atoi(ptr);
e.push_back(p-1);
for(int j=0;j<o-1;j++){
// mandarle un null parece que hace que continue con el puntero del anterior strtok
ptr = strtok(NULL," ");
p = atoi(ptr);
e.push_back(p-1);
}
elementos.push_back(e);
}
/// LEEMOS LAS CONDICIONES DE CONTORNO
/// LA ORGANIZACION DEL CONTORNO ES
/// NumNodo TipoFront Valores
/// LEEMOS LA CANTIDAD DE NODOS CON WALL
f.getline(t,100);
n = atoi(t);
for(int i=0;i<n;i++){
vector<double> nContorno;
/// NODO 1
f.getline(t,100);
nContorno.push_back(atoi(t)-1);
/// NODO 2
f.getline(t,100);
nContorno.push_back(atoi(t)-1);
/// TIPO DE CONTORNO
nContorno.push_back(1.0);
/// ASIGNAMOS u = v = 0 porque es wall
nContorno.push_back(.0);
nContorno.push_back(.0);
contorno.push_back(nContorno);
}
/// LEEMOS LA CANTIDAD DE NODOS CON VELOCIDAD IMPUESTA
f.getline(t,100);
n = atoi(t);
for(int i=0;i<n;i++){
vector<double> nContorno;
/// NODO 1
f.getline(t,100);
nContorno.push_back(atoi(t)-1);
/// NODO 2
f.getline(t,100);
nContorno.push_back(atoi(t)-1);
/// TIPO DE CONTORNO
nContorno.push_back(1.0);
/// LEEMOS u
//.........这里部分代码省略.........
示例13: read_line
static string read_line(ifstream &file){
static char buffer[BUFFER_SIZE];
file.get(buffer,BUFFER_SIZE);
file.get();
return string(buffer);
}
示例14: pgmb_read_data
bool pgmb_read_data ( ifstream &input, int xsize, int ysize,
unsigned char *g )
//****************************************************************************80
//
// Purpose:
//
// PGMB_READ_DATA reads the data in a binary portable gray map file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 16 December 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, ifstream &INPUT, a pointer to the file containing the binary
// portable gray map data.
//
// Input, int XSIZE, YSIZE, the number of rows and columns of data.
//
// Output, unsigned char *G, the array of XSIZE by YSIZE data values.
//
// Output, bool PGMB_READ_DATA, is true if an error occurred.
//
{
char c;
bool error;
int i;
unsigned char *indexg;
int j;
indexg = g;
for ( j = 0; j < ysize; j++ )
{
for ( i = 0; i < xsize; i++ )
{
input.read ( &c, 1 );
*indexg = ( unsigned char ) c;
indexg = indexg + 1;
error = input.eof();
if ( error )
{
cout << "\n";
cout << "PGMB_READ_DATA - Fatal error!\n";
cout << " End of file reading pixel ("
<< i << ", " << j <<") \n";
return true;
}
}
}
return false;
}
示例15: while
main(int argc, char* argv[])
{
// set up to handle inverse color difference
short D709 = 0;
short D2020 = 0;
short D2020C = 0;
float tmpF = 0.0;
short HD = 0; // ==1 if 1920x1080 cutout
short qHD = 0; // ==1 if 960x540 cutout
int frames = -999;
short IPixF = 0;
short Y500 =0;
short Y100 =0;
short DXYZ = 1;
short BD = 12; // 10 bit mode
short Gamma = 10000;
short SR=4;
unsigned short Half = 2048.0; // e.g half value 12 bits
unsigned short Full = 4096.0; //
short XX = 0;
unsigned short minCV = 0; //12 bits
unsigned short maxCV = 4095;
short FIR = 1;
short FULLRANGE = 0; // default is video range
short ALPHA = 0; // no alpha channel is default
short numChan2 = 3*2; // only 3 channels rgb with no alpha
short numChan = 3;
unsigned short D = 4; //D=4 for 12 bits =1 10bits = 16 for 14 bits
unsigned short minVR, maxVR, minVRC,maxVRC;
// video range is
// Luma and R,G,B: CV = Floor(876*D*N+64*D+0.5)
// Chroma: CV = Floor(896*D*N+64*D+0.5)
//Process Args:
short arg = 2;
while(arg < argc) {
if(strcmp(argv[arg],"-h")==0) {
printf("\n ARGS:\n 709 (use Rec709 Color Dif)\n 2020 (use Rec2020 Color Dif)\n HD1920 (Format is 1920x1080 images)\n HD960 (Format is 960x540 images)\n (no args get Y'DzDx color difference and 3840x2160 cutout)\n\n\n");
exit(0);
}
if(strcmp(argv[arg],"BOX")==0)FIR = 0;
if(strcmp(argv[arg],"FULL")==0)FULLRANGE = 1;
if(strcmp(argv[arg],"ALPHA")==0){
ALPHA = 1;
numChan2= 4*2;
numChan = 4;
}
if(strcmp(argv[arg],"709")==0)D709 = 1;
if(strcmp(argv[arg],"2020")==0)D2020 = 1;
if(strcmp(argv[arg],"2020C")==0)D2020C = 1;
if(strcmp(argv[arg],"HD1920")==0)HD = 1;
if(strcmp(argv[arg],"HD960")==0)qHD = 1;
if(strcmp(argv[arg],"Y100")==0)Y100 = 1;
if(strcmp(argv[arg],"Y500")==0)Y500 = 1;
if(strcmp(argv[arg],"B10")==0) {
BD = 10;
SR=6;
Half = 512.0;
Full = 1024.0;
minCV = 0;
maxCV = 1023;
D=1;
printf("\nprocessing line data 10 bits\n");
}
if(strcmp(argv[arg],"B14")==0) {
BD = 14;
SR=2;
Half = 8192;
Full = 16384;
minCV = 0;
maxCV = 16383;
D=16;
printf("\nprocessing line data 14 bits\n");
}
if(strcmp(argv[arg],"G1k")==0){
Gamma = 1;
printf("\nUsing Gamma PQ 1k\n");
}
if(strcmp(argv[arg],"G10k")==0){
Gamma = 10000;
printf("\nUsing Gamma PQ 10k\n");
}
if(strcmp(argv[arg],"G1886")==0){
Gamma = 1886;
printf("\nUsing Gamma Red1886\n");
}
if(D709 || D2020 || D2020C || Y100 || Y500)DXYZ = 0;
//.........这里部分代码省略.........