Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MOD-C-2-CPP: Compatibility fixed for NEURON 9.0, 8.2 and 8.1 #1

Merged
merged 10 commits into from
May 27, 2022
28 changes: 13 additions & 15 deletions bnet.mod
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ brule* addrule (boonet* pnet, double* psrc, int targid, double weight, double* p
int idx,i;
if(pnet->prules == 0x0) { // take care of memory allocation
pnet->rulebufsz = 16;
pnet->prules = calloc(pnet->rulebufsz, sizeof(brule) );
pnet->prules = (struct BRULE*) calloc(pnet->rulebufsz, sizeof(brule) );
pnet->nrules = 0;
} else if(pnet->nrules >= pnet->rulebufsz) {
pnet->rulebufsz *= 2;
pnet->prules = realloc(pnet->prules, pnet->rulebufsz * sizeof(brule) );
pnet->prules = (struct BRULE*) realloc(pnet->prules, pnet->rulebufsz * sizeof(brule) );
}
idx = pnet->nrules;
pnet->prules[idx].nsrc = nsrc; // set # of sources
pnet->prules[idx].ptarg = &pnet->pnodes[targid]; // set target
pnet->prules[idx].weight = weight; // set weight
// set the sources
pnet->prules[idx].psrc = calloc(nsrc, sizeof(bnode*));
pnet->prules[idx].psrc = (struct BNODE **) calloc(nsrc, sizeof(bnode*));
for(i=0;i<nsrc;i++) pnet->prules[idx].psrc[i] = &pnet->pnodes[(int)psrc[i]];
// set source state for rule to be 'on'
pnet->prules[idx].psrcstate = calloc(nsrc, sizeof(int));
pnet->prules[idx].psrcstate = (int *) calloc(nsrc, sizeof(int));
for(i=0;i<nsrc;i++) pnet->prules[idx].psrcstate[i] = (int) psrcstate[i];
return &pnet->prules[ pnet->nrules++ ]; // return the new rule and inc # rules
}
Expand Down Expand Up @@ -193,7 +193,7 @@ CONSTRUCTOR {
printf("BNET err0: must have a network with positive # of nodes!\n");
hxe();
}
_p_sop = (void*) makeboonet(sz);
_p_sop = (double*) makeboonet(sz);
pnet = BP;
pnet->id = ifarg(2) ? (int) *getarg(2) : 0;
ENDVERBATIM
Expand Down Expand Up @@ -267,7 +267,7 @@ PROCEDURE pr () {
if(prule->psrc[j]->name) {
sprintf(stmp,"%s%s%s ", j>0?"AND ":"", prule->psrcstate[j]?"":"!", prule->psrc[j]->name);
} else {
sprintf(stmp,"%s%s%s ", j>0?"AND ":"", prule->psrcstate[j]?"":"!", prule->psrc[j]->id);
sprintf(stmp,"%s%s%d ", j>0?"AND ":"", prule->psrcstate[j]?"":"!", prule->psrc[j]->id);
}
strcat(srcstr,stmp);
}
Expand All @@ -288,13 +288,12 @@ FUNCTION graphviz () {
int i, j, k, LR, fsz, w, h;
bnode* pnodes = BP->pnodes;
brule* prule;
char *ncolor, *fcolor, *arrowtype, *lstyle, *shape;//node color, font color, arrow type, line style, node shape
char buf[4096], *dotname, *fname, *ext, fontsize[128];
char buf[4096], *dotname, *fname, fontsize[128];
double penw; // penwidth
FILE* fp = 0x0;
dotname = ifarg(1) ? gargstr(1) : 0x0;
fname = ifarg(2) ? gargstr(2) : 0x0;
ext = ifarg(3) ? gargstr(3) : "gif";
const char* ext = ifarg(3) ? gargstr(3) : "gif";
LR = ifarg(4) ? (int) *getarg(4) : 1;
w = ifarg(5) ? (int) *getarg(5) : -1;
h = ifarg(6) ? (int) *getarg(6) : -1;
Expand All @@ -308,9 +307,9 @@ FUNCTION graphviz () {
if(LR){sprintf(buf, "%s", "\trankdir=LR;\n"); if(fp) fprintf(fp,"%s",buf); else fprintf(stdout,"%s",buf); }
if(w>0 && h>0) {sprintf(buf, "size=\"%d,%d\"\n",w,h); if(fp) fprintf(fp,"%s",buf); else fprintf(stdout,"%s",buf);}
for(i=0;i<BP->numnodes;i++) {
ncolor = BP->pnodes[i].knockout ? "white" : BP->pnodes[i].state > 0 ? "black" : "gray";
fcolor = BP->pnodes[i].knockout ? "black" : "white";
shape = pnodes[i].sthresh > 0 ? "invtriangle" : "doublecircle";
const char* ncolor = BP->pnodes[i].knockout ? "white" : BP->pnodes[i].state > 0 ? "black" : "gray";
const char* fcolor = BP->pnodes[i].knockout ? "black" : "white";
const char* shape = pnodes[i].sthresh > 0 ? "invtriangle" : "doublecircle";
if(BP->pnodes[i].name) {
sprintf(buf,"\t%s [fontcolor=%s,%sstyle=filled,shape=%s,fillcolor=%s,color=%s]\n",
BP->pnodes[i].name,fcolor,fontsize,shape,ncolor,ncolor);
Expand All @@ -324,8 +323,8 @@ FUNCTION graphviz () {
prule = &BP->prules[i];
for(j=0;j<prule->nsrc;j++) {
penw = prule->psrcstate[j] == prule->psrc[j]->state ? 6.0 : 1.0;
arrowtype = prule->weight < 0 ? "tee" : "open";
lstyle = prule->psrcstate[j] == 0 ? ",style=dashed" : " ";
const char* arrowtype = prule->weight < 0 ? "tee" : "open";
const char* lstyle = prule->psrcstate[j] == 0 ? ",style=dashed" : " ";
if(prule->psrc[j]->name) {
if(prule->ptarg->name) {
sprintf(buf,"\t%s -> %s [arrowhead=%s,penwidth=%g,color=%s%s]\n",
Expand Down Expand Up @@ -613,7 +612,6 @@ FUNCTION setnname () {
FUNCTION getnname () {
VERBATIM
int i, id, sz; char **pname, string[BUFSIZ];
char** hoc_pgargstr();
id = (int) *getarg(1);
if(id < 0 || id >= BP->numnodes) {
printf("BNET.getnname ERR0: invalid node index %d\n",id);
Expand Down
39 changes: 18 additions & 21 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <math.h>
#include <limits.h> /* contains LONG_MAX */
#include <time.h>
#include <sys/time.h>
#include <sys/time.h>
#include <float.h>
#include <pthread.h>

Expand Down Expand Up @@ -54,15 +54,15 @@ typedef unsigned char ui1; /* one byte unsigned integer */
typedef char si1; /* one byte signed integer */
typedef unsigned short ui2; /* two byte unsigned integer */
typedef short si2; /* two byte signed integer */
typedef unsigned int ui4; /* four byte unsigned integer */
typedef int si4; /* four byte signed integer */
typedef float sf4; /* four byte signed floating point number */
typedef double sf8; /* eight byte signed floating point number */
typedef unsigned int ui4; /* four byte unsigned integer */
typedef int si4; /* four byte signed integer */
typedef float sf4; /* four byte signed floating point number */
typedef double sf8; /* eight byte signed floating point number */

extern double ERR,GET,SET,OK,NOP,ALL,NEG,POS,CHK,NOZ,GTH,GTE,LTH,LTE,EQU;
extern double EQV,EQW,EQX,NEQ,SEQ,RXP,IBE,EBI,IBI,EBE;

extern double *vector_newsize();
extern double *vector_newsize(void* v, int n);
extern unsigned int dcrsz;
extern double *dcr;
extern double *dcrset(int);
Expand All @@ -73,50 +73,52 @@ extern unsigned int iscrsz;
extern int *iscr;
extern int *iscrset(int);
extern double BVBASE;
#ifndef NRN_VERSION_GTEQ_8_2_0
extern double* hoc_pgetarg();
extern void hoc_notify_iv();
extern double hoc_call_func(Symbol*, int narg);
extern FILE* hoc_obj_file_arg(int narg);
extern Object** hoc_objgetarg();
char *gargstr();
char** hoc_pgargstr();
extern void vector_resize();
extern int vector_instance_px();
extern void* vector_arg();
extern double* vector_vec();
extern int vector_buffer_size(void*);
extern double hoc_epsilon;
extern int stoprun;
extern void set_seed();
extern void dshuffle(double* x,int nx);
extern void mcell_ran4_init(u_int32_t);
extern double mcell_ran4(u_int32_t *idx1, double *x, unsigned int n, double range);
extern int nrn_mlh_gsort();
extern int ivoc_list_count(Object*);
extern Object* ivoc_list_item(Object*, int);
extern int list_vector_px2();
extern int hoc_is_double_arg(int narg);
extern int hoc_is_str_arg(int narg);
extern int hoc_is_object_arg(int narg);
extern int hoc_is_pdouble_arg(int narg);
extern int hoc_is_tempobj_arg(int narg);
extern Symbol *hoc_get_symbol(char *);
extern Symbol *hoc_lookup(const char*);
extern Point_process* ob2pntproc(Object*);

extern char* hoc_object_name(Object*);
extern int cmpdfn();
#endif
extern void dshuffle(double* x,int nx);
int uniq2(int, double*, double*, double*);
extern int cmpdfn(double, double);
extern int openvec(int, double **);
int list_vector_px();
double *list_vector_resize();
int list_vector_px(Object*, int, double**);
int list_vector_px2(Object *, int, double**, IvocVect**);
int list_vector_px3(Object*, int, double**, IvocVect**);
int list_vector_px4(Object *ob, int i, double** px, unsigned int n);
double *list_vector_resize(Object *ob, int i, int sz);
static void hxe() { hoc_execerror("",0); }
extern void FreeListVec(ListVec** pp);
extern ListVec* AllocListVec(Object* p);
extern ListVec* AllocILV(Object*, int, double *);
void FillListVec(ListVec* p,double dval);
void ListVecResize(ListVec* p,int newsz);
extern short *nrn_artcell_qindex_;
extern double nrn_event_queue_stats(double*);
extern void clear_event_queue();
int IsList(Object*);

static double sc[6];
static FILE* testout;
Expand All @@ -132,8 +134,3 @@ extern double ismono1 (double *x, int n, int flag);
double kcorfast(double* input1, double* input2, double* i1d , double* i2d,int n,double* ps);
double Rktau (double* x, double* y, int n); // R version
double kcorfast (double* input1, double* input2, double* i1d , double* i2d,int n,double* ps);





11 changes: 5 additions & 6 deletions misc.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ NEURON {
}

VERBATIM
#include "misc.h"

#include <unistd.h> /* F_OK */
#include <errno.h> /* errno */
#include <signal.h>
#include <sys/types.h> /* MUST REMEMBER THIS */
#include <time.h>
#include <stdio.h>
#include <limits.h>
extern int hoc_is_tempobj(int narg);
ENDVERBATIM

:* FUNCTION file_exist()
Expand All @@ -58,7 +59,7 @@ VERBATIM
errno else will get a nrnoc error. Seems to be a problem even
if I don't include <errno.h> */

char *gargstr(), *filename;
char *filename;

filename = gargstr(1);

Expand All @@ -85,7 +86,6 @@ FUNCTION sassign() {
VERBATIM
FILE *pipein;
char string[BUFSIZ], **strname, *syscall;
char** hoc_pgargstr();

strname = hoc_pgargstr(1);
syscall = gargstr(2);
Expand Down Expand Up @@ -197,7 +197,7 @@ VERBATIM
size_t x,y;
x=(size_t)_lsz;
pmlc=(char *)malloc(x);
printf("Did %ld: %x\n",x,pmlc);
printf("Did %ld: %p\n",x,pmlc);
y=(unsigned int)_lsz-1;
pmlc[y]=(char)97;
printf("WRITE/READ 'a': ");
Expand All @@ -217,8 +217,7 @@ ENDVERBATIM
FUNCTION hocgetc() {
VERBATIM
{
FILE* f, *hoc_obj_file_arg();
f = hoc_obj_file_arg(1);
FILE* f = hoc_obj_file_arg(1);
_lhocgetc = (double)getc(f);
}
ENDVERBATIM
Expand Down
5 changes: 5 additions & 0 deletions readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
For questions/comments email: samuel dot neymotin at yale dot edu or
samn at neurosim dot downstate dot edu

<b>Changelog:</b>

20160920 This updated version from the Lytton lab allows this model to
run on the mac.
20220523 Updated MOD files to contain valid C++ and be compatible with
the upcoming versions 8.2 and 9.0 of NEURON. Updated to use post ~2011
signature of mcell_ran4_init function.
</pre></html>
Loading