MathGroup Archive 1998

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

Search the Archive

Announcing Java-Interface to MathLink



Hello

I have written an interface in Java for MathLink. It enables you to
write Java-Applications that use the Mathematica-Kernel for their
calculations. There are nearly all functions implemented as in the
C-Language interface.
The documentation of this package is located at
http://www.isbiel.ch/~zahnb/docs/frame.html If you are interested in
this package, please send me a mail to zahnb@student.isbiel.ch.
Because it is JavaNativeInterface based it runs under Java1.1 or newer
and currently only under Win32, but im am working on the SunSolaris
version.

Beat Zahnd
Engineering School Biel
Switzerland

Small usage example:
****************************

import packages.mathematica.*;
import java.io.File;

public class JMathLinkTest
{
  static String func;
  
  public static void main( String argv[] ) throws MathLinkException
  {
    File f = new File( "D:\\Programme\\Wolfram
Research\\Mathematica\\3.0\\MathKernel.exe" );
    if( f.exists() )
    {
      JMathLink ml = new JMathLink( f );
      new JMathLinkTest( ml );
      ml.jMLClose( ml.link );
      System.out.println( );
    }
    else System.out.println( "\n\nMathKernel nicht gefunden!\n" );
  }
  
  JMathLinkTest( JMathLink mld ) throws MathLinkException
  {
    put( mld );
    for( int a = 0; a < 2; a++ )
    {
      func = new String( );
      get( mld );
      System.out.println( func + "\n" );
    }
  }
  
  void put( JMathLink mlc ) throws MathLinkException
  {
    mlc.jMLPutFunction( mlc.link, "EvaluatePacket", 1 );
    mlc.jMLPutFunction( mlc.link, "FactorInteger", 1 );
    mlc.jMLPutNext( mlc.link, mlc.MLTKINT );
    mlc.jMLPutByteString( mlc.link,
"4711930799906184953162487834760260422020574773409675520188634839616415335845034221205289256705544681972439104097777157991804380284218315038719444943990492579030720635990538452312528339864352999310398481791730017201031090"
);
    mlc.jMLEndPacket( mlc.link );
  }
  
  void get( JMathLink mlc ) throws MathLinkException
  {
    int tkn, i;
    double d;
    String str;
    
    tkn = mlc.jMLGetNext( );
    
    switch( tkn )
    {
    case mlc.MLTKSYM :
      str = mlc.jMLGetSymbol( );
      func += str;
      break;
    case mlc.MLTKSTR :
      str = mlc.jMLGetString( );
      func += ( "\"" + str + "\"" );
      break;
    case mlc.MLTKINT :
      i = mlc.jMLGetInteger( );
      func += i;
      break;
    case mlc.MLTKREAL :
      d = mlc.jMLGetReal( );
      func += d;
      break;
    case mlc.MLTKFUNC :
      i = mlc.jMLGetArgCount( );
      get( mlc );
      func += "[";
      for( int s = 0; s < i; s++ )
      {
        get( mlc );
        if( s < i - 1 ) func += ", ";
      }
      func += "]";
      break;
    case mlc.MLTKERROR :
      str = mlc.jMLErrorMessage( mlc.link );
      mlc.jMLClearError( mlc.link );
      func += str;
      break;
    }
  }
}



  • Prev by Date: Mathematica Training (USA & France)
  • Next by Date: RE: How Mathematica select one
  • Prev by thread: Mathematica Training (USA & France)
  • Next by thread: RE: How Mathematica select one