fortran以特定格式逐帧平均列

时间:2018-05-01 05:58:32

标签: fortran computational-geometry gfortran fortran90 chemistry

我想平均显示here的第一列和最后一列(这是我的输出)。我的代码做了几件事,例如比较特定原子和每个帧的名称“CA”(我有1000帧),排除最近的邻居并根据截止值,并根据我的愿望计算这些联系人并单独打印它们(输入文件看起来像this)。我想打印一个文件,它给我输出类似下面的输出:

1 0

2 12

3 12

...

100 16

需要通过帮助我形成循环或条件来实现这一目标。

  open(unit=11,file="0-1000.gro", status="old", action="read")      
  do f=1,frames,10               
  25 format (F10.5,F10.5,F10.5)      

  do h=1,natoms_frames
  read(11,format11)nom(h),resname(h),atmtype(h),num(h),x(h),y(h),z(h)
  end do
  read(11,25)lasta(f),lastb(f),lastc(f) 

  count=0    
  do h=1, natoms_frames        
  if (atmtype(h).eq.'  CA') then
      count=count+1
      CAx(count)=x(h) 
      CAy(count)=y(h)
      CAz(count)=z(h)    
  end if
  end do      

  do h=1, count
  avg_cal=0 
    cal=0 
    do hh=h+3, count
    if (h.ne.hh) then
  ! finding distance formula from the gro file  
  distance = sqrt((CAx(hh)-CAx(h))**2 + (CAy(hh)-CAy(h))**2 + (CAz(hh)-CAz(h))**2)
  if (distance.le.cutoff) then
  cal = cal+1
  set = set+1
  final_set=final_set+1
  avg_cal=avg_cal+1
  end if
  end if
  end do
   write(*,*)h,cal,final_set 
  end do

  end do ! end of frames

  close(11)

  end program num_contacts     

1 个答案:

答案 0 :(得分:0)

在文件中写入(ASCII格式)与在屏幕上打印相同,只是您需要指定文件的单位。

首先,打开你的文件:

open(unit = 10, file = "filename.dat", access = "sequential", form = "formatted", status = "new", iostat = ierr)

其中'unit'是一个唯一的整数,它将与您的文件相关联(作为ID)。请注意,'form'是'格式化',因为您想要输出人类可读的内容。然后你可以开始你的循环:

do h = 1, natoms_frames
  ! BUNCH OF STUFF TO CALCULATE REQUIRED VARIABLES
  write(10, *) h, cal, final_set
end do

最后,关闭你的文件:

close(10)