#include #include #include "ReadData.h" extern void ReadData(char *name,double **datap,int *Xsize, int *Ysize){ FILE *dataf; char res,*line,*linep; int k,j,skip=0,sub; double *mydat; dataf=fopen(name,"r"); if (dataf==NULL){ fprintf(stderr,"Can not open %s. Exiting...",name); exit(1); } res=getc(dataf); while (res=='#'){ skip++; while ('\n'!=getc(dataf)); res=getc(dataf); } while (res==' ') res=getc(dataf); for (res=0,k=0;'\n'!=res;) { res=getc(dataf); sub=0; if ((res==' ') || (res==' ')){ k++; while (res==' '){ sub=-1; /* there are spaces befor the cr */ res=getc(dataf); } } } line=(char *) malloc(k*30*sizeof(char)); *Xsize=k+1+sub; for (j=0;NULL!=fgets(line,k*30,dataf);j++); *Ysize=j+1; /* the first line has already been read */ /* we need to know if the last line was empty */ sub=1; for (k=0;'\0'!=line[k];k++) if (line[k]!=' ') sub=0; *Ysize-=sub; *datap= (double *) malloc(*Xsize* *Ysize*sizeof(double)); rewind(dataf); mydat=*datap; for (j=0;j