Пример #1
0
bool BkgModelControlOpts::read_file_xyflow(HashTable_xyflow &xyf_hash, int numFlows)
{
    xyf_hash.clear();
    xyf_hash.setFilename(bkgModel_xyflow_fname_in);
    //xyf_hash.set_xyflow_limits(numFlows);
    std::ifstream infile;
    infile.open(bkgModel_xyflow_fname_in.c_str());
    if (infile.is_open()) { /* ok, proceed with output */
        std::string line;
        int nLines = 0;
        while(!infile.eof()){
          //read data from file
          std::getline (infile,line);
          if (line.length()==0)
              break;
          nLines++;
          std::vector<std::string> tokens;
          split(line,' ',tokens);
          int x = atoi(tokens[0].c_str());
          int y = atoi(tokens[1].c_str());
          int f = atoi(tokens[2].c_str());
          xyf_hash.insert_xyflow(x,y,f);
          xyf_hash.insert_xy(x,y);
          //std::cout << r << " " << c << " " << flow << std::endl;
        }
        std::cout << nLines << " lines read by read_file_xyflow()..."  << std::endl << std::flush;
        //xyf_hash.print();
    }
    else {
        std::cerr << "read_file_xyflow() open error!!!"  << std::endl << std::flush;
        return (false);
    }
    infile.close();
    return (true);
}
Пример #2
0
bool BkgModelControlOpts::read_file_sse(HashTable_xyflow &xyf_hash, int numFlows)
{
    xyf_hash.clear();
    xyf_hash.setFilename(bkgModel_xyflow_fname_in);
    //xyf_hash.set_xyflow_limits(numFlows);
    std::ifstream infile;
    infile.open(bkgModel_xyflow_fname_in.c_str());
    if (infile.is_open()) { /* ok, proceed with output */
        std::string line;
        //std::getline (infile,line); // header line
        int nLines = 0;
        while(!infile.eof()){
          //read data from file
          std::getline (infile,line);
          if (line.length()==0)
              break;
          nLines++;
          std::vector<std::string> tokens;
          std::vector<std::string> elem;
          split(line,'\t',tokens);
          if (tokens.size()<9) {
              split(line,' ',tokens);
              if (tokens.size()<9) {
                  std::cerr << "read_file_sse() parsing error: not enough number of tokens in line " << nLines << ": " << line << std::endl << std::flush;
                  //assert(tokens.size()>=9);
                  break;
              }
          }
          split(tokens[1],':',elem);
          int nTokens = elem.size();
          int r = atoi(elem[nTokens-2].c_str());
          int c = atoi(elem[nTokens-1].c_str());
          int f = atoi(tokens[4].c_str());
          bool mm = tokens[6].compare("1")==0 ? 1:0;
          std::string hp = tokens[8];
          xyf_hash.insert_rcflow(r,c,f,mm,hp);
          xyf_hash.insert_rc(r,c);
          //std::cout << r << " " << c << " " << flow << std::endl;
        }
        std::cout << nLines << " lines read by read_file_sse()..."  << std::endl << std::flush;
        std::cout << "xyf_hash.size() = " << xyf_hash.size()  << std::endl << std::flush;
        std::cout << "xyf_hash.size_xy() = " << xyf_hash.size_xy()  << std::endl << std::flush;
        //xyf_hash.print();
    }
    else {
        std::cerr << "read_file_sse() open error!!!"  << std::endl << std::flush;
        return (false);
    }
    infile.close();
    return (true);
}