8#include "tpcclibConfig.h"
21static char *info[] = {
22 "Converts arterial plasma TAC from a [O-15]O2 PET study",
23 "to blood [O-15]H2O TAC (1).",
25 "Usage: @P [Options] plasmafile bloodfile",
29 " Specify the hematocrit; when specified, the plasma-to-blood ratio",
30 " is calculated using it, assuming that water contents of RBCs and",
31 " plasma are 0.73 and 0.94, respectively.",
32 " -PBR=<Plasma-to-blood ratio>",
33 " Specify the plasma-to-blood ratio; by default 1.12; effective only",
34 " when HCT is not given.",
35 " -SCT=<Sample collect time>",
36 " Plasma sample collection time (usually 20 s) should be given for",
37 " accurate fit with fit_o2bl.",
41 "1. Lubberink M, Wong YY, Raijmakers PGHM, Schuit RC, Luurtsema G,",
42 " Boellaard R, Knaapen P, Vonk-Noordegraaf A, Lammertsma AA. Myocardial",
43 " oxygen extraction fraction measured using bolus inhalation of 15O-oxygen",
44 " gas and dynamic PET. J Nucl Med. 2011;52(1):60-66.",
46 "See also: fit_o2bl, o2metab, sim_o2bl, b2t_mo2, fit_mo2, tac2svg, taccalc",
48 "Keywords: input, oxygen, blood, metabolite correction",
67int main(
int argc,
char **argv)
69 int ai, help=0, version=0, verbose=1;
71 char pfile[FILENAME_MAX], bfile[FILENAME_MAX], *cptr;
72 double pb_ratio=1.12, bp_ratio, HCT=-1.0, coll_time=-1.0;
74 double w_p=0.94, w_rbc=0.73;
75 int times_converted=0;
81 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
82 pfile[0]=bfile[0]=(char)0;
85 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
88 if(strncasecmp(cptr,
"PBR=", 4)==0) {
89 if(!
atofCheck(cptr+4, &pb_ratio) && pb_ratio>=1.0 && pb_ratio<2.0)
91 }
else if(strncasecmp(cptr,
"HCT=", 4)==0) {
92 if(!
atofCheck(cptr+4, &HCT) && HCT>0.0 && HCT<1.0) {
93 pb_ratio=-1.0;
continue;
95 }
else if(strncasecmp(cptr,
"SCT=", 4)==0) {
96 if(!
atofCheck(cptr+4, &coll_time) && coll_time>=0.0 && coll_time<60.0)
99 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
108 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
113 for(; ai<argc; ai++) {
115 strlcpy(pfile, argv[ai], FILENAME_MAX);
continue;
116 }
else if(!bfile[0]) {
117 strlcpy(bfile, argv[ai], FILENAME_MAX);
continue;
119 fprintf(stderr,
"Error: too many arguments: '%s'.\n", argv[ai]);
125 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
131 for(ai=0; ai<argc; ai++)
132 printf(
"%s ", argv[ai]);
134 printf(
"bfile := %s\n", bfile);
135 printf(
"pfile := %s\n", pfile);
136 if(HCT<=0.0) printf(
"pb_ratio := %g\n", pb_ratio);
137 else printf(
"HCT := %g\n", HCT);
138 if(coll_time>=0.0) printf(
"coll_time := %g [s]\n", coll_time);
145 printf(
"w_rbc := %g\n", w_rbc);
146 printf(
"w_plasma := %g\n", w_p);
148 bp_ratio= 1.0 - HCT*(1.0 - w_rbc/w_p);
149 pb_ratio=1.0/bp_ratio;
150 if(verbose>1) printf(
"pb_ratio := %g\n", pb_ratio);
152 bp_ratio=1.0/pb_ratio;
154 if(verbose>1) printf(
"bp_ratio := %g\n", bp_ratio);
160 if(verbose>1) printf(
"reading %s\n", pfile);
161 ret=
tacRead(&tac, pfile, &status);
163 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
168 printf(
"tacNr := %d\n", tac.
tacNr);
169 printf(
"sampleNr := %d\n", tac.
sampleNr);
174 fprintf(stderr,
"Warning: only first TAC in plasma file is used.\n");
182 if(verbose>1) printf(
"missing concentrations.\n");
186 fprintf(stderr,
"Error: missing concentrations in %s.\n", pfile);
196 fprintf(stderr,
"Warning: sample times are assumed to be in minutes.\n");
198 fprintf(stderr,
"Warning: sample times are assumed to be in seconds.\n");
205 if(verbose>1) printf(
"Sample times are converted to sec\n");
213 for(
int i=0; i<tac.
sampleNr; i++) tac.
c[0].
y[i]*=bp_ratio;
219 if(verbose>1) printf(
"setting collection time\n");
222 if(i>0 && ((tac.
x[i]-tac.
x[i-1])<coll_time)) {
223 fprintf(stderr,
"Error: sample and collection times do not match.\n");
227 tac.
x1[i]=tac.
x[i]-0.5*coll_time;
228 tac.
x2[i]=tac.
x[i]+0.5*coll_time;
235 strcpy(tac.
c[0].
name,
"Blood_H2O");
240 if(times_converted) {
241 if(verbose>1) printf(
"Sample times are converted back to min\n");
250 if(verbose>1) printf(
"writing %s\n", bfile);
251 FILE *fp; fp=fopen(bfile,
"w");
253 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", bfile);
259 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
262 if(verbose>=0) printf(
"Blood curve written in %s\n", bfile);
int atofCheck(const char *s, double *v)
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)
char name[MAX_TACNAME_LEN+1]
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
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 tacXUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
Header file for library libtpcextensions.
@ UNIT_UNKNOWN
Unknown unit.
char * unitName(int unit_code)
Header file for library libtpcift.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.
@ TAC_FORMAT_PMOD
PMOD TAC format.
@ TAC_FORMAT_SIMPLE
x and y's with space delimiters