/********************************************* file name: io.c Description: Functions for input and output the data. **********************************************/ #include #include #include #include #include double Two = 0.5; int flag_diag = 0; /* int input_from_file(char *fname, double ***Xp, double **Yp) Reading the values of dim,X, and Y from a file. */ int input_from_file(char *fname, double ***Xp, double **Yp) { FILE *fp; int dim, M, i, j; double **X, *Xy, *Y; fp = fopen(fname,"r"); if (fp == NULL) { fprintf(stderr,"%s:File open error.\n", fname); return(-1); } fscanf(fp,"%d", &dim); #ifdef _SPHERE M = dim+1; #else M = dim; #endif if (M>0){ X = (double **)malloc(sizeof(double *) * M); /* memory allocation */ Xy = (double *)malloc(sizeof(double) * M*M); Y = (double *)malloc(sizeof(double) * M); for (i=0; i 0 && nv%2 == 0 ) return (nv/2); }else{ while (s0){ dim=M-1; X = (double **)malloc(sizeof(double *) * M); /* memory allocation */ Xy = (double *)malloc(sizeof(double) * M*M); Y = (double *)malloc(sizeof(double) * M); for (i=0; i= argc) break; } for (i=0; ii) X[i][j] *= Two; X[j][i] = X[i][j]; k++; if (k >= argc) break; } if (k>= argc) break; } } for (i=0; i= argc) break; } *Xp = X; *Yp = Y; return dim; } /* void free_xy(double **X, double Y) Description: Free the memory allocated by the function input_from_file or input_from_command. */ void free_xy(double **X, double *Y) { free(*X); free(X); free(Y); } /* void print_vec(int n, int length, char *name, double v[], ...); Description: This function is for printing vectors which has the same length. The variable "n" means the number of vectors and "length" means the length of vectors. example: print_vec(4,10, "foo:\n", foo "bar:\n", bar, "baz:\n", baz, "qux:\n", qux ); */ void print_vec(int n, int length, ...) { va_list ap; char *s; double *v; int i,j; va_start(ap, length); for(i= 0; isize; int i,j; printf("%s\n\t", str); for(i=0; isize1, ncol = m->size2; int i,j; printf("%s\n", str); for(i=0; i