1MAT_VARREADNEXTINFO(3) BSD Library Functions Manual MAT_VARREADNEXTINFO(3)
2
4 Mat_VarReadNextInfo — Reads the information for the next variable in a
5 MATLAB MAT file.
6
8 #include <matio.h>
9
10 matvar_t *
11 Mat_VarReadNextInfo(mat_t *matfp);
12
14 The Mat_VarReadNextInfo() function reads the information for the next
15 variable stored in the open MAT file.
16
18 If there is another variable in the MAT file and is read successfully, a
19 pointer to the MATLAB variable structure is returned. If there are no
20 more variables, or there was an error reading the variable, NULL is
21 returned.
22
24 This example program opens a MAT file named by the first argument to the
25 program, and uses Mat_VarReadNextInfo() to read the information about
26 each variable in the file. For each variable read, the name, size, and
27 class are printed in a format similar to the MATLAB whos command.
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include "matio.h"
32
33 static char *mxclass[17] = {"cell", "struct", "object", "char", "sparse",
34 "double", "single", "int8", "uint8", "int16",
35 "uint16", "int32", "uint32", "int64", "uint64",
36 "function", "opaque"
37 };
38
39 int
40 main(int argc, char **argv)
41 {
42 mat_t *matfp;
43 matvar_t *matvar;
44 char size[32] = {' ',};
45
46 matfp = Mat_Open(argv[1], MAT_ACC_RDONLY);
47 if ( NULL == matfp ) {
48 fprintf(stderr, "Error opening MAT file %s0, argv[1]);
49 return EXIT_FAILURE;
50 }
51
52 printf("%-20s %-10s %-10s %-18s0, "Name", "Size",
53 "Bytes", "Class");
54 while ( NULL != (matvar = Mat_VarReadNextInfo(matfp)) ) {
55 printf("%-20s", matvar->name);
56 if ( matvar->rank > 0 ) {
57 int cnt = 0;
58 int i;
59 printf("%8d", matvar->dims[0]);
60 for ( i = 1; i < matvar->rank; i++ ) {
61 if ( ceil(log10(matvar->dims[i])) + 1 < 32 )
62 cnt += sprintf(size + cnt, "x%d", matvar->dims[i]);
63 }
64 printf("%-10s", size);
65 } else {
66 printf(" ");
67 }
68 printf(" %-18s0, mxclass[matvar->class_type - 1]);
69
70 Mat_VarFree(matvar);
71 }
72
73 Mat_Close(matfp);
74 return EXIT_SUCCESS;
75 }
76
78 Mat_VarRead(3), Mat_VarReadInfo(3), Mat_VarReadNext(3)
79
80BSD September 12, 2019 BSD