/* ** Program: dat2mat.c ** Author: Steve Mann, 1992 Aug 8 (working with szummer: set MATLAB=/mas/lib/$MACHTYPE/matlab.4.2 to compile: cc dat2mat.c -I/mas/vision/include/common \ -I$MATLAB/extern/include \ $MATLAB/extern/lib/$MACHTYPE/libmat.a \ -L/mas/vision/lib/$MACHTYPE -ldat -lm szummer break (compile first then incrememtally link) compile: to compile: cc +w1 -c dat2mat.c -I/mas/vision/include/common\ -I$MATLAB/extern/include cc -c mat link: cc dat2mat.o -L/mas/vision/lib/$MACHTYPE -ldat -lm +w1 gives warnings */ #include #include #include #include #include /* garden #include #include */ /* vismod */ #include #include /* local function */ static void Check_Infile(DATFILE *infile, int *nsets,int *nchans,int *hdim,int *vdim); #define DEBUG 0 #define DEBUGEVERYPEL 0 #define GCC 0 /* *********************** main program ******************************* */ /* void main (argc, argv) szummer's suggestion, change to int */ int main (argc, argv) int argc; #if GCC const char *const argv[]; /* gcc WILL NOT WORK; produces strange matrices */ #endif char *argv[]; { register long MN, mn; /* running index of the matrix */ DATFILE *infile; /* datfile input */ FILE *fd_out; /* Matlab matrix output */ char fd_string[256]; FILE *fopen(); unsigned char *inbuf; int nsets, dset, dchan, nchans; /* dset is frame count, dchan color count*/ int in_size; /* number of pixels, not number of bytes */ int in_hdim, in_vdim; boolean verbose = FALSE; char name[20]; /* Matlab matrix variable name */ int type, mrows, ncols, imagf; unsigned short *matrixrint, *matrixiint; /* real and imag integer matrices*/ /* Parse command line and set up */ scanargv(argc, argv, "%s [-v]", "%r %s [ -v %+ ]", /* %+ means increment an integer */ &infile, fd_string, &verbose); /* get dimensions of input datfile */ Check_Infile(infile,&nsets,&nchans,&in_hdim,&in_vdim); fprintf(stderr,"%s: finished Check Infile; input dimensions are %d by %d\n", argv[0], in_vdim, in_hdim); MN = (long) in_hdim * (long) in_vdim; if( DEBUG ) printf("MN = %d\n",MN); in_size = (int) MN; mrows = in_vdim; ncols = in_hdim; fprintf(stderr, "%s: exchanging row and column dims because .mat is column order\n", argv[0]); mrows = in_hdim; /* reversed */ ncols = in_vdim; /* reversed */ strcpy(name,"deleteme_dat"); /* automatically puts a \000 at the end */ /* name[0] = 'd'; name[1] = 'a'; name[2] = 't'; name[3] = '\000'; */ /* allocate all buffers */ if( DEBUG ) printf("about to malloc inbuf\n"); inbuf = (byte *) malloc(MN * sizeof(byte)); if( DEBUG ) printf("finished malloc inbuf\n"); matrixrint = (unsigned short *) malloc(MN * sizeof(unsigned short)); /* matrixiint = (unsigned short *) malloc(MN * sizeof(unsigned short)); */ type = 40; /* Machine Orientation Precision Text: 40 = DECstation uss */ imagf = 0; /* assume real for now */ printf("type (Machine, Orientation, Precision, Text) is being set to %d\n", type); if(DEBUG) printf("about to if !inbuf ...\n"); if( !inbuf || !matrixrint ) { fprintf(stdout,"Malloc allocation error\n"); exit(0); } if (DEBUG) printf("finished if !inbuf ...\n"); #if 0 for( dset=0; dset < nsets; dset++ ) { for(dchan = 0; dchan < nchans ; dchan++) { if( verbose ) printf("Reading dataset %d channel %d\r",dset,dchan); #endif if (DEBUG) printf("about to d_read\n"); /* read and convert to bytes */ d_readc(infile, inbuf, in_size, 'b'); if (DEBUG) printf("about to enter for (mn...\n"); for( mn = 0; mn 2 ) { printf("The input datfile has more than 2 dimensions.\n"); exit(0); } *nsets = size.dset; *nchans = size.chan; *vdim = size.dim[0]; *hdim = size.dim[1]; if( *nchans!=1 ) { printf("%d channels. Expecting 8 bit (real) image: punting.\n",*nchans); exit(0); } }