/** This main function is for driving the program in pure UNIX/CYGWIN OS. There is a mex_function() defined in "mex_parse.c" which is used as the driver in MATLAB. */ int main(int argc, char **args) { FILE *inFile; // Test data access double *A; double *b; int dim; int i, j; if (argc < 2) { printf("Please provide an input file.\n"); exit(0); } Call_Parser( args[1] ); dim = Get_Matrix_Size(); printf("\ndim = %d", dim); A = malloc((dim+1)*(dim+1)*sizeof(double)); b = malloc((dim+1)*sizeof(double)); Get_MNA_System(&A, &b); printf("\nA:\n\t"); for (i = 0; i < (dim+1)*(dim+1); i++) printf("%-8.3f", A[i]); printf("\nb:\n\t"); for (i = 0; i < (dim+1); i++) printf("%-8.3f", b[i]); return (0); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { char *netlistname; double *A, *b; // pointers for A and b (A*x = b) //size_t total_bytes; unsigned int M; // matrix dimension /* Check for correct number of arguments */ if (nrhs!=1) mexErrMsgTxt("One input required."); else if (nlhs > 2) mexErrMsgTxt("Too many output arguments."); /* Input must be a string */ if (mxIsChar(prhs[0]) != 1) mexErrMsgTxt("Input must be a string."); /* Input must be a row vector */ if (mxGetM(prhs[0]) != 1) mexErrMsgTxt("Please make sure input is a single string."); /* Copy the string data from prhs[0] to the netlistname string in C. */ netlistname = mxArrayToString(prhs[0]); if (netlistname == NULL) mexErrMsgTxt("No file name is given."); /* Call the C subroutine */ Call_Parser(netlistname); /** Retrieve MNA matrix and RHS vector from the parser. Place the retrieved MNA system (A, b) into the LHS variables of the mex function. **/ M = Get_Matrix_Size(); plhs[0] = mxCreateDoubleMatrix(M+1, M+1, mxREAL); // Matrix plhs[1] = mxCreateDoubleMatrix(M+1, 1, mxREAL); // RHS // Fetch the pointers for the MNA system A = (double*) mxGetPr(plhs[0]); b = (double*) mxGetPr(plhs[1]); // TOTAL_ELEMENTS = 4 defined as macro //total_bytes = 4 * mxGetElementSize(plhs[0]); //memcpy(lhs_ptr, data, total_bytes); /* Passing out the matrix and rhs from the parser. */ Get_MNA_System(&A, &b); mxFree(netlistname); return; }