Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > 2 D array initialization

Reply
Thread Tools

2 D array initialization

 
 
mk.supriya@gmail.com
Guest
Posts: n/a
 
      07-25-2007
hello,
can anyone tell me how to read from / write to a 2D array from a file?

 
Reply With Quote
 
 
 
 
KJ
Guest
Posts: n/a
 
      07-25-2007

<> wrote in message
news: oups.com...
> hello,
> can anyone tell me how to read from / write to a 2D array from a file?
>

By writing your own procedure that reads from / writes to each element one
at a time.

KJ


 
Reply With Quote
 
 
 
 
mk.supriya@gmail.com
Guest
Posts: n/a
 
      07-25-2007

> By writing your own procedure that reads from / writes to each element one
> at a time.
>
> KJ


i am not able to access the elements, every type of assignment i make
i get an error

 
Reply With Quote
 
Jonathan Bromley
Guest
Posts: n/a
 
      07-25-2007
On Wed, 25 Jul 2007 05:08:24 -0700, wrote:

>i am not able to access the elements, every type of assignment i make
>i get an error


How can anyone possibly help you from this non-description?
*I* can access the elements of a 2-D array, and do so routinely.
There is no fundamental problem. Show us a code fragment and
we'll try to help with YOUR problem.

A few guesses...
- you're using the wrong kind of double-subscript:
depending on how you defined the array, you may need
to use subscripts like (row,column) or (row)(column)
- the array is a signal, and you are trying to pass
elements of it to the READ procedures; those
procedures expect variables
Without seeing your code and the error message, these
can only be guesses.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK

http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Reply With Quote
 
mk.supriya@gmail.com
Guest
Posts: n/a
 
      07-25-2007
> How can anyone possibly help you from this non-description?
> *I* can access the elements of a 2-D array, and do so routinely.
> There is no fundamental problem. Show us a code fragment and
> we'll try to help with YOUR problem.
>
> A few guesses...
> - you're using the wrong kind of double-subscript:
> depending on how you defined the array, you may need
> to use subscripts like (row,column) or (row)(column)
> - the array is a signal, and you are trying to pass
> elements of it to the READ procedures; those
> procedures expect variables
> Without seeing your code and the error message, these
> can only be guesses.
> --
> Jonathan Bromley, Consultant
>
> DOULOS - Developing Design Know-how
> VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
>
> Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
> jonathan.brom...@MYCOMPANY.comhttp://www.MYCOMPANY.com
>
> The contents of this message may contain personal views which
> are not the views of Doulos Ltd., unless specifically stated.

hello,
when i ran the following code, it assigns 1 to each and every element
in the array tout.
instead of write(my_file,'1'), suppose i have defined an array of
bit_vector(0 to 7) if i give write(my_file,x"04") it gives fatal error
in XST
package arr is
type row is array (0 to 7) of character;
type mat is array (0 to 7) of row;
end arr;

use work.arr.all;

entity arrfile is
port ( tout: out mat);
end arrfile;

architecture ARCH of arrfile is
begin
process is
type ch_file is file of character;
file my_file : ch_file;
constant file_name : string := "testfile4.txt";
--constant matrix : mat := ((0,1) => 'a', (1,0)=> 'c', others => '0');
variable my_char : character;
begin
file_open(my_file, file_name, write_mode);
for i in 0 to 7 loop
for j in 0 to 7 loop
write(my_file, '1');
end loop;
end loop;
file_close(my_file);
wait for 2 ns;
file_open(my_file, file_name, read_mode);
for i in 0 to 7 loop
for j in 0 to 7 loop
read(my_file, my_char);
tout(i)(j) <= my_char;
end loop;
end loop;
file_close(my_file);
end process;
end ARCH;

 
Reply With Quote
 
mk.supriya@gmail.com
Guest
Posts: n/a
 
      07-25-2007
is bit_vector(0 to 7)not equivalent to character?
if i define the file as a file of characters, why am i not able to get
data into a bit_vector?



 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      07-25-2007
wrote:
> is bit_vector(0 to 7)not equivalent to character?


No.
character is a scaler type.
bit vector is an array type.

> if i define the file as a file of characters, why am i not able to get
> data into a bit_vector?


I could write a function to make such a conversion.
Here is a related example:

function int2sgn (arg : integer) return signed is
subtype vec_t is signed(127 downto 0);
variable arg_v : vec_t := to_signed(arg, vec_t'length);
constant min_c : natural := min_len_sgn(arg);
subtype this_sgn_t is signed(min_c -1 downto 0);
begin
return arg_v(this_sgn_t'range);
end function int2sgn;

Details here:
http://home.comcast.net/~mike_treseler/

-- Mike Treseler
 
Reply With Quote
 
Nicolas Matringe
Guest
Posts: n/a
 
      07-25-2007
a écrit :

> hello,
> when i ran the following code, it assigns 1 to each and every element
> in the array tout.
> instead of write(my_file,'1'), suppose i have defined an array of
> bit_vector(0 to 7) if i give write(my_file,x"04") it gives fatal error
> in XST


Hi
So you are tring to *synthesize* this ? No wonder it doesn't work, I
don't know of *any* synthesis tool that supports file access.

Nicolas
 
Reply With Quote
 
mk.supriya@gmail.com
Guest
Posts: n/a
 
      07-26-2007

>
> Hi
> So you are tring to *synthesize* this ? No wonder it doesn't work, I
> don't know of *any* synthesis tool that supports file access.
>
> Nicolas


no i wasnt synthesising it, i was simulating using xilinx simulator,
thanks to Mr Mike and Mr.Jonathan i now have an idea as to what to do.
thanks again

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
initialization of array as a member using the initialization list aaragon C++ 2 11-02-2008 04:57 PM
array initialization in initialization list. toton C++ 5 09-28-2006 05:13 PM
Initialization of non-integral type in initialization list anongroupaccount@googlemail.com C++ 6 12-11-2005 09:51 PM
Initialization via ctor vs. initialization via assignment Matthias Kaeppler C++ 2 07-18-2005 04:25 PM
Default Initialization Vs. Value Initialization JKop C++ 10 09-22-2004 07:26 PM



Advertisments
 



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 47 48 49 50 51 52 53 54 55 56 57