Neat way to define a long parameter vector in fortran

依然范特西╮ 提交于 2019-11-29 12:26:01

The problem with the parameter is only that you can't define the constant array to depend on itself. But you could define the fundamental quantities, and then the whole array including the derived quantities, as so:

program foo
implicit none

real, dimension(2), parameter :: basic = [2.4, 1.4]
real, dimension(4), parameter :: all = [basic(1), basic(2),           &   
                                        basic(1)*basic(2)**basic(1),  &
                                        abs(basic(1))]

print *, basic
print *, all

end program foo

and in fact if you want to go that way, you might as well name the fundamental quantities:

program foo
implicit none

real, parameter :: height = 2.4, bodymass = 1.4
real, dimension(4), parameter :: all = [height, bodymass,     &   
                                        height*bodymass**2,  &
                                        abs(height)]

print *, height, bodymass
print *, all

end program foo

I can't imagine height is the sort of thing you need to take the absolute value of, but you see my point.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!