Page 1 of 1

Can I force an assigned variable to be an integer in NMODL

Posted: Thu Sep 15, 2011 10:11 am
by Raj
I wrote the NMODL file below, which defines an artificial cell which counts spikes/events of all the NetCons connected to it and fires when it reaches a predefined value. The firing of this cell is used to halt the simulation and subsequently save the results to file.
It would be neat if the assigned variables `count' and the parameter `stopcount' were unsigned integers. Is there a way to achieve that?

Code: Select all

: networkcounter.mod
NEURON {
        ARTIFICIAL_CELL NetCounter
        RANGE count, stopcount
}

PARAMETER {
	stopcount=1e9 (1) <0,1e9>
}

ASSIGNED {
	count (1)
}

INITIAL {
	count=0
}

NET_RECEIVE(w) {   
    count=count+1
    if(count >= stopcount){
        net_event(t)    
    }	
}

Re: Can I force an assigned variable to be an integer in NMO

Posted: Fri Sep 16, 2011 6:58 am
by hines
The only way to declare non-double variables is within a VERBATIM block.
The most general idiom (works on both 32 and 64 bit machines)
for getting your own c structures matched up with the mechanism
instances to use :

NEURON { POINTER ptr }

VERBATIM
typedef stuct {
...
} MyStruct;
#define MYCAST MyStruct** ms = (MyStruct**)(&(_p_ptr))
ENDVERBATIM

See nrn/src/nrnoc/pattern.mod for an elaborated example of this idiom and how to use it.
Of course the 'ptr' variable above is useless as a direct variable in hoc and the only access
should be through function calls to set and get fields of a MyStruct instance.