Syntax errors in HOC

Anything that doesn't fit elsewhere.
Post Reply
cobaltplusone

Syntax errors in HOC

Post by cobaltplusone »

I am having difficulties debugging some HOC code that I am working with. When I run the code, I get the following error message:

Code: Select all

nrniv: syntax error
 in ModelB.hoc near line 311
                        s = 0
        ^
xopen("ModelB.hoc"        )
execute1("{xopen("ModelB.hoc")}"      )
load_file("C:/Users/Username/Documents/Lab - Data/Nerve Simulations/Models/ModelB.hoc"    )
        0 
nrniv: syntax error
 in ModelB.hoc near line 324
                                        inodes[s].e_extracellular = Out
I cannot figure out what is wrong with either "s = 0" or "inodes[s].e_extracellular = Out". These two lines fall within the integrate procedure (see below). When I try adding print statements for debugging purposes, none of them are actually executed. Any insights into how I should proceed would be thoroughly appreciated. Thank you!

Code: Select all

//Integrates the model 
proc integrate() {                       
	while (t<tstop) {
		if(t > 1 && t < 1+stimtime){			
			n = 0
			m = 0
			s = 0
			flag = 0
			for i = 0,nodes*11-11{
				flag = 0
				n = n+1
				if(n == 1){
					assignExt(i,1,1)
					node[m].e_extracellular = Out 
					flag = 1
				}
					
				if(n == 2){
					assignExt(i,Ran,Rax)
					inodes[s].e_extracellular = Out
					s = s+1
					flag = 1
				}
				if(n == 11){
					assignExt(i,Rax,Ran)
					inodes[s].e_extracellular = Out
					s = s+1
					flag = 1
				}    
				if(flag == 0){
					assignExt(i,Rax,Rax)
					inodes[s].e_extracellular = Out
					s = s+1
					flag = 1
				}
				if(n == 11){
					n = 0
					m = m+1
				}
			}
		}
		if(t > 1+stimtime){
			n = 0
			m = 0
			s = 0
			flag = 0
			for i = 0,nodes*11-11{
				flag = 0
				n = n+1
				if(n == 1){
					assignExt(i,1,1)
					node[m].e_extracellular = 0 
					flag = 1
				}
				if(n == 2){
					assignExt(i,Ran,Rax)
					inodes[s].e_extracellular = 0
					s = s+1
					flag = 1
				}
				if(n == 11){
					assignExt(i,Rax,Ran)
					inodes[s].e_extracellular = 0
					s = s+1
					flag = 1
				}    
				if(flag == 0){
					assignExt(i,Rax,Rax)
					inodes[s].e_extracellular = 0
					s = s+1
					flag = 1
				}
				if(n == 11){
					n = 0
					m = m+1
				}
			}
		}			

		fadvance()

		if(writetofile == 1){
			for i =0,nodes-1{
			  //savv.printf("%f \n",node[i].v) //Uncomment this part if you want to save the voltage profile for each trial, this slows down the process significantly but can useful to gain an sense of what is going on
			}
		}

		//Checks nodal segments for presence of significant depolarization (action potential). Checks both middle segments as well as segments further down the axon on both sites to make sure that the action potential propagates
		if(writetofile == 1 && (node[int(nodes/2)-2].v > -25 || node[int(nodes/2)-1].v > -25 || node[int(nodes/2)].v > -25 || node[int(nodes/2)+1].v > -25)){
			result[0] = 1
		}

		if(writetofile == 1 && node[int(nodes/2)-6].v > -25){
			result[1] = 1
		}

		if(writetofile == 1 && node[int(nodes/2)+6].v > -25){
			result[2] = 1
		}
	}
}
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Syntax errors in HOC

Post by ted »

From the "keyhole view" provided in your post, it's hard to know exactly what proc integrate() is supposed to do, let alone what to make of the error message. I don't see any obvious trigger for a syntax error message. integrate()'s design goal might be accomplished more easily by using NEURON-specific features such as Vector.play and/or events (in particular FInitializeHandler and cvode.event()); the result would be much simpler code that is easier to debug and executes more quickly. But absent a clear idea of what you're trying to do, I can't give any more specific recommendation in this regard.

If you prefer to stick with your present approach, then my suggestion is to revert to the most recent previous version of your program that worked properly, and try to extend from there. That assumes that your code development has (1) used version management and (2) followed the cycle of

Code: Select all

start with something small and simple that works
REPEAT
  add a slight increase of complexity
  REPEAT
    test and revise
  UNTIL the revision works
UNTIL a final version is achieved that works properly
Another way to proceed is to comment out most of the contents of proc integrate--say all but the first if() statement ( if(t > 1 && t < 1+stimtime){ ) and the 4 assignment statements

Code: Select all

             n = 0
             m = 0
             s = 0
             flag = 0
that it is supposed to execute when the conditional evaluates to TRUE. That should parse without error.

Then

Code: Select all

REPEAT
  uncomment a bit more code
  if the parser complains, identify and fix the problem
UNTIL all statements in proc integrate() parse without error
The first bit I would uncomment is the for loop inside
if(t > 1 && t < 1+stimtime){ }
which begins
for i = 0,nodes*11-11{
and just the first two assignment statements inside it
flag = 0
n = n+1

Tedious, yes, but necessary and likely to work.
cobaltplusone

Re: Syntax errors in HOC

Post by cobaltplusone »

Thank you for your detailed response. I will try your suggestion of incrementally uncommenting the code - this seems to be the most promising approach, since I inherited this code from a previous graduate student in my lab and do not have access to any version control.
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Syntax errors in HOC

Post by ted »

Ow. The only thing worse than debugging one's own old code is having to debug someone else's. Good luck.
cobaltplusone

Re: Syntax errors in HOC

Post by cobaltplusone »

I figured it out. I had created a string variable called "s" using strdef, and this was causing a conflict when the integrate() procedure tried to assign s=0. I will use this technique of uncommenting one line at a time in future.

Thanks!
Post Reply