SUBROUTINE MAKANA (WRDSIZ, CLRBYT, WRDLEN, ANABYT) C Author: T. R. Wyant C Date: 20-Jul-1990 C Remarks: C Subroutine MAKANA translates anagrams into their C 'canonical' form: all lower case, with the letters in C alphabetical order. To do this, it builds a frequency C table of the letters found, and then just regurgitates C the table back out into the output buffer. The algorithm C stops processing at the first nonalphabetic character C encountered - that is, if the input is 'FOO BAR' the C output is 'FOO'. C C Note as a matter of passing interest that this algorithm C assumes that the uppercase and lowercase letters occupy C a contiguous range of character codes. This is true for C ASCII (and maybe for EBCDIC, but who cares?), but not C for all systems (I remember the Burroughs 5500 like it C was yesterday ...). If you have one of these 'other C systems', you'll need to do some work here. C INTEGER*2 WRDSIZ ! Size of words handled. LOGICAL*1 CLRBYT(WRDSIZ) ! Word to look up, as bytes. INTEGER*2 WRDLEN ! Length of word. LOGICAL*1 ANABYT(WRDSIZ) ! Anagram, as bytes. LOGICAL*1 LCAYE ! Lower case 'a'. PARAMETER (LCAYE = 'a') LOGICAL*1 LCZEE ! Lower case 'z'. PARAMETER (LCZEE = 'z') LOGICAL*1 UCAYE ! Upper case 'A'. PARAMETER (UCAYE = 'A') LOGICAL*1 UCZEE ! Upper case 'Z'. PARAMETER (UCZEE = 'Z') LOGICAL*1 SPA ! Single space. PARAMETER (SPA = ' ') INTEGER*2 FRQSIZ ! Size of frequency table. PARAMETER (FRQSIZ = 32) ! Slight overkill. INTEGER*2 CHRCNT ! Character count. INTEGER*2 CHRCOD ! Character code. INTEGER*2 FREQ(FRQSIZ) ! Letter frequencies. INTEGER*2 WRDLOC ! Location in word. C Zero the frequency table. DO 1220 CHRCOD=1, FRQSIZ FREQ(CHRCOD) = 0 1220 CONTINUE C Scan the input word, building the frequency table. DO 1280 WRDLEN=1, WRDSIZ IF (CLRBYT(WRDLEN) .GE. LCAYE .AND. 1 CLRBYT(WRDLEN) .LE. LCZEE) THEN FREQ (CLRBYT(WRDLEN)-LCAYE+1) = 1 FREQ (CLRBYT(WRDLEN)-LCAYE+1) + 1 ELSE IF (CLRBYT(WRDLEN) .GE. UCAYE .AND. 1 CLRBYT(WRDLEN) .LE. UCZEE) THEN FREQ (CLRBYT(WRDLEN)-UCAYE+1) = 1 FREQ (CLRBYT(WRDLEN)-UCAYE+1) + 1 ELSE GO TO 1290 END IF 1280 CONTINUE WRDLEN = WRDSIZ + 1 1290 CONTINUE WRDLEN = WRDLEN - 1 C Pad the unused part of the 'canonical' algorithm with spaces. DO 1380 WRDLOC = WRDLEN+1, WRDSIZ ANABYT (WRDLOC) = SPA 1380 CONTINUE C Loop through the frequency table, emuitting characters as C specified. Note the assumption of a zero iteration DO loop. WRDLOC = 0 DO 1480 CHRCOD=1, FRQSIZ DO 1470 CHRCNT=1,FREQ(CHRCOD) WRDLOC = WRDLOC + 1 ANABYT(WRDLOC) = CHRCOD+LCAYE-1 1470 CONTINUE 1480 CONTINUE C We're done. Just return. RETURN END