Error in Fortran

Asked

Viewed 68 times

-1

I have this programming in Python:

from time import sleep #importando biblioteca para usar a função sleep
G = 6.67408 * (10 ** -11)
M1 = 1.98*(10**30)
Xo = 15 * (10 ** 10)
Yo = 0
Voy = 2.97 * (10 ** 4)
Vox = 0

ax, ay, t = 1, 1, 0

for t in range(0, 31539150, 3150):
  sleep(0.200) # intervalo de 0.2 segundo para repetição do loop
  x = (ax*(t**2))/2 + Vox*t + Xo
  print("-" * 20)
  y = (ay*(t**2))/2 + Voy*t + Yo
  print("t = ", t)
  print("posição no eixo x = ", x)
  print("posição no eixo y = ", y)
  print("-" * 20)
  print("\n")
  posicaox = x
  posicaoy = y
  arquivo = open("arq01.txt", "a")
  arquivo.write(str(posicaox) + ", " + str(posicaoy) + "\n")
  arquivo.close()

and wanted to rewrite it in Fortran, but is in error. I do not know how to fix.

Follow what I did in Fortran:

program trajetoria
REAL :: X, Y, Ax, Ay, Vx, Vy, G, Msol

G = 6.67408*(10**-11)
M1 = 1.98*(10**30)
Voy = 2.97*(10**4)

X = (Ax*(t**2))/2 + 15**10 ! O termo Vox*t foi omitido pois dará sempre zero.
Y = (Ay*(t**2))/2 + Voy*t ! O termo Yo foi ocultado pois é zero.
Ax = (G*Msol*X)/((X**2 + Y**2)**3/2)
Ay = (G*Msol*Y)/((X**2 + Y**2)**3/2)
Vx = Vx + Ax*t
Vy = Vy + Ay*t

t = 0
DO
  t = t + 3150
  IF (t <= 31539150) CYCLE
  PRINT*, "Ax é", Ax
ENDDO

END

The errors that appear are as follows::

Compiling and linking file: traj.f95

C:\Users\Kratos\Documents\IC\traj.F95(4) : error 565 - '-' found where an operand was expected

C:\Users\Kratos\Documents\IC\traj.F95(5) : warning 1226 - A REAL constant has been truncated with possible loss of precision - maybe a KIND is required

C:\Users\Kratos\Documents\IC\traj.F95(5) : comment 368 - This assignment will result in a loss of precision, assigning from REAL(KIND=1) to INTEGER(KIND=3)

Compilation failed.

1 answer

1

FORTRAN only accepts unary operators alongside other arithmetic operations if they are within parentheses:

G = 6.67408*(10**-11)

should be

G = 6.67408 * (10 ** (-11))

This should solve the error you specified.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.