I'm a student, and I had to do a freefall program. But I'm having some issues with variables. As soon as a subroutine ends, they go bananas! The problematic trio is 'y','v' and 'nshow'. When the subroutine Euler ends, 'v' gets the module of y, y go to zero and nshow to 32767!(adsbygoogle = window.adsbygoogle || []).push({});

How can I fix that?

_________________________________________

______________________________________________________Code (Text):PROGRAM free_fall

IMPLICIT NONE

DOUBLE PRECISION y,a,g,t,dt,v

INTEGER nshow, counter

t = 0.0d0

OPEN(UNIT=1, FILE="TEST.dat")

OPEN(UNIT=2, FILE="TESTEULER.dat")

CALL initial (y,v,a,g,t,dt)

WRITE (1,*) v,y,nshow

!^Here my variables change misteriously

counter=0

CALL Euler (y,v,a,t,dt,nshow,counter)

CALL print_table(y,v,a,dt,t,nshow)

END

SUBROUTINE initial(a,y,v,g,t,dt)

DOUBLE PRECISION y,a,g,t,dt,v

WRITE(*,*) 'time step ='

READ(*,*) dt

WRITE(*,*) 'height ='

READ(*,*) y

WRITE(*,*) 'initial velocity ='

READ(*,*) v

WRITE(*,*) 'number of times steps between output ='

READ(*,*) nshow

WRITE (1,*) v,y,nshow

!^Until this point, variables are OK

END

SUBROUTINE Euler(y,v,a,t,dt,nshow,counter)

DOUBLE PRECISION y,a,t,dt,v

INTEGER nshow,counter

OPEN(UNIT=4, FILE="vt.dat")

OPEN(UNIT=3, FILE="yt.dat")

a = -9.8

100 v = v+a*dt;

y = y+v*dt

t = t+dt

counter = counter + 1

IF (mod(counter,nshow) .EQ. 0.0D0) CALL print_table(y,v,a,dt,t,nshow)

WRITE (2,*) t,y,v,dt,a,counter,nshow

WRITE (*,*) t,y,v,dt,a

IF (y .LE. 0.0D0) go to 200

go to 100

200 STOP

END

SUBROUTINE print_table(y,v,a,dt,t)

DOUBLE PRECISION y,t,v

WRITE (4,*) t,v

WRITE (3,*) t,y

!Each table will be made in a file. TEST and TESTEULER are, obviously, tests

END

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Issues with changing variables

Loading...

Similar Threads - Issues changing variables | Date |
---|---|

Struggling with a strange on screen format issue | Jan 9, 2018 |

Changing Algorithms compatible with AI? | Oct 16, 2017 |

Matlab to r-pi to I2C device issue | Jan 13, 2017 |

Javascript Compatibilty issue | Dec 26, 2016 |

Arithmetic Issue in FORTRAN | Oct 28, 2015 |

**Physics Forums - The Fusion of Science and Community**