home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
SCIENCE
/
STAGES12.ZIP
/
MOVES.C
< prev
next >
Wrap
Text File
|
1991-04-21
|
12KB
|
443 lines
#include "header.h"
#include "file.h"
#define FACTOR 1000
/************************************************************************/
/** cycle movement calculations **/
/************************************************************************/
/* includes the functions:
forward
backward
cellcheck
*/
static cellcheck (int cellnum, int part, int *ok, int *flagp, char dir,
double days, double life, char *opstr);
/********************************/
/* function: forward */
/********************************/
/* returns 1 if all movements ok,
returns 0 if any movement caused spermiation */
forward (initseq, index, third, days, cell, ok, endspotp, opstr)
int initseq, index;
double third, days;
int *cell, *ok, *endspotp;
char *opstr;
{
double d[4]; /* four day counts, starting */
/* from beg, 1/3, 2/3, and end */
/* of current stage */
/* the following array duplicates the d[4] array. it is used to track
stages after the particular cell has been spermiated */
double dd[4];
double life[4]; /* time til spermiation, from */
/* the beg, 1/3, 2/3 and end */
int i; /* cell sequence number */
int j; /* stage array counter */
int k; /* iteration var */
int here; /* temp var for cell stage # */
int strsetq; /* error opstr set yet? if so, */
/* don't set it again */
#if (DEBUG > 4)
#if PC
clrscr1(3);
gotoxy(1, 1);
cprintf("%sforward: entering", tab);
hitreturn(1);
#else
printf("\tforward: entering\n");
#endif
#endif
strsetq = 0;
*endspotp = 0;
/* d[0] starts .001 of the way into the stage[index] */
life[0] = stage[index]*0.999;
life[1] = 2*third;
life[2] = third;
/* d[3] starts .001 from the end of the stage[index] */
life[3] = stage[index]*0.001;
for ( k=0; k<4; k++ ) {
ok[k] = 1;
d[k] = days - life[k]; /* d vars */
dd[k] = d[k];
cell[k] = 0; /* init cell vars to anything */
} /* for k */
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sforward: life: [0]=<%lf> [1]=<%lf>", tab, life[0], life[1]);
gotoxy(1, 6);
cprintf("%s [2]=<%lf> [3]=<%lf>", tab, life[2], life[3]);
gotoxy(1, 7);
cprintf("%sforward: d: [0]=<%lf> [1]=<%lf>", tab, d[0], d[1]);
gotoxy(1, 8);
cprintf("%s [2]=<%lf> [3]=<%lf>", tab, d[2], d[3]);
gotoxy(1, 9);
cprintf("%sforward: dd: [0]=<%lf> [1]=<%lf>", tab, dd[0], dd[1]);
gotoxy(1, 10);
cprintf("%s [2]=<%lf> [3]=<%lf>", tab, dd[2], dd[3]);
hitreturn(1);
#else
printf("\t: \n");
#endif
#endif
for ( k=0; k<4; k++ ) {
i = initseq;
j = index;
while ((d[k] > 0.0) && ok[k]) {
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sforward: i=<%d> CellNames[i]=<%s>",
tab, i, CellNames[i]);
hitreturn(1);
#else
printf("\tforward: i=<%d> CellNames[i]=<%s>\n", i, CellNames[i]);
#endif
#endif
here = getcellstg(CellNames[i]);
if (here == INVALID) {
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sforward: Illegal value, here=<%d>", tab, here);
gotoxy(1, 7);
cprintf("%s Sorry, aborting.", tab);
#else
printf("\tforward: Illegal value, here=<%d>\n", here);
printf("\t Sorry, aborting.");
#endif
printexit(601);
} /* if INVALID */
/* skip cells in same stage as current cell, to get to first successor
cell in the next stage, but only move fwd til i > MaxCellIndex+1
'+1' because of epididymis */
while ((++i <= MaxCellIndex+1) && (getcellstg(CellNames[i])==here));
cellcheck(i, k, ok, &strsetq, 'F', days, life[k], opstr);
switch (ok[k]) {
case 1: /* cell ok, still in cycle */
j = ++j % NumStages;
if (d[k] < stage[j]) {
/* move ends @ this stage: find which 3d moves ends in */
if (d[k] <= (stage[j]/3.0)) {
*endspotp = 1;
} else {
if (d[k] <= (2.0*stage[j]/3.0)) {
*endspotp = 2;
} else {
*endspotp = 3;
}
}
}
life[k] += stage[j];
d[k] -= stage[j];
dd[k] = d[k];
break;
case 2: /* cell into epididymis */
life[k] += EpiTime;
d[k] -= EpiTime;
/* for stage tracking, just use stage index j and ignore cell */
j = ++j % NumStages;
dd[k] -= stage[j];
break;
case 0:
default: /* ejaculate: but keep going, to get final stage reached */
j = ++j % NumStages;
dd[k] -= stage[j];
break;
} /* switch */
} /* while d[k] */
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sforward: k=<%d> ok[k]=<%d> cell#=<%d> stg#=<%d>",
tab, k, ok[k], i, j);
hitreturn(1);
#else
printf("\tforward: \n");
#endif
#endif
/* stopped moving: set cell or stage reached */
switch (ok[k]) {
case 1: /* reached normal cell */
cell[k] = i;
break;
case 2: /* reached epi: use stage that would've been reached */
cell[k] = j;
break;
case 0:
default: /* ejaculated: set cell[k] to stage reached */
cell[k] = j;
break;
} /* switch */
} /* for k */
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 4);
cprintf("%sforward: mid-function", tab);
gotoxy(1, 5);
cprintf("%sforward: cell: [0]=<%d> [1]=<%d>", tab, cell[0], cell[1]);
gotoxy(1, 6);
cprintf("%s [2]=<%d> [3]=<%d>", tab, cell[2], cell[3]);
hitreturn(1);
#else
printf("\t: \n");
#endif
#endif
/* for those starting pts which ended up with epi/ejact cells, continue
to track stages */
for ( k=0; k<4; k++ ) {
if (ok[k] != 1) {
j = cell[k]; /* the stage this starting pt left off at */
while (dd[k] > 0.0) {
j = ++j % NumStages;
dd[k] -= stage[j];
} /* while dd[k] */
/* stopped moving: set stage reached */
cell[k] = j+1;
} /* if */
} /* for k */
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 4);
cprintf("%sforward: leaving", tab);
gotoxy(1, 5);
cprintf("%sforward: cell: [0]=<%d> [1]=<%d>", tab, cell[0], cell[1]);
gotoxy(1, 6);
cprintf("%s [2]=<%d> [3]=<%d>", tab, cell[2], cell[3]);
gotoxy(1, 7);
cprintf("%s endspot=<%d>", tab, *endspotp);
hitreturn(1);
#else
printf("\tforward: leaving\n");
#endif
#endif
return(0);
} /* forward */
/********************************/
/* function: backward */
/********************************/
/* returns 1 if all movements ok,
returns 0 if any movement went further back than when
cell entered cycle */
backward (initseq, index, third, days, cell, ok, endspotp, opstr)
int initseq, index;
double third, days;
int *cell, *ok, *endspotp;
char *opstr;
{
double d[4]; /* four day counts, starting */
/* from beg, 1/3, 2/3, and end */
/* of current stage */
/* the following array duplicates the d[4] array. it is used to track
stages after the particular cell has been spermiated. */
double dd[4];
double life[4]; /* time til cell released, from */
/* the beg, 1/3, 2/3 and end */
int i; /* cell sequence number */
int j; /* stage array counter */
int k; /* iteration var */
int here; /* temp var for cell stage # */
int strsetq; /* error opstr set yet? */
strsetq = 0;
*endspotp = 3;
/* d[3] starts .001 from the end of the stage[index] */
life[3] = stage[index]*0.999;
life[2] = 2*third;
life[1] = third;
/* d[0] starts .001 of the way into the stage[index] */
life[0] = stage[index]*0.001;
for ( k=0; k<4; k++ ) {
ok[k] = 1; /* init ok vars */
d[k] = days - life[k]; /* init d vars */
dd[k] = d[k];
cell[k] = 0; /* init cell vars to anything */
}
for ( k=3; k>-1; k-- ) {
i = initseq;
j = index;
while ((d[k] > 0) && ok[k]) {
here = getcellstg(CellNames[i]);
/* skip cells in same stage as current cell, to get to first successor
cell in the next stage, but only move bwd til i = 0 */
while ((--i >= 0) && (getcel