Exemplo n.º 1
0
static double abstol(void* v) {
	NetCvode* d = (NetCvode*)v;
	Symbol* sym;
	if (hoc_is_str_arg(1)) {
		sym = d->name2sym(gargstr(1));
	}else{
		hoc_pgetarg(1);
		sym = hoc_get_last_pointer_symbol();
		if (!sym) {
hoc_execerror("Cannot find the symbol associated with the pointer when called from Python", "Use a string instead of pointer argument");
		}
		if (nrn_vartype(sym) != STATE && sym->u.rng.type != VINDEX) {
			hoc_execerror(sym->name, "is not a STATE");
		}
	}
	if (ifarg(2)) {
		hoc_symbol_tolerance(sym, chkarg(2, 1e-30, 1e30));
		d->structure_change();
	}
	if (sym->extra && sym->extra->tolerance > 0.) {
		return sym->extra->tolerance;
	}else{
		return 1.;
	}
}
Exemplo n.º 2
0
static char* key_help() {
	static char key[50];
	if (hoc_is_str_arg(1)) {
		return gargstr(1);
	}else{
		sprintf(key, "%g", *getarg(1));
		return key;
	}
}
Exemplo n.º 3
0
static double post(void* v) {
	OcBBS* bbs = (OcBBS*)v;
	pack_help(2, bbs);
	posting_ = false;
	if (hoc_is_str_arg(1)) {
		bbs->post(gargstr(1));
	}else{
		char key[50];
		sprintf(key, "%g", *getarg(1));
		bbs->post(key);
	}
	return 1.;
}
Exemplo n.º 4
0
JNIEXPORT jstring JNICALL Java_neuron_Neuron_getHocStringArg(
    JNIEnv *env, jclass cls, jint idx) {    
	char *str="";
	if (!ifarg(idx)) {
		printf("error - missing string as arg %d\n", idx);
		illegalArg(env, "missing string");
		return nil;
	}
	if (hoc_is_str_arg( idx )) {
		str =  gargstr( idx );
	} else {
		printf("error - expecting string as arg %d\n", idx);
		illegalArg(env, "expecting string");
		return nil;
	}
	jstring ret = env->NewStringUTF( str );
	return ret;
}
Exemplo n.º 5
0
static void unpack_help(int i, OcBBS* bbs) {
	for (; ifarg(i); ++i) {
		if (hoc_is_pdouble_arg(i)) {
			*hoc_pgetarg(i) = bbs->upkdouble();
		}else if (hoc_is_str_arg(i)) {
			char* s = bbs->upkstr();
			char** ps = hoc_pgargstr(i);
			hoc_assign_str(ps, s);
			delete [] s;
		}else if (is_vector_arg(i)){
			Vect* vec = vector_arg(i);
			int n = bbs->upkint();
			vec->resize(n);
			bbs->upkvec(n, vec->vec());
		}else{
hoc_execerror("pc.unpack can only unpack str, scalar, or Vector.",
"use pc.upkpyobj to unpack a Python Object");
		}
	}
}
Exemplo n.º 6
0
JNIEXPORT jobject JNICALL Java_neuron_Neuron_getHocObjectArg
  (JNIEnv *env, jclass cl, jint i, jthrowable e) {
	jobject ret;
//printf("getHocObjArg %s  %ld\n", hoc_object_name(o), (long)o);
	if (!ifarg(i)) {
		printf("error - missing Object as arg %d\n", i);
		illegalArg(env, "missing Object");
		return e;
	}
	if (hoc_is_object_arg(i)) {
		Object* o = *hoc_objgetarg(i);
		ret = h2jObject(o);
	}else if (hoc_is_str_arg(i)) { //encapsulate in String
		char* s = gargstr(i);
		ret = Java_neuron_Neuron_getHocStringArg(env, cl, i);
	}else{
		printf("error - expecting Object or strdef as arg %d\n", i);
		illegalArg(env, "expecting Object or strdef");
		ret = e;
	}
	return ret;
}
Exemplo n.º 7
0
static void pack_help(int i, OcBBS* bbs) {
	if (!posting_) {
		bbs->pkbegin();
		posting_ = true;
	}
	for (; ifarg(i); ++i) {
		if (hoc_is_double_arg(i)) {
			bbs->pkdouble(*getarg(i));
		}else if (hoc_is_str_arg(i)) {
			bbs->pkstr(gargstr(i));
		}else if (is_vector_arg(i)){
			int n; double* px;
			n = vector_arg_px(i, &px);
			bbs->pkint(n);
			bbs->pkvec(n, px);
		}else{ // must be a PythonObject
			size_t size;
			char* s = nrnpy_po2pickle(*hoc_objgetarg(i), &size);
			bbs->pkpickle(s, size);
			delete [] s;
		}
	}
}
Exemplo n.º 8
0
static double ste_transition(void* v) {
	StateTransitionEvent* ste = (StateTransitionEvent*)v;
	int src = (int)chkarg(1, 0, ste->nstate()-1);
	int dest = (int)chkarg(2, 0, ste->nstate()-1);
	double* var1 = hoc_pgetarg(3);
	double* var2 = hoc_pgetarg(4);
	HocCommand* hc = NULL;
	if (ifarg(5)) {
		Object* obj = NULL;
		if (hoc_is_str_arg(5)) {
			char* stmt = NULL;
			stmt = gargstr(5);
			if (ifarg(6)) {
				obj = *hoc_objgetarg(6);
			}
			hc = new HocCommand(stmt, obj);
		}else{
			obj = *hoc_objgetarg(5);
			hc = new HocCommand(obj);
		}
	}
	ste->transition(src, dest, var1, var2, hc);
	return 1.;
}
Exemplo n.º 9
0
void nrn_vecsim_add(void* v, boolean record) {
	IvocVect* yvec, *tvec, *dvec;
	extern short* nrn_is_artificial_;
	double* pvar = nil;
	char* s = nil;
	double ddt;
	Object* ppobj = nil;
	int iarg = 0;

	yvec = (IvocVect*)v;
	
	if (hoc_is_object_arg(1)) {
		iarg = 1;
		ppobj = *hoc_objgetarg(1);
		if (!ppobj || ppobj->ctemplate->is_point_ <= 0
		    || nrn_is_artificial_[ob2pntproc(ppobj)->prop->type]
		    ) {
			hoc_execerror("Optional first arg is not a POINT_PROCESS", 0);
		}
	}
	if (record == false && hoc_is_str_arg(iarg+1)) {//statement involving $1
		// Vector.play("proced($1)", ...)
		s = gargstr(iarg+1);
	}else if (record == false && hoc_is_double_arg(iarg+1)) {// play that element
		// Vector.play(index)
		// must be a VecPlayStep and nothing else
			VecPlayStep* vps = (VecPlayStep*)net_cvode_instance->playrec_uses(v);
		if (vps) {
			int j = (int)chkarg(iarg+1, 0., yvec->capacity()-1);
			if (vps->si_) {
				vps->si_->play_one(yvec->elem(j));
			}
		}
		return;
	}else{
		// Vector.play(&SEClamp[0].amp1, ...)
		// Vector.record(&SEClamp[0].i, ...)
		pvar = hoc_pgetarg(iarg+1);
	}
	tvec = nil;
	dvec = nil;
	ddt = -1.;
	int con = 0;
	if (ifarg(iarg+2)) {
		if (hoc_is_object_arg(iarg+2)) {
			// Vector...(..., tvec)
			tvec = vector_arg(iarg+2);
		}else{
			// Vector...(..., Dt)
			ddt = chkarg(iarg+2, 1e-9, 1e10);
		}
		if (ifarg(iarg+3)) {
			if (hoc_is_double_arg(iarg+3)) {
				con = (int)chkarg(iarg+3, 0., 1.);
			}else{
				dvec = vector_arg(iarg+3);
				con = 1;
			}
		}
	}	
	
// tvec can be used for many record/play items
//	if (tvec) { nrn_vecsim_remove(tvec); }
	if (record) {
		// yvec can be used only for one record (but many play)
		if (yvec) { nrn_vecsim_remove(yvec); }
		if (tvec) {
			new VecRecordDiscrete(pvar, yvec, tvec, ppobj);
		} else if (ddt > 0.) {
			new VecRecordDt(pvar, yvec, ddt, ppobj);
		} else if (pvar == &t) {
			new TvecRecord(chk_access(), yvec, ppobj);
		} else {
			new YvecRecord(pvar, yvec, ppobj);
		}
	}else{
		if (con) {
			if (s) {
				new VecPlayContinuous(s, yvec, tvec, dvec, ppobj);
			}else{
				new VecPlayContinuous(pvar, yvec, tvec, dvec, ppobj);
			}
		}else{
			if (!tvec && ddt == -1.) {
				chkarg(iarg+2, 1e-9, 1e10);
			}
			if (s) {
				new VecPlayStep(s, yvec, tvec, ddt, ppobj);
			}else{
				new VecPlayStep(pvar, yvec, tvec, ddt, ppobj);
			}
		}
	}
}
Exemplo n.º 10
0
static int submit_help(OcBBS* bbs) {
	int id, i, firstarg, style;
	char* pname = 0; // if using Python callable
	posting_ = true;
	bbs->pkbegin();
	i = 1;
	if (hoc_is_double_arg(i)) {
		bbs->pkint((id = (int)chkarg(i++, 0, 1e7)));
	}else{
		bbs->pkint((id = --bbs->next_local_));
	}
	if (ifarg(i+1)) {
#if 1
		int argtypes = 0;
		int ii = 1;
		if (hoc_is_str_arg(i)) {
			style = 1;
			bbs->pkint(style); // "fname", arg1, ... style
			bbs->pkstr(gargstr(i++));
		}else{
			Object* ob = *hoc_objgetarg(i++);
			size_t size;
			if (nrnpy_po2pickle) {
				pname = (*nrnpy_po2pickle)(ob, &size);
			}
			if (pname) {
				style = 3;
				bbs->pkint(style); // pyfun, arg1, ... style
				bbs->pkpickle(pname, size);
				delete [] pname;
			}else{
				style = 2;
				bbs->pkint(style); // [object],"fname", arg1, ... style
				bbs->pkstr(ob->ctemplate->sym->name);
				bbs->pkint(ob->index);
//printf("ob=%s\n", hoc_object_name(ob));
				bbs->pkstr(gargstr(i++));

			}
		}
		firstarg = i;
		for (; ifarg(i); ++i) { // first is least significant
			if (hoc_is_double_arg(i)) {
				argtypes += 1*ii;
			}else if (hoc_is_str_arg(i)) {
				argtypes += 2*ii;
			}else if (is_vector_arg(i)) { //hoc Vector
				argtypes += 3*ii;
			}else{ // must be a PythonObject
				argtypes += 4*ii;
			}
			ii *= 5;
		}
//printf("submit style %d %s argtypes=%o\n", style, gargstr(firstarg-1), argtypes);
		bbs->pkint(argtypes);
		pack_help(firstarg, bbs);
#endif
	}else{
		if (hoc_is_str_arg(i)) {
			bbs->pkint(0); // hoc statement style
			bbs->pkstr(gargstr(i));
		}else if (nrnpy_po2pickle) {
			size_t size;
			pname = (*nrnpy_po2pickle)(*hoc_objgetarg(i), &size);
			bbs->pkint(3); // pyfun with no arg style
			bbs->pkpickle(pname, size);
			bbs->pkint(0); // argtypes
			delete [] pname;
		}
	}
	posting_ = false;
	return id;
}