コード例 #1
0
ファイル: EpwData.cpp プロジェクト: NREL/OpenStudio
void EpwData::parseData(const std::string &line, size_t row)
{
  std::stringstream linestream(line);
  size_t col = 0;

  for(size_t i = 0;i<22;i++)
  {
    std::string s;
    std::getline(linestream, s, ',');
    switch(i)
    {
      case 6:
      case 7:
      case 8:
      case 13:
      case 14:
      case 15:
      case 21:
        assert(col < m_data.size());
        assert(row < m_data[col].size());
        m_data[col++][row] = ::atof(s.c_str());
        break;
      default:
        break;
    }
  }
}
コード例 #2
0
ファイル: mitkTransform.cpp プロジェクト: zomboir/MITK
  void Transform::FromCSVFile(const std::string& file)
  {
    std::ifstream csvFile (file.c_str());
    endoAssert ( csvFile.fail() == false );

    mitk::Transform::Pointer transform = mitk::Transform::New();
    vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat;
    std::string line;
    mitk::ScalarType d = 0.0f;
    int row=0,column = 0;

    while (std::getline (csvFile, line))
    {
      std::istringstream linestream(line);
      std::string item;
      column = 0;
      while (std::getline (linestream, item, ','))
      {
        std::istringstream number;
        number.str(item);
        number >> d;
        mat(row, column) = d;
        ++column;
      }
      ++row;
    }
    endoAssert( row == 4 && column == 4 );
    transform->SetMatrix( mat );

    this->SetNavigationData( transform->GetNavigationData() );
    // modified is called in SetNavigationData
  }
