本文介绍了fortran动态变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写代码,我需要将数组定义为u1,u2,u3.我要求定义的变量数量由用户决定.例如,如果用户输入整数值"7".然后定义的变量为u1,u2,u3,u4,u5,u6,u7.因此,数组的变量名是由用户输入的值定义的.
I am writing a code where I need to arrays defined as u1,u2,u3.I require that number of variables defined are dictated by the user. for example if the user enters an integer value of "7". Then the variables defined are u1,u2,u3,u4,u5,u6,u7.So the variable names for the arrays are being defined by what value the user enters.
推荐答案
从问题描述中,您只需要一个可分配的数组.
From the description of your problem, you simply want an allocatable array.
TYPE(whatever), ALLOCATABLE :: u(:)
INTEGER :: some_number
PRINT *, 'Enter the number of things you want:'
READ *, some_number
ALLOCATE(u(some_number))
! work with u(1) through to u(some_number)
Standard Fortran不提供开箱即用"的动态变量命名.
Standard Fortran does not offer dynamic variable naming "out of the box".
这篇关于fortran动态变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!