Fortran 77中的动态数组 [英] Dynamic array in Fortran 77

查看:124
本文介绍了Fortran 77中的动态数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在Fortran 77(我正在使用Intel Fortran)中编写一个子例程,该子例程从文本文件中读取测量值并将其存储在矩阵中。

I have to write a subroutine in Fortran 77(i'm using Intel Fortran), which reads the measured values from a text file and stores them in a matrix.

由于测量值的数量始终是可变的,因此我必须动态分配矩阵。

Since the number of measured values is always variable, I must dynamically allocate the matrix.

我知道只能从Fortran 90中进行动态分配,但是那时人们遇到了同样的问题,所以这也是可能的。
您将如何进行?

I know that the dynamic allocation is only possible from Fortran 90, but at that time people had the same problems, so it is also possible. How would you proceed?

我不想为矩​​阵保留太多空间,因为该方法对我而言不切实际。

I do not want to reserve too much space for the matrix because the method is impractical for me.

推荐答案

如果确实受限于Fortran 77,则不进行动态分配。而是声明一个比您认为可能需要的数组大的数组,而数组不能太大以防止程序在目标系统上运行。然后将您的值存储在该大型数组中,分别跟踪所使用的大型数组中有多少个元素。如果您选择的数组大小不够大,请让用户知道并终止程序。

If you really are restricted to Fortran 77, you do not do dynamic allocation. Instead, declare an array that is larger than what you think you will likely need, without it being too large to prevent the program from running on your target system. Then store your values in that large array, separately keeping track of how many elements of the large array that you use. If your choice of array size was not large enough, let the user know and terminate the program.

人们发现Fortran 77中缺乏动态分配的情况非常严格,因此他们通常使用非标准语言扩展名。如果您决定沿用语言扩展的路径,那么如今在这种情况下使用的对Fortran 77的最佳扩展是Fortran 90引入的可分配数组功能。我认为可以说所有积极维护的编译器都可以处理Fortran 77也将处理Fortran 90可分配数组(然后是一些)。

People found the lack of dynamic allocation in Fortran 77 very restrictive, so they often resorted to using non-standard language extensions. If you decide to go down the path of language extensions, then these days the best extension to Fortran 77 to use in this situation is the allocatable array feature introduced with Fortran 90. I think it is fair to say that all actively maintained compilers that can handle Fortran 77 will also handle Fortran 90 allocatable arrays (and then some).

这篇关于Fortran 77中的动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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