Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

reading integer values representing an image from file

hii..

i'm trying to read ".txt" file representing an image, contains integer value like that..

0 0 0 0 23 163 145 149 154 154 154 155 155 156 156 156 158 158 158 158 158 158 158 ......150 149 149 148 148 148 148 151 143 139 140 102 0 0

0 0 0 0 23 163 145 149 154 154 154 155 155 156 156 156 158 158 158 158 158 158 158 ......150 149 149 148 148 148 148 151 143 139 140 102 0 0

0 0 0 0 23 163 145 149 154 154 154 155 155 156 156 156 158 158 158 158 158 158 158 ......150 149 149 148 148 148 148 151 143 139 140 102 0 0

0 0 0 0 23 162 145 149 154 154 154 155 155 156 156 156 158 158 158 158 158 158 158 ......150 149 149 148 148 148 148 151 143 139 140 102 0 0

.......

...........

..........

0 0 0 0 0 158 136 128 141 141 141 141 141 141 141 142 144 144 144 144 144 144 144 .......140 140 140 140 140 140 143 139 125 141 129 106 0 0

0 0 0 0 0 143 136 134 136 136 136 136 136 136 136 138 142 142 142 142 142 142 142 .......140 140 140 140 140 140 140 140 130 141 129 104 0 0

0 0 0 0 0 147 139 126 140 140 140 140 140 140 140 141 141 141 141 141 141 141 141 .......140 140 140 140 140 140 141 143 136 134 127 102 0 0

0 0 0 0 0 148 132 134 140 140 140 140 140 140 140 141 138 138 138 138 138 138 138 .......135 135 135 135 135 135 129 135 135 132 133 106 0 0

0 0 0 0 0 143 113 137 141 141 141 141 141 141 141 142 145 145 145 145 145 145 145 .......137 137 137 137 137 137 136 139 136 128 130 102 0 0

0 0 0 0 0 149 118 123 137 137 137 137 137 137 137 139 145 145 145 145 145 145 145 .......132 132 132 132 132 132 123 130 129 126 126 94 0 0

0 0 0 0 14 129 129 123 136 136 136 136 136 136 136 138 139 139 139 139 139 139 139 .......0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ....... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

but whenever i start simulation i got this warning : )TEXTIO procedure READ(INTEGER) : Parameter L designates an empty string)

hence it is not the estimated output

i thought i was getting this warning since the entire data is integer and i'm declaring my file like this

(file testing_read: text open read_mode is "abc.txt" )

so i changed it to be like that

(

type integer_file is file of integer;

....

file testing_read: integer_file open read_mode is "abc.txt";

)

after which i got this error when compiling: (No feasible entries for subprogram "READLINE".)

I would be so happy for your reply..

thanks,

Niveen..

9 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You cant use readline with a file of type integer, because its only defined for text files. And you woudnt want to do that anyway, because a file of integers is not a text file but a data file, so there is no "line" to speak of.

    Anyway, you havent shown your code that reads from the text file. The problem will be your code, not the data file.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    so should i change file extension to .dat instead of .txt or what??

    here is my process

    if (rising_edge(clk)) then

    if rst = '1' then

    eog_sig <= '0';

    else--rst

    while (col_s < starting_line_col) loop

    if(NOT(endfile(testing_read))) then

    READLINE(testing_read, my_line_read);

    else

    eog_sig <= '1';

    end if;

    col_s := col_s + 1;

    end loop;

    col_e := col_s;

    while col_e < (ending_line_col+1) loop

    if(NOT(endfile(testing_read))) then

    READLINE(testing_read, my_line_read);

    READ(my_line_read, s);

    end if;

    while (row_s < starting_line_row) loop

    READ(my_line_read, s);

    row_s := row_s + 1;

    end loop;--row_s < starting_line_row

    row_e := row_s;

    row_s := 1;

    while row_e < (ending_line_row+1) loop

    READ(my_line_read, s);

    row_e := row_e + 1;

    x := x+s;

    i := i+1;

    end loop;

    col_e := col_e + 1;

    end loop;

    results := x/i;

    x := 0;

    i := 1;

    resultd_out <= To_StdLogicVector(results,N) ;

    col_s := 1;

    col_e := 1;

    row_s := 1;

    row_e := 1;

    end if;--rst

    end if;--clk

    Note:

    starting_line_col, starting_line_row, ending_line_col, ending_line_row are input integer values representing a rectangular area of x,y,width,height from which i select certain area to calculate its avarage

    sorry for my lazy code..

    execuse me cause i'm totally new in that field..

    willing to write smart code next time...

    thanks for your patiance..

    Niveen
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    renaming it .dat wont make a difference - it will still be a text file. You would have to regenerate the file writing the values direct to 32 bits rather than text values.

    The error is becuase you have read in an empty line, or you're trying to read past the end of a line. are you sure you have all the dimensions correct?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    actually, its even simpler than that. You're reading the entire file in a single clock cycle. so on the next clock, you've got an empty file. you need to read 1 value per clock cycle, not all of them!

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks alot.. i got your point.. :)

    i'm having one more question -->can i restart reading the same file in the same clock cycle...

    Thanks,

    Niveen..
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    yes you can. use the procedures:

    FILE_CLOSE(my_file);

    FILE_OPEN(my_file);
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thanks Tricky sooo much

    i wrote --> FILE_OPEN(testing_read);

    befor --> if(NOT(endfile(testing_read)))

    and FILE_CLOSE(testing_read); at the end

    but i got this error (No feasible entries for subprogram "file_open".)

    i want to finish reading the file every clk thats why i'm using a while loop and in the next clock the input values change so i want to re-read the same file again with the new rectangular area...

    what should i do then..

    i really appreciate your help alot..

    thanks your patiance,

    Niveen
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i got that file_open should be like that --> FILE_OPEN(testing_read,"abc.txt",read_mode);

    i placed it after (else of rst)

    i also defined these two lines

    line 1-->type f_read is file of text;

    line 2-->file testing_read: f_read;

    and i'm still having this error

    No feasible entries for subprogram "READLINE".

    either i wrote integer or string instead of text in line 1

    i don't know where is the problem.. :(

    thanks alot,

    Niveen..
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    its working now :)

    i replaced line 1 & line 2 by --> file testing_read : text;

    file_open() on its place @ the begining and file_close() at the end...

    Niveen..