Exemple #1
0
void *run_main( void *in )
{
    mxArray *N;    /* Matrix containing n. */
    mxArray *R = NULL;    /* Result matrix. */
    int      n;    /* Integer parameter from command line. */

    seterr(0); /*reset the error code */
    /* Get any command line parameter. */
    if (((inputs*)in)->ac >= 2) {
        n = atoi(((inputs*)in)->av[1]);
    } else {
        n = 12;
    }

    /* Call the mclInitializeApplication routine. Make sure that the application
     * was initialized properly by checking the return status. This initialization
     * has to be done before calling any MATLAB API's or MATLAB Compiler generated
     * shared library functions. */
    if( !mclInitializeApplication(NULL,0) )
    {
        fprintf(stderr, "Could not initialize the application.\n");
        seterr(-2);
	return in;
    }
    /* Call the library intialization routine and make sure that the
     * library was initialized properly */
    if (!libPkgInitialize())
    {
      fprintf(stderr,"Could not initialize the library.\n");
      seterr(-3);
    }
    else
    {
	/* Create a 1-by-1 matrix containing n. */
        N = mxCreateScalarDouble(n);
      
	/* Call mlfMrank, the compiled version of mrank.m. */
	mlfMrank(1, &R, N);
	
	/* Print the results. */
	mlfPrintmatrix(R);
	
	/* Free the matrices allocated during this computation. */
	mxDestroyArray(N);
	mxDestroyArray(R);
	
	libPkgTerminate();    /* Terminate the library of M-functions */
    }
/* On MAC, you need to call mclSetExitCode with the appropriate exit status
 * Also, note that you should call mclTerminate application in the end of
 * your application. mclTerminateApplication terminates the entire 
 * application and exits with the exit code set using mclSetExitCode. Note
 * that this behavior is only on MAC platform.
 */
#ifdef __APPLE_CC__
    mclSetExitCode(((inputs*)in)->err);
#endif
    mclTerminateApplication();
    return in;
}
Exemple #2
0
void *run_main(void *x)
{
  int *err = x;
    mxArray *in1, *in2; /* Define input parameters */
    mxArray *out = NULL;/* and output parameters to be passed to the library functions */
    
    double data[] = {1,2,3,4,5,6,7,8,9};

    /* Call the mclInitializeApplication routine. Make sure that the application
     * was initialized properly by checking the return status. This initialization
     * has to be done before calling any MATLAB API's or MATLAB Compiler generated
     * shared library functions.  */
    if( !mclInitializeApplication(NULL,0) )
    {
        fprintf(stderr, "Could not initialize the application.\n");
	*err = -1;
        return(x);
    }
    
    /* Create the input data */
    in1 = mxCreateDoubleMatrix(3,3,mxREAL);
    in2 = mxCreateDoubleMatrix(3,3,mxREAL);
    memcpy(mxGetPr(in1), data, 9*sizeof(double));
    memcpy(mxGetPr(in2), data, 9*sizeof(double));
    
    /* Call the library intialization routine and make sure that the
     * library was initialized properly. */
    if (!libmatrixInitialize()){
        fprintf(stderr,"Could not initialize the library.\n");
        *err = -2;
    }
    else
    {
        /* Call the library function */
        mlfAddmatrix(1, &out, in1, in2);
	/* Display the return value of the library function */
	printf("The value of added matrix is:\n");
	display(out);
	/* Destroy the return value since this varaible will be resued in
	 * the next function call. Since we are going to reuse the variable,
	 * we have to set it to NULL. Refer to MATLAB Compiler documentation
	 * for more information on this. */
	mxDestroyArray(out); out=0;
	mlfMultiplymatrix(1, &out, in1, in2);
	printf("The value of the multiplied matrix is:\n");
	display(out);
	mxDestroyArray(out); out=0;
	mlfEigmatrix(1, &out, in1);
	printf("The eigenvalues of the first matrix are:\n");
	display(out);
	mxDestroyArray(out); out=0;
	
	/* Call the library termination routine */
	libmatrixTerminate();
	
	/* Free the memory created */
	mxDestroyArray(in1); in1=0;
	mxDestroyArray(in2); in2 = 0;
    }
/* On MAC, you need to call mclSetExitCode with the appropriate exit status
 * Also, note that you should call mclTerminate application in the end of
 * your application. mclTerminateApplication terminates the entire 
 * application and exits with the exit code set using mclSetExitCode. Note
 * that this behavior is only on MAC platform.
 */
#ifdef __APPLE_CC__
    mclSetExitCode(*err);
#endif
    mclTerminateApplication();
    return 0;
}