#include "mat.h" char **matGetDir(fp,num)MATFile *fp;int *num;
integer*4 function matGetDir(fp,num)integer*4 fp, num
fpnum
matGetDir returns a pointer to an internal array containing pointers to the NULL-terminated names of the Matrices in the MAT-file pointed to by fp. The length of the internal array (number of Matrices in the MAT-file) is placed into num. The internal array is allocated using a single mxCalloc and must be freed using mxFree when you are finished with it.
matGetDir returns NULL if it fails.
MATLAB variable names can by up to length mxMAXNAM, where mxMAXNAM is defined in the file matrix.h.
/*The Fortran version of this program is inmattest7.c*/#include <stdio.h> #include "mat.h" main() { MATFile *fp;char **dir;int ndir,i; fp = matOpen("foo.mat","r"); dir = matGetDir(fp,&ndir); matClose(fp); if (dir == NULL) { printf("Can''t read directory.\n"); exit(0); } else { printf("Directory of MAT-file:\n"); for (i = 0; i < ndir; i++) { printf("%s\n",dir[i]); } } mxFree(dir); }
mattest7.f:
program maininteger*4 fp, dir, ndir, adir(100)character*20 names(100)fp = matOpen('foo.mat','r');dir = matGetDir(fp,ndir)if (dir .eq. 0) thenwrite (6,*) 'Can't read directory.'stopend ifc Copy pointer into an array of pointerscall mxCopyPtrToInteger4(dir, adir, ndir)c Copy pointer to character stringdo 20 i = 1,ndircall mxCopyPtrToCharacter(adir(i),names(i),20)20 continuewrite(6,*) 'Directory of MAT-file:'do 30 i = 1,ndirwrite(6,*) names(i)30 continuematClose(fp)stopend
(c) Copyright 1994 by The MathWorks, Inc.