/*
 * MRANKMAC
 * "Macintosh" C main program illustrating the use of the MATLAB Math Library.
 * Calls mlfMrank, obtained by using MCC to compile mrank.m.
 *
 * $Revision: 1.2 $ 
 */

#include <stdio.h>
#include <math.h>
#include "matlab.h"

/* Prototype for mlfMrank */
extern mxArray * mlfMrank( mxArray * );

void MacPrint(const char *text)
{
    /* This call to printf will eventually get intercepted by
     * either MPW's SIOW or Metrowerks' SIOUX standard input/output
     * emulator.
     */
    printf(text);
}

main()
{
    mxArray *N;    /* Matrix containing n. */
    mxArray *R;    /* Result matrix. */
    int      n;    /* Integer parameter from command line. */
    
    /* Estlablish print handler */
    mlfSetPrintHandler(MacPrint);
    
    /* Request from user an input number to pass to mrank. */
    printf("Please enter an integer to pass to mrank:\n");
    scanf("%d", &n);
    
    /* Create a 1-by-1 matrix containing n. */
    N = mxCreateDoubleMatrix (1, 1, mxREAL);
    *mxGetPr(N) = n;
    
    /* Call mlfMrank, the compiled version of mrank.m. */
    R = mlfMrank(N);
    
    /* Print the results. */
    mlfPrintMatrix(R);
    
    /* Free the matrices allocated during this computation. */
    mxDestroyArray(N);
    mxDestroyArray(R);
   
}
