library IEEE;
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
use Ieee.std_logic_unsigned.all;
use std.textio.all;
entity tb_project is
end tb_project;
architecture tb_project_arch of tb_project is
begin
read_input_file:process
--ouput variables
variable OUTLINE : LINE;
file FILEOUT : TEXT is OUT "ouput.TXT";
--
--Input variables
variable inline:line;
variable character_variable:character; --should this be a string?
variable end_of_line:boolean;
file myfile:text is "input.txt";
begin
while not endfile(myfile) loop
readline(myfile,inline);
read(inline,character_variable,end_of_line);
--end_of_line is EOLN boolean flag
while end_of_line loop
read(inline,character_variable,end_of_line);
WRITE(OUTLINE,character_variable); --add variable to outline variable for output.
end loop;
end loop;
WRITELINE(FILEOUT, OUTLINE); --writes outline variable to file.
wait; --Do nothing when finished
end process read_input_file;
end tb_project_arch;
The problem you have is because you call the read function before the loop
[B]begin[/B]
[B]while not endfile(myfile) loop[/B]
readline(myfile,inline);
read(inline,character_variable,end_of_line);
--end_of_line is EOLN boolean flag
[B]while end_of_line loop[/B]
read(inline,character_variable,end_of_line);
WRITE(OUTLINE,character_variable); --add variable to outline variable for output.
[B]end loop;[/B]
[B]end loop;[/B]
WRITELINE(FILEOUT, OUTLINE); --writes outline variable to file.
while not endfile(myfile) loop
readline(myfile,inline);
--end_of_line is EOLN boolean flag
end_of_line := true;
while end_of_line loop
read(inline,character_variable,end_of_line);
WRITE(OUTLINE,character_variable); --add variable to outline variable for output.
end loop;
end loop;
while not endfile(myfile) loop
readline(myfile,inline);
--end_of_line is EOLN boolean flag
end_of_line := true;
while end_of_line loop
read(inline,character_variable,end_of_line);
WRITE(OUTLINE,character_variable); --add variable to outline variable for output.
end loop;
end loop;
WRITELINE(FILEOUT, OUTLINE); --writes outline variable to file.
while not endfile(myfile) loop
readline(myfile,inline);
--end_of_line is EOLN boolean flag
end_of_line := true;
while end_of_line loop
read(inline,character_variable,end_of_line);
if end_of_line then --you need to rename your variables to be more meaningful
WRITE(OUTLINE,character_variable); --add variable to outline variable for output.
end if;
end loop;
end loop;
WRITELINE(FILEOUT, OUTLINE); --writes outline variable to file.
variable string1 : string(1 to 80) := (others => ' ');
begin
while not endfile(myfile) loop
readline(myfile,inline);
--end_of_line is EOLN boolean flag
end_of_line := true;
read(inline,string1,end_of_line);
while end_of_line loop
read(inline,string1,end_of_line);
if end_of_line then --you need to rename your variables to be more meaningful
WRITE(OUTLINE,string1); --add variable to outline variable for output.
end if;
end loop;
end loop;
WRITELINE(FILEOUT, OUTLINE); --writes outline variable to file.
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
use Ieee.std_logic_unsigned.all;
use std.textio.all;
entity tb_project is
end tb_project;
architecture tb_project_arch of tb_project is
begin
read_input_file:process
--ouput variables
variable OUTLINE : LINE;
file FILEOUT : TEXT is OUT "ouput.TXT";
--Input variables
variable inline:line;
variable character_variable:character;
variable end_of_line:boolean;
file myfile:text is "input.txt";
--other read variables
variable int1 : integer;
variable string1 : string(1 to 80) := (others => ' ');
variable in_string: boolean;
begin
--main portion of code starts here!
readline(myfile, OUTLINE);
-- clear the contents of the result string
for i in string1'range loop
string1(i) := ' ';
end loop;
-- read all characters of the line, up to the length
-- of the results string
for i in string1'range loop
read(OUTLINE, character_variable, in_string);
string1(i) := character_variable;
if not in_string then -- found end of line
exit;
end if;
end loop;
if (string1(1 to 4) = "abcd")then
WRITE(OUTLINE,string'("hi "));
else
WRITE(OUTLINE,string'(" hello"));
end if;
write(OUTLINE,string1);
WRITELINE(FILEOUT, OUTLINE); --writes outline variable to file.
wait; --Do nothing when finished
end process read_input_file;
end tb_project_arch;
its the same problem as before. You are putting the extra "d" on because you are not exiting the loop before you append the char to the string. So "d" is still in character_variable after it goes over the end of the line. in_string is only "true" after there are no more characters left on the line.
for i in string1'range loop
read(OUTLINE, character_variable, in_string);
string1(i) := character_variable;
if not in_string then -- found end of line
exit;
end if;
end loop;
for i in string1'range loop
read(OUTLINE, character_variable, in_string);
if in_string then -- found end of line
string1(i) := character_variable;
else
exit;
end if;
end loop;
Modified, very similar to before.
Code:for i in string1'range loop read(OUTLINE, character_variable, in_string); if in_string then -- found end of line string1(i) := character_variable; else exit; end if; end loop;
This may help: "A simple guide describing how to print from VHDL code..."
**broken link removed**
First step - stop asking in other people's threads.
im so sorry, i was kind of rushSecond step - Don't cut and paste the exact same question across 5 threads. One will do just fine.
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?