ham84.c 3.5 KB

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