Debian Codegraph @

matio-1.5.30/documentation/Mat_VarCreateStruct.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 January 5, 2026
27 .Dt MAT_VARCREATESTRUCT 3
28 .Os
29 .Sh NAME
30 .Nm Mat_VarCreateStruct
31 .Nd Creates a structure variable.
32 .Sh SYNOPSIS
33 .Fd #include <matio.h>
34 .Ft matvar_t *
35 .Fo Mat_VarCreateStruct
36 .Fa "const char *name"
37 .Fa "int rank"
38 .Fa "const size_t *dims"
39 .Fa "const char *const *fields"
40 .Fa "unsigned nfields"
41 .Fc
42 .Sh DESCRIPTION
43 The
44 .Fn Mat_VarCreateStruct
45 function creates a structure variable named
46 .Fa name
47 that can be written to a MAT file.
48 .Sh RETURN VALUES
49 If the structure variable was successfully created, a pointer to the variable
50 is returned.
51 Otherwise NULL is returned.
52 The structure variable pointer should be free'd when no longer needed using
53 .Fn Mat_VarFree .
54 The names of the fields are copied in the function, and thus should be released
55 after calling the function if necessary.
56 .SH DEPRECATED
57 This function is deprecated since version 1.5.30.
58 Use \fBMat_VarCreateStruct2\fP instead.
59 .Sh EXAMPLES
60 This example program opens a MAT file named by the first argument to the
61 program, and writes a structure named
62 .Em a
63 to the file.
64 .Bd -literal
65 #include "matio.h"
66
67 int
68 main(int argc, char **argv)
69 {
70 mat_t *matfp;
71 matvar_t *matvar;
72 matvar_t *field;
73 const char *fields[2] = {"field1", "field2"};
74 double data1 = 1, data2 = 2;
75 size_t dims[2] = {1, 1};
76
77 matfp = Mat_Open(argv[1], MAT_ACC_RDWR);
78 if ( NULL == matfp ) {
79 fprintf(stderr, "Error opening MAT file %s\n", argv[1]);
80 return EXIT_FAILURE;
81 }
82
83 dims[0] = 1; dims[1] = 1;
84 matvar = Mat_VarCreateStruct("a", 2, dims, fields, 2);
85 if ( NULL == matvar ) {
86 Mat_Close(matfp);
87 return EXIT_FAILURE;
88 }
89
90 field = Mat_VarCreate(NULL, MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &data1,
91 MAT_F_DONT_COPY_DATA);
92 Mat_VarSetStructFieldByName(matvar, "field1", 0, field);
93
94 field = Mat_VarCreate(NULL, MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &data2,
95 MAT_F_DONT_COPY_DATA);
96 Mat_VarSetStructFieldByName(matvar, "field2", 0, field);
97
98 Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
99 Mat_VarFree(matvar);
100
101 Mat_Close(matfp);
102 return EXIT_SUCCESS;
103 }
104 .Ed
105 .Sh SEE ALSO
106 .Xr Mat_VarCreateStruct2 3 ,
107 .Xr Mat_VarCreate 3 ,
108 .Xr Mat_VarSetStructFieldByName 3