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