Reading different data on a single line from file in VHDL - file

Supposing I've got a file filled with data separated by a tabulation (in this format):
1 2
3 4
5 6
and I'd like to read these data in pairs from a single line, so that result would be as follows:
var1=1;
var2=2;
var1=3;
var2=4;
var1=5;
var2=6;
How am I supposed to work? Right now my code works for a single data on a single line (see following):
read_from_file: process(clk)
variable input_data: natural;
variable ILine: line;
begin
for i in 0 to NSAMPLES-1 loop
readline (input_vectors, ILine);
read(ILine, input_data);
end loop;
end process;
Thank you for helping!

You should be able to call the read function again.
For example:
read_from_file: process(clk)
variable input_data_column1: natural;
variable input_data_column2: natural;
variable ILine: line;
begin
for i in 0 to NSAMPLES-1 loop
readline (input_vectors, ILine);
read(ILine, input_data_column1);
read(ILine, input_data_column2);
-- Now you can do things like conv_std_logic_vector(input_data_column1, bitwidth) etc
end loop;
end process;
Note: I am not positive if any whitespace will be accepted. Spaces have worked for me.

Related

Different results on printing the values of array

I am writing a stored procedure that accepts a string as an input and then converts that string to an array with comma as a delimiter, once I have that array I am appending a string '_1' to each element of the array as I need to further utilize that. However when I execute this stored proc to find the result the raise info command behaves differently on printing the value of array (the values will change obviously but the format in which they are displayed changes)
CREATE OR REPLACE FUNCTION Test1(inputlist text) RETURNS text AS $BODY$
DECLARE
a text;
acceptList text[];
counter integer;
length integer;
BEGIN
acceptList = string_to_array(inputList,',');
SELECT array_length(acceptList,1) into length;
RAISE INFO 'Length : %',length;
RAISE INFO 'AcceptList Print 1 : %',acceptList;
counter = 0;
FOREACH a in ARRAY acceptList LOOP
acceptList[counter] = a||'_1';
counter = counter + 1;
END LOOP;
RAISE INFO 'AcceptList Print 2 : %',acceptList;
END;
$BODY$
LANGUAGE plpgsql;
The output in messages tab would be :
INFO: Length : 4
INFO: AcceptList Print 1 : {INC000073535133,INC000073533828,INC000073535942,INC000073535857}
INFO: Acceptlist Print 2 : [0:4]={INC000073535133_1,INC000073533828_1,INC000073535942_1,INC000073535857_1,INC000073535857}
If you notice in the above output the values are appended correctly however, in the print 2 it is showing the size as well as an equal to symbol before printing the values of array
Want to understand why such behavior is seen
By default, arrays in Postgres are indexed from 1, while in the function body the first index of the modified array is 0. As a result, the original array has been extended by one element. The notation [0:4] = {...} means a five-element array with the non-standard first index of 0. Of course, this could be fixed in a simple way:
...
counter = 1;
FOREACH a in ARRAY acceptList LOOP
...
However, note the comment by horse_with_no_name that indicated how this should be done in Postgres with a single query:
select string_agg(concat(t.element, '_1'), ',' order by t.nr)
from unnest(string_to_array('one,two,three',',')) with ordinality as t(element, nr);
Read about arrays in the documentation.

Concatenation operator in System verilog in a loop

I am trying to do the following : concat = {concat[7:0],clk} inside a forever loop as below :
bit [7:0] concat;
concat = 0;
forever begin
#(posedge clk);
concat = {concat[7:0],clk};
end
I wanted to know what value will it contain after 8 clock iterations at any point of time, if the initial value of concat = 0.
Can it be different from 'hAA or 'h55 at any point of time?
You can not just write concat = 0; you should either assign concat = 0; or
initial begin
concat = 0;
end
Forever can not be used like that, the only two top levels you're allowed are initial and always. You want some thing like the following for a simulation:
initial begin
forever begin
#(posedge clk);
concat = {concat[6:0],clk};
end
end
If you are writing for synthesis then you might want to imply a flip-flop:
always #(posedge clk) begin
concat = {concat[6:0],clk};
end
Once you have fixed your RTL it should be easy to try out on EDA Playground.
Since you have #(posdege clk), clk will always be 1 (or x) when evaluating the RHS of the assignment. So concat will be 'h00, 'h01, 'h03, 'h07, 'h17, ...
Also note that if any other thread tries to read concat on the same positive edge of clk, you have a race condition, so please use a NBA to make the assignment.

Error for Associative Array : Missing IN OUT Parameter

