开发者

Looping variable names in fortran 90

开发者 https://www.devze.com 2023-01-15 08:53 出处:网络
I have a large amount of arrays of different dimensions. However, I name them with a sequential order, say var1, var2, and so on. In order to read them, I would be interested in looping over them in s

I have a large amount of arrays of different dimensions. However, I name them with a sequential order, say var1, var2, and so on. In order to read them, I would be interested in looping over them in something like:

do i=1,n
     read(1,*) var<i>
enddo

Of course, since the arrays are of different dimensions, I cannot simply add a dimension and collapse them into a single one.

My impression is 开发者_如何转开发that Fortran does not allow to convert strings into variable names or something similar, so does anybody know how to deal with this?

Thanks!


What you are asking would essentially be metaprogramming in a (very) traditional compiled language. You can't really do that.

The closest I can think of for Fortran would be to get hold of a compiler that supports some of the OO stuff in Fortran 2003, and use its runtime polymorphisim. That way you could create a parent array class, then a subclass for each different set of array bounds, and then loop through an array of those.

0

精彩评论

暂无评论...
验证码 换一张
取 消