In my programme, I require a mulitidimensional array, in which the length of second and third dimension depend on the index of the first dimension. This is not directly possible with normal array in Fortran 90. Is there a equivalent of Class (in this sense) in Fortran that I can use here ?
Asked
Active
Viewed 149 times
1
-
1Is it strictly required to use a 25 year old Standard of Fortran, or are you at liberty to choose a more recent version? – Alexander Vogt Jul 11 '16 at 08:50
-
@AlexanderVogt : I am using FORTRAN 90. – user35952 Jul 11 '16 at 09:06
1 Answers
0
Yes, this is possible by using derived types:
type myType
integer :: index
integer,allocatable :: arr(:,:)
end type
You can assign the scalar by
type(myType) :: var
var%index = 10
and similarly allocate the array:
allocate( var%arr( var%index, var%index ) )

Alexander Vogt
- 17,879
- 13
- 52
- 68
-
-
-
If I have the defintion of some type in the program, can I define a variable of that type in the subroutine too (without having to define the type again in subroutine) ? – user35952 Jul 11 '16 at 09:44
-
If you put the derived type declaration into a module (and `use` that module), yes. – Alexander Vogt Jul 11 '16 at 10:05