Memory Allocation issues in FORTRAN 90

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 6K views
ZackVM
Messages
2
Reaction score
0
I'm having trouble allocating memory for a dynamic two dimensional array in FORTRAN 90; the odd thing is that when I did the same thing using three on dimensional arrays instead of an array with the dimensions 3*x, I didn't have a problem.

read (1,*) ndat1 !The first line of every file is the number of
read (2,*) ndat2 !rows of data.

allocate (input1(3,ndat1), STAT=AllocateStatus) !Allocating memory for input arrays.
if (AllocateStatus /= 0) STOP "first ***Not enough memory"
allocate (input1(3,ndat2), STAT=AllocateStatus)
if (AllocateStatus /= 0) STOP "***second Not enough memory"

When I run it, I get to 'second Non enough memory', and when I print out an error statement, I get 5014. Does anyone know what is going on? Thanks.
 
on Phys.org
ZackVM said:
I'm having trouble allocating memory for a dynamic two dimensional array in FORTRAN 90; the odd thing is that when I did the same thing using three on dimensional arrays instead of an array with the dimensions 3*x, I didn't have a problem.

read (1,*) ndat1 !The first line of every file is the number of
read (2,*) ndat2 !rows of data.

allocate (input1(3,ndat1), STAT=AllocateStatus) !Allocating memory for input arrays.
if (AllocateStatus /= 0) STOP "first ***Not enough memory"
allocate (input1(3,ndat2), STAT=AllocateStatus)
if (AllocateStatus /= 0) STOP "***second Not enough memory"

When I run it, I get to 'second Non enough memory', and when I print out an error statement, I get 5014. Does anyone know what is going on? Thanks.

It looks to me like you are trying to allocate memory for the same array -- input1 -- twice. Why aren't you using a different array for the 2nd call to allocate?
 
Sorry, I was being dumb; I just didn't catch that typo. Thanks very much; it works now. I changed input1 to input2. I am reading from two separate files, and then building an array for each file, which is why I needed to I/O units. Thanks again!