Search code examples
filevhdl

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?


Solution

  • 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.