home *** CD-ROM | disk | FTP | other *** search
- #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) && (getcellstg(CellNames[i])==here));
- cellcheck(i, k, ok, &strsetq, 'B', days, life[k], opstr);
-
- if (j==0)
- j = MaxStage;
- else
- j = --j % NumStages;
-
- switch (ok[k]) {
- case 1: /* cell ok, still in cycle */
- if (d[k] < stage[j]) {
- /* move ends @ this stage: find which 3d moves ends in */
- if (d[k] <= (stage[j]/3.0)) {
- *endspotp = 3;
- } else {
- if (d[k] <= (2.0*stage[j]/3.0)) {
- *endspotp = 2;
- } else {
- *endspotp = 1;
- }
- }
- }
- life[k] += stage[j];
- d[k] -= stage[j];
- dd[k] = d[k];
- break;
- case 0:
- default: /* pre-entry: but keep going, to get final stage reached */
- dd[k] -= stage[j];
- break;
- } /* switch */
- } /* while d[k] */
-
- /* stopped moving: set cell reached */
- switch (ok[k]) {
- case 1: /* reached normal cell */
- cell[k] = i;
- break;
- case 0:
- default: /* pre-entry: set cell[k] to stage reached */
- cell[k] = j;
- break;
- } /* switch */
- } /* for k */
-
- /* for those starting pts which ended up as pre-entry, continue to
- track stages */
- for ( k=3; k>-1; k-- ) {
- if (! ok[k]) {
- j = cell[k]; /* the stage this starting pt left off at */
- while (dd[k] > 0) {
- if (j==0)
- j = MaxStage;
- else
- 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("%sbackward: leaving", tab);
- gotoxy(1, 5);
- cprintf("%sbackward: 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 ok: [0]=<%d> [1]=<%d>", tab, ok[0], ok[1]);
- gotoxy(1, 8);
- cprintf("%s [2]=<%d> [3]=<%d>", tab, ok[2], ok[3]);
- gotoxy(1, 9);
- cprintf("%s endspot=<%d>", tab, *endspotp);
- hitreturn(1);
- #else
- printf("\tbackward: leaving\n");
- #endif
- #endif
- return(0);
- } /* backward */
-
- /********************************/
- /* function: cellcheck */
- /********************************/
- /* checks if cell moved to is valid
- ok[part] set to: 0: not ok: cell ejaculated or pre-entry
- 1: cell ok
- 2: cell in epididymis */
- /* static means that this function is only used within this file
- saves space in the executable file */
- static cellcheck (cellnum, part, ok, flagp, dir, days, life, opstr)
- int cellnum, part, *ok, *flagp;
- char dir;
- double days;
- double life; /* = #days since spermiation, or
- #days since cell entered spermatogenesis */
- char *opstr;
- {
- double tmp;
- char tmpstr[20];
-
- if (((dir=='F') && (cellnum > MaxCellIndex)) ||
- ((dir=='B') && (cellnum < CycleStart))) {
- if (cellnum == (MaxCellIndex+1))
- /* ok: cell moved into the epididymis */
- ok[part] = 2;
- else
- /* not ok: cell ejaculated or pre-entry */
- ok[part] = 0;
-
- if (! *flagp) {
- if (dir=='F') {
- *flagp = 1;
- tmp = (days-life)/CycleTime;
- sprintf(opstr, "Spermiation occurred after %.2lf day", life);
- /* want to see if life, a double, is within 1/FACTOR of 1 */
- if ((int) (FACTOR*life + 0.5) != FACTOR)
- strcat(opstr, "s");
- sprintf(tmpstr, "; %.2lf cycle", tmp);
- strcat(opstr, tmpstr);
- if ((int) (FACTOR*tmp + 0.5) != FACTOR)
- strcat(opstr,"s have ");
- else
- strcat(opstr, " has ");
- strcat(opstr, "since passed");
- }
- if (dir=='B') {
- *flagp = 1;
- tmp = life/CycleTime;
- sprintf(opstr, "Cell entered spermatogenesis cycle %.2lf day", life);
- if ((int) (FACTOR*life + 0.5) != FACTOR)
- strcat(opstr, "s");
- sprintf(tmpstr, " = %.2lf cycle", tmp);
- strcat(opstr, tmpstr);
- if ((int) (FACTOR*tmp + 0.5) != FACTOR)
- strcat(opstr, "s");
- strcat(opstr, " ago");
- #if (DEBUG > 4)
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%scellcheck: cellnum=<%d>", tab, cellnum);
- gotoxy(1, 6);
- cprintf("%s opstr=<%s>", tab, opstr);
- hitreturn(1);
- #else
- printf("\t: \n");
- #endif
- #endif
- }
- } /* if *flagp */
- } else
- /* ok: normal cell */
- ok[part] = 1;
- return(0);
- } /* cellcheck */