Here is a quick tutorial on how to write and compile a simple Fortran program:
- Install a Fortran compiler: Before you can write and run Fortran code, you need to have a Fortran compiler installed on your machine. There are several options available, including GNU Fortran (gfortran) and Intel Fortran (ifort).
- Open a text editor: Fortran code can be written in any plain text editor, such as Notepad or Sublime Text.
- Write your Fortran code: Here’s an example of a simple Fortran program that prints “Hello, world!” to the console:javaCopy code
PROGRAM HelloWorld WRITE(*,*) 'Hello, world!' END PROGRAM HelloWorld
- Save your code: Save your Fortran code with a .f90 or .f95 file extension.
- Compile your program: Use your Fortran compiler to compile your program. If you’re using gfortran, you can use the following command:Copy code
gfortran -o HelloWorld HelloWorld.f90This will create an executable file called “HelloWorld” that you can run.
- Run your program: To run your program, simply enter the following command in your terminal:Copy code
./HelloWorldThis will execute your Fortran code and print “Hello, world!” to the console.
By completing this tutorial, you should now have a basic understanding of how to write and compile simple Fortran programs. From here, you can continue to explore and experiment with the many features and capabilities of this powerful programming language.
Add a Comment