General custom vector method

Download the zip file or view the two code files below:



myMethod NMODL code for defining and
installing a custom vector method (for
use with vecmethodsample.hoc), based
on Bill Lytton's technique
Written by Marianne Bezaire (marianne dot bezaire at gmail dot com)
in April 2011 and March 2014


# include <stdlib.h>
# include <stdio.h>
# include <math.h>

	SUFFIX nothing

extern double* vector_vec();
extern int vector_capacity();
extern void* vector_arg();

// define the custom vector method
// hocParamVec argument is the vector myParams in hoc
static double customMethod(void* hocParamVec) {
	double *outputVec, *inputVec, resultsVecHoc, ny, pTwo, pOne;

    resultsVecHoc = vector_instance_px(hocParamVec, &outputVec);
    ny = vector_arg_px(1, &inputVec); // 1 for first vector passed in
                                      // use 2, 3, etc for additional
                                      // vectors passed to method in hoc

    pOne = inputVec[0];
    pTwo = inputVec[1];

    outputVec[0] = pTwo - pOne; // 7
    outputVec[1] = pTwo*pOne; // 60
    outputVec[2] = pOne -  pTwo; // -7

    return resultsVecHoc; // resultsVecHoc becomes
                          // the vector myResults in hoc

PROCEDURE install_customVectorMethod() {
	: This procedure is run from hoc
	: to allow users to call the customMethod
	: as a vector method in hoc
    install_vector_method("customMethodinHoc", customMethod);



// vecmethodsample code for using
// a custom vector method in hoc (for
// use with myMethod.mod), based
// on Bill Lytton's technique
// Written by Marianne Bezaire (marianne dot bezaire at gmail dot com)
// March 2014

{load_file("nrngui.hoc")} // Standard definitions-NEURON library file

{install_customVectorMethod()} // prints 1 if not enclosed with {}

// define input argument vector and output vector
objref myParams, myResults
myParams = new Vector(2) // input argument vector
myResults = new Vector(3) // output vector

// set parameters in vector
paramOne = 5.0
paramTwo = 12.0
myParams.x[0] = paramOne
myParams.x[1] = paramTwo

// use vector method
{myResults.customMethodinHoc(myParams)} // prints myResults length
                                        // if not enclosed with {}

// do things with myResults
print myResults.x[0] // will print 7
print myResults.x[1] // will print 60
print myResults.x[2] // will print -7


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s