Debian Codegraph @

matio-1.5.30/documentation/Mat_Rewind.3

raw
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 September 12, 2019
27 .Dt MAT_REWIND 3
28 .Os
29 .Sh NAME
30 .Nm Mat_Rewind
31 .Nd Rewinds an open MAT file to the beginning.
32 .Sh SYNOPSIS
33 .Fd #include <matio.h>
34 .Ft int
35 .Fo Mat_Rewind
36 .Fa "mat_t *matfp"
37 .Fc
38 .Sh DESCRIPTION
39 Rewinds an open MAT file so that
40 .Fn Mat_VarReadNext
41 or
42 .Fn Mat_VarReadNextInfo
43 reads the first variable in the file.
44 .Sh RETURN VALUES
45 The function returns 0 on success, or -1 on failure.
46 .Sh EXAMPLES
47 The following example shows a list of variables in the MAT file, and prompts the
48 user for the index of the variable to read.
49 If the index is valid, the file is
50 reset to the beginning, and variables read until the selected index is reached.
51 .Bd -literal
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include "matio.h"
55
56 int
57 main(int argc, char **argv)
58 {
59 mat_t *matfp;
60 matvar_t *matvar;
61 int idx, num_variables;
62
63 matfp = Mat_Open(argv[1], MAT_ACC_RDONLY);
64 if ( NULL == matfp ) {
65 fprintf(stderr, "Error opening MAT file %s\n", argv[1]);
66 return EXIT_FAILURE;
67 }
68
69 idx = 0;
70 while ( NULL != (matvar = Mat_VarReadNextInfo(matfp)) ) {
71 idx++;
72 printf("%3d. %s\n", idx, matvar->name);
73 Mat_VarFree(matvar);
74 }
75 num_variables = idx;
76 if ( num_variables > 0 ) {
77 printf("Which variable would you like to read? ");
78 if ( 0 == fscanf(stdin,"%d",&idx) ) {
79 printf("Invalid variable selection!\n");
80 } else if ( idx < 1 || idx > num_variables ) {
81 fprintf(stderr, "That is an invalid variable index!\n");
82 } else {
83 int k;
84 Mat_Rewind(matfp);
85 for ( k = 1; k < idx; k++ ) {
86 matvar = Mat_VarReadNextInfo(matfp);
87 Mat_VarFree(matvar);
88 }
89 matvar = Mat_VarReadNext(matfp);
90 Mat_VarPrint(matvar, 1);
91 Mat_VarFree(matvar);
92 }
93 }
94
95 Mat_Close(matfp);
96 return EXIT_SUCCESS;
97 }
98 .Ed
99 .Sh SEE ALSO
100 .Xr Mat_Open 3 ,
101 .Xr Mat_Close 3 ,
102 .Xr Mat_VarReadNext 3 ,
103 .Xr Mat_VarReadNextInfo 3 ,
104 .Xr Mat_VarPrint 3