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 instances,
20     the data type may not match the class type. For exmaple, an array of
21     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 minimum
25     rank is 2. The number of elements in each dimension is specified in the
26     array dims.
27
28     The data argument is a pointer to the variable data. The pointer is typi‐
29     cally 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 should
33     be a mat_sparse_t *.
34
35

RETURN VALUES

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

EXAMPLES

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

SEE ALSO

95     Mat_VarCreateStruct(3), Mat_VarFree(3), Mat_VarWrite(3)
96
97BSD                             March 18, 2012                             BSD
Impressum