[Tutor] Do loop in Python
Charles Becker
charleshbecker at gmail.com
Fri Nov 25 10:41:09 CET 2011
Sue,
I'm not familiar with FORTRAN, and since I'm not completely sure what you're trying to accomplish please take this simply as an 'educated guess'.
My guess is that you're not getting the curve because Z is only defined to one decimal location (1/10th) precision and probably needs higher precision (and is likely getting it) in the FORTRAN version.
http://docs.python.org/tutorial/floatingpoint.html this should help
Charles
Sent from my iPhone
On Nov 25, 2011, at 2:16 AM, stm atoc <stm.at.oc at googlemail.com> wrote:
> 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
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list