fortran - Error declaring types with kind parameter -
with following program experience errors.
program com !input !no of atoms !no of iterations !respective positions. !as of homogeneous clusters. implicit none real, parameter :: r8b=selected_real_kind(10) real, parameter :: r4b=selected_real_kind(4) integer, parameter :: i1b=selected_int_kind(2) integer, parameter :: i2b=selected_int_kind(4) integer, parameter :: i4b=selected_int_kind(9) integer, parameter :: i8b=selected_int_kind(18) real (r8b), dimension (:,:), allocatable :: posx, posy, posz real (r8b), dimension (:), allocatable :: posx_n, posy_n, posz_n real (r8b), dimension (:), allocatable :: dist_com, avj_dist_com integer (i4b), dimension (:), allocatable :: bin_array real (r8b) :: comx, comy, comz integer (i8b) :: niter, natom, dist integer (i8b) :: i,j,ii,k integer (i1b) :: xyz_format, flagr, flagm, flag_com integer (i8b) :: bin integer (r8b) :: max_dist character (50) pos_file, com_file,bin_file character (2) jj read (*,*) pos_file read (*,*) com_file read (*,*) bin_file read (*,*) natom read (*,*) niter read (*,*) xyz_format read (*,*) max_dist, bin ! if flag_com == 1 compute dist com ! if 0 specify atom no , g(r) computed.. ! i.e. no of atoms atom between dist r , r + dr allocate (posx(natom,niter)) allocate (posy(natom,niter)) allocate (posz(natom,niter)) ! xyz_format = 0 ==> old_ks ! xyz_format = 1 ==> xmakemol ! xyz_format = 2 ==> envision write(*,*)pos_file open (unit=99, file=pos_file) if (xyz_format == 0 ) = 1,niter read(99,*) j = 1,natom read(99,*)ii,posx(j,i),posy(j,i),posz(j,i),ii enddo enddo elseif (xyz_format == 1 ) = 1,niter read(99,*)ii read(99,*) j = 1,natom read(99,*)jj,posx(j,i),posy(j,i),posz(j,i) enddo enddo elseif (xyz_format == 2 ) read(99,*) read(99,*) read(99,*) read(99,*) = 1,niter j = 1,natom read(99,*) read(99,*)posx(j,i),posy(j,i),posz(j,i) enddo enddo endif close (99) write (*,'(\1x,"reading complete")') allocate (avj_dist_com (niter)) allocate (dist_com (natom)) avj_dist_com = 0.0d0 dist_com = 0.0d0 allocate (posx_n(natom)) allocate (posy_n(natom)) allocate (posz_n(natom)) allocate (bin_array(bin)) posx_n = 0.0d0 posy_n = 0.0d0 posz_n = 0.0d0 bin_array = 0.0d0 open (unit=2, file=com_file) = 1, niter comx = 0.0d0 comy = 0.0d0 comz = 0.0d0 j = 1, natom comx = comx + posx(j,i) comy = comy + posy(j,i) comz = comz + posz(j,i) enddo comx = comx/natom comy = comy/natom comz = comz/natom write (*,*) i, comx, comy, comz j = 1, natom posx_n (j) = posx(j,i) - comx posy_n (j) = posy(j,i) - comy posz_n (j) = posz(j,i) - comz dist_com (j) = dsqrt ( posx_n(j)*posx_n(j) & + posy_n(j)*posy_n(j) & + posz_n(j)*posz_n(j) ) avj_dist_com (i) = avj_dist_com(i) + dist_com(j) enddo avj_dist_com(i) = avj_dist_com(i)/natom j = 1, natom dist = dist_com (j) * dfloat((bin/max_dist)) bin_array(dist) = bin_array(dist) + 1 enddo write (2,'(2x,i6,143(2x,f10.7))') i, avj_dist_com(i),(dist_com(k),k=1,natom) write(*,*) enddo close (2) open (unit=3, file=bin_file) = 1, bin write (3,'(2x,i6,4x,i8)') , bin_array(i) enddo close (3) deallocate (posx) deallocate (posy) deallocate (posz) deallocate (posx_n) deallocate (posy_n) deallocate (posz_n) deallocate (avj_dist_com) deallocate (dist_com) deallocate (bin_array) stop end program com
the errors like
real(kind=r8b), dimension (:), allocatable :: posx, posy, posz 1 error: integer expression required @ (1)
and there many more
how can rectify these?
the kind parameter type must integer constant expression. have latter part down, using named constants r8b
, r4b
.
however, , error message says, have not used integer constant expression. should notice selected_real_kind
returns integer value kind selected real type. so, can correct code with
integer, parameter :: r8b=selected_real_kind(10) integer, parameter :: r4b=selected_real_kind(4)
Comments
Post a Comment