0

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/

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Or in FORTRAN 77 we always have EQUIVALENCE.
Shame on you @VladimirF for even thinking about EQUIVALENCE let alone suggesting it !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.