I'm learning about Collections and trying out Associative Arrays in Oracle 11g. I'm using SQL Developer to write and test my code below and I am getting the error which I can't troubleshoot :
Error Report
Missing IN OUT Parameter at index ::1
Code I have written is as follows:
---SIMPLE collections EXAMPLE
DECLARE
TYPE prospect_towns IS TABLE OF VARCHAR2 (25)
INDEX BY PLS_INTEGER;
a_big_towns prospect_towns; -- associative array
i PLS_INTEGER := 1; -- index for the array
v_counter NUMBER;
v_town VARCHAR2(25);
BEGIN
a_big_towns(1):='Birmingham';
a_big_towns(2):='London':
a_big_towns(3):='Manchester';
-- v_counter := 1;
FOR i IN 1..a_big_towns.COUNT
LOOP <<big towns>>
--v_town := a_big_towns(i);
DBMS_OUTPUT.PUT_LINE('Inside Loop, town is '||a_big_towns(i));
i= a_big_towns.next:
END LOOP<<big towns>>
END;
/
Any ideas what's wrong ?
The second of these lines:
a_big_towns(1):='Birmingham';
a_big_towns(2):='London':
a_big_towns(3):='Manchester';
... has a colon at the end, instead of a semicolon. That's causing the following a_big_towns to be interpreted as a bind variable name by the parser. So it should be:
a_big_towns(2):='London';
Once you get past that, this line isn't needed, and would need := instead of = if it was, and also has a colon instead of a semicolon at the end:
i= a_big_towns.next:
... so remove that completely.
I'm not sure the labels are really adding anything here, but if you do have a label it doesn't need to be repeated at the end, and the name can't have a space in it, so make it:
<<big_towns>>
FOR i IN 1..a_big_towns.COUNT LOOP
And this needs a semicolon at the dned:
END LOOP;
This SQL Fiddle compiles.

Delphi TFloatField.DisplayFormat for numeric fields less than 1.0

This is my procedure.
procedure format_integer_field(Atable: TDataSet);
var i: integer;
begin
if Atable.Active then
if Atable.FieldCount > 0 then
with Atable do
begin
for i:= 0 to FieldCount-1 do
if (Fields[i] is TIntegerField) then
begin
(Fields[i] as TIntegerField).DisplayFormat := '###,###';
(Fields[i] as TIntegerField).EditFormat := '#';
end
else
if (Fields[i] is TFloatField) then
begin
(Fields[i] as TFloatField).DisplayFormat := '###,###.##';
(Fields[i] as TFloatField).EditFormat := '#.##';
end;
end;
end;
This is work fine until a number like "0.9" has been entered and result will be ".9".
How can I have thousand separator and zero before floating point that smaller than "1".
Try (Fields[i] as TFloatField).DisplayFormat := '##0,000.00';
As you did read in documentation at http://docwiki.embarcadero.com/RADStudio/XE3/en/Using_Default_Formatting_for_Numeric,_Date,_and_Time_Fields it says
Default formatting is performed by the following routines:
FormatFloat -- TFloatField, TCurrencyField
And how you did read in the following documentation pages
http://docwiki.embarcadero.com/Libraries/XE3/en/System.SysUtils.FormatFloat
http://docwiki.embarcadero.com/Libraries/XE3/en/Data.DB.TNumericField.DisplayFormat
the documentation quotes
0 -> Digit placeholder. If the value being formatted has a digit in the position where '0' appears in the format string, then
that digit is copied to the output string. Otherwise, a '0' is
stored in that position in the output string.
# -> Digit placeholder. If the value being formatted has a digit in the position where '#' appears in the format string, then
that digit is copied to the output string. Otherwise, nothing is
stored in that position in the output string.
So by using "#" in the formatting pattern you tell Delphi "i do not need any digits (and thousands separators with them) in this place, but you might put them if you want" - and since Delphi does not want to put leading zeros - you don't have any. However, if you really need those digits and the thousands separator with them, you put "0" instead of "#" and that way you tell Delphi "the digits just need to be here, whether you want to put them or not"
The format you need is ###,##0.0#

creating array of text files with FPS

Is it possible that FPS program read user input and then creates a file with a name of that input and that read another input and so on and on..?
I have tried to create array of text file but got some problems.
First of all an error occurred that (some) access was denied and secondly, how to create a result file where variable is in the middle of the text file name (I've tried assign (Df,'rezult',i,'.txt'); i - here is changing variable, but in this way program does not work.
P.S. Sorry for my English language skills...
This is what I have tried:
program testing;
var
Df : text;
i:integer;
SomeUserInput:integer;
begin
for i:=1 to 10 do
begin
Assign(Df,'rez.txt'); Rewrite(Df);
Read(SomeUserInput);
WriteLn(Df,'some words + ',SomeUserInput);
Close(Df);
end;
Readln;
end.
(fixed the problem that first comment suggest, but now only last thing is written in my file, I wish to create 10 or more files)
If I understand correctly, you want to number the filename with your loop var.
This should work:
program testing;
Uses
SysUtils;
var
Df : text;
i:integer;
SomeUserInput:integer;
begin
for i:=1 to 10 do
begin
Assign(Df,'rez'+IntToStr(i)+'.txt');
Rewrite(Df);
ReadLn(SomeUserInput);
WriteLn(Df,'some words + ',SomeUserInput);
Close(Df);
end;
Readln;
end.

Resources