Errors during executing the program (Compaq Visual Fortran)

Click For Summary

Discussion Overview

The discussion revolves around issues encountered while executing a program written in Compaq Visual Fortran 6.6, specifically related to generating log-normally distributed random numbers. Participants explore the behavior of the program when attempting to generate a larger number of random values, noting that it runs without errors for a limited range but fails to progress beyond a certain point.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • Some participants note that the program executes correctly for values of j up to 117 but fails to progress beyond that without error messages.
  • One participant suggests that the truncation of input values when read as REAL variables may affect calculations, proposing the use of DOUBLE PRECISION to avoid loss of significant digits.
  • Another participant mentions the possibility of an infinite loop occurring after j = 117, where a specific condition leads to repeated evaluations without progress.
  • A participant expresses gratitude for assistance received and shares that switching to DOUBLE PRECISION allowed them to extend the calculation steps to 530, but they still seek to reach 6000 steps.
  • Some participants recommend inserting WRITE statements to monitor key values during execution for debugging purposes.

Areas of Agreement / Disagreement

Participants generally agree that there are issues with the program's execution beyond a certain point, but the exact cause remains debated, with multiple hypotheses presented regarding data type handling and potential infinite loops.

Contextual Notes

Limitations include potential truncation of floating-point values due to the use of REAL data types, which may impact the calculations. The discussion also highlights the need for debugging tools to identify logical errors in the program.

Who May Find This Useful

Readers interested in programming in Fortran, particularly those dealing with random number generation and debugging techniques, may find this discussion relevant.

js6201
Messages
7
Reaction score
0

Homework Statement


First of all, I used the Window xp & Compaq Visual Fortran 6.6 installed in VMware workstation.
In my case, there are no compile and link errors in source code, and excuting that program is also done.
But I want to generate 300 random numbers by using my program (Log-normally distributed).
In the case of j=1,2,3,...,117, there is no errors. but,
the case of j is larger than 117, the error is occurred (no error messages in window console, but
no calculation....The calculation step is not progressed...).
The source code is attached below...

<Input Data>
3.93e-5,235421, 65889643, 15484354, 1235487, 4758, 85697, 2.9624, -14.5322

2. Homework Equations


Algorithms 712: Generate a normally distributed pseudo-random number.
The algorithm uses the ratio of uniforms method of A.J. Kinderman and J.F. Monahan augmented with quadratic bonding curves.

The Attempt at a Solution



In the first time, I see the message "image expended maximum..." So, I added the ignore terms in setting menu, (/ignore:4084).
Fortran:
Program Test

Implicit none

integer i, n0d, j

real xkbdot, m, lkbdot(310)

real seed1, seed2, a1, b11, c1, d1, sigma, mu

real X1, X2, S, T1, A, B, R1, R2, RANDN(310)

real u(310), v(310), q(310), kbdot(310)

real rand1(310), rand2(310), x(310), y(310)

open(unit=1, file="input", form="formatted", status="unknown")

read(1,*) xkbdot, SEED1, SEED2, A1, B11, C1, D1, sigma, mu

j=1

X1=MOD(A1*SEED1,B11)

X2=MOD(C1*SEED2,D1)

RAND1(j)=X1/B11

RAND2(j)=X2/D1

SEED1=X1

SEED2=X2

DO WHILE (j .le. 150)

X1=MOD(A1*SEED1,B11)

X2=MOD(C1*SEED2,D1)

RAND1(j)=X1/B11

RAND2(j)=X2/D1

SEED1=X1

SEED2=X2

C... Generate Log-normally Distributed Random Numbers.....C

S=0.449871

T1=-0.386595

A=0.19600

B=0.25472

R1=0.27597

R2=0.27846

C... Generate P=(u,v) uniform in rectangle enclosing acceptance region .....C

  50 u(j)=RAND1(j)

v(j)=RAND2(j)

v(j)=1.7156*(v(j)-0.5)

C... Evaluate the quadratic form .....C

X(j)=u(j)-S

Y(j)=ABS(v(j))-T1

Q(j)=X(j)**2+Y(j)*(A*Y(j)-B*Y(j))

C... Accept P if inside inner ellipse .....C

IF (Q(j) .LT. R1) GO TO 100

C... Reject P if outside outer ellipse .....C

IF (Q(j) .GT. R2) GO TO 50

C... Reject P if outside acceptance region .....C

