#!/usr/bin/awk -f # entropy.awk - compute entropy from distribution function # # Input file is in format: # # 1:real_time 2:relat_time 3:x 4:F(x>0,t) 5:F(x<0,t) 6:v 7:F(v>0,t) 8:F(v<0,t) # # Developed by Lubomir Host 'rajo' # Copyright (c) 2003 Platon SDG # Licensed under terms of GNU General Public License. # All rights reserved. # # entropy = - Sum_i(f_i * ln(f_i)) # f_i - probability that the velocity of ion has a value between u_i and u_i + du # $Platon$ BEGIN { entropy = 0.0; sum = 0.0; time1 = 0.0; time2 = 0.0; f_max_v = 1.0; print "\n#\n# ENTROPY\n# Data format: 1:real_time 2:relat_time 3:entropy 4:sum\n" } # ignore! /^## Data format/ { next; } # reinitialize maximum speed --> speed step /^## PARAM: f_max_v/ { f_max_v = $5; printf "#@ value of f_max_v initialized to %g\n", f_max_v; } # print comments and continue /^#/ { print; next; } # ignore empty lines /^$/ { next; } # next time step time1 != $1 { printf "%g %g %g %g\n", time1, time2, entropy / f_max_v, sum; time1 = $1; time2 = $2; # clear entropy for next time step entropy = 0.0; sum = 0.0; } # prevent log(0) = -infty $7 != 0.0 { entropy -= $7 * log($7); sum += $7; } $8 != 0.0 { entropy -= $8 * log($8); sum += $8; } # vim: cindent