1254 lines
35 KiB
JavaScript
1254 lines
35 KiB
JavaScript
// This file contains function that are Javascript generic
|
|
|
|
function parse_formula (mf) {
|
|
// This function takes a chemical formula and returns
|
|
// an object that contains the atoms and their number
|
|
var mf = mf.replace(/\[/g,"(").replace(/\]/g,")").replace(/\{/g,"(").replace(/\}/g,")").replace(/\s+/g,"");
|
|
if(/^\d+/.test(mf)) throw new SyntaxError("Molecular formula should not start with a number!");
|
|
var mol = {};
|
|
while(mf.includes("(")){
|
|
var x = mf.lastIndexOf("(");
|
|
var y = mf.indexOf(")", mf.lastIndexOf("("));
|
|
|
|
var z = mf.substr(x+1, y-x-1);
|
|
var c = mf.substr(y+1);
|
|
c = /^\d+/.exec(c);
|
|
c=(c!= null)?Number(c[0]):1;
|
|
|
|
var a = this.parse_formula(z);
|
|
var b = "";
|
|
for(var k in a){
|
|
b+=k+""+a[k]*c;
|
|
}
|
|
mf = mf.substr(0, x)+ b + mf.substr(y+1+((c>1)?(c+'').length:0));
|
|
}
|
|
|
|
var m = "";
|
|
while(m = /([A-Z]{1}[a-z]{0,}[0-9]{0,})/.exec(mf)){
|
|
var m1 = /([A-Z]{1,}[a-z]{0,})/.exec(m[0]);
|
|
var m2 = /\d+/.exec(m[0]);
|
|
if(typeof mol[m1[0]] == 'undefined') mol[m1[0]]=(m2!=null)?Number(m2[0]):1;
|
|
else mol[m1[0]] += (m2!=null)?Number(m2[0]):1;
|
|
mf = mf.replace(m[0], "");
|
|
}
|
|
return mol;
|
|
}
|
|
|
|
|
|
function Zof(Element)
|
|
{
|
|
var ElementsZ = {
|
|
"Muon":1,
|
|
"Li8":3,
|
|
"B12":5,
|
|
"H":1,
|
|
"He":2,
|
|
"Li":3,
|
|
"Be":4,
|
|
"B":5,
|
|
"C":6,
|
|
"N":7,
|
|
"O":8,
|
|
"F":9,
|
|
"Ne":10,
|
|
"Na":11,
|
|
"Mg":12,
|
|
"Al":13,
|
|
"Si":14,
|
|
"P":15,
|
|
"S":16,
|
|
"Cl":17,
|
|
"Ar":18,
|
|
"K":19,
|
|
"Ca":20,
|
|
"Sc":21,
|
|
"Ti":22,
|
|
"V":23,
|
|
"Cr":24,
|
|
"Mn":25,
|
|
"Fe":26,
|
|
"Co":27,
|
|
"Ni":28,
|
|
"Cu":29,
|
|
"Zn":30,
|
|
"Ga":31,
|
|
"Ge":32,
|
|
"As":33,
|
|
"Se":34,
|
|
"Br":35,
|
|
"Kr":36,
|
|
"Rb":37,
|
|
"Sr":38,
|
|
"Y":39,
|
|
"Zr":40,
|
|
"Nb":41,
|
|
"Mo":42,
|
|
"Tc":43,
|
|
"Ru":44,
|
|
"Rh":45,
|
|
"Pd":46,
|
|
"Ag":47,
|
|
"Cd":48,
|
|
"In":49,
|
|
"Sn":50,
|
|
"Sb":51,
|
|
"Te":52,
|
|
"I":53,
|
|
"Xe":54,
|
|
"Cs":55,
|
|
"Ba":56,
|
|
"La":57,
|
|
"Ce":58,
|
|
"Pr":59,
|
|
"Nd":60,
|
|
"Pm":61,
|
|
"Sm":62,
|
|
"Eu":63,
|
|
"Gd":64,
|
|
"Tb":65,
|
|
"Dy":66,
|
|
"Ho":67,
|
|
"Er":68,
|
|
"Tm":69,
|
|
"Yb":70,
|
|
"Lu":71,
|
|
"Hf":72,
|
|
"Ta":73,
|
|
"W":74,
|
|
"Re":75,
|
|
"Os":76,
|
|
"Ir":77,
|
|
"Pt":78,
|
|
"Au":79,
|
|
"Hg":80,
|
|
"Tl":81,
|
|
"Pb":82,
|
|
"Bi":83,
|
|
"Po":84,
|
|
"At":85,
|
|
"Rn":86,
|
|
"Fr":87,
|
|
"Ra":88,
|
|
"Ac":89,
|
|
"Th":90,
|
|
"Pa":91,
|
|
"U":92,
|
|
"":0.0000
|
|
}
|
|
return ElementsZ[Element];
|
|
}
|
|
|
|
function Massof(Element)
|
|
{
|
|
var ElementsA = {
|
|
"Muon":0.113,
|
|
"Li8":8.0,
|
|
"B12":12.0,
|
|
"H":1.00800,
|
|
"He":4.00300,
|
|
"Li":6.93900,
|
|
"Be":9.01200,
|
|
"B":10.81100,
|
|
"C":12.01100,
|
|
"N":14.00700,
|
|
"O":15.99900,
|
|
"F":18.99800,
|
|
"Ne":20.18300,
|
|
"Na":22.99000,
|
|
"Mg":24.31200,
|
|
"Al":26.98200,
|
|
"Si":28.08600,
|
|
"P":30.97400,
|
|
"S":32.06400,
|
|
"Cl":35.45300,
|
|
"Ar":39.94800,
|
|
"K":39.10200,
|
|
"Ca":40.08000,
|
|
"Sc":44.95600,
|
|
"Ti":47.90000,
|
|
"V":50.94200,
|
|
"Cr":51.99600,
|
|
"Mn":54.93800,
|
|
"Fe":55.84700,
|
|
"Co":58.93300,
|
|
"Ni":58.71000,
|
|
"Cu":63.54000,
|
|
"Zn":65.37000,
|
|
"Ga":69.72000,
|
|
"Ge":72.59000,
|
|
"As":74.92200,
|
|
"Se":78.96000,
|
|
"Br":79.90900,
|
|
"Kr":83.80000,
|
|
"Rb":85.47000,
|
|
"Sr":87.62000,
|
|
"Y":88.90500,
|
|
"Zr":91.22000,
|
|
"Nb":92.90600,
|
|
"Mo":95.94000,
|
|
"Tc":98.00000,
|
|
"Ru":101.07000,
|
|
"Rh":102.90500,
|
|
"Pd":106.40000,
|
|
"Ag":107.87000,
|
|
"Cd":112.40000,
|
|
"In":114.82000,
|
|
"Sn":118.69000,
|
|
"Sb":121.75000,
|
|
"Te":127.60000,
|
|
"I":126.90400,
|
|
"Xe":131.30000,
|
|
"Cs":132.90500,
|
|
"Ba":137.34000,
|
|
"La":138.91000,
|
|
"Ce":140.12000,
|
|
"Pr":140.90700,
|
|
"Nd":144.24001,
|
|
"Pm":147.00000,
|
|
"Sm":150.35001,
|
|
"Eu":151.96001,
|
|
"Gd":157.25000,
|
|
"Tb":158.92400,
|
|
"Dy":162.50000,
|
|
"Ho":164.92999,
|
|
"Er":167.25999,
|
|
"Tm":168.93401,
|
|
"Yb":173.03999,
|
|
"Lu":174.97000,
|
|
"Hf":178.49001,
|
|
"Ta":180.94800,
|
|
"W":183.85001,
|
|
"Re":186.20000,
|
|
"Os":190.20000,
|
|
"Ir":192.20000,
|
|
"Pt":195.09000,
|
|
"Au":196.96700,
|
|
"Hg":200.59000,
|
|
"Tl":204.37000,
|
|
"Pb":207.19000,
|
|
"Bi":208.98000,
|
|
"Po":210.00000,
|
|
"At":210.00000,
|
|
"Rn":222.00000,
|
|
"Fr":223.00000,
|
|
"Ra":226.00000,
|
|
"Ac":227.00000,
|
|
"Th":232.03799,
|
|
"Pa":231.00000,
|
|
"U":238.03000,
|
|
"":0.0000
|
|
}
|
|
return ElementsA[Element];
|
|
}
|
|
|
|
function Elastof(Element) {
|
|
var Elast ={
|
|
"H":0.10000,
|
|
"He":0.10000,
|
|
"Li":1.63000,
|
|
"Be":3.32000,
|
|
"B":5.77000,
|
|
"C":7.37000,
|
|
"N":4.92000,
|
|
"O":2.60000,
|
|
"F":0.84000,
|
|
"Ne":0.02000,
|
|
"Na":1.11000,
|
|
"Mg":1.51000,
|
|
"Al":3.39000,
|
|
"Si":4.63000,
|
|
"P":3.43000,
|
|
"S":2.85000,
|
|
"Cl":1.40000,
|
|
"Ar":0.08000,
|
|
"K":0.93000,
|
|
"Ca":1.84000,
|
|
"Sc":3.90000,
|
|
"Ti":4.85000,
|
|
"V":5.31000,
|
|
"Cr":4.10000,
|
|
"Mn":2.92000,
|
|
"Fe":4.28000,
|
|
"Co":4.39000,
|
|
"Ni":4.44000,
|
|
"Cu":3.49000,
|
|
"Zn":1.35000,
|
|
"Ga":2.81000,
|
|
"Ge":3.85000,
|
|
"As":2.96000,
|
|
"Se":2.25000,
|
|
"Br":1.22000,
|
|
"Kr":0.12000,
|
|
"Rb":0.85000,
|
|
"Sr":1.72000,
|
|
"Y":4.37000,
|
|
"Zr":6.25000,
|
|
"Nb":7.57000,
|
|
"Mo":6.82000,
|
|
"Tc":6.85000,
|
|
"Ru":6.74000,
|
|
"Rh":5.75000,
|
|
"Pd":3.89000,
|
|
"Ag":2.95000,
|
|
"Cd":1.16000,
|
|
"In":2.52000,
|
|
"Sn":3.14000,
|
|
"Sb":2.75000,
|
|
"Te":2.23000,
|
|
"I":1.11000,
|
|
"Xe":0.16000,
|
|
"Cs":0.80000,
|
|
"Ba":1.90000,
|
|
"La":4.47000,
|
|
"Ce":4.32000,
|
|
"Pr":3.70000,
|
|
"Nd":3.40000,
|
|
"Pm":0.10000,
|
|
"Sm":2.14000,
|
|
"Eu":1.86000,
|
|
"Gd":4.14000,
|
|
"Tb":4.05000,
|
|
"Dy":3.04000,
|
|
"Ho":3.14000,
|
|
"Er":3.29000,
|
|
"Tm":2.42000,
|
|
"Yb":1.60000,
|
|
"Lu":4.43000,
|
|
"Hf":6.44000,
|
|
"Ta":8.10000,
|
|
"W":8.90000,
|
|
"Re":8.03000,
|
|
"Os":8.17000,
|
|
"Ir":6.94000,
|
|
"Pt":5.84000,
|
|
"Au":3.81000,
|
|
"Hg":0.67000,
|
|
"Tl":1.88000,
|
|
"Pb":2.03000,
|
|
"Bi":2.18000,
|
|
"Po":1.50000,
|
|
"At":0.10000,
|
|
"Rn":0.20000,
|
|
"Fr":0.10000,
|
|
"Ra":1.66000,
|
|
"Ac":4.25000,
|
|
"Th":6.20000,
|
|
"Pa":0.10000,
|
|
"U":5.55000,
|
|
"":0.00000
|
|
};
|
|
return Elast[Element];
|
|
}
|
|
|
|
function Stopicru(Element)
|
|
{
|
|
var Stopicru = {
|
|
"H":"1.25400,1.44000,242.60001,12000.00000,0.11590",
|
|
"He":"1.22900,1.39700,484.50000,5873.00000,0.05225",
|
|
"Li":"1.41100,1.60000,725.59998,3013.00000,0.04578",
|
|
"Be":"2.24800,2.59000,966.00000,153.80000,0.03475",
|
|
"B":"2.47400,2.81500,1206.00000,1060.00000,0.02855",
|
|
"C":"2.60100,2.60100,1701.00000,1279.00000,0.01638",
|
|
"N":"2.95400,3.35000,1683.00000,1900.00000,0.02513",
|
|
"O":"2.65200,3.00000,1920.00000,2000.00000,0.02230",
|
|
"F":"2.08500,2.35200,2157.00000,2634.00000,0.01816",
|
|
"Ne":"1.95100,2.19900,2393.00000,2699.00000,0.01568",
|
|
"Na":"2.54200,2.86900,2628.00000,1854.00000,0.01472",
|
|
"Mg":"3.79100,4.29300,2862.00000,1009.00000,0.01397",
|
|
"Al":"4.15400,4.73900,2766.00000,164.50000,0.02023",
|
|
"Si":"4.91400,5.59800,3193.00000,232.70000,0.01419",
|
|
"P":"3.23200,3.64700,3561.00000,1560.00000,0.01267",
|
|
"S":"3.44700,3.89100,3792.00000,1219.00000,0.01211",
|
|
"Cl":"5.30100,6.00800,3969.00000,645.09998,0.01183",
|
|
"Ar":"5.73100,6.50000,4253.00000,530.00000,0.01123",
|
|
"K":"5.15200,5.83300,4482.00000,545.70001,0.01129",
|
|
"Ca":"5.52100,6.25200,4710.00000,553.29999,0.01120",
|
|
"Sc":"5.20100,5.88400,4938.00000,560.90002,0.01000",
|
|
"Ti":"4.85800,5.48900,5260.00000,651.09998,0.00893",
|
|
"V":"4.47900,5.05500,5391.00000,952.29999,0.00912",
|
|
"Cr":"3.98300,4.48900,5616.00000,1336.00000,0.00841",
|
|
"Mn":"3.46900,3.90700,5725.00000,1461.00000,0.00883",
|
|
"Fe":"3.51900,3.96300,6065.00000,1243.00000,0.00778",
|
|
"Co":"3.14000,3.53500,6288.00000,1372.00000,0.00736",
|
|
"Ni":"3.55300,4.00400,6205.00000,555.09998,0.00876",
|
|
"Cu":"3.69600,4.19400,4649.00000,81.13000,0.02242",
|
|
"Zn":"4.21000,4.75000,6953.00000,295.20001,0.00681",
|
|
"Ga":"5.04100,5.69700,7137.00000,202.60001,0.00673",
|
|
"Ge":"5.55400,6.30000,6496.00000,110.00000,0.00969",
|
|
"As":"5.32300,6.01200,7611.00000,292.50000,0.00645",
|
|
"Se":"5.87400,6.65600,7395.00000,117.50000,0.00768",
|
|
"Br":"6.65800,7.53600,7694.00000,222.30000,0.00651",
|
|
"Kr":"6.41300,7.24000,11850.00000,153.70000,0.00288",
|
|
"Rb":"5.69400,6.42900,8478.00000,292.89999,0.00609",
|
|
"Sr":"6.33900,7.15900,8693.00000,330.29999,0.00600",
|
|
"Y":"6.40700,7.23400,8907.00000,367.79999,0.00589",
|
|
"Zr":"6.73400,7.60300,9120.00000,405.20001,0.00576",
|
|
"Nb":"6.90100,7.79100,9333.00000,442.70001,0.00559",
|
|
"Mo":"6.42400,7.24800,9545.00000,480.20001,0.00538",
|
|
"Tc":"6.79900,7.67100,9756.00000,517.59998,0.00532",
|
|
"Ru":"6.10900,6.88700,9966.00000,555.09998,0.00515",
|
|
"Rh":"5.92400,6.67700,10180.00000,592.50000,0.00492",
|
|
"Pd":"5.23800,5.90000,10380.00000,630.00000,0.00476",
|
|
"Ag":"5.34500,6.03800,6790.00000,397.79999,0.01676",
|
|
"Cd":"5.81400,6.55400,10800.00000,355.50000,0.00463",
|
|
"In":"6.22900,7.02400,11010.00000,370.89999,0.00454",
|
|
"Sn":"6.40900,7.22700,11210.00000,386.39999,0.00447",
|
|
"Sb":"7.50000,8.48000,8608.00000,348.00000,0.00907",
|
|
"Te":"6.97900,7.87100,11620.00000,392.39999,0.00440",
|
|
"I":"7.72500,8.71600,11830.00000,394.79999,0.00438",
|
|
"Xe":"8.33700,9.42500,10510.00000,269.60001,0.00621",
|
|
"Cs":"7.28700,8.21800,12230.00000,399.70001,0.00445",
|
|
"Ba":"7.89900,8.91100,12430.00000,402.10001,0.00451",
|
|
"La":"8.04100,9.07100,12630.00000,404.50000,0.00454",
|
|
"Ce":"7.48800,8.44400,12830.00000,406.89999,0.00442",
|
|
"Pr":"7.29100,8.21900,13030.00000,409.29999,0.00430",
|
|
"Nd":"7.09800,8.00000,13230.00000,411.79999,0.00418",
|
|
"Pm":"6.90900,7.78600,13430.00000,414.20001,0.00406",
|
|
"Sm":"6.72800,7.58000,13620.00000,416.60001,0.00398",
|
|
"Eu":"6.55100,7.38000,13820.00000,419.00000,0.00388",
|
|
"Gd":"6.73900,7.59200,14020.00000,421.39999,0.00386",
|
|
"Tb":"6.21200,6.99600,14210.00000,423.89999,0.00372",
|
|
"Dy":"5.51700,6.21000,14400.00000,426.29999,0.00363",
|
|
"Ho":"5.22000,5.87400,14600.00000,428.70001,0.00350",
|
|
"Er":"5.07100,5.70600,14790.00000,433.00000,0.00341",
|
|
"Tm":"4.92600,5.54200,14980.00000,433.50000,0.00334",
|
|
"Yb":"4.78800,5.38600,15170.00000,435.89999,0.00329",
|
|
"Lu":"4.89300,5.50500,15360.00000,438.29999,0.00324",
|
|
"Hf":"5.02800,5.65700,15550.00000,440.79999,0.00320",
|
|
"Ta":"4.73800,5.32900,15740.00000,443.20001,0.00319",
|
|
"W":"4.58700,5.16000,15410.00000,415.29999,0.00341",
|
|
"Re":"5.20100,5.85100,16120.00000,441.60001,0.00312",
|
|
"Os":"5.07100,5.70400,16300.00000,440.89999,0.00308",
|
|
"Ir":"4.94600,5.56300,16490.00000,440.10001,0.00296",
|
|
"Pt":"4.47700,5.03400,16670.00000,439.29999,0.00287",
|
|
"Au":"4.84400,5.45800,7852.00000,975.79999,0.02077",
|
|
"Hg":"4.30700,4.84300,17040.00000,487.79999,0.00288",
|
|
"Tl":"4.72300,5.31100,17220.00000,537.00000,0.00291",
|
|
"Pb":"5.31900,5.98200,17400.00000,586.29999,0.00287",
|
|
"Bi":"5.95600,6.70000,17800.00000,677.00000,0.00266",
|
|
"Po":"6.15800,6.92800,17770.00000,586.29999,0.00281",
|
|
"At":"6.20300,6.97900,17950.00000,586.29999,0.00278",
|
|
"Rn":"6.18100,6.95400,18120.00000,586.29999,0.00275",
|
|
"Fr":"6.94900,7.82000,18300.00000,586.29999,0.00274",
|
|
"Ra":"7.50600,8.44800,18480.00000,586.29999,0.00273",
|
|
"Ac":"7.64800,8.60900,18660.00000,586.29999,0.00270",
|
|
"Th":"7.71100,8.67900,18830.00000,586.29999,0.00264",
|
|
"Pa":"7.40700,8.33600,19010.00000,586.29999,0.00260",
|
|
"U":"7.29000,8.20400,19180.00000,586.29999,0.00267",
|
|
"":"0.00000,0.00000,0.00000,0.00000,0.00000"
|
|
};
|
|
return Stopicru[Element];
|
|
}
|
|
|
|
|
|
function rho_fun()
|
|
{
|
|
var irow = this.parentNode.parentNode.rowIndex;
|
|
var caller = this.id;
|
|
var chem = document.getElementById(caller).value;
|
|
var rhoLi = "L"+irow+"rho";
|
|
|
|
var rhos = {
|
|
"NbN":8.47,
|
|
"Bi2Se3":7.51,
|
|
"La2CuO4": 7.08,
|
|
"La1.84Sr0.16CuO4": 6.94,
|
|
"N2":1.145,
|
|
"ZnO":5.61,
|
|
"ZnSe":5.26,
|
|
"ZnS":4.09,
|
|
"ZrO":6.0,
|
|
"Gd3Ga5O12":7.08,
|
|
"MgAl2O4":3.60,
|
|
"NdGaO3":7.57,
|
|
"YAlO3":4.88,
|
|
"Y3Al5O12":4.55,
|
|
"LiF":2.60,
|
|
"CaF2":3.18,
|
|
"BaFe":4.83,
|
|
"MgF2":3.18,
|
|
"SiO2":2.65,
|
|
"TiO2":4.26,
|
|
"KTaO3":6.967,
|
|
"LaAlO3":6.70,
|
|
"Al2O3":3.98,
|
|
"SrTiO3":5.12,
|
|
"SrLaGaO4":6.389,
|
|
"SrLaAlO4":5.924,
|
|
"NbSe2":6.30,
|
|
"MgO":3.58,
|
|
"YBa2Cu3O7":6.54,
|
|
"GaAs":5.32,
|
|
"C60":1.65,
|
|
"H":0.08,
|
|
"He":0.12,
|
|
"Li":0.53,
|
|
"Be":1.85,
|
|
"B":2.34,
|
|
"C":2.26,
|
|
"N":1.03,
|
|
"O":2.00,
|
|
"F":1.11,
|
|
"Ne":1.50,
|
|
"Na":0.97,
|
|
"Mg":1.74,
|
|
"Al":2.7,
|
|
"Si":2.33,
|
|
"P":1.00,
|
|
"S":2.07,
|
|
"Cl":2.03,
|
|
"Ar":1.77,
|
|
"K":0.86,
|
|
"Ca":1.55,
|
|
"Sc":2.99,
|
|
"Ti":4.54,
|
|
"V":6.11,
|
|
"Cr":7.19,
|
|
"Mn":7.43,
|
|
"Fe":7.87,
|
|
"Co":8.9,
|
|
"Ni":8.9,
|
|
"Cu":8.96,
|
|
"Zn":7.13,
|
|
"Ga":5.91,
|
|
"Ge":5.32,
|
|
"As":5.72,
|
|
"Se":4.79,
|
|
"Br":3.14,
|
|
"Kr":3.10,
|
|
"Rb":1.53,
|
|
"Sr":2.54,
|
|
"Y":4.47,
|
|
"Zr":6.51,
|
|
"Nb":8.57,
|
|
"Mo":10.22,
|
|
"Tc":11.5,
|
|
"Ru":12.37,
|
|
"Rh":12.41,
|
|
"Pd":12.02,
|
|
"Ag":10.5,
|
|
"Cd":8.65,
|
|
"In":7.31,
|
|
"Sn":7.31,
|
|
"Sb":6.68,
|
|
"Te":6.24,
|
|
"I":4.93,
|
|
"Xe":3.80,
|
|
"Cs":1.90,
|
|
"Ba":3.59,
|
|
"La":6.15,
|
|
"Ce":6.77,
|
|
"Pr":6.77,
|
|
"Nd":7.01,
|
|
"Pm":7.22,
|
|
"Sm":7.52,
|
|
"Eu":5.24,
|
|
"Gd":7.9,
|
|
"Tb":8.23,
|
|
"Dy":8.55,
|
|
"Ho":8.8,
|
|
"Er":9.07,
|
|
"Tm":9.32,
|
|
"Yb":6.9,
|
|
"Lu":9.84,
|
|
"Hf":13.31,
|
|
"Ta":16.65,
|
|
"W":19.35,
|
|
"Re":21.04,
|
|
"Os":22.6,
|
|
"Ir":22.4,
|
|
"Pt":21.45,
|
|
"Au":19.32,
|
|
"Hg":13.55,
|
|
"Tl":11.85,
|
|
"Pb":11.35,
|
|
"Bi":9.75,
|
|
"Po":9.3,
|
|
"Th":11.72,
|
|
"Pa":15.4,
|
|
"U":18.95,
|
|
"":""
|
|
}
|
|
document.getElementById(rhoLi).value = rhos[chem];
|
|
}
|
|
|
|
function openTab(event, tabName) {
|
|
// Declare all variables
|
|
var i, tabcontent, tablinks;
|
|
// Get all elements with class="tabcontent" and hide them
|
|
tabcontent = document.getElementsByClassName("tabcontent");
|
|
for (i = 0; i < tabcontent.length; i++) {
|
|
tabcontent[i].style.display = "none";
|
|
}
|
|
|
|
// Get all elements with class="tablinks" and remove the class "active"
|
|
tablinks = document.getElementsByClassName("tablinks");
|
|
for (i = 0; i < tablinks.length; i++) {
|
|
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
|
}
|
|
|
|
// Show the current tab, and add an "active" class to the button that opened the tab
|
|
document.getElementById(tabName).style.display = "block";
|
|
event.currentTarget.className += " active";
|
|
}
|
|
|
|
function adjust_table()
|
|
{
|
|
var numLayer = document.getElementById("numLayer").value;
|
|
var LTable = document.getElementById("LTable");
|
|
var Nrows = LTable.rows.length;
|
|
|
|
var Comps = [];
|
|
var Rhos = [];
|
|
var Ds = [];
|
|
|
|
// Need to loop to get the right number of rows when reloading
|
|
if (numLayer >= Nrows) {
|
|
for (i = Nrows;i<=numLayer;i++) {
|
|
var row = LTable.insertRow(i);
|
|
var Li = row.insertCell(0);
|
|
Li.innerHTML = i;
|
|
var compL = row.insertCell(1);
|
|
var compCell = document.createElement("input");
|
|
compCell.id = "L"+i+"Comp";
|
|
compCell.name = "L"+i+"Comp";
|
|
compCell.size = 15;
|
|
compCell.onchange = rho_fun;
|
|
if (Comps[i-1]) {compCell.value = Comps[i-1];}else{compCell.value = 'SrTiO3';}
|
|
compL.appendChild(compCell);
|
|
var rhoL = row.insertCell(2);
|
|
var rhoCell = document.createElement("input");
|
|
rhoCell.id = "L"+i+"rho";
|
|
rhoCell.name = "L"+i+"rho";
|
|
rhoCell.size = 5;
|
|
rhoL.appendChild(rhoCell);
|
|
if (Rhos[i-1]) {rhoCell.value = Rhos[i-1];}else{rhoCell.value = '5.12';}
|
|
var thickL = row.insertCell(3);
|
|
var thickCell = document.createElement("input");
|
|
thickCell.id = "L"+i+"d";
|
|
thickCell.name = "L"+i+"d";
|
|
thickCell.size = 7;
|
|
thickL.appendChild(thickCell);
|
|
if (Ds[i-1]) {thickCell.value = Ds[i-1];}else{thickCell.value = '10000';}
|
|
}
|
|
} else {
|
|
for (i = Nrows-1;i>numLayer;i--) {
|
|
LTable.deleteRow(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
function adjust_scans()
|
|
{
|
|
// Deal with scans checkbox and type
|
|
var scanSeq = document.getElementById("scanSeq").checked;
|
|
var sender = document.getElementById("scanSeq");
|
|
var scanType = document.getElementById("scanType").value;
|
|
// consider only if scans checkbox is checked
|
|
if (scanSeq) {
|
|
// Which type of scan
|
|
if (scanType == "scanLoop") {
|
|
ShowHide(1,'ScansTable');
|
|
ShowHide(0,'ScansLine');
|
|
} else {
|
|
ShowHide(1,'ScansLine');
|
|
ShowHide(0,'ScansTable');
|
|
}
|
|
} else {
|
|
// Hide both
|
|
ShowHide(0,'ScansTable');
|
|
ShowHide(0,'ScansLine');
|
|
}
|
|
}
|
|
|
|
function ProjSmartDefaults()
|
|
{
|
|
var Proj = document.getElementById("ProjType").value;
|
|
var sigEnergy = document.getElementById("sigEnergy");
|
|
var sigAngle = document.getElementById("sigAngle");
|
|
|
|
if (Proj == "Muon") {
|
|
sigEnergy.value = "450";
|
|
sigAngle.value = "15";
|
|
} else {
|
|
sigEnergy.value = "0";
|
|
sigAngle.value = "0";
|
|
}
|
|
}
|
|
|
|
function ProjNumberLimit()
|
|
{
|
|
var numberProj = document.getElementById("numberProj").value;
|
|
|
|
if (numberProj > 5000) {
|
|
alert("Maximum number is 5000");
|
|
document.getElementById("numberProj").value = 5000;
|
|
}
|
|
}
|
|
|
|
|
|
function ShowHide(onoff,item) {
|
|
// this function can switch item to visible/hidden onoff=1/0
|
|
if(onoff){
|
|
// document.getElementById(item).style.display = 'block';
|
|
document.getElementById(item).style.visibility = "visible";
|
|
} else {
|
|
// document.getElementById(item).style.display = 'none';
|
|
document.getElementById(item).style.visibility = "hidden";
|
|
}
|
|
}
|
|
|
|
function prep_cfg(toggle) {
|
|
// This function collects various values and returns
|
|
// toggle=1 : returns object with all values
|
|
// toggle!=1 : returns string containing cfg file
|
|
let TrimSPcfg = "";
|
|
let strtmp = "";
|
|
let valtmp = "";
|
|
|
|
let All = new Object();
|
|
|
|
// Prepare Layers section
|
|
let LayersSec = "[Layers]\n";
|
|
let numLayer = document.getElementById("numLayer").value;
|
|
All['numLayer']=numLayer;
|
|
LayersSec = LayersSec + "numLayer="+numLayer+"\n";
|
|
for (i = 1;i<=numLayer;i++) {
|
|
strtmp = "L"+i+"Comp";
|
|
valtmp = document.getElementById(strtmp).value;
|
|
All[strtmp]=valtmp;
|
|
LayersSec = LayersSec + strtmp +"="+ valtmp+"\n";
|
|
strtmp = "L"+i+"rho";
|
|
valtmp = document.getElementById(strtmp).value;
|
|
All[strtmp]=valtmp;
|
|
LayersSec = LayersSec + strtmp +"="+ valtmp+"\n";
|
|
strtmp = "L"+i+"d";
|
|
valtmp = document.getElementById(strtmp).value;
|
|
All[strtmp]=valtmp;
|
|
LayersSec = LayersSec + strtmp +"="+ valtmp+"\n";
|
|
}
|
|
|
|
// Prepare projectile parameters section
|
|
let parProj = ["workPath","fileNamePrefix","ProjType","numberProj","z0","dz","valEnergy","sigEnergy","valAngle","sigAngle","ranSeed"];
|
|
let ProjSec = "[ProjectileParameters]\n";
|
|
for (key of parProj) {
|
|
All[key]= document.getElementById(key).value;
|
|
ProjSec = ProjSec + key + "=" + All[key] + "\n";
|
|
}
|
|
|
|
// Prepare Files section
|
|
let FilesSec = "[Files]\n";
|
|
FilesSec = FilesSec + "fileNamePrefix="+All["fileNamePrefix"]+"\nworkPath="+All["workPath"]+"\n";
|
|
|
|
// Prepare ScanSequence section
|
|
let ScanSec = "[ScanSequence]\n";
|
|
strtmp = "scanSeq";
|
|
valtmp = 1*(document.getElementById(strtmp).checked);
|
|
All[strtmp]=valtmp;
|
|
ScanSec = ScanSec + strtmp +"="+ valtmp+"\n";
|
|
let parScan = ["comboScan","scanType","scanFrom","scanStep","scanTo","scanList","scanListdz"];
|
|
for (key of parScan) {
|
|
All[key]= document.getElementById(key).value;
|
|
ScanSec = ScanSec + key + "=" + All[key] + "\n";
|
|
}
|
|
|
|
// Collect other parameters
|
|
let parOther = ["parEF", "parESB", "parSHEATH", "parERC", "parRD", "parCA", "parKK0", "parKK0R", "parKDEE1", "parKDEE2", "parIPOT", "parIPOTR", "parIRL"];
|
|
for (key of parOther) {
|
|
All[key]= document.getElementById(key).value;
|
|
}
|
|
|
|
// Construct full content of cfg file
|
|
TrimSPcfg = FilesSec + LayersSec + ProjSec + ScanSec;
|
|
if (toggle) {
|
|
return All;
|
|
} else {
|
|
return TrimSPcfg;
|
|
}
|
|
}
|
|
|
|
function setValues(content) {
|
|
// This function takes cfg file content and substitutes values in the GUI
|
|
// Split file content into lines
|
|
var event = new Event('change');
|
|
var lines = content.toString().split('\n');
|
|
// Remove comment lines, empty lines and those starting with "["
|
|
var PATTERN= /^(?!\[)(?!\#)(\S)/,
|
|
flines = lines.filter(function (str) {return PATTERN.test(str);});
|
|
for (var i=0; i<flines.length; i++) {
|
|
// Loop over parameters, set appropriate values and trigger associated onChange
|
|
var param=flines[i].replace(/\s+/,'').split('=');
|
|
if (param[0] == 'scanSeq') {
|
|
// This is a checkbox
|
|
var seqChecked = true;
|
|
if (param[1] == 0) {seqChecked = false;}
|
|
document.getElementById(param[0]).checked = seqChecked;
|
|
document.getElementById(param[0]).dispatchEvent(event);
|
|
} else {
|
|
document.getElementById(param[0]).value = param[1];
|
|
document.getElementById(param[0]).dispatchEvent(event);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function CreateInpFile(All) {
|
|
// Create and return input file for the Trim.SP simulation binary
|
|
// Takes object All as input for all relevant parameters
|
|
|
|
// This is the form of the begining of the input file:
|
|
var TemplateFile= " ProjZ ProjAM valEnergy sigEnergy valAngle sigAngle parEF parESB parSHEATH parERC\n numberProj ranSeed ranSeed ranSeed z0 parRD dz parCA parKK0 parKK0R parKDEE1 parKDEE2 parIPOT parIPOTR parIRL";
|
|
|
|
// Then comes the number of layers (new format) for example 4 layers:
|
|
// N_Layers=4
|
|
TemplateFile=TemplateFile+"\n"+"N_Layers=numLayer";
|
|
|
|
// Then loop over the layers and for each give the following structure
|
|
var TemplateLayer= "L1d L1rho L1CK\n L1ELZ1 L1ELZ2 L1ELZ3 L1ELZ4 L1ELZ5\n L1ELW1 L1ELW2 L1ELW3 L1ELW4 L1ELW5\n L1ELC1 L1ELC2 L1ELC3 L1ELC4 L1ELC5\n L1ELE1 L1ELE2 L1ELE3 L1ELE4 L1ELE5\n L10301 L10302 L10303 L10304 L10305\n 0.0000 0.0000 0.0000 0.0000 0.0000\n L1ELST11 L1ELST21 L1ELST31 L1ELST41 L1ELST51\n L1ELST12 L1ELST22 L1ELST32 L1ELST42 L1ELST52\n L1ELST13 L1ELST23 L1ELST33 L1ELST43 L1ELST53\n L1ELST14 L1ELST24 L1ELST34 L1ELST44 L1ELST54\n L1ELST15 L1ELST25 L1ELST35 L1ELST45 L1ELST55";
|
|
|
|
let projectile = All['ProjType'];
|
|
All['ProjZ']=Zof(projectile);
|
|
All['ProjAM']=Massof(projectile);
|
|
|
|
// This is the flag for checking layers
|
|
let Check=0;
|
|
let Layer='';
|
|
let Li='';
|
|
|
|
// This containes mapped object pairs of original:replace
|
|
let repAll = new Object();
|
|
// Loop over layers an create appropriate values
|
|
for (var i=1; i<=All['numLayer'];i++){
|
|
Li = 'L'+i;
|
|
Layer = TemplateLayer;
|
|
Layer = Layer.replace(/L1/g,Li);
|
|
TemplateFile = TemplateFile+"\n"+Layer;
|
|
Check=0;
|
|
// Composition of layers
|
|
let LComp="L"+i+"Comp";
|
|
let Comp = document.getElementById(LComp).value;
|
|
All[LComp] = Comp;
|
|
let LElComp=parse_formula(Comp);
|
|
for (key of Object.keys(LElComp)) {
|
|
// Check if composition is understood
|
|
if (key=="" || Zof(key)=="") {
|
|
Check++;
|
|
}
|
|
}
|
|
if (Comp == "") {Check++;}
|
|
// Write composition to results file header
|
|
|
|
// Densities of layers
|
|
let Lrho="layer"+i+"rho";
|
|
let rho = 1*All[Lrho];
|
|
// How to do this? All[Lrho]=sprintf("%6.2f",rho);
|
|
if (rho=="") {Check++;}
|
|
|
|
// Thickness of layers
|
|
let Ld ="L"+i+"d";
|
|
let d = All[Ld];
|
|
// How to do this? All[Ld]=sprintf("%8.2f",d);
|
|
if (d=="") {Check++;}
|
|
|
|
// Sanity check, is the layer supposed to have value? are they all there?
|
|
if (Check!=0) {
|
|
ErrMsg="Error: Bad chemical formula in Layer $i.\nPleach check!\n";
|
|
//print STDERR $ErrMsg;
|
|
return ErrMsg;
|
|
}
|
|
|
|
let tmp = "L"+i+"CK";
|
|
All[tmp]=1.0; // sprintf("%6.2f",1.0);
|
|
|
|
let Sum = 0;
|
|
for (key of Object.keys(LElComp)) {
|
|
Sum=Sum+LElComp[key];
|
|
}
|
|
if (Sum==0) {Sum=1;}
|
|
|
|
let Els = Object.keys(LElComp);
|
|
|
|
for (let NEl=1;NEl<=5;NEl++) {
|
|
let El = "";
|
|
if (NEl <= Els.length) {
|
|
El = Els[NEl-1];
|
|
}
|
|
let LEkey = "L"+i+"EL";
|
|
let ElZ = Zof(El);
|
|
let ElW = Massof(El);
|
|
let ElC = 0;
|
|
if (LElComp[El] != null){ElC=LElComp[El]/Sum;}
|
|
let ElE = Elastof(El);
|
|
let El030 = 30;
|
|
if (El=="") { El030 = 0.0;}
|
|
|
|
All[LEkey+"Z"+NEl]=ElZ; // sprintf("%8.4f",$ElZ);
|
|
All[LEkey+"W"+NEl]=ElW; // sprintf("%8.4f",$ElW);
|
|
All[LEkey+"C"+NEl]=ElC; // sprintf("%8.4f",$ElC);
|
|
All[LEkey+"E"+NEl]=ElE; // sprintf("%8.4f",$ElE);
|
|
All["L"+i+"030"+NEl]=El030; // sprintf("%8.4f",$El030);
|
|
|
|
let ElST = Stopicru(El);
|
|
let ElSTs = ElST.split(',');
|
|
let j=1;
|
|
for (let iElST of ElSTs) {
|
|
LEkey = "L"+i+"ELST"+NEl+j;
|
|
j++;
|
|
All[LEkey]=iElST; // sprintf("%11.6f",$_);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let key of Object.keys(All)) {
|
|
if (All[key]!=null){
|
|
if (key=="ranSeed") {
|
|
// Seed repeats three times
|
|
TemplateFile = TemplateFile.replace(/ranSeed/g,All[key]);
|
|
} else {
|
|
TemplateFile = TemplateFile.replace(key,All[key]);
|
|
}
|
|
}
|
|
}
|
|
return TemplateFile;
|
|
}
|
|
|
|
function replaceAll(str,mapObj){
|
|
// Takes string str and replaces all mapped objects in it
|
|
// The mapped object are pairs of original:replace
|
|
var re = new RegExp(Object.keys(mapObj).join("|"),"gi");
|
|
|
|
return str.replace(re, function(matched){
|
|
return mapObj[matched.toLowerCase()];
|
|
});
|
|
}
|
|
|
|
function sum(array){
|
|
// Takes and array and returns the sum of its elements
|
|
let sum_array = array.reduce(function(a, b){
|
|
return a + b;
|
|
}, 0);
|
|
return sum_array;
|
|
}
|
|
|
|
function startSequence(All) {
|
|
let cmd = '';
|
|
|
|
// Check if workPath exists otherwise create it
|
|
checkDir(All['workPath']); // from TrimSPelec.js, Electron/Node specific
|
|
|
|
let Progress =0;
|
|
// document.getElementById("myBar").style.width = Progress + "%";
|
|
// document.getElementById("myBar").innerHTML = Progress + "%";
|
|
|
|
// This is a flag to indicate whether the lists of values and inclements are the same size
|
|
All["SdzFlag"]=0;
|
|
var SValues = [];
|
|
if (All["scanSeq"]) {
|
|
// For multiple runs or a scan
|
|
if (All["scanType"]=="scanVals") {
|
|
var SValues=All["scanList"].split(/,/);
|
|
var SdzValues=All["scanListdz"].split(/,/);
|
|
if (SValues.length == SdzValues.length) {All["SdzFlag"]=1;}
|
|
} else {
|
|
for (let Val=parseInt(All["scanFrom"]);Val<=parseInt(All["scanTo"]);Val=Val+parseInt(All["scanStep"])) {
|
|
SValues.push(Val);
|
|
}
|
|
}
|
|
|
|
let ScanName = "";
|
|
let ScanAttrib = "";
|
|
ScanName = "E";
|
|
ScanAttrib = "valEnergy";
|
|
if (All["comboScan"]==1) {
|
|
ScanName = "SigE";
|
|
ScanAttrib = "sigEnergy";
|
|
} else if (All["comboScan"]==2) {
|
|
ScanName = "Angle";
|
|
ScanAttrib = "valAngle";
|
|
} else if (All["comboScan"]==3) {
|
|
ScanName = "SigAngle";
|
|
ScanAttrib = "sigAngle";
|
|
} else if (All["comboScan"]==4) {
|
|
ScanName = "N";
|
|
ScanAttrib = "numberProj";
|
|
} else if (All["comboScan"]==5) {
|
|
ScanName = "Ld"+All["scandL"];
|
|
ScanAttrib = "L"+All["scandL"]+"d";
|
|
}
|
|
|
|
let iScan=0;
|
|
for (var SValue of SValues) {
|
|
document.getElementById(ScanAttrib).value = SValue;
|
|
All[ScanAttrib]=SValue;
|
|
if ( All["SdzFlag"] == 1) {
|
|
if (All["comboScan"]=="Energy") {
|
|
document.getElementById(ScanAttrib).value = SdzValues[iScan];
|
|
} else if (All["comboScan"]=="") {
|
|
document.getElementById(ScanAttrib).value = SdzValues[iScan];
|
|
}
|
|
}
|
|
let eingabe1=CreateInpFile(All);
|
|
if (eingabe1=="ERROR") {return(0);}
|
|
let FILENAME=All["workPath"]+"/"+All["fileNamePrefix"]+"_"+ScanName+SValue;
|
|
writeAsciiFile(FILENAME+".inp",eingabe1)
|
|
// Use Linux version
|
|
Progress=Progress+90/SValues.length;
|
|
// Update GUI progress bar
|
|
let path = process.env.PWD;
|
|
cmd = "cd "+All["workPath"]+";cp "+FILENAME+".inp eingabe1.inp;trimspNL"; // Or use $ENV{'TRIMBIN'};
|
|
// document.getElementById("myBar").style.width = Progress + "%";
|
|
// document.getElementById("myBar").innerHTML = Progress + "%";
|
|
// Execute command
|
|
execute(cmd);
|
|
|
|
for (let ext of [".err",".out",".rge"]) {
|
|
cmd = "cd "+All["workPath"]+";mv -f ausgabe1"+ext+" "+FILENAME+ext;
|
|
execute(cmd);
|
|
}
|
|
let [cols,data]= readDatFile(FILENAME+".rge");
|
|
// convert depth to nm and normalize stopping profile
|
|
let depth=data[0];
|
|
let nmuons=data[1];
|
|
let dz = (depth[1]-depth[0])/10;
|
|
let norm = dz*sum(nmuons)/100;
|
|
for (let i=0; i<depth.length; i++) {
|
|
depth[i]=depth[i]/10;
|
|
nmuons[i]=nmuons[i]/norm;
|
|
}
|
|
Plot_xy("plotRge",depth,nmuons,['Depth (nm)','Stopped muons (%/nm)',ScanName+'='+Number(SValue)/1000+'keV']);
|
|
// Read the sequence data
|
|
let [cfort,cdata]= readDatFile(All["workPath"]+"/fort.33");
|
|
let lyrs = [6]; // back scattered muons
|
|
for (let ilayer=18;ilayer<cdata.length;ilayer++){lyrs.push(ilayer);} // the rest of the layers
|
|
// Now loop over all
|
|
Plotly.purge("plotFrac")
|
|
for (let ilayer of lyrs) {
|
|
// Normalize
|
|
let idata = cdata[ilayer];
|
|
for (let i=0; i<idata.length; i++) {
|
|
idata[i]=100*idata[i]/cdata[4][i];
|
|
}
|
|
let chem = cfort[ilayer];
|
|
if (ilayer != 6) {
|
|
let LComp = "L"+(ilayer-17)+"Comp";
|
|
chem = All[LComp];
|
|
}
|
|
Plot_xy("plotFrac",cdata[0],cdata[ilayer],['E (keV)','Fraction of muons (%)',chem]);
|
|
}
|
|
iScan++;
|
|
}
|
|
} else {
|
|
// For a single run
|
|
let eingabe1=CreateInpFile(All);
|
|
if (eingabe1=="ERROR") {return(0);}
|
|
let FILENAME=All["workPath"]+"/"+All["fileNamePrefix"];
|
|
writeAsciiFile(FILENAME+".inp", eingabe1);
|
|
Progress=20;
|
|
// Update progress on GUI
|
|
let path = process.env.PWD;
|
|
cmd = "cd "+All["workPath"]+";cp "+FILENAME+".inp eingabe1.inp;trimspNL"; // Or use $ENV{'TRIMBIN'};
|
|
execute(cmd);
|
|
// document.getElementById("myBar").style.width = Progress + "%";
|
|
// document.getElementById("myBar").innerHTML = Progress + "%";
|
|
for (let ext of [".err",".out",".rge"]) {
|
|
cmd = "cd "+All["workPath"]+";mv -f ausgabe1"+ext+" "+FILENAME+ext;
|
|
execute(cmd);
|
|
}
|
|
Progress=90;
|
|
// Update progress on GUI
|
|
// document.getElementById("myBar").style.width = Progress + "%";
|
|
// document.getElementById("myBar").innerHTML = Progress + "%";
|
|
// Make plot (only fractions make sense)
|
|
let [cols,data]= readDatFile(FILENAME+".rge");
|
|
// convert depth to nm
|
|
let depth=data[0];
|
|
let nmuons=data[1];
|
|
let dz = (depth[1]-depth[0])/10;
|
|
let norm = dz*sum(nmuons)/100;
|
|
for (let i=0; i<depth.length; i++) {
|
|
depth[i]=depth[i]/10;
|
|
nmuons[i]=nmuons[i]/norm;
|
|
}
|
|
Plot_xy("plotRge",depth,nmuons,['Depth (nm)','Stopped muons (%/nm)','E='+All['valEnergy']+'eV']);
|
|
let [cfort,cdata]= readDatFile(All["workPath"]+"/fort.33");
|
|
let lyrs = [6]; // back scattered muons
|
|
for (let ilayer=18;ilayer<cdata.length;ilayer++){lyrs.push(ilayer);} // the rest of the layers
|
|
// Now loop over all
|
|
for (let ilayer of lyrs) {
|
|
// Normalize
|
|
let idata = cdata[ilayer];
|
|
for (let i=0; i<idata.length; i++) {
|
|
idata[i]=100*idata[i]/cdata[4][i];
|
|
}
|
|
let chem = cfort[ilayer];
|
|
if (ilayer != 6) {
|
|
let LComp = "L"+(ilayer-17)+"Comp";
|
|
chem = All[LComp];
|
|
}
|
|
Plot_xy("plotFrac",cdata[0],cdata[ilayer],['E (keV)','Fraction of muons (%)',chem]);
|
|
}
|
|
}
|
|
|
|
// An easy way to keep track of chemical formula is to replace impL_i by the corresponding chemical formula of layer i
|
|
let data = readAsciiFile(All["workPath"]+"/"+"fort.33");
|
|
let LComp = "";
|
|
let chem_formula = "";
|
|
let place_holder = "";
|
|
let re = new RegExp(place_holder,"g");
|
|
for (let i=1;i<=All["numLayer"];i++) {
|
|
LComp = "L"+i+"Comp";
|
|
chem_formula = All[LComp];
|
|
place_holder = "impL"+i;
|
|
re = new RegExp(place_holder,"g");
|
|
data = data.replace(re, chem_formula);
|
|
}
|
|
let seq_file = All["workPath"]+"/"+All["fileNamePrefix"]+"_Seq_Results.dat";
|
|
writeAsciiFile(seq_file, data);
|
|
|
|
// Remove the fort.33 and other redundant files
|
|
cmd="cd "+All["workPath"]+";rm -f eingabe1.inp; rm -f fort.33";
|
|
execute(cmd);
|
|
Progress=100;
|
|
// document.getElementById("myBar").style.width = Progress + "%";
|
|
// document.getElementById("myBar").innerHTML = Progress + "%";
|
|
return(0);
|
|
}
|
|
|
|
function readDatFile(filename) {
|
|
// Read column data file and return
|
|
// cols - labels of columns
|
|
// data - 2D array with the columns
|
|
let lines = readAsciiFile(filename);
|
|
let data = [];
|
|
let i=0; // line counter
|
|
for (let line of lines.trim().split('\n')) {
|
|
// take labels from the first row
|
|
if (i==0) {
|
|
var cols = line.trim().split(/[#\s]+/g);
|
|
} else {
|
|
let words = line.trim().split(/[#\s]+/g);
|
|
for (let j=0; j<cols.length;j++) {
|
|
if (data[j] == null) {data[j]=[];}
|
|
data[j].push(parseFloat(words[j]));
|
|
}
|
|
}
|
|
i++;
|
|
}
|
|
return [cols,data];
|
|
}
|
|
|
|
function plotProfiles(filenames) {
|
|
// Plot rge files filenames
|
|
|
|
var win = window.open("", "_blank", "toolbar=no, menubar=no");
|
|
win.document.open();
|
|
win.document.write('<html><head><link rel="stylesheet" href="plotly.css"></head><body>');
|
|
win.document.write('<table style="width: 100%"><tr><td><div id="newPlot"><!-- Plotly chart will be drawn inside this DIV --></div></td></tr></table>');
|
|
win.document.write('</body></html>');
|
|
win.addEventListener('resize', sizePlot);
|
|
win.document.close();
|
|
var plotDiv=win.document.getElementById("newPlot");
|
|
|
|
// Extract energies from run files if available
|
|
var files= new Object();
|
|
var Es = [];
|
|
for (let i=0;i<filenames.length;i++) {
|
|
Es[i]=Number(filenames[i].substring(filenames[i].indexOf('_')+2,filenames[i].indexOf('.')));
|
|
files[Es[i]] = filenames[i];
|
|
}
|
|
// console.log(Es,files);
|
|
// Es=Es.sort();
|
|
// console.log(Es,files);
|
|
// console.log("sortFiles=",files[Es]);
|
|
|
|
// loop on sorted values and plot
|
|
for (let i=0;i<Es.length;i++) {
|
|
//console.log(Es[i],files[Es[i]]);
|
|
let [cols,data]= readDatFile(files[Es[i]]);
|
|
// convert depth to nm and normalize profile
|
|
let depth=data[0];
|
|
let nmuons=data[1];
|
|
let dz = (depth[1]-depth[0])/10;
|
|
let norm = dz*sum(nmuons)/100;
|
|
for (let i=0; i<depth.length; i++) {
|
|
depth[i]=depth[i]/10;
|
|
nmuons[i]=nmuons[i]/norm;
|
|
}
|
|
Plot_xy(plotDiv,depth,nmuons,['Depth (nm)','Stopped muons (%/nm)','E='+(Es[i]/1000)+'keV']);
|
|
}
|
|
|
|
}
|
|
|
|
function plotFractions(filename) {
|
|
// Plot fractions stopped in layers from sequence file
|
|
|
|
var win = window.open("", "_blank", "toolbar=no, menubar=no");
|
|
win.document.open();
|
|
win.document.write('<html><head><link rel="stylesheet" href="plotly.css"></head><body>');
|
|
win.document.write('<table style="width: 100%"><tr><td><div id="newPlot"><!-- Plotly chart will be drawn inside this DIV --></div></td></tr></table>');
|
|
win.document.write('</body></html>');
|
|
win.addEventListener('resize', sizePlot);
|
|
win.document.close();
|
|
var plotDiv=win.document.getElementById("newPlot");
|
|
|
|
var [cfort,cdata]= readDatFile(filename);
|
|
let lyrs = [6]; // back scattered muons
|
|
for (let ilayer=18;ilayer<cdata.length;ilayer++){lyrs.push(ilayer);} // the rest of the layers
|
|
// Now loop over all
|
|
for (let ilayer of lyrs) {
|
|
// Normalize
|
|
let idata = cdata[ilayer];
|
|
for (let i=0; i<idata.length; i++) {
|
|
idata[i]=100*idata[i]/cdata[4][i];
|
|
}
|
|
Plot_xy(plotDiv,cdata[0],cdata[ilayer],['E (keV)','Fraction of muons (%)',cfort[ilayer]]);
|
|
}
|
|
plotDiv=win.document.getElementById("newPlot");
|
|
}
|
|
|
|
function plotMean(filename) {
|
|
// Plot mean and straggeling from sequence file
|
|
|
|
var win = window.open("", "_blank", "toolbar=no, menubar=no");
|
|
win.document.open();
|
|
win.document.write('<html><head><link rel="stylesheet" href="plotly.css"></head><body>');
|
|
win.document.write('<table style="width: 100%"><tr><td><div id="newPlot" style="width: 500px; height: 400px;"><!-- Plotly chart will be drawn inside this DIV --></div></td></tr></table>');
|
|
win.document.write('</body></html>');
|
|
win.addEventListener('resize', sizePlot);
|
|
win.document.close();
|
|
var plotDiv=win.document.getElementById("newPlot");
|
|
|
|
let [cfort,cdata]= readDatFile(filename);
|
|
let mean = cdata[10];
|
|
let strag = cdata[11];
|
|
for (let i=0; i<mean.length; i++) {
|
|
mean[i]=mean[i]/10;
|
|
strag[i]=strag[i]/10;
|
|
}
|
|
Plot_xy(plotDiv,cdata[0],mean,['E (keV)','Mean Depth/Stragg. (nm)',cfort[10]]);
|
|
Plot_xy(plotDiv,cdata[0],strag,['E (keV)','Mean Depth/Stragg. (nm)',cfort[11]]);
|
|
}
|
|
|
|
function tester() {
|
|
var All=prep_cfg(1);
|
|
// Switch to plots tab
|
|
document.getElementById("btnPlots").click();
|
|
// Clear plots first
|
|
Plotly.purge("plotFrac")
|
|
Plotly.purge("plotRge")
|
|
|
|
//var test = All["L1Comp"];
|
|
//console.log('test='+test);
|
|
startSequence(All)
|
|
//CreateInpFile(All);
|
|
// document.location =
|
|
//
|
|
// "http://musruser.psi.ch/cgi-bin/TrimSP.cgi?TrimSPcfg="+TrimSPcfg+'go=start';
|
|
//console.log(TrimSPcfg);
|
|
// call the function
|
|
//execute('ping -c 4 0.0.0.0', (output) => {
|
|
// console.log(output);
|
|
// });
|
|
}
|
|
|