Hi guys,its my first time here in this forum.Firstly,nice to meet you all.I would like to request help for my assignment as I am having difficulties at one part of my assignment. I am trying to read from a file that has 3 columns,and I only need the middle column,So I declared 2 extra variables to store the left and right column while another variable(for my input)is used for the middle column.Attached is my input file and below is my code(reading part).Any help is greatly appreciated and thanks for taking your time to read my post. Input ________ 00002180 F31834C2BB6DE27A U5dªÎy)¨VÔRðfÏ,§ 00002190 2F3BED3B8FCDCA36 ó0B”Œ„ B.„ 000021A0 01A70C2A1064D71A B.„ B.„ ” 000021B0 9142F343EAD0CC86 JD B.„ B.„ 000021C0 4C640F3EB318FDAE B.„ B.„ 0FC48AEBAB655950 670F0E5568CC9F1A D8004E3FF2165382 694AF9ABFBB52758 Code ________________ process use std.textio.all; use ieee.numeric_std.all; file inputfile:text open read_mode is "input8.txt"; variable ipa:std_logic_vector(63 downto 0); variable ipb:std_logic_vector(63 downto 0); variable inline:line; variable ipc:character; begin while not(endfile(inputfile))loop readline(inputfile,inline); hread(inline,ipa); --data_in<=ipa; hread(inline,ipb); data_in<=ipb; read(inline,ipc); --data_out2<= std_logic_vector(to_unsigned(character'pos(ipc),data_out2'length)); wait for 800 ns; end loop; wait; end process;
: Edited by User
Miller Jackson wrote: > I am trying to read from a file And whats the problem with that? I have a kind of a deja vu with the thread https://embdev.net/topic/321964 Is this the same exercise?
: Edited by Moderator
I am using modelsim,and when I stimulate the code,It shows the input as 000000...,I believe this happened because halfway through the input file,The left and right column is empty while the middle column(The input that I want)is continuing,I tested by using the left Column as my input and just store the other 2 columns(middle,right)into variables and it works. So was wondering if it is possible to read the middle column although the other two columns are empty? That looks similar to my assignment too,just that my input file is much longer and the left/right columns goes empty through halfway of the input file Thanks for reading and looking forward to your reply!
Hi, Maybe this will be useful. There are few assumptions regarding the input file syntax. Seems to work ok with yours input8.txt .
entity tb is end; architecture arch of tb is begin process use std.textio.all; use ieee.numeric_std.all; file OFile:text open read_mode is "input8.txt"; file OFile2:text open write_mode is "output.txt"; variable OLine : line; variable OLine2 : line; variable temp_str : string(1 to 26); variable what : boolean:= false; begin while not(endfile(OFile))loop readline(OFile,OLine); read (OLine, temp_str,what); -- to skip empty lines if what then -- report temp_str(10 to 26); write(OLine2, temp_str(10 to 26)); writeline(OFile2,OLine2); end if; end loop; file_close(OFile); file_close(OFile2); report "hello"; wait; end process; end;