#!/usr/bin/perl # the above is the standard linux/unix path for perl: change if your computer is nonstandard sub print_help{ print STDERR <0 or die "Invalid threshold $thresh\n"; next; } if($p eq "-h"){ # help print_help; die "\n"; } print_help; die "invalid option $p\n"; } if($#inputfiles<0){ push(@inputfiles,"-"); # adds stdio for lack of arguments } $#inputfiles<2 or die "Can process either 1 file only!\n"; $filename=$inputfiles[0]; $count=0; $totp=0; $frames=0; $nold=-99999; $threshq=$thresh*$thresh; open(INPUT, $filename) || die "Cannot open $filename\n"; while(){ s/^\s*//; # remove leading spaces @li = split('\s+'); if($#li==0 && $li[0]+0==$li[0] && $count!=1){ $n=$li[0]+0; if($n==$nold){ print; }elsif($nold!=-99999){ print STDERR "ERROR xyz_displacement: file $filename has frames with different numbers of particles: $n, $nold\n"; } $frames++; $count=0; }elsif($count==1){ $t=1. *$li[1]; if($t==$li[1]){ $tnow=$t; if($n==$nold){ if($thresh>0){ print "#intermediate_time= ",0.5*($tnow+$told),"\n"; }else{ print "#deltat= ",$tnow-$told,"\n"; } } }else{ if($n==$nold){print;} } $told=$tnow; }else{ if($n==$nold){ $dx=$li[1]-$oldx[$count]; $dy=$li[2]-$oldy[$count]; $dz=$li[3]-$oldz[$count]; if($thresh>0){ $delta=$dx*$dx+$dy*$dy+$dz*$dz; if($delta>$threshq){ print "Rb $li[1] $li[2] $li[3]\n"; }else{ print; } }else{ print "$li[0] $dx $dy $dz\n"; } } $oldx[$count]=$li[1]; $oldy[$count]=$li[2]; $oldz[$count]=$li[3]; if($count==$n+1){ $nold=$n; } } $count++; } close(INPUT);