• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. $fread to read the text file into an array.

Stats

  • Replies 0
  • Subscribers 158
  • Views 12434
  • Members are here 0
More Content

$fread to read the text file into an array.

archive
archive over 17 years ago

Hi,

I need some help with file read. Here's the problem statement.

I want to read an file at runtime which will give me the size of the image and the actual data into an dynamic array, imgData.
I tried to use the code below, but i get the wrong result.

Can i use $readmemh system tasks to perform the same operation? This should give me the exact file size and i don't want an arbitrary size array, since i'll be packing the data and passing it over an interface.


  int imgSize, status;
  rand image_type imgType;
  reg [7:0] imgData [];


  task read_image;
    integer file, start, count;
    reg [7:0] mem[0:200_000] ;
    begin
        case (imgType)
       YUV422 : begin
                file = $fopen("YUV422.txt","rb");
                if (file != 0) begin
                   $display("Error Opening YUV422 File.");
                 $finish;
                 end // if (file
                imgSize = $fread(mem,file);
                imgData = new[imgSize] (mem);
                $display("Number of Elements in Image = ",imgSize);
                for(int i=0; i
                    $display("Data at Locatin [%h] is %h", i, imgData[i]);
                $fclose(file);
         default: $display("No Where!");
         endcase
      end
endtask


Originally posted in cdnusers.org by prasad_vc
  • Sign in to reply
  • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information