views:

36

answers:

1

Hi,

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!

+1  A: 

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.

T.E.D.