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:`include "disciplines.vams"
`include "constants.vams"
module vfile (out, gnd);
parameter string fname = "vfile.ctrl";
inout out, gnd;
electrical out, gnd;
real amp, offset, freq, phase;
integer fp, n_items;
analog begin
@(initial_step) begin
fp = $fopen(fname, "r");
`ifdef __TIBURONDA__
n_items = n_items + $fscanf(fp, "Amp = %g\n", amp);
n_items = n_items + $fscanf(fp, "Offset = %g\n", offset);
n_items = n_items + $fscanf(fp, "Freq = %g\n", freq);
n_items = n_items + $fscanf(fp, "Phase = %g\n", phase);
`else
$fscanf(fp, "Amp = %g", amp);
if (amp) n_items = n_items + 1;
$fscanf(fp, "Offset = %g", offset);
if (offset) n_items = n_items + 1;
$fscanf(fp, "Freq = %g", freq);
if (freq) n_items = n_items + 1;
$fscanf(fp, "Phase = %g", phase);
if (phase) n_items = n_items + 1;
`endif
$display("Read %d specifications", n_items);
$display(" Amp = %g", amp);
$display(" Offset = %g", offset);
$display(" Freq = %g", freq);
$display(" Phase = %g", phase);
$fclose(fp);
end // initial_step
V(out, gnd) <+ offset + amp * sin(`M_TWO_PI * freq * $abstime + `M_PI * phase / 180);
end
endmodule
And the file that is read through these $fscanf call has these contents:
Code:Amp = 0.5
Offset = 0.5
Freq = 1.2e+06
Phase = 45
Hope this helps.
Cheers,
Marq