Go to the first, previous, next, last section, table of contents.

Reading and writing matrices

The library provides functions for reading and writing matrices to a file as binary data or formatted text.

Function: int gsl_matrix_fwrite (FILE * stream, const gsl_matrix * m)
This function writes the elements of the matrix m to the stream stream in binary format. The return value is 0 for success and GSL_EFAILED if there was a problem writing to the file. Since the data is written in the native binary format it may not be portable between different architectures.

Function: int gsl_matrix_fread (FILE * stream, gsl_matrix * m)
This function reads into the matrix m from the open stream stream in binary format. The matrix m must be preallocated with the correct dimensions since the function uses the size of m to determine how many bytes to read. The return value is 0 for success and GSL_EFAILED if there was a problem reading from the file. The data is assumed to have been written in the native binary format on the same architecture.

Function: int gsl_matrix_fprintf (FILE * stream, const gsl_matrix * m, const char * format)
This function writes the elements of the matrix m line-by-line to the stream stream using the format specifier format, which should be one of the %g, %e or %f formats for floating point numbers and %d for integers. The function returns 0 for success and GSL_EFAILED if there was a problem writing to the file.

Function: int gsl_matrix_fscanf (FILE * stream, gsl_matrix * m)
This function reads formatted data from the stream stream into the matrix m. The matrix m must be preallocated with the correct dimensions since the function uses the size of m to determine how many numbers to read. The function returns 0 for success and GSL_EFAILED if there was a problem reading from the file.


Go to the first, previous, next, last section, table of contents.