1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Errors during executing the program (Compaq Visual Fortran)

  1. Feb 5, 2016 #1
    1. The problem statement, all variables and given/known data
    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 occured (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. Relevant 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.

    3. 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).
    Code (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








    DO WHILE (j .le. 150)







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







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

      50 u(j)=RAND1(j)



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




    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


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




    END IF

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


    End do

  2. jcsd
  3. Feb 5, 2016 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
  4. Feb 5, 2016 #3
    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!
  5. Feb 5, 2016 #4


    User Avatar
    Science Advisor
    Homework Helper
    2017 Award


    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.
  6. Feb 5, 2016 #5
    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!
  7. Feb 5, 2016 #6


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    The handle is SteamKing, not StreamKing. You're welcome.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted