8#include "tpcclibConfig.h"
21static char *info[] = {
22 "Correct the sample times in Allogg, Scanditronics, or GEMS ABSS on-line",
23 "blood sampler data file by giving the correct sampling start time in format",
24 "hh:mm:ss. If the new sampling start time is not given, program lists",
25 "information on the current sample times on the screen.",
27 "Use this, if sampling was accidentally started later than the PET scan.",
28 "In old Allogg files the sampler start time is given before the sampler",
29 "data lines in format hhmmss. In new Allogg files individual sample time is",
30 "stored for each sampling frame.",
31 "In Scanditronics data files the correct sampling start time is in the file",
32 "headers; however, in old Scanditronics data files the headers do not contain",
33 "time, but it is read from the first sample data line.",
34 "In GEMS data files the time in file headers is not the sampling start time,",
35 "but time is read from the first sample data line.",
36 "If new sampling time is given and it is different than the current sampling",
37 "start time, then all sample times in the sampler data file are changed.",
38 "Decay correction is not changed.",
40 "Notice that the original data file is overwritten by default.",
42 "Usage: @P [options] abssfile starttime",
46 " Name for corrected file; by default the original file is overwritten.",
49 "Example: List the start times from ABSS data and ECAT image, and",
50 "set the ABSS start time based on the PET scanner start time.",
52 " egetstrt us1328dy1.v",
53 " @P us1328.bld 13:07:45",
55 "See also: absszero, abssbkg, absscal, abssfch, abssexam, injdifft",
57 "Keywords: input, ABSS, blood, time, physical decay, calibration",
76int main(
int argc,
char **argv)
78 int ai, help=0, version=0, verbose=1;
79 char abssfile[FILENAME_MAX], outfile[FILENAME_MAX];
80 char *cptr, startTime[256];
87 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
88 abssfile[0]=outfile[0]=startTime[0]=(char)0;
90 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
92 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
93 if(strncasecmp(cptr,
"O=", 2)==0 && strlen(cptr)>2) {
94 strlcpy(outfile, cptr+2, FILENAME_MAX);
continue;
96 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
105 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
110 if(ai<argc)
strlcpy(abssfile, argv[ai++], FILENAME_MAX);
113 strlcpy(startTime, argv[ai], 9);
115 fprintf(stderr,
"Error: invalid time '%s'.\n", argv[ai]);
121 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
126 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
129 if(!outfile[0]) strcpy(outfile, abssfile);
134 printf(
"abssfile := %s\n", abssfile);
135 printf(
"startTime := %s\n", startTime);
136 printf(
"outfile := %s\n", outfile);
143 if(verbose>1) printf(
"reading %s\n", abssfile);
145 ret=
tacRead(&abss, abssfile, &status);
151 printf(
"sampleNr := %d\n", abss.
sampleNr);
154 printf(
"tacNr := %d\n", abss.
tacNr);
156 if(verbose>1 || !startTime[0]) {
164 fprintf(stderr,
"Error: not valid ABSS format.\n");
167 if(verbose>100)
abssWrite(&abss, stdout, NULL);
169 fprintf(stderr,
"Error: not valid ABSS format.\n");
174 char samplerStartTime[128], sampleStartTime[128], zeroTime[128];
180 fprintf(stdout,
"sampler_start_time := %s\n", samplerStartTime);
182 strcpy(samplerStartTime,
"");
185 strcpy(sampleStartTime,
"");
188 fprintf(stderr,
"Error: invalid start time in %s\n", abssfile);
191 strcpy(zeroTime, sampleStartTime);
192 fprintf(stdout,
"zero_time := %8.8s\n", zeroTime+11);
193 if(fabs(abss.
x1[0])>0.5) {
198 if(strftime(sampleStartTime, 32,
"%Y-%m-%d %H:%M:%S", &starttm)==0)
199 strcpy(sampleStartTime,
"");
202 fprintf(stderr,
"Error: invalid start time in %s\n", abssfile);
206 fprintf(stdout,
"date := %10.10s\n", sampleStartTime);
207 fprintf(stdout,
"first_sample_time := %8.8s\n", sampleStartTime+11);
211 fprintf(stdout,
"sample_interval[s] := %g\n", abss.
x2[0]-abss.
x1[0]);
213 fprintf(stdout,
"sampling_time[s] := %g\n",
221 if(!startTime[0]) {
tacFree(&abss);
return(0);}
226 struct tm newtm, oldtm;
227 char newZeroTime[128];
228 strlcpy(newZeroTime, zeroTime, 12);
229 strcat(newZeroTime, startTime);
230 if(verbose>3) printf(
"newZeroTime := %s\n", newZeroTime);
234 fprintf(stderr,
"Error: invalid start times.\n");
239 printf(
"required_start_time_change[s] := %g\n", timeDiff);
241 if(fabs(timeDiff)<1.0) {
242 fprintf(stdout,
"Note: start times are not different; file not changed.\n");
250 fprintf(stderr,
"Error: cannot set new start time.\n");
256 for(
int i=0; i<abss.
sampleNr; i++) {
258 abss.
x1[i]-=timeDiff;
259 abss.
x2[i]-=timeDiff;
269 printf(
"writing corrected data file in %s\n", outfile); fflush(stdout);}
271 fp=fopen(outfile,
"w");
273 fprintf(stderr,
"Error: cannot open file for writing.\n");
283 printf(
"corrected data written in %s\n", outfile);
int abssWrite(TAC *d, FILE *fp, TPCSTATUS *status)
int strDateTimeRead(const char *str, struct tm *date)
void tmAdd(int s, struct tm *d)
int strTimeValid(const char *str)
int strDateTimeValid(const char *str, char *intdate)
double tmDifference(struct tm *tm1, struct tm *tm0)
int iftFindKey(IFT *ift, const char *key, int start_index)
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)
IFT h
Optional (but often useful) header information.
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
int tacSetHeaderScanstarttime(IFT *h, const char *s)
int tacGetHeaderScanstarttime(IFT *h, char *s, TPCSTATUS *status)
int tacRead(TAC *d, const char *fname, TPCSTATUS *status)
char * tacFormattxt(tacformat c)
Header file for libtpcabss.
Header file for library libtpcextensions.
Header file for library libtpctac.
@ TAC_FORMAT_ABSS_ALLOGG
ALLOGG ABSS data; reading supported.
@ TAC_FORMAT_ABSS_GEMS
GEMS ABSS data; reading supported.
@ TAC_FORMAT_ABSS_ALLOGG_OLD
ALLOGG ABSS data (old format); reading supported.
@ TAC_FORMAT_ABSS_SCANDITRONICS
Scanditronics ABSS data; reading supported.