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] how to determine the size of a file? VHDL

Status
Not open for further replies.

linuxunil

Newbie level 3
Joined
Jun 17, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
I need to check if two files are identical.


I need to avoid this:
# ** Fatal: (vsim-3336) Attempt to read past the end of file

this error happens when it reads files that are different because they have different sizes.

At the moment, I want to insert a block that checks the file size, because if it is different i no longer need to see the rest.

But what i do?:cry:
 

there is no way to do this easily in VHDL. VHDL is not set up to do File io nicely other than text.

What file are you trying to read? For every file you can use the ENDFILE() function to see if you have reached the end of a file:

eg.
Code:
while not ENDFILE(my_file) loop
  readline(file, inline);
  ...etc
end loop;

You could use this loop method to count the number of lines in a text file, or if you are using modelsim you can do this with bytes in a binary file, but its not very neat.

Otherwise, I suggest you make sure all your files are the same length before you try and read them.
 

there is no way to do this easily in VHDL. VHDL is not set up to do File io nicely other than text.

What file are you trying to read? For every file you can use the ENDFILE() function to see if you have reached the end of a file:

eg.
Code:
while not ENDFILE(my_file) loop
  readline(file, inline);
  ...etc
end loop;

You could use this loop method to count the number of lines in a text file, or if you are using modelsim you can do this with bytes in a binary file, but its not very neat.

Otherwise, I suggest you make sure all your files are the same length before you try and read them.

I want to compare any two files to see if they are exactly alike. I already knew "ENDFILE." The problem happens when the files were different and therefore have different sizes.

I found a simple solution:

while not (ENDFILE (file1)) loop
read (file1, buff1);

if not (ENDFILE (file2)) then
read (file2, buff2);
end if;
end loop;

so it will read the entire file1, but if he reaches the end of file2 before, buffer2 will contain only the last part of file2. and so I can know if there are differences between the files through a variable that I use.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top