vipin
vipin

Reputation: 1660

How to write real data type into a file in VHDL?

I have 2 D matrix type in my VHDL code with all elements being "real" type.

Something like this:

type type1 is array (1 to 50,1 to 50) of real;

Now I want to write this whole matrix into a text file.Each row should be written in a line separated by a comma How can I do that?

I looked into the textio package, but not sure how to use them for the real data type.

Is there any custom package for this?

Upvotes: 0

Views: 2690

Answers (3)

pico
pico

Reputation: 1910

From std.Textio.all package

library std;
use std.textio.all;

--Write real
procedure write(
    L         :inout line; 
    value     :in    real;
    justified :in    side    := right; 
    field     :in    width   := 0;
    digits    :in    natural := 0
);

Upvotes: 0

Martin Thompson
Martin Thompson

Reputation: 16812

Start using textio

use textio.all;

a couple of useful variables:

    variable s : line;
    file output : text;

the main code goes something like this:

    for y in image1'range(2) loop
      for x in image1'range(1) loop
        write(s,real'image(image1(x,y));
      end loop;
      writeline(output,s);
    end loop;

I'll leave you to add in your comma delimiters and any header/footer you need.

Upvotes: 2

mouviciel
mouviciel

Reputation: 67849

Have you checked real'image(value) for obtaining a string representation of a real value ?

Upvotes: 2

Related Questions