在 CentOS 上学习 Fortran 编程,可以按下面几个阶段来走,从环境搭建到实际编程练习。
CentOS 默认可能没有 Fortran 编译器,先安装:
sudo yum install gcc-gfortran
安装完成后检查:
gfortran --version
看到版本信息说明安装成功。
推荐:
vim(终端)nano(简单)安装 vim:
sudo yum install vim
vim hello.f90
program hello
print *, "Hello, Fortran!"
end program hello
gfortran hello.f90 -o hello
./hello
输出:
Hello, Fortran!
program / end program)integer, real, character)read, print)示例:
program demo
integer :: a, b
a = 3
b = 4
print *, "a + b =", a + b
end program demo
ifdo 循环select casedo i = 1, 5
print *, i
end do
real :: x(10)
x = 0.0
x(1) = 1.0
subroutine add(a, b, c)
integer, intent(in) :: a, b
integer, intent(out) :: c
c = a + b
end subroutine add
.txt, .dat)openmpi)gfortran 调试(-g, gdb)如果你愿意,我可以:
你可以告诉我你的基础(零基础 / 有编程经验 / 科研用途)。