The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl Design Languages >> Verilog-AMS >> Reading strings from a file in VerilogA https://designers-guide.org/forum/YaBB.pl?num=1376423154 Message started by luxmee on Aug 13th, 2013, 12:45pm |
Title: Reading strings from a file in VerilogA Post by luxmee on Aug 13th, 2013, 12:45pm I have a text file which looks like this: x=1,y=2,z=3 'This is a comment x=3,y=4,z=5 x=6,y=7,z=8 'Last line I'm trying to read the file in VerilogA(values of x,y & z) and I want to ignore the comments. I tried using the fscanf function file = $fopen("myfile.txt","r"); $fscanf(file,"x=%d,y=%d,z=%d%s",int1,int2,int3,str1); But this doesn't work, it works as far the syntax goes but when I run my testbench, it gives me a fatal error saying "Format string in $fscanf doesn't match input file/string". I also tried a combination of fgets and then sscanf but that doesn't work either. Does anyone know how to do this? |
Title: Re: Reading strings from a file in VerilogA Post by Marq Kole on Aug 15th, 2013, 7:38am I've been able to get $fscanf to work but it is very picky - especially strings are a nuisance. Apparently a string is any character string delimited by whitespace, so if your comments include whitespace $fscanf won't work. On the other hand, the amount of whitespace does not matter - one space in the format string can match any number of spaces/tabs in the actual file, as long as it relates to a single line. What I've found is that $fscanf reads complete lines and then tries to match the line to the format string. Please find below a Verilog-A module definition and a text input file that at least works with the analog simulators of a few different vendors. It is a file-driven sine-wave source. All lines in the input file have to be present and have to be in the given order. Code:
And the file that is read through these $fscanf call has these contents: Code:
Hope this helps. Cheers, Marq |
The Designer's Guide Community Forum » Powered by YaBB 2.2.2! YaBB © 2000-2008. All Rights Reserved. |