33 hoc_execerror(path.c_str(),
"directory did not exist and makePath for it failed");
44 std::string path(
".");
46 path = hoc_gargstr(1);
51 std::string
get_filename(
const std::string& path, std::string file_name){
52 std::string
fname(path+
'/'+file_name);
60 std::ofstream fs(fname);
62 hoc_execerror(
"nrncore_write write_mem_mech_types could not open for writing: %s\n", fname);
76 FILE* f =
fopen(fname,
"w");
78 hoc_execerror(
"nrncore_write write_globals could not open for writing: %s\n", fname);
87 for (
void* sp =
NULL;;) {
91 fprintf(f,
"%s[%d]\n", name, size);
92 for (
int i=0;
i < size; ++
i) {
96 fprintf(f,
"%s %.20g\n", name, val[0]);
119 FILE* f =
fopen(fname,
"wb");
121 hoc_execerror(
"nrncore_write write_nrnthread could not open for writing:", fname);
136 f =
fopen(fname,
"w");
138 hoc_execerror(
"nrncore_write write_nrnthread could not open for writing:", fname);
144 int ngid, n_real_gid,
nnode, ndiam, nmech, *tml_index, *ml_nodecount, nidata,
147 nmech, tml_index, ml_nodecount, nidata, nvdata, nweight);
150 fprintf(f,
"%d n_real_gid\n", n_real_gid);
151 fprintf(f,
"%d nnode\n", nnode);
152 fprintf(f,
"%d ndiam\n", ndiam);
153 fprintf(f,
"%d nmech\n", nmech);
155 for (
int i=0;
i < nmech; ++
i) {
157 fprintf(f,
"%d\n", ml_nodecount[i]);
160 delete [] ml_nodecount;
163 fprintf(f,
"%d nvdata\n", nvdata);
164 fprintf(f,
"%d nweight\n", nweight);
183 for (
size_t i = 0;
i < mla.size(); ++
i) {
184 int type = mla[
i].first;
186 std::vector<int> pointer2type;
203 sz = pointer2type.size();
204 fprintf(f,
"%d npointer\n",
int(sz));
211 int *output_vindex, *netcon_pnttype, *netcon_pntindex;
212 double *output_threshold, *weights, *delays;
214 netcon_pnttype, netcon_pntindex, weights, delays);
216 delete [] output_vindex;
218 delete [] output_threshold;
224 delete [] netcon_pnttype;
226 delete [] netcon_pntindex;
235 fprintf(f,
"%d bbcorepointer\n", n);
238 for (
size_t i = 0;
i < mla.size(); ++
i) {
239 int type = mla[
i].first;
241 int icnt, dcnt, *iArray;
double* dArray;
244 fprintf(f,
"%d\n%d\n", icnt, dcnt);
267 size_t n = fwrite(p,
sizeof(
int), size, f);
273 size_t n = fwrite(p,
sizeof(
double), size, f);
277 #define writeint(p,size) writeint_(p, size, f) 278 #define writedbl(p,size) writedbl_(p, size, f) 284 for (
int i = 0;
i < nitem; ++
i) {
285 size_t n = fwrite(data[
i],
sizeof(
double), szitem, f);
291 double* d1 =
new double[nitem*szitem];
293 for (
int i = 0;
i < nitem; ++
i) {
294 for (
int j=0;
j < szitem; ++
j) {
295 d1[k++] = data[
i][
j];
305 std::vector<int> indices;
307 fprintf(f,
"%d VecPlay instances\n",
int(indices.size()));
308 for (
auto i: indices) {
309 int vptype, mtype, ix, sz;
double *yvec, *tvec;
312 if (
nrnthread_dat2_vecplay_inst(nt.
id,
i, vptype, mtype, ix, sz, yvec, tvec, unused, unused, unused)) {
326 if (fgets(s, size, f) ==
NULL) {
331 if (n && s[n-1] ==
'\n') {
351 std::vector<int> iSend;
355 if ( cgs[iInt].group_id >= 0) {
356 iSend.push_back(cgs[iInt].group_id);
361 std::vector<int> iRecv, iDispl;
369 int num_datasets = iSend.size();
374 nrnmpi_int_gather(&num_datasets,
begin_ptr(iRecv), 1, 0);
376 iRecv[0] = num_datasets;
379 iRecv[0] = num_datasets;
389 iDispl[iInt] = iSumThread;
390 iSumThread += iRecv[iInt];
395 std::vector<int> iRecvVec(iSumThread);
402 for (
int iInt = 0; iInt < num_datasets; ++iInt) {
403 iRecvVec[iInt] = iSend[iInt];
407 for (
int iInt = 0; iInt < num_datasets; ++iInt) {
408 iRecvVec[iInt] = iSend[iInt];
420 std::stringstream ss;
421 ss << path <<
"/files.dat";
423 std::string filename = ss.str();
426 if (append ==
false) {
427 fp =
fopen(filename.c_str(),
"w");
429 hoc_execerror(
"nrncore_write: could not open for writing:", filename.c_str());
432 fp =
fopen(filename.c_str(),
"r+");
434 hoc_execerror(
"nrncore_write append: could not open for modifying:", filename.c_str());
438 constexpr
int max_line_len = 20;
439 char line[max_line_len];
446 if ((strlen(line) != n)
449 hoc_execerror(
"nrncore_write append: existing files.dat has inconsisten version:", line);
459 if (strcmp(line,
"-1") != 0) {
461 hoc_execerror(
"nrncore_write append: existing files.dat does not have a gap junction indicator\n",
NULL);
471 long pos = ftell(fp);
474 if (sscanf(line,
"%d", &oldval) != 1) {
480 hoc_execerror(
"nrncore_write append: existing files.dat has gap junction indicator where we expected a groupgid count.",
NULL);
482 iSumThread += oldval;
483 fseek(fp, pos, SEEK_SET);
485 fprintf(fp,
"%10d\n", iSumThread);
489 fseek(fp, 0, SEEK_END);
493 for (
int i = 0;
i < iRecvVec.size(); ++
i) {
505 std::stringstream ss;
506 ss << path <<
"/" << gid <<
"_3.dat";
508 std::string
fname(ss.str());
521 for(
size_t i = 0;
i < minfo.
size();
i++) {
527 for(
size_t j = 0;
j < c->
size();
j++) {
int nrnthread_dat2_3(int tid, int nweight, int *&output_vindex, double *&output_threshold, int *&netcon_pnttype, int *&netcon_pntindex, double *&weights, double *&delays)
Section to segment mapping.
int nrnthread_dat2_2(int tid, int *&v_parent_index, double *&a, double *&b, double *&area, double *&v, double *&diamvec)
T * begin_ptr(std::vector< T > &v)
int nrnthread_dat2_mech(int tid, size_t i, int dsz_inst, int *&nodeindices, double *&data, int *&pdata, std::vector< int > &pointer2type)
bool makePath(const std::string &path)
void writeint_(int *p, size_t size, FILE *f)
double * contiguous_art_data(double **data, int nitem, int szitem)
int nsec
number of sections in section list
std::vector< MlWithArtItem > MlWithArt
size_t size()
number of section lists
void(* nrnthread_v_transfer_)(NrnThread *)
Represent main neuron object computed by single thread.
int nrnthread_dat2_vecplay(int tid, std::vector< int > &indices)
void write_memb_mech_types(const char *fname)
int nrnthread_dat2_1(int tid, int &ngid, int &n_real_gid, int &nnode, int &ndiam, int &nmech, int *&tml_index, int *&ml_nodecount, int &nidata, int &nvdata, int &nweight)
static philox4x32_key_t k
std::string get_write_path()
std::vector< SecMapping * > secmapping
list of section lists (like soma, axon, apic)
std::string name
name of section list
#define writedbl(p, size)
int nrnthread_dat2_corepointer(int tid, int &n)
void write_contiguous_art_data(double **data, int nitem, int szitem, FILE *f)
int nrnthread_dat2_corepointer_mech(int tid, int type, int &icnt, int &dcnt, int *&iArray, double *&dArray)
bool isDirExist(const std::string &path)
int num_segments()
total number of segments in a cell
void append(Item *ql, Item *q)
void writedbl_(double *p, size_t size, FILE *f)
int const size_t const size_t n
void(*)(double *, int *, int *, int *, double *, Datum *, Datum *, NrnThread *) bbcore_write_t
int num_sections()
total number of sections in a cell
static void nrnmpi_barrier()
NetCvode * net_cvode_instance
static void fgets_no_newline(char *s, int size, FILE *f)
static const char * fname(const char *name)
void * get_global_dbl_item(void *p, const char *&name, int &size, double *&val)
void hoc_execerror(const char *, const char *)
void write_nrnthread(const char *path, NrnThread &nt, CellGroup &cg)
short * nrn_is_artificial_
bbcore_write_t * nrn_bbcore_write_
fprintf(stderr, "Don't know the location of params at %p\, pp)
Compartment mapping information for NrnThread.
size_t size()
number of cells
void nrnbbcore_vecplay_write(FILE *f, NrnThread &nt)
std::string get_filename(const std::string &path, std::string file_name)
int * nrn_prop_param_size_
void write_globals(const char *fname)
void create_dir_path(const std::string &path)
create directory with given path
VEC * cgs(MTX_FN A, void *A_params, VEC *b, VEC *r0, double tol, VEC *x)
const char * bbcore_write_version
int nrnthread_dat2_vecplay_inst(int tid, int i, int &vptype, int &mtype, int &ix, int &sz, double *&yvec, double *&tvec, int &last_index, int &discon_index, int &ubound_index)
void write_memb_mech_types_direct(std::ostream &s)
static char line[MAXLINE]
#define writeint(p, size)
void write_nrnthread_task(const char *path, CellGroup *cgs, bool append)
Write all dataset ids to files.dat.
uint32_t nrnran123_get_globalindex()
std::vector< CellMapping * > mapping
list of cells mapping
Compartment mapping information for a cell.
void nrn_write_mapping_info(const char *path, int gid, NrnMappingInfo &minfo)
dump mapping information to gid_3.dat file
std::vector< int > segments
list of segments
std::vector< int > sections
list sections associated with each segment