9
9
#include " coreneuron/nrniv/nrniv_decl.h"
10
10
#include " coreneuron/nrnoc/membfunc.h"
11
11
#include " coreneuron/nrniv/nrn_assert.h"
12
+ #include " coreneuron/nrniv/nrn2core_direct.h"
13
+
14
+ void * (*nrn2core_get_global_dbl_item_)(void *, const char *& name, int & size, double *& val);
15
+ int (*nrn2core_get_global_int_item_)(const char * name);
12
16
13
17
using namespace std ;
14
18
namespace coreneuron {
@@ -37,69 +41,99 @@ void set_globals(const char* path, bool cli_global_seed, int cli_global_seed_val
37
41
(*n2v)[" dt" ] = PSD (0 , &dt);
38
42
(*n2v)[" t" ] = PSD (0 , &t);
39
43
40
- string fname = string (path) + string (" /globals.dat" );
41
- FILE* f = fopen (fname.c_str (), " r" );
42
- if (!f) {
43
- printf (" ignore: could not open %s\n " , fname.c_str ());
44
- delete n2v;
45
- n2v = NULL ;
46
- return ;
47
- }
48
-
49
- char line[256 ];
50
- char name[256 ];
51
- double val;
52
- int n;
53
-
54
- fscanf (f, " %s\n " , line);
55
- check_bbcore_write_version (line);
44
+ if (corenrn_embedded) { // CoreNEURON embedded, get info direct from NEURON
56
45
57
- for (;;) {
58
- nrn_assert (fgets (line, 256 , f) != NULL );
59
- N2V::iterator it;
60
- if (sscanf (line, " %s %lf" , name, &val) == 2 ) {
61
- if (strcmp (name, " 0" ) == 0 ) {
62
- break ;
63
- }
46
+ const char * name;
47
+ int size;
48
+ double * val = NULL ;
49
+ for (void * p = NULL ; (p = (*nrn2core_get_global_dbl_item_)(p, name, size, val)) != NULL ;) {
50
+ N2V::iterator it;
64
51
it = n2v->find (name);
65
52
if (it != n2v->end ()) {
66
- nrn_assert (it->second .first == 0 );
67
- *(it->second .second ) = val;
68
- }
69
- } else if (sscanf (line, " %[^[][%d]\n " , name, &n) == 2 ) {
70
- if (strcmp (name, " 0" ) == 0 ) {
71
- break ;
53
+ if (size == 0 ) {
54
+ nrn_assert (it->second .first == 0 );
55
+ *(it->second .second ) = val[0 ];
56
+ } else {
57
+ nrn_assert (it->second .first == (size_t )size);
58
+ double * pval = it->second .second ;
59
+ for (int i = 0 ; i < size; ++i) {
60
+ pval[i] = val[i];
61
+ }
62
+ }
72
63
}
73
- it = n2v->find (name);
74
- if (it != n2v->end ()) {
75
- nrn_assert (it->second .first == (size_t )n);
76
- double * pval = it->second .second ;
77
- for (int i = 0 ; i < n; ++i) {
78
- nrn_assert (fgets (line, 256 , f) != NULL );
79
- nrn_assert (sscanf (line, " %lf\n " , &val) == 1 );
80
- pval[i] = val;
64
+ delete[] val;
65
+ }
66
+ secondorder = (*nrn2core_get_global_int_item_)(" secondorder" );
67
+ nrnran123_set_globalindex ((*nrn2core_get_global_int_item_)(" Random123_global_index" ));
68
+
69
+ } else { // get the info from the globals.dat file
70
+
71
+ string fname = string (path) + string (" /globals.dat" );
72
+ FILE* f = fopen (fname.c_str (), " r" );
73
+ if (!f) {
74
+ printf (" ignore: could not open %s\n " , fname.c_str ());
75
+ delete n2v;
76
+ n2v = NULL ;
77
+ return ;
78
+ }
79
+
80
+ char line[256 ];
81
+ char name[256 ];
82
+ double val;
83
+ int n;
84
+
85
+ fscanf (f, " %s\n " , line);
86
+ check_bbcore_write_version (line);
87
+
88
+ for (;;) {
89
+ nrn_assert (fgets (line, 256 , f) != NULL );
90
+ N2V::iterator it;
91
+ if (sscanf (line, " %s %lf" , name, &val) == 2 ) {
92
+ if (strcmp (name, " 0" ) == 0 ) {
93
+ break ;
94
+ }
95
+ it = n2v->find (name);
96
+ if (it != n2v->end ()) {
97
+ nrn_assert (it->second .first == 0 );
98
+ *(it->second .second ) = val;
81
99
}
100
+ } else if (sscanf (line, " %[^[][%d]\n " , name, &n) == 2 ) {
101
+ if (strcmp (name, " 0" ) == 0 ) {
102
+ break ;
103
+ }
104
+ it = n2v->find (name);
105
+ if (it != n2v->end ()) {
106
+ nrn_assert (it->second .first == (size_t )n);
107
+ double * pval = it->second .second ;
108
+ for (int i = 0 ; i < n; ++i) {
109
+ nrn_assert (fgets (line, 256 , f) != NULL );
110
+ nrn_assert (sscanf (line, " %lf\n " , &val) == 1 );
111
+ pval[i] = val;
112
+ }
113
+ }
114
+ } else {
115
+ nrn_assert (0 );
82
116
}
83
- } else {
84
- nrn_assert (0 );
85
117
}
86
- }
87
118
88
- while (fgets (line, 256 , f)) {
89
- if (sscanf (line, " %s %d" , name, &n) == 2 ) {
90
- if (strcmp (name, " secondorder" ) == 0 ) {
91
- secondorder = n;
92
- } else if ( strcmp (name, " Random123_globalindex" ) == 0 ) {
93
- nrnran123_set_globalindex ((uint32_t )n);
119
+ while (fgets (line, 256 , f)) {
120
+ if (sscanf (line, " %s %d" , name, &n) == 2 ) {
121
+ if (strcmp (name, " secondorder" ) == 0 ) {
122
+ secondorder = n;
123
+ } else if (strcmp (name, " Random123_globalindex" ) == 0 ) {
124
+ nrnran123_set_globalindex ((uint32_t )n);
125
+ }
94
126
}
95
127
}
96
- }
97
128
98
- fclose (f);
99
- // overwrite global.dat config if seed is specified on Command line
100
- if (cli_global_seed) {
101
- nrnran123_set_globalindex ((uint32_t )cli_global_seed_value);
129
+ fclose (f);
130
+
131
+ // overwrite global.dat config if seed is specified on Command line
132
+ if (cli_global_seed) {
133
+ nrnran123_set_globalindex ((uint32_t )cli_global_seed_value);
134
+ }
102
135
}
136
+
103
137
#if 0
104
138
for (N2V::iterator i = n2v->begin(); i != n2v->end(); ++i) {
105
139
printf("%s %ld %p\n", i->first.c_str(), i->second.first, i->second.second);
@@ -109,4 +143,5 @@ void set_globals(const char* path, bool cli_global_seed, int cli_global_seed_val
109
143
delete n2v;
110
144
n2v = NULL ;
111
145
}
146
+
112
147
} // namespace coreneuron
0 commit comments