A.2.3.2 Listing of TABAN
PROGRAM TABAN (TABLE, OUTPUT, TOTAL,
SECT1, SECT2, SECT3,
SECT4, SECT5, SECT6,
SECT7, SECT8, SECT9,
TSECT1, TSECT2, TSECT3,
TSECT4, TSECT5, TSECT6,
TSECT7, TSECT8, TSECT9,
NUM1, NUM2, NUM3,
NUM4, NUM5, NUM6,
NUM7, NUM8, NUM9,
NUMT);
CONST WLENGTH = 16; { only read first 16 chars of 20 char word
to allow four columns to fit across page
in final output }
WORDPLUS1 = 17;
SKIP2 = 10;
SKIP3 = 8;
VAR TABLE : TEXT; { input table }
TOTAL, NUMT : TEXT; { total files }
SECT1, SECT2, SECT3 : TEXT; { final output files for }
SECT4, SECT5, SECT6 : TEXT; { textual information }
SECT7, SECT8, SECT9 : TEXT;
NUM1, NUM2, NUM3 : TEXT; { final output files for }
NUM4, NUM5, NUM6 : TEXT; { numerical information }
NUM7, NUM8, NUM9 : TEXT;
TSECT1, TSECT2, TSECT3 : TEXT; { temporary output files }
TSECT4, TSECT5, TSECT6 : TEXT; { for textual informat'n }
TSECT7, TSECT8, TSECT9 : TEXT;
S1_COUNT, S2_COUNT : INTEGER; { temporary token count }
S3_COUNT, S4_COUNT : INTEGER; { for current type }
S5_COUNT, S6_COUNT : INTEGER; { in each sect'n }
S7_COUNT, S8_COUNT, S9_COUNT : INTEGER;
S1_TYPES, S2_TYPES : INTEGER; { total type count }
S3_TYPES, S4_TYPES : INTEGER; { for each section }
S5_TYPES, S6_TYPES : INTEGER;
S7_TYPES, S8_TYPES, S9_TYPES : INTEGER;
S1_TOKENS, S2_TOKENS : INTEGER; { total token count }
S3_TOKENS, S4_TOKENS : INTEGER; { for each section }
S5_TOKENS, S6_TOKENS : INTEGER;
S7_TOKENS, S8_TOKENS, S9_TOKENS : INTEGER;
TOT_TYPES, TOT_TOKENS : INTEGER;
CH, TESTCH, SECTNO : CHAR;
I, COUNT : INTEGER;
FREQ : REAL;
WORD : PACKED ARRAY [1..WLENGTH] OF CHAR;
{*************************************************}
PROCEDURE OPEN_TEMP_FILES (VAR FILE_TO_OPEN : TEXT);
{ FUNCTION: Opens temporary files
CALLED BY: Initialize
CALLS: Nothing }
BEGIN
OPEN (FILE_VARIABLE := FILE_TO_OPEN,
HISTORY := NEW,
RECORD_TYPE := FIXED,
RECORD_LENGTH := 27,
ACCESS_METHOD := SEQUENTIAL,
ORGANIZATION := SEQUENTIAL);
REWRITE (FILE_TO_OPEN);
END; { Open_Temp_Files }
{-------------------------------------}
PROCEDURE INITIALIZE;
{ FUNCTION: Opens files, sets variables to zero
CALLED BY: Main
CALLS: Open_Temp_Files }
BEGIN
{ open data table for reading }
OPEN (FILE_VARIABLE := TABLE,
FILE_NAME := 'TABLE',
HISTORY := READONLY,
RECORD_TYPE := FIXED,
RECORD_LENGTH := 40,
ACCESS_METHOD := SEQUENTIAL,
ORGANIZATION := SEQUENTIAL);
RESET (TABLE);
{ open total output tables for writing }
OPEN (FILE_VARIABLE := TOTAL,
FILE_NAME := 'TOTAL',
HISTORY := NEW,
RECORD_TYPE := FIXED,
RECORD_LENGTH := 32,
ACCESS_METHOD := SEQUENTIAL,
ORGANIZATION := SEQUENTIAL);
REWRITE (TOTAL);
OPEN (FILE_VARIABLE := NUMT,
FILE_NAME := 'NUMT',
HISTORY := NEW);
REWRITE (NUMT);
{ open temporary files }
OPEN_TEMP_FILES (TSECT1);
OPEN_TEMP_FILES (TSECT2);
OPEN_TEMP_FILES (TSECT3);
OPEN_TEMP_FILES (TSECT4);
OPEN_TEMP_FILES (TSECT5);
OPEN_TEMP_FILES (TSECT6);
OPEN_TEMP_FILES (TSECT7);
OPEN_TEMP_FILES (TSECT8);
OPEN_TEMP_FILES (TSECT9);
{ set total type and token counts to zero }
S1_TYPES := 0; S1_TOKENS := 0;
S2_TYPES := 0; S2_TOKENS := 0;
S3_TYPES := 0; S3_TOKENS := 0;
S4_TYPES := 0; S4_TOKENS := 0;
S5_TYPES := 0; S5_TOKENS := 0;
S6_TYPES := 0; S6_TOKENS := 0;
S7_TYPES := 0; S7_TOKENS := 0;
S8_TYPES := 0; S8_TOKENS := 0;
S9_TYPES := 0; S9_TOKENS := 0;
TOT_TYPES := 0; TOT_TOKENS := 0;
END; { Initialize }
{----------------------------------------------}
PROCEDURE ZERO_COUNTS;
{ FUNCTION: Zeros the temporary count variables
used for each type
CALLED BY: Main
CALLS: Nothing }
BEGIN
S1_COUNT := 0;
S2_COUNT := 0;
S3_COUNT := 0;
S4_COUNT := 0;
S5_COUNT := 0;
S6_COUNT := 0;
S7_COUNT := 0;
S8_COUNT := 0;
S9_COUNT := 0;
END; { Zero_Counts }
{----------------------------------------}
PROCEDURE WRITE_LIST (VAR CUR_LIST : TEXT;
{ temp. output file }
CUR_COUNT : INTEGER;
{ no. of times type used in curr. section }
VAR CUR_TYPES,
{ no. of types in current section }
CUR_TOKENS : INTEGER);
{ no. of tokens in current section }
{ FUNCTION: Writes the current type and the number of times
it is used in the current section. Increments the
number of types in the current section, and
updates the number of tokens
CALLED BY: Write_Lists
CALLS: Nothing }
BEGIN
IF CUR_COUNT <> 0 THEN
BEGIN
WRITELN (CUR_LIST, WORD, ' ', CUR_COUNT);
CUR_TYPES := CUR_TYPES + 1;
CUR_TOKENS := CUR_TOKENS + CUR_COUNT;
END;
END; { Write_List }
{--------------------------------------}
PROCEDURE WRITE_LISTS;
{ FUNCTION: Writes the temporary output lists of words
CALLED BY: Main
CALLS: Write_List }
BEGIN
WRITE_LIST (TSECT1, S1_COUNT, S1_TYPES, S1_TOKENS);
WRITE_LIST (TSECT2, S2_COUNT, S2_TYPES, S2_TOKENS);
WRITE_LIST (TSECT3, S3_COUNT, S3_TYPES, S3_TOKENS);
WRITE_LIST (TSECT4, S4_COUNT, S4_TYPES, S4_TOKENS);
WRITE_LIST (TSECT5, S5_COUNT, S5_TYPES, S5_TOKENS);
WRITE_LIST (TSECT6, S6_COUNT, S6_TYPES, S6_TOKENS);
WRITE_LIST (TSECT7, S7_COUNT, S7_TYPES, S7_TOKENS);
WRITE_LIST (TSECT8, S8_COUNT, S8_TYPES, S8_TOKENS);
WRITE_LIST (TSECT9, S9_COUNT, S9_TYPES, S9_TOKENS);
END; { Write_Lists }
{--------------------------------------}
PROCEDURE WRITE_FILE (VAR CUR_LIST,
{ current temporary output file }
OUT_LIST,
{ current final output file }
OUT_NUM : TEXT;
{ current numeric information file }
CUR_TOKENS,
{ count of tokens for current section }
CUR_TYPES : INTEGER);
{ count of types for current section }
{ FUNCTION: Writes the final output files (types, counts,
frequencies)
CALLED BY: Write_Files
CALLS: Nothing }
VAR WORDETC : PACKED ARRAY [1..WORDPLUS1] OF CHAR;
BEGIN
IF CUR_TYPES > 0 THEN
BEGIN
RESET (CUR_LIST);
OPEN (FILE_VARIABLE := OUT_LIST,
HISTORY := NEW,
RECORD_TYPE := FIXED,
RECORD_LENGTH := 32,
ACCESS_METHOD := SEQUENTIAL,
ORGANIZATION := SEQUENTIAL);
REWRITE (OUT_LIST);
REPEAT { until end of CUR_LIST }
READ (CUR_LIST, WORDETC);
WRITE (OUT_LIST, WORDETC);
READ (CUR_LIST, COUNT);
WRITE (OUT_LIST, COUNT : 5);
WRITE (OUT_LIST, ' ', COUNT/CUR_TOKENS : 9 : 6);
WRITELN (OUT_LIST);
READLN (CUR_LIST);
UNTIL EOF (CUR_LIST);
OPEN (FILE_VARIABLE := OUT_NUM,
HISTORY := NEW,
ACCESS_METHOD := SEQUENTIAL,
ORGANIZATION := SEQUENTIAL);
REWRITE (OUT_NUM);
WRITELN (OUT_NUM, 'The number of Types = ', CUR_TYPES);
WRITELN (OUT_NUM, 'The number of Tokens = ', CUR_TOKENS);
WRITE (OUT_NUM, 'The Logarithmic Type/Token Ratio = ');
WRITELN (OUT_NUM, LN(CUR_TYPES)/LN(CUR_TOKENS) : 8 : 5);
END
END; { Write_File }
{--------------------------------------}
PROCEDURE WRITE_FILES;
{ FUNCTION: Writes the final output files
CALLED BY: Main
CALLS: Write_File }
BEGIN
WRITE_FILE (TSECT1, SECT1, NUM1, S1_TOKENS, S1_TYPES);
WRITE_FILE (TSECT2, SECT2, NUM2, S2_TOKENS, S2_TYPES);
WRITE_FILE (TSECT3, SECT3, NUM3, S3_TOKENS, S3_TYPES);
WRITE_FILE (TSECT4, SECT4, NUM4, S4_TOKENS, S4_TYPES);
WRITE_FILE (TSECT5, SECT5, NUM5, S5_TOKENS, S5_TYPES);
WRITE_FILE (TSECT6, SECT6, NUM6, S6_TOKENS, S6_TYPES);
WRITE_FILE (TSECT7, SECT7, NUM7, S7_TOKENS, S7_TYPES);
WRITE_FILE (TSECT8, SECT8, NUM8, S8_TOKENS, S8_TYPES);
WRITE_FILE (TSECT9, SECT9, NUM9, S9_TOKENS, S9_TYPES);
END; { Write_Files }
{****************************************}
BEGIN { Taban }
INITIALIZE; { open table, total files, zero overall counts }
REPEAT { until EOF (TABLE) }
ZERO_COUNTS; { set all temp counts to zero }
GET (TABLE); { skip initial '*' }
READ (TABLE, WORD); { first 16 chars only }
FOR I := 1 TO 5 DO GET (TABLE); { skip to start of count }
READ (TABLE, COUNT);
READLN (TABLE, FREQ);
WRITELN (TOTAL, WORD, ' ', COUNT : 5, ' ', FREQ);
TOT_TYPES := TOT_TYPES + 1;
TOT_TOKENS := TOT_TOKENS + COUNT;
REPEAT { until TESTCH = '$' }
{ skip to start of section no.info info for current ref }
FOR I := 1 TO SKIP2 DO GET (TABLE);
READ (TABLE, SECTNO);
CASE SECTNO OF
'1' : S1_COUNT := S1_COUNT + 1;
'2' : S2_COUNT := S2_COUNT + 1;
'3' : S3_COUNT := S3_COUNT + 1;
'4' : S4_COUNT := S4_COUNT + 1;
'5' : S5_COUNT := S5_COUNT + 1;
'6' : S6_COUNT := S6_COUNT + 1;
'7' : S7_COUNT := S7_COUNT + 1;
'8' : S8_COUNT := S8_COUNT + 1;
'9' : S9_COUNT := S9_COUNT + 1;
OTHERWISE { do nothing }
END;
{ skip to start of next ref }
FOR I := 1 TO SKIP3 DO GET (TABLE);
READ (TABLE, TESTCH);
IF EOLN (TABLE) AND (TESTCH <> '$') THEN { end of current
ref line }
READLN (TABLE);
UNTIL TESTCH = '$'; { last ref read for this type }
IF NOT EOF (TABLE) THEN
READLN (TABLE); { move to next line of table }
WRITE_LISTS;
UNTIL EOF (TABLE);
WRITE_FILES;
WRITELN (NUMT, 'The Total number of Types = ', TOT_TYPES);
WRITELN (NUMT, 'The Total number of Tokens = ', TOT_TOKENS);
WRITE (NUMT, 'The Overall Logarithmic Type/Token Ratio = ');
WRITELN (NUMT, LN(TOT_TYPES)/LN(TOT_TOKENS) : 8 : 6);
END. { Taban }
[Back to Roadmap / Site Index ] [ Table of Contents ] [ E-mail Author ]
Last modified: Monday, 18-Sep-2017 03:29:56 AEST