Home > Community > Forums > PCB SKILL > $fread to read the text file into an array.

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 $fread to read the text file into an array. 

Last post Tue, Jan 15 2008 2:45 AM by archive. 0 replies.
Started by archive 15 Jan 2008 02:45 AM. Topic has 0 replies and 1288 views
Page 1 of 1 (1 items)
Sort Posts:
  • Tue, Jan 15 2008 2:45 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    $fread to read the text file into an array. Reply

    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<= imgSize;i++) begin
                        $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
    • Post Points: 0
Page 1 of 1 (1 items)
Sort Posts:
Started by archive at 15 Jan 2008 02:45 AM. Topic has 0 replies.