-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate.js
executable file
·74 lines (68 loc) · 2.93 KB
/
calculate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
// Copyright (C) 2021 Paul Ciarlo <paul.ciarlo@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/**
* Calculate indoor/outdoor relative humidity from (outdoor) dewpoint and
* (indoor/outdoor) temperatures.
*/
const { RHCalc, logger, _test } = require('./lib');
const test = require('./test');
function usage(scriptName) {
logger.info(`Usage:\n${scriptName} [-f|-c] [-p <atmosphericPressure>] <[-t] temp1 [[-d]|-r <dewpointOrRelativeHumidity>]> [[-t] temp2 [[-d]|-r <dewpointOrRelativeHumidity>]]`);
logger.info("Calculates saturation partial pressure of water vapor for temp1, actual partial pressure/relative humidity for temp1 at dewpoint/frostpoint, and for temp2 at equal pressure, or rh2, if provided");
logger.info("-h Show this help");
logger.info("-c Temperatures specified in degrees Celsius [default]");
logger.info("-f Temperatures specified in degrees Fahrenheit");
logger.info("-k Temperatures specified in Kelvin");
logger.info("-p Atmospheric pressure in hPa [default = 1013.25]");
logger.info("-r Relative humidity in % at temp1 [calculate dewpoint]");
logger.info("-d Dewpoint [calculate relative humidity]");
}
async function main(argv) {
const nodeExecutable = argv.shift();
const script = argv.shift();
if (argv.length == 0 || argv[0] === '-h') {
return usage(script);
}
const calc = new RHCalc();
while (argv.length > 0) {
let arg = argv.shift();
if (arg === '-c' || arg === '-f' || arg === '-k') {
calc.setTempUnits(arg[1]);
} else if (arg === '-p') {
calc.setPressure(argv.shift());
} else if (arg === '-t') {
calc.addTemp(argv.shift());
} else if (arg === '-d') {
calc.addDewpoint(argv.shift());
} else if (arg === '-r') {
calc.addHumidity(argv.shift());
} else {
calc.addParam(arg);
}
}
calc.calculate();
calc.printResult();
}
main(process.argv)
.then(res => console.log(res))
.then(() => test())
.catch(e => console.error(e))
.finally(() => {});