Question

This is sort of related to my earlier question, but different. I can't figure out how to give MathLink function options without using Evaluate(), etc. For example, I have the following C# code:

ml.PutFunction("Abs",1);
ml.PutFunction("Fourier",2);
ml.Put(data); //data = double[]
ml.Put("FourierParameters->{-1,1}");

It doesn't work. It puts the FourierParameters part as a literal string, and not an option. I tried creating an Expr with that string and putting that, but that failed too. Is this even possible to do in .NETLink?

Was it helpful?

Solution

Following this example page, seems the option must be entered with PutSymbol, and you need to add a "Rule" PutFunction.

Resulting in something like (not tested):

ml.PutFunction("EvaluatePacket", 1);
ml.PutFunction("Abs",1);
ml.PutFunction("Fourier",2);
ml.Put(data); //data = double[]

ml.PutFunction("Rule", 2);
ml.PutSymbol("FourierParameters");
ml.PutFunction("List", 2);
ml.Put(-1); 
ml.Put(1); 
ml.EndPacket();

OTHER TIPS

I would do this using high level wrappers. For example, one could write a Mathematica function called MyFunction, using all the conveniences of Mathematica, that calls one of several low level, mathlink functions say myFunction1, myFunction2, etc. Which mathlink function to call would be based on standard option handling techniques within Mathematica.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top