Fortran Fortran Programming Silverfrost Error 112

Click For Summary
The discussion centers on troubleshooting a Fortran program that produces an error 112 when run. The error likely stems from an array index going out of bounds, specifically when accessing the array S, which has a maximum index of 50, while the code attempts to access S(N+1) under certain conditions. Suggestions include inserting WRITE statements to identify the failure point and ensuring all variables are initialized, as modern compilers enforce stricter checks compared to older ones. The program may not handle even values of N correctly, as the last value of S is never calculated. Properly managing array dimensions and indices is crucial for resolving this error.
carlosg
Messages
1
Reaction score
0
I'm new to Fortran, trying to run this program but when I enter the variables it gives me an error 112.

Please help me find where is the mistake. I copied the program from an old book.

DIMENSION S(50),V(50) ! Element stress and velocity
DIMENSION U(51) ! Nodal displacement
! Double arrays for tabular or graph representation of stress discontinuity
DIMENSION X(102),SP(102)
INTEGER J,JP
WRITE(*,*) 'Number of elements N<=50' ! Imput data
READ(*,*) N
WRITE(*,*) 'Number of time steps NT'
READ(*,*) NT
NP=2*N
DO 10 J=1,N ! Initial state of the system at T=O.
S(J)=0.
V(J)=0.
10 U(J)=0.
DX=1./N ! Length of element
DT=DX ! Time increment
DO 20 I=1,NT ! Beginning of time loop
T=I*DT ! Current time
S1=-1. ! Boundary conditions at free end, J=1
V1=V(1)-S1+S(1)
U(1)=U(1)+V1*DT ! Displacement at J=1
DO 30 J=2,N ! Beginning of element loop
V2=0.5*(V(J)+V(J-1)+S(J)-S(J-1)) ! V and S at right border
S2=S(J-1)+V2-V(J-1) ! of the element J-1
U(J)=U(J)+V2*DT ! Displacement at node J
V(J-1)=V1+V2-V(J-1) ! New values of V and S
S(J-1)=S1+S2-S(J-1) ! for element J-1
V1=V2 ! V and S at left border
S1=S2 ! of element J
30 CONTINUE ! End of element loop
V2=0. ! Boundary conditions at fixed
S2=S(N)+V2-V(N) ! end, J=N+1
V(N)=V1+V2-V(N) ! New values of V and S
S(N)=S1+S2-S(N) ! for element J=N
20 CONTINUE ! End of time loop
! To output of stress discontinuity along the rod length
X(1)=0.
X(2)=0.
SP(1)=S(1)
DO 40 JP=3,NP+2
X(JP)=X(JP-2)+DX
SP(JP-1)=S(JP/2)
40 CONTINUE
OPEN(5,FILE='STRESS') ! Element stress vs. rod length at I=NT
WRITE(5,*)'Element stress vs. rod length'
WRITE(5,*)' X S(X)'
WRITE(5,50)(X(JP+1),SP(JP),JP=1,NP)
50 FORMAT(2X,2(E12.5,2X))
OPEN(7,FILE='RESULTS') ! Control results for NT=2*N
WRITE(7,*) 'Control results for NT=2*N'
WRITE(7,*) 'Input data: N=',N,' ','NT=',NT
WRITE(7,*) 'Benchmark: T=2, U(1 )=2, S(N)=-2, S2=-2'
WRITE(7,*) 'Calculated: T=',T,' ','U(1)=',U(1)
WRITE(7,*) 'S(N)=',S(N),' ','S2=',S2
STOP
END ! End of Program

Thank you very much.
 
Technology news on Phys.org
Enclose programming code in the [\CODE] tags when posting. This helps preserve the original indenting, and Fortran 77 and older versions are sensitive to having statements start in a particular column.

One of your array variables is outside of its dimensioned limits. About the only thing I can suggest is that you insert some WRITE statements inside the loops to determine where the failure is occurring. This particular problem is best solved running the program and not scanning the source.
 
WRITE(*,*) 'Number of elements N<=50' ! Imput data

Above line has spelling error. I don't know if it makes any difference.
 
The text after the '!' is treated as a comment. It is stripped out by the compiler before any code generation takes place and does not affect the execution of the program. The error lies elsewhere.
 
Seemingly F77, the source for sure lost possible indentation; then, again, F77 is a subset of F90. So, I simply copied and pasted the source above and compiled with every line starting in column 1, it compiled and run...I did not see any error message.

Maybe you can paste exactly the entire output when you run it. I don't know anything about Silverfrost and how it runs program...I rather see you starting a DOS terminal of your own, running the program from the command line and seeing all output there.
 
Well, like I said, the program compiled and run for me...but I don't know what I am doing and simply punched a couple of numbers.

Upon second review, I can see that if you specify the maximum allowed N of 50, NP turns out 100 and the last loop let's JP go to NP+2 = 102...the index JP-1=101 which is o.k. for SP of length 102; but the index JP/2=51 is not o.k. for S of length 50.
 
Last edited:
gsal said:
Upon second review, I can see that if you specify the maximum allowed N of 50, NP turns out 100 and the last loop let's JP go to NP+2 = 102...the index JP-1=101 which is o.k. for SP of length 102; but the index JP/2=51 is not o.k. for S of length 50.

I suspect it doesn't work correctly for any even value of N, since the "last" value of S that is used is never calculated.

It might be doing the wrong thing for odd values of N as well, but we don't know what it's supposed to calculate that's just guessing.
 
I see what you mean...the last value in the loop being JP=NP+2 and the index of S being JP/2 = (NP+2)/2 = (2N+2)/2 = N + 1 ...and, you are right, it does not look like the value of S(N+1) is ever calculated...heck, either even or odd N
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
1
Views
2K
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
Replies
1
Views
2K
  • · Replies 75 ·
3
Replies
75
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K