9 messages in net.java.dev.jna.usersRe: [jna-users] Wrapping a C api to c...
FromSent OnAttachments
Richard OteroOct 12, 2007 3:59 pm 
Albert StrasheimOct 12, 2007 4:39 pm 
Albert StrasheimOct 12, 2007 5:51 pm 
Albert StrasheimOct 12, 2007 6:00 pm 
Timothy WallOct 13, 2007 6:05 am 
Timothy WallOct 13, 2007 7:05 am 
Timothy WallOct 13, 2007 7:27 am 
Albert StrasheimOct 13, 2007 10:55 am 
Richard OteroOct 14, 2007 2:50 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Wrapping a C api to control Matlab using Java (with example)Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Oct 13, 2007 7:05:59 am
List:net.java.dev.jna.users

You might also take a look at this link http://www.cs.virginia.edu/ ~whitehouse/matlab/JavaMatlab.html. It's not supported by matlab, but uses some of their internal plumbing. If you're not sure how to handle something, it might give you some ideas (good or bad, I can't say).

I think binding to the C interface via JNA is a better solution, since you know *that* is never going to change, and probably gives you more functionality, since MatlabControl doesn't really provide for data exchange except via matlab's output buffer.

On Oct 12, 2007, at 6:59 PM, Richard Otero wrote:

Thank you for your work with simplifying the native interface!

I am trying to create a Java API for Matlab by calling the current C API using JNA.

I am a graduate aerospace student working in a spacecraft design lab. Much of what we do uses Matlab but I would like to transition one tool to Java/Fortran. During the interim, some legacy modules will still need to be run using Matlab which is motivating my desire for a Matlab Java API.

This is the lions share of the API that I will need to wrap:

Engine - A handle to a MATLAB engine object. int engClose(Engine *ep); int engEvalString(Engine *ep,const char *string); int engGetVisible(Engine *ep, bool *value); Engine *engOpen(const char *startcmd); Engine *engOpenSingleUse(const char *startcmd, void *dcom, int *retstatus); int engOutputBuffer(Engine *ep, char *p, int n); int engSetVisible(Engine *ep, bool value);

mxArray - The fundamental type underlying MATLAB data. mxArray *engGetVariable(Engine *ep, const char *name); int engPutVariable(Engine *ep, const char *name, const mxArray *pm);

An example of using this would be: main() { Engine * ep; char * buffer;

ep = engOpen("matlab "); buffer = mxCalloc(101,sizeof(char)); engOutputBuffer(ep, buffer, 100); if (engEvalString(ep,"d=eye(3)")) fprintf(stderr,"Error evaluating d=eye(3)"); else printf("Result of engEvalString is \n%s\n",buffer); mxFree(buffer); }

Given the signatures for these functions, is there any advice on using JNA that comes to mind? This will be my first go at calling a native interface so a nudge in the right direction would be most appreciated.

thank you, Richard