Fortran Simple Fortran Program Help: Calling Precision Function | Program Alpha

  • Thread starter Thread starter Thibaut
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion revolves around troubleshooting a Fortran program that fails to call a function named "precision." The user reports that the program does not enter the function, despite using write statements for debugging. A key point raised is the need to declare the function's return type in the main program. Specifically, adding "real*8 precision" ensures the compiler recognizes the function as returning a real*8 variable instead of defaulting to real*4. This declaration is crucial for preventing potential crashes or incorrect outputs, as the program will not function correctly without it.
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
 
Technology 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
4
Views
2K
Replies
12
Views
1K
Replies
4
Views
2K
Replies
8
Views
2K
Replies
8
Views
4K
Replies
8
Views
4K
Replies
4
Views
2K
Back
Top