Fortran Memory Allocation issues in FORTRAN 90

AI Thread Summary
The discussion revolves around issues with memory allocation for a dynamic two-dimensional array in FORTRAN 90. The user initially encounters an error when trying to allocate memory for the array `input1` with dimensions based on values read from two different files. The error message indicates insufficient memory during the second allocation attempt. A key point raised is the confusion about using the same array name for both allocations. After clarification, it is revealed that the user needed to allocate a different array, `input2`, for the second file, which resolved the memory allocation issue. The user successfully implemented the change and confirmed that the problem was fixed.
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.
 
Technology news 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?
 
Why does your READ statement refer to two different I/O units?
 
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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
2
Views
5K
Replies
2
Views
3K
Replies
5
Views
3K
Replies
4
Views
11K
Replies
5
Views
8K
Replies
20
Views
6K
Replies
8
Views
3K
Back
Top