How to query data from txt file into AspenTech IP21 Historian? - sqlplus

I have process data in this format in a txt file.
testTag testTag2
10 18
6 15
7 15
9 19
Please help me to build a SQLPlus script so that after every 5 seconds one of these values orderly should update IP_INPUT_VALUE field of testTag & testTag2.
Option to reschedule the query after every 5 seconds, can be used just in case required.
Please help.

This issue is resolved by myself after multiple attempts. All i had to do is changed the txt format to below format and run the query
A B
NAME VALUE
----------------------------------------
testTag 10 6 7 9
testTag2 18 15 15 19
SQLPLus Query:
local tagname char(24);
local value real;
local x,y integer;
y=2;
for x = y to 5 do
wait 00:00:05.00;
for (select line as ln from 'c:\data\Data.txt') do
tagname = substring(1 of ln between' ');
value = substring (x of ln between ' ');
UPDATE ip_analogdef SET IP_INPUT_VALUE = value,
QSTATUS(IP_INPUT_VALUE) = 'Good'
where name=tagname;
y=y+1;
end;
end;

Related

Intercalate columns when they are in pairs

Using this table:
A
B
C
D
1
2
3
4
5
6
7
8
9
10
11
12
In Google Sheets if I do this here in column E:
={A1:B3;C1:D3}
Teremos:
E
F
1
2
5
6
9
10
3
4
7
8
11
12
But the result I want is this:
E
F
1
2
3
4
5
6
7
8
9
10
11
12
I tried multiple options with FLATTEN, but none of them returned what I wanted.
Well you can try:
=WRAPROWS(TOCOL(A1:D3),2)
You could try with MAKEARRAY
=MAKEARRAY(ROWS(A1:D3)*2,2,LAMBDA(r,c,INDEX(FLATTEN(A1:D3),c+(r-1)*2)))
GENERAL ANSWER
For you or anyone else: to do something similar but with a variable number of columns of origin or of destination, you can use this formula. Changing the range and amount of columns at the end of LAMBDA:
=LAMBDA(range,cols,MAKEARRAY(ROWS(range)*ROUNDUP(COLUMNS(range)/cols),cols,LAMBDA(r,c,IFERROR(INDEX(FLATTEN(range),c+(r-1)*cols)))))(A1:D3,2)
you can do:
={FLATTEN({A1:A3, C1:C3}), FLATTEN({B1:B3, D1:D3})}
for more columns, it could be automated with MOD

How to extract multiple line strings between two keywords using grepwin

Hi I have a directory of files and each file has multiple languages text strings over multiple lines. Using grepwin I would like to extract all the English text strings and save into another text file. Typically in the each file the english text is inside a Switch/Case condition like this:
Default //English
bitmap 8 20 "bmp5/warning.bmp"
Ltext 5 1 11 "USB Device Overload"
LText 85 20 13 "USB"
Ltext 50 33 13 "Device Overload!"
Break
Case _French
bitmap 8 20 "bmp5/warning.bmp"
LTEXT 5 1 11 "Surcharge clé USB!"
LTEXT 45 30 13 "Surcharge clé USB"
Break
Since all the English text is always between 'Default' and 'Break' I want to use those two keywords as the delimeter. Finally all the text between the two keywords needs to be saved out to another text file.
Can anyone help at all.
Thanks guys
Through grep.
$ grep -oPz '(?s)(?<=\n|^)Default\b[^\n]*\n\K.*?(?=\nBreak\b)' file
bitmap 8 20 "bmp5/warning.bmp"
Ltext 5 1 11 "USB Device Overload"
LText 85 20 13 "USB"
Ltext 50 33 13 "Device Overload!"
To save the result to another file, you need to use output redirection operator.
grep -oPz '(?s)(?<=\n|^)Default\b[^\n]*\n\K.*?(?=\nBreak\b)' infile > outfile
From man grep
-P, --perl-regexp PATTERN is a Perl regular expression
-z, --null-data a data line ends in 0 byte, not newline

How to read decimal in SPSS syntax?

I want to read the following data in SPSS :
ID Age Sex GPA
----------------
1 17 M 5
2 16 F 5
3 17 F 4.75
4 18 M 5
5 19 M 4.5
My attempt:
DATA LIST / ID 1 AGE 2-3 SEX 4(A) GPA 5-8.
BEGIN DATA
117M5
216F5
317F4.75
418M5
519M4.5
END DATA.
LIST.
But the output is
ID AGE SEX GPA
---------------
1 17 M 5
2 16 F 5
3 17 F 5
4 18 M 5
5 19 M 5
How can I get the decimals?
You data is as expected, it is just the format of the GPA variable was incorrectly set to not have any decimals. You can simply use whats below to set it to show the decimals.
FORMATS GPA (F3.2).
Alternatively you can also try this
DATA LIST / ID 1 AGE 2-3 SEX 4(A) GPA 5-7(F,2).
BEGIN DATA
117M500
317F475
END DATA.
LIST.

breeze date (ko.observable) to moment not converting correctly

I have a breeze entity with a date in it, I need to get the year, month, day separately and was going to use momentjs to do it but I'm getting some strange results for something that I would have thought would be quite simple:
var dob = moment(observableDate());
console.log(observableDate() + ' to -> ' + dob.day() + ' - ' + dob.month() + ' - ' + dob.year());
//ouput
//Thu Dec 18 1975 11:00:00 GMT+1100 (AUS Eastern Summer Time) to -> 4 - 11 - 1975
I don't understand where the 4th of Nov is coming from....
The date is stored in Sql Server and the value is '1975-12-18 00:00:00.000'
Thanks in advance.
According to the moment.js documentation
day() returns the day of the week, i.e. a number between 0 and 6; (4 == thursday).
month() returns the month of the year but 0 origin. i.e. a number between 0 and 11 - (11 == december)
See: Moment.js docs

Parsing a Large Text in Sections in Matlab

I have a large text file as below imported in MATLAB:
Run Lat Long Time
1 32 32 34
1 23 22 21
2 23 12 11
2 11 11 11
2 33 11 12
up to 10 runs etc.
So I'm trying to break up each section in the file: section 1, section 2, etc and write it to 10 different text files. File 1 will have data from Run 1. File 2 will have data from Run 2.
What you're looking for is Matlab's textread function. I'll give you the pieces you need and frame out the logic, but you'll need to connect the pieces yourself :)
Your read would look something like this
[head1, head2, head3, head4] = textread(file_name,'%s %s %s %s',1);
[run, lat, long, time] = textread(file_name,'%u %u %u %u');
and your write method would use a loop to iterate over the values in
unique(run)
creating a file with
fout = fopen([base_file_name_out num2str(run_number)]);
and writing to it the values contained in
lat_this_run=Lat(run==run_number);
using the method
fprintf(fout,'%u %u %u\n', lat_this_run, long_this_run, time_this_run)
If your data is already loaded into matlab and named A, you could do:
>> a = max(A(:,1));
>> AA={};
>> for i = 1:a
AA{i}=A(find(A(:,1)==i),:)
name=sprintf('%d.txt',i);
dlmwrite(name,AA{i},'\t');
end
The output will be .txt files containing tab-delimited data.

Resources