单个fortran模块在多个文件中 [英] Single fortran module in multiple files

查看:189
本文介绍了单个fortran模块在多个文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚阅读了有关正确方法的非常好的问题/答案这里在Fortran中使用模块。通过在模块中编写子例程,除了阐明代码之外,还要使它们变得明确。

据我所知,模块必须放在单个文件中mod_exemple.f90。
我编写的程序通常非常长,有许多子程序可以按目的进行排序,因此可以放在模块中。问题在于:非常长的模块文件,有几百行。



你可以把一个模块分成几个文件吗?建议吗?为什么?你有其他的建议,分裂吗?

解决方案

我会advoid分裂一个模块在多个文件,这不是一个标准的做法而且如果所有相关的例程都在同一个文件中,我会发现它更难以阅读/理解。如果你的模块太大,我强烈建议重新思考模块的逻辑,看看你是否不能将常用的代码和实用程序分解到它们自己的模块中。而不是让你的相关的代码分布在多个文件中,一个有文档记录的,格式良好的单个文件模块源将是最好的解决方案,无论需要多少行。


I just read the very good question/answers here about proper ways to use modules in Fortran. By writing subroutines in modules, one makes them explicit, in addition to clarifying the code.

To my knowledge, a module has to be put in a single file, for instance "mod_exemple.f90". Programs I write are often very long, with many subroutines that indeed could be sorted by purpose and thus be put in modules. The problem: that would do very long module files, with hundreds of lines.

Can you split a module over several files? Is it advised? Why? Do you have other suggestions that splitting?

解决方案

I would advoid splitting a module over mutiple files, it is not that standard a practice and I would find it more difficult to read/understand than if all related routines were in the same file. If your modules are too large then I strongly suggest rethinking the logic of the modules and seeing if you cannot factor out common code and utility routines into their own modules. Rather than having your related code spread across multiple files a well documented, well formated single file module source would be best solution, regardless of how many lines that takes.

这篇关于单个fortran模块在多个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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