コード例 #3
0
void LoadBCE_fromFile(thrust::host_vector<Real3> &posRadBCE, // do not set the
                                                             // size here since
                                                             // you are using
                                                             // push back later
                      std::string fileName) {
  std::string ddSt;
  char buff[256];
  int numBce = 0;
  const int cols = 3;
  std::cout << "  reading BCE data from: " << fileName << " ...\n";
  std::ifstream inMarker;
  inMarker.open(fileName);
  if (!inMarker) {
    std::cout << "   Error! Unable to open file: " << fileName << std::endl;
  }
  getline(inMarker, ddSt);
  Real q[cols];
  while (getline(inMarker, ddSt)) {
    std::stringstream linestream(ddSt);
    for (int i = 0; i < cols; i++) {
      linestream.getline(buff, 50, ',');
      q[i] = atof(buff);
    }
    posRadBCE.push_back(mR3(q[0], q[1], q[2]));
    numBce++;
  }

  std::cout << "  Loaded BCE data from: " << fileName << std::endl;
}
コード例 #4
0
ファイル: Gas.cpp プロジェクト: alfaceor/HeatCond
// TODO: Read initial conditions from file
bool Gas::initCondFromFile(string filename){
	struct stat buffer;   
	// Check if file exist
  if (stat (filename.c_str(), &buffer) != 0){
//    cout<<filename+" doesn't Exist!"<<endl;
    return false;
  }else{
    ifstream iniCondFile;
	  iniCondFile.open(filename.c_str()); //"xxxxxx.ini"
	  string line;
	  getline(iniCondFile,line);
//	  cout<<line<<endl;
	  stringstream linestream(line);
	  string key;
	  getline(linestream,key,' ');
	  double time=atof(key.c_str());
    int i=0;
    while( getline(linestream,key,' ') ){
      this->omega[i] = atof(key.c_str());
      getline(linestream,key,' ');
      this->theta[i] = atof(key.c_str());
      i++;
    }

    if(i>this->N or i<this->N){
      cout<<"Caralho! Deu merda! o numero de particulas nao coincide! FDP"<<endl;
    }

	  iniCondFile.close();
    return true;
  }

}
コード例 #5
0
ファイル: trainer.cpp プロジェクト: 8l/insieme
size_t Trainer::loadModel(const std::string& filename, const std::string& path){
	std::string filePath = path + "/" + filename;
	// load model
	model.load((filePath + ".mod").c_str());

	// load the feature normalization parameters
	std::ifstream fnp;
	fnp.open(filePath + ".fnp", std::ios::in);

	if(!fnp.is_open())
		throw MachineLearningException("Cannot open " + filePath + ".fnp for reading");

	featureNormalization.resize(0,0,false);
	std::string line, buf;
	size_t numF = 0;

	// read parameters from ssv, one line for each feature in forom: avgerage, min, max
	while(getline(fnp, line)) {
		numF = 0;
		std::stringstream linestream(line);
		// read the four features
		while(linestream >> buf) {
			++numF;
			featureNormalization.append_elem(insieme::utils::numeric_cast<double>(buf));
		}

	}
	featureNormalization.resize(4, numF, false);

	return numF;
}
コード例 #6
0
ファイル: controller.cpp プロジェクト: stevendaniluk/ghost
/* RLInitialization
*
* Initializes the data for the racing line (but does not set the velocities
* or yaw rates). Loads the track file, reverses it if necessary, and stores
* it in RL_.
*/
void Controller::RLInitialization(std::string &track_name, bool &CW) {	
	// Load the track file
	std::string full_file = ros::package::getPath("ghost") + "/tracks/" + track_name;	
	std::ifstream data(full_file.c_str());
		
	// Load the coordinates into the racing line (ignore first line of file)
	int i = 0;
	std::string line;
	std::getline(data, line);
	while(std::getline(data, line)) {
		std::stringstream linestream(line);
		RL_pt pt;
		linestream >> pt.x >> pt.y;
		RL_.push_back(pt);
    i++;
	}
	RL_num_pts_ = RL_.size();
	
	// Reverse the track for CCW lap, when needed
	if(!CW) {
		std::vector<RL_pt> new_RL(RL_num_pts_);
		for(int index = 0; index < RL_num_pts_; index++) {
			new_RL[RL_num_pts_ - index - 1] = RL_[index];
		}
		RL_ = new_RL;
	}
	
	// Calculate average distance between points
	double d = sqrt(pow((RL_[0].x - RL_[RL_num_pts_ - 1].x), 2) + pow((RL_[0].y - RL_[RL_num_pts_ - 1].y), 2));
	for(int index = 1; index < RL_num_pts_; index++) {
			d += sqrt(pow((RL_[index].x - RL_[index - 1].x), 2) + pow((RL_[index].y - RL_[index - 1].y), 2));
	}
	ds_dpt_ = d/RL_num_pts_;
	
}
コード例 #7
0
void Discontinuity::readTopography ( )
{
  
  std::ifstream myfile;
  Constants con;
  
  std::cout << "Reading topography." << std::endl;
  myfile.open ( "./dat/discontinuities/10MinuteTopoGrid.txt", std::ios::in );
  
  std::string line;
  while ( std::getline (myfile, line) )    
  {
    
    std::stringstream linestream (line);
    std::string value;
    
    int i = 0;
    while ( std::getline (linestream, value, ',') )
    {
      if ( i == 0 )
      {
        double lon = stod ( value );
        if ( lon < 0. )
          lon = 360 + lon;
        lonElv.push_back ( stod (value) );
      }        
      if ( i == 1 )
        colElv.push_back ( 90. - stod (value) );
      if ( i == 2 )
        elv.push_back ( stod (value) );
      i++;
    }     
  }
        
}
コード例 #8
0
ファイル: main.cpp プロジェクト: nunofmaia/pavement
void loadScene(std::string fileName) {
	std::cout << "Loading scene..." << std::endl;
	std::cout << fileName << std::endl;
	std::ifstream myfile(fileName);
	std::string line;
	
	if (myfile.is_open()) {
		//TODO deveriamos fazer algum metodo que reiniciasse tudo?!
		ID = 1;
		SelectedNode = NULL;
		DrawingZone->getScene()->deleteAllNodes();
		while (getline(myfile, line)) {
			std::stringstream linestream(line);
			int shape;
			glm::vec3 position;
			glm::vec4 color;
			GLfloat angle;
			linestream >> shape;
			linestream >> position.x;
			linestream >> position.y;
			linestream >> position.z;
			linestream >> color.r;
			linestream >> color.g;
			linestream >> color.b;
			linestream >> color.a;
			linestream >> angle;
			SceneNode* node = addNode(shape);
			node->setPosition(position);
			node->setColor(color);
			node->setAngle(angle);
		}
		myfile.close();
		std::cout << "This scene has been loaded." << std::endl;
	} else {
コード例 #9
0
/**
 * Read the variables and their corresponding segment hashes from the given 
 * file.
 */
std::vector<SegmentHash>
readVariables(const std::string& filename) {

	std::vector<SegmentHash> hashes;

	std::ifstream labelsfile(filename.c_str());

	std::string line;

	while(std::getline(labelsfile, line)) {

		std::stringstream linestream(line);

		bool defaultValue;
		linestream >> defaultValue;

		char hashSymbol;
		linestream >> hashSymbol;

		if (hashSymbol != '#')
			UTIL_THROW_EXCEPTION(
					IOError,
					"line '" << line << "' does not have valid syntax (expected '#', got '" << hashSymbol << "'");

		SegmentHash hash;
		linestream >> hash;

		hashes.push_back(hash);
	}

	return hashes;
}
コード例 #10
0
ファイル: hcwr.cpp プロジェクト: ianmurrays/rttp-hcwr
HCWR::HCWR(string input, int maxIterations, int maxRestarts)
{
  this->maxIterations = maxIterations;
  this->maxRestarts = maxRestarts;
  this->input = input;
  
  // Open the input file
  //ifstream inputFile (input.c_str());
  //istream inputFile = cin;
  
  //if ( ! inputFile.is_open())
  //{
  //  exit(1);
  //}
  
  // Parse it
  string line;
  string number;
  vector< vector<int> > distances; // Stores distances matrix

  //while (getline(inputFile, line))
  while (getline(cin, line))
  {
    if (trimmed(line, " \t") == "")
    {
      continue;
    }
    
    stringstream linestream(line);
    vector<int> row;
    
    while (linestream >> number)
    {
      row.push_back(atoi(number.c_str()));
    }
    
    distances.push_back(row);
    row.clear();
  }
  
  // We can now initialize our RTTP instance
  this->rttp = new RTTP(distances.size(), (2 * (distances.size() - 1) + OFF_DAYS), MAX_CONSECUTIVE_OFF_DAYS, MAX_CONSECUTIVE_GAMES, MAX_CONSECUTIVE_AWAY_GAMES);
  
  // Set costs
  for (size_t i = 0; i < distances.size(); i++)
  {
    for (size_t j = 0; j < distances.size(); j++)
    {
      int test = distances[i][j];
      this->rttp->setIndividualCost(i, j, test);
    }
    
    distances[i].clear();
  }
  
  // Done
  distances.clear();
  
  this->continue_iterating = true;
}
コード例 #11
0
ファイル: NodeImporter.cpp プロジェクト: thillux/TopoGen
void NodeImporter::importCitiesFromFile(void) {
    /*
      ASSUME TOPOVIEW MAP EXPORT FILE FORMAT [STR , LAT , LON]
    */
    std::unique_ptr<Config> config(new Config);
    std::ifstream inputFile((config->get<std::string>("debug.inputNodePath")).c_str());
    assert(inputFile.good());

    std::string line;
    while (std::getline(inputFile, line)) {
        // extract latitude and longitude
        std::stringstream linestream(line);
        std::vector<std::string> elems;
        std::string value;
        while (std::getline(linestream, value, ',')) {
            elems.push_back(value);
        }
        double lon = atof(elems.back().c_str());
        elems.pop_back();
        double lat = atof(elems.back().c_str());

        // create node from scratch
        CityNode ci(_nodenumber, std::to_string(_nodenumber), lat, lon, 0.0, "United States");
        ++_nodenumber;
        GeographicNode_Ptr np(new CityNode(ci));
        addNode(np);
    }
}
コード例 #12
0
ファイル: Mesh.cpp プロジェクト: ovieira/PSJ
void Mesh::parse(std::string meshString) {
	std::string line;
	std::stringstream meshstream(meshString);

	std::vector<glm::vec4> vertexIndices;
	std::vector<glm::vec4> normalIndices;
	std::vector<glm::vec2> textureIndices;
	bool readUV = false;

	while (getline(meshstream, line)) {
		if (line[0]=='v') {
			std::stringstream linestream(line.substr(2));
			glm::vec3 vertice;
			linestream >> vertice.x;
			linestream >> vertice.y;
			linestream >> vertice.z;

			if (line[1] == ' ') {
				vertexIndices.push_back(glm::vec4(vertice,1.0f));
			} else if (line[1] == 'n') {
				normalIndices.push_back(glm::vec4(vertice,1.0f));
			} else if (line[1] == 't') {
				vertice.t = 1 - vertice.t;
				textureIndices.push_back(glm::vec2(vertice));
				readUV=true;
			}
		} else if (line[0] == 'f') {
コード例 #13
0
ファイル: map.cpp プロジェクト: mxm/vs
//do a word count on a local file
std::map<std::string, int> mymap(std::string filename) {

    std::string word;
    std::string line;

    std::map<std::string, int> wordcounts;

    std::ifstream input(filename.c_str());

    if(input.is_open()) {

        while(input.good()) {

            //read a line from input file
            getline(input, line);

            //handle special characters as whitespace
            replaceAll(line, ".", " ");
            replaceAll(line, ",", " ");
            replaceAll(line, ";", " ");
            replaceAll(line, ":", " ");
            replaceAll(line, "-", " ");
            replaceAll(line, "+", " ");
            replaceAll(line, "/", " ");
            replaceAll(line, "?", " ");
            replaceAll(line, "!", " ");
            replaceAll(line, "(", " ");
            replaceAll(line, ")", " ");
            replaceAll(line, "[", " ");
            replaceAll(line, "]", " ");
            //replace numbers
            replaceAll(line, "0", " ");
            replaceAll(line, "1", " ");
            replaceAll(line, "2", " ");
            replaceAll(line, "3", " ");
            replaceAll(line, "4", " ");
            replaceAll(line, "5", " ");
            replaceAll(line, "6", " ");
            replaceAll(line, "7", " ");
            replaceAll(line, "8", " ");
            replaceAll(line, "9", " ");

            //be case insensetive
            std::transform(line.begin(), line.end(), line.begin(), ::tolower);

            std::stringstream linestream(line);

            //get words, split by whitespaces
            while(getline(linestream, word, ' ')) {
                if(word != "") {
                    ++wordcounts[word];
                }
            }
        }
    } else {
        //TODO some error handling?
    }

    return wordcounts;
}
コード例 #14
0
ファイル: functions.cpp プロジェクト: as4724/4075P
void importData(vector<double>& open,
	vector<double>& high,
	vector<double>& low,
	vector<double>& close,
	vector<int>& volume,
	vector<int>& tickCount){

	unsigned int count = 0;
	ifstream myReadFile;
	myReadFile.open("WC5min.txt");
	string line;
	if(myReadFile.is_open()){
    	cout << "\nFile Opened successfully!!!. Reading data from file into vectors\n" << endl;
		while (getline(myReadFile,line)){
			++count;
			stringstream linestream(line);
			double o, h, l, c;
			int i, v, t;
			linestream >> i >> o >> h >> l >> c >> v >> t;
			open.push_back(o);
			high.push_back(h);
			low.push_back(l);
			close.push_back(c);
			volume.push_back(v);
			tickCount.push_back(t);
		}
	}
コード例 #15
0
    bool
    loadmodelfromfile(
        const string &filename, // read-only
        string &dest_labelname,
        vector< string > &dest_exnames,
        vector< string > &dest_attrnames,
        forest_t &dest_forest,
        size_t &dest_nmin,
        size_t &dest_numattr,
        size_t &dest_optimizationlayers
    ) {

        ifstream infile( filename );
        if( !infile ) {
            cerr << "error opening input file: " << filename << endl;
            return false;
        }

        dest_forest = move( forest_t() );

        // labelname, ordered list of label/class values
        {
            stringstream linestream( nutil::getline( infile ) );
            linestream >> dest_labelname;
            for( label_t label; linestream >> label; ) {
                dest_forest.indextolabel.push_back( label );
            }
        }
コード例 #16
0
ファイル: System.cpp プロジェクト: excelsi0r/CAL-Project1
void System::retrieveBus(const char * file)
{
	ifstream inFile;
	inFile.open(file);

	if (!inFile)
	{
		cerr << "Unable to open file " << file;
		exit(1);   // call system to stop
	}

	string  line;
	int cap=0;

	while(getline(inFile, line))
	{
		stringstream linestream(line);
		linestream >> cap;

		Bus * b = new Bus(cap);
		this->company->push_back(b);
	}

	inFile.close();
}
コード例 #17
0
ファイル: SimpleGraphTests.cpp プロジェクト: pax19/algorithms
        void ReadAdjacencyList(const std::string& file_name, const ListTypes& list_type)
        {
            std::ifstream input(file_name);
            for (std::string line; getline(input, line); )
            {
                std::stringstream linestream(line);
                auto i = 0; // first line is node number
                auto node_index = 0;
                AdjacencyList adjacency_list;
                for (std::string tab_delim; getline(linestream, tab_delim, '\t');)
                {
                    if (i == 0)
                    {
                        node_index = atoi(tab_delim.c_str());                        
                        i++;
                    }
                    else
                    {
                        auto destination_node_index = atoi(tab_delim.c_str());
						adjacency_list.emplace_back(destination_node_index);
                    }
                }
				InsertAdjancencyList(adjacency_list, node_index);
            }
            graph_backup_ = graph_;
        }
コード例 #18
0
void LINE::setelem(string line){
	std::istringstream linestream (line, istringstream::in);
	string w;
	getline (linestream, w, '\t');
	chromosome = w;
	getline (linestream, w, '\t');
	position = atoi(w.c_str());
	getline (linestream, w, '\t');
	snpid = w;
	getline (linestream, w, '\t');
	familyid = w;
	getline (linestream, w, '\t');
	individualid = w;
	getline (linestream, w, '\t');
	dad = w;
	getline (linestream, w, '\t');
	mom = w;
	getline (linestream, w, '\t');
	sex = w;
	int i;
	std::vector<string> genotypes;
	genotypes.reserve(10);
	genotypes.insert(genotypes.end(),  {"AA", "AC", "AG", "AT", "CC", "CG", "CT", "GG", "GT", "TT"});
	std::map<string, long double> GL;
//	cout << GL.size() << endl;
	for (i=0; i<10; i++){
		getline (linestream, w, '\t');
		//cout << genotypes[i] << ":" << atof(w.c_str()) << "|" << w.c_str() << "\t";
		if (w!="")
		{
			GL.insert(std::make_pair(genotypes[i], atof(w.c_str()) ));
		}
		else
			continue;
//			GL.insert(std::make_pair(genotypes[i], 0 ));
//		GL[genotypes[i]]= atoi(w.c_str());
	}
	//cout << endl;
	//for (auto pos=GL.begin(); pos!=GL.end(); pos++){
	//	cout << pos->first << ":" << pos->second << "\t";
	//}
	//cout << endl;
			
	try
	{
		for (auto pos=GL.begin(); pos!=GL.end(); pos++){
			if (pos->second != -1 && pos->second <0)
				throw "Genotype probability is less than 1.";
		}		
	}
	catch(const char* Message)
	{
		cerr << "Error: " << Message << endl;
		exit (EXIT_FAILURE);
	}	
//	return GL;
//	cout << GL.size() << endl;
	GLs = GL;
}
コード例 #19
0
/**
 * Read the coefficients of each segment from the given file.
 */
std::map<SegmentHash, double>
readCoefficients(const std::string& filename) {

	std::map<SegmentHash, double> coefficients;

	std::ifstream coefsfile(filename.c_str());

	while (coefsfile.good()) {

		std::string line;
		std::getline(coefsfile, line);

		std::stringstream linestream(line);

		std::string varname;
		linestream >> varname;

		// first line or comment or empty or constant
		if (varname == "numVar" || varname == "constant" || varname.find_first_of('#') == 0 || varname.empty())
			continue;

		double coef;
		linestream >> coef;

		char hashSymbol;
		linestream >> hashSymbol;

		if (hashSymbol != '#')
			UTIL_THROW_EXCEPTION(
					IOError,
					"line '" << line << "' does not have valid syntax (expected '#', got '" << hashSymbol << "'");

		SegmentHash hash;
		linestream >> hash;

		double gs;
		linestream >> gs;

		double fs;
		linestream >> fs;

		double fm;
		linestream >> fm;

		double fp;
		linestream >> fp;

		double fn;
		linestream >> fn;

		double weightSplits = optionWeightSplits.as<double>();
		double weightMerges = optionWeightMerges.as<double>();

		// Initial factor accounts for sign depending on if the segment is part of the goldstandard.
		coefficients[hash] = (-2*gs + 1) * ( weightSplits * (fs + fp) + weightMerges * (fm + fn) );
	}

	return coefficients;
}
コード例 #20
0
ファイル: utilities.cpp プロジェクト: jcasse/xperimenter
std::vector<std::string> tokenize(const std::string & line, const char delim) {
	std::string field;
	std::vector<std::string> fields;
	std::stringstream linestream(line);
	while(getline(linestream, field, delim))
		fields.emplace_back(dequote(field));
	return fields;
}
コード例 #21
0
ファイル: utilities.cpp プロジェクト: jcasse/xperimenter
std::vector<wxString> tokenize2(const std::string & line, const char delim) {
	std::string field;
	std::vector<wxString> ret;
	std::stringstream linestream(line);
	while(getline(linestream, field, delim))
		ret.emplace_back(dequote(field));
	return ret;
}
コード例 #22
0
  ordinal_type compareToAnalytic( std::ifstream &inputFile,
                                  const Kokkos::DynRankView<ValueType,testMatProperties...> testMat,
                                  const ValueType reltol,
                                  const ordinal_type iprint,
                                  const TypeOfExactData analyticDataType ) {
    INTREPID2_TEST_FOR_EXCEPTION( testMat.rank() != 2, std::invalid_argument,
                                  ">>> ERROR (compareToAnalytic): testMat must have rank 2");

    Teuchos::RCP<std::ostream> outStream;
    Teuchos::oblackholestream  outNothing;
    if (iprint > 0)
      outStream = Teuchos::rcp(&std::cout, false);
    else
      outStream = Teuchos::rcp(&outNothing, false);

    // Save the format state of the original std::cout.
    Teuchos::oblackholestream oldFormatState;
    oldFormatState.copyfmt(std::cout);

    std::string line;
    ValueType testentry;
    ValueType abstol;
    ValueType absdiff;
    ordinal_type i = 0, j = 0;
    ordinal_type err = 0;

    while (! inputFile.eof() && i < static_cast<ordinal_type>(testMat.dimension(0)) ) {
      std::getline(inputFile,line);
      std::istringstream linestream(line);
      std::string chunk;
      j = 0;
      while( linestream >> chunk ) {
        ordinal_type num1;
        ordinal_type num2;
        std::string::size_type loc = chunk.find( "/", 0);
        if( loc != std::string::npos ) {
          chunk.replace( loc, 1, " ");
          std::istringstream chunkstream(chunk);
          chunkstream >> num1;
          chunkstream >> num2;
          testentry = (ValueType)(num1)/(ValueType)(num2);
          abstol = ( std::fabs(testentry) < reltol ? reltol : std::fabs(reltol*testentry) );
          absdiff = std::fabs(testentry - testMat(i, j));
          if (absdiff > abstol) {
            ++err;
            *outStream << "FAILURE --> ";
          }
          *outStream << "entry[" << i << "," << j << "]:" << "   "
                     << testMat(i, j) << "   " << num1 << "/" << num2 << "   "
                     << absdiff << "   " << "<?" << "   " << abstol << "\n";
        }
        else {
          std::istringstream chunkstream(chunk);
          if (analyticDataType == INTREPID2_UTILS_FRACTION) {
            chunkstream >> num1;
            testentry = (ValueType)(num1);
          }
          else if (analyticDataType == INTREPID2_UTILS_SCALAR)
コード例 #23
0
ファイル: Graph.cpp プロジェクト: Soulrift/GSP295_Final
void Graph::CreateNodes()
{
	//pull in text file to "myFile" and parse out nodes
	//also, put neighbors into the vector of ints inside
	//each node to create edges later
	vector<int> nodevalues;

	int temp;

	ifstream myFile("map2.txt");
	string line;
	int linenum = 0;
	Node* n;

	while (getline (myFile, line))
	{
		linenum++;
		istringstream linestream(line);
		string item;
		int itemnum = 0;
		while (getline (linestream, item, ','))
		{
			itemnum++;
			if (itemnum < 5)
			{
				temp = atoi(item.c_str());
				nodevalues.push_back(temp);
				if (itemnum == 4)
					n = new Node(nodevalues[0], Vector3(nodevalues[1], nodevalues[2], nodevalues[3]));
			}
			else if (itemnum > 4)
			{
				temp = atoi(item.c_str());
				n->neighbors.push_back(temp);
			}
		} // end while
		nodes.push_back(n);
		nodevalues.clear();
	}	

	//Drawing da nodes
	Vector3 tempPos;

	for(int i = 0; i < (int)nodes.size(); i++)
	{
		tempPos = nodes[i]->position;
		gMyGameWorld->CreateSphere(GLB->circID);
		gMyGameWorld->SetSpherePosition(GLB->circID, tempPos.x, tempPos.y, tempPos.z);
		gMyGameWorld->SetSphereColor(GLB->circID, 255, 255, 255);
		gMyGameWorld->SetSphereScale(GLB->circID, 0.4);
		if (i < 10)
			gMyGameWorld->AddSphereText(GLB->circID, "\n\n   ", i);
		else
			gMyGameWorld->AddSphereText(GLB->circID, "\n\n  ", i);
		nodes.at(i)->SphereID = GLB->circID;
		GLB->circID++;
	}
}
コード例 #24
0
vector<int> readChainErrors(string line) {
  vector<int> chains_errors_and_indicators;
  std::istringstream linestream(line);
  copy(std::istream_iterator<int>(linestream), 
       std::istream_iterator<int>(), 
       std::back_inserter(chains_errors_and_indicators));
  int chain_size = chains_errors_and_indicators.size() / 2;
  return vector<int>(chains_errors_and_indicators.begin(), 
                     chains_errors_and_indicators.begin() + chain_size);
}
コード例 #25
0
ファイル: FSDir.cpp プロジェクト: lukasic/ncfm
void FSDir::readContent()
{
	freeContent();
	std::string command = "ls -lh";

	command += " " + getAbsolutePath() + "/";
	command += " | tail -n +2 ";
	command += " | ";
	command += AWK;

	std::string ls = exec(command);

	std::istringstream iss(ls);
	std::string line;

	while ( line.clear(), getline(iss, line) )
	{
		std::istringstream linestream(line);
		std::string filename;
		std::string date; 
		std::string size;
		std::string owner;
		std::string perms;

		getline(linestream, filename, '#');
		getline(linestream, date, '#');
		getline(linestream, size, '#');
		getline(linestream, owner, '#');
		getline(linestream, perms);

		if ( ! hidden && filename[0] == '.' )
			continue;

		if ( perms[0] == 'd' )
		{
			FSDir * d = new FSDir( getAbsolutePath() + PATH_SEPARATOR + filename);
			d->setAttrs(date, owner, size, perms);
			content.push_back((FSObject*) d);
		}
		else if ( perms[0] == 'l' )
		{
			FSSymlink * d = new FSSymlink( getAbsolutePath() + PATH_SEPARATOR + filename);
			d->setAttrs(date, owner, size, perms);
			content.push_back((FSObject*) d);
		}
		else
		{
			FSFile * f = new FSFile(getAbsolutePath() + PATH_SEPARATOR + filename);
			f->setAttrs(date, owner, size, perms);
			content.push_back((FSObject*) f);
		}
	}

	std::sort(content.begin(), content.end(), directoriesFirst);
}
コード例 #26
0
bool MeteorologyData::load( std::string fileName )
{
	std::ifstream infile( fileName.c_str() );
	if ( !infile )
	{
		std::cerr << "Fail to read data file" << std::endl;
		return false;
	}

	std::string line;
	// 根据第一行关键词“diamond”,判断数据文件合法性
	std::getline( infile, line );
	int pos = line.find("diamond");
	if ( pos == std::string::npos )
	{
		std::cerr << "Data file illegal" << std::endl;
		return false;
	}
	//读取第二行中的数据头信息
	std::getline( infile, line );
	std::istringstream linestream( line );
	linestream >> year;
	linestream >> month;
	linestream >> day;
	linestream >> hour;
	linestream >> lifecycle;
	linestream >> level;
	linestream >> longitudeGridSpace;
	linestream >> latitudeGridSpace;
	linestream >> startLongitude;
	linestream >> endLongitude;
	linestream >> startLatitude;
	linestream >> endLatitude;
	linestream >> latitudeGridNumber;
	linestream >> longitudeGridNumber;
	linestream >> isolineSpace;
	linestream >> isolineStartValue;
	linestream >> isolineEndValue;
	linestream >> smoothFactor;
	linestream >> bold;
	
	//从第三行开始读取网格点数据值
	pValue = new float[longitudeGridNumber*latitudeGridNumber];
	int i = 0;
	float temp;
	while ( infile >> temp )
	{
		pValue[i++] = temp;
		if ( temp > maxValue  ) maxValue = temp;
		if ( temp < minValue ) minValue = temp;
	}
	return true;
}
コード例 #27
0
ファイル: GriddedData.C プロジェクト: AhmedAly83/moose
/**
 * Splits an input_string using space as the separator
 * Converts the resulting items to Real, and adds these
 * to the end of output_vec
 */
void
GriddedData::splitToRealVec(const std::string & input_string, std::vector<Real> & output_vec)
{
  std::istringstream linestream(input_string);
  std::string item;
  while (getline(linestream, item, ' '))
  {
    std::istringstream i(item);
    Real d;
    i >> d;
    output_vec.push_back(d);
  }
}
コード例 #28
0
ファイル: System.cpp プロジェクト: excelsi0r/CAL-Project1
void System::retrieveCompany(const char * file)
{
	ifstream inFile;

	inFile.open(file);

	if (!inFile)
	{
		cerr << "Unable to open file " << file;
		exit(1);   // call system to stop
	}

	string  line;

	int idNo=0;
	int X=0;
	int Y=0;

	getline(inFile, line);

	if(line == "")
	{
		cerr << "No company coordenates on file\n";
		exit(1);
	}

	stringstream linestream(line);
	string  data;

	linestream >> idNo;

	getline(linestream, data, ';');  // read up-to the first ; (discard ;).
	linestream >> X;
	getline(linestream, data, ';');  // read up-to the first ; (discard ;).
	linestream >> Y;

	Coordenate *c = existsCoord(X,Y);

	if(c == NULL)
	{
		cerr << "Invalid Coordenates for Company. Inexistence in Coordenates List\n";
		exit(1);
	}

	Company* s = new Company();

	s->setCoord(c);
	this->company = s;

	inFile.close();
}
コード例 #29
0
void getSokolovOfChainsBulk(string path, string input_name) {
  string input_filename(path);
  input_filename.append(input_name);

  std::ifstream input_file;
  input_file.open(input_filename);
  
  string line;
  getline (input_file, line);
  istringstream linestream(line);
  
  int L, l, m;
  long double eps;
  string output_name;
  linestream >> L >> l >> m >> eps >> output_name;
  
  string output_filename(path);
  output_filename.append(output_name);
  std::ofstream output_file;
  output_file.open(output_filename);
  output_file.close();
  
  int max_probs_count = 20;
  vector<long double> probs;
  probs.reserve(max_probs_count);

  int probs_count = 0;
  
  do {
    getline (input_file, line);
    if (!line.empty()) {
      vector<int> errors(readChainErrors(line));
      long double prob = GetSokolovBound(L, l, m, eps, errors);
      probs.push_back(prob);
      ++probs_count;
    }
    if ((probs_count == max_probs_count) or (input_file.eof())) {
      output_file.open(output_filename, std::ios::app);
      copy(probs.begin(), probs.end(), std::ostream_iterator<long double>(output_file, "\n"));
      output_file.close();
      probs.clear();
      probs.reserve(max_probs_count);
      probs_count = 0;
    }
    std::cout << probs.size() << "\n";
  } 
  while (!input_file.eof());
  input_file.close();
}
コード例 #30
0
ファイル: System.cpp プロジェクト: excelsi0r/CAL-Project1
void System::retrieveSchools(const char * file)
{
	ifstream inFile;

	inFile.open(file);

	if (!inFile)
	{
		cerr << "Unable to open file " << file;
		exit(1);   // call system to stop
	}

	string  line;

	int idNo=0;
	int X=0;
	int Y=0;

	while(getline(inFile, line))
	{
		stringstream linestream(line);
		string  data;

		linestream >> idNo;

		getline(linestream, data, ';');  // read up-to the first ; (discard ;).
		linestream >> X;
		getline(linestream, data, ';');  // read up-to the first ; (discard ;).
		linestream >> Y;

		Coordenate* c = existsCoord(X,Y);

		if(c == NULL)
		{
			cerr << "Invalid Coordenates for Company. Inexistence in Coordenates List\n";
			exit(1);
		}

		School* s = new School();
		s->setCoord(c);

		this->schools.push_back(s);


	}

	inFile.close();

}