fortran 0.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +109 -0
- package/lib/compile/index.js +50 -0
- package/lib/index.js +54 -0
- package/package.json +80 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-26 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
|
|
2
|
+
|
|
3
|
+
[](#)
|
|
4
|
+
|
|
5
|
+
# fortran
|
|
6
|
+
|
|
7
|
+
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://www.npmjs.com/package/fortran) [](https://www.npmjs.com/package/fortran) [](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
|
|
8
|
+
|
|
9
|
+
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
|
|
10
|
+
|
|
11
|
+
> Fortran bridge for Node.js which allows you to run Fortran code from Node.js.
|
|
12
|
+
|
|
13
|
+
[](#)
|
|
14
|
+
|
|
15
|
+
## :cloud: Installation
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
# Using npm
|
|
19
|
+
npm install --save fortran
|
|
20
|
+
|
|
21
|
+
# Using yarn
|
|
22
|
+
yarn add fortran
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Prerequisites
|
|
26
|
+
|
|
27
|
+
You have to install the Fortran compiler:
|
|
28
|
+
```sh
|
|
29
|
+
# Ubuntu
|
|
30
|
+
sudo apt-get install gfortran
|
|
31
|
+
sudo apt-get install fort77
|
|
32
|
+
|
|
33
|
+
# OS X
|
|
34
|
+
brew install gcc
|
|
35
|
+
```
|
|
36
|
+
## :clipboard: Example
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const fotran = require("fortran");
|
|
40
|
+
|
|
41
|
+
// Let's run some Fortran stuff
|
|
42
|
+
fotran(`
|
|
43
|
+
program hello
|
|
44
|
+
print *, "Hello World!"
|
|
45
|
+
end program hello
|
|
46
|
+
`, (err, data) => {
|
|
47
|
+
console.log(err || data);
|
|
48
|
+
// => Hello World
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## :memo: Documentation
|
|
53
|
+
|
|
54
|
+
### `fortran(input, callback)`
|
|
55
|
+
Runs Fortran code from the Node.js side.
|
|
56
|
+
|
|
57
|
+
#### Params
|
|
58
|
+
- **String|Path** `input`: The Fortran code to execute, or a path to a Fortran file (generally having the `.f` extension).
|
|
59
|
+
- **Function** `callback`: The callback function called with `err`, `stdout` and `stderr`.
|
|
60
|
+
|
|
61
|
+
## :question: Get Help
|
|
62
|
+
|
|
63
|
+
There are a few ways to get help:
|
|
64
|
+
|
|
65
|
+
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long as you add a link to your Stack Overflow question.
|
|
66
|
+
2. For bug reports and feature requests, open issues. :bug:
|
|
67
|
+
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
68
|
+
|
|
69
|
+
## :yum: How to Contribute
|
|
70
|
+
|
|
71
|
+
Have an idea? Found a bug? See [how to contribute][contributing].
|
|
72
|
+
|
|
73
|
+
## :sparkling_heart: Support My Projects
|
|
74
|
+
|
|
75
|
+
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute it (even resell it).
|
|
76
|
+
|
|
77
|
+
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are a few ways you can do it:
|
|
78
|
+
|
|
79
|
+
- Starring and sharing the projects you like :rocket:
|
|
80
|
+
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you for years if you buy me one. :grin: :book:
|
|
81
|
+
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
|
|
82
|
+
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
|
|
83
|
+
- **Bitcoin**—You can send me bitcoins at this address (or by scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
|
|
84
|
+
|
|
85
|
+

|
|
86
|
+
|
|
87
|
+
Thanks! :heart:
|
|
88
|
+
|
|
89
|
+
## :sparkles: Related
|
|
90
|
+
|
|
91
|
+
- [`node.fortran`](https://github.com/IonicaBizau/node.fortran#readme)—Execute Node.js in your Fortran programs.
|
|
92
|
+
- [`cobol`](https://github.com/IonicaBizau/node-cobol)—COBOL bridge for NodeJS which allows you to run COBOL code from NodeJS.
|
|
93
|
+
- [`node.cobol`](https://github.com/IonicaBizau/node.cobol#readme)—Node.js bridge for COBOL which allows you to run Node.js code from COBOL.
|
|
94
|
+
|
|
95
|
+
## :scroll: License
|
|
96
|
+
|
|
97
|
+
[MIT][license] © [Ionică Bizău][website]
|
|
98
|
+
|
|
99
|
+
[license]: /LICENSE
|
|
100
|
+
[website]: https://ionicabizau.net
|
|
101
|
+
[contributing]: /CONTRIBUTING.md
|
|
102
|
+
[docs]: /DOCUMENTATION.md
|
|
103
|
+
[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg
|
|
104
|
+
[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg
|
|
105
|
+
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
|
|
106
|
+
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
|
|
107
|
+
[patreon]: https://www.patreon.com/ionicabizau
|
|
108
|
+
[amazon]: https://amzn.eu/hRo9sIZ
|
|
109
|
+
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const prgmInstalled = require("prgm-installed")
|
|
4
|
+
, spawn = require("spawno")
|
|
5
|
+
, OArgv = require("oargv")
|
|
6
|
+
, Path = require("path")
|
|
7
|
+
;
|
|
8
|
+
|
|
9
|
+
function getExe(cb) {
|
|
10
|
+
prgmInstalled("fort77", installed => {
|
|
11
|
+
if (installed) { return cb(null, "fort77"); }
|
|
12
|
+
prgmInstalled("gfortran", installed => {
|
|
13
|
+
if (installed) { return cb(null, "gfortran"); }
|
|
14
|
+
callback(new Error("Couldn't find the Fortran compiler executable in the PATH. Please install fort77 or gfortran."));
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function checkBin(callback) {
|
|
20
|
+
prgmInstalled("fort77", callback);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function Compile(input, callback) {
|
|
24
|
+
getExe((err, exe) => {
|
|
25
|
+
if (err) { return callback(err); }
|
|
26
|
+
|
|
27
|
+
let output = Path.resolve(Path.basename(input).slice(0, -2))
|
|
28
|
+
, args = {
|
|
29
|
+
_: input,
|
|
30
|
+
o: output
|
|
31
|
+
}
|
|
32
|
+
;
|
|
33
|
+
|
|
34
|
+
spawn(exe, OArgv(args), (err, stdout, stderr) => {
|
|
35
|
+
|
|
36
|
+
if (/^Cannot open/.test(stderr)) {
|
|
37
|
+
err = new Error(stderr);
|
|
38
|
+
stderr = "";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (stderr || err) {
|
|
42
|
+
return callback(stderr || err);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
callback(null, output);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = Compile;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const noop = require("noop6")
|
|
4
|
+
, fs = require("fs")
|
|
5
|
+
, spawn = require("spawno")
|
|
6
|
+
, tmp = require("tmp")
|
|
7
|
+
, compile = require("./compile")
|
|
8
|
+
, ul = require("ul")
|
|
9
|
+
, oneByOne = require("one-by-one")
|
|
10
|
+
;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* fortran
|
|
14
|
+
* Runs Fortran code from the Node.js side.
|
|
15
|
+
*
|
|
16
|
+
* @name fortran
|
|
17
|
+
* @function
|
|
18
|
+
* @param {String|Path} input The Fortran code to execute, or a path to a Fortran file (generally having the `.f` extension).
|
|
19
|
+
* @param {Function} callback The callback function called with `err`, `stdout` and `stderr`.
|
|
20
|
+
*/
|
|
21
|
+
function fortran(input, callback) {
|
|
22
|
+
|
|
23
|
+
callback = callback || noop;
|
|
24
|
+
|
|
25
|
+
// File
|
|
26
|
+
if (typeof input === "string" && input.split("\n").length === 1) {
|
|
27
|
+
return oneByOne([
|
|
28
|
+
next => compile(input, next)
|
|
29
|
+
, (next, path) => {
|
|
30
|
+
spawn(path, (err, stdout, stderr) => {
|
|
31
|
+
next(err, !err && [stdout.slice(0, -1), stderr]);
|
|
32
|
+
fs.unlink(path, noop);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
], (err, data, last) => callback.apply(this, [err, !err && last[0], !err && last[1]]));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Code
|
|
39
|
+
if (typeof input === "string") {
|
|
40
|
+
return oneByOne([
|
|
41
|
+
next => tmp.file({ postfix: ".f" }, (err, path) => next(err, path))
|
|
42
|
+
, (next, path) => fs.writeFile(path, input, err => next(err, path))
|
|
43
|
+
, (next, path) => {
|
|
44
|
+
fortran(path, (err, stdout, stderr) =>
|
|
45
|
+
next(err, [stdout, stderr])
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
], (err, data, last) => callback.apply(this, [err, last[0], last[1]]));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
callback(new Error("Incorrect usage."));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = fortran;
|
package/package.json
CHANGED
|
@@ -1,12 +1,85 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fortran",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Fortran bridge for Node.js which allows you to run Fortran code from Node.js.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"directories": {
|
|
7
|
+
"example": "examples"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"abs": "^1.3.1"
|
|
11
|
+
},
|
|
6
12
|
"scripts": {
|
|
7
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
14
|
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
"keywords": [
|
|
16
|
+
"fortran",
|
|
17
|
+
"node",
|
|
18
|
+
"bridge"
|
|
19
|
+
],
|
|
20
|
+
"author": "Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"blah": {
|
|
23
|
+
"h_img": "http://i.imgur.com/P2ExtzQ.png",
|
|
24
|
+
"ex_img": "http://i.imgur.com/f6QlDFx.png",
|
|
25
|
+
"related": [
|
|
26
|
+
"node.fortran",
|
|
27
|
+
"cobol",
|
|
28
|
+
"node.cobol"
|
|
29
|
+
],
|
|
30
|
+
"installation": [
|
|
31
|
+
{
|
|
32
|
+
"h3": "Prerequisites"
|
|
33
|
+
},
|
|
34
|
+
"You have to install the Fortran compiler:",
|
|
35
|
+
{
|
|
36
|
+
"code": {
|
|
37
|
+
"language": "sh",
|
|
38
|
+
"content": [
|
|
39
|
+
"# Ubuntu",
|
|
40
|
+
"sudo apt-get install gfortran",
|
|
41
|
+
"sudo apt-get install fort77",
|
|
42
|
+
"",
|
|
43
|
+
"# OS X",
|
|
44
|
+
"brew install gcc"
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"noop6": "^1.0.1",
|
|
52
|
+
"oargv": "^3.4.2",
|
|
53
|
+
"one-by-one": "^3.1.2",
|
|
54
|
+
"prgm-installed": "^1.0.2",
|
|
55
|
+
"sliced": "^1.0.1",
|
|
56
|
+
"spawno": "^1.0.1",
|
|
57
|
+
"tmp": "0.0.28",
|
|
58
|
+
"ul": "^5.2.2",
|
|
59
|
+
"which": "^1.2.8"
|
|
60
|
+
},
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/IonicaBizau/node-fortran.git"
|
|
64
|
+
},
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/IonicaBizau/node-fortran/issues"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://github.com/IonicaBizau/node-fortran",
|
|
69
|
+
"files": [
|
|
70
|
+
"bin/",
|
|
71
|
+
"app/",
|
|
72
|
+
"lib/",
|
|
73
|
+
"dist/",
|
|
74
|
+
"src/",
|
|
75
|
+
"scripts/",
|
|
76
|
+
"resources/",
|
|
77
|
+
"menu/",
|
|
78
|
+
"cli.js",
|
|
79
|
+
"index.js",
|
|
80
|
+
"index.d.ts",
|
|
81
|
+
"bloggify.js",
|
|
82
|
+
"bloggify.json",
|
|
83
|
+
"bloggify/"
|
|
84
|
+
]
|
|
85
|
+
}
|