在Ubuntu下编写Fortran脚本,你需要遵循以下步骤:
sudo apt update
sudo apt install gfortran
hello.f90
的文件:nano hello.f90
program hello
implicit none
print *, 'Hello, World!'
end program hello
保存并关闭文件。
编译Fortran代码:在终端中,导航到包含Fortran源文件的目录,并使用gfortran编译器编译它。例如:
cd /path/to/your/fortran/file
gfortran -o hello hello.f90
这将生成一个名为hello
的可执行文件。
./hello
你应该看到输出 “Hello, World!”。
注意:上述示例使用的是Fortran 90标准。如果你的代码需要遵循其他Fortran标准(如Fortran 77或Fortran 2003),请在编译命令中指定相应的标准,例如:
gfortran -std=gnu95 -o hello hello.f90
这将使用GNU Fortran 95标准编译代码。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:CentOS下Fortran代码如何编写