unit pasmex32;
(************************************************************************
* Unit zur Erstellung von Matlab-DLL-MEX-Dateien mit Borland Delphi2+. *
* Verwendbar fr 32bit Matlab 5+ fr Windows. *
* *
* h#s 11/00, Idee: EA *
************************************************************************
* Die zu erstellende DLL mu folgenden Aufbau haben: *
--------------------------------------------------------------------------
library example; {$N+,E-} {MATLAB setzt ohnehin Koprozessor voraus}
uses pasmex32,windows;
procedure mexFunction(nlhs:LongInt; var plhs:TMatArr;
nrhs:LongInt; const prhs:TMatArr); stdcall;
begin
MessageBox(0,'Hallo Welt','Hi',MB_OK or MB_TaskModal);
end;
exports
mexFunction;
begin
end.
--------------------------------------------------------------------------
* *
************************************************************************)
{$HINTS ON}
interface
uses Windows;
const
mxMAXNAM =32;
type
PPArray=^PArray;
PArray=^TArray;
TArray=record
name: array[0..mxMAXNAM-1] of Char;
reserved1: array[0..1] of LongInt;
reserved2: Pointer;
number_of_dims: LongInt;
nelements_allocated: LongInt;
reserved3: array[0..2] of LongInt;
pdata: Pointer;
pimag_data: Pointer;
reserved4: Pointer;
reserved5: array[0..2] of LongInt;
end;
{Symbolische Arrays fr die Verwendung in der <library>}
TDblArr=array[0..0]of Double;
TLongArr=array[0..0]of LongInt;
TMatArr=array[0..16382]of PArray; {Symbolisches Array fr plhs, prhs}
type
PPChar=^PChar;
PDouble=^Double;
type
PMatFile=^TMatFile;
TMatFile=record {geheim}
end;
PFile=^TFile;
TFile=record {wie codiert C (32bit) ein FILE?}
level: LongInt;
flags: Cardinal;
fd: Char;
hold: Char;
bsize: LongInt;
buffer,curp: PChar;
istemp: LongBool;
token: Integer; {"short" in BC45!!}
end;
type
PEngine=^TEngine;
TEngine=record {geheimer Inhalt}
end;
type
TAlloc_Filter=function(p:Pointer):Pointer; cdecl;
TFree_Filter=function(p:Pointer):Pointer; cdecl;
TOutOfMemory_Listener=procedure(p:Pointer); cdecl;
TCalloc_Proc=function(i,j:LongInt):Pointer; cdecl;
TFree_Proc=procedure(p:Pointer); cdecl;
TRealloc_Proc=function(p:Pointer; i:LongInt):Pointer; cdecl;
TMalloc_Proc=function(i:LongInt):Pointer; cdecl;
{$Z4}
type
EmxClassID=(
mxUNKNOWN_CLASS, {Schummel, ist eigentlich -1!!!}
mxCELL_CLASS,
mxSTRUCT_CLASS,
mxOBJECT_CLASS,
mxCHAR_CLASS,
mxSPARSE_CLASS,
mxDOUBLE_CLASS,
mxSINGLE_CLASS,
mxINT8_CLASS,
mxUINT8_CLASS,
mxINT16_CLASS,
mxUINT16_CLASS,
mxINT32_CLASS,
mxUINT32_CLASS,
mxINT64_CLASS,
mxUINT64_CLASS);
type
EmxComplexity=(
mxREAL,
mxCOMPLEX);
TErrCode=(mxOK); {0 wenn OK, <>0 bei Fehler}
{mx-Funktionen, alphabetisch (Array-Manipulation)}
procedure mxAddToAllocList(p:Pointer); cdecl;
function mxArrayToString(pm:PArray):PChar; cdecl;
function mxCalcSingleSubscript(pm:PArray;
nsubs:LongInt; subs:PLongInt):LongInt; cdecl;
function mxCalloc(n,size:LongInt):Pointer; cdecl;
procedure mxClearLogical(pm:PArray); cdecl;
function mxCreateCellArray(
ndim: LongInt; dims:PLongInt):PArray; cdecl;
function mxCreateCellMatrix(m,n:LongInt):PArray; cdecl;
function mxCreateCharArray(
ndim: LongInt; dims:PLongInt):PArray; cdecl;
function mxCreateCharMatrixFromStrings(
argc: LongInt; argv:PPChar):PArray; cdecl;
function mxCreateDoubleMatrix(m,n:LongInt;
flag:EmxComplexity):PArray; cdecl;
function mxCreateNumericArray(ndim: LongInt; dims:PLongInt;
classid: EmxClassID; flag:EmxComplexity):PArray; cdecl;
function mxCreateSparse(m,n,nzmax:LongInt;
ComplexFlag:EmxComplexity):PArray; cdecl;
function mxCreateString(str:PChar):PArray; cdecl;
function mxCreateStringFromNChars(str:PChar; n:LongInt):PArray;cdecl;
function mxCreateStructArray(ndim: LongInt; dims:PLongInt;
argc: LongInt; argv:PPChar):PArray; cdecl;
function mxCreateStructMatrix(m,n: LongInt;
argc: LongInt; argv:PPChar):PArray; cdecl;
procedure mxDestroyArray(pm:PArray); cdecl;
function mxDuplicateArray(a:PArray):PArray; cdecl;
procedure mxFree(p:PChar); cdecl;
function mxGetCell(a:PArray; i:LongInt):PArray; cdecl;
function mxGetClassID(a:PArray):EmxClassID; cdecl;
function mxGetClassName(a:PArray):PChar; cdecl;
function mxGetData(a:PArray):Pointer; cdecl;
function mxGetDimensions(pm:PArray):PLongInt; cdecl;
function mxGetElementSize(pm:PArray):LongInt; cdecl;
function mxGetEps:Double; cdecl;
function mxGetField(pm:PArray;
i:LongInt; fieldname:PChar):PArray; cdecl;
function mxGetFieldByNumber(pm:PArray;
i,fieldnum:LongInt):PArray; cdecl;
function mxGetFieldNumber(pm:PArray; name:PChar):LongInt; cdecl;
function mxGetFieldNameByNumber(pm:PArray; n:LongInt):PChar; cdecl;
function mxGetImagData(a:PArray):Pointer; cdecl;
function mxGetInf:Double; cdecl;
function mxGetIr(pm:PArray):PLongInt; cdecl;
function mxGetJc(pm:PArray):PLongInt; cdecl;
function mxGetM(pm:PArray):LongInt; cdecl;
function mxGetN(pm:PArray):LongInt; cdecl;
function mxGetName(pm:PArray):PChar; cdecl;
function mxGetNaN:Double; cdecl;
procedure mxGetNChars(pm:PArray; buf:PChar; nChars:LongInt); cdecl;
function mxGetNzmax(pm:PArray):LongInt; cdecl;
function mxGetNumberOfDimensions(pm:PArray):LongInt; cdecl;
function mxGetNumberOfElements(pm:PArray):LongInt; cdecl;
function mxGetNumberOfFields(pm:PArray):LongInt; cdecl;
function mxGetPi(pm:PArray):PDouble; cdecl;
function mxGetPr(pm:PArray):PDouble; cdecl;
function mxGetScalar(pm:PArray):Double; cdecl;
function mxGetString(pm:PArray; buf:PChar; buflen:LongInt):
TErrCode; cdecl;
function mxGetUserBits(pm:PArray):Byte; cdecl;
procedure mxInitStaticArray(pm:PArray; ClassID:EmxClassID); cdecl;
function mxIsCell(pm:PArray):LongBool; cdecl;
function mxIsChar(pm:PArray):LongBool; cdecl;
function mxIsClass(pm:PArray):LongBool; cdecl;
function mxIsComplex(pm:PArray):LongBool; cdecl;
function mxIsDouble(pm:PArray):LongBool; cdecl;
function mxIsEmpty(pm:PArray):LongBool; cdecl;
function mxIsFinite(x:Double):LongBool; cdecl;
function mxIsFromGlobalWS(pm:PArray):LongBool; cdecl;
function mxIsInf(x:Double):LongBool; cdecl;
function mxIsInt16(pm:PArray):LongBool; cdecl;
function mxIsInt32(pm:PArray):LongBool; cdecl;
function mxIsInt8(pm:PArray):LongBool; cdecl;
function mxIsLogical(pm:PArray):LongBool; cdecl;
function mxIsNaN(x:Double):LongBool; cdecl;
function mxIsNumeric(pm:PArray):LongBool; cdecl;
function mxIsSingle(pm:PArray):LongBool; cdecl;
function mxIsSparse(pm:PArray):LongBool; cdecl;
function mxIsStruct(pm:PArray):LongBool; cdecl;
function mxIsUInt16(pm:PArray):LongBool; cdecl;
function mxIsUInt32(pm:PArray):LongBool; cdecl;
function mxIsUInt8(pm:PArray):LongBool; cdecl;
function mxMalloc(n:LongInt):Pointer; cdecl;
function mxRealloc(p:Pointer; n:LongInt):Pointer; cdecl;
procedure mxSetAllocFcns(callocfcn: TCalloc_Proc; freefcn: TFree_Proc;
reallocfcn: TRealloc_Proc; mallocfcn: TMalloc_Proc); cdecl;
procedure mxSetAllocListeners(allochandler:TAlloc_Filter;
freehandler:TFree_Filter); cdecl;
procedure mxSetCell(a:PArray; i:LongInt; value:PArray); cdecl;
procedure mxSetClassName(pm:PArray; classname:PChar); cdecl;
procedure mxSetData(pm:PArray; p:Pointer); cdecl;
procedure mxSetDimensions(pm:PArray;
size:PLongInt; ndims:LongInt); cdecl;
procedure mxSetField(pm:PArray;
i:LongInt; fieldname:PChar; value:PArray); cdecl;
procedure mxSetFieldByNumber(pm:PArray;
i,fieldnum:LongInt; value:PArray); cdecl;
procedure mxSetImagData(pm:PArray; p:Pointer); cdecl;
procedure mxSetLogical(pm:PArray); cdecl;
procedure mxSetFromGlobalWS(pm:PArray;global:LongBool); cdecl;
procedure mxSetName(pm:PArray; S:PChar); cdecl;
procedure mxSetM(pm:PArray; m:LongInt); cdecl;
procedure mxSetN(pm:PArray; n:LongInt); cdecl;
procedure mxSetOutOfMemoryListener
(outofmemoryhandler:TOutOfMemory_Listener); cdecl;
procedure mxSetPr(pm:PArray; pr:PDouble); cdecl;
procedure mxSetPi(pm:PArray; pi:PDouble); cdecl;
procedure mxSetNzmax(pm:PArray; nzmax:LongInt); cdecl;
procedure mxSetIr(pm:PArray; ir:PLongInt); cdecl;
procedure mxSetJc(pm:PArray; jc:PLongInt); cdecl;
procedure mxSetUserBits(pm:PArray; b:Byte); cdecl;
{mex-Funktionen, alphabetisch}
procedure mexAddFlops(count: LongInt); cdecl;
function mexAtExit(ExitFcn:TFarProc):TErrCode; cdecl;
function mexCallMATLAB(nlhs:LongInt; plhs:PArray;
nrhs:LongInt; prhs:PArray; name:PChar):TErrCode; cdecl;
procedure mexGetCallMATLABFunction; cdecl;
function mexEvalString(str:PChar):TErrCode; cdecl;
function mexGet(handle:Double;prop:PChar):PArray; cdecl;
function mexGetArray(name,workspace:PChar):PArray; cdecl;
function mexGetArrayPtr(name,workspace:PChar):PArray; cdecl;
procedure mexGetFunctionHandle; cdecl;
procedure mexLock; cdecl;
procedure mexErrMsgTxt(error_msg:PChar); cdecl;
function mexFunctionName:PChar; cdecl;
function mexIsGlobal(a:PArray):LongBool; cdecl;
function mexIsLocked:LongBool; cdecl;
procedure mexMakeArrayPersistent(a:PArray); cdecl;
procedure mexMakeMemoryPersistent(a:Pointer); cdecl;
procedure mexPrintAssertion(test,fname:PChar;
linenum:LongInt; message:PChar); cdecl;
function mexPrintf(format:PChar):LongInt; cdecl;
function mexPrintf0(format:PChar):LongInt; cdecl;
function mexPrintf1(format:PChar;a1:LongInt):LongInt; cdecl;
function mexPrintf2(format:PChar;a1,a2:LongInt):LongInt; cdecl;
function mexPrintf3(format:PChar;a1,a2,a3:LongInt):LongInt; cdecl;
function mexPrintf4(format:PChar;a1,a2,a3,a4:LongInt):LongInt; cdecl;
function mexPrintf5(format:PChar;a1,a2,a3,a4,a5:LongInt):LongInt;
cdecl;
function mexPrintf6(format:PChar;a1,a2,a3,a4,a5,a6:LongInt):LongInt;
cdecl;
function mexPrintf7(format:PChar;a1,a2,a3,a4,a5,a6,a7:LongInt):LongInt;
cdecl;
function mexPrintf8(format:PChar;a1,a2,a3,a4,a5,a6,a7,a8:LongInt):LongInt;
cdecl;
function mexPutArray(a:PArray;workspace:PChar):TErrCode; cdecl;
procedure mexRegisterFunction; cdecl;
function mexSet(handle:Double;prop:PChar;a:PArray):TErrCode; cdecl;
procedure mexSetTrapFlag(trap_flag:LongBool); cdecl;
procedure mexSubsAssign(plhs:PArray; sub: PPArray;
nsubs:LongInt; prhs:PArray); cdecl;
function mexSubsReference(prhs:PArray; sub: PPArray;
nsubs:LongInt):PArray; cdecl;
procedure mexUnlock; cdecl;
procedure mexWarnMsgTxt(warn_msg:PChar); cdecl;
function matClose(ph:PMatFile):TErrCode; cdecl;
function matDeleteArray(ph:PMatFile; name:PChar):TErrCode; cdecl;
function matGetArray(ph:PMatFile; name:PChar):PArray; cdecl;
function matGetArrayHeader(ph:PMatFile; name:PChar):PArray; cdecl;
function matGetDir(ph:PMatFile; var num:LongInt):PPChar; cdecl;
function matGetFp(ph:PMatFile):PFile; cdecl;
function matGetNextArray(ph:PMatFile):PArray; cdecl;
function matGetNextArrayHeader(ph:PMatFile):PArray; cdecl;
function matOpen(filename,mode:PChar):PMatFile; cdecl;
function matPutArray(ph:PMatFile; pm:PArray):TErrCode; cdecl;
function matPutArrayAsGlobal(ph:PMatFile; pm:PArray):TErrCode; cdecl;
function engClose(ep: PEngine):TErrCode; cdecl;
function engEvalString(ep: PEngine; str:PChar):TErrCode; cdecl;
function engGetArray(ep: PEngine; name:PChar):PArray; cdecl;
function engOpen(startcmd:PChar):PEngine; cdecl;
function engOutputBuffer(ep:PEngine;p:PChar;n:LongInt):LongInt;cdecl;
function engPutArray(ep: PEngine; pm:PArray):TErrCode; cdecl;
type
LongRec=record
lo,hi: Word;
end;
implementation
const
mx_DLL='MATLAB.EXE';
{ndern auf 'LIBMX.DLL', wenn eigene .EXE auf Arrays zugreifen soll}
procedure mxAddToAllocList; external mx_DLL;
function mxArrayToString; external mx_DLL;
function mxCalcSingleSubscript; external mx_DLL;
function mxCalloc; external mx_DLL;
procedure mxClearLogical; external mx_DLL;
function mxCreateCellArray; external mx_DLL;
function mxCreateCellMatrix; external mx_DLL;
function mxCreateCharArray; external mx_DLL;
function mxCreateCharMatrixFromStrings;external mx_DLL;
function mxCreateDoubleMatrix; external mx_DLL;
function mxCreateNumericArray; external mx_DLL;
function mxCreateSparse; external mx_DLL;
function mxCreateString; external mx_DLL;
function mxCreateStringFromNChars; external mx_DLL;
function mxCreateStructArray; external mx_DLL;
function mxCreateStructMatrix; external mx_DLL;
procedure mxDestroyArray; external mx_DLL;
function mxDuplicateArray; external mx_DLL;
procedure mxFree; external mx_DLL;
function mxGetCell; external mx_DLL;
function mxGetClassID; external mx_DLL;
function mxGetClassName; external mx_DLL;
function mxGetData; external mx_DLL;
function mxGetDimensions; external mx_DLL;
function mxGetElementSize; external mx_DLL;
function mxGetEps; external mx_DLL;
function mxGetField; external mx_DLL;
function mxGetFieldByNumber; external mx_DLL;
function mxGetFieldNumber; external mx_DLL;
function mxGetFieldNameByNumber; external mx_DLL;
function mxGetImagData; external mx_DLL;
function mxGetInf; external mx_DLL;
function mxGetIr; external mx_DLL;
function mxGetJc; external mx_DLL;
function mxGetM; external mx_DLL;
function mxGetN; external mx_DLL;
function mxGetName; external mx_DLL;
function mxGetNaN; external mx_DLL;
procedure mxGetNChars; external mx_DLL;
function mxGetNzmax; external mx_DLL;
function mxGetNumberOfDimensions; external mx_DLL;
function mxGetNumberOfElements; external mx_DLL;
function mxGetNumberOfFields; external mx_DLL;
function mxGetPi; external mx_DLL;
function mxGetPr; external mx_DLL;
function mxGetScalar; external mx_DLL;
function mxGetString; external mx_DLL;
function mxGetUserBits; external mx_DLL;
procedure mxInitStaticArray; external mx_DLL;
function mxIsCell; external mx_DLL;
function mxIsChar; external mx_DLL;
function mxIsClass; external mx_DLL;
function mxIsComplex; external mx_DLL;
function mxIsDouble; external mx_DLL;
function mxIsEmpty; external mx_DLL;
function mxIsFinite; external mx_DLL;
function mxIsFromGlobalWS; external mx_DLL;
function mxIsInf; external mx_DLL;
function mxIsInt16; external mx_DLL;
function mxIsInt32; external mx_DLL;
function mxIsInt8; external mx_DLL;
function mxIsLogical; external mx_DLL;
function mxIsNaN; external mx_DLL;
function mxIsNumeric; external mx_DLL;
function mxIsSingle; external mx_DLL;
function mxIsSparse; external mx_DLL;
function mxIsStruct; external mx_DLL;
function mxIsUInt16; external mx_DLL;
function mxIsUInt32; external mx_DLL;
function mxIsUInt8; external mx_DLL;
function mxMalloc; external mx_DLL;
function mxRealloc; external mx_DLL;
procedure mxSetAllocFcns; external mx_DLL;
procedure mxSetAllocListeners; external mx_DLL;
procedure mxSetCell; external mx_DLL;
procedure mxSetClassName; external mx_DLL;
procedure mxSetData; external mx_DLL;
procedure mxSetDimensions; external mx_DLL;
procedure mxSetField; external mx_DLL;
procedure mxSetFieldByNumber; external mx_DLL;
procedure mxSetImagData; external mx_DLL;
procedure mxSetLogical; external mx_DLL;
procedure mxSetFromGlobalWS; external mx_DLL;
procedure mxSetName; external mx_DLL;
procedure mxSetM; external mx_DLL;
procedure mxSetN; external mx_DLL;
procedure mxSetOutOfMemoryListener; external mx_DLL;
procedure mxSetPr; external mx_DLL;
procedure mxSetPi; external mx_DLL;
procedure mxSetNzmax; external mx_DLL;
procedure mxSetIr; external mx_DLL;
procedure mxSetJc; external mx_DLL;
procedure mxSetUserBits; external mx_DLL;
{mex-Funktionen knnen nicht in einer eigenen .EXE gerufen werden}
procedure mexAddFlops; external 'MATLAB.EXE';
function mexAtExit; external 'MATLAB.EXE';
function mexCallMATLAB; external 'MATLAB.EXE';
procedure mexGetCallMATLABFunction; external 'MATLAB.EXE';
function mexEvalString; external 'MATLAB.EXE';
function mexGet; external 'MATLAB.EXE';
function mexGetArray; external 'MATLAB.EXE';
function mexGetArrayPtr; external 'MATLAB.EXE';
procedure mexGetFunctionHandle; external 'MATLAB.EXE';
procedure mexLock; external 'MATLAB.EXE';
procedure mexErrMsgTxt; external 'MATLAB.EXE';
function mexFunctionName; external 'MATLAB.EXE';
function mexIsGlobal; external 'MATLAB.EXE';
function mexIsLocked; external 'MATLAB.EXE';
procedure mexMakeArrayPersistent; external 'MATLAB.EXE';
procedure mexMakeMemoryPersistent; external 'MATLAB.EXE';
procedure mexPrintAssertion; external 'MATLAB.EXE';
function mexPrintf; external 'MATLAB.EXE';
function mexPutArray; external 'MATLAB.EXE';
procedure mexRegisterFunction; external 'MATLAB.EXE';
function mexSet; external 'MATLAB.EXE';
procedure mexSetTrapFlag; external 'MATLAB.EXE';
procedure mexSubsAssign; external 'MATLAB.EXE';
function mexSubsReference; external 'MATLAB.EXE';
procedure mexUnlock; external 'MATLAB.EXE';
procedure mexWarnMsgTxt; external 'MATLAB.EXE';
function mexPrintf0; external 'MATLAB.EXE' name 'mexPrintf';
function mexPrintf1; external 'MATLAB.EXE' name 'mexPrintf';
function mexPrintf2; external 'MATLAB.EXE' name 'mexPrintf';
function mexPrintf3; external 'MATLAB.EXE' name 'mexPrintf';
function mexPrintf4; external 'MATLAB.EXE' name 'mexPrintf';
function mexPrintf5; external 'MATLAB.EXE' name 'mexPrintf';
function mexPrintf6; external 'MATLAB.EXE' name 'mexPrintf';
function mexPrintf7; external 'MATLAB.EXE' name 'mexPrintf';
function mexPrintf8; external 'MATLAB.EXE' name 'mexPrintf';
const
mat_DLL='MATLAB.EXE';
{ndern auf 'LIBMAT.DLL', wenn eigene .EXE auf Dateien zugreifen soll}
function matClose; external mat_DLL;
function matDeleteArray; external mat_DLL;
function matGetArray; external mat_DLL;
function matGetArrayHeader; external mat_DLL;
function matGetDir; external mat_DLL;
function matGetFp; external mat_DLL;
function matGetNextArray; external mat_DLL;
function matGetNextArrayHeader; external mat_DLL;
function matOpen; external mat_DLL;
function matPutArray; external mat_DLL;
function matPutArrayAsGlobal; external mat_DLL;
function engClose; external 'LIBENG.DLL';
function engEvalString; external 'LIBENG.DLL';
function engGetArray; external 'LIBENG.DLL';
function engOpen; external 'LIBENG.DLL';
function engOutputBuffer; external 'LIBENG.DLL';
function engPutArray; external 'LIBENG.DLL';
end.
Vorgefundene Kodierung: UTF-8 | 0
|