chitra ranganath
Member level 2
i want to know how to store all the values read from the text file which contains integers, into an array
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
type some_array_t is array(integer range <>) of integer;
signal ar : some_array_t(0 to 99); --could be a varaible
--inside a process
file f : text open read_mode is "my_file.txt";
variable inline : line;
for i in ar'range loop
readline(f, inline);
read(f, ar(i));
end loop;
for i in ar'range loop
readline(f, inline);
read(inline, ar(i));
end loop;
constant prec:integer:=16;
process
file infile : TEXT;
variable fstatus : file_open_status;
variable buf_in : line;
variable temp: integer:=16;
begin
data_bus<=(others=>'0');
wait for 1 ns;
while reset = '1' loop
file_open(fstatus, infile, "myfile.txt",READ_MODE);
while (not endfile (infile)) loop
wait until clk'event and clk = '0';
readline (infile, buf_in);
read (buf_in ,temp);
data_bus<=CONV_STD_LOGIC_VECTOR(temp,prec);
end loop;
file_close (infile);
end loop;
end process;
i:=0;
while (not endfile(f_open1)) loop
readline(f_open1,L1);
read(L1,ar(i));
i:=i+1;
end loop;
I assume your using a synchronous circuit. Every clk'event you need to use the data or do something with it or it will get overwritten.i`m able to read the values in file but everytime the parameter in read ie value is getting overwritten.
What's exactly the problem or error in this case? If there's actually a problem to use array elements in read() function with your simulator tool (I don't know why), then you can read the data to an auxilary integer variable.its not possible to read that way. array s r not supported that way i think
read(inline, temp);
ar(i):=temp;
Like others, I was under the assumption, that the values are supplied in the file line by line. Please clarify.it read the values but all 1st row elements r not read properly.