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

Fortran Please, Help with Data Reading in Fortran

  1. May 30, 2015 #1
    I have been trying to read in a data using Fortran but for some reasons, it doesn't read the data correctly. Please, any help will be appreciated. To read the data, I used the following (Note, for the attached data, Nm=1, nw-nu=5, nw=10).
    The array data(i,j,m,n) is declared as data(1:Nm,1:Nm,-nw:nw,0:nw-u). When it tries reading, it spits the error message "Subscript #4 of the array data has value 1 which is greater than the upper bound of 0". A snippet of the code is below.

    2015 read(40,"(a72)") lineda
    do n=0,nu
    do m=-nw,nw-nu
    do i=1,Nm
    do j=1,Nm
    if(index(lineda(1:72),'data') /= 0 ) then
    read(40,"(1x,i2,1x,i2,2x,i5,2x,i5,1x,2(1x,e15.8))",IOSTAT=istat) i1,i2,i3,i4,r1,r2
    write(809,"(1x,i2,1x,i2,2x,i5,2x,i5,1x,2(1x,e15.8))") i,j,m,n,data(i,j,m,n)
    if(istat /= 0) goto 2018
    goto 2015
    2018 continue

    The sample data is attached.

    Thank you very much for your help.

    Attached Files:

    Last edited: May 30, 2015
  2. jcsd
  3. May 30, 2015 #2


    Staff: Mentor

    You don't show the actual array declaration, so I'll have to take your word that it is declared as you say above. The fourth dimension of array has indexes that range betwee 0 and nw - u.

    What is u? You don't mention it above. Was this a typo and it should be nu?
  4. May 30, 2015 #3
    Thank you very much for your assistant.
    Sorry as I wasn't explicit enough. The array is declared as:
    complex*16:: data(1:Nm,1:Nm,-nw:nw,0:nwu)
    And for clarity, nw-u is actually nwu and not a subtraction as it seem to show.
  5. May 30, 2015 #4


    Staff: Mentor

    That's not what you wrote in post #1, which I have copied below.
    So if it's actually nwu, what is the value of nwu?

    Your error message shows that there is a problem with subscript 4 of your array.
  6. May 30, 2015 #5
    It is the same. I just explained that nw-u is actually nwu and not subtraction as it seem to show. Yes, it shows that the error is in the 4th argument but I don't know why it should be out of bound when I clearly defined it.

  7. May 30, 2015 #6


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Compilers are totally literal beasts.

    You may have written "nwu" in your declaration, but somehow, the compiler is reading and trying to figure out what to do with "nw-u", since that is what you copied from your source file.

    Without any other reference for us to look at, how are we supposed to help you solve this problem?
  8. May 30, 2015 #7


    Staff: Mentor

    NO! nw-u and nwu are completely different!

    You wrote nw-u in your post (which I quoted verbatim), but you didn't include the part of your code where you actually declared your array (named data).
    Show us
    1. The declaration of your array
    2. The declaration of nwu
    Last edited: May 31, 2015
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook