Simple Fortran Program Help: Calling Precision Function | Program Alpha

  • Context: Fortran 
  • Thread starter Thread starter Thibaut
  • Start date Start date
  • Tags Tags
    Fortran
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
Thibaut
Messages
1
Reaction score
0
Hello,
I'm writing a really simple program in fortran which is a part of a bigger program.
It is not working at the moment, but I really don't know why.

I am calling a function called precision, but the program does not enter it ( I know it since I use write statements inside).
I compared this to other functions on websites, but it really seems to be the same, and so I don't know what to do. ( The 6 spaces are missing in this post, but I put them before the statements)
I need a little help.

Thank you.

My program:

program alpha

real*8 b

b=1.
write(*,*) b
write(*,*) precision(b)

end

c**********


real*8 function precision(a)
real*8 c, a

write(*,*) a

c = 2.E-13

do while (a .LT. 100)
a=a*10.
c= c/10.
write(*,*) a, c
end do

precision = c

RETURN
END
 
Physics news on Phys.org
In your main program (alpha) you need to add

real*8 precision

Otherwise, the compiler thinks "precision" will return a real*4 variable (since its name starts with the letter p).

Without the real*8 declaration, the program might crash before it produced any output, or it might appear to run but give the wrong answers - but it certainly won't work correctly.