Can Fortran 90 Arrays Be Dynamically Allocated Based on a Variable?

  • Context: Fortran 
  • Thread starter Thread starter truparel
  • Start date Start date
  • Tags Tags
    Array Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
truparel
Messages
1
Reaction score
0
Hello forum,

I was wondering if there is a way to declare/define arrays depending on some previously defined variable.

example:

if a=2, then declare/define 2 arrays
if a=3, then declare/define 3 arrays

If doable, how does one assign names to these arrays?
 
Physics news on Phys.org
what you can do is declared all 3 arrays as "allocatable", then, depending on a=2 or a=3, you go ahead and allocate as necessary.

please read up on "allocatable" and take a shot at some Fortran code. Hint: it's very, very simple.