1MAT_VARCREATE(3)         BSD Library Functions Manual         MAT_VARCREATE(3)
2

NAME

4     Mat_VarCreate — Creates a MAT variable structure.
5

SYNOPSIS

7     #include <matio.h>
8
9     matvar_t *
10     Mat_VarCreate(const char *name, enum matio_classes class_type,
11         enum matio_types data_type, int rank, size_t *dims, void *data,
12         int opt);
13

DESCRIPTION

15     The Mat_VarCreate() function creates a MAT structure variable named name
16     that can be written to a MAT file.  The class_type argument specifies the
17     class of the variable, and the data_type argument specifies the type of
18     the data.  For example, a double-precision class would use MAT_C_DOUBLE
19     for the class type and MAT_T_DOUBLE for the data type.  In some
20     instances, the data type may not match the class type.  For example, an
21     array of integers can be written in the double-precision class by using
22     MAT_T_INT32 for data_type.
23
24     The rank argument specifies how many dimensions the data has.  The mini‐
25     mum rank is 2.  The number of elements in each dimension is specified in
26     the array dims.
27
28     The data argument is a pointer to the variable data.  The pointer is typ‐
29     ically a pointer to a numeric array (e.g. double, float, int, etc.) for
30     real variables.  For complex variables, the pointer is a pointer to a
31     mat_complex_split_t which contains pointers to the real and imaginary
32     data as fields of the structure.  For sparse variables, the pointer
33     should be a mat_sparse_t *.
34

RETURN VALUES

36     If the variable was successfully created, a pointer to the variable is
37     returned.  Otherwise NULL is returned.  The variable should be free'd
38     when no longer needed using Mat_VarFree().
39

EXAMPLES

41     The example program below creates a MAT file named test.mat, and writes
42     two real numeric variables x and y and a complex variable z to the file.
43
44     #include <stdlib.h>
45     #include <stdio.h>
46     #include "matio.h"
47
48     int
49     main(int argc,char **argv)
50     {
51         mat_t    *matfp;
52         matvar_t *matvar;
53         size_t    dims[2] = {10,1};
54         double    x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10},
55                   y[10] = {11,12,13,14,15,16,17,18,19,20};
56         struct mat_complex_split_t z = {x, y};
57
58         matfp = Mat_CreateVer("test.mat", NULL, MAT_FT_DEFAULT);
59         if ( NULL == matfp ) {
60             fprintf(stderr, "Error creating MAT file
61             return EXIT_FAILURE;
62         }
63
64         matvar = Mat_VarCreate("x", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, x, 0);
65         if ( NULL == matvar ) {
66             fprintf(stderr, "Error creating variable for 'x'0);
67         } else {
68             Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
69             Mat_VarFree(matvar);
70         }
71
72         matvar = Mat_VarCreate("y", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, y, 0);
73         if ( NULL == matvar ) {
74             fprintf(stderr, "Error creating variable for 'y'0);
75         } else {
76             Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
77             Mat_VarFree(matvar);
78         }
79
80         matvar = Mat_VarCreate("z", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &z,
81                      MAT_F_COMPLEX);
82         if ( NULL == matvar ) {
83             fprintf(stderr, "Error creating variable for 'z'0);
84         } else {
85             Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
86             Mat_VarFree(matvar);
87         }
88
89         Mat_Close(matfp);
90         return EXIT_SUCCESS;
91     }
92

SEE ALSO

94     Mat_VarCreateStruct(3), Mat_VarFree(3), Mat_VarWrite(3)
95
96BSD                           September 12, 2019                           BSD
Impressum