NEURON
nrnnemo.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 #include "section.h"
4 
5 
6 #define OBSOLETE 1
7 
8 #if !OBSOLETE
9 #include "membfunc.h"
10 #include "hocassrt.h"
11 
12 /* basic loop taken from topology() in solve.cpp */
13 static FILE *fin, *fmark, *fdat;
14 static int inode;
15 static dashes(), file_func(), dat_head();
16 #define MAXMARKS 32
17 static long* marksec;
18 static printline();
19 
20 extern int section_count;
21 extern Section** secorder;
22 #endif
23 
24 void nemo2neuron(void) {
25  hoc_retpushx(1.0);
26 }
27 
28 void neuron2nemo(void) {
29 #if OBSOLETE
30  hoc_execerror("neuron2nemo:", "implementation is obsolete");
31 #else
32  short i, isec, imark;
33  extern int tree_changed;
34  char name[50];
35 
36  if (tree_changed) {
38  }
39  Sprintf(name, "in/%s", gargstr(1));
40  if ((fin = fopen(name, "w")) == (FILE*) 0) {
41  hoc_execerror("Can't write to ", name);
42  }
43  Sprintf(name, "mark/%s", gargstr(1));
44  if ((fmark = fopen(name, "w")) == (FILE*) 0) {
45  hoc_execerror("Can't write to ", name);
46  }
47  Sprintf(name, "dat/%s", gargstr(1));
48  if ((fdat = fopen(name, "w")) == (FILE*) 0) {
49  hoc_execerror("Can't write to ", name);
50  }
51  dat_head();
52 
53  /* set up the mark for every section */
54  imark = 1;
55  marksec = (long*) ecalloc(section_count, sizeof(long));
56  for (i = 1; i < section_count; i++) {
57  isec = i;
58  if (marksec[isec]) {
59  marksec[i] = marksec[isec];
60  } else {
61  if (imark < MAXMARKS) {
62  marksec[i] = 1L << (imark++);
63  file_func(secorder[isec]);
64  }
65  }
66  }
67  Fprintf(fin, "/* created by NEURON */\n");
68  inode = 0;
69  for (i = 0; i < rootnodecount; i++) {
70  printline(v_node[i]->child, 0, 0., (double) (i * 100));
71  dashes(v_node[i]->child, 0., (double) (i * 100), 0., 1);
72  }
73  free((char*) marksec);
74  fclose(fin);
75  fclose(fmark);
76 #endif
77  hoc_retpushx(1.0);
78 }
79 
80 #if !OBSOLETE
81 static dashes(Section* sec, double x, double y, double theta, int leftend) {
82  Section* ch;
83  int i, nrall, irall;
84  double cos(), sin(), xx, yy, ttheta, dx;
85 
86  dx = section_length(sec) / ((double) sec->nnode - 1);
87  nrall = (int) sec->prop->dparam[4].val;
88  for (irall = 0; irall < nrall; irall++) {
89  xx = x;
90  yy = y;
91  ttheta = theta + (double) (nrall - 2 * irall - 1) / (double) nrall;
92  for (i = 0; i < sec->nnode - 1; i++) {
93  xx += dx * cos(ttheta);
94  yy += dx * sin(ttheta);
95  printline(sec, i, xx, yy);
96  }
97  for (i = sec->nnode - 1; i >= 0; i--) {
98  if ((ch = sec->pnode[i]->child) != (Section*) 0) {
99  if (i == sec->nnode - 1) {
100  dashes(ch, xx, yy, ttheta, 0);
101  } else {
102  dashes(ch, xx, yy, ttheta + .5, 0);
103  }
104  }
105  if (i < sec->nnode - 1) {
106  xx -= dx * cos(ttheta);
107  yy -= dx * sin(ttheta);
108  }
109  }
110  if (leftend) {
111  ttheta = 3.14159 - .5;
112  }
113  if ((ch = sec->sibling) != (Section*) 0) {
114  dashes(ch, x, y, ttheta + .5, 0);
115  }
116  }
117 }
118 
119 static double diamval(Node* nd) {
120  Prop* p;
121 
122  for (p = nd->prop; p; p = p->next) {
123  if (p->type == MORPHOLOGY) {
124  break;
125  }
126  }
127  assert(p);
128  return p->param[0];
129 }
130 
131 static void printline(Section* sec, int i, double x, double y) {
132  char type;
133  int nb;
134  Section* csec;
135  Node* nd;
136  double d;
137 
138  ++inode;
139  assert(sec->nnode > 1);
140  type = 'C';
141  nd = sec->pnode[i];
142  d = diamval(nd);
143  nb = 0;
144  for (csec = nd->child; csec; csec = csec->sibling) {
145  nb += (int) csec->prop->dparam[4].val;
146  }
147  if (i == sec->nnode - 2) {
148  ++i;
149  nd = sec->pnode[i];
150  for (csec = nd->child; csec; csec = csec->sibling) {
151  nb += (int) csec->prop->dparam[4].val;
152  }
153  }
154  if (i < sec->nnode - 2) {
155  nb++;
156  }
157  if (nb > 2) { /*many branches*/
158  type = 'B';
159  x -= .001;
160  while (nb > 2) {
161  fwrite((char*) &marksec[sec->order], sizeof(long), 1, fmark);
162  Fprintf(fin, "%d\t%c\t%g\t%g\t0\t%g\n", inode++, type, (x += .001), y, d);
163  --nb;
164  }
165  } else if (nb == 2) { /*one branch*/
166  type = 'B';
167  } else if (nb == 0) {
168  type = 'T';
169  }
170  fwrite((char*) &marksec[sec->order], sizeof(long), 1, fmark);
171  Fprintf(fin, "%d\t%c\t%g\t%g\t0\t%g\n", inode, type, x, y, d);
172 }
173 
174 /* modified from nemo.cpp */
175 static void file_func(Section* sec) {
176  int active;
177  Node* nd;
178  Prop* p;
179  Symbol *s, *hoc_lookup();
180  static int hhtype = 0;
181 
182  if (!hhtype) {
183  s = hoc_lookup("HH");
184  hhtype = s->subtype;
185  }
186  nd = sec->pnode[0];
187 
188  active = 0;
189  for (p = nd->prop; p; p = p->next) {
190  if (p->type == hhtype) {
191  active = 1;
192  }
193  }
194 
195  assert(sec->prop->dparam[0].sym);
196  fprintf(fdat, "%s\n", sec->prop->dparam[0].sym->name);
197  fprintf(fdat, "^area %g\n", 1.);
198  fprintf(fdat, "^Rm %g\n", 1.);
199  fprintf(fdat, "^active %d\n", active);
200  fprintf(fdat, "^synapse %d\n", 0);
201  fprintf(fdat, "^Erev %g\n", 0.);
202  fprintf(fdat, "^gback %g\n", 0.);
203  fprintf(fdat, "^gsyn %g\n", 0.);
204  fprintf(fdat, "^tstart %g\n", 0.);
205  fprintf(fdat, "^twidth %g\n", 0.);
206 }
207 
208 static void dat_head(void) {
209  double Ra = 35.4;
210 
211  fprintf(fdat, "freq\n");
212  fprintf(fdat, "%d %g %g\n", 4, 1., 1000.);
213 
214  fprintf(fdat, "tran\n");
215  fprintf(fdat, "%g %g\n", .1, 10.);
216 
217  fprintf(fdat, "elec\n");
218  fprintf(fdat, "%g %g %g\n", 1000., 1.e-6, Ra);
219 
220  fprintf(fdat, "syn\n");
221  fprintf(fdat, "%g %g\n", 30., -15.);
222 
223  fprintf(fdat, "hh\n");
224  fprintf(fdat, "%g %g %g %g %g %g\n", 1., 1., 1., 1., 1., 1.);
225 
226  fprintf(fdat, "batt\n");
227  fprintf(fdat, "%g %g\n", 115., -12.);
228 
229  fprintf(fdat, "%10d\n", 9999);
230 }
231 
232 #endif
Section ** secorder
Definition: solve.cpp:77
int section_count
Definition: solve.cpp:76
double section_length(Section *sec)
Definition: cabcode.cpp:387
short type
Definition: cabvars.h:9
static double active(void *v)
Definition: cvodeobj.cpp:212
int tree_changed
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
void hoc_retpushx(double x)
Definition: hocusr.cpp:154
Symbol * hoc_lookup(const char *)
#define assert(ex)
Definition: hocassrt.h:32
void * ecalloc(size_t n, size_t size)
Definition: symbol.cpp:215
#define gargstr
Definition: hocdec.h:14
#define sec
Definition: md1redef.h:13
#define i
Definition: md1redef.h:12
#define MORPHOLOGY
Definition: membfunc.h:63
#define Sprintf
Definition: model.h:233
#define Fprintf
Definition: model.h:234
sin
Definition: extdef.h:3
cos
Definition: extdef.h:3
char * name
Definition: init.cpp:16
#define fprintf
Definition: mwprefix.h:30
void setup_topology()
for(i=0;i< n;i++)
size_t p
void nemo2neuron(void)
Definition: nrnnemo.cpp:24
void neuron2nemo(void)
Definition: nrnnemo.cpp:28
static void dashes(Section *sec, int offset, int first)
Definition: solve.cpp:304
#define fin
Definition: redef.h:60
FILE * fopen()
Definition: section.h:133
struct Prop * prop
Definition: section.h:152
Section * child
Definition: section.h:153
Definition: section.h:214
Datum * dparam
Definition: section.h:220
struct Prop * prop
Definition: section.h:63
struct Section * sibling
Definition: section.h:46
Definition: model.h:57
long subtype
Definition: model.h:59
double val
Definition: hocdec.h:178