Esempio n. 1
0
int load_map(FILE *f, struct node **nodesp, unsigned int *nnodes){
  unsigned char ver = 0;
  struct node *nodes;
  int err;

  err = read_header(f, &ver, nnodes);
  if (err) {
    return 1;
  }
  if (ver > current_version) {
    fprintf(stderr,
            "File version is %u, %u is the maximum version\n",
            (unsigned int) ver, (unsigned int) current_version);
    return 1;
  }

  if (*nnodes == 0) {
    fprintf(stderr, "No nodes to read\n");
    return 1;
  }

  nodes = xmalloc((*nnodes) * sizeof(*nodes));

  err = read_nodes(f, nodes, *nnodes);
  if (err) {
    free(nodes);
    return 1;
  }

  *nodesp = nodes;

  return 0;
}
Esempio n. 2
0
/*
  read_gmsh: read the gmsh II file and output a pointer to mesh structure 
  ckecked: ok
*/
mesh *read_gmsh(const char *fname)
{

    id i; // index cell 
    id j; // index for face in all faces 
    id k; // index for faces in one cell 
    gmsh_raw *gmsh; 
    mesh *m; 

    // open mesh file and allocate gmsh strucut
    fp = sfopen(fname, "in read_gmsh() for fp");     
    gmsh = smalloc(sizeof(gmsh_raw)*1, "in read_gmsh, for gmsh");
    
    /*find the opening mark, and read the text blocks*/
    while(fgets(line, MAXLINE, fp) != NULL){ // read line by line 
        if (sscanf(line, "%s", w) == 1){
            if (strcmp(w, "$PhysicalNames") == 0) read_physicalNames(fp, gmsh);  
            if (strcmp(w, "$Nodes") == 0)         read_nodes(fp, gmsh);  
            if (strcmp(w, "$Elements") == 0)      read_elems(fp, gmsh);  
        }
    }

    /* construct mesh from elements*/
    m = elems_to_mesh(gmsh);

    /* sort the faces according to its 3 types: boundary, salve, nb*/ 
    sort_faces();

    /*clean up*/
    fclose(fp);
    free(facetypes);

    return m;
}
Esempio n. 3
0
/*
 * reads in data from all relevant files
 * returns a pointer to an event object
 */
