/* cvort (centrifugation velocity or time ) is a program to compute running time (and total time) necessary at a given speed for centrifuging out a given particle from a given medium. If a 'v' option specified on the run-line, a time (total time) must be entered and a velocity will be computed for the given time, medium and particle. */ #include "cvort.h" #include #include #include #define MAXLINE 151 main(argc,argv) int argc; char**argv; { double ta,td, /* acceleration time, deceleration time */ r1,r2; /*distance from center of centrifuge of top & bottom */ float tr,vsc,vel,rad, /*running time,viscosity of medium,angular vel, radius of particle*/ p,p0; /*density of particle, density of medium */ char *temp,*word,*strtok(),line[MAXLINE]; double atof(); int itemp,c,tflag,mflag,pflag,vflag; /* temperature is only useful when the medium is water & the range is between 16 - 40 degrees Centigrade if medium specified the specific gravity [p0] and the viscosity [vsc] must be specified; therefore, the temperature is not needed */ /* medium flag allows entry of medium density and viscosity temp flag allow selection of density & viscosity of water from 16-40C particle flag allows entry of density of particle velocity flag specifies computation of velocity rather than time */ /* for quartz */ p = 2.65; /* for water at 20 degrees */ vsc = vis[4]; p0 = sp0[4]; mflag = tflag = pflag = vflag = 0; if (argc > 1) { if (**++argv != '-' || invalid(*argv,"mtvp")) { fprintf(stderr,"\n ** Usage: cvort [-vpmt] ** \n"); exit(1); } if (strchr(*argv,'m')) mflag = 1; if (strchr(*argv,'t')) tflag = 1; if (strchr(*argv,'v')) vflag = 1; if (strchr(*argv,'p')) pflag = 1; } if (mflag && tflag) { printf("Cannot select temperature for medium other than water.\n"); exit(1); } if (mflag) { printf(" Enter viscosity (poises) of medium: "); if (scanf ("%f",&vsc) == EOF) bombed(); printf(" Enter density(g/cc) of medium: "); if (scanf("%f",&p0) == EOF) bombed(); } if (tflag) { printf(" Enter a water temperature(16-40C): "); if (scanf("%d",&itemp) == EOF) bombed(); itemp -= 16; if (itemp < 0 || itemp > 24) { fprintf(stderr, "Must specify 'm' option for water not at 16- 40 deg C.\n"); bombed(); } vsc = vis[itemp]; p0 = sp0[itemp]; } if (pflag) { printf(" Enter particle density (g/cc): "); if (scanf("%f",&p) == EOF) bombed(); } else printf(" Particle to be settled is quartz (%.3f)\n",p); if (!mflag && !tflag) printf(" \n *** Assumed medium is WATER at 20 degrees C *** \n"); printf(" Enter particle radius(micrometers): "); if (scanf("%f",&rad) == EOF) bombed(); rad *= 0.0001; /* convert micrometers to cm */ getchar(); /* to get straggling cr/lf from scanf read */ dist: printf (" Enter initial,final distance from center: "); if (!gets(line)) bombed(); if ((word = strtok(line,",")) == '\0') {printf("COMMA delimiter expected.\n"); goto dist;} r1 = atof(word); if ((word = strtok('\0',",")) == '\0') {printf("COMMA delimiter expected.\n"); goto dist;} r2 = atof(word); if (r1 > r2) { tr = r1; r1 = r2; r2 = tr; } if (vflag) { do { printf(" Enter total time in seconds (Ta + Tr + Td): "); if (scanf("%f",&tr) == EOF) bombed(); getchar(); /* to get straggling cr/lf from scanf read */ time: printf (" Enter acceleration time, deceleration time (secs): "); if (!gets(line)) bombed(); if ((word = strtok(line,",")) == '\0') {printf("COMMA delimiter expected.\n"); goto time;} ta = atof(word); if ((word = strtok('\0',",")) == '\0') {printf("COMMA delimiter expected.\n"); goto time;} td = atof(word); tr = tr - 0.66667*(ta+td); if (tr <= 0) { fprintf(stderr,"Unrealistic time specification \07\n"); continue; } vel = sqrt((vsc*log(r2/r1))/(8.77*tr*rad*rad*(p-p0))); /* convert rps to rpm */ vel *= 60.0; printf(" *** Computed velocity (rpm): %d \n",(int) vel); } while (tr <= 0.0); } else { printf(" Enter velocity(rpm): "); if (scanf("%f",&vel) == EOF) bombed(); /* convert rpm to rps */ vel /= 60.0; getchar(); /* to get straggling cr/lf from scanf read */ btime: printf (" Enter acceleration time, deceleration time (secs): "); if (!gets(line)) bombed(); if ((word = strtok(line,",")) == '\0') {printf("COMMA delimiter expected.\n"); goto btime;} ta = atof(word); if ((word = strtok('\0',",")) == '\0') {printf("COMMA delimiter expected.\n"); goto btime;} td = atof(word); tr = (double)((vsc*log(r2/r1))/(8.77*vel*vel*rad*rad*(p-p0))); tr += 0.666667*(ta+td); printf("\n *** Total time (sec): %f\n",tr); printf(" T - td (sec): %f\n",(tr - td)); if (tr < (ta+td)) printf("\n\07 Separation completed prior to the expiration of the total time!\n"); } exit(0); } bombed() { fprintf(stderr," Abnormal termination.\n"); exit(2); } /* list is a word on the run-line - opts is a list of valid option characters */ invalid(list,opts) char *list; char *opts; { char c,*opc; while ((c = *++list)) { opc = opts; while (*opc) if (c == *opc++) return (0); } return (1); }