0

Suppose I have an array A[a,b]. The dimension of a is 2. When a=1, the dimension of b is 3; when a=2, the dimension of b is 6.

For example, one array A looks like

[[1,2,3]
[4,5,6,7,8,9]]

it is combined from 1*3 and 1*6. In total 9 entries, not from input.

Is there any method to define such an array in Fortran? or I need other type of data structure?

AlphaF20
  • 583
  • 6
  • 14

1 Answers1

2

You need to provide a better description of what you want to do. With allocatable entities you can trivially achieve what you have described.

program foo
  integer a, b
  real, allocatable :: x(:,:)
  read(*,*) a
  if (a == 1 .or. a == 2) then
     b = 3 * a
     allocate(x(a,b))
   else
     stop 'Is this right?'
  end if
  x = 1
  print *, shape(x)
end program foo
steve
  • 657
  • 1
  • 4
  • 7