Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help using std.textio

Status
Not open for further replies.

nabla101

Junior Member level 3
Joined
Feb 8, 2011
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,600
Hi, could anyone help me using the READLINE and READ procedures of the std.textio package?

Say if I had a text file with numerical values seperated by whitespace, how could I intitialise an array with these values for simulation (Read them from the file one by one and into the array)?

i.e. how can I use the READLINE and READ procedures to parse the file line-by-line, or value-by-value?

the structure of the text file will be something like:

1 78 255 0 145 34
92 3 194 65 245 0
etc..

With a fixed number of values per line seperated by spaces.


Thanks
 

here you go:

Code:
type int_ar_t is array(0 to 5) of integer;
type line_t is array(0 to N_LINES-1) of int_ar_t;

signal my_array : line_t;


.....


process
  file     f      : text open read_mode is "text.txt";
  variable inline : line;
begin
  for i in 0 to N_LINES-1 loop
    readline(f, inline);
  
    for j in int_ar_t'range loop
      read(inline, my_array(i)(j) ); --read the text into the integers
    end loop;
  end loop;

end process;
 

Thanks, I'm just not sure about the usage of the readline and read functions. Readline is used to select a line from the file and place it in your variable inline? How does it know which line to select if it only has the target variable and the target file as an argument, and not a line number? (For instance what if I wanted to skip a group of lines).

Then the read function will read a value of the line into a specified variable? Again, how does it know which value to read from within the line (For example if I wanted to skip a value)?

Does it just increment to the next group of characters (word or number) following a whitespace on every usage? What happens when it reaches the end of the file?

Thanks
 

You cannot do random access - readline simply reads the next line in the file, and Read simply just reads the next value on the line.

If you try and use the read function where there are no more elements on the line, you will get a similation failure, unless you use the version of the function with the "good" parameter that will return false when it tries to read an illegal value or goes over the end of the line.

If you try and read more lines out after the end of a file. you will get an error.
 
Thnka, I have one more question. Can I only have one file open per process, and does it have to be closed afterwards?

Or could a process open a set of files in the declarations section so they are open at the same time, and then in the main body process them all one by one?
 

You open as many files as you like, where you like. Im concerned when you say "main body process". There is no Main in VHDL.
 
You open as many files as you like, where you like. Im concerned when you say "main body process". There is no Main in VHDL.

Thanks, I simply meant the body of the process between the "begin" and "end process" statements, as opposed to the declaration section between the "process" and "begin" statements, but I'm not sure what the correct terms would be.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top