Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

readline from file using readline

Status
Not open for further replies.

korssane2000

Programmer
Aug 29, 2005
1
0
0
CA
hi .bros,

i am trying to read PGM file ...using textio lib..and readline instruction...i am a new in vhdll..i would like to read such file format:
The program i write is just reading the header and the first
integer of each line ...

P5
255 255 = (width height)
255
100 101 102 103.....(width)
201 202 207 203......
.....................
.....................
.....................
height...............width


here is my program if u can help me pls it wll be appreciated..

library ieee;
use ieee.std_logic_1164.all;
USE ieee.numeric_std.ALL;

use std.textio.all;
use work.txt_util.all;


entity FILE_READ is
generic (
stim_file: string := "sim.dat"
);
port(
CLK : in std_logic;
RST : in std_logic;
ENTETE : OUT string (2 DOWNTO 1 );
LARGEUR : OUT natural;
HAUTEUR : OUT natural;
MAX_VALUE : OUT natural;
DATA : out unsigned(7 downto 0)


);
end FILE_READ;



architecture read_from_file of FILE_READ is


file stimulus: TEXT open read_mode is stim_file;


begin



-- read data and control information from a file

receive_data: process

variable l: line;
variable s: natural;
variable magic_number: string (2 DOWNTO 1);
variable width, height,max : natural;
variable header_read : boolean := false ;
variable bon : boolean;
CONSTANT nbr_pixels : natural := width * height ;
-
begin

wait until (CLK 'event and CLK='1'); -- pour synchroniser

IF header_read=false THEN

readline(stimulus,l);-- ouverture du fichier image
read(l,magic_number);
ENTETE <= magic_number;

readline(stimulus,l);-- READ WIDTH
read(l,width);
LARGEUR <= width;
--readline(stimulus,l);-- READ HEIGHT
read(l,height);
HAUTEUR <= height;

readline(stimulus,l);-- READ GRAY_MAX_VALUE
read(l,max);
MAX_VALUE <= max;

header_read:= true;

END IF;

while not endfile(stimulus) loop

-- read digital data from input file

IF header_read and CLK ='1' THEN

readline(stimulus, l);
read(l,s);

DATA <= to_unsigned(s,8);


END IF;

end loop;



end process receive_data;



end read_from_file;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top