Simple Fortran Program Help: Calling Precision Function | Program Alpha

  • Fortran
  • Thread starter Thibaut
  • Start date
  • Tags
    Fortran
In summary, the conversation discusses a program written in Fortran that is not working and the use of a function called precision. The main issue is the lack of a real*8 declaration for the precision function in the main program, causing potential errors or incorrect output.
  • #1
Thibaut
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
 
Technology news on Phys.org
  • #2
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.
 

1. What is Fortran and why do I need help with it?

Fortran is a programming language commonly used in scientific and engineering applications. It is known for its efficient numerical calculations and is often used in high-performance computing. If you are struggling with Fortran, it could be due to its complex syntax and strict rules for array indexing and memory management.

2. How can I improve my Fortran skills?

One of the best ways to improve your Fortran skills is by practicing regularly and working on small projects. You can also refer to online tutorials, textbooks, and forums to learn new techniques and troubleshoot any issues you encounter.

3. Can I use Fortran for other types of programming?

While Fortran is mainly used for scientific and engineering applications, it can also be used for other types of programming, such as creating databases or web applications. However, it may not be the most optimal choice for these types of projects compared to other programming languages.

4. Is Fortran still relevant in today's programming landscape?

Yes, Fortran is still widely used in many industries, particularly in fields that require heavy numerical computations, such as weather forecasting, computational chemistry, and aerospace engineering. It has also evolved over the years, with the latest version, Fortran 2018, being released in 2018.

5. Are there any alternatives to Fortran?

Yes, there are many alternatives to Fortran, such as C, C++, and Python. These languages also have strong capabilities in scientific computing and may be more user-friendly for beginners. However, Fortran remains a popular choice for its efficiency and extensive libraries for numerical calculations.

Similar threads

  • Programming and Computer Science
Replies
4
Views
611
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
12
Views
961
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
2
Replies
37
Views
3K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top