Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get started with gfortran on a Mac?

Tags:

macos

fortran

Just finished installing the compiler gfortran 6.1. El Capitan. Next, I want to know how to run a file. So, I have a few questions:

  1. Which extension should I use to save the file? Is it .f90 or something else?
  2. What kind of software can be used to edit and save the source code?
  3. Once I save the file, how do I compile it? Is is gfortran followed by the file name (with path) in the Terminal? Also, how does the path look like on a Mac?

A step by step guide would be a great help. I am a first time Mac user. :)

like image 731
odnerpmocon Avatar asked Jun 06 '16 19:06

odnerpmocon


People also ask

How do I use Fortran on Mac?

On every Mac computer, there is a application called terminal that allows you to communicate with the computer and get stuff done. Terminal will then ask a password, enter it and allow the program to install on your computer. This is your compiler; it's called gfortran!

Can you code in Fortran on a Mac?

The OS X Fortran compiler supports a full range of project targets including command-line programs and GUI based applications. It provides a complete 64-bit macOS/OS X Fortran compiler solution and supports mixed language development by interfacing with Apple's Xcode C/C++ compiler.

How do I set up Fortran?

5. To create a new fortran program click on file>New>File>Select Fortran Source>Hit Go and follow the instructions in the dialog box. 6. To open an existing fortran source file select File>Open> and navigate to the fortran source file.


1 Answers

  1. .f90 for free formatted sources is commonly used
  2. Any texteditor you are comfortable with and used to, vim for example
  3. gfortran /your/source/file that would be with an absolute path. If you are in the directory of the source file already you do not need to specify the complete path.

Step by step "hello world":

  • Create a text file with your Fortran program
  • Just to give a command line example without the need for an editor (this is not what you typically would do):

    • Open the terminal, then enter

      cat >hello.f90 <<EOF
      program hello
        implicit none
        write(*,*) 'hello world'
      end program hello
      EOF
      
  • Compile your program in the terminal with: gfortran hello.f90

  • Execute it in the terminal with ./a.out
  • If you want another name use the -o option:

    gfortran -o hello hello.f90
    ./hello
    
like image 146
haraldkl Avatar answered Oct 03 '22 01:10

haraldkl