End-to-end verification of the Verilog-AMS string-formatting and file-reading
system functions implemented in Enhancement-11 (the counterparts to the
file-output set in ../fileio_examples/), using version11's own openvaf-r
and ngspice-46.
Functions covered: $swrite, $sformat, $sscanf, $fgets, $fscanf,
$ferror.
| File | Purpose |
|---|---|
stringio_demo.va |
Formats strings ($sformat/$swrite), parses a literal ($sscanf), round-trips a file read ($fgets/$fscanf over a file it wrote itself), queries $ferror, and writes a report. |
verify_stringio.py |
Runs a .op and checks the report against expected values. |
stringio_out.txt, _sio.cir, *.osdi |
Artifacts. |
python3 verify_stringio.py
Expected tail:
ALL PASS (6/6)
sformat=[R=1000 G=0.001]
swrite=[n= 5 ok]
sscanf=3 42 3.14 [hello]
fgets=13
fscanf=2 99 2.5
ferror=0 []
$sformat/$swriteformat into a string variable ($swriteconcatenates like$write).$sscanf("42 3.14 hello", ...)parses an int / real / string and returns the match count (3).$fgetsreads the line"line seven 7\n"back from a file (length 13, including the newline).$fscanfparses"99 2.5"from a file (count 2).$ferroron a good descriptor returns code 0 and an empty message.
The scanner parses each field by the destination variable's type (int via
strtol, real via strtod, string as the next whitespace-delimited token)
rather than by interpreting the C format string — adequate for the usual
whitespace-separated input. As with the file-output functions, keep string/file
I/O parameter/setup-derived so it runs once in the model's initialization code
(see ../Enhancement-11.md §1.3, §6).