如果变量满足两个值中的一个,我试图触发一个条件.我知道我可以表达为:
if x == 5 || x == 6
execute code...
end
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有一些更优雅的东西,如果x有一个长名称.就像是:
if x == {5, 6}
execute code...
end
Run Code Online (Sandbox Code Playgroud)
有人有主意吗?
我正在尝试运行一个需要特别长时间的代码。为了完成它,我将时间步循环分开,以便可以转储数据,然后为下一个循环重新读取:
do 10 n1 = 1, 10
OPEN(unit=11,file='Temperature', status='replace')
if (n1.eq.1) then
(set initial conditions)
elseif (n1.gt.1) then
READ(11,*) (reads the T values from 11)
endif
do 20 n = 1, 10000
(all the calculations for new T values)
WRITE(11,*) (overwrites the T values in 11 - the file isn't empty to begin with)
20 continue
10 continue
Run Code Online (Sandbox Code Playgroud)
我的问题是,这仅适用于 2 次 n1 时间步 - 在它替换文件 11 一次后,它不再替换并只是重申其中的值。
open语句有问题吗?有没有办法可以在同一代码中多次替换文件 11?