I need a little help in Fortran

  • Fortran
  • Thread starter Thibaut
  • Start date
  • #1
1
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
 

Answers and Replies

  • #2
AlephZero
Science Advisor
Homework Helper
6,994
291
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.
 

Related Threads on I need a little help in Fortran

Replies
2
Views
5K
  • Last Post
Replies
8
Views
3K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
3
Views
751
  • Last Post
Replies
7
Views
2K
Replies
1
Views
2K
  • Last Post
Replies
1
Views
2K
Replies
32
Views
30K
Top