Please, Help with Data Reading in Fortran

  • Context: Fortran 
  • Thread starter Thread starter komp
  • Start date Start date
  • Tags Tags
    Data Fortran Reading
Click For Summary

Discussion Overview

The discussion revolves around issues related to reading data in Fortran, specifically focusing on array declarations and subscript errors encountered during data reading. Participants are seeking assistance with a coding problem involving the correct interpretation of array bounds and variable definitions.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes an error message indicating that a subscript of an array is out of bounds, specifically mentioning that "Subscript #4 of the array data has value 1 which is greater than the upper bound of 0".
  • Another participant questions the declaration of the variable 'u', suggesting it might be a typo for 'nu', and seeks clarification on its definition.
  • A participant clarifies that the array is declared as complex*16:: data(1:Nm,1:Nm,-nw:nw,0:nwu), indicating that 'nw-u' is actually 'nwu' and not a subtraction.
  • There is a contention regarding the consistency of the array declaration between posts, with one participant noting a discrepancy between the initial declaration and the later clarification.
  • Another participant emphasizes the importance of the exact variable names used in the code, pointing out that 'nw-u' and 'nwu' are treated differently by the compiler.
  • Participants express frustration over the lack of clarity in the original post and the need for more information about the variable declarations to provide effective help.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the error. There are competing views regarding the interpretation of the variable names and their implications for the array bounds. The discussion remains unresolved as participants seek further clarification and information.

Contextual Notes

There are limitations in the information provided, particularly regarding the definitions of variables and the exact code snippets. The discussion highlights the dependency on precise variable names and declarations in Fortran programming.

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:
Technology 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:

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
9K