#!/bin/sh
 #### atree release 2.0                                                   ####
 #### Adaptive Logic Network (ALN) simulation program.                    ####
 #### Copyright (C) A. Dwelly, R. Manderscheid, W.W. Armstrong, 1991.     ####
 ####                                                                     ####
 #### License:                                                            ####
 #### A royalty-free license is granted for the use of this software for  ####
 #### NON_COMMERCIAL PURPOSES ONLY. The software may be copied and/or     ####
 #### modified provided this notice appears in its entirety and unchanged ####
 #### in all derived source programs.  Persons modifying the code are     ####
 #### requested to state the date, the changes made and who made them     ####
 #### in the modification history.                                        ####
 ####                                                                     ####
 #### Patent License:                                                     ####
 #### The use of a digital circuit which transmits a signal indicating    ####
 #### heuristic responsibility is protected by U. S. Patent 3,934,231     ####
 #### and others assigned to Dendronic Decisions Limited of Edmonton,     ####
 #### W. W. Armstrong, President.  A royalty-free license is granted      ####
 #### by the company to use this patent for NON_COMMERCIAL PURPOSES ONLY  ####
 #### to adapt logic trees using this program and its modifications.      ####
 ####                                                                     ####
 #### Limited Warranty:                                                   ####
 #### This software is provided "as is" without warranty of any kind,     ####
 #### either expressed or implied, including, but not limited to, the     ####
 #### implied warrantees of merchantability and fitness for a particular  ####
 #### purpose.  The entire risk as to the quality and performance of the  ####
 #### program is with the user.  Neither the authors, nor the             ####
 #### University of Alberta, its officers, agents, servants or employees  ####
 #### shall be liable or responsible in any way for any damage to         ####
 #### property or direct personal or consequential injury of any nature   ####
 #### whatsoever that may be suffered or sustained by any licensee, user  ####
 #### or any other party as a consequence of the use or disposition of    ####
 #### this software.                                                      ####

nawk 'func abs(n)
    {
      if (n < 0)
        return n * -1;
      else
        return n;
    }

    BEGIN {
      largest_error = 0;
      codimensions = 1;
    }

    {
      if (NR == 1 && NF == 1) {
        codimensions = $1;
      }
      else {
        for (n = 0; n < codimensions ; n++) {
          error = abs($(NF - 2*n) - $(NF - 2*(codimensions + n)) );
          error_count[error "," n]++;
          if (error > largest_error)
          {
            largest_error = error;
          }
        }
      }
    }

    END {
      for (dim = 0; dim < codimensions; dim++) {
        ia[dim] = 0;
      }

      for (i = 0; i <= largest_error; i++)
      {
        printf("%9d errors =", i);
        for (dim = 0; dim < codimensions; dim++) {
          printf("\t%d", error_count[i "," dim]);
          ia[dim] += i * error_count[i "," dim];
        }
        printf("\n");
      }

      printf("Inaccuracy level =",ia);
      for (dim = 0; dim < codimensions; dim++) {
        printf("\t%d", ia[dim]);
      }
      printf("\n");
    }' $@
