关于FORTRAN调用matlab出现问题,无从下手,跪求大神指点! 20C

首先说明,我用的是VS2008平台,intel fortran安装在该平台下,matlab为2010a版本
。调用了matlab中的libeng.lib libmat.lib libmex.lib libmx.lib库文件。程序可以编译,但是运行时候出错。代码
!!matlab函数调用模块
!!!!!
module matlab
implicit none

integer ep !指针,用于指向打开的matlab
integer mstatus !非指针,记录命令执行的结果是否有效

integer,external::engOpen,engPutVariable,engGetVariable,engEvalString,engClose
integer,external::mxCreateDoubleMatrix,mxGetPr

contains
!!======================================
!!打开matlab应用程序
subroutine startmatlab()

implicit none
write(*,*)"正在打开matlab应用程序,请稍后......."
ep = engOpen('matlab')
if(ep==0)then
write(*,*)"未能打开matlab应用程序,程序结束"
stop
else
write(*,*)"成功打开matlab应用程序窗口"
endif

endsubroutine startmatlab
!!===================================
!!关闭matlab应用程序
subroutine closematlab()

implicit none
write(*,*)"正在关闭matlab窗口,请稍后......"
mstatus = engClose(ep)
if(mstatus /=0 )then
write(*,*)"未能关闭matlab程序窗口,程序结束"
stop
else
write(*,*)"成功关闭matlab的程序窗口"
endif

endsubroutine closematlab
!!========================================
!!在matlab中执行命令
subroutine mc(string)

implicit none
character(*) string
print ,"正在matlab中计算语句: ",string
if(engEvalString(ep,string) /=0 )then

!!!engEvalString发送命令让 Matlab 执行,参数 ep 为函数 engOpen 返回的引擎指针,字符串 string 为要 matlab 执行的命令。
write(6,
) 'engEvalString failed'
stop
endif
endsubroutine mc
!!==========================================
!!将fortran中的矩阵送到matlab中去
subroutine f2m(fdata,mstring,row,col)

implicit none
integer row,col
real(8) fdata(1:row,1:col)
character(*)mstring
integer ptemp
ptemp = mxCreateDoubleMatrix(row,col,0) !!!mxCreatDoubleMatrix新建一个double 类型数组
if(ptemp==0)then
write(*,*)"无法申请内存"
stop
endif
call mxCopyReal8ToPtr(fdata,mxGetPr(ptemp),row*col)
!!!mxCopyReal8ToPtr将一个Fortran语言的实数类型数组中的数据复制到某个阵列的实数部分或虚数部分中。
!!!fdata为fortran语言的实数类型数组
!!!mxGetPr(ptemp)为指向某个阵列的实数或虚数部分的数据的指针;mxGetPr用来获取矩阵指针
!!!row*col为希望复制的元素的个数
mstatus = engPutVariable(ep,mstring,ptemp) !!!向 Matlab 引擎工作空间写入变量。
call mxDestroyArray(ptemp) !!!释放内存

print *,"正在matlab中生成矩阵:      ",mstring

if(mstatus /= 0)then !!成功返回0
    write(*,*) 'engPutVariable failed'
    stop
endif

endsubroutine f2m
!!==============================================
!!将matlab中的矩阵输入到Fortran中
subroutine m2f(mstring,ddata,row,col)

integer row,col
real(8) ddata(row,col)
character(*)mstring

integer ptemp
ptemp = engGetVariable(ep,mstring) !!!获得当前 Matlab 窗口的显示 / 隐藏情况,可以调用函数:
call mxCopyPtrToReal8(mxGetPr(ptemp),ddata,row*col)
endsubroutine m2f

endmodule

!!=================================================
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
program main
use matlab
implicit none

integer,parameter :: ndata=10
real(8) x(ndata),y(ndata),z(ndata)
integer m
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!给x和y赋值
do m=1,ndata
x(m)=3.1415926587*(m-1)/(ndata-1)
y(m)=sin(x(m))
enddo
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!打开matlab
!call startmatlab()

!!将x和y输出到matlab
call f2m(x,"x",1,ndata)
call f2m(y,"y",1,ndata)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!在matlab中画图
call mc("plot(x,y);title('y=sin(x)';xlable('x');ylable('y'))")

!!在matlab中计算
call mc("z=2*y")

!!将计算结果输出到fortran
call m2f("z",z,1,ndata)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!在fortran中打印结果
print ," x "," y " ," z "
do m=1,ndata
write(
,"(G15.6,G15.6,G15.6)") x(m),y(m),z(m)
enddo

end program main

出错时指向 cookie = systime.ft_struct.dwLowDateTime;
cookie ^= systime.ft_struct.dwHighDateTime;

错误