# Forum: FPGA, VHDL & Verilog handling two dimensional array using vhdl

 Author: Sanghamitra D. (Company: education) (sanghamitra6) Posted on: 2016-09-07 22:23

Rate this post
 0 ▲ useful ▼ not useful
i have a two dimensional array in a text file. i want to read it from
the text file and write it in another text file as a two dimensional
array. i have tried using the code given below. but it writes only one
column. how to write all the columns.
 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 "bit8.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 "bit8_inv.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; 

: Edited by Moderator
 Author: Lothar M. (lkmiller) (Moderator) Posted on: 2016-09-08 06:58

Rate this post
 0 ▲ useful ▼ not useful
Sanghamitra D. wrote:
> i have a two dimensional array in a text file. i want to read it from
> the text file and write it in another text file as a two dimensional
> array.
So, why not simpy copy one file to the other? This is, what you are
doing here:
 read(inline, dataread1); dataread <=dataread1; --put the value available in variable in a signal. : : write(outline, dataread, right, 16, 12); 
So, at best those two files may be the same afterwards...

> how to write all the columns.
A text file itself is only linear memory. There no second dimension in a
text file. There may be some kind of restrictions (line length or
carriage returns) to mark a second or more dimensions.

> i have a two dimensional array in a text file.
How does that input text file look like? What ware the two dimensions in
it? What should happen to those two dimensions? How should the output
file look like?

 Author: Achim S. (Guest) Posted on: 2016-09-08 08:25

Rate this post
 0 ▲ useful ▼ not useful
I think your main problem can be understood from this comment:

Sanghamitra D. wrote:
> --reading the data from the line and putting it in a real type variable.

Probably every line of your file contains several real numbers as
give you several real numbers. But you interprete and store each line as
a single real number.

All the remaining numbers in that line (i.e. all the remaining columns)
get lost. You cannot store a sequence of real numbers in a single real
type variable.

• $formula (LaTeX syntax)$