57 #define LINE_LENGTH 200 84 if (chaco_offset == 0 || chaco_offset >= chaco_break_pnt) {
85 if (chaco_offset >= chaco_break_pnt) {
89 for (i=length_left; i; i--) *ptr2++ = *ptr++;
90 length = chaco_save_pnt + 1;
98 ptr2 = fgets(&chaco_line[length_left], length, infile);
100 if (ptr2 == (
char *) NULL) {
102 return((
double) 0.0);
114 if (chaco_line[chaco_break_pnt] !=
'\0') {
115 if (isspace((
int)(chaco_line[chaco_break_pnt]))) {
117 chaco_save_pnt = chaco_break_pnt + 1;
121 else if (white_seen) {
134 while (isspace((
int)(chaco_line[chaco_offset])) && chaco_offset <
LINE_LENGTH) chaco_offset++;
135 if (chaco_line[chaco_offset] ==
'%' || chaco_line[chaco_offset] ==
'#') {
140 return((
double) 0.0);
144 val = strtod(ptr, &ptr2);
149 return((
double) 0.0);
152 chaco_offset = (int) (ptr2 - chaco_line) /
sizeof(char);
179 if (chaco_offset == 0 || chaco_offset >= chaco_break_pnt) {
180 if (chaco_offset >= chaco_break_pnt) {
184 for (i=length_left; i; i--) *ptr2++ = *ptr++;
185 length = chaco_save_pnt + 1;
193 ptr2 = fgets(&chaco_line[length_left], length, infile);
195 if (ptr2 == (
char *) NULL) {
209 if (chaco_line[chaco_break_pnt] !=
'\0') {
210 if (isspace((
int)(chaco_line[chaco_break_pnt]))) {
212 chaco_save_pnt = chaco_break_pnt + 1;
216 else if (white_seen) {
229 while (isspace((
int)(chaco_line[chaco_offset])) && chaco_offset <
LINE_LENGTH) chaco_offset++;
230 if (chaco_line[chaco_offset] ==
'%' || chaco_line[chaco_offset] ==
'#') {
239 val = (int) strtol(ptr, &ptr2, 10);
247 chaco_offset = (int) (ptr2 - chaco_line) /
sizeof(char);
265 while (c !=
'\n' && c !=
'\f')
328 while (end_flag == 1) {
333 printf(
"ERROR in graph file `%s':", inname);
334 printf(
" Invalid number of vertices (%d).\n", *nvtxs);
341 printf(
"ERROR in graph file `%s':", inname);
342 printf(
" Invalid number of expected edges (%d).\n", narcs);
351 using_ewgts = option - 10 * (option / 10);
353 using_vwgts = option - 10 * (option / 10);
355 vtxnums = option - 10 * (option / 10);
358 (*vwgt_dim) = using_vwgts;
359 (*ewgt_dim) = using_ewgts;
362 if (!end_flag && using_vwgts==1){
364 if (!end_flag) (*vwgt_dim) = j;
366 if (!end_flag && using_ewgts==1){
368 if (!end_flag) (*ewgt_dim) = j;
376 *start = (
int *) malloc((
unsigned) (*nvtxs + 1) *
sizeof(
int));
378 *adjacency = (
int *) malloc((
unsigned) (2 * narcs + 1) *
sizeof(
int));
383 *vweights = (
float *) malloc((
unsigned) (*nvtxs) * (*vwgt_dim) *
sizeof(float));
388 *eweights = (
float *)
389 malloc((
unsigned) (2 * narcs + 1) * (*ewgt_dim) *
sizeof(float));
404 while ((using_vwgts || vtxnums || narcs) && end_flag != -1) {
411 if (vertex == *nvtxs)
413 printf(
"ERROR in graph file `%s':", inname);
414 printf(
" no vertex number in line %d.\n", line_num);
418 if (j != vertex && j != vertex + 1) {
419 printf(
"ERROR in graph file `%s':", inname);
420 printf(
" out-of-order vertex number in line %d.\n", line_num);
438 if (using_vwgts && new_vertex) {
439 for (j=0; j<(*vwgt_dim); j++){
442 printf(
"ERROR in graph file `%s':", inname);
443 printf(
" not enough weights for vertex %d.\n", vertex);
447 (*vweights)[(vertex-1)*(*vwgt_dim)+j] = weight;
461 for (j=0; j<(*ewgt_dim); j++){
465 printf(
"ERROR in graph file `%s':", inname);
466 printf(
" not enough weights for edge (%d,%d).\n", vertex, neighbor);
479 if (++nedges > 2*narcs) {
480 printf(
"ERROR in graph file `%s':", inname);
481 printf(
" at least %d adjacencies entered, but nedges = %d\n",
486 *adjptr++ = neighbor;
495 (*start)[vertex] = sum_edges;
500 while (!flag && end_flag != -1) {
506 (*start)[*nvtxs] = sum_edges;
514 if (*adjacency != NULL)
517 if (*eweights != NULL)
526 if (*adjacency != NULL)
528 if (*vweights != NULL)
530 if (*eweights != NULL)
569 while (end_flag == 1) {
574 if (end_flag == -1) {
575 printf(
"No values found in geometry file `%s'\n", geomname);
589 printf(
"Too many values on input line of geometry file `%s'\n",
592 printf(
" Maximum dimensionality is 3\n");
601 *x = (
float *) malloc((
unsigned) nvtxs *
sizeof(float));
604 *y = (
float *) malloc((
unsigned) nvtxs *
sizeof(float));
608 *z = (
float *) malloc((
unsigned) nvtxs *
sizeof(float));
612 for (nread = 1; nread < nvtxs; nread++) {
615 i = fscanf(fingeom,
"%f", &((*x)[nread]));
617 else if (ndims == 2) {
618 i = fscanf(fingeom,
"%f%f", &((*x)[nread]), &((*y)[nread]));
620 else if (ndims == 3) {
621 i = fscanf(fingeom,
"%f%f%f", &((*x)[nread]), &((*y)[nread]),
626 printf(
"Too few lines of values in geometry file; nvtxs=%d, but only %d read\n",
631 else if (i != ndims) {
632 printf(
"Wrong number of values in line %d of geometry file `%s'\n",
642 while (!flag && end_flag != -1) {
static int chaco_save_pnt
static void chaco_flush_line(FILE *)
helper function for zoltan1 chaco reader code Reader code was copied from zoltan1 test driver code...
double chaco_read_val(FILE *infile, int *end_flag)
read a double from a file Reader code was copied from zoltan1 test driver code.
int chaco_read_int(FILE *infile, int *end_flag)
read a int from a file Reader code was copied from zoltan1 test driver code.
static int chaco_break_pnt
static char chaco_line[LINE_LENGTH]
int chaco_input_graph(FILE *fin, char *inname, int **start, int **adjacency, int *nvtxs, int *vwgt_dim, float **vweights, int *ewgt_dim, float **eweights)
read a Chaco graph file Reader code was copied from zoltan1 test driver code. File is closed when rea...
int chaco_input_geom(FILE *fingeom, char *geomname, int nvtxs, int *igeom, float **x, float **y, float **z)
read a Chaco coordinates file Reader code was copied from zoltan1 test driver code. File is closed when read is completed.