Page 1 of 1

problem with this_node(x)/parent_node(x)

Posted: Mon Jul 18, 2005 8:37 am
by peter
Hello,
I've got a problem using commands
this_node(x)
parent_node(x)
to obtain segment number associated with a specific position x
on a section. If I execute e.g.
######################
load_file("nrngui.hoc")
create soma
access soma
soma nseg = 5
soma L = 18.8

print this_node(0)
1.3500451e+08
print this_node(1)
1.3539657e+08
#######################
using parent_node(x) I got similar results. I expected
to achieve first >1< for segment 1 and than >5< for
segment 5. Maybe someone could tell me what is
going wrong ?

peter

Posted: Tue Jul 19, 2005 10:07 am
by hines
The descriptions in the documentation for this_node and parent_node are bizarrely misleading. Just like this_section and parent_section, they return the pointer value coded as a double precision number and are conceivably useful only for comparison. Nowadays, with 64 bit addresses it is no longer possible to safely represent a pointer with a double.
I will update the documentation to indicate that this_section() and parent_section() have been superceded by the SectionRef class, specifically, SectionRef.sec and SectionRef.parent .
Off hand I cannot think of any purpose at the hoc level for a pointer to an internal segment. At any rate, a hoc function that returns the segment number is

Code: Select all

func segnum() {
        if ($1 <= 0) {
                return 0
        }else if ($1 >= 1) {
                return nseg+1
        }else {
                return int($1*nseg + .5)
        }
}
but notice that for other purposes you may wish to avoid the x=0 and x=1 cases and return an integer in the range 0 to nseg-1 where 0 corresponds to the center of the first non-zero area segment.