matlab调用gfortran编译的fortran程序出现end of file问题

https: // ww2.mathworks.cn/matlabcentral/answers/44388-or-system-or-unix-input-redirection#answer_56185

Executing a GFORTRAN executable within a Apple terminal window is not equivalent to executing it within MATLAB. In particular, MATLAB will set various environment variables and this can have unexpected results which seems to be the case here.

To work around this issue you need to set your environment variables for the GFORTRAN-compiled programs correctly within MATLAB before you execute them. You can use the SETENV function for this purpose. Please execute your FORTRAN script as follows:

setenv(‘GFORTRAN_STDIN_UNIT’, ‘5’)
setenv(‘GFORTRAN_STDOUT_UNIT’, ‘6’)
setenv(‘GFORTRAN_STDERR_UNIT’, ‘0’)
!./forward <
input
setenv(‘GFORTRAN_STDIN_UNIT’, ‘-1’)
setenv(‘GFORTRAN_STDOUT_UNIT’, ‘-1’)
setenv(‘GFORTRAN_STDERR_UNIT’, ‘-1’)

Note that after executing the FORTRAN script, I set the environment variables back to their default values.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注