Reputation: 255
im trying to go through a little algorithm in fortran (im not a fortran programmer unfortunately) but i need to understand what its doing: here it is,
omega = 0.d0
s = 1.d0
i = 1
j = 2
k = 3
101 do iperm = 1, 3
omega = omega + s * a1 (i) * a2 (j) * a3 (k)
l = i
i = j
j = k
k = l
enddo
i = 2
j = 1
k = 3
s = - s
if (s.lt.0.d0) goto 101
omega = abs (omega) * alat**3
a1,a2,a3
are vectors (three elements each, real values, representing vectors in 3d space)
s
is a unit integer (can be 1 or -1 alternately) and i,j,k
are integers while omega
(which is what i need to understand how its arrived at) is a floating point value, so is alat
.
Now what is going on up there?
especially the iperm =1,3
part, is that a vector being created? at first i thought iperm might be some fancy function/routine or iterator, but after some search i think thats not the case, whats the purpose of the iperm?
is there some looping over iperm
between "do
" and "enddo
" ?
Upvotes: 0
Views: 279
Reputation: 78316
All you've got is a sequence of assignments with a loop thrown in for fun. I guess you understand that statement such as
lhs = rhs
evaluates rhs
and assigns the result to the variable lhs
.
The line
101 do iperm = 1, 3
starts a do
loop. The 101
is a statement label, it's used later. The loop comprises all the statements from that line to the line enddo
. The loop will be executed 3 times (once for each of the integers in the sequence starting at 1
and ending at 3
). The loop control variable iperm
is assigned these values in turn. The loop is a little unusual in that the loop variable is not used inside the loop. The statement
omega = omega + s * a1 (i) * a2 (j) * a3 (k)
updates the value of omega
. The term a1(i)
(the space in your original is immaterial) means the i-th element of array a1
. et cetera
When the line
if (s.lt.0.d0) goto 101
is executed if s
is less than 0
control goes bak to the line labelled 101
.
Finally, the term alat**3
calculates the cube of alat
.
So now get a piece of paper and figure out what value omega
gets.
Upvotes: 3