@sdeverywhere/cli 0.7.6 → 0.7.8
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/package.json +2 -2
- package/src/c/model.c +43 -0
- package/src/c/sde.h +4 -6
- package/src/sde-compare.js +4 -0
- package/src/sde-test.js +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdeverywhere/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.8",
|
|
4
4
|
"description": "Contains the `sde` command line interface for the SDEverywhere tool suite.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@sdeverywhere/build": "^0.3.0",
|
|
15
|
-
"@sdeverywhere/compile": "^0.7.
|
|
15
|
+
"@sdeverywhere/compile": "^0.7.5",
|
|
16
16
|
"bufx": "^1.0.5",
|
|
17
17
|
"byline": "^5.0.0",
|
|
18
18
|
"ramda": "^0.27.0",
|
package/src/c/model.c
CHANGED
|
@@ -23,6 +23,49 @@ size_t savePointIndex = 0;
|
|
|
23
23
|
|
|
24
24
|
int step = 0;
|
|
25
25
|
|
|
26
|
+
void initControlParamsIfNeeded() {
|
|
27
|
+
static bool controlParamsInitialized = false;
|
|
28
|
+
if (controlParamsInitialized) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Some models may define the control parameters as variables that are
|
|
33
|
+
// dependent on other values that are only known at runtime (after running
|
|
34
|
+
// the initializers and/or one step of the model), so we need to perform
|
|
35
|
+
// those steps once before the parameters are accessed
|
|
36
|
+
// TODO: This approach doesn't work if one or more control parameters are
|
|
37
|
+
// defined in terms of some value that is provided at runtime as an input
|
|
38
|
+
initConstants();
|
|
39
|
+
initLevels();
|
|
40
|
+
_time = _initial_time;
|
|
41
|
+
evalAux();
|
|
42
|
+
controlParamsInitialized = true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Return the constant or computed value of `INITIAL TIME`.
|
|
47
|
+
*/
|
|
48
|
+
double getInitialTime() {
|
|
49
|
+
initControlParamsIfNeeded();
|
|
50
|
+
return _initial_time;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Return the constant or computed value of `FINAL TIME`.
|
|
55
|
+
*/
|
|
56
|
+
double getFinalTime() {
|
|
57
|
+
initControlParamsIfNeeded();
|
|
58
|
+
return _final_time;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Return the constant or computed value of `SAVEPER`.
|
|
63
|
+
*/
|
|
64
|
+
double getSaveper() {
|
|
65
|
+
initControlParamsIfNeeded();
|
|
66
|
+
return _saveper;
|
|
67
|
+
}
|
|
68
|
+
|
|
26
69
|
char* run_model(const char* inputs) {
|
|
27
70
|
// run_model does everything necessary to run the model with the given inputs.
|
|
28
71
|
// It may be called multiple times. Call finish() after all runs are complete.
|
package/src/c/sde.h
CHANGED
|
@@ -50,7 +50,10 @@ EXTERN double _final_time;
|
|
|
50
50
|
EXTERN double _time_step;
|
|
51
51
|
EXTERN double _saveper;
|
|
52
52
|
|
|
53
|
-
// API (defined in model.
|
|
53
|
+
// API (defined in model.c)
|
|
54
|
+
double getInitialTime(void);
|
|
55
|
+
double getFinalTime(void);
|
|
56
|
+
double getSaveper(void);
|
|
54
57
|
char* run_model(const char* inputs);
|
|
55
58
|
void runModelWithBuffers(double* inputs, double* outputs);
|
|
56
59
|
void run(void);
|
|
@@ -58,11 +61,6 @@ void startOutput(void);
|
|
|
58
61
|
void outputVar(double value);
|
|
59
62
|
void finish(void);
|
|
60
63
|
|
|
61
|
-
// API (defined by the generated model)
|
|
62
|
-
double getInitialTime(void);
|
|
63
|
-
double getFinalTime(void);
|
|
64
|
-
double getSaveper(void);
|
|
65
|
-
|
|
66
64
|
// Functions implemented by the generated model
|
|
67
65
|
void initConstants(void);
|
|
68
66
|
void initLevels(void);
|
package/src/sde-compare.js
CHANGED
|
@@ -79,6 +79,10 @@ export let compare = async (vensimfile, sdefile, opts) => {
|
|
|
79
79
|
}
|
|
80
80
|
if (noDATDifference) {
|
|
81
81
|
pr(`Data were the same for ${vensimfile} and ${sdefile}`)
|
|
82
|
+
return true
|
|
83
|
+
} else {
|
|
84
|
+
pr(`Data differences detected for ${vensimfile} and ${sdefile}`)
|
|
85
|
+
return false
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
let isZero = value => {
|
package/src/sde-test.js
CHANGED
|
@@ -53,7 +53,12 @@ export let test = async (model, opts) => {
|
|
|
53
53
|
let vensimPathname = path.join(modelDirname, `${modelName}.dat`)
|
|
54
54
|
let p = path.parse(logPathname)
|
|
55
55
|
let sdePathname = path.format({ dir: p.dir, name: p.name, ext: '.dat' })
|
|
56
|
-
await compare(vensimPathname, sdePathname, opts)
|
|
56
|
+
let noDiffs = await compare(vensimPathname, sdePathname, opts)
|
|
57
|
+
if (!noDiffs) {
|
|
58
|
+
// Exit with a non-zero error code if differences were detected
|
|
59
|
+
console.error()
|
|
60
|
+
process.exit(1)
|
|
61
|
+
}
|
|
57
62
|
} catch (e) {
|
|
58
63
|
// Exit with a non-zero error code if any step failed
|
|
59
64
|
console.error(`ERROR: ${e.message}\n`)
|