--	R/W Files with std_logic_type
--   Taken from "VHDL Start's Guide" by Sudhakar Yalamanchili, page 156-157 (Figure 7-1) of 1998 Printing

    library IEEE; 
    use IEEE.std_logic_1164.all; 
    use STD.textio.all; 
      
    package classio is 
    procedure read_v1d (file f:  text; v : out std_logic_vector);
    procedure write_v1d (file f: text; v : in std_logic_vector);	
    end; 
      
    package body classio is 
    procedure read_v1d (file f: text; v: out std_logic_vector) is 
    variable buf: line; -- line terminated by line feed & carriage return 
    variable c: character; --character of text line read 
      
    begin 
    readline (f,buf); -- STD.textio defined function reads line into "buf" 
    for i in v'range loop
    read(buf,c); -- reads single character from "buf" 
    case c is

        when 'X' => v(i) := 'X'; -- covering all signal types in list above 
        when 'U' => v(i) := 'U'; 
        when 'Z' => v(i) := 'Z'; 
        when '0' => v(i) := '0'; 
        when '1' => v(i) := '1'; 
        when 'W' => v(i) := 'W'; 
        when 'L' => v(i) := 'L'; 
        when 'H' => v(i) := 'H'; 
        when '-' => v(i) := '-'; 
        when others => v(i) := '0'; -- for illegal characters 

    end case; 
    end loop; 
    end; 
      
    procedure write_v1d (file f: text; v: in std_logic_vector) is 
    variable buf: line; -- line terminated by line feed & carriage return 
    variable c: character; --character of text line read 
      
    begin 
    for i in v'range loop
    case v(i) is

        when 'X' => write(buf, 'X'); 
        when 'U' => write(buf, 'U'); 
        when 'Z' => write(buf, 'Z'); 
        when '0' => write(buf, character'('0')); 
        when '1' => write(buf, character'('1')); 
        when 'W' => write(buf, 'W'); 
        when 'L' => write(buf, 'L'); 
        when 'H' => write(buf, 'H'); 
        when '-' => write(buf, '-'); 
        when others => write(buf, character'('0')); 

    end case; 
    end loop; 
    writeline (f,buf); 
    end; 
    end package body classio;
