From 274cd5413380cddc63eee44d6b66e97b9ff05273 Mon Sep 17 00:00:00 2001 From: salman Date: Tue, 10 Jan 2023 21:52:34 +0100 Subject: [PATCH] More work towards unification of online and standalone versions. --- TrimSP.html | 78 +++++++++------------------------------------------ TrimSPelec.js | 59 ++++++++++++++++++++++++++++++++++++++ TrimSPlib.js | 68 ++++++++++++++++++++------------------------ 3 files changed, 102 insertions(+), 103 deletions(-) diff --git a/TrimSP.html b/TrimSP.html index a24376c..53a8f1a 100644 --- a/TrimSP.html +++ b/TrimSP.html @@ -80,7 +80,7 @@ Angle [deg] Angle sigma [deg] Random seed - + @@ -313,7 +313,7 @@ - + Force the TRIM.SP code to use stopping power parameters from the old ICRU tables. @@ -353,26 +353,16 @@ - - - - - + + +
+
0%
+
+ + diff --git a/TrimSPelec.js b/TrimSPelec.js index e19e46c..62dbc05 100644 --- a/TrimSPelec.js +++ b/TrimSPelec.js @@ -64,3 +64,62 @@ function fileExists(filename) { } return 0; } + +function firstLoad() { + document.getElementById("trimPath").value = remote.getGlobal('path'); + + // Catch calls for open file + ipcRenderer.on('openFile', function(event, filename) { + console.log('Open file '+filename); + fs.readFile(filename.toString(), function read(err, data) { + if (err) { + throw err; + } + setValues(data); + }); + }); + + // Catch calls for selectfolder + ipcRenderer.on('selectFolder', function(event, foldername) { + if (foldername.length != 0) { + document.getElementById("workPath").value = foldername[0]; + // Change process directory + process.chdir(foldername[0]); + } + console.log("currentdir",process.cwd()); + }); + // Catch calls for save as + ipcRenderer.on('saveFile', function(event, filename) { + // If filename is empty use default value + if (filename == '') {filename='TrimSP.cfg';} + // Get values from all fields and prepare config file + let trimSPcfg=prep_cfg(0); + // Save file to filename + console.log('Save file to '+filename); + try { fs.writeFileSync(filename, trimSPcfg, 'utf-8'); } + catch(e) { alert('Failed to save the file !'); } + }); + // Catch calls for plotProf + ipcRenderer.on('plotProf', function(event, filename) { + console.log("filename="+filename); + plotProfiles(filename); + }); + // Catch calls for plotFrac + ipcRenderer.on('plotFrac', function(event, filename) { + console.log("filename="+filename); + plotFractions(filename); + }); + // Catch calls for plotMean + ipcRenderer.on('plotMean', function(event, filename) { + console.log("filename="+filename); + plotMean(filename); + }); + // Catch clicks for Browse button + ipcRenderer.on('browseFolder', function(event, foldername) { + if (foldername.length != 0) { + document.getElementById("workPath").value = foldername[0]; + // Change process directory + process.chdir(foldername[0]); + } + }); +} diff --git a/TrimSPlib.js b/TrimSPlib.js index 51366b8..837badc 100644 --- a/TrimSPlib.js +++ b/TrimSPlib.js @@ -39,7 +39,6 @@ function parse_formula (mf) { else mol[m1[0]] += (m2!=null)?Number(m2[0]):1; mf = mf.replace(m[0], ""); } - console.log("mol=",mol); return mol; } @@ -517,11 +516,10 @@ function StoppingCoefficients(Element,flag) }; if (flag) { - console.log("ICRU"); + // Using stopping coefficients derived from ICRU Report 49 return StoppingCoefficientsICRU[Element]; } else { - console.log("IAEA"); - // prefer using stopping coefficients derived from data in the IAEA database; + // Using stopping coefficients derived from data in the IAEA database; // however, if they are unavailable, return those from ICRU Report 49 return (Element in StoppingCoefficientsIAEA) ? StoppingCoefficientsIAEA[Element] : StoppingCoefficientsICRU[Element]; } @@ -698,7 +696,7 @@ function openTab(event, tabName) { // 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"; + if (event) event.currentTarget.className += " active"; } function adjust_table() @@ -1047,26 +1045,25 @@ function sum(array){ function startSequence(All) { let cmd = ''; let trimBin = All['trimPath']+"/trimspNL"; - console.log(trimBin); // Check if the trimspNL binary is found if (!fileExists(trimBin)) { // if not found, try in PATH and hope for the best trimBin = "trimspNL"; } - console.log(trimBin); // 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 + "%"; + document.getElementById("pBar").style.width = Progress + "%"; + document.getElementById("pBar").innerHTML = Progress + "%"; // This is a flag to indicate whether the lists of values and inclements are the same size All["SdzFlag"]=0; var SValues = []; let ScanName = "E"; let ScanAttrib = "valEnergy"; + // Generate an arry of scanned values (one element for a single run) if (All["scanSeq"]) { // For multiple runs or a scan if (All["scanType"]=="scanVals") { @@ -1095,14 +1092,16 @@ function startSequence(All) { ScanName = "Ld"+All["scandL"]; ScanAttrib = "L"+All["scandL"]+"d"; } - } else { // For single run, array with single value of valEnergy SValues.push(parseInt(All["valEnergy"])); } - + + // Now start the actual simulation + //setInterval(() => { let iScan=0; for (var SValue of SValues) { + // Update value in GUI document.getElementById(ScanAttrib).value = SValue; All[ScanAttrib]=SValue; if ( All["SdzFlag"] == 1) { @@ -1112,21 +1111,25 @@ function startSequence(All) { document.getElementById(ScanAttrib).value = SdzValues[iScan]; } } + // Update GUI progress bar + Progress=Progress+90/SValues.length; + document.getElementById("pBar").style.width = Progress + "%"; + document.getElementById("pBar").innerHTML = Progress + "%"; + + // Single run: Start let eingabe1=CreateInpFile(All); if (eingabe1=="ERROR") {return(0);} let FILENAME=All["workPath"]+"/"+All["fileNamePrefix"]+"_"+ScanName+SValue; writeAsciiFile(FILENAME+".inp",eingabe1) - // Update GUI progress bar - Progress=Progress+90/SValues.length; // Prepare command and execute - cmd = "cd "+All["workPath"]+";cp "+FILENAME+".inp eingabe1.inp;"+trimBin; + cmd = "cd " + All["workPath"]; + cmd += ";cp " + FILENAME + ".inp eingabe1.inp"; + cmd += ";" + trimBin; + cmd += "; mv -f ausgabe1.rge " + FILENAME + ".reg"; + cmd += "; mv -f ausgabe1.out " + FILENAME + ".out"; + cmd += "; mv -f ausgabe1.err " + FILENAME + ".err"; execute(cmd); - - // Rename files to standarized format - for (let ext of [".err",".out",".rge"]) { - cmd = "cd "+All["workPath"]+";mv -f ausgabe1"+ext+" "+FILENAME+ext; - execute(cmd); - } + // Single run: End // Read stopping profiels let [cols,data]= readDatFile(FILENAME+".rge"); @@ -1161,7 +1164,7 @@ function startSequence(All) { } iScan++; } - + //},1000); // 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 = ""; @@ -1182,8 +1185,8 @@ function startSequence(All) { 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 + "%"; + document.getElementById("pBar").style.width = Progress + "%"; + document.getElementById("pBar").innerHTML = Progress + "%"; return(0); } @@ -1198,7 +1201,6 @@ function readDatFile(filename,flag) { } else { lines = readAsciiFile(filename); } - console.log(lines); let data = []; let i=0; // line counter for (let line of lines.trim().split('\n')) { @@ -1236,14 +1238,9 @@ function plotProfiles(filenames) { 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 { - // console.log(output); - // }); } // Function to load and ascii file