/* FLIPBYTES.C Cmex function to flip the bytes of a given number or matrix. This function is usefull to read and write the Nanoscope file in the correct way. The calling syntax is: [Q] = flipbytes(R) Claudio October 2, 1994 */ #include #include "mex.h" /* Input Arguments */ #define M_IN prhs[0] /* Output Arguments */ #define M_OUT plhs[0] static void flip( double pin[], double pout[], int s ) { unsigned short p; short q; int i; for(i=0; i>8; pout[i]=(double)q; } return; } void mexFunction( int nlhs, Matrix *plhs[], int nrhs, Matrix *prhs[] ) { double *pin; double *pout; unsigned int row,col; /* Check for proper number of arguments */ if (nrhs != 1) { mexErrMsgTxt("FLIPBYTES requires one input arguments."); } else if (nlhs > 1) { mexErrMsgTxt("FLIPBYTES requires one output argument."); } /* Check the dimensions of M_IN */ row = mxGetM(M_IN); col = mxGetN(M_IN); /* Create a matrix for the return argument */ M_OUT = mxCreateFull(row, col, REAL); /* Assign pointers to the various parameters */ pout = mxGetPr(M_OUT); pin = mxGetPr(M_IN); /* Do the actual computations in a subroutine */ flip(pin,pout,row*col); return; }