Help with file read please
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
Help with file read please

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> FPGA
Author Message
Pete Fraser
Guest





Posted: Mon Dec 20, 2004 3:06 am    Post subject: Help with file read please Reply with quote

I'm trying to read a list of stimulus files from a directory file.
This is described on page 527 of Ashenden's book.

At the start of file_loop, read(directory, file_name, file_name_length);
doesn't do what I expected. I assumed it would read an individual
string representing a file name, and would stop when it came to a <CR>
or <LF> . Then on the next pass of the loop it would read the
next filename. Instead, it fills file_name with 50 characters
(including <CR> and <LF>) on each pass.

What am I doing wrong?

Thanks




file_reader : process is
type directory_file is file of string;
file directory : directory_file open read_mode is "stimulus-directory";
variable file_name : string(1 to 50);
variable file_name_length : natural;
variable open_status : file_open_status;
variable char : character;
type char_file is file of character; -- one byte each
file stim_file : char_file;
begin
file_loop : while not endfile(directory) loop
read(directory, file_name, file_name_length);
if file_name_length > file_name'length then
report "file name too long: " & file_name & "... - file skipped"
severity warning;
next file_loop;
end if;
file_open (open_status, stim_file,
file_name(1 to file_name_length), read_mode);
if open_status /= open_ok then
report file_open_status'image(open_status) & " while opening file "
& file_name(1 to file_name_length) & " -file skipped"
severity warning;
next file_loop;
end if;
stimulus_loop : while not endfile(stim_file) loop
if (rst = '1') then
sig <= "00000000";
data_valid <= '0';
elsif (clk'event and clk='1') then
data_valid <= valid;
if (valid = '1') then
read(stim_file, char);
end if;
sig <= char2std(char);
end if;
end loop stimulus_loop;
file_close(stim_file);
end loop file_loop;
wait;
end process file_reader;
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> FPGA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB