• FORTRAN混合编程笔记


    FORTRAN混合编程笔记

    1、C++调用FORTRAN静态链接库
    • 首先将FORTRAN编译成静态链接库(***.lab)文件;
    • 在VS中创建一个C++工程文件
    • 创建一个f2c.h头文件,主要目的是将FORTRAN的变量类型和C++的变量类型做一个转换
    /* f2c.h  --  Standard Fortran to C header file */
    
    /**  barf  [ba:rf]  2.  "He suggested using FORTRAN, and everybody barfed."
    
    	- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
    
    	/* 2008 Feb 18  James M Anderson  --MPIfR  --edit the standard f2c.h header
    										to select just what is needed for basic
    										FORTRAN interaction in C, as the standard
    										f2c.h is incompatible with C++ <vector> */
    
    #ifndef F2C_INCLUDE
    #define F2C_INCLUDE
    
    typedef int integer;
    typedef unsigned int uinteger;
    typedef char *address;
    typedef short int shortint;
    typedef float real;
    typedef double doublereal;
    typedef struct { real r, i; } complex;
    typedef struct { doublereal r, i; } doublecomplex;
    typedef int logical;
    typedef short int shortlogical;
    typedef char logical1;
    typedef char integer1;
    #ifdef INTEGER_STAR_8	/* Adjust for integer*8. */
    typedef long long longint;		/* system-dependent */
    typedef unsigned long long ulongint;	/* system-dependent */
    #endif
    
    /* Extern is for use with -E */
    #ifndef Extern
    #define Extern extern
    #endif
    
    /* procedure parameter types for -A and -C++ */
    
    
    
    #endif /* F2C_INCLUDE */
    
    
    • 在函数声明头文件中开头和结尾使用以下宏定义
    #ifdef __cplusplus
    extern "C" {
    #endif
    	extern 函数返回类型 函数名(函数参数);
        ...
    #ifdef __cplusplus
    }
    #endif
    
    • 在函数定义文件前添加如下宏定义,用于调用静态链接库中的子函数时使用。
    #ifndef FTN_NAME
    #define FTN_NAME(a)                               a
    #endif
    

    如需要调用静态链接库中一个名为iristec的函数时则可以写成FTN_NAME(iristec)();

    • 在进行函数传值的时候一定要注意原FORTRAN程序中变量的类型,如果是指针则要传变量地址进去。
    • 注意函数定义文件的文件后缀必须是.c,否则无法编译成功。
    2、C++编译动态链接库(***.DLL)
    • 函数声明时前面加上__declspec(dllexport)
  • 相关阅读:
    网络与系统安全第四次作业
    2018-2019-1 20189203《linux内核原理与分析》第六周作业
    《网络攻防实践》第五周作业
    《网络攻防实践》第四周作业
    《网络攻防实践》第三周作业
    《网络攻防实践》第二周作业
    《网络攻防实践》第一周作业
    《Linux内核原理与分析》第九周作业
    《Linux内核原理与分析》第八周作业
    《Linux内核原理与分析》第七周作业
  • 原文地址:https://www.cnblogs.com/hellovan/p/10776663.html
Copyright © 2020-2023  润新知