fortran中具有未知等级(形状)的子例程参数 [英] subroutine argument with unknown rank (shape) in fortran

查看:52
本文介绍了fortran中具有未知等级(形状)的子例程参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在Fortran中最好地处理一个接受未知等级参数的子程序.例如:

 实数* 8 :: array1(2,2),array2(2,2,3)调用mysubroutine(array1)调用mysubroutine(array2) 

就目前而言,我总是需要在子程序中固定形状(等级数).

例如,内在子例程 random_number ( array )可以执行.(但是也许它不是用Fortran编码的?)

解决方案

您必须为每个数组等级编写一个特定的子例程,但是您需要创建一个通用接口,以便可以对所有等级使用通用调用,而不必不必弄清楚要致电的具体电话.在如何编写分配"包装器的示例代码

I am wondering how to best handle in Fortran a subroutine that takes an argument of unknown rank. For instance:

Real * 8 :: array1(2,2),array2(2,2,3)

call mysubroutine(array1)
call mysubroutine(array2)

As for now, I always need to fix the shape (number of rank) in the subroutine.

For instance, the intrinsic subroutine random_number(array) can do. (But maybe it is not coded in Fortran?)

解决方案

You have to write a specific subroutine for each array rank, but you create a generic interface so that you can use a generic call for all the ranks and don't have to figure out the specific one to call. There is example code at how to write wrapper for 'allocate'

这篇关于fortran中具有未知等级(形状)的子例程参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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