简体   繁体   English

如何在 Mac 上开始使用 gfortran?

[英]How to get started with gfortran on a Mac?

Just finished installing the compiler gfortran 6.1.刚刚安装编译器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?是 .f90 还是别的什么?
  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?终端中是 gfortran 后跟文件名(带路径)吗? Also, how does the path look like on a Mac?另外,路径在 Mac 上是什么样子的?

A step by step guide would be a great help.一步一步的指南将是一个很大的帮助。 I am a first time Mac user.我是第一次使用 Mac 用户。 :) :)

  1. .f90 for free formatted sources is commonly used 通常使用.f90对于自由格式化的源
  2. Any texteditor you are comfortable with and used to, vim for example 任何你习惯和习惯的texteditor,例如vim
  3. gfortran /your/source/file that would be with an absolute path. gfortran /your/source/file将使用绝对路径。 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 使用Fortran程序创建文本文件
  • 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 使用以下gfortran hello.f90在终端中编译您的程序: gfortran hello.f90

  • Execute it in the terminal with ./a.out 使用./a.out在终端中执行它
  • If you want another name use the -o option: 如果您想要其他名称,请使用-o选项:

     gfortran -o hello hello.f90 ./hello 

on windows to see result of fortran code in cmd在 Windows 上查看 cmd 中 fortran 代码的结果

myapp.f90 to see its result: myapp.f90 查看结果:

gfortran myapp.f90 -o myapp.exe !this line make myapp.exe by myapp.f90 gfortran myapp.f90 -o myapp.exe !这一行通过 myapp.f90 生成 myapp.exe
myapp "" OUTPUT.DAT !this line execute myapp.exe myapp "" OUTPUT.DAT !这一行执行 myapp.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM