Dan M
New Member
Offline
Posts: 3
|
I'm kind of stumped on this one, the file handling facilities in VerilogA seem to be quite poor. I poured through the manual, and also did a search on Cadence community and found one person asking the same question and got no response, so here goes:
I want to determine if a file exists and read it in if it does, and write one if it doesn't.
I tried integer filehandle filehandle=$fopen("filename","r");
However, if filename doesn't exist, it fatal errors and that's the end.
The other thought I had was to open it for append and then close it, and then re-open it for read. The theory is that if it does exist, opening it for append will not affect it. If it doesn't, it'll create it as a 0 byte file and now I can open it for read, attempt to read it, get an immediate $feof(filehandle) and then determine its of 0 bytes, and I can close it and re-open it for write. The problem is, VerilogA complains (fatal errors) if you try to re-open a file you already opened, so you get one shot at it. So this doesn't work either.
Is there anyway to detect if a file exists without fatal erroring? Or if not, is there a way to "trap" the error so that I can decide based on the presence of an error what to do next?
|