Errors during executing the program (Compaq Visual Fortran)

In summary, the conversation discusses the issue of generating random numbers using a log-normal distribution in Fortran. The source code is attached and there are no compile or link errors, but when trying to generate 300 random numbers, the calculation process stops after 117 steps. The conversation suggests using the debugger to identify the issue, which is found to be an infinite loop after j=117. The solution is to modify the code to prevent this loop and allow for the desired number of random numbers to be generated.
  • #1
js6201
7
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
  • #2
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 js6201
  • #3
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 becuase 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!
 
  • #4
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 js6201
  • #5
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!
 
  • #6
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.
 

What causes errors during executing the program in Compaq Visual Fortran?

There can be several reasons for errors during execution of a program in Compaq Visual Fortran. Some common causes include syntax errors in the code, incorrect data types or variable declarations, memory allocation issues, and compatibility issues with the compiler or operating system.

How can I troubleshoot errors in my Compaq Visual Fortran program?

To troubleshoot errors in a Compaq Visual Fortran program, it is important to carefully review the code for any syntax errors or incorrect data types. You can also use debugging tools provided by the compiler to step through the code and identify the source of the error. Additionally, checking for compatibility issues with the compiler or operating system may also help resolve the error.

What are some common types of errors in Compaq Visual Fortran?

Some common types of errors in Compaq Visual Fortran include syntax errors, logical errors, and runtime errors. Syntax errors occur when the code does not follow the correct syntax rules of the language. Logical errors occur when the code does not produce the expected results. Runtime errors occur during program execution and can be caused by issues such as memory allocation errors or invalid data types.

How can I prevent errors in my Compaq Visual Fortran program?

To prevent errors in a Compaq Visual Fortran program, it is important to carefully review and test the code before execution. Using proper coding practices, such as commenting and indentation, can also help prevent errors. Additionally, keeping the compiler and operating system up-to-date can prevent compatibility issues that may lead to errors.

Is there a way to handle errors during program execution in Compaq Visual Fortran?

Yes, Compaq Visual Fortran provides error handling mechanisms such as the "ON ERROR" statement, which allows you to specify actions to take when a runtime error occurs. You can also use the "TRY...CATCH" construct to catch and handle specific types of errors. Additionally, using proper error-checking and handling techniques in your code can help prevent errors from occurring in the first place.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
8
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
2K
  • Programming and Computer Science
Replies
4
Views
15K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
6
Views
4K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
9
Views
9K
Back
Top