home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
NERVES.ZIP
/
NO87
/
DATAMOD.C
next >
Wrap
C/C++ Source or Header
|
1990-12-27
|
17KB
|
805 lines
#include "defn.h"
#include "nsdata.c"
#include "proto.h"
void datamod(void) /* allows user to modify/add/delete neuron data */
{
enum asc_val asc;
enum ext_val ext;
char str[41];
char *p;
int newneur;
FILE *file;
int i,j,done,line,cc,newcon;
struct neuron *np,tn;
struct con *cp,*tc,*cq,*cs;
struct Iint ti;
double d;
/* modify data */
start:
clrscr();
textattr(BLUE + (LIGHTGRAY<<4));
gotoxy(1,24);
cputs(" ^S-Save file Esc-Main menu ");
textattr(LIGHTGRAY);
getname:
clrline(1);
gotoxy(1,1);
cputs("Neuron name: ");
i = 0;
while (!i)
i = bioskey(1);
asc = i & 0xff;
if (asc == ESC)
{ /* return to main menu without saving */
bioskey(0);
return; /* go to main menu */
}
else
if (asc == CTRLS)
{ /* save file */
bioskey(0);
/* count neurons */
for (i=0, j=0, np=ns; i<nn; i++, np++)
if (np->name[0])
j++;
clrscr();
if (neurfname[0])
{
cprintf("Save to %s? ",neurfname);
i = toupper(bioskey(0) & 0xff);
}
if (!neurfname[0] || i != 'Y')
{
gotoxy(1,1);
cputs("Enter file spec: ");
gotoxy(18,1);
str[0] = 38;
p = cgets(str);
strcpy(neurfname,p);
}
file = fopen(neurfname,"wb");
fwrite(&j,2,1,file);
for (i=0, np=ns; i<nn; i++, np++)
if (np->name[0])
{
fwrite(np,27,1,file);
if (np->Iint)
j = (int)np->Iint - (int)Iinta + 1;
else
j = 0;
fwrite(&j,2,1,file);
fwrite(&(np->Isens),18,1,file);
if (np->con)
j = (int)np->con - (int)cona + 1;
else
j = 0;
fwrite(&j,2,1,file);
}
fwrite(&ni,2,1,file);
for (i=0; i<ni; i++)
fwrite(Iinta+i,19,1,file);
fwrite(&nc,2,1,file);
for (i=0, cp=cona; i<nc; i++, cp++)
{
fwrite(cp,sizeof(struct con)-6,1,file);
if (cp->next)
j = (int)cp->next - (int)cona + 1;
else
j = 0;
fwrite(&j,2,1,file);
}
fclose(file);
return; /* go to main menu */
}
else
{ /* neuron name input */
str[0] = 7;
p = cgets(str);
if ((*p == '?' || *p == '/') && *(p+1) == 0)
{ /* list neuron names */
for (np=ns, i=0, j=0; i<nn && j<10; j++)
for (line=3; line<24 && i<nn; line++, i++, np++)
{
gotoxy(1+j*8,line);
while (!np->name[0] && i<nn)
{
np++;
i++;
}
if (i<nn)
cprintf("%s",np->name);
}
goto getname;
}
else
if (!*p)
goto getname;
else
{
for (np=ns, i=0; i<nn; i++, np++)
if (!strncmp(p,np->name,6))
break;
if (i == nn)
{
gotoxy(1,2);
cputs("Neuron not found; create new neuron? ");
if (toupper(bioskey(0) & 0xff) != 'Y')
goto getname;
newneur = TRUE;
nn++;
}
else
newneur = FALSE;
}
/* save neuron's data in temporary storage */
tn = *np;
if (newneur)
strcpy(tn.name,p);
if (np->Iint)
ti = *(np->Iint);
else
ti = *(Iinta + ni);
for (cp=np->con, tc=cona+nc, cc=0; cp!=NULL; cp=cp->next, cc++, tc++)
*tc = *cp;
tc = cona+nc;
ndisp(tn,ti,3); /* display neuron's parameters */
/* modify parameters */
line = 3;
done = FALSE;
while(!done)
{
i = 0;
while(!i)
i = bioskey(1);
asc = i & 0xff;
if (asc)
{
if (asc < 32)
{
bioskey(0);
switch(asc)
{
case CTRLD: /* delete neuron */
if (!strcmp(tn.name,np->name)) /* if existing neuron, delete */
np->name[0] = 0;
if (newneur)
nn--;
goto start;
case CTRLS: /* save neuron */
/* convert to integer values */
tn.iGmem = tn.Gmem * 1e8 + .5;
tn.iCmem = tn.Cmem * 1e11 + .5;
tn.iVt = tn.Vt * 1e6 + fsgn(tn.Vt)*.5;
tn.iFmin = tn.Fmin * 10000 + .5;
tn.iGain = tn.Gain * 1e-2 + .5;
tn.ipI[0] = tn.pI[0] * 1e13 + fsgn(tn.pI[0])*.5;
tn.ipI[1] = tn.pI[1] * 1e13 + fsgn(tn.pI[1])*.5;
tn.imconst = tn.mconst * 1e1 + fsgn(tn.mconst)*.5;
ti.iIL = ti.IL * 1e11 + fsgn(ti.IL)*.5;
if (ti.type == 0)
ti.ipL[0] = ti.pL[0] * 1e6 + fsgn(ti.pL[0])*.5;
else
ti.ipL[0] = ti.pL[0] * 1e3 + .5;
ti.ipL[1] = ti.pL[1] * 1e3 + .5;
ti.ipL[2] = ti.pL[2] * 1e2 + .5;
ti.iIH = ti.IH * 1e11 + fsgn(ti.IH)*.5;
ti.ipH[0] = ti.pH[0] * 1e3 + .5;
ti.ipH[1] = ti.pH[1] * 1e3 + .5;
for (cq=tc, j=0; j<cc; cq++, j++)
{
cq->iIsr = cq->Isr * 1e10 + fsgn(cq->Isr)*.5;
cq->iIcr = cq->Icr * 1e10 + fsgn(cq->Icr)*.5;
}
if (!newneur && strcmp(np->name,tn.name))
{ /* copied neuron */
if (tn.Iint)
tn.Iint = Iinta+ni;
np = ns + nn;
np->Iint = 0;
np->con = 0;
nn++;
}
if (!np->con)
newcon = TRUE;
else
newcon = FALSE;
if (!np->Iint && tn.Iint)
ni++;
*(np) = tn;
if (tn.Iint)
*tn.Iint = ti;
j = 0;
cq = tc;
if (!newcon)
for (cp=np->con; cp!=NULL && j<cc; cp=cs, cq++, j++)
{
cs = cp->next;
*cp = *cq;
if (j == cc-1)
cp->next = NULL;
else
if (cs == NULL && j < cc-1)
cp->next = cona + nc;
else
cp->next = cs;
}
if (cp == NULL)
{
if (j != cc)
{
for (cp=cona+nc, i=0; j<cc; cp++, j++, cq++, i++)
{
if (!newcon)
*cp = *cq;
cp->next = cp + 1;
}
(cp-1)->next = NULL;
if (newcon)
np->con = cona + nc;
nc += i;
}
}
goto start;
case CR:
switch (line)
{
case 8: /* Intrinsic current type */
if (!tn.Iint)
{
tn.Iint = Iinta + ni;
ti.type = 0;
}
else
if (ti.type == 0)
ti.type = 1;
else
tn.Iint = NULL;
ndisp(tn,ti,line);
break;
case 16: /* Sensory current function */
tn.Isens++;
if (tn.Isens > 6)
tn.Isens = 0;
ndisp(tn,ti,line);
break;
case 19: /* motor output type */
tn.mtype++;
if (tn.mtype > 2)
tn.mtype = 0;
ndisp(tn,ti,line);
break;
case 20: /* motor output sub type */
if (tn.mtype == 1)
{
tn.mname++;
if (tn.mname > 2)
tn.mname = 0;
}
else
if (tn.mtype == 2)
tn.mname = !tn.mname;
else
break;
ndisp(tn,ti,line);
break;
case 22: /* Switch to connections page */
conmod(tn.name,tc,&cc);
ndisp(tn,ti,3);
line = 3;
break;
default:
if (line < 22)
line++;
else
line = 1;
gotoxy(40,line);
break;
}
break;
case ESC:
if (newneur)
nn--;
goto start;
default:
break;
}
}
else
{ /* process input */
if (line <= 7 ||
(tn.Iint && line >= 9 && line <= 15 &&
!(line == 12 && ti.type == 1)) ||
(tn.Isens && (line == 17) || (tn.Isens == OS && line == 18)) ||
(tn.mtype && (line == 21)))
{ /* get numerical input */
gotoxy(40,line);
cputs(" ");
gotoxy(40,line);
if (line == 1)
str[0] = 7;
else
str[0] = 15;
p = cgets(str);
if (line == 1)
{
strcpy(tn.name,p);
line = 3;
gotoxy(40,3);
}
else
{
d = atof(p);
gotoxy(40,line);
if (line == 18 || line == 17)
cprintf("%.4f",d);
else
cprintf("%.2f",d);
switch (line)
{
case 3: /* Gmem */
tn.Gmem = d * 1e-6;
break;
case 4: /* Cmem */
tn.Cmem = d * 1e-9;
break;
case 5: /* Vt */
tn.Vt = d * 1e-3;
break;
case 6: /* Fmin */
tn.Fmin = d;
break;
case 7: /* Gain */
tn.Gain = d * 1e3;
break;
case 9: /* IL */
ti.IL = d * 1e-9;
break;
case 10:
ti.pL[0] = d * 1e-3;
break;
case 11:
ti.pL[1] = d * 1e-3;
break;
case 12:
ti.pL[2] = d