The Python code for the new 39 math functions of GeneXproTools was easily generated from the VB.Net code.
The IF THEN ELSE construct of Python with the colon after the if expression is easily created by replacing "Then" by the colon, "Else" by "else:" and "ElseIf" by "elif"; removing the "End If" line was also easy.
I also ended up putting parentheses both around if expressions and "and" clauses but they are not a requirement of the language.
Then I just had to remove the keywords "Dim", "As Double", "As Integer", and "Const"; replace "Return" by "return"; "If" by "if"; the comment marks by "#"; "<>" by "!=" and "And" by "and".
And finally, the function headers and footers are also different in both programming languages, but the use of templates to generate the grammars greatly simplifies the translation.
if (z < minValue):
return 0.0
elif ((z >= minValue) and (z < midrange)):
return 1.0
elif ((z >= midrange) and (z < maxValue)):
return 2.0
elif (z >= maxValue):
return 3.0
def gepMap4C(a, b, c, d):
# evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
#
# evaluate minValue(a,b,c) and argMin(a,b,c)
minValue = a
argMin = 0
if (minValue > b):
minValue = b
argMin = 1
if (minValue > c):
minValue = c
argMin = 2
# evaluate maxValue(a,b,c) and argMax(a,b,c)
maxValue = a
argMax = 0
if (maxValue < b):
maxValue = b
argMax = 1
if (maxValue < c):
maxValue = c
argMax = 2
# evaluate midleValue(a,b,c)
midleValue = c
if ((0 != argMin) and (0 != argMax)):
midleValue = a
if ((1 != argMin) and (1 != argMax)):
midleValue = b
if (z < minValue):
return 0.0
elif ((z >= minValue) and (z < midpoint1)):
return 1.0
elif ((z >= midpoint1) and (z < midpoint2)):
return 2.0
elif ((z >= midpoint2) and (z < maxValue)):
return 3.0
elif (z >= maxValue):
return 4.0
def gepMap5C(a, b, c, d):
# evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
#
# evaluate minValue(a,b,c) and argMin(a,b,c)
minValue = a
argMin = 0
if (minValue > b):
minValue = b
argMin = 1
if (minValue > c):
minValue = c
argMin = 2
# evaluate maxValue(a,b,c) and argMax(a,b,c)
maxValue = a
argMax = 0
if (maxValue < b):
maxValue = b
argMax = 1
if (maxValue < c):
maxValue = c
argMax = 2
# evaluate midleValue(a,b,c)
midleValue = c
if ((0 != argMin) and (0 != argMax)):
midleValue = a
if ((1 != argMin) and (1 != argMax)):
midleValue = b
midrange1 = (minValue + midleValue)/2.0
midrange2 = (midleValue + maxValue)/2.0
if (z < minValue):
return 0.0
elif ((z >= minValue) and (z < midpoint1)):
return 1.0
elif ((z >= midpoint1) and (z < midrange)):
return 2.0
elif ((z >= midrange) and (z < midpoint2)):
return 3.0
elif ((z >= midpoint2) and (z < maxValue)):
return 4.0
elif (z >= maxValue):
return 5.0
def gepMap6C(a, b, c, d):
# evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
#
# evaluate minValue(a,b,c) and argMin(a,b,c)
minValue = a
argMin = 0
if (minValue > b):
minValue = b
argMin = 1
if (minValue > c):
minValue = c
argMin = 2
# evaluate maxValue(a,b,c) and argMax(a,b,c)
maxValue = a
argMax = 0
if (maxValue < b):
maxValue = b
argMax = 1
if (maxValue < c):
maxValue = c
argMax = 2
# evaluate midleValue(a,b,c)
midleValue = c
if ((0 != argMin) and (0 != argMax)):
midleValue = a
if ((1 != argMin) and (1 != argMax)):
midleValue = b
# evaluate midrange1 and midrange2
midrange1 = (minValue + midleValue)/2.0
midrange2 = (midleValue + maxValue)/2.0
The R code for the 39 new math functions of GeneXproTools was easily created from the C# code. I basically just removed all type keywords (double, int, const), put parentheses around the "return" expression, removed all the semi-colons, replaced the assignment sign by "<-", the comment marks by "#", and Math.Min and Math.Max by min and max.
The functions declarations are also different in both programming languages, but that's easily taken care of as we can use templates to generate the different function headers used in the R language.
outVal <- 0.0
if (z < minValue)
outVal <- 0.0
else if (z >= minValue && z < midrange)
outVal <- 1.0
else if (z >= midrange && z < maxValue)
outVal <- 2.0
else if (z >= maxValue)
outVal <- 3.0
return (outVal)
}
gepMap4C <- function(a, b, c, d)
{
# evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
#
# evaluate minValue(a,b,c)
minValue <- a
argMin <- 0
if (minValue > b)
{
minValue <- b
argMin <- 1
}
if (minValue > c)
{
minValue <- c
argMin <- 2
}
# evaluate maxValue(a,b,c)
maxValue <- a
argMax <- 0
if (maxValue < b)
{
maxValue <- b
argMax <- 1
}
if (maxValue < c)
{
maxValue <- c
argMax <- 2
}
# evaluate midleValue(a,b,c)
midleValue <- c
if (0 != argMin && 0 != argMax)
midleValue <- a
if (1 != argMin && 1 != argMax)
midleValue <- b
outVal <- 0.0
if (d < minValue)
outVal <- 0.0
else if (d >= minValue && d < midleValue)
outVal <- 1.0
else if (d >= midleValue && d < maxValue)
outVal <- 2.0
else if (d >= maxValue)
outVal <- 3.0
return (outVal)
}
outVal <- 0.0
if (z < minValue)
outVal <- 0.0
else if (z >= minValue && z < midpoint1)
outVal <- 1.0
else if (z >= midpoint1 && z < midpoint2)
outVal <- 2.0
else if (z >= midpoint2 && z < maxValue)
outVal <- 3.0
else if (z >= maxValue)
outVal <- 4.0
return (outVal)
}
gepMap5C <- function(a, b, c, d)
{
# evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
#
# evaluate minValue(a,b,c)
minValue <- a
argMin <- 0
if (minValue > b)
{
minValue <- b
argMin <- 1
}
if (minValue > c)
{
minValue <- c
argMin <- 2
}
# evaluate maxValue(a,b,c)
maxValue <- a
argMax <- 0
if (maxValue < b)
{
maxValue <- b
argMax <- 1
}
if (maxValue < c)
{
maxValue <- c
argMax <- 2
}
# evaluate midleValue(a,b,c)
midleValue <- c
if (0 != argMin && 0 != argMax)
midleValue <- a
if (1 != argMin && 1 != argMax)
midleValue <- b
# evaluate midrange1 and midrange2
midrange1 <- (minValue + midleValue)/2.0
midrange2 <- (midleValue + maxValue)/2.0
outVal <- 0.0
if (d < minValue)
outVal <- 0.0
else if (d >= minValue && d < midrange1)
outVal <- 1.0
else if (d >= midrange1 && d < midrange2)
outVal <- 2.0
else if (d >= midrange2 && d < maxValue)
outVal <- 3.0
else if (d >= maxValue)
outVal <- 4.0
return (outVal)
}
gepMap6A <- function(x, y)
{
SLACK <- 10.0
outVal <- 0.0
if (y < (x - SLACK))
outVal <- 0.0
else if (y >= (x - SLACK) && y < (x - SLACK/2.0))
outVal <- 1.0
else if (y >= (x - SLACK/2.0) && y < x)
outVal <- 2.0
else if (y >= x && y < (x + SLACK/2.0))
outVal <- 3.0
else if (y >= (x + SLACK/2.0) && y < (x + SLACK))
outVal <- 4.0
else if (y >= (x + SLACK))
outVal <- 5.0
return (outVal)
}
outVal <- 0.0
if (z < minValue)
outVal <- 0.0
else if (z >= minValue && z < midpoint1)
outVal <- 1.0
else if (z >= midpoint1 && z < midrange)
outVal <- 2.0
else if (z >= midrange && z < midpoint2)
outVal <- 3.0
else if (z >= midpoint2 && z < maxValue)
outVal <- 4.0
else if (z >= maxValue)
outVal <- 5.0
return (outVal)
}
gepMap6C <- function(a, b, c, d)
{
# evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
#
# evaluate minValue(a,b,c)
minValue <- a
argMin <- 0
if (minValue > b)
{
minValue <- b
argMin <- 1
}
if (minValue > c)
{
minValue <- c
argMin <- 2
}
# evaluate maxValue(a,b,c)
maxValue <- a
argMax <- 0
if (maxValue < b)
{
maxValue <- b
argMax <- 1
}
if (maxValue < c)
{
maxValue <- c
argMax <- 2
}
# evaluate midleValue(a,b,c)
midleValue <- c
if (0 != argMin && 0 != argMax)
midleValue <- a
if (1 != argMin && 1 != argMax)
midleValue <- b
# evaluate midrange1 and midrange2
midrange1 <- (minValue + midleValue)/2.0
midrange2 <- (midleValue + maxValue)/2.0
outVal <- 0.0
if (d < minValue)
outVal <- 0.0
else if (d >= minValue && d < midrange1)
outVal <- 1.0
else if (d >= midrange1 && d < midleValue)
outVal <- 2.0
else if (d >= midleValue && d < midrange2)
outVal <- 3.0
else if (d >= midrange2 && d < maxValue)
outVal <- 4.0
else if (d >= maxValue)
outVal <- 5.0
return (outVal)
}
gepECL3A <- function(x, y, z)
{
if (y > x && z < x)
return (1.0)
else
if (y < x && z > x)
return (-1.0)
else return (0.0)
}
gepECL3B <- function(x, y, z)
{
if (y > x && z > x)
return (1.0)
else
if (y < x && z < x)
return (-1.0)
else return (0.0)
}
gepECL3C <- function(x, y, z)
{
if (y >= x && z >= x)
return (1.0)
else
if (y <= -x && z <= -x)
return (-1.0)
else return (0.0)
}
gepECL3D <- function(a, b, c, d)
{
minValue <- min(a,b)
maxValue <- max(a,b)
if (c >= maxValue && d >= maxValue)
return (1.0)
else
if (c <= minValue && d <= minValue)
return (-1.0)
else return (0.0)
}
For programming the new 39 math functions of GeneXproTools in Pascal, I had to decide whether to use the Ada code or the Fortran code. I ended up using the Ada code even though Pascal shares with Fortran the same style for returning a function output. Moreover, all three programming languages use a declarative block or region for declaring variables and constants and in both Pascal and Fortran you cannot declare and initialize your variables at the same time.
function gepRamp1(x: real): real;
begin
if (x > 0.0) then
gepRamp1 := x
else
gepRamp1 := 0.0;
end;
function gepRamp2(x: real): real;
begin
if (x > 0.0) then
gepRamp2 := 0.0
else
gepRamp2 := x;
end;
function gepRamp3(x: real): real;
begin
if (x > 0.0) then
gepRamp3 := 0.0
else
gepRamp3 := -x;
end;
function gepRamp4(x: real): real;
begin
if (x > 0.0) then
gepRamp4 := -x
else
gepRamp4 := 0.0;
end;
function gepStep1(x: real): real;
begin
if (x > 0.0) then
gepStep1 := 1.0
else
gepStep1 := -1.0;
end;
function gepStep2(x: real): real;
begin
if (x > 0.0) then
gepStep2 := 1.0
else
gepStep2 := 0.0;
end;
function gepStep3(x: real): real;
begin
if (x >= 1.0) then
gepStep3 := 1.0
else if (x <= -1.0) then
gepStep3 := -1.0
else
gepStep3 := x;
end;
function gepStep4(x: real): real;
begin
if (x >= 1.0) then
gepStep4 := 1.0
else if (x <= 0.0) then
gepStep4 := 0.0
else
gepStep4 := x;
end;
function gepCL2A(x, y: real): real;
begin
if ((x > 0.0) and (y > 0.0)) then
gepCL2A := 1.0
else
gepCL2A := -1.0;
end;
function gepCL2B(x, y: real): real;
begin
if ((x >= 0.0) and (y < 0.0)) then
gepCL2B := -1.0
else
gepCL2B := 1.0;
end;
function gepCL2C(x, y: real): real;
begin
if ((x > 1.0) and (y < -1.0)) then
gepCL2C := -1.0
else
gepCL2C := 1.0;
end;
function gepCL2D(x, y: real): real;
begin
if ((x > 0.0) and (y > 0.0)) then
gepCL2D := 1.0
else
gepCL2D := 0.0;
end;
function gepCL2E(x, y: real): real;
begin
if ((x >= 0.0) and (y <= 0.0)) then
gepCL2E := 0.0
else
gepCL2E := 1.0;
end;
function gepCL2F(x, y: real): real;
begin
if ((x > 1.0) and (y < -1.0)) then
gepCL2F := 0.0
else
gepCL2F := 1.0;
end;
function gepCL3A(x, y: real): real;
begin
if ((x > 0.0) and (y < 0.0)) then
gepCL3A := 1.0
else if ((x < 0.0) and (y > 0.0)) then
gepCL3A := -1.0
else
gepCL3A := 0.0;
end;
function gepCL3B(x, y: real): real;
begin
if ((x >= 1.0) and (y >= 1.0)) then
gepCL3B := 1.0
else if ((x <= -1.0) and (y <= -1.0)) then
gepCL3B := -1.0
else
gepCL3B := 0.0;
end;
function gepCL3C(x, y: real): real;
begin
if ((x > 0.0) and (y > 0.0)) then
gepCL3C := 1.0
else if ((x < 0.0) and (y < 0.0)) then
gepCL3C := -1.0
else
gepCL3C := 0.0;
end;
function gepMap3A(x, y: real): real;
const SLACK = 10.0;
begin
if (y < (x - SLACK)) then
gepMap3A := -1.0
else if (y > (x + SLACK)) then
gepMap3A := 1.0
else
gepMap3A := 0.0;
end;
function gepMap3B(x, y, z: real): real;
var
minValue, maxValue: real;
begin
minValue := x;
maxValue := y;
if (minValue > y) then
begin
minValue := y;
maxValue := x;
end;
if (z < minValue) then
gepMap3B := -1.0
else if (z > maxValue) then
gepMap3B := 1.0
else
gepMap3B := 0.0;
end;
function gepMap3C(a, b, c, d: real): real;
var
minValue, maxValue: real;
begin
{ evaluate minValue(a,b,c) and maxValue(a,b,c) }
{ evaluate minValue(a,b,c) }
minValue := a;
if (minValue > b) then
minValue := b;
if (minValue > c) then
minValue := c;
{ evaluate maxValue(a,b,c) }
maxValue := a;
if (maxValue < b) then
maxValue := b;
if (maxValue < c) then
maxValue := c;
if (d < minValue) then
gepMap3C := -1.0
else if (d > maxValue) then
gepMap3C := 1.0
else
gepMap3C := 0.0;
end;
function gepMap4A(x, y: real): real;
const SLACK = 10.0;
begin
if (y < (x - SLACK)) then
gepMap4A := 0.0
else if ((y >= (x - SLACK)) and (y < x)) then
gepMap4A := 1.0
else if ((y >= x) and (y < (x + SLACK))) then
gepMap4A := 2.0
else if (y >= (x + SLACK)) then
gepMap4A := 3.0;
end;
function gepMap4B(x, y, z: real): real;
var
minValue, maxValue, midrange: real;
begin
{ evaluate minValue(x,y), maxValue(x,y) and midrange }
minValue := x;
maxValue := y;
if (minValue > y) then
begin
minValue := y;
maxValue := x;
end;
midrange := (maxValue + minValue)/2.0;
if (z < minValue) then
gepMap4B := 0.0
else if ((z >= minValue) and (z < midrange)) then
gepMap4B := 1.0
else if ((z >= midrange) and (z < maxValue)) then
gepMap4B := 2.0
else if (z >= maxValue) then
gepMap4B := 3.0;
end;
function gepMap4C(a, b, c, d: real): real;
var
minValue, maxValue, midleValue: real;
argMin, argMax: integer;
begin
{ evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c) }
{ evaluate minValue(a,b,c) }
minValue := a;
argMin := 0;
if (minValue > b) then
begin
minValue := b;
argMin := 1;
end;
if (minValue > c) then
begin
minValue := c;
argMin := 2;
end;
{ evaluate maxValue(a,b,c) }
maxValue := a;
argMax := 0;
if (maxValue < b) then
begin
maxValue := b;
argMax := 1;
end;
if (maxValue < c) then
begin
maxValue := c;
argMax := 2;
end;
{ evaluate midleValue(a,b,c) }
midleValue := c;
if ((0 <> argMin) and (0 <> argMax)) then
midleValue := a;
if ((1 <> argMin) and (1 <> argMax)) then
midleValue := b;
if (d < minValue) then
gepMap4C := 0.0
else if ((d >= minValue) and (d < midleValue)) then
gepMap4C := 1.0
else if ((d >= midleValue) and (d < maxValue)) then
gepMap4C := 2.0
else if (d >= maxValue) then
gepMap4C := 3.0;
end;
function gepMap5A(x, y: real): real;
const SLACK = 15.0;
begin
if (y < (x - SLACK)) then
gepMap5A := 0.0
else if ((y >= (x - SLACK)) and (y < (x - SLACK/3.0))) then
gepMap5A := 1.0
else if ((y >= (x - SLACK/3.0)) and (y < (x + SLACK/3.0))) then
gepMap5A := 2.0
else if ((y >= (x + SLACK/3.0)) and (y < (x + SLACK))) then
gepMap5A := 3.0
else if (y >= (x + SLACK)) then
gepMap5A := 4.0;
end;
function gepMap5B(x, y, z: real): real;
var
minValue, maxValue, intervalLength, midpoint1, midpoint2: real;
begin
{ evaluate minValue(x,y), maxValue(x,y), midpoint1, midpoint2 }
minValue := x;
maxValue := y;
if (minValue > y) then
begin
minValue := y;
maxValue := x;
end;
intervalLength := (maxValue - minValue)/3.0;
midpoint1 := minValue + intervalLength;
midpoint2 := minValue + 2.0*intervalLength;
if (z < minValue) then
gepMap5B := 0.0
else if ((z >= minValue) and (z < midpoint1)) then
gepMap5B := 1.0
else if ((z >= midpoint1) and (z < midpoint2)) then
gepMap5B := 2.0
else if ((z >= midpoint2) and (z < maxValue)) then
gepMap5B := 3.0
else if (z >= maxValue) then
gepMap5B := 4.0;
end;
function gepMap5C(a, b, c, d: real): real;
var
minValue, maxValue, midleValue, midrange1, midrange2: real;
argMin, argMax: integer;
begin
{ evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2 }
{ evaluate minValue(a,b,c) }
minValue := a;
argMin := 0;
if (minValue > b) then
begin
minValue := b;
argMin := 1;
end;
if (minValue > c) then
begin
minValue := c;
argMin := 2;
end;
{ evaluate maxValue(a,b,c) }
maxValue := a;
argMax := 0;
if (maxValue < b) then
begin
maxValue := b;
argMax := 1;
end;
if (maxValue < c) then
begin
maxValue := c;
argMax := 2;
end;
{ evaluate midleValue(a,b,c) }
midleValue := c;
if ((0 <> argMin) and (0 <> argMax)) then
midleValue := a;
if ((1 <> argMin) and (1 <> argMax)) then
midleValue := b;
{ evaluate midrange1 and midrange2 }
midrange1 := (minValue + midleValue)/2.0;
midrange2 := (midleValue + maxValue)/2.0;
if (d < minValue) then
gepMap5C := 0.0
else if ((d >= minValue) and (d < midrange1)) then
gepMap5C := 1.0
else if ((d >= midrange1) and (d < midrange2)) then
gepMap5C := 2.0
else if ((d >= midrange2) and (d < maxValue)) then
gepMap5C := 3.0
else if (d >= maxValue) then
gepMap5C := 4.0;
end;
function gepMap6A(x, y: real): real;
const SLACK = 10.0;
begin
if (y < (x - SLACK)) then
gepMap6A := 0.0
else if ((y >= (x - SLACK)) and (y < (x - SLACK/2.0))) then
gepMap6A := 1.0
else if ((y >= (x - SLACK/2.0)) and (y < x)) then
gepMap6A := 2.0
else if ((y >= x) and (y < (x + SLACK/2.0))) then
gepMap6A := 3.0
else if ((y >= (x + SLACK/2.0)) and (y < (x + SLACK))) then
gepMap6A := 4.0
else if (y >= (x + SLACK)) then
gepMap6A := 5.0;
end;
function gepMap6B(x, y, z: real): real;
var
minValue, maxValue, midrange, midpoint1, midpoint2: real;
begin
{ evaluate minValue(x,y), maxValue(x,y), midrange, midpoint1, midpoint2 }
minValue := x;
maxValue := y;
if (minValue > y) then
begin
minValue := y;
maxValue := x;
end;
midrange := (minValue + maxValue)/2.0;
midpoint1 := (minValue + midrange)/2.0;
midpoint2 := (midrange + maxValue)/2.0;
if (z < minValue) then
gepMap6B := 0.0
else if ((z >= minValue) and (z < midpoint1)) then
gepMap6B := 1.0
else if ((z >= midpoint1) and (z < midrange)) then
gepMap6B := 2.0
else if ((z >= midrange) and (z < midpoint2)) then
gepMap6B := 3.0
else if ((z >= midpoint2) and (z < maxValue)) then
gepMap6B := 4.0
else if (z >= maxValue) then
gepMap6B := 5.0;
end;
function gepMap6C(a, b, c, d: real): real;
var
minValue, maxValue, midleValue, midrange1, midrange2: real;
argMin, argMax: integer;
begin
{ evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2 }
{ evaluate minValue(a,b,c) }
minValue := a;
argMin := 0;
if (minValue > b) then
begin
minValue := b;
argMin := 1;
end;
if (minValue > c) then
begin
minValue := c;
argMin := 2;
end;
{ evaluate maxValue(a,b,c) }
maxValue := a;
argMax := 0;
if (maxValue < b) then
begin
maxValue := b;
argMax := 1;
end;
if (maxValue < c) then
begin
maxValue := c;
argMax := 2;
end;
{ evaluate midleValue(a,b,c) }
midleValue := c;
if ((0 <> argMin) and (0 <> argMax)) then
begin
midleValue := a;
end;
if ((1 <> argMin) and (1 <> argMax)) then
begin
midleValue := b;
end;
{ evaluate midrange1 and midrange2 }
midrange1 := (minValue + midleValue)/2.0;
midrange2 := (midleValue + maxValue)/2.0;
if (d < minValue) then
gepMap6C := 0.0
else if ((d >= minValue) and (d < midrange1)) then
gepMap6C := 1.0
else if ((d >= midrange1) and (d < midleValue)) then
gepMap6C := 2.0
else if ((d >= midleValue) and (d < midrange2)) then
gepMap6C := 3.0
else if ((d >= midrange2) and (d < maxValue)) then
gepMap6C := 4.0
else if (d >= maxValue) then
gepMap6C := 5.0;
end;
function gepECL3A(x, y, z: real): real;
begin
if ((y > x) and (z < x)) then
gepECL3A := 1.0
else if ((y < x) and (z > x)) then
gepECL3A := -1.0
else
gepECL3A := 0.0;
end;
function gepECL3B(x, y, z: real): real;
begin
if ((y > x) and (z > x)) then
gepECL3B := 1.0
else if ((y < x) and (z < x)) then
gepECL3B := -1.0
else
gepECL3B := 0.0;
end;
function gepECL3C(x, y, z: real): real;
begin
if ((y >= x) and (z >= x)) then
gepECL3C := 1.0
else if ((y <= -x) and (z <= -x)) then
gepECL3C := -1.0
else
gepECL3C := 0.0;
end;
function gepECL3D(a, b, c, d: real): real;
var
minValue, maxValue: real;
begin
minValue := a;
maxValue := b;
if (minValue > b) then
begin
minValue := b;
maxValue := a;
end;
if ((c >= maxValue) and (d >= maxValue)) then
gepECL3D := 1.0
else if ((c <= minValue) and (d <= minValue)) then
gepECL3D := -1.0
else
gepECL3D := 0.0;
end;
function gepAMin2(x, y: real): real;
begin
if (x < y) then
gepAMin2 := 0.0
else
gepAMin2 := 1.0;
end;
function gepAMin3(x, y, z: real): real;
var
temp, argMin: real;
begin
temp := x;
argMin := 0.0;
if (temp >= y) then
begin
temp := y;
argMin := 1.0;
end;
if (temp >= z) then
argMin := 2.0;
gepAMin3 := argMin;
end;
function gepAMin4(a, b, c, d: real): real;
var
temp, argMin: real;
begin
temp := a;
argMin := 0.0;
if (temp >= b) then
begin
temp := b;
argMin := 1.0;
end;
if (temp >= c) then
begin
temp := c;
argMin := 2.0;
end;
if (temp >= d) then
argMin := 3.0;
gepAMin4 := argMin;
end;
function gepAMax2(x, y: real): real;
begin
if (x >= y) then
gepAMax2 := 0.0
else
gepAMax2 := 1.0;
end;
function gepAMax3(x, y, z: real): real;
var
temp, argMax: real;
begin
temp := x;
argMax := 0.0;
if (temp < y) then
begin
temp := y;
argMax := 1.0;
end;
if (temp < z) then
argMax := 2.0;
gepAMax3 := argMax;
end;
function gepAMax4(a, b, c, d: real): real;
var
temp, argMax: real;
begin
temp := a;
argMax := 0.0;
if (temp < b) then
begin
temp := b;
argMax := 1.0;
end;
if (temp < c) then
begin
temp := c;
argMax := 2.0;
end;
if (temp < d) then
argMax := 3.0;
gepAMax4 := argMax;
end;
The Ada code for the 39 new math functions of GeneXproTools was created from the C++ code. And the main reason for choosing C++ as the starting point for the Ada code was the use of "return" in both programming languages.
There are, however, quite a few differences between both languages, including the word "then" after each if statement and "end if;" at the end of each if block.
The assignment sign is also different in both languages, as are the keywords "const", "double", "int" and "else if" (which in Ada translates to "constant", "long_float", "integer" and "elsif"). And there are also differences in the comment marks and logical and conditional operators.
And finally, the declaration of functions is also very different in Ada and C++, with Ada using a declarative block for the declaration of variables and constants.
function gepRamp1(x: in long_float) return long_float is
begin
if (x > 0.0) then
return x;
else
return 0.0;
end if;
end gepRamp1;
function gepRamp2(x: in long_float) return long_float is
begin
if (x > 0.0) then
return 0.0;
else
return x;
end if;
end gepRamp2;
function gepRamp3(x: in long_float) return long_float is
begin
if (x > 0.0) then
return 0.0;
else
return -x;
end if;
end gepRamp3;
function gepRamp4(x: in long_float) return long_float is
begin
if (x > 0.0) then
return -x;
else
return 0.0;
end if;
end gepRamp4;
function gepStep1(x: in long_float) return long_float is
begin
if (x > 0.0) then
return 1.0;
else
return -1.0;
end if;
end gepStep1;
function gepStep2(x: in long_float) return long_float is
begin
if (x > 0.0) then
return 1.0;
else
return 0.0;
end if;
end gepStep2;
function gepStep3(x: in long_float) return long_float is
begin
if (x >= 1.0) then
return 1.0;
elsif (x <= -1.0) then
return -1.0;
else
return x;
end if;
end gepStep3;
function gepStep4(x: in long_float) return long_float is
begin
if (x >= 1.0) then
return 1.0;
elsif (x <= 0.0) then
return 0.0;
else
return x;
end if;
end gepStep4;
function gepCL2A(x, y: in long_float) return long_float is
begin
if ((x > 0.0) and then (y > 0.0)) then
return 1.0;
else
return -1.0;
end if;
end gepCL2A;
function gepCL2B(x, y: in long_float) return long_float is
begin
if ((x >= 0.0) and then (y < 0.0)) then
return -1.0;
else
return 1.0;
end if;
end gepCL2B;
function gepCL2C(x, y: in long_float) return long_float is
begin
if ((x > 1.0) and then (y < -1.0)) then
return -1.0;
else
return 1.0;
end if;
end gepCL2C;
function gepCL2D(x, y: in long_float) return long_float is
begin
if ((x > 0.0) and then (y > 0.0)) then
return 1.0;
else
return 0.0;
end if;
end gepCL2D;
function gepCL2E(x, y: in long_float) return long_float is
begin
if ((x >= 0.0) and then (y <= 0.0)) then
return 0.0;
else
return 1.0;
end if;
end gepCL2E;
function gepCL2F(x, y: in long_float) return long_float is
begin
if ((x > 1.0) and then (y < -1.0)) then
return 0.0;
else
return 1.0;
end if;
end gepCL2F;
function gepCL3A(x, y: in long_float) return long_float is
begin
if ((x > 0.0) and then (y < 0.0)) then
return 1.0;
elsif ((x < 0.0) and then (y > 0.0)) then
return -1.0;
else
return 0.0;
end if;
end gepCL3A;
function gepCL3B(x, y: in long_float) return long_float is
begin
if ((x >= 1.0) and then (y >= 1.0)) then
return 1.0;
elsif ((x <= -1.0) and then (y <= -1.0)) then
return -1.0;
else
return 0.0;
end if;
end gepCL3B;
function gepCL3C(x, y: in long_float) return long_float is
begin
if ((x > 0.0) and then (y > 0.0)) then
return 1.0;
elsif ((x < 0.0) and then (y < 0.0)) then
return -1.0;
else
return 0.0;
end if;
end gepCL3C;
function gepMap3A(x, y: in long_float) return long_float is
SLACK: constant long_float := 10.0;
outVal: long_float := 0.0;
begin
if (y < (x - SLACK)) then
outVal := -1.0;
elsif (y > (x + SLACK)) then
outVal := 1.0;
end if;
return outVal;
end gepMap3A;
function gepMap3B(x, y, z: in long_float) return long_float is
minValue: long_float := x;
maxValue: long_float := y;
outVal: long_float := 0.0;
begin
if (minValue > y) then
minValue := y;
maxValue := x;
end if;
if (z < minValue) then
outVal := -1.0;
elsif (z > maxValue) then
outVal := 1.0;
end if;
return outVal;
end gepMap3B;
function gepMap3C(a, b, c, d: in long_float) return long_float is
minValue: long_float := a;
maxValue: long_float := a;
outVal: long_float := 0.0;
begin
-- evaluate minValue(a,b,c) and maxValue(a,b,c)
--
-- evaluate minValue(a,b,c)
if (minValue > b) then
minValue := b;
end if;
if (minValue > c) then
minValue := c;
end if;
-- evaluate maxValue(a,b,c)
if (maxValue < b) then
maxValue := b;
end if;
if (maxValue < c) then
maxValue := c;
end if;
if (d < minValue) then
outVal := -1.0;
elsif (d > maxValue) then
outVal := 1.0;
end if;
return outVal;
end gepMap3C;
function gepMap4A(x, y: in long_float) return long_float is
SLACK: constant long_float := 10.0;
outVal: long_float := 0.0;
begin
if (y < (x - SLACK)) then
outVal := 0.0;
elsif ((y >= (x - SLACK)) and then (y < x)) then
outVal := 1.0;
elsif ((y >= x) and then (y < (x + SLACK))) then
outVal := 2.0;
elsif (y >= (x + SLACK)) then
outVal := 3.0;
end if;
return outVal;
end gepMap4A;
function gepMap4B(x, y, z: in long_float) return long_float is
minValue: long_float := x;
maxValue: long_float := y;
midrange: long_float;
outVal: long_float := 0.0;
begin
-- evaluate minValue(x,y), maxValue(x,y) and midrange
if (minValue > y) then
minValue := y;
maxValue := x;
end if;
midrange := (maxValue + minValue)/2.0;
if (z < minValue) then
outVal := 0.0;
elsif ((z >= minValue) and then (z < midrange)) then
outVal := 1.0;
elsif ((z >= midrange) and then (z < maxValue)) then
outVal := 2.0;
elsif (z >= maxValue) then
outVal := 3.0;
end if;
return outVal;
end gepMap4B;
function gepMap4C(a, b, c, d: in long_float) return long_float is
minValue: long_float := a;
maxValue: long_float := a;
argMin: integer := 0;
argMax: integer := 0;
midleValue: long_float := c;
outVal: long_float := 0.0;
begin
-- evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
--
-- evaluate minValue(a,b,c)
if (minValue > b) then
minValue := b;
argMin := 1;
end if;
if (minValue > c) then
minValue := c;
argMin := 2;
end if;
-- evaluate maxValue(a,b,c)
if (maxValue < b) then
maxValue := b;
argMax := 1;
end if;
if (maxValue < c) then
maxValue := c;
argMax := 2;
end if;
-- evaluate midleValue(a,b,c)
if ((0 /= argMin) and then (0 /= argMax)) then
midleValue := a;
end if;
if ((1 /= argMin) and then (1 /= argMax)) then
midleValue := b;
end if;
if (d < minValue) then
outVal := 0.0;
elsif ((d >= minValue) and then (d < midleValue)) then
outVal := 1.0;
elsif ((d >= midleValue) and then (d < maxValue)) then
outVal := 2.0;
elsif (d >= maxValue) then
outVal := 3.0;
end if;
return outVal;
end gepMap4C;
function gepMap5A(x, y: in long_float) return long_float is
SLACK: constant long_float := 15.0;
outVal: long_float := 0.0;
begin
if (y < (x - SLACK)) then
outVal := 0.0;
elsif ((y >= (x - SLACK)) and then (y < (x - SLACK/3.0))) then
outVal := 1.0;
elsif ((y >= (x - SLACK/3.0)) and then (y < (x + SLACK/3.0))) then
outVal := 2.0;
elsif ((y >= (x + SLACK/3.0)) and then (y < (x + SLACK))) then
outVal := 3.0;
elsif (y >= (x + SLACK)) then
outVal := 4.0;
end if;
return outVal;
end gepMap5A;
function gepMap5B(x, y, z: in long_float) return long_float is
minValue: long_float := x;
maxValue: long_float := y;
intervalLength: long_float;
midpoint1: long_float;
midpoint2: long_float;
outVal: long_float := 0.0;
begin
-- evaluate minValue(x,y), maxValue(x,y), midpoint1, midpoint2
if (minValue > y) then
minValue := y;
maxValue := x;
end if;
intervalLength := (maxValue - minValue)/3.0;
midpoint1 := minValue + intervalLength;
midpoint2 := minValue + 2.0*intervalLength;
if (z < minValue) then
outVal := 0.0;
elsif ((z >= minValue) and then (z < midpoint1)) then
outVal := 1.0;
elsif ((z >= midpoint1) and then (z < midpoint2)) then
outVal := 2.0;
elsif ((z >= midpoint2) and then (z < maxValue)) then
outVal := 3.0;
elsif (z >= maxValue) then
outVal := 4.0;
end if;
return outVal;
end gepMap5B;
function gepMap5C(a, b, c, d: in long_float) return long_float is
minValue: long_float := a;
maxValue: long_float := a;
argMin: integer := 0;
argMax: integer := 0;
midleValue: long_float := c;
midrange1: long_float;
midrange2: long_float;
outVal: long_float := 0.0;
begin
-- evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
--
-- evaluate minValue(a,b,c)
if (minValue > b) then
minValue := b;
argMin := 1;
end if;
if (minValue > c) then
minValue := c;
argMin := 2;
end if;
-- evaluate maxValue(a,b,c)
if (maxValue < b) then
maxValue := b;
argMax := 1;
end if;
if (maxValue < c) then
maxValue := c;
argMax := 2;
end if;
-- evaluate midleValue(a,b,c)
if ((0 /= argMin) and then (0 /= argMax)) then
midleValue := a;
end if;
if ((1 /= argMin) and then (1 /= argMax)) then
midleValue := b;
end if;
-- evaluate midrange1 and midrange2
midrange1 := (minValue + midleValue)/2.0;
midrange2 := (midleValue + maxValue)/2.0;
if (d < minValue) then
outVal := 0.0;
elsif ((d >= minValue) and then (d < midrange1)) then
outVal := 1.0;
elsif ((d >= midrange1) and then (d < midrange2)) then
outVal := 2.0;
elsif ((d >= midrange2) and then (d < maxValue)) then
outVal := 3.0;
elsif (d >= maxValue) then
outVal := 4.0;
end if;
return outVal;
end gepMap5C;
function gepMap6A(x, y: in long_float) return long_float is
SLACK: constant long_float := 10.0;
outVal: long_float := 0.0;
begin
if (y < (x - SLACK)) then
outVal := 0.0;
elsif ((y >= (x - SLACK)) and then (y < (x - SLACK/2.0))) then
outVal := 1.0;
elsif ((y >= (x - SLACK/2.0)) and then (y < x)) then
outVal := 2.0;
elsif ((y >= x) and then (y < (x + SLACK/2.0))) then
outVal := 3.0;
elsif ((y >= (x + SLACK/2.0)) and then (y < (x + SLACK))) then
outVal := 4.0;
elsif (y >= (x + SLACK)) then
outVal := 5.0;
end if;
return outVal;
end gepMap6A;
function gepMap6B(x, y, z: in long_float) return long_float is
minValue: long_float := x;
maxValue: long_float := y;
midrange: long_float;
midpoint1: long_float;
midpoint2: long_float;
outVal: long_float := 0.0;
begin
-- evaluate minValue(x,y), maxValue(x,y), midrange, midpoint1, midpoint2
if (minValue > y) then
minValue := y;
maxValue := x;
end if;
midrange := (minValue + maxValue)/2.0;
midpoint1 := (minValue + midrange)/2.0;
midpoint2 := (midrange + maxValue)/2.0;
if (z < minValue) then
outVal := 0.0;
elsif ((z >= minValue) and then (z < midpoint1)) then
outVal := 1.0;
elsif ((z >= midpoint1) and then (z < midrange)) then
outVal := 2.0;
elsif ((z >= midrange) and then (z < midpoint2)) then
outVal := 3.0;
elsif ((z >= midpoint2) and then (z < maxValue)) then
outVal := 4.0;
elsif (z >= maxValue) then
outVal := 5.0;
end if;
return outVal;
end gepMap6B;
function gepMap6C(a, b, c, d: in long_float) return long_float is
minValue: long_float := a;
maxValue: long_float := a;
argMin: integer := 0;
argMax: integer := 0;
midleValue: long_float := c;
midrange1: long_float;
midrange2: long_float;
outVal: long_float := 0.0;
begin
-- evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
--
-- evaluate minValue(a,b,c)
if (minValue > b) then
minValue := b;
argMin := 1;
end if;
if (minValue > c) then
minValue := c;
argMin := 2;
end if;
-- evaluate maxValue(a,b,c)
if (maxValue < b) then
maxValue := b;
argMax := 1;
end if;
if (maxValue < c) then
maxValue := c;
argMax := 2;
end if;
-- evaluate midleValue(a,b,c)
if ((0 /= argMin) and then (0 /= argMax)) then
midleValue := a;
end if;
if ((1 /= argMin) and then (1 /= argMax)) then
midleValue := b;
end if;
-- evaluate midrange1 and midrange2
midrange1 := (minValue + midleValue)/2.0;
midrange2 := (midleValue + maxValue)/2.0;
if (d < minValue) then
outVal := 0.0;
elsif ((d >= minValue) and then (d < midrange1)) then
outVal := 1.0;
elsif ((d >= midrange1) and then (d < midleValue)) then
outVal := 2.0;
elsif ((d >= midleValue) and then (d < midrange2)) then
outVal := 3.0;
elsif ((d >= midrange2) and then (d < maxValue)) then
outVal := 4.0;
elsif (d >= maxValue) then
outVal := 5.0;
end if;
return outVal;
end gepMap6C;
function gepECL3A(x, y, z: in long_float) return long_float is
begin
if ((y > x) and then (z < x)) then
return 1.0;
elsif ((y < x) and then (z > x)) then
return -1.0;
else
return 0.0;
end if;
end gepECL3A;
function gepECL3B(x, y, z: in long_float) return long_float is
begin
if ((y > x) and then (z > x)) then
return 1.0;
elsif ((y < x) and then (z < x)) then
return -1.0;
else
return 0.0;
end if;
end gepECL3B;
function gepECL3C(x, y, z: in long_float) return long_float is
begin
if ((y >= x) and then (z >= x)) then
return 1.0;
elsif ((y <= -x) and then (z <= -x)) then
return -1.0;
else
return 0.0;
end if;
end gepECL3C;
function gepECL3D(a, b, c, d: in long_float) return long_float is
minValue: long_float := a;
maxValue: long_float := b;
begin
if (minValue > b) then
minValue := b;
maxValue := a;
end if;
if ((c >= maxValue) and then (d >= maxValue)) then
return 1.0;
elsif ((c <= minValue) and then (d <= minValue)) then
return -1.0;
else
return 0.0;
end if;
end gepECL3D;
function gepAMin2(x, y: in long_float) return long_float is
begin
if (x < y) then
return 0.0;
else
return 1.0;
end if;
end gepAMin2;
function gepAMin3(x, y, z: in long_float) return long_float is
temp: long_float := x;
argMin: long_float := 0.0;
begin
if (temp >= y) then
temp := y;
argMin := 1.0;
end if;
if (temp >= z) then
argMin := 2.0;
end if;
return argMin;
end gepAMin3;
function gepAMin4(a, b, c, d: in long_float) return long_float is
temp: long_float := a;
argMin: long_float := 0.0;
begin
if (temp >= b) then
temp := b;
argMin := 1.0;
end if;
if (temp >= c) then
temp := c;
argMin := 2.0;
end if;
if (temp >= d) then
argMin := 3.0;
end if;
return argMin;
end gepAMin4;
function gepAMax2(x, y: in long_float) return long_float is
begin
if (x >= y) then
return 0.0;
else
return 1.0;
end if;
end gepAMax2;
function gepAMax3(x, y, z: in long_float) return long_float is
temp: long_float := x;
argMax: long_float := 0.0;
begin
if (temp < y) then
temp := y;
argMax := 1.0;
end if;
if (temp < z) then
argMax := 2.0;
end if;
return argMax;
end gepAMax3;
function gepAMax4(a, b, c, d: in long_float) return long_float is
temp: long_float := a;
argMax: long_float := 0.0;
begin
if (temp < b) then
temp := b;
argMax := 1.0;
end if;
if (temp < c) then
temp := c;
argMax := 2.0;
end if;
if (temp < d) then
argMax := 3.0;
end if;
return argMax;
end gepAMax4;
For the Fortran code of the 39 new math functions added to the built-in math functions of GeneXproTools 5.0 with Mini-Release 1, a good starting point is the Visual Basic code. Although there are quite a few differences between Fortran and Visual Basic, the basic structures that we need for the Fortran code are already there, namely, IF THEN ELSE structures with END IF and using the function name to return a function output.
Another similarity between both languages concerns the initialization of variables: in both cases variables cannot be initialized during declaration. But in Fortran there's the additional constraint of having to declare all variables together right after the function declaration, together with any needed constants.
Also important is that in Fortran parentheses are required around if statements and logical operators such as ".and." and ".or.", whereas in Visual Basic they are optional.
The functions declarations and endings are also very different in both programming languages, but they follow a regular pattern in both cases and therefore it's easy to go from one to the other.
And like we did for other languages with built-in min and max functions (thus far, C#, VB.Net, Java, and JavaScript), we are going to make good use of the native min and max functions of Fortran to clean up the code a bit, leaving as usual the code where min and max values are used to evaluate argmin and argmax values.
So here's the Fortran code for the 39 new math functions that were implemented in GeneXproTools 5.0 MR1 "Mini-Release I: What's New?":
real(8) function gepRamp1(x)
real(8), intent(in) :: x
if (x > 0.0) then
gepRamp1 = x
else
gepRamp1 = 0.0
end if
end function gepRamp1
real(8) function gepRamp2(x)
real(8), intent(in) :: x
if (x > 0.0) then
gepRamp2 = 0.0
else
gepRamp2 = x
end if
end function gepRamp2
real(8) function gepRamp3(x)
real(8), intent(in) :: x
if (x > 0.0) then
gepRamp3 = 0.0
else
gepRamp3 = -x
end if
end function gepRamp3
real(8) function gepRamp4(x)
real(8), intent(in) :: x
if (x > 0.0) then
gepRamp4 = -x
else
gepRamp4 = 0.0
end if
end function gepRamp4
real(8) function gepStep1(x)
real(8), intent(in) :: x
if (x > 0.0) then
gepStep1 = 1.0
else
gepStep1 = -1.0
end if
end function gepStep1
real(8) function gepStep2(x)
real(8), intent(in) :: x
if (x > 0.0) then
gepStep2 = 1.0
else
gepStep2 = 0.0
end if
end function gepStep2
real(8) function gepStep3(x)
real(8), intent(in) :: x
if (x >= 1.0) then
gepStep3 = 1.0
else if (x <= -1.0) then
gepStep3 = -1.0
else
gepStep3 = x
end if
end function gepStep3
real(8) function gepStep4(x)
real(8), intent(in) :: x
if (x >= 1.0) then
gepStep4 = 1.0
else if (x <= 0.0) then
gepStep4 = 0.0
else
gepStep4 = x
end if
end function gepStep4
real(8) function gepCL2A(x, y)
real(8), intent(in) :: x, y
if ((x > 0.0) .and. (y > 0.0)) then
gepCL2A = 1.0
else
gepCL2A = -1.0
end if
end function gepCL2A
real(8) function gepCL2B(x, y)
real(8), intent(in) :: x, y
if ((x >= 0.0) .and. (y < 0.0)) then
gepCL2B = -1.0
else
gepCL2B = 1.0
end if
end function gepCL2B
real(8) function gepCL2C(x, y)
real(8), intent(in) :: x, y
if ((x > 1.0) .and. (y < -1.0)) then
gepCL2C = -1.0
else
gepCL2C = 1.0
end if
end function gepCL2C
real(8) function gepCL2D(x, y)
real(8), intent(in) :: x, y
if ((x > 0.0) .and. (y > 0.0)) then
gepCL2D = 1.0
else
gepCL2D = 0.0
end if
end function gepCL2D
real(8) function gepCL2E(x, y)
real(8), intent(in) :: x, y
if ((x >= 0.0) .and. (y <= 0.0)) then
gepCL2E = 0.0
else
gepCL2E = 1.0
end if
end function gepCL2E
real(8) function gepCL2F(x, y)
real(8), intent(in) :: x, y
if ((x > 1.0) .and. (y < -1.0)) then
gepCL2F = 0.0
else
gepCL2F = 1.0
end if
end function gepCL2F
real(8) function gepCL3A(x, y)
real(8), intent(in) :: x, y
if ((x > 0.0) .and. (y < 0.0)) then
gepCL3A = 1.0
else if ((x < 0.0) .and. (y > 0.0)) then
gepCL3A = -1.0
else
gepCL3A = 0.0
end if
end function gepCL3A
real(8) function gepCL3B(x, y)
real(8), intent(in) :: x, y
if ((x >= 1.0) .and. (y >= 1.0)) then
gepCL3B = 1.0
else if ((x <= -1.0) .and. (y <= -1.0)) then
gepCL3B = -1.0
else
gepCL3B = 0.0
end if
end function gepCL3B
real(8) function gepCL3C(x, y)
real(8), intent(in) :: x, y
if ((x > 0.0) .and. (y > 0.0)) then
gepCL3C = 1.0
else if ((x < 0.0) .and. (y < 0.0)) then
gepCL3C = -1.0
else
gepCL3C = 0.0
end if
end function gepCL3C
real(8) function gepMap3A(x, y)
real(8), intent(in) :: x, y
real(8), parameter :: SLACK = 10.0
if (y < (x - SLACK)) then
gepMap3A = -1.0
else if (y > (x + SLACK)) then
gepMap3A = 1.0
else
gepMap3A = 0.0
end if
end function gepMap3A
real(8) function gepMap3B(x, y, z)
real(8), intent(in) :: x, y, z
real(8) :: minValue
real(8) :: maxValue
minValue = min(x,y)
maxValue = max(x,y)
if (z < minValue) then
gepMap3B = -1.0
else if (z > maxValue) then
gepMap3B = 1.0
else
gepMap3B = 0.0
end if
end function gepMap3B
real(8) function gepMap3C(a, b, c, d)
real(8), intent(in) :: a, b, c, d
real(8) :: minValue
real(8) :: maxValue
minValue = min(a,b,c)
maxValue = max(a,b,c)
if (d < minValue) then
gepMap3C = -1.0
else if (d > maxValue) then
gepMap3C = 1.0
else
gepMap3C = 0.0
end if
end function gepMap3C
real(8) function gepMap4A(x, y)
real(8), intent(in) :: x, y
real(8), parameter :: SLACK = 10.0
if (y < (x - SLACK)) then
gepMap4A = 0.0
else if ((y >= (x - SLACK)) .and. (y < x)) then
gepMap4A = 1.0
else if ((y >= x) .and. (y < (x + SLACK))) then
gepMap4A = 2.0
else if (y >= (x + SLACK)) then
gepMap4A = 3.0
end if
end function gepMap4A
real(8) function gepMap4B(x, y, z)
real(8), intent(in) :: x, y, z
! evaluate minValue(x,y), maxValue(x,y) and midrange
real(8) :: minValue
real(8) :: maxValue
real(8) :: midrange
minValue = min(x,y)
maxValue = max(x,y)
midrange = (maxValue + minValue)/2.0
if (z < minValue) then
gepMap4B = 0.0
else if ((z >= minValue) .and. (z < midrange)) then
gepMap4B = 1.0
else if ((z >= midrange) .and. (z < maxValue)) then
gepMap4B = 2.0
else if (z >= maxValue) then
gepMap4B = 3.0
end if
end function gepMap4B
real(8) function gepMap4C(a, b, c, d)
real(8), intent(in) :: a, b, c, d
real(8) :: minValue, maxValue, midleValue
integer :: argMin, argMax
! evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
!
! evaluate minValue(a,b,c)
minValue = a
argMin = 0
if (minValue > b) then
minValue = b
argMin = 1
end if
if (minValue > c) then
minValue = c
argMin = 2
end if
! evaluate maxValue(a,b,c)
maxValue = a
argMax = 0
if (maxValue < b) then
maxValue = b
argMax = 1
end if
if (maxValue < c) then
maxValue = c
argMax = 2
end if
! evaluate midleValue(a,b,c)
midleValue = c
if ((0 /= argMin) .and. (0 /= argMax)) then
midleValue = a
end if
if ((1 /= argMin) .and. (1 /= argMax)) then
midleValue = b
end if
if (d < minValue) then
gepMap4C = 0.0
else if ((d >= minValue) .and. (d < midleValue)) then
gepMap4C = 1.0
else if ((d >= midleValue) .and. (d < maxValue)) then
gepMap4C = 2.0
else if (d >= maxValue) then
gepMap4C = 3.0
end if
end function gepMap4C
real(8) function gepMap5A(x, y)
real(8), intent(in) :: x, y
real(8), parameter :: SLACK = 15.0
if (y < (x - SLACK)) then
gepMap5A = 0.0
else if ((y >= (x - SLACK)) .and. (y < (x - SLACK/3.0))) then
gepMap5A = 1.0
else if ((y >= (x - SLACK/3.0)) .and. (y < (x + SLACK/3.0))) then
gepMap5A = 2.0
else if ((y >= (x + SLACK/3.0)) .and. (y < (x + SLACK))) then
gepMap5A = 3.0
else if (y >= (x + SLACK)) then
gepMap5A = 4.0
end if
end function gepMap5A
if (z < minValue) then
gepMap5B = 0.0
else if ((z >= minValue) .and. (z < midpoint1)) then
gepMap5B = 1.0
else if ((z >= midpoint1) .and. (z < midpoint2)) then
gepMap5B = 2.0
else if ((z >= midpoint2) .and. (z < maxValue)) then
gepMap5B = 3.0
else if (z >= maxValue) then
gepMap5B = 4.0
end if
end function gepMap5B
real(8) function gepMap5C(a, b, c, d)
real(8), intent(in) :: a, b, c, d
real(8) :: minValue, maxValue, midleValue, midrange1, midrange2
integer :: argMin, argMax
! evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
!
! evaluate minValue(a,b,c)
minValue = a
argMin = 0
if (minValue > b) then
minValue = b
argMin = 1
end if
if (minValue > c) then
minValue = c
argMin = 2
end if
! evaluate maxValue(a,b,c)
maxValue = a
argMax = 0
if (maxValue < b) then
maxValue = b
argMax = 1
end if
if (maxValue < c) then
maxValue = c
argMax = 2
end if
! evaluate midleValue(a,b,c)
midleValue = c
if ((0 /= argMin) .and. (0 /= argMax)) then
midleValue = a
end if
if ((1 /= argMin) .and. (1 /= argMax)) then
midleValue = b
end if
midrange1 = (minValue + midleValue)/2.0
midrange2 = (midleValue + maxValue)/2.0
if (d < minValue) then
gepMap5C = 0.0
else if ((d >= minValue) .and. (d < midrange1)) then
gepMap5C = 1.0
else if ((d >= midrange1) .and. (d < midrange2)) then
gepMap5C = 2.0
else if ((d >= midrange2) .and. (d < maxValue)) then
gepMap5C = 3.0
else if (d >= maxValue) then
gepMap5C = 4.0
end if
end function gepMap5C
real(8) function gepMap6A(x, y)
real(8), intent(in) :: x, y
real(8), parameter :: SLACK = 10.0
if (y < (x - SLACK)) then
gepMap6A = 0.0
else if ((y >= (x - SLACK)) .and. (y < (x - SLACK/2.0))) then
gepMap6A = 1.0
else if ((y >= (x - SLACK/2.0)) .and. (y < x)) then
gepMap6A = 2.0
else if ((y >= x) .and. (y < (x + SLACK/2.0))) then
gepMap6A = 3.0
else if ((y >= (x + SLACK/2.0)) .and. (y < (x + SLACK))) then
gepMap6A = 4.0
else if (y >= (x + SLACK)) then
gepMap6A = 5.0
end if
end function gepMap6A
if (z < minValue) then
gepMap6B = 0.0
else if ((z >= minValue) .and. (z < midpoint1)) then
gepMap6B = 1.0
else if ((z >= midpoint1) .and. (z < midrange)) then
gepMap6B = 2.0
else if ((z >= midrange) .and. (z < midpoint2)) then
gepMap6B = 3.0
else if ((z >= midpoint2) .and. (z < maxValue)) then
gepMap6B = 4.0
else if (z >= maxValue) then
gepMap6B = 5.0
end if
end function gepMap6B
real(8) function gepMap6C(a, b, c, d)
real(8), intent(in) :: a, b, c, d
real(8) :: minValue, maxValue, midleValue, midrange1, midrange2
integer :: argMin, argMax
! evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
!
! evaluate minValue(a,b,c)
minValue = a
argMin = 0
if (minValue > b) then
minValue = b
argMin = 1
end if
if (minValue > c) then
minValue = c
argMin = 2
end if
! evaluate maxValue(a,b,c)
maxValue = a
argMax = 0
if (maxValue < b) then
maxValue = b
argMax = 1
end if
if (maxValue < c) then
maxValue = c
argMax = 2
end if
! evaluate midleValue(a,b,c)
midleValue = c
if ((0 /= argMin) .and. (0 /= argMax)) then
midleValue = a
end if
if ((1 /= argMin) .and. (1 /= argMax)) then
midleValue = b
end if
! evaluate midrange1 and midrange2
midrange1 = (minValue + midleValue)/2.0
midrange2 = (midleValue + maxValue)/2.0
if (d < minValue) then
gepMap6C = 0.0
else if ((d >= minValue) .and. (d < midrange1)) then
gepMap6C = 1.0
else if ((d >= midrange1) .and. (d < midleValue)) then
gepMap6C = 2.0
else if ((d >= midleValue) .and. (d < midrange2)) then
gepMap6C = 3.0
else if ((d >= midrange2) .and. (d < maxValue)) then
gepMap6C = 4.0
else if (d >= maxValue) then
gepMap6C = 5.0
end if
end function gepMap6C
real(8) function gepECL3A(x, y, z)
real(8), intent(in) :: x, y, z
if ((y > x) .and. (z < x)) then
gepECL3A = 1.0
else if ((y < x) .and. (z > x)) then
gepECL3A = -1.0
else
gepECL3A = 0.0
end if
end function gepECL3A
real(8) function gepECL3B(x, y, z)
real(8), intent(in) :: x, y, z
if ((y > x) .and. (z > x)) then
gepECL3B = 1.0
else if ((y < x) .and. (z < x)) then
gepECL3B = -1.0
else
gepECL3B = 0.0
end if
end function gepECL3B
real(8) function gepECL3C(x, y, z)
real(8), intent(in) :: x, y, z
if ((y >= x) .and. (z >= x)) then
gepECL3C = 1.0
else if ((y <= -x) .and. (z <= -x)) then
gepECL3C = -1.0
else
gepECL3C = 0.0
end if
end function gepECL3C
real(8) function gepECL3D(a, b, c, d)
real(8), intent(in) :: a, b, c, d
real(8) :: minValue, maxValue
minValue = min(a,b)
maxValue = max(a,b)
if ((c >= maxValue) .and. (d >= maxValue)) then
gepECL3D = 1.0
else if ((c <= minValue) .and. (d <= minValue)) then
gepECL3D = -1.0
else
gepECL3D = 0.0
end if
end function gepECL3D
real(8) function gepAMin2(x, y)
real(8), intent(in) :: x, y
if (x < y) then
gepAMin2 = 0.0
else
gepAMin2 = 1.0
end if
end function gepAMin2
real(8) function gepAMin3(x, y, z)
real(8), intent(in) :: x, y, z
real(8) :: temp
real(8) :: argMin
temp = x
argMin = 0.0
if (temp >= y) then
temp = y
argMin = 1.0
end if
if (temp >= z) then
argMin = 2.0
end if
gepAMin3 = argMin
end function gepAMin3
real(8) function gepAMin4(a, b, c, d)
real(8), intent(in) :: a, b, c, d
real(8) :: temp
real(8) :: argMin
temp = a
argMin = 0.0
if (temp >= b) then
temp = b
argMin = 1.0
end if
if (temp >= c) then
temp = c
argMin = 2.0
end if
if (temp >= d) then
argMin = 3.0
end if
gepAMin4 = argMin
end function gepAMin4
real(8) function gepAMax2(x, y)
real(8), intent(in) :: x, y
if (x >= y) then
gepAMax2 = 0.0
else
gepAMax2 = 1.0
end if
end function gepAMax2
real(8) function gepAMax3(x, y, z)
real(8), intent(in) :: x, y, z
real(8) :: temp
real(8) :: argMax
temp = x
argMax = 0.0
if (temp < y) then
temp = y
argMax = 1.0
end if
if (temp < z) then
argMax = 2.0
end if
gepAMax3 = argMax
end function gepAMax3
real(8) function gepAMax4(a, b, c, d)
real(8), intent(in) :: a, b, c, d
real(8) :: temp
real(8) :: argMax
temp = a
argMax = 0.0
if (temp < b) then
temp = b
argMax = 1.0
end if
if (temp < c) then
temp = c
argMax = 2.0
end if
if (temp < d) then
argMax = 3.0
end if
gepAMax4 = argMax
end function gepAMax4