Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Memory Allocation issues in FORTRAN 90

  1. Jun 14, 2013 #1
    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.
     
  2. jcsd
  3. Jun 14, 2013 #2

    Mark44

    Staff: Mentor

    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?
     
  4. Jun 14, 2013 #3

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Why does your READ statement refer to two different I/O units?
     
  5. Jun 14, 2013 #4
    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!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook