| 1 |
.\" Copyright (c) 2015-2026, The matio contributors |
| 2 |
.\" Copyright (c) 2011-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 March 4, 2024 |
| 27 |
.Dt MAT_VARREADNEXTINFO 3 |
| 28 |
.Os |
| 29 |
.Sh NAME |
| 30 |
.Nm Mat_VarReadNextInfo |
| 31 |
.Nd Reads the information for the next variable in a MATLAB MAT file. |
| 32 |
.Sh SYNOPSIS |
| 33 |
.Fd #include <matio.h> |
| 34 |
.Ft matvar_t * |
| 35 |
.Fo Mat_VarReadNextInfo |
| 36 |
.Fa "mat_t *matfp" |
| 37 |
.Fc |
| 38 |
.Sh DESCRIPTION |
| 39 |
The |
| 40 |
.Fn Mat_VarReadNextInfo |
| 41 |
function reads the information for the next variable stored in the open MAT |
| 42 |
file. |
| 43 |
.Sh RETURN VALUES |
| 44 |
If there is another variable in the MAT file and is read successfully, a pointer |
| 45 |
to the MATLAB variable structure is returned. If there are no more variables, or |
| 46 |
there was an error reading the variable, NULL is returned. |
| 47 |
.Sh EXAMPLES |
| 48 |
This example program opens a MAT file named by the first argument to the |
| 49 |
program, and uses |
| 50 |
.Fn Mat_VarReadNextInfo |
| 51 |
to read the information about each variable in the file. |
| 52 |
For each variable read, the name, size, and class are printed in a format |
| 53 |
similar to the MATLAB whos command. |
| 54 |
.Bd -literal |
| 55 |
#include <math.h> |
| 56 |
#include <stdlib.h> |
| 57 |
#include <stdio.h> |
| 58 |
#include "matio.h" |
| 59 |
|
| 60 |
static char *mxclass[17] = {"cell", "struct", "object", "char", "sparse", |
| 61 |
"double", "single", "int8", "uint8", "int16", |
| 62 |
"uint16", "int32", "uint32", "int64", "uint64", |
| 63 |
"function", "opaque" |
| 64 |
}; |
| 65 |
|
| 66 |
int |
| 67 |
main(int argc, char **argv) |
| 68 |
{ |
| 69 |
mat_t *matfp; |
| 70 |
matvar_t *matvar; |
| 71 |
char size[32] = {'\0',}; |
| 72 |
|
| 73 |
matfp = Mat_Open(argv[1], MAT_ACC_RDONLY); |
| 74 |
if ( NULL == matfp ) { |
| 75 |
fprintf(stderr, "Error opening MAT file %s\n", argv[1]); |
| 76 |
return EXIT_FAILURE; |
| 77 |
} |
| 78 |
|
| 79 |
printf("%-32s%-16s%-16s%-16s\n\n", "Name", "Size", "Bytes", "Class"); |
| 80 |
while ( NULL != (matvar = Mat_VarReadNextInfo(matfp)) ) { |
| 81 |
printf("%-32s", matvar->name); |
| 82 |
if ( matvar->rank > 0 ) { |
| 83 |
int cnt; |
| 84 |
int i; |
| 85 |
cnt = snprintf(size, sizeof(size), "%zd", matvar->dims[0]); |
| 86 |
for ( i = 1; i < matvar->rank; i++ ) { |
| 87 |
if ( ceil(log10((double)matvar->dims[i])) + 1 < 32 ) { |
| 88 |
cnt += snprintf(size + cnt, sizeof(size) - cnt, |
| 89 |
"x%zd", matvar->dims[i]); |
| 90 |
if ( cnt >= sizeof(size) ) { |
| 91 |
break; |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
printf("%-16s", size); |
| 96 |
} else { |
| 97 |
printf(" "); |
| 98 |
} |
| 99 |
snprintf(size, sizeof(size), "%zd", Mat_VarGetSize(matvar)); |
| 100 |
printf("%-16s", size); |
| 101 |
printf("%-16s\n", mxclass[matvar->class_type - 1]); |
| 102 |
|
| 103 |
Mat_VarFree(matvar); |
| 104 |
} |
| 105 |
|
| 106 |
Mat_Close(matfp); |
| 107 |
return EXIT_SUCCESS; |
| 108 |
} |
| 109 |
.Ed |
| 110 |
.Sh SEE ALSO |
| 111 |
.Xr Mat_VarRead 3 , |
| 112 |
.Xr Mat_VarReadInfo 3 , |
| 113 |
.Xr Mat_VarReadNext 3 |