我一直在疯狂地试图在我的简单程序中将一些数据读入数组。我无法弄清楚为什么会出现分段错误。我的代码开始:
program guess_input
implicit none
CHARACTER*2, allocatable, dimension(:) :: element
double precision, allocatable, dimension(:,:) :: xyzq
INTEGER, allocatable, dimension(:) :: label,cs_num, br_num, xx_num
real, allocatable, dimension(:) :: distance
real, allocatable, dimension(:) :: ep
INTEGER :: stat, numatom, i, j
CHARACTER*80 :: line
numatom = 61502
allocate(element(numatom))
allocate(xyzq(4,numatom))
allocate(label(numatom))
OPEN(UNIT=22,FILE='EMBQ_EPF.OUT',iostat=stat)
If(stat.ne.0) Stop "File not found"
!Read in the input into two arrays
do i=1,numatom
READ(22,'(A)') line
READ(line, *) xyzq(1,i), xyzq(2,i), xyzq(3,i), xyzq(4,i), label(i)
enddo
CLOSE(22)
!Define element type in parallel array based on the charge
do i=1,numatom
if(xyzq(4,i) == 1.00) then
element(i) = 'Cs'
elseif(xyzq(4,i) == -1.00) then
element(i) = 'Br'
else
element(i) = 'XX'
endif
enddo
OPEN(33, FILE='element.out')
do i=1,numatom
write(33,*) element(i)
enddo
end program guess_input
我已经尝试隔离故障,但我真的无法弄清楚出了什么问题。
任何帮助将不胜感激,谢谢。