MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

MLPutRealList vs. sequence of MLPutDouble

   I am a new subscriber to the list and I have a seemingly
simple (read: stupid) question: why does this code work
when I send a sequence of reals and not work when I send
a list?

        /* Now initialize and call Mathematica */
        env = MLInitialize(NULL);
        if (env == NULL) return 1;

        link = MLOpen(num_strings, Mparams);
        if (link == NULL) return 1;


        /* Load the compare function definition into Mathematica */
        MLPutFunction(link, "EnterTextPacket", 1);
        MLPutString(link, "<<" SCRIPT_NAME ".m");

        /* call the compare function with x[1], x[2]*/
        MLPutFunction(link, "EvaluatePacket", 1);
        MLPutFunction(link, SCRIPT_NAME, 1);
        MLPutFunction(link, SCRIPT_NAME, NUM_VARS);
        for ( i=0; i<NUM_VARS; i++ ) { MLPutDouble(link, x[i]); }

        /* skip any packets before the first ReturnPacket
           and then get the result from the calculation   */
        int pkt;
        while( (pkt = MLNextPacket(link), pkt) && pkt != RETURNPKT) {
                if (MLError(link)) {
                        fprintf( stderr, "2 Error detected by MathLink: 
                        MLErrorMessage(link)); }

        double fn_val=0.0;
        MLGetDouble(link, &fn_val);
        if (MLError(link)) {
                fprintf( stderr, "3 Error detected by MathLink: %s.\n",
                MLErrorMessage(link)); }

this is the Mathematica script that is called (it takes a list and 
returns a single value) :

(* test[x_Real,x2_Real] := x; *)
test[y_List] := y[[2]];

this is the output:

Error detected by MathLink: MLGet out of sequence.
test : { 0.616000, 29.000000} -> f: 0.000000


Reese Jones
Sandia National Laboratories, MS 9042, P.O. Box 0969
Livermore, CA 94551

phone: (925) 294-4744 or (800) 4SANDIA x4-4744
fax:   (925) 294-1459
e-mail: rjones at

  • Prev by Date: Re: IMAP interface to Mathematica
  • Next by Date: Anomaly or expected behaviour?
  • Previous by thread: Re: Why aren't nested groups? XML again.
  • Next by thread: Re: MLPutRealList vs. sequence of MLPutDouble