Connecting a new section to your model within a process or function

The basics of how to develop, test, and use models.
Post Reply
DavidSwygart
Posts: 11
Joined: Mon Dec 03, 2018 6:50 pm

Connecting a new section to your model within a process or function

Post by DavidSwygart »

Hello, I am trying to add new sections to an existing model. I can create the new sections and successfully access the sections of the old model that I want to connect them to (using forsec), however, I get a syntax error when trying to connect them together. This only seems to occur while working within a function or process (See example code below). Any suggestions?

Code: Select all

create soma
access soma

proc ConnectAnAxon() {
  create axon[3]
  connect axon[0](0), 1
}
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Connecting a new section to your model within a process or function

Post by ted »

Read chapter 12 of the NEURON Book and you'll see the cause of your problem. Actually, this should also be explained in the Programmer's Reference. For those who don't have the book, here's a brief summary.

hoc is a typed language. User-created names can be used to refer to scalars, arrays, strings, names for user-defined classes, class names, object instances, or sections. The first occurrence of a user-created name in a program "declares" which of these things it refers to. The only type declaration that is completely automatic is scalar. So
foo = 3.14
is OK (makes foo a scalar), and this "declaration by assignment" works regardless of whether foo first appears inside or outside of a proc or func. If you want foo to be an array of double precision numbers, you first have to declare at least
double foo[1]
outside of any proc or func so that hoc knows foo is an array. Then you can do

Code: Select all

proc bigfoo() {
  double foo[3]
  for i = 0,2 foo[i] = i*i
}
Similarly, hoc won't let you execute
create bar
inside a func or proc unless a
create bar
statement has already been executed outside of a func or proc. And it definitely won't let you create an "array of sections"
create axon[3]
inside a func or proc unless a statement like
create axon[1]
has already been executed outside of a func or proc.
Post Reply