The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 20th, 2024, 5:54am
Pages: 1
Send Topic Print
How to detect if a file exists in VerilogA (Read 41 times)
Dan M
New Member
*
Offline



Posts: 3

How to detect if a file exists in VerilogA
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?
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.