Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 计算Fortran循环中的行数_Loops_Fortran - Fatal编程技术网

Loops 计算Fortran循环中的行数

Loops 计算Fortran循环中的行数,loops,fortran,Loops,Fortran,我有一个从0到15000行的时间序列数据和一些列。我希望以60秒的间隔分离数据,并计算每个间隔内的数据量 我创建了一个do循环,它正确地创建了从开始到文件结尾的60秒间隔,但是,我不知道如何计算每个间隔内的行数 我要寻找的最终结果是有两列作为结果: 间隔数和行数 以下是我到目前为止得到的信息: program flash_selection implicit none integer i, zero, qtd, cellnumb, flashcell, tipo, segmen

我有一个从0到15000行的时间序列数据和一些列。我希望以60秒的间隔分离数据,并计算每个间隔内的数据量

我创建了一个do循环,它正确地创建了从开始到文件结尾的60秒间隔,但是,我不知道如何计算每个间隔内的行数

我要寻找的最终结果是有两列作为结果: 间隔数和行数

以下是我到目前为止得到的信息:

program flash_selection

implicit none       

integer i, zero, qtd, cellnumb, flashcell, tipo, segment

real time, Etrig, xtrig, ytrig, ztrig, poscharge, negq, chargeneutr

open(1,file='my_file.txt',status='OLD') 

read(1,*)                                           

do 

read(1,*,end=100) qtd, time, cellnumb, flashcell, tipo, segment, Etrig, xtrig, ytrig, ztrig, poscharge, negq, chargeneutr

do i = 1, 420

open(2,file='test.txt')

if (time .GE. (i-1)*60 .AND. time .LT. i*60) then

write(2,*) qtd, time, tipo, segment, Etrig, xtrig, ytrig, ztrig, poscharge, negq, chargeneutr

end if

end do 
end do

IF语句根据我的要求正确地分隔了数据,剩下的唯一一件事就是知道每60个间隔上有多少行。

只需添加一个
计数器
变量即可。每次通过循环时递增
计数器
。如果IF测试成功,请打印出
计数器
,然后将其设置回零


(顺便说一句,您不确定是否希望循环中包含
OPEN
语句。您应该使用大于10的文件号。)

关于单元号,根据编译器的不同,它可能支持自动单元分配,请参阅感谢Jack和Craig的回复。我通过在第一个循环之外执行循环(第一次执行时I=1420)和在IF语句之后执行addin a=a+1来实现它,这就是您提到的计数器。