在Ubuntu上编写Fortran脚本,你需要遵循以下步骤:
sudo apt update
sudo apt install gfortran
hello.f90
的文件:nano hello.f90
program hello
print *, "Hello, World!"
end program hello
保存并关闭文件:保存你的更改并关闭文本编辑器。
编译Fortran程序:在终端中,导航到包含你的Fortran源文件的目录,并使用gfortran编译器编译它。例如:
cd /path/to/your/fortran/files
gfortran -o hello hello.f90
这将生成一个名为hello
的可执行文件。
./hello
你应该看到输出 “Hello, World!”。
注意:上述步骤适用于Fortran 90/95。如果你使用的是其他Fortran版本(如Fortran 2003、2008等),语法可能略有不同。但是,大多数现代Fortran编译器都支持Fortran 90/95标准。