jpcgandre
jpcgandre

Reputation: 1505

Fortran77 define array with integer variables in first column and string variables in the second

How to define array with integer variables in first column and string variables in the second?

For example: The array mELF ideally will have numbers in the first and third columns and strings in the third. I have it working only with integers but now I want to mix different types of variables. Is it possible?

  INTEGER, save :: mELF(11000, 11000, 11000)
  DATA mELF/11000*11000*11000*0/

Upvotes: 0

Views: 577

Answers (1)

High Performance Mark
High Performance Mark

Reputation: 78364

No, it is not possible to mix the types of elements of an array in FORTRAN77, or any more recent edition of the language either. In an array all the elements must be of the same type (and kind).

In modern Fortran, ie 90 and later, you can define a derived type such as;

type my_type
  integer :: col1, col3
  character(len=16) :: col2
end type

and then declare an array such as

type(my_type), dimension(:), allocatable :: my_array

and now you have a data structure which you can slice with expressions such as

my_array % col2

my_array(1:12) % col1

my_array(2:6) % col2(5:8)

and so forth.

Upvotes: 3

Related Questions