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.

to read a text file and to write in another text file

Status
Not open for further replies.

prdarsini

Newbie level 1
Joined
Dec 29, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,294
hi...
actually i'm trying to read a text file which contains a matrix of elements of size 256x256. but i was able to find some rows of extra zeros occurs periodically... how could i eliminate that...
this is the code i used...


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use std.textio.all;
use ieee.std_logic_textio.all;

entity testing1 is
generic
(
WIDTH : integer := 256;
HEIGHT : integer := 256 -- IMAGE_MEMORY_SIZE
);

port(clk,en:in std_logic;
INPUT_FILENAME : string := "Test1.txt";
OUTPUT_FILENAME : string := "Result1.txt");
end testing1;

architecture Behavioral of testing1 is
file ifile:text is in "text1.txt";
file ofile:text is out "result1.txt";
begin

process(clk,en)
type tarray is array(0 to width*height-1)of bit;
variable myline:line;
variable i:tarray;
variable b:tarray;
begin
if clk'event and clk='1' then
if en ='1' then
while not endfile(ifile)loop
readline(ifile,myline);
for n in 0 to 255 loop
read(myline,i(n));
b(n):=i(n);
end loop;



for m in 0 to 255 loop
write(myline,b(m));
end loop;
writeline(ofile,myline);
end loop;
end if;
end if;
end process;
end Behavioral;
 

do you realise this is reading and writing the entire file on every clock cycle?
This code is just reading single bits at a time. So on each line I assume you have a load of 1's and 0s separated by spaces (like "0 1 0 1 1 1 0..." etc).

Also, dont declare an array of bits. Thats what the bit_vector type is for. You can read bit_vectors directly from a file.
If there are more than 256 elements on a single line, the myline variable wont be empty when you move into the write loop I suggest you put:

DEALLOCATE(myline);

between the two for loops (n and m)
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top