Debian Codegraph @

matio-1.5.30/documentation/Mat_VarCreate.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 October 26, 2025
27 .Dt MAT_VARCREATE 3
28 .Os
29 .Sh NAME
30 .Nm Mat_VarCreate
31 .Nd Creates a MAT variable structure.
32 .Sh SYNOPSIS
33 .Fd #include <matio.h>
34 .Ft matvar_t *
35 .Fo Mat_VarCreate
36 .Fa "const char *name"
37 .Fa "enum matio_classes class_type"
38 .Fa "enum matio_types data_type"
39 .Fa "int rank"
40 .Fa "const size_t *dims"
41 .Fa "const void *data"
42 .Fa "int opt"
43 .Fc
44 .Sh DESCRIPTION
45 The
46 .Fn Mat_VarCreate
47 function creates a MAT structure variable named
48 .Fa name
49 that can be written to a MAT file.
50 The
51 .Fa class_type
52 argument specifies the class of the variable, and the
53 .Fa data_type
54 argument specifies the type of the data.
55 For example, a double-precision class would use
56 .Dv MAT_C_DOUBLE
57 for the class type and
58 .Dv MAT_T_DOUBLE
59 for the data type.
60 In some instances, the data type may not match the class type.
61 For example, an array of integers can be written in the double-precision
62 class by using
63 .Dv MAT_T_INT32
64 for
65 .Fa data_type.
66 .Pp
67 The
68 .Fa rank
69 argument specifies how many dimensions the data has.
70 The number of elements in each dimension is specified in the array
71 .Fa dims.
72 .Pp
73 The
74 .Fa data
75 argument is a pointer to the variable data.
76 The pointer is typically a pointer to a numeric array (e.g. double, float, int,
77 etc.) for real variables.
78 For complex variables, the pointer is a pointer to a
79 .Vt mat_complex_split_t
80 which contains pointers to the real and imaginary data as fields of the
81 structure.
82 For sparse variables, the pointer should be a
83 .Vt mat_sparse_t *.
84 .Sh RETURN VALUES
85 If the variable was successfully created, a pointer to the variable is returned.
86 Otherwise NULL is returned.
87 The variable should be free'd when no longer needed
88 using
89 .Fn Mat_VarFree .
90 .Sh EXAMPLES
91 The example program below creates a MAT file named
92 .Va test.mat,
93 and writes two real numeric variables
94 .Va x
95 and
96 .Va y
97 and a complex variable
98 .Va z
99 to the file.
100 .Bd -literal
101 #include <stdlib.h>
102 #include <stdio.h>
103 #include "matio.h"
104
105 int
106 main(int argc,char **argv)
107 {
108 mat_t *matfp;
109 matvar_t *matvar;
110 size_t dims[2] = {10,1};
111 double x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10},
112 y[10] = {11,12,13,14,15,16,17,18,19,20};
113 struct mat_complex_split_t z = {x, y};
114
115 matfp = Mat_CreateVer("test.mat", NULL, MAT_FT_DEFAULT);
116 if ( NULL == matfp ) {
117 fprintf(stderr, "Error creating MAT file \"test.mat\"\n");
118 return EXIT_FAILURE;
119 }
120
121 matvar = Mat_VarCreate("x", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, x, 0);
122 if ( NULL == matvar ) {
123 fprintf(stderr, "Error creating variable for 'x'\n");
124 } else {
125 Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
126 Mat_VarFree(matvar);
127 }
128
129 matvar = Mat_VarCreate("y", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, y, 0);
130 if ( NULL == matvar ) {
131 fprintf(stderr, "Error creating variable for 'y'\n");
132 } else {
133 Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
134 Mat_VarFree(matvar);
135 }
136
137 matvar = Mat_VarCreate("z", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &z,
138 MAT_F_COMPLEX);
139 if ( NULL == matvar ) {
140 fprintf(stderr, "Error creating variable for 'z'\n");
141 } else {
142 Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
143 Mat_VarFree(matvar);
144 }
145
146 Mat_Close(matfp);
147 return EXIT_SUCCESS;
148 }
149 .Ed
150 .Sh SEE ALSO
151 .Xr Mat_VarCreateStruct 3 ,
152 .Xr Mat_VarFree 3 ,
153 .Xr Mat_VarWrite 3