#include "fintrf.h" C #if 0 C C dblmatmsf.F C .F file needs to be preprocessed to generate .for equivalent C #endif C C dblmatmsf.f C C double the input matrix C C Microsoft Fortran assumes a C language calling convention when C %val is invoked. Accordingly, if you want to use %val to call a C Fortran subroutine, you must modidy the dblmat.F example to C include extra gateway code that converts the calling convention C assumptions of %val back to Fortran conventions. This code is the C Microsoft version of dblmat.F C This is a MEX-file for MATLAB. C Copyright (c) 1984-98 by The MathWorks, Inc. C $Revision: 1.6 $ C this subroutine is the main gateway to MATLAB C when a MEX function is executed, MATLAB calls C subroutine in the corresponding MEX-file. C DO NOT modify this subroutine declaration subroutine mexFunction(nlhs, plhs, nrhs, prhs) C this is the library needed to set the floating point C exception word and it needs to be here in the code use msflib C----------------------------------------------------------------------- C pointer type C mwpointer plhs(*), prhs(*) mwpointer mxCreateFull, mxGetPr C----------------------------------------------------------------------- C integer nlhs, nrhs integer mxGetM, mxGetN, mxIsNumeric C these are the interfaces needed to accommodate C the use of %val when these function are called. C an 'interface' block needs to added for any C new subroutine that uses %val interface subroutine dbl_mat_msf(out_mat, in_mat, m, n) implicit double precision(A-H,O-Z) integer m, n end subroutine dbl_mat_msf end interface C these interfaces are not necessary for this program, but are C included for convenient use in other user-built programs. interface subroutine mxCopyPtrToReal8(A, B, C) real*8 B integer A, C end subroutine mxCopyPtrToReal8 end interface interface subroutine mxCopyReal8ToPtr(A, B, C) real*8 B integer A, C end subroutine mxCopyReal8ToPtr end interface C user should modify the following code to fit the user's requirements integer m, n C----------------------------------------------------------------------- C pointer type C mwpointer pr_in, pr_out C----------------------------------------------------------------------- C C set the floating-point control word to allow divide by zero C note: this is not used in dbl_mat_msf, but is necessary in C situations where a divide by zero may occur. this is included C here for convenience integer(2) control, newcontrol call getcontrolfpqq(control) newcontrol = control .or. FPCW$ZERODIVIDE call setcontrolfpqq(newcontrol) C Check to see that input and output are present if(nrhs .ne. 1) then call mexErrMsgTxt('One input required.') endif if(nlhs .ne. 1) then call mexErrMsgTxt('One output required.') endif C proceed with the Fortran gateway code m = mxGetM(prhs(1)) n = mxGetN(prhs(1)) C check that the input is numeric if(mxIsNumeric(prhs(1)) .ne. 1) then call mexErrMsgTxt('Input is not numeric') endif pr_in = mxGetPr(prhs(1)) plhs(1) = mxCreateFull(m, n, 0) pr_out = mxGetPr(plhs(1)) C call the computational subroutine call dbl_mat_msf(%val(pr_out), %val(pr_in), m, n) return end C this is the computational routine. it is C same the which can be found in dbl_mat.F subroutine dbl_mat_msf(out_mat, in_mat, m, n) integer m, n integer i real*8 out_mat(20), in_mat(20) do 10 i=1,m*n out_mat(i) = 2 * in_mat(i) 10 continue return end