0

I was trying to create an array using two 'do' loops. But, some how, the way I made the array shows an error as mentioned in the title. Please be kind enough to point out the bug. I am new to Fortran.

Here's the code:

program energy
integer::Nx=100,Ny=10
real::kx(101),Epos(101),Eneg(101),E0=0.12,ts=0.2,tsp=2.0,ky(11),Es,Ep
Es=-(E0-4.0*ts)
Ep=(Eo-4.0*ts)
kx(1)=-0.50
do i=1,Nx
  kx(i+1)=kx(1)+i*(1.00/Nx)
end do

ky(1)=-0.50
do j=1,Ny
  ky(j+1)=ky(1)+j*(1.00/Ny)
end do

do j=1,11
  do i=1,101

"The error points the line below as its source."

    Epos(i,j)=sqrt(-Es*(Ep+2*ts*(cos(kx(i))+cos(ky(j)))) &
                  -(2*ts*(cos(kx(i))+cos(ky(j)))*(Ep-2*ts*(cos(kx(i))+cos(ky(j))))) &
                +(4*tsp**2)*((sin(kx(i)))**2 +(sin(ky(j)))**2))
  end do
end do

open(unit=1, file='data.dat')
do i=1,101
  write(1,*) kx(i), Epos(i,1)
end do

close(unit=1)
end program energy

Also, how do I plot Epos(i,j) Versus Kx(i) while keeping j or 'ky' as a parameter ?

1
  • I appreciate your suggestion, let me do the editing. Thank you. Commented Oct 12, 2014 at 19:01

1 Answer 1

1

For the rank mismatch part of your question: Epos is declared as a one-dimensional array by

real::Epos(101)

What you need is a two-dimensional array! From your code I assume it should look like

real::Epos(101,11)

For the plotting part, I would suggest writing the result to an ASCII file (if the amount of data is not too large), and then using an external tool like GNUPLOT, Python, or Octave/Matlab for plotting the data.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Alexander for the timely help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.