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.

[SOLVED] TEXTIO procedure READ(INTEGER)

Status
Not open for further replies.

electronical

Advanced Member level 4
Joined
Nov 4, 2011
Messages
104
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
1,975
read input from txt file

Hello.I download this code from internet and run it in modelsim ,I dont khow why cant read input from file
Code:
--include this library for file handling in VHDL.
library std;
use std.textio.all;  --include package textio.vhd

--entity declaration
entity filehandle is
end filehandle;

--architecture definition
architecture Behavioral of filehandle is
--period of clock,bit for indicating end of file.
signal clock,endoffile : bit := '0';
--data read from the file.
signal    dataread : real;
--data to be saved into the output file.
signal    datatosave : real;
--line number of the file read or written.
signal    linenumber : integer:=1; 

begin


clock <= not (clock) after 1 ns;    --clock with time period 2 ns


--read process
reading :
process
    file   infile    : text is in  "1.txt";   --declare input file
    variable  inline    : line; --line number declaration
    variable  dataread1    : real;
begin
wait until clock = '1' and clock'event;
if (not endfile(infile)) then   --checking the "END OF FILE" is not reached.
readline(infile, inline);       --reading a line from the file.
  --reading the data from the line and putting it in a real type variable.
read(inline, dataread1);
dataread <=dataread1;   --put the value available in variable in a signal.
else
endoffile <='1';         --set signal to tell end of file read file is reached.
end if;

end process reading;

--write process
writing :
process
    file      outfile  : text is out "2.txt";  --declare output file
    variable  outline  : line;   --line number declaration  
begin
wait until clock = '0' and clock'event;
if(endoffile='0') then   --if the file end is not reached.
--write(linenumber,value(real type),justified(side),field(width),digits(natural));
write(outline, dataread, right, 16, 12);
-- write line to external file.
writeline(outfile, outline);
linenumber <= linenumber + 1;
else
null;
end if;

end process writing;

end Behavioral;


i used this number in 1.txt
12.00
13.00
 
Last edited:

Where you live people don't use error messages? Anyways, try to use the full paths for those filenames and see if that helps.
 

Sorry !!!,what is your mean?
thanks for any help,but ...
 
Last edited:

What I mean is.

a) if something doesn't work + you get an error message and you want help from other people, then it is useful to provide the actual error message.

b) if it fails because it cannot find the file, then it helps to use the full path for where the hell it can find the file. In other words, do not use "1.txt". Do use "C:\somedir\somesubdir\1.txt" instead on windows, or "/somedir/somesubdir/1.txt" on linux.

Because ...

c) due to lack of provided details people will just have to guess what "I dont khow why cant read input from file" translates to. I guess you mean something like file not found, but who the hell knows. If you just provide error messages ==> less guessing, more information.
 
I use the full path ,there is no error message
 

Well, if you get no error message then I guess "it works".

Care to provide any details to what you feel it should be doing, in contrast to what it is actually doing? Otherwise you'll be random-internet-dude number 3497345 with poorly described problem #87634.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top