/* * LIBML library - read, write and manipulate MATLAB MAT-files * Copyright (C) 1994 Michael J. Maurer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Michael Maurer * Durand Bldg - Room 232 * Stanford, CA 94305-4055 * (415) 723-1024 */ static char rcsid[]="$Id: matls.c,v 1.0 1992/04/15 23:07:24 maurer Stable $"; /****************************************************************************** matls.c Lists the variables in a (level 1) Matlab MAT file. Does not actually read the data into memory. Based on viewmat.c provided by the Mathworks with Matlab 3.5. 1991, Michael Maurer (maurer@nova.stanford.edu). ******************************************************************************/ /* $Log: matls.c,v $ * Revision 1.0 1992/04/15 23:07:24 maurer * Initial revision * */ #include #include #include #include "libml.h" #include "libml.p" #ifndef SEEK_SET #define SEEK_SET 0 #endif #define MATLS_C #include "matls.p" char *inname=NULL,*prog; FILE *infile; int main(argc,argv) int argc; char *argv[]; { long offset,nskip=0; char pname[20],*kind,*dt,*ord,*mach; int type,mrows,ncols,imagf,M,O,P,T,dsize,pf; prog=argv[0]; if (argc>1 && !strcmp(argv[1],"-h")) giveUsage(argv[0]); if (argc>2 && !strcmp(argv[1],"-s")) { nskip=atoi(argv[2]); argc-=2; argv+=2; } pf = argc>2; while (open_file(--argc,++argv)) { if (pf && argc>0) printf("%s:\n",*argv); if (nskip>0) fseek(infile,nskip,SEEK_SET); while (!mlreadh(infile,&type,pname,&mrows,&ncols,&imagf)) { dsize=mltype(type,&M,&O,&P,&T); offset = dsize*mrows*ncols; if (imagf) offset *= 2; if (T) kind="String"; else kind = (imagf) ? "Complex" : "Real"; switch (M*1000) { case ML_MIPS: mach = "MIPS"; break; case ML_SUN: mach = "Sun"; break; case ML_VAXD: mach = "VAX-D"; break; case ML_VAXG: mach = "VAX-G"; break; default: mach = "???"; break; } ord = (O) ? " (Row-major)" : ""; switch (P*10) { case ML_DOUBLE: dt = "double"; break; case ML_FLOAT: dt = "float "; break; case ML_INT: dt = "long "; break; case ML_SHORT: dt = "short "; break; case ML_USHORT: dt = "ushort"; break; case ML_UCHAR: dt = "uchar "; break; default: dt = "??????"; break; } printf("%15s %6d by %6d %7s %7d bytes %5s %s%s\n", pname,mrows,ncols,kind,offset,mach,dt,ord); if (fseek(infile,offset,1)) { fprintf(stderr,"%s: fseek failed\n",prog); exit(3); } } fclose(infile); if (argc>1) printf("\n"); } return 0; } int open_file(argc,argv) int argc; char *argv[]; { static first=1; if (argc > 0) inname = argv[0]; else if (!first) return 0; first=0; if ((!inname) || (!strcmp(inname,"-")) || (!strcmp(inname,"stdin"))) infile = stdin; else if (((infile = fopen(inname,"r")) == NULL) && ((infile = fopen(strcat(inname,".mat"),"r")) == NULL)) { fprintf(stderr,"%s: Unable to open %s for reading...aborting.\n",prog,inname); exit(1); } return 1; } void giveUsage(prog) char *prog; { fprintf(stderr,"\nUsage : %s [-s nskip] [infile ...]\n\n",prog); fprintf(stderr,"Fast listing of contents of .mat (Matlab) file.\n"); exit(1); }