WATCHing arrays

NMODL and the Channel Builder.
Post Reply
sec6
Posts: 39
Joined: Sat Mar 15, 2008 10:32 am

WATCHing arrays

Post by sec6 »

The following seems to be illegal:

Code: Select all

NET_RECEIVE (weight) {
	...
	FROM i = 0 TO N - 1 {
		WATCH (myArray[i] < 0) 1
	}
	...
}
It fails with the following error message:
  • In function '_watch3_cond':
    error: '_li' undeclared (first use in this function)
Here is the C sourcecode which NMODL generated for _watch3_cond:

Code: Select all

static double _watch3_cond(_pnt) Point_process* _pnt; {
	_p = _pnt->_prop->param; _ppvar = _pnt->_prop->dparam; v = NODEV(_pnt->node);
	return  -( ( myArray [ _li ] ) - ( 0.0 ) ) ;
}
Variable i is an ASSIGNED, but I get the same result if I declare it local to the NET_RECEIVE block.

Is there a correct way to this?
hines
Site Admin
Posts: 1600
Joined: Wed May 18, 2005 3:32 pm

Post by hines »

You will have to avoid arrays. The implementation can only work when a WATCH
variable is a scalar.
sec6
Posts: 39
Joined: Sat Mar 15, 2008 10:32 am

Post by sec6 »

hines wrote:You will have to avoid arrays. The implementation can only work when a WATCH
variable is a scalar.
OK.

For the benefit of anyone else who runs into this, my workaround was as follows:

Code: Select all

...
INITIAL {
	...
	net_send(0,99)
	...
}
...
BREAKPOINT {
	...
	myArrayMin = 0
	FROM i = 0 TO N-1 {
		if (myArray[i] < myArrayMin) {
			myArrayMin = myArray[i]
		}
	}
	...
}
...
NET_RECEIVE (weight) {
	IF (flag == 99) {
		WATCH (myArrayMin < 0) 1
	}
	...
	IF (flag == 1) {
		printf("One or more elements of myArray were less than zero.\n")
		FROM i = 0 to N-1 {
			printf("\tmyArray[%g] = %g\n",i,myArray[i])
		}
	}
	...
}
Post Reply