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.

file reading problem in VHDL

Status
Not open for further replies.

raghava

Member level 2
Joined
Jul 31, 2008
Messages
51
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,870
HI all,

I am facing problems with file reading in VHDL. I am newbie to VHDL.

I am expecting answers.
Here is the code and error message I have got.

***********************

procedure PrepareInput is
variable inLIne: line;
variable int_text : integer:= 0;
variable index : integer:= 0;
--file file_in : text open read_mode is "../data/input/lena_64_64.txt";
--file file_in : integer;
type int_file is file of integer;
file file_in : int_file is in "../data/input/lena_64_64.txt";
begin

while not endfile(file_in) and (index<IR*IC) loop
--readline(file_in, inLIne);
--exit when endfile (file_in);
--read(inLIne, int_text);
read(file_in, pixelImage(index));
index := index + 1;
end loop;

file_close(file_in);

end PrepareInput;

Error message is ERROR: In process testbench.vhd:stim_proc
../data/input/lena_64_64.txt read error on type int_file
INFO: Simulator is stopped.
 

Hi,

What simulator are you using?

1. Why do you not use the VHDL-93 file procedure:
file file_in : text open read_mode is "...";

2. The readline is necessary. Reading a file has 2 steps, first read the entire line with the readline function and next, break up this line (if necessary) and assign it to variables with one of the several read functions.

Devas
 

    raghava

    Points: 2
    Helpful Answer Positive Rating
HI Devas,


Thanks for your reply.

I am uising ISE 11.3 simulator.
I wanted to read a .txt file in which MXN matrix of integers (image raster data).
Should I have still readline and read command individually.

Now the new code is given below. Could you check it out. And moreover inbetween readline and read command, exit should be there or not.

Expecting your valuable reply as I am newbie to VHDL.

**************************************

procedure PrepareInput is
variable inLIne: line;
variable index_test : integer:= 0;
variable end_file:bit:= '0';
file file_in : text open read_mode is "../data/input/lena_64_64.txt"; --VHDL 93 syntax usage
begin
while not endfile(file_in) and (index_test<IR*IC) loop
readline(file_in, inLIne);
exit when endfile (file_in);
read(inLIne, pixelImage(index_test));
index_test := index_test + 1;
end loop;

file_close(file_in);

end PrepareInput;
 

Hi,

You need always a readline and almost 1 read, as readline reads one line from the file and read gets a value from this line. When you have more than 1 value on the line, then you need more reads behind the readline, for example when your input file is:
9 4 3
2 6 2

You need 1 readline and 3 reads, the first gets value 9, the second value 4, the third value 3.

The exit is not necessary as the while ends when you reach end of file (or index has reached a value).

pixelimage(index) has to be declared. The read expects a variable, so you can declare it inside the procedure as a variable. From your previous post you declared it outside as a signal. Then you need to declare the pixelImage as a signal in the procedure parameter declaration and you can use a temp variable in the read and on the next line pixelImage(index) <= temp_var;

Devas
 

    raghava

    Points: 2
    Helpful Answer Positive Rating
HI,

Thanks for your reply.

I have to read MXN matrix from the input file.
M = number of rows and N = number of columns.
Then read statement should be put under for loop iterating for N times or what.
Here PixelImage is shared variable.
Could you modify the present code given below.

*************************
procedure PrepareInput is
variable inLIne: line;
variable index_test : integer:= 0;
variable end_file:bit:= '0';
file file_in : text open read_mode is "../data/input/lena_64_64.txt"; --VHDL 93 syntax usage
begin
while not endfile(file_in) and (index_test<M*N) loop
readline(file_in, inLIne);
read(inLIne, pixelImage(index_test));
index_test := index_test + 1;
end loop;

file_close(file_in);

end PrepareInput;
 

Hi,

Well I would suggest to try it out. I believe that is the best way to learn a language.

If your input file has more than one value on a line, than yes you need more reads. In my previous example with 3 values on 1 line:
readline(....);
read(....);
read(....);
read(.....);

Sucess,

Devas
 

    raghava

    Points: 2
    Helpful Answer Positive Rating
HI Devas,

Thanks for your reply.

This is the code I have written now. read statement I have put under for loop running for IC iterations.(Which represents no of columns i.e no of elements in a row)

while not endfile(file_in) and (index_test<IR*IC) loop
readline(file_in, inLIne);
for i in 0 to IC-1 loop
read(inLIne, pixelImage(index_test));
index_test := index_test + 1;
end loop;
end loop;

Added after 4 hours 28 minutes:

HI all,

The problem got solved.

Thanks to Devas for your help. This is the final code

procedure PrepareInput is
variable inLIne: line;
variable int_text : integer:= 0;
variable index_test : integer:= 0;
variable end_file:bit:= '0';
file file_in : text open read_mode is "../data/input/lena_256_256.txt";

begin

while not endfile(file_in) and (index_test<IR*IC) loop
readline(file_in, inLIne);
for i in 0 to IC-1 loop
read(inLIne, pixelImage(index_test));
index_test := index_test + 1;
end loop;
end loop;

file_close(file_in);

end PrepareInput;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top