From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Thu May 10 2012 - 22:06:41 CDT

On Thu, May 10, 2012 at 10:17 PM, Bennion, Brian <Bennion1_at_llnl.gov> wrote:
> Hello
>
> expr statements should use curly braces.
>
> set sum [expr {$sum+$campo}]

well, they don't *have* to. using curly braces
doesn't change code like this, it just makes
it execute faster, since it saves one round of
variable expansion.

axel.

> Brian
>
>
> ________________________________________
> From: owner-vmd-l_at_ks.uiuc.edu [owner-vmd-l_at_ks.uiuc.edu] On Behalf Of Andrés Morales [h.andres.m1986_at_gmail.com]
> Sent: Thursday, May 10, 2012 4:40 PM
> To: vmd-l_at_ks.uiuc.edu
> Subject: vmd-l: Loop for
>
> Dear VMD users
>
> I am trying to calculate an specific amount (electric potential) from data extracted from a text file. The script works fine to calculate this value for an specific point (specific values of x, y, z variables), but when I tried to run it for a range of values it doesn't work. I used the following script:
>
> ###################################
> set file2 [open total.txt r]
> set output2 [open campo.txt w];
> puts $output2 "y z potencial"
> set sum 0
> for {set i -35 } {$i <= 35 } { incr i 5 } {
> for {set j -30 } {$j <= 55 } { incr j 5 } {
> set x1 0
> set y1 [expr $i]
> set z1 [expr $j]
> while { [gets $file2 line2] != -1 } {
> set dist [expr pow(([lindex $line2 1]-$x1)*([lindex $line2 1]-$x1) + ([lindex $line2 2]-$y1)*([lindex $line2 2]-$y1) + ([lindex $line2 3]-$z1)*([lindex $line2 3]-$z1),0.5)]
> set campo [expr [lindex $line2 0] / abs($dist)]
> set sum [expr $sum + $campo]
>  }
> puts $output2 "$i $j $sum"
> }}
> close $output2
> #######################################
>
> I got an output like this:
>
> y z potencial
> -35 -30 0.01074960712757333
> -35 -25 0.01074960712757333
> -35 -20 0.01074960712757333
> -35 -15 0.01074960712757333
> -35 -10 0.01074960712757333
> -35 -5 0.01074960712757333
> -35 0 0.01074960712757333
> -35 5 0.01074960712757333
> -35 10 0.01074960712757333
> ....
>
> Does anybody know what is wrong and how I can solve it???
>
>
> Thanks a lot
>
> Andres
>
>
>
>

-- 
Dr. Axel Kohlmeyer
akohlmey_at_gmail.com  http://goo.gl/1wk0
College of Science and Technology
Temple University, Philadelphia PA, USA.