如何避免重複聲明子程序中具有常量值的變量?如何避免在每個子例程中聲明和設置變量的值?
例如:
program test
implicit none
integer :: n
integer :: time
print*, "enter n" ! this will be a constant value for the whole program
call Calcul(time)
print*, time
end program
subroutine Calcul(Time)
implicit none
integer :: time
! i don't want to declare the constant n again and again because some times the subroutines have a lot of variables.
time = n*2
end subroutine
有時候也有很多是由用戶定義的,我會賺很多使用這些常量子程序的常數,所以我想炒股他們,並利用它們而不是一次又一次地重新定義它們。
你必須使用模塊。另外,不要將'n'稱爲常量。這是一個變量。你正在'read'語句中改變它。 –
請參閱http://stackoverflow.com/questions/42024559/using-global-variables-in-fortran和http://stackoverflow.com/questions/19040118/how-to-avoid-global-variables-in-fortran- 90或更高http://stackoverflow.com/questions/1240510/how-do-you-use-fortran-90-module-data和其他人(可能重複。 –