REPORTER 22.1

C Shell Program/Script

C Shell program/script

Bash (Unix Shell)
#!/bin/csh -f
#
# Script to extract the 5 smallest timesteps from otf file
#
# Arguments: 1: otf filename

# Test to see if there is an argument
if ($#argv < 1) then
echo "No otf filename";
exit;
endif
# test to see if the otf file exists
if ( !(-e $argv[1]) ) then
echo "otf file $argv[1] does not exist";
exit;
endif
# Use awk to extract the timesteps
awk '/smallest timesteps/ { # search for smallest timestep \
n = $1; # save how many found \
getline; # skip a line \
getline; # skip a line \
if (n > 5) n = 5; # limit to 5 timesteps \
t = 1.0e+20; # initialise smallest timestep \
for (i=0; i<n; i++) # loop over lines \
{ # \
getline; # read the line \
print $0; # print it \
if ($NF < t) t = $NF; # save timestep if smaller \
} # than current smallest \
} # \
END { # \
printf ("VAR TIMESTEP VALUE=\"%e\"\n", t); # Print smallest timestep \
} # \
' $argv[1]