1 /*
2 
3  * Revision 1.1  1996/08/19  22:32:07  jaf
4  * Initial revision
5  *
6 
7 */
8 
9 /*  -- translated by f2c (version 19951025).
10    You must link the resulting object file with the libraries:
11 	-lf2c -lm   (in that order)
12 */
13 
14 #include "f2c.h"
15 
16 extern int ham84_(integer *input, integer *output, integer *errcnt);
17 
18 /* ***************************************************************** */
19 
20 /* 	HAM84 Version 45G */
21 
22 /*
23  * Revision 1.1  1996/08/19  22:32:07  jaf
24  * Initial revision
25  * */
26 /* Revision 1.3  1996/03/21  15:26:00  jaf */
27 /* Put comment header in standard form. */
28 
29 /* Revision 1.2  1996/03/13  22:00:13  jaf */
30 /* Comments added explaining that none of the local variables of this */
31 /* subroutine need to be saved from one invocation to the next. */
32 
33 /* Revision 1.1  1996/02/07 14:47:04  jaf */
34 /* Initial revision */
35 
36 
37 /* ***************************************************************** */
38 
39 /*  Hamming 8,4 Decoder - can correct 1 out of seven bits */
40 /*   and can detect up to two errors. */
41 
42 /* Input: */
43 /*  INPUT  - Seven bit data word, 4 bits parameter and */
44 /*           4 bits parity information */
45 /* Input/Output: */
46 /*  ERRCNT - Sums errors detected by Hamming code */
47 /* Output: */
48 /*  OUTPUT - 4 corrected parameter bits */
49 
50 /* This subroutine is entered with an eight bit word in INPUT.  The 8th */
51 /* bit is parity and is stripped off.  The remaining 7 bits address the */
52 /* hamming 8,4 table and the output OUTPUT from the table gives the 4 */
53 /* bits of corrected data.  If bit 4 is set, no error was detected. */
54 /* ERRCNT is the number of errors counted. */
55 
56 /* This subroutine has no local state. */
57 
ham84_(integer * input,integer * output,integer * errcnt)58 /* Subroutine */ int ham84_(integer *input, integer *output, integer *errcnt)
59 {
60     /* Initialized data */
61 
62     static integer dactab[128] = { 16,0,0,3,0,5,14,7,0,9,14,11,14,13,30,14,0,
63 	    9,2,7,4,7,7,23,9,25,10,9,12,9,14,7,0,5,2,11,5,21,6,5,8,11,11,27,
64 	    12,5,14,11,2,1,18,2,12,5,2,7,12,9,2,11,28,12,12,15,0,3,3,19,4,13,
65 	    6,3,8,13,10,3,13,29,14,13,4,1,10,3,20,4,4,7,10,9,26,10,4,13,10,15,
66 	    8,1,6,3,6,5,22,6,24,8,8,11,8,13,6,15,1,17,2,1,4,1,6,15,8,1,10,15,
67 	    12,15,15,31 };
68 
69     integer i__, j, parity;
70 
71 /*       Arguments */
72 /*       Parameters/constants */
73 /*       Local variables that need not be saved */
74 /*  Determine parity of input word */
75     parity = *input & 255;
76     parity ^= parity / 16;
77     parity ^= parity / 4;
78     parity ^= parity / 2;
79     parity &= 1;
80     i__ = dactab[*input & 127];
81     *output = i__ & 15;
82     j = i__ & 16;
83     if (j != 0) {
84 /*          No errors detected in seven bits */
85 	if (parity != 0) {
86 	    ++(*errcnt);
87 	}
88     } else {
89 /*          One or two errors detected */
90 	++(*errcnt);
91 	if (parity == 0) {
92 /*             Two errors detected */
93 	    ++(*errcnt);
94 	    *output = -1;
95 	}
96     }
97     return 0;
98 } /* ham84_ */
99 
100