主题:请教一下这个数组越界怎么处理
DTPATH = 'C:\Users\ray\Desktop\test trajectory\Console1\Console1'
DTNAME = 'CdData.mat'
mp = matopen(DTNAME,'r')
if (mp .ne. 0)then
write(*,*)'打开mat文件成功'
endif
dir = matGetDir(mp,ndir)
if(dir .ne. 0)then
write(*,*)'数据地址读取成功'
endif
call mxCopyPtrToPtrArray(dir,adir,ndir)
write (*,*)'ndir=',ndir
do i=1,ndir
call mxCopyPtrToCharacter(adir(i),names(i),32)
enddo
write(*,*)'mat文件地址名输出:'
do i=1,ndir
write(*,*)names(i)
enddo
stat = matClose(mp)
if(stat.eq.0)then
write(*,*)'关闭mat文件成功'
endif
mp = matopen(DTNAME,'r')
if (mp .ne. 0)then
write(*,*)'打开mat文件成功'
endif
ep= engopen('matlab')
if(ep.ne.0)then
write(*,*)'打开matlab引擎成功'
endif
! 写入DATA.DAT 路径名和文件名
! 写入路径名
DTPTH = mxCreateString(DTPATH)
STATUS1 = engPutVariable(ep, 'DTPTH', DTPTH)
! 写入文件名
DTNM = mxCreateString(DTNAME)
STATUS2 = engPutVariable(ep, 'DTNM', DTNM)
IF( (STATUS1 .NE. 0) .OR. (STATUS2 .NE. 0) )THEN
STAT = engEvalString(ep," [DTNM,DTPTH] = uigetfile('*.mat',' Select A MAT-file: ') ")
IF (STAT .eq. 0) THEN
WRITE(6,*) 'engEvalString 成功'
ENDIF
ENDIF
STAT = engEvalString(ep, 'cd(DTPTH)')
IF (STAT .eq. 0) THEN
WRITE(6,*) 'DATA.DAT 加载路径成功 '
ENDIF
STAT = engEvalString(ep, 'load(DTNM)') ! 必须先把DTNM后面的空格处理掉
IF (STAT .eq. 0) THEN
WRITE(6,*) 'MATLAB load .mat文件成功'
ENDIF
I = 1
DO WHILE(I<ndir+1)
PA = matGetVariable(mp,names(i))
M = mxGetM(PA)
N = mxGetN(PA)
write(*,*)names(i)
write(*,*)'M=',M,'N=',N !RS测试m,n
SELECT CASE(names(I))
CASE('CLca')
Allocate(Cd_Cl(M*N),STAT = ERR )
IF(ERR/=0)THEN
Write(6,*) 'CdData: Cd_Cl 分配空间失败!'
PAUSE
STOP
ENDIF
PB = engGetVariable(ep,names(i))
Call mxCopyPtrToReal8(mxGetPr(PB),Cd_Cl,M*N)
CASE('Hca')
Allocate(Cd_H(M*N),STAT = ERR)
IF(ERR/=0)THEN
Write(6,*) 'CdData: Cd_H 分配空间失败!'
PAUSE
STOP
ENDIF
PB = engGetVariable(ep,names(i))
Call mxCopyPtrToReal8(mxGetPr(PB),Cd_H,M*N)
! Len_H = M*N
CASE('Mnca')
Allocate(Cd_M(M*N),STAT=ERR)
IF(ERR==0)THEN
Write(6,*) 'CdData: Cd_M 分配空间成功!'
PAUSE
ENDIF
PB = engGetVariable(ep,names(i))
Call mxCopyPtrToReal8(mxGetPr(PB),Cd_M,M*N) !在这出现了错误
! Len_M = M*N
CASE('Cdd')
nam = names(i)
END SELECT
I = I + 1
DTNAME = 'CdData.mat'
mp = matopen(DTNAME,'r')
if (mp .ne. 0)then
write(*,*)'打开mat文件成功'
endif
dir = matGetDir(mp,ndir)
if(dir .ne. 0)then
write(*,*)'数据地址读取成功'
endif
call mxCopyPtrToPtrArray(dir,adir,ndir)
write (*,*)'ndir=',ndir
do i=1,ndir
call mxCopyPtrToCharacter(adir(i),names(i),32)
enddo
write(*,*)'mat文件地址名输出:'
do i=1,ndir
write(*,*)names(i)
enddo
stat = matClose(mp)
if(stat.eq.0)then
write(*,*)'关闭mat文件成功'
endif
mp = matopen(DTNAME,'r')
if (mp .ne. 0)then
write(*,*)'打开mat文件成功'
endif
ep= engopen('matlab')
if(ep.ne.0)then
write(*,*)'打开matlab引擎成功'
endif
! 写入DATA.DAT 路径名和文件名
! 写入路径名
DTPTH = mxCreateString(DTPATH)
STATUS1 = engPutVariable(ep, 'DTPTH', DTPTH)
! 写入文件名
DTNM = mxCreateString(DTNAME)
STATUS2 = engPutVariable(ep, 'DTNM', DTNM)
IF( (STATUS1 .NE. 0) .OR. (STATUS2 .NE. 0) )THEN
STAT = engEvalString(ep," [DTNM,DTPTH] = uigetfile('*.mat',' Select A MAT-file: ') ")
IF (STAT .eq. 0) THEN
WRITE(6,*) 'engEvalString 成功'
ENDIF
ENDIF
STAT = engEvalString(ep, 'cd(DTPTH)')
IF (STAT .eq. 0) THEN
WRITE(6,*) 'DATA.DAT 加载路径成功 '
ENDIF
STAT = engEvalString(ep, 'load(DTNM)') ! 必须先把DTNM后面的空格处理掉
IF (STAT .eq. 0) THEN
WRITE(6,*) 'MATLAB load .mat文件成功'
ENDIF
I = 1
DO WHILE(I<ndir+1)
PA = matGetVariable(mp,names(i))
M = mxGetM(PA)
N = mxGetN(PA)
write(*,*)names(i)
write(*,*)'M=',M,'N=',N !RS测试m,n
SELECT CASE(names(I))
CASE('CLca')
Allocate(Cd_Cl(M*N),STAT = ERR )
IF(ERR/=0)THEN
Write(6,*) 'CdData: Cd_Cl 分配空间失败!'
PAUSE
STOP
ENDIF
PB = engGetVariable(ep,names(i))
Call mxCopyPtrToReal8(mxGetPr(PB),Cd_Cl,M*N)
CASE('Hca')
Allocate(Cd_H(M*N),STAT = ERR)
IF(ERR/=0)THEN
Write(6,*) 'CdData: Cd_H 分配空间失败!'
PAUSE
STOP
ENDIF
PB = engGetVariable(ep,names(i))
Call mxCopyPtrToReal8(mxGetPr(PB),Cd_H,M*N)
! Len_H = M*N
CASE('Mnca')
Allocate(Cd_M(M*N),STAT=ERR)
IF(ERR==0)THEN
Write(6,*) 'CdData: Cd_M 分配空间成功!'
PAUSE
ENDIF
PB = engGetVariable(ep,names(i))
Call mxCopyPtrToReal8(mxGetPr(PB),Cd_M,M*N) !在这出现了错误
! Len_M = M*N
CASE('Cdd')
nam = names(i)
END SELECT
I = I + 1
END DO
错误提示的是数组越界