libdspl-2.0
Digital Signal Processing Algorithm Library
|
Functions | |
int DSPL_API | readbin (char *fn, void **x, int *pn, int *pm, int *dtype) |
Read array from the bin-file. More... | |
int DSPL_API | writebin (void *x, int n, int m, int dtype, char *fn) |
Save 1D vector to the binary file. More... | |
int DSPL_API | writetxt (double *x, double *y, int n, char *fn) |
Save real data \(y(x)\) to the text file fn . . More... | |
int DSPL_API | writetxt_3d (double *x, int nx, double *y, int ny, double *z, char *fn) |
Save data \( z(x,y)\) to the text file fn for 3D surface plotting. More... | |
int DSPL_API | writetxt_int (int *x, int *y, int n, char *fn) |
Save interger data \(y(x)\) to the text file fn . . More... | |
Detailed Description
Function Documentation
◆ readbin()
int readbin | ( | char * | fn, |
void ** | x, | ||
int * | pn, | ||
int * | pm, | ||
int * | dtype | ||
) |
Read array from the bin-file.
Function reads real or complex 1D/2D array size n x m
from the binary file fn
.
File supports 1D and 2D arrays and has follow format:
type 4 bytes type int. Can take on value: DAT_DOUBLE, if x pointer to the real vector; DAT_COMPLEX, if x pointer to the complex vector; n 4 bytes type int. Number of array rows. m 4 bytes type int. Number of array columns. This parameter equals 1 because this function saves 1D vector. data Data in binary raw. Data size is: n * sizeof(double), if dtype==DAT_DOUBLE; n * sizeof(complex_t), if dtype==DAT_COMPLEX.
Binary file can be used for algorithms verification by external packages like GNU Octave, Matlab, Python because the function reads data without loss of accuracy.
- Parameters
-
[in] fn File name.
[in] x Pointer to the data memory.
Memory will be allocated for the output array.
[in] pn rows number.
[in] m Pointer to the columns number.
[in] dtype Type of data.
Can be one of follow:
DAT_DOUBLE
– real data;
DAT_COMPLEX
– complex data.
- Returns
RES_OK
if file read successfully.
Else code error.
Write bin-file in GNU Octave and Matlab:
Example:
◆ writebin()
int writebin | ( | void * | x, |
int | n, | ||
int | m, | ||
int | dtype, | ||
char * | fn | ||
) |
Save 1D vector to the binary file.
Function saves real or complex 1D vector size n
to the binary file fn
.
File format supports 1D and 2D arrays and has follow format:
type 4 bytes type int. Can take on value: DAT_DOUBLE, if x pointer to the real vector; DAT_COMPLEX, if x pointer to the complex vector; n 4 bytes type int. Number of array rows. m 4 bytes type int. Number of array columns. This parameter equals 1 because this function saves 1D vector. data Data in binary raw. Data size is: n * sizeof(double), if dtype==DAT_DOUBLE; n * sizeof(complex_t), if dtype==DAT_COMPLEX.
Binary file can be used for algorithms verification by external packages like GNU Octave, Matlab, Python because the function writes to a file without loss of accuracy.
- Parameters
-
[in] x Pointer to the input vector.
Vector size is[n x 1]
.
[in] n Rows number.
[in] m Columns number.
[in] dtype Type of data.
Can be one of follow:
DAT_DOUBLE
– real data;
DAT_COMPLEX
– complex data.
[in] fn File name.
- Returns
RES_OK
if file is saved successfully.
Else code error.
Reading saved binary file from GNU Octave or Matlab:
Definition at line 217 of file writebin.c.
◆ writetxt()
int writetxt | ( | double * | x, |
double * | y, | ||
int | n, | ||
char * | fn | ||
) |
Save real data \(y(x)\) to the text file fn
.
.
File format is:
x[0] y[0] x[1] y[1] ... ... x[n-1] y[n-1]
Text file can be used to plotting data with a third-party program for example, the GNUPLOT package (see Plotting data by Gnuplot interface.).
- Parameters
-
[in] x Pointer to the vector x
.
Vector size is[n x 1]
.
[in] y Pointer to the vector y
.
Vector size is[n x 1]
.
This pointer can beNULL
. File will have only one column corresponds tox
vector in this case.
[in] n Size of vectors x
andy
.
[in] fn File name.
- Returns
RES_OK
if file is saved successfully.
Else code error.
- Note
- This function rounds data when writing to a file. So, it is not recommended to use it to verify algorithms.
Definition at line 122 of file writetxt.c.
◆ writetxt_3d()
int writetxt_3d | ( | double * | x, |
int | nx, | ||
double * | y, | ||
int | ny, | ||
double * | z, | ||
char * | fn | ||
) |
Save data \( z(x,y)\) to the text file fn
for 3D surface plotting.
Function \( z(x,y)\) describes as matrix z[x[n], y[n]]
as it showed on the follow figure:
Matrix z
writen in the memory by columns as it it showed on the figure by red arrow.
Text file fas follow format:
x[0] y[0] z[0, 0] x[1] y[0] z[1, 0] x[2] y[0] z[2, 0] ... ... ... x[nx-1] y[0] z[nx-1, 0] x[0] y[1] z[0, 1] x[1] y[1] z[1, 1] x[2] y[1] z[2, 1] ... ... ... x[nx-1] y[1] z[nx-1, 1] ... ... ... ... ... ... ... ... ... x[0] y[ny-1] z[0, ny-1] x[1] y[ny-1] z[1, ny-1] x[2] y[ny-1] z[2, ny-1] ... ... ... x[nx-1] y[ny-1] z[nx-1, ny-1]
Each z
matrix value is writen on individual line corresponds to x
and y
values. Matrix columns are separated from each other by an empty line.
The file can be used to build a 3D surface with a third-party program for example, the GNUPLOT package (see Plotting data by Gnuplot interface.). Also this format supported by pgfplot3d packages of the Latex system.
- Parameters
-
[in] x Pointer to the vector x
.
Vector size is[nx x 1]
.
[in] nx Size of vector x
.
[in] y Pointer to the vector y
.
Vector size is[ny x 1]
.
[in] ny Size of vector y
.
[in] z Pointer to the matrix z(x, y)
.
Size of matrix is[nx x ny]
.
[in] fn 3D data file name.
- Returns
RES_OK
if file is saved successfully.
Else code error.
Example of 3D surface plotting:
Program calcultes function
\[ z(x,y) = x \exp(-x^2 -y^2) \]
and save data to the dat/data3d.txt
file.
In addition, GNUPLOT built a 3D surface by data saved to the dat/data3d.txt
file:
Definition at line 214 of file writetxt_3d.c.
◆ writetxt_int()
int writetxt_int | ( | int * | x, |
int * | y, | ||
int | n, | ||
char * | fn | ||
) |
Save interger data \(y(x)\) to the text file fn
.
.
File format
x[0] y[0] x[1] y[1] ... ... x[n-1] y[n-1]
Text file can be used to plotting data with a third-party program for example, the GNUPLOT package (see Plotting data by Gnuplot interface.).
- Parameters
-
[in] x Pointer to the interger vector x
.
Vector size is[n x 1]
.
[in] y Pointer to the interger vector y
.
Vector size is[n x 1]
.
This pointer can beNULL
. File will have only one column corresponds tox
vector in this case.
[in] n Size of vectors x
andy
.
[in] fn File name.
- Returns
RES_OK
if file is saved successfully.
Else code error.
Definition at line 115 of file writetxt_int.c.
Generated on Wed Jan 5 2022 12:44:37 for libdspl-2.0 by 1.9.2