8#include "tpcclibConfig.h"
22static char *info[] = {
23 "Calculates the TAC of blood cells (erythrocytes, RBC) using",
24 "haematocrit (HCT), blood TAC, and plasma TAC, based on equation",
26 " Blood = HCT*RBC + (1-HCT)*Plasma ",
28 "HCT is normally between 0.40-0.51 in men and 0.36-0.47 in women.",
30 "Usage: @P [Options] bloodfile plasmafile HCT rbcfile",
35 "See also: bpr2cpr, p2blood, b2plasma, taccalc, fit_bpr",
37 "Keywords: input, modelling, simulation, RBC, plasma, blood",
56int main(
int argc,
char **argv)
58 int ai, help=0, version=0, verbose=1;
60 char pfile[FILENAME_MAX], bfile[FILENAME_MAX], rfile[FILENAME_MAX];
68 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
69 pfile[0]=bfile[0]=rfile[0]=(char)0;
72 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
75 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
84 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
89 for(; ai<argc; ai++) {
91 strlcpy(bfile, argv[ai], FILENAME_MAX);
continue;
92 }
else if(!pfile[0]) {
93 strlcpy(pfile, argv[ai], FILENAME_MAX);
continue;
96 if(HCT>1.0) HCT/=100.0;
97 if(HCT>0.0 && HCT<=1.0)
continue;
99 fprintf(stderr,
"Error: invalid HCT.\n");
101 }
else if(!rfile[0]) {
102 strlcpy(rfile, argv[ai], FILENAME_MAX);
continue;
104 fprintf(stderr,
"Error: too many arguments: '%s'.\n", argv[ai]);
110 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
116 for(ai=0; ai<argc; ai++)
117 printf(
"%s ", argv[ai]);
119 printf(
"pfile := %s\n", pfile);
120 printf(
"bfile := %s\n", bfile);
121 printf(
"rfile := %s\n", rfile);
122 printf(
"HCT := %g\n", HCT);
129 if(verbose>1) printf(
"reading %s\n", bfile);
130 ret=
tacRead(&blood, bfile, &status);
132 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
137 printf(
"tacNr := %d\n", blood.
tacNr);
138 printf(
"sampleNr := %d\n", blood.
sampleNr);
143 fprintf(stderr,
"Warning: only first TAC in blood file is used.\n");
150 if(verbose>1) printf(
"reading %s\n", pfile);
151 ret=
tacRead(&plasma, pfile, &status);
153 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
158 printf(
"tacNr := %d\n", plasma.
tacNr);
159 printf(
"sampleNr := %d\n", plasma.
sampleNr);
164 fprintf(stderr,
"Warning: only first TAC in plasma file is used.\n");
174 if(verbose>1) printf(
"missing blood concentrations.\n");
178 fprintf(stderr,
"Error: missing concentrations in %s.\n", bfile);
184 if(verbose>1) printf(
"missing plasma concentrations.\n");
188 fprintf(stderr,
"Error: missing concentrations in %s.\n", pfile);
196 fprintf(stderr,
"Warning: different or unknown time units.\n");
200 fprintf(stderr,
"Warning: different or unknown concentration units.\n");
207 fprintf(stderr,
"Warning: different sample times.\n");
217 fprintf(stderr,
"Error: cannot interpolate plasma TAC.\n");
223 blood.
c[0].
y[i] = (blood.
c[0].
y[i] - (1.0-HCT)*blood.
c[1].
y[i]) / HCT;
229 if(verbose>1) printf(
"writing %s\n", rfile);
231 FILE *fp; fp=fopen(rfile,
"w");
233 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", rfile);
239 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
242 if(verbose>=0) printf(
"RBC curve written in %s\n", rfile);
int atofCheck(const char *s, double *v)
int liInterpolate(double *x, double *y, const int nr, double *newx, double *newy, double *newyi, double *newyii, const int newnr, const int se, const int ee, const int verbose)
Linear interpolation and/or integration with trapezoidal method.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
void statusInit(TPCSTATUS *s)
char * errorMsg(tpcerror e)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
int tacAllocateMore(TAC *tac, int tacNr)
int tacRead(TAC *d, const char *fname, TPCSTATUS *status)
char * tacFormattxt(tacformat c)
int tacWrite(TAC *tac, FILE *fp, tacformat format, int extra, TPCSTATUS *status)
int tacSortByTime(TAC *d, TPCSTATUS *status)
int tacYUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
int tacXUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
Header file for library libtpcextensions.
char * unitName(int unit_code)
Header file for library libtpcift.
Header file for libtpcli.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.