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

NEURON 8.2+ compatibility. #1

Merged
merged 7 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions misc.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// $Id: misc.h,v 1.33 2010/06/05 15:32:28 billl Exp $

#include <stdint.h> /* uint32_t */
#include <stdlib.h>
#include <math.h>
#include <limits.h> /* contains LONG_MAX */
#include <time.h>
#include <sys/time.h>
#ifdef __APPLE__&__MACH__
#include <sys/time.h>
#if defined(__APPLE__) && defined(__MACH__)
#include <float.h>
#else
#include <values.h>
Expand Down Expand Up @@ -57,15 +57,14 @@ 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 unsigned int dcrsz;
extern double *dcr;
extern double *dcrset(int);
Expand All @@ -76,6 +75,7 @@ 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);
Expand All @@ -91,14 +91,12 @@ 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 unsigned int valseed;
extern void mcell_ran4_init(unsigned int *idum);
extern double mcell_ran4(unsigned int* idum,double* ran_vec,unsigned int n,double range);
extern void mcell_ran4_init(uint32_t);
extern double mcell_ran4(uint32_t* high, 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);
Expand All @@ -108,19 +106,29 @@ extern Symbol *hoc_lookup(const char*);
extern Point_process* ob2pntproc(Object*);

extern char* hoc_object_name(Object*);
extern int cmpdfn();
extern int openvec(int, double **);
int list_vector_px();
double *list_vector_resize();
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();
extern int hoc_is_tempobj(int narg);
extern int hoc_is_tempobj_arg(int narg);
#endif
ListVec* AllocListVec(Object* p);
ListVec* AllocILV(Object*, int, double *);
int cmpdfn(double a, double b);
void dshuffle(double* x, int nx);
void FreeListVec(ListVec** pp);
static void hxe() { hoc_execerror("",0); }
int IsList(Object* p);
int list_vector_px(Object *ob, int i, double** px);
int list_vector_px2(Object *ob, int i, double** px, void** vv);
int list_vector_px3(Object *ob, int i, double** px, void** vv);
int list_vector_px4(Object *ob, int i, double** px, unsigned int n);
double* list_vector_resize(Object *ob, int i, int sz);
int openvec(int, double **);
int uniq2(int n, double *x, double *y, double *z);
double *vector_newsize(void* vv, int n);

static double sc[6];
static FILE* testout;
Expand Down
25 changes: 12 additions & 13 deletions misc.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ VERBATIM
#include <time.h>
#include <stdio.h>
#include <limits.h>
extern int hoc_is_tempobj(int narg);
#include "misc.h"
ENDVERBATIM

:* FUNCTION file_exist()
Expand All @@ -59,10 +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;

filename = gargstr(1);

