1
Hello, I’m writing a program in Python with a code I have in Fortran. I have a problem writing this excerpt (from Fortran):
do i=1,n
write(3,350)r(i),(ener(j)*alfa,j=1,6) !meV
end do
I tried to write this way in Python:
file=open("energia_nll2_R50A.dat","w")
for i in range(1,n+1):
for j in range(1,6):
file.write("r[i],(ener[j]*alfa)")
file.close()
I was wondering if there’s another equivalent way to write this excerpt in Python.
Complete code:
alfa = 3014.4
r = []
for i in range(1,n1+1):
x = r1 + (i - 1)*hr1
r.append(x)
ener = []
for i in range(1,n):
for j in range(i+1,n+1):
if ener[i]>ener[j]:
az = ener[j]
ener[j] = ener[i]
ener[i] = az
for k in range(1,n+1):
zz3 = vetor[k,j]
vetor[k,j] = vetor[k,i]
vetor[k,i] = zz3
file=open("energia_nll2_R50A.dat","w")
for i in range(1,n+1):
for j in range(1,6):
file.write("r[i],(ener[j]*alfa)")
file.close()
Do you want i and j values to appear in the archive? What are
r
,ener
,alfa
andn
?– Woss
i and j here refer to the number of vectors to appear in the file.
– oklucas
alpha is a number, n is the precision and r and ener are the vectors
– oklucas
I also wanted to know if you are right this way of referencing vectors within write... because I found nothing about.
– oklucas
And are they set in Python? Please enter the full code.
– Woss
Ready, I edited the post.
– oklucas
Okay, I review my words. Your code made no sense, so explain in words what you intend to do. Describe what your input is, what calculations you want to make, and what the expected output is.
– Woss
Just a question, are you making a header here? file.write("r[i],(ener[j]*alpha)") ? Or is trying to write the values of r[i] and ener[j]*alpha in the file ?
– FourZeroFive
I am trying to write them in the archive. For the 6 energy levels (that is this "ener"). It is the variation of the radius "r" to the 6 energy levels "ener". In the Fortran file I opened in Qtiplot, there were 6 energy levels, one in each column - repeating the same number for a given level, n times, in the lines. I need it to plot the energy graph.
– oklucas