static inline mxArray* _getMatlabVar(PyObject *lHandle, char *lName){ #ifdef _V6_5_OR_LATER return engGetVariable((Engine *)PyCObject_AsVoidPtr(lHandle), lName); #else return engGetArray((Engine *)PyCObject_AsVoidPtr(lHandle), lName); #endif }
static inline mxArray* _getMatlabVar(PyObject *lHandle, char *lName){ #ifdef _V6_5_OR_LATER return engGetVariable((Engine *)PyCapsule_GetPointer(lHandle, NULL), lName); #else return engGetArray((Engine *)PyCapsule_GetPointer(lHandle, NULL), lName); #endif }
JNIEXPORT jobjectArray JNICALL Java_JMatLink_engGetCharArrayNATIVE (JNIEnv *env, jobject jthis, jint engine, jstring arrayS_JNI) { // Check if engine pointer is within allowed region //if (( engine < 1 ) || ( engine >= enginePMax )) //{ // return NULL; // Pointer is out of allowed region //} const char *arrayS = (*env)->GetStringUTFChars(env, arrayS_JNI, 0); if (debugB) printf("native engGetArray %s \n",arrayS); arrayP = engGetArray( engineP[ engine ], arrayS); if (arrayP == NULL) { printf("Could not get array %s from MATLAB workspace.\n", arrayS); (*env)->ReleaseStringUTFChars(env, arrayS_JNI, arrayS); // free memory return NULL; } if (mxIsChar(arrayP) != 0) { printf("The array %s is not of type char.\n", arrayS); (*env)->ReleaseStringUTFChars(env, arrayS_JNI, arrayS); // free memory return NULL; } mxDestroyArray(arrayP); // free memory (*env)->ReleaseStringUTFChars(env, arrayS_JNI, arrayS); // free memory } // end engGetCharArrayNATIVE
JNIEXPORT jdouble JNICALL Java_JMatLink_engGetScalarNATIVE (JNIEnv *env, jobject obj, jint engine, jstring scalarS_JNI) { const char *scalarS= (*env)->GetStringUTFChars(env, scalarS_JNI, 0); // Check if engine pointer is within allowed region if (( engine < 1 ) || ( engine >= enginePMax )) { return 0.0; // Pointer is out of allowed region } if (debugB) printf("native engGetScalar %s \n",scalarS); //if (OpenB==0) return 0.0; // engine is not open arrayP = engGetArray( engineP[ engine ], scalarS); if (arrayP == NULL) { printf("Could not get scalar from MATLAB workspace.\n"); (*env)->ReleaseStringUTFChars(env, scalarS_JNI, scalarS); // free memory return 0.0; } else { scalar = mxGetScalar(arrayP); } mxDestroyArray(arrayP); // free memory (*env)->ReleaseStringUTFChars(env, scalarS_JNI, scalarS); // free memory return scalar; }
TmxArray* TMatlab::Get(const char *name, TmxArray *a) { #ifdef HAVE_MATLAB if (!a) a = new TmxArray(name); a->Setmx(engGetArray((Engine*)fEngine,name)); return a; #else return NULL; #endif }
JNIEXPORT jobjectArray JNICALL Java_JMatLink_engGetArrayNATIVE (JNIEnv *env, jobject obj, jint engine, jstring arrayS_JNI) { // NOTE: in java there are only 1-dimensional (array[]) arrays. // higher dimensional arrays are arrays of arrays. jarray rowA; jclass rowClass; jarray columnA; int in,im; int m = 0; int n = 0; jdouble *rowElements; double *TP; // convert array name to c-string const char *arrayS = (*env)->GetStringUTFChars(env, arrayS_JNI, 0); // Check if engine pointer is within allowed region //if (( engine < 1 ) || ( engine >= enginePMax )) //{ // return NULL; // Pointer is out of allowed region //} if (engineP[ engine ] != NULL) { if (debugB) printf("native engGetArray %s \n",arrayS); arrayP = engGetArray( engineP[ engine ] , arrayS); if (arrayP == NULL) { printf("Could not get array %s from MATLAB workspace.\n", arrayS); (*env)->ReleaseStringUTFChars(env, arrayS_JNI, arrayS); // free memory return NULL; } m = mxGetM( arrayP ); // rows n = mxGetN( arrayP ); // columns TP = mxGetPr( arrayP ); // get pointer to values /* create an array of double and get its class */ rowA = (*env)->NewDoubleArray( env, n); // row vector rowClass = (*env)->GetObjectClass( env, rowA); // row class /* create an array of object with the rowClass as the the default element */ columnA = (*env)->NewObjectArray( env, m, rowClass, NULL); // column vector for (im=0; im<m; im++) { rowA = (*env)->NewDoubleArray( env, n); // row vector rowClass = (*env)->GetObjectClass( env, rowA); // row class rowElements = (*env)->GetDoubleArrayElements(env, rowA, 0); // row elements for (in=0; in<n; in++) { rowElements[in] = TP[in*m + im]; } (*env)->SetObjectArrayElement(env, columnA, im, rowA); (*env)->ReleaseDoubleArrayElements(env, rowA, rowElements, 0); } } // engineP[ ] mxDestroyArray(arrayP); // free memory (*env)->ReleaseStringUTFChars(env, arrayS_JNI, arrayS); // free memory // are the following two line ok? return NULL ?!?!? if (engineP[ engine ] != NULL) return columnA; else return NULL; }