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

NAME

4     Mat_VarCreateStruct — Creates a structure variable.
5

SYNOPSIS

7     #include <matio.h>
8
9     matvar_t *
10     Mat_VarCreateStruct(const char *name, int rank, size_t *dims,
11         const char **fields, unsigned nfields);
12

DESCRIPTION

14     The Mat_VarCreateStruct() function creates a structure variable named
15     name that can be written to a MAT file.
16

RETURN VALUES

18     If the structure variable was successfully created, a pointer to the
19     variable is returned. Otherwise NULL is returned. The structure variable
20     pointer should be free'd when no longer needed using Mat_VarFree(3) after
21     calling the function if necessary.
22

EXAMPLES

24     This example program opens a MAT file named by the first argument to the
25     program, and writes a structure named a to the file.
26
27     #include "matio.h"
28
29     int
30     main(int argc,char **argv)
31     {
32         mat_t    *matfp;
33         matvar_t *matvar;
34         matvar_t *field;
35         const char *fields[2] = {"field1","field2"};
36         double       data1 = 1, data2 = 2;
37         size_t       dims[2] = {1, 1};
38
39         matfp = Mat_Open(argv[1],MAT_ACC_RDWR);
40         if ( NULL == matfp ) {
41             fprintf(stderr,"Error opening MAT file %s0,argv[1]);
42             return EXIT_FAILURE;
43         }
44
45         dims[0] = 1; dims[1] = 1;
46         matvar = Mat_VarCreateStruct("a",2,dims,fields,2);
47         if ( NULL == matvar ) {
48             Mat_Close(matfp);
49             return EXIT_FAILURE;
50         }
51
52         field = Mat_VarCreate(NULL,MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,&data1,
53                     MAT_F_DONT_COPY_DATA);
54         Mat_VarSetStructFieldByName(matvar, "field1", 0, field);
55
56         field = Mat_VarCreate(NULL,MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,&data2,
57                     MAT_F_DONT_COPY_DATA);
58         Mat_VarSetStructFieldByName(matvar, "field2", 0, field);
59
60         Mat_VarWrite(matfp,matvar,MAT_COMPRESSION_NONE);
61         Mat_VarFree(matvar);
62
63         Mat_Close(matfp);
64         return EXIT_SUCCESS;
65     }
66

SEE ALSO

68     Mat_VarCreate(3), Mat_VarSetStructFieldByName(3)
69
70BSD                             March 18, 2012                             BSD
Impressum