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] Having trouble accessing all files in folder using VHDL textio library

Status
Not open for further replies.

logari84

Newbie level 6
Joined
Jul 15, 2015
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,452
Accesing all files in folder using VHDL textio library

Hi all,

for the project I am currently working on, I am using data from an input file. My design is almost done but I have tested it only with one input data file. Now I want to test it on all of the data files (~10000). In addition I want to make some statistics based on them. I am wondering if there is a way to switch from a constant name for the input file (51_303042564_0 in the example line that follows) to a variable name. Or if there is a way to access sequentially all the files in a folder. Apparently I couldn't find something on the web.

This is the way I am accessing the file "51_303042564_0"
file infile : t_char_file open read_mode is "51_303042564_0";

Thank you in advance.
 

Re: Accesing all files in folder using VHDL textio library

Yes. Vhdl had built in FILE_OPEN and FILE_CLOSE procedures, so you can have a string variable to create the file name and then open the file. If your filenames all have the same length, you can use a string. If the lengths are different, you need to use a line (which is a pointer to a string)

For example:


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
Variable fname :line;
 
For I in 1 to 100 loop
  write(fname, "" & "file"); -- instead of writing string'
 
  write(fname, integer'image(i));
 
  file_open(myfile, fname.all );
  deallocate(fname);  -- to clear the line before the next loop 
 
  -- do some stuff
End loop;

 
Re: Accesing all files in folder using VHDL textio library

Thank you very much. I don't actually understand what .all at fname.all does. But I managed to make it work. I didn't know that you can create one continuous string by concatenating some others. That, plus the integer'image() was the solution. Thank you again.
 

Re: Accesing all files in folder using VHDL textio library

the line type in VHDL is a pointer to a string:

type line is access string;

this means that the line variable stores the memory location of the string. To derefence the pointer, you use the .all field (like *ptr in C).

The problem with VHDL is that arrays need to have a defined length when you declare them. To have a variable length array you need to use a pointer to dynamically allocate space for them (hence the line type).
 
Re: Accesing all files in folder using VHDL textio library

Thank you very much. I don't actually understand what .all at fname.all does. But I managed to make it work. I didn't know that you can create one continuous string by concatenating some others. That, plus the integer'image() was the solution. Thank you again.

You can also dispense with the 'fname' variable completely as well as the calls to write and deallocate and simply do this...
Code:
for i in 1 to 100 loop
  file_open(myfile, "file" & integer'image(i));
  ...
end loop;

Kevin
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top