extern void __stdcall FORTRANFUNCTION(const double *array1, const double *scalar1 [, etc.]); // Since FORTRAN typically expects arguments by reference, arguments are passed // as pointers. To pass values, the FORTRAN code must contain a compiler directive // telling the function to expect a value rather than an address. LRESULT mcadfunction(LPCOMPLEXARRAY array1, LPCCOMPLEXSCALAR scalar1, etc.) // this defines the function before FUNCTIONINFO, using the same variable names // called by the external FORTRAN function. { // some error checking goes here, followed by the // actual call to the FORTRAN function. For example, FORTRANFUNCTION(&array1->hReal[0][0], &scalar1->real [, etc.]); // Either the function call must be in UPPERCASE, or you will have to set // Settings->FORTRAN->External procedures->External name implementation // to "Upper case" in your FORTRAN compiler. Any other C functionality follows... return 0; }
链接库
1. 在 MS Visual C++ 或 Visual Studio 中现有的 C 项目下,选择链接器选项卡,然后从类别菜单中选择输入。在列表末尾的 Object/library modules 文本框中输入 [myfortranlib].lib。
• 用一个特殊函数 (将错误代码返回到调用 C 中,这将优雅地终止线程) 替换 Fortran 代码中所有的 STOP 语句,这是有用的。
• 如果 Fortran 代码包含 PRINT 到控制台语句,则通过将控制台再分配给文件可以转换这些语句,这样输出将到达文件而非屏幕。如果 Fortran 由于一个错误正常终止,则可以编写 C++ 程序读取该日志文件并作为一个窗口显示此文件。例如:
SUBROUTINE INIT_STDOUT () c this subro which redirects FORTRAN output to file use dfwin integer res c CALL close_stdout res=SETENVQQ("FOR_PRINT=C:\FORT_OUT.TXT") c PRINT *, 'Print a character to initialize ' PRINT *,' ' RETURN END