大家好,初学编程,可是程序调试时出现segmentation fault,请大家帮忙看看,我的程序有什么问题,多谢了。
 sum = 0
 
 open(nin,file='TRAJ1',status='old',form &
                ='unformatted')
      open(nout,file='cswb.out',form='formatted')
      open(21,file='check')
        call readmdinit (mdtype,nin) 
      loop1:  do istep=1, nstep   
               call readmd  &
                   (mdtype,nattot,nin,atomname,xxx,yyy,zzz,&
                   cell,resname,resindex)
               open(npdb,file='newsystem.pdb',status='old')
               call readpdb (atomname,npdb,nattot,resname,resindex)
               close(npdb)     
! loop over all waters
               num=0       

            loop2:   do i=1, nattot
                  if ((atomname(i).eq.' O  ').and.(resname(i).eq.'WAT')) then
                     io = i
                  loop3:   do j=1,2
                        ih=io+j
                      loop4:  do iat=1,nattot
             if (((resname(iat).eq.'DC5'.or.resname(iat).eq.DC))&
                                then 
                              call findhbond &
                                   (io,ih,iat,xxx,yyy,zzz,nattot,cell,ihbnum)
                              if (ihbnum=1) then
                              acc(j)=iat
                              else exit loop3
                              endif
                            endif 
                        enddo loop4
                     enddo loop3
                     if (acc(1)*acc(2)/=0) then
                        if (resindex(ia1).ne.resindex(ia2)+1 &
                         .or. resindex(ia1).ne. resindex(ia2)-1) then
                            nhb=nhb+1 
                            acc1(nhb)=ia1
                            acc2(nhb)=ia2 
                        endif 
                     endif
                endif
          enddo loop2 
          sum=sum+nhb
        enddo loop1
        avgnhb=sum/nstep
        write (nout,*) ihbnum1


          close(nout)
          end