The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> How to detect if a file exists in VerilogA
https://designers-guide.org/forum/YaBB.pl?num=1476553607

Message started by Dan M on Oct 15th, 2016, 10:46am

Title: How to detect if a file exists in VerilogA
Post by Dan M on Oct 15th, 2016, 10:46am

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?  

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.