flag=0 proc err () { xpanel("**** ERROR ****") xlabel($s1) xpanel() } strdef tstr if (unix_mac_pc() == 3) { chdir(neuronhome()) if (chdir("fctb")==0) flag=1 if (chdir("..\fctb")==0) flag=1 if (flag==0) { sprint(tstr,"ERROR: FCTB directory not found; should be in %s or %s/..\n",neuronhome(),neuronhome()) err(tstr) } else if (default_dll_loaded_== 0) { flag = nrn_load_dll("nrnmech.dll") if (flag==1) { default_dll_loaded_ = 1 } else { sprint(tstr,"ERROR loading %s/nrnmech.dll; remake with mknrndll.\n",getcwd()) err(tstr) } } } objref helpbox, helpdeck proc help_list() { helpbox=new HBox(2) helpbox.intercept(1) xpanel("") xbutton("General","helpdeck.flip_to(0)") xbutton("GUI","helpdeck.flip_to(1)") xbutton("Exercises","helpdeck.flip_to(2)") xpanel() helpdeck=new Deck() helpdeck.intercept(1) xpanel("") xlabel("Fig. 8-6 offers 2 alternate parameterizations for an image to be") xlabel("presented to the limulus model. The first, \"Lump,\" function is") xlabel("an exponentiated Gaussian:") xlabel(" f(x) = min+(max-min)*exp(-((x-N/2)/(width/2))^(2*n))") xlabel(" The parameters are min, max, n, width.") xlabel("The second, \"Square,\" function is a") xlabel("square wave: ") xlabel(" f(x): if (x>x0 && x0) { min=0 max=$2-1 } else { min=$o1.size+$2 max=$o1.size-1 } if (numarg()==3) if ($3>-1) { min=$2 max=$3 } else { min=0 max=$o1.size-1 dual=1 } if (numarg()==4) { min=$3 max=$4 dual=1 } if (min<0) min=0 if (max>$o1.size-1) max=$o1.size-1 if (dual) if (max>$o2.size-1) max=$o2.size-1 for i=min,max { if (dual) printf("%g:%g ",$o1.x[i],$o2.x[i]) else printf("%g ",$o1.x[i]) if ((j=j+1)%vlk_width==0 && nl) { print "" } } if (nl) print "" } //** savevec([list,]vec1[,vec2,...]) add vector onto veclist or other list if given as 1st arg objref veclist veclist = new List() proc savevec () { local i,flag,beg if (isobj($o1,"List")) beg=2 else beg=1 for i=beg, numarg() { tmpvec = new Vector($oi.size) tmpvec.copy($oi) if (beg==2) $o1.append(tmpvec) else veclist.append(tmpvec) tmpvec = nil } } //* graphics; symbols and colors {symnum = 7 colnum = 9} objectvar cl[colnum], sym[symnum] for ii=0,colnum-1 cl[ii]=new String() { cl[0].s ="white" cl[1].s ="black" cl[2].s ="red" cl[3].s ="blue" cl[4].s ="green" cl[5].s ="orange" cl[6].s ="brown" cl[7].s ="violet" cl[8].s ="yellow" } for ii=0,symnum-1 sym[ii]=new String() { sym[0].s = "o" sym[1].s = "t" sym[2].s = "s" sym[3].s = "O" sym[4].s = "T" sym[5].s = "S" sym[6].s = "+"} gcl=0 // graph color func color () { gcl = (gcl+1)%colnum if (gcl==0) gcl=1 // throw out white if (numarg()==1) $o1.color(gcl) return gcl } //** qhp() basic buttons proc qhp () { if (numarg()==1) xpanel("CONTROLS",1) xbutton("Quit","quit()") xbutton("Help","help_list()") xbutton("Print panel","pwman_place(50,50)") xbutton("Reset","reset()") if (numarg()==1) xvarlabel(mesg) if (numarg()==1) xpanel(0,0) mesg="" } //** allgraphs() proc remgrs () { local ii for ii=0,3 graphList[ii].remove_all() objref graphItem } proc allgraphs () { for ii=0,3 for ltr(XO,graphList[ii]) XO.exec_menu($s1) } proc vp() { allgraphs("View = plot") } proc allgrop () { for ii=0,3 for ltr(XO,graphList[ii]) { sprint(tstr,"%s.%s",XO,$s1) execute(tstr) } } //** grrtsize() use view=plot and then pad a little proc grrtsize () { local h,w,frac if (numarg()>=1) tmpobj=$o1 else tmpobj=graphItem if (numarg()>=2) frac = $2 else frac=.05 tmpobj.exec_menu("View = plot") tmpobj.size(&x) w=frac*(x[1]-x[0]) h=frac*(x[3]-x[2]) x[0]-=2*w x[1]+=w x[2]-=4*h x[3]+=h // need extra padding on bottom tmpobj.size(x[0],x[1],x[2],x[3]) } //** isobj(o1,s2) checks whether object $o1 is of type $s2 func isobj () { sprint(temp_string_,"%s",$o1) if (sfunc.substr(temp_string_,$s2)==0) { return 1 } else { return 0 } } // cbin(min,max): binary colormap proc cbin () { $o1.colormap(2) $o1.colormap(0, 255, 0, 0) $o1.colormap(1, 255, 255, 0) $o1.scale($2, $3) } // my version of newPlotV() leaves off the label proc newplotv () { newplot() graphItem.addvar("","v(.5)",1,3) } proc redraw0 () { plrdrf=0 } // stub with flag proc plcback () { } // callback objref oxv,oyv // coordinates: 0,1 line start; 2,3 last loc oxv=new Vector(2) oyv=new Vector(2) plrdrf=1 // flag will be unset if using redraw stub plhorz=0 // 1 for horizontal, 2 for verticle lines proc pl () { if ($1==2) { // mouse down -- new line redraw0() // unset plrdrf if redraw0() not overwritten oxv.x[0]=oxv.x[1]=$2 oyv.x[0]=oyv.x[1]=$3 } else { if (plrdrf) graphItem.erase_all oyv.line(graphItem,oxv,0,2) oxv.x[1]=$2 oyv.x[1]=$3 if (plhorz==1) oyv.x[1]=oyv.x[0] if (plhorz==2) oxv.x[1]=oxv.x[0] oyv.line(graphItem,oxv,2,2) redraw0() // will redraw if defined if ($1==3) plcback(oxv,oyv) } } // newplot([width,height,pointer]) OR newplot([pointer]) proc newplot () { local wd,ht graphItem = new Graph(0) if (numarg()==1) $o1=graphItem // make a pointer if (numarg()==3) $o3=graphItem if (numarg()>1) { wd=$1 ht=$2 } else { wd=500 ht=300 } graphItem.save_name("graphList[0].") graphList[0].append(graphItem) graphItem.view(0,-90,tstop,150,600,200,wd,ht) } //* cbw(min,max): b/w binary colormap proc cbw () { $o1.colormap(2) $o1.colormap(0, 0, 0, 0) $o1.colormap(1, 255, 255, 255) $o1.scale($2, $3) } //* I/O //** svrd(0/1,name,file_ext[,fflag]) save-0 and read-1 // eg svrd(1,"Image","img") will look for file.img files to read // fflag -- return filename only -- don't call parser proc svrd () { local ii,num,cnt,fflag rdflag=$1 if (numarg()==4) fflag=$4 else fflag=0 sprint(tstr2,"*.%s",$s3) if (rdflag==0) { // write sprint(tstr,"Write %s",$s2) tmpfile.chooser("w",tstr,tstr2,"WRITE","","") if (tmpfile.chooser()==1) { tmpfile.getname(filename) if (!fflag) parsr(rdflag) } } else if (rdflag==1) { // read sprint(tstr,"Read %s",$s2) tmpfile.chooser("r",tstr,tstr2,"READ","","") if (tmpfile.chooser()==1) { tmpfile.getname(filename) if (!fflag) parsr(rdflag) } } mesg=filename tmpfile.close } //* xgetargs, d2b //** range(val,min,max) -- return val only if in proper range // eg stim.noise=range(stim.noise,0,1) func range () { if ($1<$2) return $2 if ($1>$3) return $3 return $1 } //** err() proc err () { if (numarg()==1) mesg=$s1 print mesg } //** xvarstr(): display a list of strings in an xpanel using xvarlabel proc xvarstr () { local ii,cnt // ivoc_style("*font", "fixed") if (unix_mac_pc() == 1) { ivoc_style("*font", "*helvetica-bold-r-normal*--14*") } xpanel($s1) for ltr(XO,$o2) xvarlabel(XO.s) xpanel() } //** xgetargs(panel_name,command,arg1[,arg2,...],defaults) // xgetargs("Random session","newrand","# of patts","patt size ","overlap ","5,33,7") objref argv argv = new Vector() proc xgetargs () { local i,args args=numarg()-3 i=numarg() argv.resize(0) sprint(temp_string_,"argv.append(%s)",$si) execute(temp_string_) if (argv.size!=args) argv.resize(args) xpanel($s1) mesg=$s1 xvarlabel(mesg) for i=3,numarg()-1 { sprint(temp_string_,"argv.x[%d]",i-3) xvalue($si,temp_string_) } sprint(temp_string_,"xgetexec(\"%s\",%d)",$s2,args) xbutton("Execute",temp_string_) xpanel() } proc xgetexec () { local i,args args = $2 if (argv.size!=args) { mesg="Error-close & relaunch panel" return } sprint(temp_string_,"%s(",$s1) for i=0,args-2 sprint(temp_string_,"%s%g,",temp_string_,argv.x[i]) sprint(temp_string_,"%s%g)",temp_string_,argv.x[i]) print temp_string_ execute(temp_string_) } //** d2b(): decimal to binary, gives a binary appearing number for showing // eg for ii=0,100 printf("%010d\n",d2b(ii)) func d2b () { local num,ii,rem,res num=$1 ii=0 res=0 while (num>0) { rem = int(2*(num/2-int(num/2))) // right digit num=int(num/2) // remove right digit res+=rem*10^ii ii+=1 } return res } //* matrix stuff //** cvec(),rvec() put out col bzw row vecs in latex format proc cvec () { local i printf("\\bpm ") for vtr(&x,$o1) if (i1<$o1.size-1) printf("%g \\\\ ",x) printf("%g \\epm\n",x) } proc rvec () { local i printf("\\bpm ") for vtr(&x,$o1) if (i1<$o1.size-1) printf("%g & ",x) printf("%g \\epm\n",x) } //** matp(mat,rows,cols) prints out matrix in latex format proc matp () { local i,j,rows,cols rows=$2 cols=$3 if ($o1.size!=rows*cols) {print "ERR: matp - mat.size != rows*cols" return} printf("\\bpm\n") for (i=0;irows) for i=rows,cols-1 printf("%70.04g \n",$o2.x[i]) } //** mmlt(mdest,m1,m2,r2) matrix mult between 2 mats // r2==c1 gives shared dimension proc mmlt () { local i,j,r1,c1,r2,c2 c1 = r2 = $4 // shared dimension (cols of 1st/rows of second) r1=$o2.size/c1 c2=$o3.size/r2 printf("%dx%d * %dx%d = %dx%d\n",r1,c1,r2,c2,r1,c2) $o1.resize(r1*c2) vec[0].resize(c1) // length of a row of mat A vec[1].resize(r2) // length of a col of mat B for i=0,r1-1 for j=0,c2-1 { vec[0].mrow($o2,i,c1) vec[1].mcol($o3,j,c2) $o1.x[i*c2+j]=vec[0].dot(vec[1]) } $o1.mprintf(r1,c2) dealloc(a) } //* membrane and pp's //** runbutton running_ = 1 proc runbutton () { if (running_ == 0) { stoprun = 1 return } if (t>0 && tx0 && $1x0 || $1x0 && x