Debian Codegraph @

matio-1.5.30/documentation/Mat_VarWrite.3

raw
1 .\" Copyright (c) 2015-2026, The matio contributors
2 .\" Copyright (c) 2012-2014, Christopher C. Hulbert
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions are met:
7 .\"
8 .\" 1. Redistributions of source code must retain the above copyright notice, this
9 .\" list of conditions and the following disclaimer.
10 .\"
11 .\" 2. Redistributions in binary form must reproduce the above copyright notice,
12 .\" this list of conditions and the following disclaimer in the documentation
13 .\" and/or other materials provided with the distribution.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 .\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 .\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 .\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 .\"
26 .Dd September 12, 2019
27 .Dt MAT_VARWRITE 3
28 .Os
29 .Sh NAME
30 .Nm Mat_VarWrite
31 .Nd Writes a MATLAB variable to a MATLAB MAT file.
32 .Sh SYNOPSIS
33 .Fd #include <matio.h>
34 .Ft int
35 .Fo Mat_VarWrite
36 .Fa "mat_t *matfp"
37 .Fa "matvar_t *matvar"
38 .Fa "enum matio_compression compress"
39 .Fc
40 .Sh DESCRIPTION
41 The
42 .Fn Mat_VarWrite
43 function writes the MATLAB variable
44 .Fa matvar
45 to the MAT file
46 .Fa matfp
47 which must be opened for writing. If the MAT file is a version 5 or HDF5 MAT
48 file, the
49 .Fa compress
50 option allows the variable to be written using zlib compression if available.
51 If compression is not available, the variable is written uncompressed.
52 .Sh RETURN VALUES
53 The function returns 0 if the variable was successfully written to the MAT file.
54 Otherwise, an error value is returned.
55 .Sh EXAMPLES
56 This example program creates a MAT file named by the first argument to the
57 program, and writes the variable named
58 .Em m_pi
59 to the file.
60 .Bd -literal
61 #include <math.h>
62 #include "matio.h"
63
64 int
65 main(int argc, char **argv)
66 {
67 mat_t *matfp;
68 matvar_t *matvar;
69 size_t dims[2] = {1, 1};
70 double m_pi = M_PI;
71
72 matfp = Mat_CreateVer(argv[1], NULL, MAT_FT_DEFAULT);
73 if ( NULL == matfp ) {
74 fprintf(stderr, "Error creating MAT file %s\n", argv[1]);
75 return EXIT_FAILURE;
76 }
77
78 matvar = Mat_VarCreate("m_pi", MAT_C_DOUBLE, MAT_T_DOUBLE,
79 2, dims, &m_pi, 0);
80 if ( NULL != matvar ) {
81 Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB);
82 Mat_VarFree(matvar);
83 }
84
85 Mat_Close(matfp);
86 return EXIT_SUCCESS;
87 }
88
89 .Ed
90 .Sh SEE ALSO
91 .Xr Mat_CreateVer 3 ,
92 .Xr Mat_Open 3 ,
93 .Xr Mat_VarRead 3 ,
94 .Xr Mat_VarWriteAppend 3