storing .txt file in an array..

Discussion in 'VHDL' started by gopal.master, Mar 24, 2011.

  1. gopal.master

    gopal.master

    Joined:
    Mar 24, 2011
    Messages:
    1
    hi all !
    i have made a program to read a text file from a specified location , and i want to store it an array .. i don't know how to do this...please help me..

    here is my code for reading a file..

    Code:
    LIBRARY ieee;
    USE ieee.std_logic_1164.ALL;
    use STD.textio.all; 
    
    ENTITY read_file IS
    END read_file;
    
    ARCHITECTURE beha OF read_file IS
    
        signal  bin_value : std_logic_vector(3 downto 0):="0000";
       
    BEGIN
       
       --Read process
        process
          file file_pointer : text;
            variable line_content : string(1 to 4);
          variable line_num : line;
            variable j : integer := 0;
            variable char : character:='0';
       begin
            ----------Open the file read.txt from the specified location for reading(READ_MODE).
          file_open(file_pointer,"C:\read.txt",READ_MODE);   
          while not endfile(file_pointer) loop ------------till the end of file is reached continue.
          readline (file_pointer,line_num);  --------------------Read the whole line from the file
            ----------------------Read the contents of the line from  the file into a variable.
          READ (line_num,line_content);
            ------------------------For each character in the line convert it to binary value.
           ---------------------------------- --And then store it in a signal named 'bin_value'.
            for j in 1 to 4 loop       
                char := line_content(j);
                if(char = '0') then
                    bin_value(4-j) <= '0';
                else
                    bin_value(4-j) <= '1';
                end if;
            end loop;  
            wait for 10 ns; --------------------------------after reading each line wait for 10ns.
          end loop;
          file_close(file_pointer);  ------------------------after reading all the lines close the file. 
            wait;
        end process;
    
    end beha;
    
     
    gopal.master, Mar 24, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zigbeedeep@gmail.com
    Replies:
    1
    Views:
    11,420
    Dan Andrews
    Sep 29, 2006
  2. Sameen
    Replies:
    2
    Views:
    484
    Victor Bazarov
    Aug 29, 2005
  3. toton
    Replies:
    11
    Views:
    743
    toton
    Oct 13, 2006
  4. Jonathan Wood
    Replies:
    1
    Views:
    532
    Jonathan Wood
    Jun 2, 2008
  5. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,879
    Roedy Green
    Sep 15, 2011
Loading...

Share This Page