简体   繁体   English

离散值的 Fortran 循环

[英]Fortran loop for discrete values

Is there any way to run a loop for discrete values of a variable?有没有办法为变量的离散值运行循环? What about in some latest version?在某些最新版本中呢?

Something like就像是

for i in 1  5 9 11  31 77 

used in Unix shell script?在 Unix shell 脚本中使用?

integer, dimension (5) :: indx = [5, 9, 11, 31, 71]

do i=1, size(indx)
   j=indx(i)
   ....
end do

You can also use an implied do loop to accomplish this, but you'll have to define the array of values as above:您还可以使用隐含的 do 循环来完成此操作,但您必须按上述方式定义值数组:

integer, dimension (5) :: indx = [5, 9, 11, 31, 71]
integer, dimension (5) :: rslt 
integer, external      :: func
rslt = (/ func(indx(j)), j=1,5 /)

I am not sure if this helps, but you can use arrays for indeces我不确定这是否有帮助,但是您可以将数组用于 indeces

program Console1

implicit none

! Variables
INTEGER :: X(4) = (/ 1, 3, 5, 7 /)
REAL :: Y(10) = 0.0

! Body of Console1
print *, X
!   1   3   5   7
Y(X) = 10.0/X
print *, Y
!   10.0    0.0    3.33   0.0    2.00   0.0    1.428    0.0 ...

end program Console1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM