Variable file name

Anything that doesn't fit elsewhere.
Post Reply
Posts: 2
Joined: Sun Nov 18, 2018 3:23 pm

Variable file name

Post by Manorama » Mon May 20, 2019 2:21 pm

I want to make an axon and shift its position according to the z coordinates in Vector d. Also, I want to store the coordinates of the axon compartments in separate files. I have defined the geometry using a function "define_geometry" written outside this code. So, I called the function in a loop and tried saving the coordinates in files with variable name, ending with the z coordinate to help differentiate them. But I am getting a syntax error in the line where I define f2 as new File(). I think there maybe syntax error in the way I defined the variable file name, but I am not sure what is the syntax error. Please suggest what could be the error here.

Code: Select all

objref d
d = new Vector(8)
d.x[0] = 5
d.x[1] = 10
d.x[2] = 25
d.x[3] = 50
d.x[4] = 75
d.x[5] = 100
d.x[6] = 125
d.x[7] = 150

for i=0, 7 {

               objref f2
               f2 = new File()
               fname = printf("%s%d","coordinates",d.x[i])
               f2.wopen(fname) // coordinate file name

	              for (x) if(x!=0 && x!=1){
		               f2.printf("%s(%g)\t%f\t%f\t%f\n", secname(), x, x_xtra(x), y_xtra(x), z_xtra(x))

Site Admin
Posts: 5727
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: Variable file name

Post by ted » Tue May 21, 2019 11:06 am

In hoc, by default, a user-created variable name is the name of a floating point scalar variable. If you want to use a user-created name as a strdef or objref, then you must first declare it to be a strdef or objref at the "top level of the hoc interpreter." This basically means that the declaration cannot be inside a pair of curly brackets. The only exception is a name declared to be a localobj inside a proc or func (a localobj is like an objref but its scope is limited to the proc or func that declared it).

Posts: 2
Joined: Sun Nov 18, 2018 3:23 pm

Re: Variable file name

Post by Manorama » Wed May 22, 2019 2:42 pm

Got it. Thank you.

Post Reply