9#include "tpcclibConfig.h"
23static char *info[] = {
24 "Print or edit the frame times in regional TAC datafile.",
26 "By default, frame start times and lengths are printed on screen, and",
27 "optionally saved in the SIF (scan information file), if it does not exist.",
28 "If an existing SIF name is specified, the SIF frames are written into",
29 "regional TAC file; also normal TAC file containing frame start and end times",
30 "can be given instead of SIF.",
32 "Usage: @P [options] tacfile sif",
36 " Frame mid time is written in TAC file instead of frame start and end",
37 " times that are read from SIF. Not effective when writing SIF.",
41 " @P iea567.tac iea567dy.img.sif",
43 "See also: tactime, tacsetx, interpol, taccat, taccut, simframe, tacformat",
45 "Keywords: TAC, SIF, tool, time",
64int main(
int argc,
char **argv)
66 int ai, help=0, version=0, verbose=1;
70 char *cptr, tacfile[FILENAME_MAX], siffile[FILENAME_MAX];
77 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
79 tacfile[0]=siffile[0]=(char)0;
81 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
83 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
84 if(strncasecmp(cptr,
"MIDDLE", 3)==0) {
87 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
96 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
101 for(; ai<argc; ai++) {
103 strlcpy(tacfile, argv[ai], FILENAME_MAX);
continue;
104 }
else if(!siffile[0]) {
105 strlcpy(siffile, argv[ai], FILENAME_MAX);
continue;
107 fprintf(stderr,
"Error: too many arguments: '%s'.\n", argv[ai]);
113 printf(
"tacfile := %s\n", tacfile);
114 printf(
"siffile := %s\n", siffile);
115 printf(
"isframe := %d\n", isframe);
120 fprintf(stderr,
"Error: missing TAC name.\n");
125 if(verbose>1) printf(
"reading %s\n", tacfile);
126 ret=
tacRead(&tac, tacfile, &status);
128 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
133 printf(
"tacNr := %d\n", tac.
tacNr);
134 printf(
"sampleNr := %d\n", tac.
sampleNr);
135 printf(
"tac_frames := %d\n", tac.
isframe);
139 fprintf(stdout,
"Warning: unknown time unit in %s\n", tacfile);
145 if(access(siffile, 0) != -1) {
152 if(verbose>2) printf(
"opMode := %d\n", opMode);
159 if(verbose>1) printf(
"reading %s\n", siffile);
160 ret=
tacRead(&sif, siffile, &status);
162 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
167 printf(
"siftacNr := %d\n", sif.
tacNr);
168 printf(
"sifsampleNr := %d\n", sif.
sampleNr);
169 printf(
"sifisframe := %d\n", sif.
isframe);
173 fprintf(stdout,
"Warning: unknown time unit in %s\n", siffile);
177 fprintf(stderr,
"Error: different frame numbers.\n");
180 fprintf(stderr,
"Warning: different frame numbers.\n");
183 if(isframe==1 && sif.
isframe==0) {
184 fprintf(stderr,
"Error: no frame start and end times in %s\n", siffile);
195 fprintf(stderr,
"Error: cannot copy frame times.\n");
207 if(verbose>1) printf(
"writing %s\n", tacfile);
208 FILE *fp; fp=fopen(tacfile,
"w");
210 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", tacfile);
216 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
226 if(verbose>1) printf(
"creating SIF data from regional TAC data\n");
235 printf(
"original data does not contain frame start and end times\n");
237 fprintf(stderr,
"Error: data does not contain valid frame times.\n");
245 if(verbose>1) printf(
"writing %s\n", siffile);
246 FILE *fp; fp=fopen(siffile,
"w");
248 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", siffile);
254 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
265 if(opMode==1 && tac.
isframe==0) {
266 fprintf(stderr,
"Error: no frame start and end times in %s\n", tacfile);
269 if(opMode==1 || verbose>1) {
270 fprintf(stdout,
"# Frame start and length\n");
271 for(
int fi=0; fi<tac.
sampleNr; fi++) {
272 fprintf(stdout,
"%g %g\n", tac.
x1[fi], tac.
x2[fi]-tac.
x1[fi]);
280 printf(
"New frames saved in datafile %s\n", tacfile);
281 }
else if(opMode==1) {
282 fprintf(stdout,
"# %d frames were found in %s\n", tac.
sampleNr, tacfile);
283 }
else if(opMode==2) {
284 printf(
"# %d frames were found in %s; saved in %s\n",
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)
int tacWriteSIF(TAC *tac, FILE *fp, int extra, TPCSTATUS *status)
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 tacFormatWriteSupported(tacformat format)
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 tacXUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
int tacXCopy(TAC *tac1, TAC *tac2, int i1, int i2)
int tacSetX(TAC *d, TPCSTATUS *status)
Set TAC x values based on x1 and x2 values, or guess x1 and x2 values based on x values.
Header file for library libtpcextensions.
@ UNIT_UNKNOWN
Unknown unit.
Header file for library libtpctac.
@ TAC_FORMAT_IFT
Interfile-type data (supported for writing).
@ TAC_FORMAT_UNKNOWN
Unknown format.
@ TAC_FORMAT_PMOD
PMOD TAC format.
@ TAC_FORMAT_SIMPLE
x and y's with space delimiters
@ TAC_FORMAT_DFT
Data format of Turku PET Centre.
@ TAC_FORMAT_SIF
Scan information file.