Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Question on importing text from files

 
Thread Tools Search this Thread
Old 06-10-2007, 10:06 AM   #1
Default Question on importing text from files


Hi I've been working on how to make my program manage to input 32 8-bit vectors in from one file (infile.txt) and write changed values into another file (outfile.txt). Here is the code that is relevant to file reading/writing:

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

entity quickSorter is
generic (infile : string := "infile.txt";
outfile : string := "outfile.txt");
end quickSorter;

architecture Behavioral of quickSorter is
begin
controller : process
variable tempData : std_logic_vector(7 downto 0);
variable tempString : bit_vector(7 downto 0);
variable sortArray : dataArray;
variable fresult : file_open_status := status_error;
variable tempLine : line;
file in_fd : text open read_mode is infile;
file out_fd : text open write_mode is outfile;
begin

--debug file processes
file_open (fresult, in_fd, infile, read_mode);
if (fresult /= OPEN_OK) then
assert false
report "usage: quickSort"
severity failure;
end if;
file_open (fresult, out_fd, outfile, write_mode);
if (fresult /= open_ok) then
assert false
report "usage: quickSort"
severity failure;
end if;

--read file
while (not endfile(in_fd)) loop
readline (in_fd, tempLine);
read (tempLine, tempString);
end loop;

--misc code
--code which generates conditions for
--the for loop underneath

--write file
for loop
write (tempLine, tempString);
writeLine (out_fd, tempLine);
end loop;

wait;
end process;
end Behavioral;

The entire program compiles correctly, syntax-wise.
However, the simulation always ends on the line after
file_open (fresult, in_fd, infile, read_mode);
which unfortunately means the file is incapable of being opened.
I have added two user document source files to the project (infile.txt and outfile.txt).
I have removed all code besides the relevant infile/outfile coding.
Could someone please help me fix the error?
Thanks for the assistance in advance.
In case of reference, this is run with Xilinx software in vhdl code.


boingboing
boingboing is offline   Reply With Quote
Old 06-21-2007, 06:12 PM   #2
scottcarl
Member
 
Join Date: May 2007
Location: USA
Posts: 51
Send a message via Yahoo to scottcarl
Default
The file_open command is not needed. Check out the subtle changes I made to your code to see how this works now. You have to place all the incoming data into an array (sortArray) and then write it back out. Generate a counter (v_count) that will tell you how many you read in and how many are needed to write out.

Code:
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; library STD; use ieee.std_logic_textio.all; use std.textio.all; entity quickSorter is generic (infile : string := "infile.txt"; outfile : string := "outfile.txt"); end quickSorter; architecture Behavioral of quickSorter is begin controller : process variable tempData : std_logic_vector(7 downto 0); variable tempString : std_logic_vector(7 downto 0); type dataArray is array(1 to 8) of std_logic_vector(7 downto 0); variable sortArray : dataArray; variable fresult : file_open_status := status_error; variable tempLine : line; variable v_count : integer := 0; file in_fd : text open read_mode is infile; file out_fd : text open write_mode is outfile; begin --read file while (not endfile(in_fd)) loop v_count := v_count + 1; readline (in_fd, tempLine); read (tempLine, tempString); sortArray(v_count) := tempString; end loop; --misc code --code which generates conditions for --the for loop underneath --write file for i in 1 to v_count loop write (tempLine, sortArray(i)); writeLine (out_fd, tempLine); end loop; wait; end process; end Behavioral;


scottcarl
scottcarl is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Video files to PSP ivan DVD Video 4 06-17-2008 11:16 AM
Convert Video files to MP4 for iPod ivan DVD Video 0 04-26-2006 08:38 AM
Very slow recognising DVD disc Terry Pinnell DVD Video 1 03-28-2006 06:53 PM
Now I introduce some popular software of multimedia eightsome@gmail.com DVD Video 0 03-28-2006 02:29 PM
quality and importing question MauiJNP DVD Video 4 01-12-2005 03:25 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46