Event* read_data() {
  char* filename;
  Event* event;
  Vector* nodes;
  Vector* tracks;
  Vector* courses;
  Vector* entrants;

  filename = get_filename("Please enter name file: ");
  event = read_event(filename);

  filename = get_filename("Please enter nodes file: ");
  nodes = read_nodes(filename);

  filename = get_filename("Please enter tracks file: ");
  tracks = read_tracks(filename, nodes);

  filename = get_filename("Please enter courses file: ");
  courses = read_courses(filename, nodes, tracks);

  filename = get_filename("Please enter entrants file: ");
  entrants = read_entrants(filename, courses);

  event->nodes = nodes;
  event->entrants = entrants;
  return event;
}
Esempio n. 4
0
static int read_managers(node *n, const char *nodesfile, endpointid **outids, int *outcount)
{
  endpointid *managerids;
  int count;
  array *nodes = read_nodes(nodesfile);
  int i;

  *outids = NULL;
  *outcount = 0;

  if (NULL == nodes)
    return -1;

  count = array_count(nodes);
  managerids = (endpointid*)calloc(count,sizeof(endpointid));

  for (i = 0; i < count; i++) {
    char *nodename = array_item(nodes,i,char*);
    char *host = NULL;
    int port = 0;

    if (NULL == strchr(nodename,':')) {
      host = strdup(nodename);
      port = WORKER_PORT;
    }
    else if (0 > parse_address(nodename,&host,&port)) {
      fprintf(stderr,"Invalid node address: %s\n",nodename);
      array_free(nodes);
      free(managerids);
      return -1;
    }
    managerids[i].port = port;
    managerids[i].localid = MANAGER_ID;

    if (0 > lookup_address(host,&managerids[i].ip,NULL)) {
      fprintf(stderr,"%s: hostname lookup failed\n",host);
      array_free(nodes);
      free(managerids);
      return -1;
    }
    free(host);
  }

  *outids = managerids;
  *outcount = count;

  array_free(nodes);
  return 0;
}
Esempio n. 5
0
File: poly.c Progetto: barnaba/jimp2
int read_poly_file(const char *filename, triangulateio * input)
{
  int error_value = 0;
  FILE *polyfile;
  int markers;
  int firstnode;

  polyfile = fopen(filename, "r");
  if (polyfile == (FILE *) NULL) {
    printf("  Error:  Cannot access file %s.\n", filename);
    return FILE_ERR;
  }

  error_value = read_nodes_header(polyfile, input, &markers);
  if (error_value != SUCCESS)
    return error_value;

  allocate_nodes(input);

  error_value = read_nodes(polyfile, input, &markers, &firstnode);
  if (error_value != SUCCESS)
    return error_value;


  error_value = read_segments_header(polyfile, input, &markers);
  if (error_value != SUCCESS)
    return error_value;

  allocate_segments(input);
  error_value = read_segments(polyfile, input, markers, firstnode);
  if (error_value != SUCCESS)
    return error_value;

  error_value = read_holes_header(polyfile, input);
  if (error_value != SUCCESS)
    return error_value;

  allocate_holes(input);
  error_value = read_holes(polyfile, input);
  if (error_value != SUCCESS)
    return error_value;


  report(input, 1, 0, 0, 1, 0, 0);
  return SUCCESS;
}
Esempio n. 6
0
bool read_data(char* inputFolder) {
	bool success;
	char* nodesPath = NULL;
	char* edgesPath = NULL;

	success = (concat_path(inputFolder, "nodes", &nodesPath) && concat_path(inputFolder, "edges", &edgesPath));

	if (success) {
		success = success && read_nodes(nodesPath);
		success = success && read_edges(edgesPath);
	}

	free(nodesPath);
	free(edgesPath);

	return success;
}
Esempio n. 7
0
static int huge_read(void)
{
  static const char sys_mm_hugepages[] = "/sys/kernel/mm/hugepages";

  if (g_flag_rpt_mm) {
    if (read_syshugepages(sys_mm_hugepages, "mm") != 0) {
      return -1;
    }
  }
  if (g_flag_rpt_numa) {
    if (read_nodes() != 0) {
      return -1;
    }
  }

  return 0;
}
Esempio n. 8
0
/**
 * @brief This function prompts the user with a question asking for the path to
 * a file containing data on nodes. The data should contain a node ID and a 
 * short string used to identify what type of node the node is.
 * 
 * @return The function returns a pointer to a NODE_LIST, the NODE_LIST will be 
 * populated with data if successful. If it fails NULL is returned.
 */
