home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
NERVES.ZIP
/
NO87
/
NSMENU.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-12
|
18KB
|
826 lines
#include "defn.h"
#include "nsdata.c"
#include "proto.h"
#include "lsin.c"
#include "lcos.c"
void nsmenu(void)
{ /* main menu */
int i,j,k,m,done,msg;
enum asc_val asc;
char str[41];
char *p;
FILE *file;
struct neuron *np;
struct con *cp;
struct Iint *ip;
float f;
msg = FALSE;
display: /* display menu */
clrscr();
if (msg)
{
gotoxy(1,1);
cputs("Recording path not found, Press P to change");
msg = FALSE;
}
gotoxy(5,8);
textattr(WHITE);
cputs("R");
textattr(LIGHTGRAY);
cputs("ead files");
gotoxy(5,10);
textattr(WHITE);
cputs("W");
textattr(LIGHTGRAY);
cputs("rite files");
gotoxy(5,12);
textattr(WHITE);
cputs("N");
textattr(LIGHTGRAY);
cputs("euron data modification");
gotoxy(5,14);
textattr(WHITE);
cputs("E");
textattr(LIGHTGRAY);
cputs("nvironment specification");
gotoxy(5,16);
textattr(WHITE);
cputs("I");
textattr(LIGHTGRAY);
cputs("nitialize conditions");
gotoxy(5,18);
textattr(WHITE);
cputs("G");
textattr(LIGHTGRAY);
cputs("raph specification");
gotoxy(5,20);
textattr(WHITE);
cputs("P");
textattr(LIGHTGRAY);
cputs("ath specification for recording");
gotoxy(5,22);
textattr(WHITE);
cputs("S");
textattr(LIGHTGRAY);
cputs("imulate");
gotoxy(5,24);
textattr(WHITE);
cputs("Q");
textattr(LIGHTGRAY);
cputs("uit");
gotoxy(37,8);
if (neurfname[0])
cprintf("Neuron file: %s",neurfname);
gotoxy(37,9);
if (envfname[0])
cprintf("Environment file: %s",envfname);
gotoxy(37,10);
if (recpath[0])
cprintf("Recording path: %s",recpath);
erasecursor();
/* get choice */
done = FALSE;
while (!done)
{
i = toupper(bioskey(0) & 0xff);
switch (i)
{
case 'R': /* read files */
start: /* get the neuron filespec & read in */
gotoxy(1,1);
cputs("Enter neuron file spec: ");
gotoxy(25,1);
j = 0;
while (!j)
j = bioskey(1);
asc = j & 0xff;
if (asc == ESC)
{
bioskey(0);
goto display;
}
else
if (asc == CR)
{
bioskey(0);
goto envfile;
}
str[0] = 25;
p = cgets(str);
file = fopen(p,"rb");
if (file == NULL)
goto start;
else
{ /* read in file */
fread(&nn,2,1,file);
for (np=ns, j=0; j<nn; np++, j++)
{
fread(np,sizeof(struct neuron)-22,1,file);
np->iGmem = np->Gmem * 1e8 + .5;
np->iCmem = np->Cmem * 1e11 + .5;
np->iVt = np->Vt * 1e6 + fsgn(np->Vt)*.5;
np->iFmin = np->Fmin * 10000 + .5;
np->iGain = np->Gain * 1e-2 + .5;
np->ipI[0] = np->pI[0] * 1e13 + fsgn(np->pI[0])*.5;
np->ipI[1] = np->pI[1] * 1e13 + fsgn(np->pI[1])*.5;
np->imconst = np->mconst * 1e1 + fsgn(np->mconst)*.5;
}
fread(&ni,2,1,file);
for (ip=Iinta, j=0; j<ni; ip++, j++)
{
fread(ip,40,1,file);
ip->iIL = ip->IL * 1e11 + fsgn(ip->IL)*.5;
if (ip->type == 0)
ip->ipL[0] = ip->pL[0] * 1e6 + fsgn(ip->pL[0])*.5;
else
ip->ipL[0] = ip->pL[0] * 1e3 + .5;
ip->ipL[1] = ip->pL[1] * 1e3 + .5;
ip->ipL[2] = ip->pL[2] * 1e2 + .5;
ip->iIH = ip->IH * 1e11 + fsgn(ip->IH)*.5;
ip->ipH[0] = ip->pH[0] * 1e3 + .5;
ip->ipH[1] = ip->pH[1] * 1e3 + .5;
}
fread(&nc,2,1,file);
for (cp=cona, j=0; j<nc; cp++, j++)
{
fread(cp,sizeof(struct con)-4,1,file);
cp->iIsr = cp->Isr * 1e10 + fsgn(cp->Isr)*.5;
cp->iIcr = cp->Icr * 1e10 + fsgn(cp->Icr)*.5;
}
fclose(file);
/* change pointers */
for (j=0, np=ns; j<nn; j++, np++)
{
if (np->Iint != NULL)
np->Iint = Iinta + ((int)np->Iint - 1)/40;
if (np->con != NULL)
np->con = cona + ((int)np->con - 1)/32;
}
for (j=0, cp=cona; j<nc; j++, cp++)
{
if (cp->next != NULL)
cp->next = cona + ((int)cp->next - 1)/32;
}
strcpy(neurfname,p);
gotoxy(37,8);
cprintf("Neuron file: %s ",neurfname);
}
envfile:
gotoxy(1,1);
cputs("Enter environment file spec: ");
gotoxy(30,1);
j = 0;
while (!j)
j = bioskey(1);
asc = j & 0xff;
if (asc == ESC || asc == CR)
{
bioskey(0);
goto display;
}
str[0] = 25;
p = cgets(str);
file = fopen(p,"rb");
if (file == NULL)
goto envfile;
else
{ /* read in file */
fread(&f,sizeof(float),1,file);
bug.x = f*1000. + .5;
fread(&f,sizeof(float),1,file);
bug.y = f*1000. + .5;
fread(&f,sizeof(float),1,file);
bug.ang = f*100000. + .5;
fread(&nfood,2,1,file);
fread(foodx,2,NFOOD,file);
fread(foody,2,NFOOD,file);
for (k=0; k<NFOOD; k++)
{
fread(&j,2,1,file);
foodsize[k] = (long)j * 10000L;
}
fread(&nblock,2,1,file);
fread(blockx,2,NBLOCK,file);
fread(blocky,2,NBLOCK,file);
fread(gr,sizeof(struct graph),5,file);
fclose(file);
strcpy(envfname,p);
}
goto display;
case 'W': /* write files */
gotoxy(1,1);
cputs("Write neuron file? ");
if (toupper(bioskey(0) & 0xff) != 'Y')
goto wenvfile;
/* write neuron file */
/* count neurons */
for (i=0, j=0, np=ns; i<nn; i++, np++)
if (np->name[0])
j++;
gotoxy(1,1);
if (neurfname[0])
{
cprintf("Save neurons 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);
wenvfile: /* write environment file */
gotoxy(1,1);
cputs("Write environment file? ");
gotoxy(1,25);
if (toupper(bioskey(0) & 0xff) != 'Y')
goto display;
gotoxy(1,1);
if (envfname[0])
{
cprintf("Save environment to %s? ",envfname);
j = toupper(bioskey(0) & 0xff);
}
if (!envfname[0] || j != 'Y')
{
gotoxy(1,1);
cputs("Enter file spec: ");
gotoxy(18,1);
str[0] = 38;
p = cgets(str);
strcpy(envfname,p);
}
file = fopen(envfname,"wb");
f = (double)bug.x/1000.;
fwrite(&f,sizeof(float),1,file);
f = (double)bug.y/1000.;
fwrite(&f,sizeof(float),1,file);
f = (float)bug.ang/100000.;
fwrite(&f,sizeof(float),1,file);
fwrite(&nfood,2,1,file);
fwrite(foodx,2,NFOOD,file);
fwrite(foody,2,NFOOD,file);
for (k=0; k<NFOOD; k++)
{
j = foodsize[k]/10000L;
fwrite(&j,2,1,file);
}
fwrite(&nblock,2,1,file);
fwrite(blockx,2,NBLOCK,file);
fwrite(blocky,2,NBLOCK,file);
fwrite(gr,sizeof(struct graph),5,file);
fclose(file);
goto display;
case 'N': /* neuron data modification */
datamod();
goto display;
case 'E': /* environment set up */
pent: gotoxy(1,1);
cprintf("Enter number of food patches (0 - %d): %d ",NFOOD,nfood);
gotoxy(39,1);
j = 0;
while (!j)
j = bioskey(1);
asc = j & 0xff;
if (asc == CR)
{
bioskey(0);
goto pdat;
}
else
if (asc == ESC)
{
bioskey(0);
goto display;
}
gotoxy(39,1);