syedshan
Advanced Member level 1
- Joined
- Feb 27, 2012
- Messages
- 463
- Helped
- 27
- Reputation
- 54
- Reaction score
- 26
- Trophy points
- 1,308
- Location
- Jeonju, South Korea
- Activity points
- 5,134
sprintf(str , "name%d.txt ",i);
Open them one by one using a loop function with indexed file names
PS. I think I know what the next problem will be - length of the string s
file infile : text is in str; --declare input file
--where variable str: STRING(1 to 9) := "data0.txt";
Open them one by one using a loop function with indexed file names
process
file infile : text;
variable str : string(1 to 9);
begin
....
for i in 0 to 9 loop
str := "text" & integer'image(i) & ".txt";
FILE_OPEN(infile, str, read_mode);
--do some stuff with the file
FILE_CLOSE(infile);
end loop;
wait;
end process;
Use concatenation, and make sure that you declare s to be large enough to hold the largest possible string you're going to use.
Finished circuit initialization process.
ERROR: In process top.vhd:reading
ENDFILE called on a file object that is not open
INFO: Simulator is stopped.
architecture Behavioral of filehandle is
signal endoffile : bit := '0';
signal clock : std_logic := '0';
signal rst : std_logic := '1';
signal dataread : integer;
signal linenumber : integer:=1; --line number of the file read or written.
signal rd_en : std_logic := '0';
signal wr_en: std_logic := '1';
signal toggle : std_logic := '0';
signal empty : std_logic ;
--signal str : string(1 to 9) := "data0.txt";
begin
clock <= not (clock) after 5 ns; --clock with time period 2 ns
process
begin
wait for 30 ns; rst <= '0';
wait for 500 ns ;
wait until endoffile = '1';
rd_en <= '1';
end process;
reading :
process(clock, rst)
variable str: STRING(1 to 9) := "data0.txt";
-- file infile : text open read_mode is "data0.txt"; --declare input file
file infile : text open read_mode is str;
variable inline : line; --line number declaration
variable dataread1 : integer;
begin
if(rst = '1') then
endoffile <= '0';
wr_en <= '0';
elsif(rising_edge(clock)) then
if (not endfile(infile)) then
readline(infile, inline);
read(inline, dataread1);
wr_en <= '1';
dataread <= dataread1;
else
endoffile <='1';
-- file_close(infile);
wr_en <= '0';
rd_en <= '1';
end if;
if(rd_en = '1') then endoffile <= '0'; end if;
end if;
end process reading;
..
file infile : text open read_mode is str;
IN VHDL length of string should be equal to the string itself, no larger as used to be in C
Note that you can avoid all of this sizing of the string stuff by constructing the filename string right in the file_open like this...
FILE_OPEN("text" & integer'image(i) & ".txt", str, read_mode);
I have no idea - opening a file with a variable like you did works fine for me (in modelsim 10.1) - and I cannot see a problem in your code.
I suggest trying to get a new version of modelsim - 6.5 is quite old (and has bugs that I got fixed!)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?