NODE_LIST *get_nodes() {
    char response[255];

    do {
        NODE_LIST *temp = NULL;

        printf("Please enter a path to a file containing node data:\n>>> ");
        scanf(" %[^\t\n]", response);

        temp = read_nodes(response);
        if (temp != NULL) {
            printf("[i] %d nodes loaded from '%s'.\n\n", temp->size, response);

            return temp;
        }

    } while (1);
}
Esempio n. 9
0
int load_map(FILE *f, struct node **nodesp, unsigned int *nnodes){
	unsigned char ver = 0;
	struct node *nodes;
	int err;

	err = read_header(f, &ver, nnodes);
	if (err) return 1;
	if (ver > current_version) {
		fprintf(stderr,
			"File version is %u, %u is the maximum version\n",
			(unsigned int) ver, (unsigned int) current_version);
		return 1;
	}

	if (*nnodes == 0) {
		fprintf(stderr, "No nodes to read\n");
		return 1;
	}

	nodes = malloc((*nnodes) * sizeof(*nodes));
	if (!nodes) {
		fprintf(stderr, "Failed allocating %lu bytes for nodes\n",
			(unsigned long) (*nnodes) * sizeof(*nodes));
		perror("malloc failed");
		return 1;
	}

	err = read_nodes(f, nodes, *nnodes);
	if (err) {
		free(nodes);
		return 1;
	}

	*nodesp = nodes;

	return 0;
}
Esempio n. 10
0
void
QcOsmPbfReader::read_osm_data()
{
  // tell about the OSMData blob
  qDebug() << "  OSMData";

  // parse the PrimitiveBlock from the blob
  if (!m_primitive_block.ParseFromArray(m_unpack_buffer, m_buffer_size))
    qCritical() << "unable to parse primitive block";

  // tell about the block's meta info
  m_granularity = m_primitive_block.granularity(); // default: 100
  m_latitude_offset = m_primitive_block.lat_offset(); // default: 0
  m_longitude_offset = m_primitive_block.lon_offset(); // default: 0
  m_date_granularity = m_primitive_block.date_granularity(); // default: 1000
  // qDebug().nospace() << "    granularity: " << m_granularity;
  // qDebug().nospace() << "    lat_offset: " << m_latitude_offset;
  // qDebug().nospace() << "    lon_offset: "  << m_longitude_offset;
  // qDebug().nospace() << "    date_granularity: " << m_date_granularity;

  // tell about the stringtable
  m_string_table.clear();
  OSMPBF::StringTable string_table = m_primitive_block.stringtable();
  qDebug().nospace() << "    stringtable: " << string_table.s_size() << " items";
  for (int i = 0; i < string_table.s_size(); i++) {
    QString string = string_table.s(i).c_str();
    // qDebug().nospace() << "      string[" << i << "] " << string ;
    m_string_table << string;
  }

  // number of PrimitiveGroups
  int number_of_primitive_groups = m_primitive_block.primitivegroup_size();
  m_number_of_primitive_groups += number_of_primitive_groups;
  qDebug().nospace() << "    primitivegroups: " << number_of_primitive_groups << " groups";

  // iterate over all PrimitiveGroups
  for (int i = 0, l = number_of_primitive_groups; i < l; i++) {
    /* A PrimitiveGroup MUST NEVER contain different types of
     * objects. So either it contains many Node messages, or a
     * DenseNode message, or many Way messages, or many Relation
     * messages, or many ChangeSet messages.
     */

    // one PrimitiveGroup from the the Block
    OSMPBF::PrimitiveGroup primitive_group = m_primitive_block.primitivegroup(i);

    bool found_items = false;

    // tell about nodes
    int number_of_nodes = primitive_group.nodes_size();
    if (number_of_nodes > 0) {
      found_items = true;
      m_number_of_node_primitive_groups++;
      m_number_of_nodes += number_of_nodes;
      qDebug().nospace() << "      primitive nodes: " << number_of_nodes;
      if (m_read_nodes)
        read_nodes(primitive_group);
    }

    // tell about dense nodes
    if (primitive_group.has_dense()) {
      found_items = true;
      m_number_of_dense_node_primitive_groups++;
      int number_of_nodes = primitive_group.dense().id_size();
      m_number_of_nodes += number_of_nodes;
      qDebug().nospace() << "      primitive dense nodes: " << number_of_nodes;
      if (m_read_nodes)
        read_dense_nodes(primitive_group);
    }

    // tell about ways
    if (primitive_group.ways_size() > 0) {
      found_items = true;
      m_number_of_way_primitive_groups++;
      int number_of_ways = primitive_group.ways_size();
      m_number_of_ways += number_of_ways;
      qDebug().nospace() << "      primitive ways: " << number_of_ways;
      if (m_read_ways)
        read_ways(primitive_group);
    }

    // tell about relations
    if (primitive_group.relations_size() > 0) {
      found_items = true;
      m_number_of_relation_primitive_groups++;
      int number_of_relations = primitive_group.relations_size();
      m_number_of_relations += number_of_relations;
      qDebug().nospace() << "      primitive relations: " << primitive_group.relations_size();
      if (m_read_relations)
        read_relations(primitive_group);
    }

    if (!found_items)
      qWarning() << "      contains no items";
  }
}