如何从C头文件准备一个fortran模块? [英] How to prepare a fortran module from a C header file?

查看:133
本文介绍了如何从C头文件准备一个fortran模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个纯C文件,该文件具有6个函数,我想让它们供fortran程序员使用:

I have this pure C file with 6 functions that I want to make available for fortran programmers:

http://tinyfiledialogs.sourceforge.net

C到Fortran的导入"可以工作吗?

Could C to Fortran "Import" work ?

我应该简单地准备像Fortran头文件一样的东西吗?

Should I simply prepare something like a Fortran header file instead ?

我意识到我的C代码正在使用几个Unix或Windows C头文件,这会使转换复杂化.但是,肯定可以为6 C函数提供与Fortran标头等效的功能.

I realise that my C code is using several Unix or Windows C header files, and this will complicate the conversion. But surely offering the equivalent of a Fortran header for 6 C functions must be achievable.

char const * tinyfd_inputBox (
    char const * const aTitle ,
    char const * const aMessage ,
    char const * const aDefaultInput ) ; 
   // the returned value is a static array

edit:我开始意识到模块实际上是依赖于编译器的. 也许我应该准备一个可以同时生成C对象文件和fortran模块来使用它的makefile.

edit: I am starting to realize that modules are actually compiler-dependent. Maybe I should instead prepare a makefile that would produce both the C object file and the fortran module to use it.

推荐答案

如果您的目的是使fortran程序员的工作更轻松,并帮助他们直接在程序中使用C代码,那么您可能想看看生成fortran模块提供接口.这些与示例标题有些相似,因为它们定义了例程类型以及所需的输入和输出.

If your aim is to make life easy for fortran programmers and help them to use your C code directly in their program then you probably want to look at generating fortran modules that provide interfaces. These are somewhat similar to your example header in that they define the routine type and the required inputs and outputs.

我在这方面没有特别的经验,所以在这里我不举一个具体的例子,但我将带您参考此网站.另一个有用的信息来源是查看其他程序包如何执行此操作,例如 netcdf PETSc .

I'm not particularly experienced in this so I won't give a specific example here but I'll refer you to this site. Another useful source of information would be to look at how other packages do this, for example netcdf and PETSc.

这篇关于如何从C头文件准备一个fortran模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