$readmemh -- is there something better?

In reply to dave_59:

This almost worked. With $fscanf() as a while loop argument, the while loop hung. This tweak worked…

typedef bit [15:0] uint16_t;
  typedef uint16_t uint16q_t[$];
  uint16q_t gain_offset_queue; 

  function automatic uint16q_t get_file_lines(string file_name);
      int fd;
      uint16_t value;
      uint16q_t ret;
      int line_num = 0;


      fd = $fopen(file_name, "r");
      if (fd)  begin
          $display("File %s was opened successfully", file_name);
          while (!$feof(fd)) begin
              $fscanf(fd, "%x", value);
              ret.push_back(value);
              if (line_num < 10) begin
                $display ("Line[%04d]: 0x%04X", line_num++, ret[ret.size()-1]);
              end
          end
      end else begin     
          $display("File %s was NOT opened successfully", file_name);
      end

      $fclose(fd);
      return ret;
  endfunction : get_file_lines

Any idea why $fscanf as a while loop argument didn’t work?

Another interesting side note. Check out the $dsiplay and note the capital X in 0x%04X. The output looks like this:

File …/…/tb/raw_proc/c_model/output/grid.mem was opened successfully

Line[0000]: 0x00ca

Line[0001]: 0x00ac

Line[0002]: 0x00dc

Line[0003]: 0x0108

Line[0004]: 0x010a

Line[0005]: 0x0136

Line[0006]: 0x015e

Line[0007]: 0x0174

Line[0008]: 0x0146

Line[0009]: 0x015c

Why are the a-f characters not capitalized? I am using questa 10.7c.

Thanks!
Aaron