Variable file name

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

Variable file name

Post by Manorama »

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 {
              	xs=-18750.5
                ys=0
                zs=d.x[i]
	
	        define_geometry()
                setpointers()
	        initialize()

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

               forall{
	              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))
	                                                }
                       }
               f2.close()
}
ted
Site Admin
Posts: 5786
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Variable file name

Post by ted »

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).
Manorama
Posts: 2
Joined: Sun Nov 18, 2018 3:23 pm

Re: Variable file name

Post by Manorama »

Got it. Thank you.
Post Reply