[Tutor] Do loop in Python

stm atoc stm.at.oc at googlemail.com
Fri Nov 25 10:16:20 CET 2011


Hi there,

I am a new python user.
I have  a question regarding  do loop.....

This is a simple program that I have written:

-----------------
N=10
h=10.0 # [micrometer]
z=-200.0 # [micrometer]
num = 0.05 #m**2/s
dz = 1.0
nuh=[]
tmax=3600
dt=20.
nu=[]height = arange(z*dz,0,dz)

outfile=open('nu.dat','w')
outfile.write('height, nu, nuh')

for z,when in enumerate(height):
   for h in range(10):
       for N in range(10):
           for z in range((N-z)+(N-h)):

               nuh.append(0.01 * exp(-0.05*(z+200.0))*dz) #turbulence
diffusivity m**2/s
               nu.append(num + nuh[z])

-----------------------
What I like to do with this program is do loop like the fortran
version of  as follows:

do i = 2, N
 z(i) = z(i-1) +h(i-1)

end do

write(0,*) 'z ', z(1:N)
write(0,*) 'when ', 'nu ','Conc '


do i= 1, N

  nuh(i)= 0.01d0*exp(-0.005d2*(z(i)+200)) ! turbulence diffusivity m**2/s
  nu(i)= num(1) + nuh(i)


end do

----------
My problem is I am notable have the curve in the output plot as I have
as a result of  FORTRAN program. What happens is just having a
straight line....!
the whole problem is in z part, which is supposed to be changed and i
do not see it!

 So, would it be possible to take a look at it please. any suggestion
would greatly appreciated.

Thank you,
Sue


More information about the Tutor mailing list