0
$\begingroup$

The following code shows how default KernelLink values are sent back to Java in 2D text form. Which becomes a heap-big mess in an array of exponential values, since all the exponents are printed first in one line...followed by the base values...messing up all their alignments.

How might it be possible to convert the return values to 1D format, e.g., 5.*^-10?

import com.wolfram.jlink.*;
public class TestJLink {
public static void main(String[] argv) {
    KernelLink ml = null;
    try {
        ml = MathLinkFactory.createKernelLink(argv);
    } catch (MathLinkException e) {
        System.out.println("Fatal error opening link: " +        e.getMessage());
        return;
    }
    try {
        ml.discardAnswer();
        String strResult = ml.evaluateToOutputForm("<<1Dreturn.m", 0);
        System.out.println("\n" + strResult + "\n");
    } catch (MathLinkException e) {
        System.out.println("MathLinkException occurred: " +  e.getMessage());
    } finally {
        ml.close();
    }
  }
}

The 1Dreturn.m file is:

Subscript[\[Gamma], E] = UnitSimplify[Quantity[None,     "ElectronMass"*"SpeedOfLight"^2]]
$\endgroup$
3
$\begingroup$

It's all right there in the name: evaluateToOutputForm.

If you want it InputForm, use evaluateToInputForm.

This is all documented in the tutorial.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.