In reply to Neddy:
Hi this is a description on how to read from binary files. It has some examples on how to use EOF. I hope it helps.
Below the example for reading from a binary file with systemverilog.
As shown in IEEE SV Standard documentation, the "nchar_code" will return the number of bytes/chars read. In case EOF have been already reached on last read this number will be zero.
Please, notice that "nchar_code" can be zero but EOF has not been reached, this happens if you have spaces or returns at the end of the data file.
You can control the number of bytes to be read with the $fread function call ("nchar_code"). This is done with the type definition of the "data_write_temp". If the "data_write_temp" variable is 16bits long then it will read 16bits each time the $fread is called. In case, "data_write_temp" is 32bits as in the example, the $fread will read nchar_code=4bytes(32bits). You can also define an array and the $fread function will try to fill that array.
Lets define a multidimensional array mem.
In the example word contents, wzyx,
The file will be structure as below (notice @z shows the z dimension blocks):
In the previous structure, the numbers shows the index of each dimension.
e.g. w048 means, the word w (32bits) value on index z =0, index y= 4 and index x= 8.
Now, you have many ways to read this.
You can read all in a **single shot** using the type "mem" declared above, or you can do a while loop until EOF reading pieces of 32bits using a "data_write_temp" variable of 32bits. The loop is interesting if you want to do something some checks for every word piece and you are not interested having a memory value.
In case multidimensional array / single shot read is chosen, then you can either use $fread or use an specific function $readmemh defined in SV standard.
is equivalent to
The $readmemh spare you the need to open/close the file.
If you use $fread for one shot read
- Is Peter Frampton considered a good guitarist
- Is black and white better than colour
- What is wrong with Bermuda
- Are immigrants beneficial to the U S
- Are data analysts in demand
- How are votes converted into a percentage
- Are disturbing and intrusive thoughts normal
- How do I become an economical person
- How I get order in Fiverr 1
- Are kids going to be supervised forever
- Is data mining a solved closed topic
- What is your max bench press
- When was the first lighthouse built
- What can cause pain in your coccyx
- Why does my refrigerator make Frankenstein noises
- What is tan 1 sqrt 2
- What are the thugs of India
- How would Jesus have sex