function table = data_read ( input_filename, m, n ) %*****************************************************************************80 % %% DATA_READ reads data from a file. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 31 July 2004 % % Author: % % John Burkardt % % Parameters: % % Input, character ( len = * ) INPUT_FILENAME, the name of the input file. % % Input, integer M, the number of spatial dimensions. % % Input, integer N, the number of points. The program % will stop reading data once N values have been read. % % Output, real TABLE(M,N), the point coordinates. % % % Build up the format string for reading M real numbers. % string = ' '; for i = 0 : m string = strcat ( string, ' %f' ); end input_unit = fopen ( input_filename ); if ( input_unit < 0 ) fprintf ( 1, '\n' ); fprintf ( 1, 'DATA_READ - Error!\n' ); fprintf ( 1, ' Could not open the input file.\n' ); error ( 'DATA_READ - Error!' ); return; end i = 0; while ( i < n ) line = fgets ( input_unit ); if ( line == -1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'DATA_READ - Error!\n' ); fprintf ( 1, ' End of input while reading data.\n' ); error ( 'DATA_READ - Error!' ); end if ( line(1) == '#' ) elseif ( s_len_trim ( line ) == 0 ) else [ x, count ] = sscanf ( line, string ); if ( count == m ) i = i + 1; table(1:m,i) = x(1:m); end end end fclose ( input_unit ); return end