Fortran77 write(0,*) DLL 命令未刷新到 R GUI 控制台

Fortran77 write(0,*) DLL command not flushing to R GUI console

我有一个 Fortran77 源代码,其中包含许多格式的打印命令:

write(fileID,label)somevariable

此 F77 代码通过 "R CMD SHLIB code.f" 编译为从 R 调用的 DLL。如果 F77 代码中的 fileID 是常规文本文件,则该命令可以正常工作。但是,如果是标准控制台输出, 即 fileID = 0 ,R 创建一个 "fort.0" 临时文件,而不是在 R GUI 控制台 window.

中显示输出

此问题仅出现在我的 Windows 64 位版本中。在 Linux 32 位和 64 位下,fileID = 0 的输出在控制台中正确显示。

我已经尝试过 flush.console() 命令。没有成功。

也许有人知道如何解决这个问题吗?不幸的是,在 R 中重写 F77 的 write(0,*) 命令不是一个选项。

谢谢!

您不应该在加载到 R 中的扩展模块中使用本机打印方法。Writing R Extensions 是这样说的:

6.5.1 Printing from FORTRAN

On many systems FORTRAN 'write' and 'print' statements can be used, but the output may not interleave well with that of C, and will be invisible on GUI interfaces. They are not portable and best avoided.

Three subroutines are provided to ease the output of information from FORTRAN code.

 subroutine dblepr(LABEL, NCHAR, DATA, NDATA)
 subroutine realpr(LABEL, NCHAR, DATA, NDATA)
 subroutine intpr (LABEL, NCHAR, DATA, NDATA)

Here LABEL is a character label of up to 255 characters, NCHAR is its length (which can be '-1' if the whole label is to be used), and DATA is an array of length at least NDATA of the appropriate type ('double precision', 'real' and 'integer' respectively). These routines print the label on one line and then print DATA as if it were an R vector on subsequent line(s). They work with zero NDATA, and so can be used to print a label alone.

我更了解 C/C++ 方面,我们肯定必须使用 Rprintf() 等才能使输出与 R 自己的输出流很好地协作。