Merge new feature to load/run cfg files from command line

This commit is contained in:
2026-06-14 16:17:38 +00:00
28 changed files with 174 additions and 81 deletions
+70 -7
View File
@@ -120,6 +120,57 @@ function fallbackBrowseForFolder() {
picker.click();
}
function getConfigValue(content, key) {
const lines = content.toString().split('\n');
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('[')) {
continue;
}
const separator = trimmed.indexOf('=');
if (separator === -1) {
continue;
}
const param = trimmed.slice(0, separator).trim();
if (param === key) {
return trimmed.slice(separator + 1).trim();
}
}
return null;
}
function resolveConfigWorkPath(filename, content) {
const configuredWorkPath = getConfigValue(content, 'workPath');
if (!configuredWorkPath) {
return null;
}
if (configuredWorkPath.startsWith('./')) {
return path.resolve(path.dirname(filename), configuredWorkPath);
}
if (path.isAbsolute(configuredWorkPath)) {
return configuredWorkPath;
}
return null;
}
function loadConfigFile(filename, autoRun = false) {
const configPath = Array.isArray(filename) ? filename[0] : filename.toString();
console.log('Open file ' + configPath);
fs.readFile(configPath, function read(err, data) {
if (err) {
throw err;
}
setValues(data);
const resolvedWorkPath = resolveConfigWorkPath(configPath, data);
if (resolvedWorkPath) {
setWorkFolder([resolvedWorkPath]);
}
if (autoRun) {
setTimeout(() => startSim(), 0);
}
});
}
function firstLoad() {
document.getElementById("trimPath").value = process.cwd();
if (typeof syncStatusBar === 'function') {
@@ -140,13 +191,12 @@ function firstLoad() {
// 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);
});
loadConfigFile(filename, false);
});
ipcRenderer.on('openFileAndMaybeRun', function(event, payload) {
if (!payload || !payload.filename) { return; }
loadConfigFile(payload.filename, !!payload.autoRun);
});
// Catch calls for selectfolder
@@ -203,3 +253,16 @@ function firstLoad() {
fallbackBrowseForFolder();
});
}
window.addEventListener('load', async function() {
try {
const startupOptions = await ipcRenderer.invoke('getStartupOptions');
if (startupOptions && startupOptions.configPath) {
setTimeout(() => {
loadConfigFile(startupOptions.configPath, !!startupOptions.autoRun);
}, 0);
}
} catch (err) {
console.log('Failed to read startup options:', err);
}
});
+31 -2
View File
@@ -1,10 +1,36 @@
const path = require('path');
const { app, BrowserWindow, Menu, dialog, ipcMain, fs } = require('electron');
const fs = require('fs');
const { app, BrowserWindow, Menu, dialog, ipcMain } = require('electron');
let currentWorkPath = process.cwd();
const startupOptions = parseStartupOptions(process.argv);
app.setName('TrimSP');
function parseStartupOptions(argv) {
const options = {
configPath: null,
autoRun: false,
};
for (const arg of argv.slice(2)) {
if (arg === '--run') {
options.autoRun = true;
} else if (!arg.startsWith('--') && options.configPath == null) {
const candidate = path.resolve(arg);
if (
path.extname(candidate).toLowerCase() === '.cfg' &&
fs.existsSync(candidate) &&
fs.statSync(candidate).isFile()
) {
options.configPath = candidate;
}
}
}
return options;
}
function showAboutDialog(parentWindow) {
const detail = [
'TRIM.SP simulation GUI for low-energy ion implantation studies.',
@@ -67,7 +93,6 @@ function createWindow () {
}
})
let template = [
{
label: 'File',
@@ -317,6 +342,10 @@ ipcMain.on('updateWorkPath', (event, folder) => {
}
});
ipcMain.handle('getStartupOptions', async () => {
return startupOptions;
});
//ipcMain.on('browseFolder-send', (event, args) => {
// dialog.showOpenDialog(null, args).then(filePaths => {
// event.sender.dend('browseFolder', filePaths);
+5 -4
View File
@@ -102,12 +102,13 @@ function resizePl(flag){
width: newx,
height: newy
};
const canRelayout = (plotDiv) => plotDiv && plotDiv.data && plotDiv.layout;
if (flag == null) {
Plotly.relayout(plotDiv1,update);
Plotly.relayout(plotDiv2,update);
if (canRelayout(plotDiv1)) Plotly.relayout(plotDiv1,update);
if (canRelayout(plotDiv2)) Plotly.relayout(plotDiv2,update);
} else if (flag == 1) {
Plotly.relayout(plotDiv1,update);
if (canRelayout(plotDiv1)) Plotly.relayout(plotDiv1,update);
} else if ( flag == 2) {
Plotly.relayout(plotDiv2,update);
if (canRelayout(plotDiv2)) Plotly.relayout(plotDiv2,update);
}
}
+1 -1
View File
@@ -7,7 +7,7 @@
"build:fortran": "make -C fortran trimspNL-static && cp fortran/trimspNL-static resources/bin/trimspNL",
"build:fortran:dynamic": "make -C fortran trimspNL && cp fortran/trimspNL resources/bin/trimspNL",
"build:fortran:static": "npm run build:fortran",
"start": "electron-forge start",
"start": "electron-forge start --",
"prepackage": "npm run build:fortran",
"package": "electron-forge package",
"premake": "npm run build:fortran",
+2 -2
View File
@@ -1,6 +1,6 @@
[Files]
fileNamePrefix=6element_plus_multilayer
workPath=/home/zaher/LEM/git/trimsp/tests/6element_plus_multilayer
workPath=./
[Layers]
numLayer=4
L1Comp=AlCoCrFeNiTi
@@ -16,7 +16,7 @@ L4Comp=Si
L4rho=2.33
L4d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/6element_plus_multilayer
workPath=./
fileNamePrefix=6element_plus_multilayer
ProjType=muon
numberProj=5000
+2 -2
View File
@@ -1,6 +1,6 @@
[Files]
fileNamePrefix=7layer_stack
workPath=/home/zaher/LEM/git/trimsp/tests/7layer_stack
workPath=./
[Layers]
numLayer=7
L1Comp=SiO2
@@ -25,7 +25,7 @@ L7Comp=Si
L7rho=2.33
L7d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/7layer_stack
workPath=./
fileNamePrefix=7layer_stack
ProjType=muon
numberProj=5000
+2 -2
View File
@@ -1,13 +1,13 @@
[Files]
fileNamePrefix=AlCoCrFeNiTi_6element
workPath=/home/zaher/LEM/git/trimsp/tests/AlCoCrFeNiTi_6elements
workPath=./
[Layers]
numLayer=1
L1Comp=AlCoCrFeNiTi
L1rho=6.245928550233616
L1d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/AlCoCrFeNiTi_6elements
workPath=./
fileNamePrefix=AlCoCrFeNiTi_6element
ProjType=muon
numberProj=5000
+2 -2
View File
@@ -1,6 +1,6 @@
[Files]
fileNamePrefix=Au_Cr_Si_3layer
workPath=/home/zaher/LEM/git/trimsp/tests/Au_Cr_Si_3layer
workPath=./
[Layers]
numLayer=3
L1Comp=Au
@@ -13,7 +13,7 @@ L3Comp=Si
L3rho=2.33
L3d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/Au_Cr_Si_3layer
workPath=./
fileNamePrefix=Au_Cr_Si_3layer
ProjType=muon
numberProj=5000
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:20:58
Start: 13.Jun. 2026 16:34:53
End: 12.Jun. 2026 19:20:58
End: 13.Jun. 2026 16:34:53
Simulation needed for 5000 muons 0 seconds
Simulation needed for 5000 projectiles 0 seconds
* INPUT DATA * Si_1layer_E1
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:21:04
Start: 13.Jun. 2026 16:35:00
End: 12.Jun. 2026 19:21:07
End: 13.Jun. 2026 16:35:03
Simulation needed for 5000 muons 3 seconds
Simulation needed for 5000 projectiles 3 seconds
* INPUT DATA * Si_1layer_E1
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:21:07
Start: 13.Jun. 2026 16:35:03
End: 12.Jun. 2026 19:21:10
End: 13.Jun. 2026 16:35:06
Simulation needed for 5000 muons 3 seconds
Simulation needed for 5000 projectiles 3 seconds
* INPUT DATA * Si_1layer_E1
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:21:10
Start: 13.Jun. 2026 16:35:06
End: 12.Jun. 2026 19:21:14
End: 13.Jun. 2026 16:35:10
Simulation needed for 5000 muons 4 seconds
Simulation needed for 5000 projectiles 4 seconds
* INPUT DATA * Si_1layer_E1
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:21:14
Start: 13.Jun. 2026 16:35:10
End: 12.Jun. 2026 19:21:18
End: 13.Jun. 2026 16:35:15
Simulation needed for 5000 muons 4 seconds
Simulation needed for 5000 projectiles 5 seconds
* INPUT DATA * Si_1layer_E1
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:21:18
Start: 13.Jun. 2026 16:35:15
End: 12.Jun. 2026 19:21:22
End: 13.Jun. 2026 16:35:19
Simulation needed for 5000 muons 4 seconds
Simulation needed for 5000 projectiles 4 seconds
* INPUT DATA * Si_1layer_E1
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:20:58
Start: 13.Jun. 2026 16:34:53
End: 12.Jun. 2026 19:20:59
End: 13.Jun. 2026 16:34:54
Simulation needed for 5000 muons 1 seconds
Simulation needed for 5000 projectiles 1 seconds
* INPUT DATA * Si_1layer_E3
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:20:59
Start: 13.Jun. 2026 16:34:54
End: 12.Jun. 2026 19:21:00
End: 13.Jun. 2026 16:34:56
Simulation needed for 5000 muons 1 seconds
Simulation needed for 5000 projectiles 2 seconds
* INPUT DATA * Si_1layer_E5
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:21:00
Start: 13.Jun. 2026 16:34:56
End: 12.Jun. 2026 19:21:02
End: 13.Jun. 2026 16:34:57
Simulation needed for 5000 muons 2 seconds
Simulation needed for 5000 projectiles 1 seconds
* INPUT DATA * Si_1layer_E7
+4 -4
View File
@@ -1,11 +1,11 @@
1
* TrimSPNL v1.1.0 *
* TrimSPNL v1.3.0 *
Start: 12.Jun. 2026 19:21:02
Start: 13.Jun. 2026 16:34:58
End: 12.Jun. 2026 19:21:04
End: 13.Jun. 2026 16:35:00
Simulation needed for 5000 muons 2 seconds
Simulation needed for 5000 projectiles 2 seconds
* INPUT DATA * Si_1layer_E9
@@ -1,4 +1,4 @@
Energy SigmaE Alpha SigAlpha ntot imp backsc trans tried negE range straggeling Eback sigEback Etrans SigEtrans red._E PRC Si
Energy SigmaE Alpha SigAlpha ntot imp backsc trans tried negE range straggeling Eback sigEback Etrans SigEtrans red._E PRC Si
1.00 0.00 0.00 0.00 5000 4389 611 0 0 0 0.6845E+02 0.3950E+02 0.2904E+03 0.1566E+03 0.0000E+00 0.0000E+00 0.2146E+00 0.3817E+00 4389
3.00 0.00 0.00 0.00 5000 4579 421 0 0 0 0.2032E+03 0.1117E+03 0.8657E+03 0.4416E+03 0.0000E+00 0.0000E+00 0.6439E+00 0.2786E+00 4579
5.00 0.00 0.00 0.00 5000 4674 326 0 0 0 0.3498E+03 0.1867E+03 0.1409E+04 0.7539E+03 0.0000E+00 0.0000E+00 0.1073E+01 0.2197E+00 4674
+2 -2
View File
@@ -1,13 +1,13 @@
[Files]
fileNamePrefix=Si_1layer
workPath=/home/zaher/LEM/git/trimsp/tests/Li8-Si_1layer
workPath=/home/l_salman/LEM/git/trimsp/tests/Li8-Si_1layer
[Layers]
numLayer=1
L1Comp=Si
L1rho=2.33
L1d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/Li8-Si_1layer
workPath=/home/l_salman/LEM/git/trimsp/tests/Li8-Si_1layer
fileNamePrefix=Si_1layer
ProjType=Li-8
numberProj=5000
+2 -2
View File
@@ -1,6 +1,6 @@
[Files]
fileNamePrefix=thin_C_Au_C
workPath=/home/zaher/LEM/git/trimsp/tests/Li8-thin_C_Au_C
workPath=./
[Layers]
numLayer=3
L1Comp=C
@@ -13,7 +13,7 @@ L3Comp=C
L3rho=2.26
L3d=100
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/Li8-thin_C_Au_C
workPath=./
fileNamePrefix=thin_C_Au_C
ProjType=Li-8
numberProj=10000
+2 -2
View File
@@ -1,13 +1,13 @@
[Files]
fileNamePrefix=SiO2_1layer
workPath=/home/zaher/LEM/git/trimsp/tests/SiO2_1layer
workPath=./
[Layers]
numLayer=1
L1Comp=SiO2
L1rho=2.65
L1d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/SiO2_1layer
workPath=./
fileNamePrefix=SiO2_1layer
ProjType=muon
numberProj=5000
+2 -2
View File
@@ -1,6 +1,6 @@
[Files]
fileNamePrefix=SiO2_Al2O3_TiN_Si_4layer
workPath=/home/zaher/LEM/git/trimsp/tests/SiO2_Al2O3_TiN_Si_4layer
workPath=./
[Layers]
numLayer=4
L1Comp=SiO2
@@ -16,7 +16,7 @@ L4Comp=Si
L4rho=2.33
L4d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/SiO2_Al2O3_TiN_Si_4layer
workPath=./
fileNamePrefix=SiO2_Al2O3_TiN_Si_4layer
ProjType=muon
numberProj=5000
+2 -2
View File
@@ -1,6 +1,6 @@
[Files]
fileNamePrefix=SiO2_Si_2layer
workPath=/home/zaher/LEM/git/trimsp/tests/SiO2_Si_2layer
workPath=./
[Layers]
numLayer=2
L1Comp=SiO2
@@ -10,7 +10,7 @@ L2Comp=Si
L2rho=2.33
L2d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/SiO2_Si_2layer
workPath=./
fileNamePrefix=SiO2_Si_2layer
ProjType=muon
numberProj=5000
+2 -2
View File
@@ -1,13 +1,13 @@
[Files]
fileNamePrefix=Si_1layer
workPath=/home/zaher/LEM/git/trimsp/tests/Si_1layer
workPath=./
[Layers]
numLayer=1
L1Comp=Si
L1rho=2.33
L1d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/Si_1layer
workPath=./
fileNamePrefix=Si_1layer
ProjType=muon
numberProj=5000
+2 -2
View File
@@ -1,6 +1,6 @@
[Files]
fileNamePrefix=thin_Au_Cr_Si
workPath=/home/zaher/LEM/git/trimsp/tests/thin_Au_Cr_Si
workPath=./
[Layers]
numLayer=3
L1Comp=Au
@@ -13,7 +13,7 @@ L3Comp=Si
L3rho=2.33
L3d=10000
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/thin_Au_Cr_Si
workPath=./
fileNamePrefix=thin_Au_Cr_Si
ProjType=muon
numberProj=10000
+2 -2
View File
@@ -1,6 +1,6 @@
[Files]
fileNamePrefix=thin_C_Au_C
workPath=/home/zaher/LEM/git/trimsp/tests/thin_C_Au_C
workPath=./
[Layers]
numLayer=3
L1Comp=C
@@ -13,7 +13,7 @@ L3Comp=C
L3rho=2.26
L3d=100
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/thin_C_Au_C
workPath=./
fileNamePrefix=thin_C_Au_C
ProjType=muon
numberProj=10000
+2 -2
View File
@@ -1,13 +1,13 @@
[Files]
fileNamePrefix=thin_C_foil
workPath=/home/zaher/LEM/git/trimsp/tests/thin_C_foil
workPath=./
[Layers]
numLayer=1
L1Comp=C
L1rho=2.26
L1d=100
[ProjectileParameters]
workPath=/home/zaher/LEM/git/trimsp/tests/thin_C_foil
workPath=./
fileNamePrefix=thin_C_foil
ProjType=muon
numberProj=10000