More work towards unification of online and standalone versions.
This commit is contained in:
+13
-65
@@ -80,7 +80,7 @@
|
||||
<tr><td>Angle [deg]</td><td><input name="valAngle" id="valAngle" type="text" size="7" value="0"></td></tr>
|
||||
<tr><td>Angle sigma [deg]</td><td><input name="sigAngle" id="sigAngle" type="text" size="7" value="15"></td></tr>
|
||||
<tr><td>Random seed</td><td><input name="ranSeed" id="ranSeed" type="text" size="7" value="78741"></td></tr>
|
||||
<tr><td><button onclick="document.getElementById('btnPlots').click();tester();">Start</button></td><td></td></tr>
|
||||
<tr><td><button onclick="startSim();">Start</button></td><td></td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -313,7 +313,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="tooltip">
|
||||
<input type="checkbox" id="flagICRU">
|
||||
<input type="checkbox" id="flagICRU" checked>
|
||||
<span class="tooltiptext">
|
||||
Force the TRIM.SP code to use stopping power
|
||||
parameters from the old ICRU tables.
|
||||
@@ -353,26 +353,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</td></tr>
|
||||
<!tr>
|
||||
<!td>
|
||||
<!progress id="myBar" max=100 min=0><!/progress>
|
||||
<!/td>
|
||||
<!/tr>
|
||||
<tr style="width: 100%;//visibility: hidden;">
|
||||
<td>
|
||||
<div class="w3-light-grey">
|
||||
<div id="pBar" class="w3-container w3-green w3-center" style="width:0%">0%</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
<script>
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
let workPath = document.getElementById("workPath");
|
||||
// If empty or undefined use local folder as default
|
||||
@@ -381,53 +371,11 @@
|
||||
workPath.value = '/tmp';
|
||||
//app.setPath('temp',process.cwd());
|
||||
}
|
||||
|
||||
// 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]);
|
||||
}
|
||||
});
|
||||
|
||||
// Get the element with id="defaultOpen" and click on it
|
||||
// Open the default Layers tab
|
||||
document.getElementById("btnLayers").click();
|
||||
|
||||
// Set up after first load (electron specific menu calls)
|
||||
firstLoad();
|
||||
|
||||
</script>
|
||||
</html>
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+30
-38
@@ -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<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];
|
||||
@@ -1309,7 +1306,8 @@ function plotMean(filename) {
|
||||
Plot_xy(plotDiv,cdata[0],strag,['E (keV)','Mean Depth/Stragg. (nm)',cfort[11]]);
|
||||
}
|
||||
|
||||
function tester() {
|
||||
function startSim() {
|
||||
// Collect data from GUI
|
||||
var All=prep_cfg(1);
|
||||
// Switch to plots tab
|
||||
document.getElementById("btnPlots").click();
|
||||
@@ -1317,18 +1315,12 @@ function tester() {
|
||||
Plotly.purge("plotFrac")
|
||||
Plotly.purge("plotRge")
|
||||
|
||||
//var test = All["L1Comp"];
|
||||
//console.log('test='+test);
|
||||
// start simulation sequence
|
||||
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);
|
||||
// });
|
||||
}
|
||||
|
||||
// Function to load and ascii file
|
||||
|
||||
Reference in New Issue
Block a user