Please, Help with Data Reading in Fortran

  • Context: Fortran 
  • Thread starter Thread starter komp
  • Start date Start date
  • Tags Tags
    Data Fortran Reading
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
6 replies · 2K views
komp
Messages
5
Reaction score
0
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
data(i,j,m,n)=dcmplx(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
else
goto 2015
endif
2018 continue
enddo
enddo
enddo
enddo

The sample data is attached.

Thank you very much for your help.
 

Attachments

Last edited:
Physics news on Phys.org
komp said:
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".
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?
komp said:
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
data(i,j,m,n)=dcmplx(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
else
goto 2015
endif
2018 continue
enddo
enddo
enddo
enddo

The sample data is attached.

Thank you very much for your help.
 
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.
 
komp said:
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)
That's not what you wrote in post #1, which I have copied below.
The array data(i,j,m,n) is declared as data(1:Nm,1:Nm,-nw:nw,0:nw-u)
komp said:
And for clarity, nw-u is actually nwu and not a subtraction as it seem to show.
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.
 
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.

Thanks.
 
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?
 
komp said:
It is the same.
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).
komp said:
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.
Show us
  1. The declaration of your array
  2. The declaration of nwu
 
Last edited: