7. Routines for filtering and sorting a table#
7.1. Mechanism for filtering rows in a table#
In routines TBLIVA, TBNULI and TBEXTB, it is necessary to « filter » an existing table in order to retain only one (or several) rows. It is this mechanism that we explain here.
To filter a table, the user imposes criteria on certain parameters. For example, he will say to remember only the rows in the table for which NUME_ORDRE =1. It can use several criteria for selecting rows and the same parameter can appear several times in the list of criteria.
The « types » of possible choice criteria are:
Note:
In routines TBLIVA and TBNULI , the type of selection criteria is (for now) always equality ( “EQ” ). The list of criteria given in these 2 routines ( written ) is therefore the list of « secondary » criteria (Cf. § 7.1.1 Special case of equality criteria… ) .
The arguments: vi, vr, vc, vk of these routines contain the values associated with these criteria (according to the type associated with each of the parameters to which the criteria relate).
We are going to explain the use of all these arguments on an example (without floating numbers):
Consider a table containing parameters I1, I2, I3 of the « integer » type and K1, K2 of the « character » type.
We want to extract rows that meet the following criteria:
the value of K1 is different from “ACTION1”
the value of I2 is between 12 and 21
the value of I3 is equal to 999
the value of I1 is « not empty »
the value of K2 is « greater » (in the sense of alphabetical order) than “III”
As arguments for TBEXTB, we’ll give:
npacri=6 There are 6 criteria to choose from because the 2nd criterion is twofold: (x>12) and (x<21)
lipacr = ('K1', 'I2', 'I2', 'I2', 'I3', 'I1', 'K2')
lcrpa = ('NE', 'GT', 'GT', 'LT', 'EQ', 'NON_VIDE', 'GT')
vk (1) =' ACTION1 ', vi (1) =12, vi (2) =21, vi (3) =999, vk (2) =' III'
Note:
The criterion types “VIDE “and” NON_VIDE “do not require arguments in arrays vi, vr,…
7.1.1. Special case of equality (or non-equality) criteria for « floating » numbers#
The equality of floating numbers is a dangerous concept in computer science because it can depend on certain truncations: rounding errors for example. For these selection criteria, a list of secondary criteria is therefore used that specify what equality is desired. There are three possible types of secondary criteria:
“EGAL”: « exact » equality of the 2 floating numbers
“ABSO”: equality of the 2 floating numbers to within one epsilon (eps) in absolute comparison: true if:math: |x1-x2| < eps
“RELA”: equality of the 2 floating numbers to within one epsilon (eps) in relative comparison: true if:math: |x1-x2| < eps * |x1|
Example:
Consider a table containing the integer parameters: I1 and I2, the real parameters R1 and R2 and the complex parameters C1 and C2. We want to extract the rows corresponding to the following criteria:
I1 > 12
C1 = C1 to 0.01 to the nearest « absolute »
R1 = r1 to within 0.1 in « relative »
C2 /= c2 to within 0.02 in « relative » (numbers that are not in the disk with center c2 and radius 0.002*c2)
R2 /= r2 to 0.2 within « absolute » (numbers that are not in the range of center R2 and radius 0.2)
As arguments for TBEXTB, we’ll give:
Npacri = 5"
lipacr = ('I1', 'C1', 'C1', 'R1', 'C2', 'R2')"
licrpa = ('GT', 'EQ', 'EQ', 'NE', 'NE')"
vi (1) = 12, vr (1) =r1, vr (2) =r2, vc (1) =c1, vc (2) =c2"
Write = ('ABSO', 'RELA', '', 'RELA', 'ABSO')"
lprec = (0.01, 0.1, 0.02, 0.2)"
7.2. Routine TBEXTB: Filtering and extracting a new table#
TBEXTB (tabin, basout, taboo, npacri, npacri, lipacr, lcrpa, vi, vr, vc, vk, lprec, lprec, write, iret)
tabin |
in jxin |
K19 |
Name of the table from which you want to extract rows |
basout |
in |
K1 |
“G”, “V”: basis for creating tabout |
taboo |
In jxout |
K19 |
Name of the table that will contain the rows extracted from tabin |
npacri |
in |
I |
Number of parameters involved in the criteria extraction (LCRPA lipacret dimension) |
lipacr |
in |
V (K16) |
List of criteria parameters see § 7 Routines for filtering and sorting a table |
lcrpa |
in |
V (K10) |
List of selection criteria: EQ, LT, GT, NE, LE, GE, VIDE, NON_VIDE The meaning of these criteria is given in § 7 Routines for filtering and sorting a table. |
vi |
in |
V (I) |
Criteria values for parameters” I “ |
vr |
in |
V (R) |
Criteria values for “R” parameters |
vc |
in |
V (C) |
Criteria values for “C” parameters |
vk |
in |
V (K) |
Criteria values for “K” parameters |
lprec |
in |
V (R) |
List of details (for the criteria of equality of floating parameters see § 7.1.1 Special case of equality criteria…) |
lcrit |
in |
V (K8) |
List of secondary equality criteria for floating parameters: “EGAL”, “RELA”, “ABSO”, “” cf. § 7.1.1 Special case of equality criteria… |
Yesterday |
out |
I |
Return code: 0: OK 1: para does not exist in the table for the row found 2: no line found matching the criteria 3: several lines found corresponding to the criteria |
When rows satisfying all the given criteria have been retrieved from tabin, only columns for which at least one value exists are kept in the tababout table. The same parameter can appear several times in the list of criteria (lcrpa).
Example:
This is the table: T3
A |
B |
C |
4 |
“Z” |
|
0 |
“A1” |
|
9 |
“A2” |
|
9 |
“A2” |
|
Lipacr (1) ='A'
lcrpa (1) =' NON_VIDE '
Lipacr (2) ='B'
lcrpa (2) ='GT'
vi (1) = 1
Lipacr (3) ='A'
lcrpa (3) ='LE'
vr (1) = 1.d2
CALL TBEXTB (T3, 'G', T3B3, 3, Lipacr, LCRPA, VI, VR, VC, VK, LPREC, LPREC, Write, Iret)
T3B output contains:
A |
B |
C |
9 |
“A2” |
|
7.3. Routine TBTRTB: Sorting the table#
TBTRTB (tabin, basout, tabout, tabout, npara, lipara, lipara, lcrit, prec, crit)
tabin |
in jxin |
K19 |
Name of the table whose rows we want to order |
basout |
in |
K1 |
Tabout creation base: G/V/L |
taboo |
in jxout |
K19 |
Name of the table containing all the tabin rows classified according to the following criteria |
npara |
in |
I |
Number of parameters involved in the sorting criteria (lipara and lcrit dimensions) |
lipara |
in |
V (K16) |
List of criteria parameters |
lcrit |
in |
V (K2) |
List of criteria types: “CR” or “DR” “CR”: ascending order “DR”: descending order |
prec |
in |
R |
precision |
crit |
in |
K8 |
criteria = “ABSOLU” or “RELATIF” |
This routine is used to create a new table (taboo) by permuting the order of the rows of an existing table (tabin) according to certain sorting criteria.
Tri
R, I values: By increasing or decreasing values
K8, K16, K24, K32 values: In ascending or descending alphabetical order
Example:
lipara = (“NOEUD”, “INST”) write = (“CR”, “DR”)
The new table (taboo) will be ordered:
firstly in ascending alphabetical order of node names,
second, in descending order of calculation times.
Notes:
The 2nd criterion only applies if there is a tie within the meaning of the first criterion.
Empty cells are classified as « heads » (they are the smallest for the order relationship) .