<commit_before>#! /bin/bash
#
# Copyright 2009-2011 The VOTCA Development Team (http://www.votca.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if [ "$1" = "--help" ]; then
cat <<EOF
${0##*/}, version %version%
postadd average script for relative entropy, 
calcs averages of (\${name}.DIST.cur) for the past few steps
and saves it to \${name}.DIST.avg
DIST can be specified by average.what option

usage: ${0##*/} infile outfile
EOF
   exit 0
fi

[[ -z $1 || -z $2 ]] && die "${0##*/}: Missing arguments"

do_external postadd dummy "$1" "$2"

name=$(csg_get_interaction_property name)

# these are arrays
what_to_do_list=( $(csg_get_interaction_property inverse.post_add_options.average.what) )

# get current step directory name and number
step_dir="$(get_current_step_dir)"
step_nr=$(get_step_nr $step_dir)

# maximum number of steps to be averaged for
max_steps_nr=$(csg_get_property cg.inverse.average.steps '1')

# we allow multiple things per interaction to be averaged
for ((i=0;i<${#what_to_do_list[@]};i++)); do
  dist=${what_to_do_list[$i]}
  # do not compute potential averages directly
  # compute it from the avg parameters
  if [[ ! ${dist} = "pot" ]]; then
    # store the tables from last max_steps_nr steps
    for ((step_i=0;step_i<$max_steps_nr;step_i++)); do
      step_dir="$(get_stepname $step_nr)"	
      if [[ -d $CSG_MAINDIR/$step_dir ]]; then
        tables[$step_i]="$CSG_MAINDIR/$step_dir/${name}.${dist}.cur"
      else
        break
      fi
      ((step_nr--))
    done
    # compute the average 
    do_external table average --output ${name}.${dist}.avg "${tables[@]}"
  else 
    # for dist = pot check if avg parameters have been computed or not
    if [[ -f ${name}.param.avg ]]; then
      critical csg_reupdate --gentable true --interaction "${name}" --param-in-ext param.avg --param-out-ext param.avg --pot-out-ext pot.avg --options $CSGXMLFILE
    else
      die "${0##*/}: file '${name}.param.avg' was not found. Make sure 'param' is specified before 'pot' in the what-do list at '$name.inverse.post_add_options.average.what'."
    fi
  fi
done
<commit_msg>correction in post add average re to avoid negative step_nr<commit_after>#! /bin/bash
#
# Copyright 2009-2011 The VOTCA Development Team (http://www.votca.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if [ "$1" = "--help" ]; then
cat <<EOF
${0##*/}, version %version%
postadd average script for relative entropy, 
calcs averages of (\${name}.DIST.cur) for the past few steps
and saves it to \${name}.DIST.avg
DIST can be specified by average.what option

usage: ${0##*/} infile outfile
EOF
   exit 0
fi

[[ -z $1 || -z $2 ]] && die "${0##*/}: Missing arguments"

do_external postadd dummy "$1" "$2"

name=$(csg_get_interaction_property name)

# these are arrays
what_to_do_list=( $(csg_get_interaction_property inverse.post_add_options.average.what) )

# get current step directory name and number
step_dir="$(get_current_step_dir)"
step_nr=$(get_step_nr $step_dir)

# maximum number of steps to be averaged for
max_steps_nr=$(csg_get_property cg.inverse.average.steps '1')

# we allow multiple things per interaction to be averaged
for ((i=0;i<${#what_to_do_list[@]};i++)); do
  dist=${what_to_do_list[$i]}
  # do not compute potential averages directly
  # compute it from the avg parameters
  if [[ ! ${dist} = "pot" ]]; then
    # store the tables from last max_steps_nr steps
    for ((step_i=0;step_i<$max_steps_nr && $step_nr>=0;step_i++)); do
      step_dir="$(get_stepname $step_nr)"	
      if [[ -d $CSG_MAINDIR/$step_dir ]]; then
        tables[$step_i]="$CSG_MAINDIR/$step_dir/${name}.${dist}.cur"
      else
        break
      fi
      ((step_nr--))
      
    done
    # compute the average 
    do_external table average --output ${name}.${dist}.avg "${tables[@]}"
  else 
    # for dist = pot check if avg parameters have been computed or not
    if [[ -f ${name}.param.avg ]]; then
      critical csg_reupdate --gentable true --interaction "${name}" --param-in-ext param.avg --param-out-ext param.avg --pot-out-ext pot.avg --options $CSGXMLFILE
    else
      die "${0##*/}: file '${name}.param.avg' was not found. Make sure 'param' is specified before 'pot' in the what-do list at '$name.inverse.post_add_options.average.what'."
    fi
  fi
done

{'fraction_non_alphanumeric': 0.1328154604016673, 'fraction_numerical': 0.009662751042061386, 'mean_word_length': 3.8034576888080074, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3859842', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1669, 'n_words': 586}