Esempio n. 1
0
    int ElmerReader::readNodes(node_map& nodes){
        string line;
        double coords[3]; // store node coords
        int id, buffer, tokens;
        char test;
        nodes.clear();
		
//		printf("reading nodes from \"%s\"\n",nodeFile.c_str());
        ifstream in(nodeFile.c_str());
        if(!in.is_open()) return -1;
//		printf("file opened successfully\n");
        while(in.good()){
            getline(in, line); test=0;
            // format for nodes is "node-id unused x y z"
            tokens=sscanf(line.c_str(),"%d %d %lf %lf %lf%c",
                    &id, &buffer, coords, coords+1, coords+2, &test);
            //printf("read %d tokens: %d %d %lf %lf %lf, test is %d\n",
            //        tokens, id, buffer, coords[0], coords[1], coords[2], test);
            if(tokens==5 && test==0){ //line format is correct
                nodes[id]=vector<double>(coords, coords+3);
            }
        }
        in.close();
//		printf("read %d nodes from %s\n", nodes.size(),nodeFile.c_str());
        return nodes.size();
    }