Commit 86b36448 authored by Eoin Clerkin's avatar Eoin Clerkin
Browse files

Adds fail flag trigger for substrances whose components don't add to

100%

Adds chemical composition output for easier human inspection.
parent ae8e05fe
......@@ -12,17 +12,17 @@
function abs(x){return (x>=0) ? x : -x}
BEGIN{
ACCEPTABLE_ERROR=0.01 # 1 % ERROR TOLERANCE FOR STATIC CHECK.
FAIL=0; # Flag for determining success. If any check fails then this value is changed.
while(getline < "LIST_ELEMENTS"){
ELEMENT_NAME[$1]=$2;
ELEMENT_SYMBOL[$1]=$3;
ELEMENT_MASS[$1]=$4;
# Index $1 is the Atomic Number of the Element
};
FAIL=0; # Flag for determining success. If any check fails then this value is changed.
ACCEPTABLE_ERROR=0.01 # 1 % ERROR TOLERANCE FOR STATIC CHECK
};
......@@ -70,7 +70,6 @@ for (i = 1; i<=NF; i++)datum[i]=$i; # Loading in a line from media.geo fle to ma
printf "Atomic Number: %s\tAtomic Mass: %s\n", datum[2+i+datum[2]], datum[2+i]; # See https://fairroot.gsi.de/?q=node/34 for info regarding format ordering.
printf "AN[%d]=> %s : Mass = %s\n", datum[2+i+datum[2]], ELEMENT_NAME[strtonum(datum[2+i+datum[2]])], ELEMENT_MASS[strtonum(datum[2+i+datum[2]])];
# datum[2] is the number of components
# datum[2 + i] is subsequent component's atomic number
# datum[2 + i + datum[2]] is subsequenct component's atomic weight
......@@ -80,10 +79,20 @@ for (i = 1; i<=NF; i++)datum[i]=$i; # Loading in a line from media.geo fle to ma
ERROR = abs( (datum[2+i] - ELEMENT_MASS[strtonum(datum[2+i+datum[2]])] )/datum[2+i])
printf "1 MASS ENTERED %s \n", datum[2+i];
printf "2 ELEMENT MASS %s \n", ELEMENT_MASS[strtonum(datum[2+i+datum[2]])];
if(datum[2]>1 && content_by~"weight"){
if(datum[2]>1){ # Checks relatavant for more than one component.
if(content_by~"number"){ # When the elements are per their relative number.
printf "%s", ELEMENT_SYMBOL[strtonum(datum[2+i+datum[2]])];
printf "%s\n", datum[3 + 2*datum[2] + i];
CHEMISTRY[ELEMENT_SYMBOL[strtonum(datum[2+i+datum[2]])]]=datum[3 + 2*datum[2] + i];
};
if(content_by~"weight"){ # When the elements are per weight
printf "RELATIVE AMOUNT: %0.2f%% \n", 100*datum[3 + 2*datum[2] + i];
RELATIVE_SUM+=datum[3 + 2*datum[2] + i];
};
};
printf "ERROR IS %f \t", ERROR;
if (ERROR > ACCEPTABLE_ERROR) {
......@@ -97,16 +106,29 @@ for (i = 1; i<=NF; i++)datum[i]=$i; # Loading in a line from media.geo fle to ma
# Check if the amount of material adds up to 100%
if(datum[2]>1 && content_by~"weight"){
printf "TOTAL AMOUNT COUNT RELATIVE SUMS: %0.2f%% \t\t\t", 100*RELATIVE_SUM;
if (RELATIVE_SUM==1){
if (RELATIVE_SUM<=1+ACCEPTABLE_ERROR && RELATIVE_SUM>=1-ACCEPTABLE_ERROR ){
printf "CHECK PASSED! %s \n\n", RELATIVE_SUM;
}else{
printf "CHECK FAILED! %s \n\n", RELATIVE_SUM;
FAIL=1;
};
};
print " " # Spacing
# Chemical Formula Attempt. For visual inspection by human.
if(datum[2]>1 && content_by~"number"){
printf "Contents by the number of atoms: \n"
for( ele in CHEMISTRY )printf "%s%s", ele, CHEMISTRY[ele];
# ELEMENT_SYMBOL[strtonum(datum[2+i+datum[2]])]
# CHEMISTRY[]
};
print " " # Spacing
delete CHEMISTRY;
};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment