home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / DATAREP.ZIP / INTERP.INC < prev    next >
Encoding:
Text File  |  1990-02-22  |  3.1 KB  |  84 lines

  1. {Takes a vector and interprets it as a string of characters.  If  }
  2. {all the elements in a byte are above an interpretion threshold,  }
  3. {(or below minus the threshold) then the character is printed.    }
  4. {Otherwise, `_' is printed.                                       }
  5.  
  6. PROCEDURE Interpret (Threshold: Real; V: Vector; VAR Interpretation: String);
  7.  
  8.     TYPE    Byte = ARRAY [1..8] OF INTEGER;
  9.  
  10.             Ivector = ARRAY [1..Dimensionality] OF INTEGER;
  11.                 
  12.     VAR  IV: Ivector;
  13.           
  14.     PROCEDURE Blank_string (VAR S: STRING);
  15.         VAR I: INTEGER;   
  16.         BEGIN
  17.         FOR I:= 1 TO 60 DO S [I]:= CHR (32);
  18.         END;
  19.    
  20.     PROCEDURE Make_Binary_Vector (V: Vector; VAR IV: Ivector);
  21.         VAR J: INTEGER;
  22.         BEGIN
  23.         FOR J:= 1 TO Dimensionality DO
  24.                 BEGIN
  25.                 IV[J]:= 0;
  26.                 IF V[J] >=  ABS(Threshold) THEN IV[J]:= 1;
  27.                 IF V[J] <= -ABS(Threshold) THEN IV[J]:=-1;
  28.                 END;
  29.         END;
  30.  
  31.     FUNCTION Count (B: Byte): INTEGER; {Counts zeros in byte.}
  32.         VAR I,Sum: INTEGER;
  33.         BEGIN
  34.         Sum:= 0;
  35.         FOR I:= 1 TO 7 DO IF B[I]=0 THEN Sum:= Sum +1; {Ignore parity bit.}
  36.         Count:= Sum;
  37.         END;
  38.  
  39.     FUNCTION Byte_Interpret (B: Byte): CHAR; 
  40.         VAR I, Charnr: INTEGER;
  41.         Print_char: CHAR;
  42.         Ambiguous: BOOLEAN;
  43.         BEGIN
  44.           {First check to see if all byte elements + 1 or - 1.}
  45.         IF Count (B) > 0 THEN Ambiguous:= TRUE ELSE Ambiguous:= FALSE;
  46.           {Now convert to byte of zero and +1.}
  47.         FOR I:= 1 TO 8 DO IF B[I]=-1 THEN B[I]:= 0; 
  48.           {Convert to Char. number.}
  49.         Charnr:= 64*B[7] + 32*B[6] + 16*B[5] + 8*B[4] + 4*B[3] + 2*B[2] + B[1];
  50.           {Special cases.}
  51.         IF (Charnr <  32) THEN Print_char := '#'    {Non-printing character. }
  52.                           ELSE Print_char := CHR (Charnr);  {Print character.}
  53.         IF (Charnr =   0) THEN Print_char := '_';   {Zero convention is '_'  }
  54.         IF (Charnr = 127) THEN Print_char:= '_';    {Delete convention is '_'}
  55.         IF Ambiguous THEN Print_char:= '_';         {Ambiguous character.    }
  56.         Byte_Interpret:= Print_char;
  57.         END;
  58.  
  59.     PROCEDURE Read_IVector_as_ASCII (IV: Ivector; VAR Interpretation: STRING);
  60.         VAR J, Nr_of_bytes: INTEGER;
  61.             B: BYTE;
  62.         BEGIN
  63.         Nr_of_bytes:= Dimensionality DIV 8;
  64.         Blank_string (Interpretation);
  65.         FOR J:= 0 TO (Nr_of_bytes-1) DO
  66.                 BEGIN                     {Form byte in correct order}
  67.                 B[8]:=IV [J*8+1];         {from vector values.       }
  68.                 B[7]:=IV [J*8+2];
  69.                 B[6]:=IV [J*8+3];
  70.                 B[5]:=IV [J*8+4];
  71.                 B[4]:=IV [J*8+5];
  72.                 B[3]:=IV [J*8+6];
  73.                 B[2]:=IV [J*8+7];
  74.                 B[1]:=IV [J*8+8];
  75.                 Interpretation [(J+1)]:= Byte_Interpret (B);
  76.                 END;
  77.          END;
  78.  
  79.     BEGIN    {Interpret procedure}
  80.     Make_Binary_Vector (V, IV);
  81.     Read_IVector_as_ASCII (IV, Interpretation);
  82.     END;     {Interpret procedure.}
  83.  
  84.