#!/usr/bin/perl -w
################################################################
# phistat.pl : Friedman's Phi Test for a text                  #
#--------------------------------------------------------------#
# Simulation to characterize the distribution                  #
#                                                              #
# Inputtext from STDIN                                         #
# Command line parameter: rr = length of text chunks           #
#   The inputtext is divided into chunks of length rr.         #
#   For these chunks the phi values (coincidence indices) are  #
#     calculated and printed.                                  #
#--------------------------------------------------------------#
# Transliteration of special characters according to English   #
#   rules                                                      #
# For special characters of other languages use preptext.pl    #
#   first.                                                     #
#--------------------------------------------------------------#
# Klaus Pommerening 2013-December-20                           #
#                                                              #
# This program is freeware. Use it as you like.                #
# Usual disclaimers apply.                                     #
################################################################

require "auxcrypt.pl";  # Use standard alphabet
                           #   as global variables $alphabet,
                           #   @alphabet, and %sa.
                           # Use procedures
                           #   &gettext, &phi.
$rr = $ARGV[0];            # Get length from command line.
$testtext = &gettext;      # Read text from standard input.

while (length($testtext) >= $rr) {
  $parttext = substr($testtext, 0, $rr);
  $testtext = substr($testtext,$rr);
  $phivalue = &phi($parttext);
  print $phivalue*$rr*($rr-1)/2, " ; ", $phivalue, "\n";
  } # end while