char* filename = gargstr(1);
if (*filename && !access(filename, F_OK)) {
_lfile_exist = 1;

Expand All @@ -86,19 +83,19 @@ PROCEDURE sassign() {
VERBATIM
FILE *pipein;
char string[BUFSIZ], **strname, *syscall;
char** hoc_pgargstr();

strname = hoc_pgargstr(1);
syscall = gargstr(2);

if( !(pipein = popen(syscall, "r"))) {
fprintf(stderr,"System call failed\n");
return;
return 0;
}

if (fgets(string,BUFSIZ,pipein) == NULL) {
fprintf(stderr,"System call did not return a string\n");
pclose(pipein); return;
pclose(pipein);
return 0;
}

/* assign_hoc_str(strname, string, 0); */
Expand All @@ -121,17 +118,20 @@ VERBATIM

if ( !(outfile = fopen("dassign","w"))) {
fprintf(stderr,"Can't open output file dassign\n");
return;
return 0;
}

if( !(pipein = popen(syscall, "r"))) {
fprintf(stderr,"System call failed\n");
fclose(outfile); return;
fclose(outfile);
return 0;
}

if (fscanf(pipein,"%lf",&num) != 1) {
fprintf(stderr,"System call did not return a number\n");
fclose(outfile); pclose(pipein); return;
fclose(outfile);
pclose(pipein);
return 0;
}

fprintf(outfile,"%s=%g\n",strname,num);
Expand Down Expand Up @@ -215,8 +215,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.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ For questions/comments contact Sam Neymotin:
or
samn at neurosim dot downstate dot edu

Changelog
---------
2022-05: 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.
45 changes: 20 additions & 25 deletions stats.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ASSIGNED { seed }

VERBATIM
#include "misc.h"
#include <stdint.h> /* uint32_t, uintptr_t */
#define MIN_MERGESORT_LIST_SIZE 32

union dblint {
Expand All @@ -50,7 +51,7 @@ union dblint {

unsigned int valseed;
static double *x1x, *y1y, *z1z;
static void vprpr();
static void vprpr(double x, int base);

static int compare_ul(const void* l1, const void* l2) {
int retval;
Expand Down Expand Up @@ -381,7 +382,7 @@ FUNCTION rpval () {
// the way to be robust. The scheme used in spearmanr is probably better.
TINY = 1.0e-20;
ts = r*sqrt(df/((1.0-r+TINY)*(1.0+r+TINY)));
mpval = betai(0.5*df,0.5,df/(df+ts*ts));
mpval = betai(_threadargscomma_ 0.5*df,0.5,df/(df+ts*ts));
return mpval;
ENDVERBATIM
}
Expand Down Expand Up @@ -424,11 +425,9 @@ static double* getrank (int n, double mdata[])
* a memory allocation error, it returns NULL.
*/
{ int i;
double* rank;
int* index;
rank = malloc(n*sizeof(double));
double* rank = (double*)malloc(n*sizeof(double));
if (!rank) return NULL;
index = malloc(n*sizeof(int));
int* index = (int*)malloc(n*sizeof(int));
if (!index)
{ free(rank);
return NULL;
Expand Down Expand Up @@ -468,11 +467,9 @@ static double spearman(int n, double* data1, double* data2)
double denom1 = 0.;
double denom2 = 0.;
double avgrank;
double* tdata1;
double* tdata2;
tdata1 = malloc(n*sizeof(double));
double* tdata1 = (double*)malloc(n*sizeof(double));
if(!tdata1) return 0.0; /* Memory allocation error */
tdata2 = malloc(n*sizeof(double));
double* tdata2 = (double*)malloc(n*sizeof(double));
if(!tdata2) /* Memory allocation error */
{ free(tdata1);
return 0.0;
Expand Down Expand Up @@ -643,7 +640,7 @@ int qsort2 (double *p1in, double* p2in, int n,double* p1out,double* p2out) {
int i;
scr=scrset(n);
for (i=0;i<n;i++) scr[i]=i;
nrn_mlh_gsort(p1in, scr, n, cmpdfn);
nrn_mlh_gsort(p1in, (int*)scr, n, cmpdfn);
for (i=0;i<n;i++) {
p1out[i]=p1in[scr[i]];
p2out[i]=p2in[scr[i]];
Expand Down Expand Up @@ -861,8 +858,8 @@ static double hash (void* vv) {
} else { xx.d=vvo[j][i]; }
if (xx.i[0]==0) { xx.i[0]=xx.i[1]; xx.i[0]<<=4; } // high order bits may be 0
if (xx.i[1]==0) { xx.i[1]=xx.i[0]; xx.i[1]<<=4; } // low order bits unlikely 0
mcell_ran4_init(&xx.i[1]);
mcell_ran4(&xx.i[0], &y, 1, big); // generate a pseudorand number based on these
mcell_ran4_init(xx.i[1]);
mcell_ran4((uint32_t*)&xx.i[0], &y, 1, big); // generate a pseudorand number based on these
prod*=y; // keep multiplying these out
}
if (! vfl) x[i]=prod; else return prod; // just return the 1 value
Expand Down Expand Up @@ -1043,7 +1040,7 @@ static double setrnd (void* vv) {
scrset(nex);
x1x = (double *)realloc(x1x,sizeof(double)*nx*4);
for (i=0;i<nex;i++) scr[i]=i;
nrn_mlh_gsort(ex, scr, nex, cmpdfn);
nrn_mlh_gsort(ex, (int*)scr, nex, cmpdfn);
for (i=0;i<nex;i++) x1x[i]=ex[scr[i]];
for (i=0;i<nex;i++) ex[i]=x1x[i];
}
Expand Down Expand Up @@ -1446,7 +1443,7 @@ static double rantran (void* vv) {
int i,j,ix,ixe,ixvn,nvn,rvn,na,xj;
double *ixv, *nv, *x, y[1], ixn,step,indx;
rvn=vector_instance_px(vv, &x);
for (na=1;ifarg(na);na++); na--; // count args
for (na=1;ifarg(na);na++) {} na--; // count args
for (i=1;i<na;i+=2) {
if (hoc_is_object_arg(i)) {
step=-1;
Expand Down Expand Up @@ -1664,6 +1661,7 @@ static double vpr2 (void* vv) {
}
printf("\n");
}
return 0.0;
}

static void vprpr (double x, int base) {
Expand Down Expand Up @@ -2025,8 +2023,8 @@ unsigned int hashseed2 (int na, double* x) {
if (xx.i[0]==0) { xx.i[0]=xx.i[1]; xx.i[0]<<=4; } // high order bits may be 0
if (xx.i[1]==0) { xx.i[1]=xx.i[0]; xx.i[1]<<=4; } // low order bits unlikely 0
xx.i[0]+=(i+1); xx.i[1]+=(i+1); // so different for different order args
mcell_ran4_init(&xx.i[1]);
mcell_ran4(&xx.i[0], &y, 1, big); // generate a pseudorand number based on these
mcell_ran4_init(xx.i[1]);
mcell_ran4((uint32_t*)&xx.i[0], &y, 1, big); // generate a pseudorand number based on these
while (y>UINT_MAX) y/=1e9; // UINT_MAX is 4.294967e+09
valseed*=(unsigned int)y; // keep multiplying these out
}
Expand Down Expand Up @@ -2091,7 +2089,7 @@ FUNCTION mc4seed () {
for (i=2;ifarg(i);i++) {
valseed*=(unsigned int)(*getarg(i));
}
mcell_ran4_init(&valseed); // do initialization
mcell_ran4_init(valseed); // do initialization
return valseed;
ENDVERBATIM
}
Expand Down Expand Up @@ -2119,16 +2117,14 @@ FUNCTION gammln (xx) {
FUNCTION betai(a,b,x) {
VERBATIM {
double bt;
double gammln(),betacf();

if (_lx < 0.0 || _lx > 1.0) {printf("Bad x in routine BETAI\n"); hxe();}
if (_lx == 0.0 || _lx == 1.0) bt=0.0;
else
bt=exp(gammln(_la+_lb)-gammln(_la)-gammln(_lb)+_la*log(_lx)+_lb*log(1.0-_lx));
bt=exp(gammln(_threadargscomma_ _la+_lb)-gammln(_threadargscomma_ _la)-gammln(_threadargscomma_ _lb)+_la*log(_lx)+_lb*log(1.0-_lx));
if (_lx < (_la+1.0)/(_la+_lb+2.0))
return bt*betacf(_la,_lb,_lx)/_la;
return bt*betacf(_threadargscomma_ _la,_lb,_lx)/_la;
else
return 1.0-bt*betacf(_lb,_la,1.0-_lx)/_lb;
return 1.0-bt*betacf(_threadargscomma_ _lb,_la,1.0-_lx)/_lb;
}
ENDVERBATIM
}
Expand Down Expand Up @@ -2193,10 +2189,9 @@ FUNCTION tstat() {

FUNCTION tdistrib() {
VERBATIM
double gammln();
double x = *getarg(1);
double dof = *getarg(2);
double res = (gammln( (dof+1.0) / 2.0 ) / gammln( dof / 2.0 ) );
double res = (gammln(_threadargscomma_ (dof+1.0) / 2.0 ) / gammln(_threadargscomma_ dof / 2.0 ) );
double pi = 3.14159265358979323846;
res *= (1.0 / sqrt( dof * pi ) );
res *= pow((1 + x*x/dof),-1.0*((dof+1.0)/2.0));
Expand Down
Loading