Entering unknown number of real numbers

Hi
I need to be able to enter an array of real numbers as parameters to my SV code.
I can provide the number of elements as well. What would be the best way to do this?
Thanks

I can think of at least two options

  1. write a script converting the array to SystemVerilog syntax
  2. use $fscanf

Thanks Dave. Could you please make an example of what you have in mind?

Suppose you have this list of real numbers

list_reals.txt

0.1
2.3
4.5
6.7
8.9

Then you could write a script to convert that list to SystemVerilog

const real array_of_reals[] = {
0.1,
2.3,
4.5,
6.7,
8.9
};

And then `include "list_reals.sv" that file into your source code where needed.

To use $fscanf

module top;
  int FD;
  int num_elements,code;
  real array_of_reals[];
  initial begin
    FD = $fopen("list_reals.txt","r");
    if($value$plusargs("num_elements=%d",num_elements) && num_elements > 0) ;
      else $fatal(0, "num_elements not set");
    array_of_reals = new[num_elements];
    foreach(array_of_reals[i]) begin
      if ($fscanf(FD, "%g",array_of_reals[i]) != 1) $fatal(0,"not enough elements to read");
      $display("array_of_reals[%0d] = %g", i, array_of_reals[i]);
    end
  end
endmodule

Instead of using $value$plusargs, you could also put the number of elements as the first number in the file.