fortran - Do loop not working, request your solutions -
fortran - Do loop not working, request your solutions -
i think silly ask, but, loop isn't working seems. can take time re-check code ?
here's code:
program hexagonal implicit none integer::i,j,info integer::n1,n2 real::a,e0,ts,tsp,es,ep real, parameter :: pi = 3.1415927 real, allocatable :: kx(:,:) real, allocatable ::ky(:,:) real, allocatable :: epos(:,:) real, allocatable :: eneg(:,:) namelist /model_parameters/ a,e0,ts,tsp namelist /lattice_size/ n1,n2 open(unit=10, file='hexinput.txt',action="read", iostat=i) read(unit=10,nml=lattice_size,iostat=info) read(unit=10,nml=model_parameters,iostat=info) close(10) write(*,*) "n1=", n1, "n2=", n2, a, e0, ts, tsp
! allocate arrays
if (allocated(kx)) deallocate(kx) allocate(kx(n1,n2)) if (allocated(ky)) deallocate(ky) allocate(ky(n1,n2)) if (allocated(epos)) deallocate(epos) allocate(epos(n1,n2)) if (allocated(eneg)) deallocate(eneg) allocate(eneg(n1,n2)) !'es' , 'ep' orbital energies. can written in below form using 'e0' , 'ts'. es=-(e0-4.0*ts) ep=(e0-4.0*ts)
! loop doesn't work !
i=1,n1 j=1,n2 kx(i,j)=((i-1)/n1)*(2*pi/a)+((j-1)/n2)*(2*pi/a) end end i=1,n1 j=1,n2 ky(i,j)=((i-1)/n1)*(-2*pi/(sqrt(3.0)*a))+((j-1)/n2)*(2*pi/(sqrt(3.0)*a)) end end j=1,n2 i=1,n1 epos(i,j)=sqrt(-es*(ep+2*ts*(cos(kx(i,j))+cos(ky(i,j)))) & -(2*ts*(cos(kx(i,j))+cos(ky(i,j)))*(ep-2*ts*(cos(kx(i,j))+cos(ky(i,j))))) & +(4*tsp**2)*((sin(kx(i,j)))**2 +(sin(ky(i,j)))**2)) end end j=1,n2 i=1,n1 eneg(i,j)=-sqrt(-es*(ep+2*ts*(cos(kx(i,j))+cos(ky(i,j)))) & -(2*ts*(cos(kx(i,j))+cos(ky(i,j)))*(ep-2*ts*(cos(kx(i,j))+cos(ky(i,j))))) & +(4*tsp**2)*((sin(kx(i,j)))**2 +(sin(ky(i,j)))**2)) end end !creating info file named "data.dat" 3 columns containing 'kx', 'epos' , 'eneg' values.. open(unit=1, file='hex.dat') i=1,n1 j=1,n2 write(1,'(3f12.6)') kx(i,j),epos(i,j),eneg(i,j) end end close(unit=1) !now run file in gnu plot. end programme hexagonal
i not able generate 'hex.dat' file mentioned! also, pretty sure other files mentioned in code called perfectly.
ok, answer, utilize real numbers real result:
real::rn1,rn2 rn1 = real(n1) rn2 = real(n2) i=1,n1 j=1,n2 kx(i,j)=((i-1)/rn1)*(2*pi/a)+((j-1)/rn2)*(2*pi/a) end end i=1,n1 j=1,n2 ky(i,j)=((i-1)/rn1)*(-2*pi/(sqrt(3.0)*a))+((j-1)/rn2)*(2*pi/(sqrt(3.0)*a)) end end
and, writing hex.dat, 1 reserved unit standard output. utilize 11 instead:
open(unit=11, file='hex.dat') i=1,n1 j=1,n2 write(11,'(3f12.6)') kx(i,j),epos(i,j),eneg(i,j) end end close(unit=11)
fortran fortran90 fortran95
Comments
Post a Comment