cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
4,329 Views
Registered: ‎08-23-2016

reading elements of a text file in blocks

i want to read the elenents of a text file that has large number of values(around 65536) in blocks or module of 256 elements at a time. plz help.

0 Kudos
Reply
3 Replies
steve_av
Voyager
Voyager
4,328 Views
Registered: ‎10-06-2015

I'm assuming you want to read the data in as part of a test bench?

0 Kudos
Reply
balkris
Xilinx Employee
Xilinx Employee
4,314 Views
Registered: ‎08-01-2008

try the following code

Code:

type img_array_t is array(natural range <>, natural range <>) of natural;
signal img_array : img_array_t(0 to X_SIZE-1, 0 to Y_SIZE-1);


.....
--inside a process/function/procedure
file img_file : text open read_mode is "text.txt";
variable l : line;


for y in 0 to Y_SIZE-1 loop
readline(img_file, l); --gets 1 line at a time

for x in 0 to X_SIZE-1 loop
read(l, img_array(x,y)); --read in each pixel
end loop;
end loo
Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Reply
muzaffer
Teacher
Teacher
4,297 Views
Registered: ‎03-31-2012

are you using verilog or vhdl ?
if verilog, you can use $fread to read as much data as you want but you have to parse it yourself.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Reply