IF (v(j)**2 .GT. -4.0*LOG(u(j))*u(j)**2) GO TO 50

C... Return ratio of P's coordinate as the normal deviate .....C

  100 RANDN(j)=v(j)/u(j)

C... Generate value of kbdot .....C

LKBDOT(j)=RANDN(j)*sigma+mu

IF (LKBDOT(j) .gt. -2.30) then

KBDOT(j)=xkbdot

ELSE

KBDOT(j)=exp(LKBDOT(j))

END IF

write(*,*) j, KBDOT(j)

j=j+1

End do

End
 
Physics news on Phys.org
js6201 said:

Homework Statement


First of all, I used the Window xp & Compaq Visual Fortran 6.6 installed in VMware workstation.
In my case, there are no compile and link errors in source code, and excuting that program is also done.
But I want to generate 300 random numbers by using my program (Log-normally distributed).
In the case of j=1,2,3,...,117, there is no errors. but,
the case of j is larger than 117, the error is occurred (no error messages in window console, but
no calculation....The calculation step is not progressed...).
The source code is attached below...

<Input Data>
3.93e-5,235421, 65889643, 15484354, 1235487, 4758, 85697, 2.9624, -14.5322

2. Homework Equations


Algorithms 712: Generate a normally distributed pseudo-random number.
The algorithm uses the ratio of uniforms method of A.J. Kinderman and J.F. Monahan augmented with quadratic bonding curves.

The Attempt at a Solution



In the first time, I see the message "image expended maximum..." So, I added the ignore terms in setting menu, (/ignore:4084).
You should be aware that reading in strings of digits as a REAL variable will only provide a certain number of floating point digits in the program's internal data storage.

For example, READing in "65889643" for SEED1 will probably result in the value of 65889600 being stored for use in further calculations. The REAL data type in Fortran will store about 6-7 of the most significant digits of an input. If you want to store more digits, the DOUBLE PRECISION data type must be used.

What effect the truncation of the input values of SEED1, SEED2, and A1 has on subsequent calculations is unknown, but since the program terminates without obvious error messages being issued, you should insert some WRITE statements into your code to display or print key values of the calculations for checking after the program terminates.
 
  • Like
Likes   Reactions: js6201
SteamKing said:
You should be aware that reading in strings of digits as a REAL variable will only provide a certain number of floating point digits in the program's internal data storage.

For example, READing in "65889643" for SEED1 will probably result in the value of 65889600 being stored for use in further calculations. The REAL data type in Fortran will store about 6-7 of the most significant digits of an input. If you want to store more digits, the DOUBLE PRECISION data type must be used.

What effect the truncation of the input values of SEED1, SEED2, and A1 has on subsequent calculations is unknown, but since the program terminates without obvious error messages being issued, you should insert some WRITE statements into your code to display or print key values of the calculations for checking after the program terminates.

Dear StreamKing
I really appreciate your help for me! :) It is really helpful for me. But.. I change the variables from real to real*8(double precision) and get more results..
For example, before (real*4 or real) ---> only the calculation step is obtained to 117 and
after the revision , I have got the results the step to 530 but ...I want 6000th step because I perform the montecarlo simulation..
Why the calculation step is stopped and there are no messages...
In Console window, I check the error,
write(*,*) j, kbdot(j), but the error is not appeared...
What can I do...
Thansk you so much in advance!
 
Hi,

Use the debugger to see that after j = 117 you go into an infinite loop: Q(118) = 0.2798609 forever. > R2 hence goto 50 etcetera.
 
  • Like
Likes   Reactions: js6201
BvU said:
Hi,

Use the debugger to see that after j = 117 you go into an infinite loop: Q(118) = 0.2798609 forever. > R2 hence goto 50 etcetera.

Oh my god !
It is really thank you T.T I am a starter of fortran...So It is really difficult to me...to find out the error...
I am very appreciate to BvU and StreamKing ! Have a good weekend!
 
js6201 said:
Oh my god !
It is really thank you T.T I am a starter of fortran...So It is really difficult to me...to find out the error...
I am very appreciate to BvU and StreamKing ! Have a good weekend!
The handle is SteamKing, not StreamKing. You're welcome.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 11 ·
Replies
11
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 8 ·
Replies
8
Views
6K
  • · Replies 3 ·
Replies
3
Views
16K
Replies
15
Views
3K
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
10K
  • · Replies 1 ·
Replies
1
Views
3K