Running SWAT+ exe. through Node.js

85 views
Skip to first unread message

Alex Rigby

unread,
Apr 27, 2021, 9:45:23 AM4/27/21
to SWAT+
Hi, 

I am currently developing a Toolkit to simplify making LULC changes to the SWAT+ model.  I am currently trying to run rev60.5.2_64rel using the following Node.js script;

var execFile = require('child_process').execFile;

const path = "C://Users//lxr20nkj//OneDrive - Bangor University//Documents//KESS 2 BUK2188//SWAT+//Catchments 2//LLYFNI2//TxtInOut//rev60.5.2_64rel.exe";

execFile(path, function(err, data) {
    console.log('stdout', err, data.toString());
}); 

but I get the fortran error;
                    "forrtl: severe (151): allocatable array is already allocated"

I was wondering if anyone had had this issue before and knows a way around it that will allow me to run SWAT+ through the js application. 

Thanks in advance

Alex

Jaclyn Tech

unread,
Apr 27, 2021, 11:16:08 AM4/27/21
to SWAT+
Hi, SWAT+ Editor actually uses Node.js too! Most likely you need to set your current working directory (cwd) if your exe is located in a different spot than your model input files.

In the editor, I am using spawn instead of execFile:

let process = require('child_process').spawn(swatExe, [], { cwd: inputDir, maxBuffer: 1024 * 1024 * 1024 });

Where 'swatExe' is the path to rev60.5.2_64rel.exe and 'inputDir' is the path to model input files. 'maxBuffer' is if you want to capture all of the stdout data.

You can then have the following functions to capture in the screen output:

//Data to the screen while model is executing successfully
process.stdout.on('data', (data) => {
  console.log(`${data}`);
});

//Log error message
process.stderr.on('data', (data) => {
  console.log(`${data}`);
});

//Perform any tasks when done if needed...
process.on('close', (code) => {
  console.log('done');
});

You can check out the SWAT+ Editor source code for more. I use Electron (which uses Node.js) and Vue.js.

Reply all
Reply to author
Forward
0 new messages