What are custom functions

How to use Fortran in custom functions
Build Fortran libraries
1. Create a new Fortran Static Library project in Compaq Visual Fortran 6.6B and add your files to the project.
2. On the Build menu, click Set Active Configuration and select Release.
3. Compile and build the code. The Fortran project's Release subfolder now contains [myfortranlib] .lib.
Change the C code for the customized function
If you have the Fortran library you need to add your C code:
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. In an existing C project in MS Visual C ++ or in Visual Studio, select the Linker tab, then select Input from the Category menu. Enter [myfortranlib] .lib in the Object / library modules text box at the end of the list.
2. Enter libc.lib in the Ignore libraries text box.
3. Enter the path of the [myfortranlib] .lib file in the Additional Library Path text field, e.g. C: \ temp.
4. Compile and build the DLL.
Additional Information
• The Fortran code must be executed as an independent thread, but not directly as a function. Even if the process is aborted, e.g. by pressing Esc, the entire thread can be terminated in this way without checking which Fortran subroutine is currently active.
• It is helpful to replace all STOP statements in Fortran code with a special function that returns an error code to the calling C code, which terminates the thread properly.
• If the Fortran code includes PRINT for console instructions, these can be converted by reassigning the console to a file; then the output is directed to a file and not to the screen. If the Fortran routine exits with an error, the C ++ front end can be programmed to read this log file and display it as a window. Example:
c this subro which redirects FORTRAN output to file
use dfwin
integer res

c CALL close_stdout

c PRINT *, 'Print a character to initialize'
PRINT *, ''
• To distribute a Fortran-based DLL, the appropriate Fortran runtime libraries must be installed on the computer on which it is running. You can use the following Fortran runtime libraries:
If these DLLs are missing, errors will occur. The DLLs are included in the Fortran compiler package. You need to install it in the Windows / system32 / or WINNT / system32 / directory.
Related topics