/* * whomat.c - Examine a binary MAT file and print a list * of the contents (like "who" or "whos"). * * Mastering MATLAB MAT-file Example * */ /* B.R. Littlefield, University of Maine, Orono, ME 04469 * 7/21/00 * Mastering MATLAB 6, Prentice Hall, ISBN 0-13-019468-9 */ #include "mat.h" #include int whomat(const char *filename) { MATFile *mfile; mxArray *marray; char **dir; char siz[25], buf[10]; int i, j, k, num, nel, elsize, ndim, eltot, btot; const int *dims; /* Open the MAT file for reading. */ mfile = matOpen(filename, "r"); if (mfile == NULL) { printf("Cannot open %s for reading.\n", filename); return(EXIT_FAILURE); } /* Get the directory list and print in "who" format. */ dir = matGetDir(mfile, &num); if (dir == NULL) { printf("Error reading the directory of %s.\n", filename); return(EXIT_FAILURE); } else { printf("\n"); printf("Variables in %s are:\n\n", filename); for (i=0; i0 && i%4==0) printf("\n"); } } /* Examine each variable and print a "whos" list. */ eltot=btot=0; printf("\n\n Name Size Bytes Class\n\n"); for (i=0; i 1) status = whomat(argv[1]); else{ status = EXIT_FAILURE; printf("Usage: whomat "); } return(status); }