src/k_read_ascii_table.c
IDL_LONG k_read_ascii_table(float **table,
														IDL_LONG *ndim,
														IDL_LONG **sizes,
														char filename[])
{
	IDL_LONG i,nelem;
	FILE *fp;

	FREEVEC((*table));
	FREEVEC((*sizes));

	fp=k_fileopen(filename,"r");
	fscanf(fp,"%d",ndim);
	if((*ndim)<=0) {
		fprintf(stderr,"k_read_ascii_table found 0-dimensional table in %s\n",
						filename);
		exit(1);
	} /* end if */
	nelem=1;
	(*sizes)=(IDL_LONG *) malloc((*ndim)*sizeof(IDL_LONG));
	for(i=0;i<(*ndim);i++) {
		fscanf(fp,"%d",&((*sizes)[i]));
		nelem*=(*sizes)[i];
	} /* end for i */
	if(nelem<=0) {
		fprintf(stderr,"k_read_ascii_table found 0-size table in %s\n",
						filename);
		exit(1);
	} /* end if */
	(*table)=(float *) malloc(nelem*sizeof(float));
	for(i=0;i<nelem;i++) 
		fscanf(fp,"%f",&((*table)[i]));
	fclose(fp);

	return(1);
}
/* load an ascii table in my standard format */
load an ascii table in my standard format
load an ascii table in my standard format
IDL_LONG k_read_ascii_table(float **table,
														IDL_LONG *ndim,
														IDL_LONG **sizes,
														char filename[])
{
	IDL_LONG i,nelem;
	FILE *fp;
	FREEVEC((*table));
	FREEVEC((*sizes));
	fp=k_fileopen(filename,"r");
	fscanf(fp,"%d",ndim);
	if((*ndim)<=0) {
		fprintf(stderr,"k_read_ascii_table found 0-dimensional table in %s\n",
						filename);
		exit(1);
	} 
	nelem=1;
	(*sizes)=(IDL_LONG *) malloc((*ndim)*sizeof(IDL_LONG));
	for(i=0;i<(*ndim);i++) {
		fscanf(fp,"%d",&((*sizes)[i]));
		nelem*=(*sizes)[i];
	} 
	if(nelem<=0) {
		fprintf(stderr,"k_read_ascii_table found 0-size table in %s\n",
						filename);
		exit(1);
	} 
	(*table)=(float *) malloc(nelem*sizeof(float));
	for(i=0;i<nelem;i++) 
		fscanf(fp,"%f",&((*table)[i]));
	fclose(fp);
	return(1);
}
IDL_LONG k_read_ascii_table ( float * * table , IDL_LONG * ndim , IDL_LONG * * sizes , char filename [ ] ) { IDL_LONG i , nelem ; FILE * fp ; FREEVEC ( ( * table ) ) ; FREEVEC ( ( * sizes ) ) ; fp = k_fileopen ( filename , " " ) ; fscanf ( fp , " " , ndim ) ; if ( ( * ndim ) <= 0 ) { fprintf ( stderr , " \n " , filename ) ; exit ( 1 ) ; } nelem = 1 ; ( * sizes ) = ( IDL_LONG * ) malloc ( ( * ndim ) * sizeof ( IDL_LONG ) ) ; for ( i = 0 ; i < ( * ndim ) ; i ++ ) { fscanf ( fp , " " , & ( ( * sizes ) [ i ] ) ) ; nelem *= ( * sizes ) [ i ] ; } if ( nelem <= 0 ) { fprintf ( stderr , " \n " , filename ) ; exit ( 1 ) ; } ( * table ) = ( float * ) malloc ( nelem * sizeof ( float ) ) ; for ( i = 0 ; i < nelem ; i ++ ) fscanf ( fp , " " , & ( ( * table ) [ i ] ) ) ; fclose ( fp ) ; return ( 1 ) ; }
load an ascii table in my standard format
load an ascii table in my standard format
/* end if */ /* end for i */ /* end if */