10#include "tpcclibConfig.h"
25static char *info[] = {
26 "Report or set data calibration units in PET images.",
27 "By default, the calibration units are only shown, not changed.",
28 "Notice that some image formats, like Analyze, do not contain information",
29 "on the calibration units.",
30 "Time frame units are determined by the image format.",
32 "Usage: @P [Options] file(s)",
35 " -u=<New unit; e.g. Bq/cc or kBq/ml>",
36 " Set the unit, but does NOT change the pixel values.",
37 " -us=<New unit; e.g. Bq/cc or kBq/ml>",
38 " Set the unit only if unit is not originally defined in the image.",
39 " This does NOT change the pixel values.",
40 " -uc=<New unit; e.g. Bq/cc or kBq/ml>",
41 " Converts pixel values to the specified unit.",
44 "The following unit conversions are tested (but also others may work):",
50 "Example: convert the pixel values in ECAT images to Bq/mL",
53 "See also: tacunit, lmhdr, lshdr, e7emhdr, imgmax, imgcalc, imglkup",
55 "Keywords: image, ECAT, unit, tool, simulation",
74int main(
int argc,
char **argv)
76 int ai, help=0, version=0, verbose=1;
77 int ret, fileNr=0, ffi=0;
80 char *cptr, petfile[FILENAME_MAX], *newunit=NULL, imgunit[128];
87 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
88 petfile[0]=(char)0; strcpy(imgunit,
"");
91 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
92 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
95 if(strncasecmp(cptr,
"US=", 3)==0 && newunit==NULL) {
98 if(strlen(newunit)>12) {
99 fprintf(stderr,
"Error: unit '%s' too long (>12).\n", newunit);
102 if(strlen(newunit)>0)
continue;
103 }
else if(strncasecmp(cptr,
"UC=", 3)==0 && newunit==NULL) {
104 cptr+=3; convertUnit=1;
106 if(strlen(newunit)>12) {
107 fprintf(stderr,
"Error: unit '%s' too long (>12).\n", newunit);
110 if(strlen(newunit)>0)
continue;
111 }
else if(strncasecmp(cptr,
"U=", 2)==0 && newunit==NULL) {
112 cptr+=2; ifUnknown=0;
114 if(strlen(newunit)>12) {
115 fprintf(stderr,
"Error: unit '%s' too long (>12).\n", newunit);
118 if(strlen(newunit)>0)
continue;
120 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
125 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
130 for(; ai<argc; ai++) {
137 fprintf(stderr,
"Error: missing command-line argument; try %s --help\n",
144 printf(
"imgunit := %s\n", imgunit);
145 printf(
"fileNr := %d\n", fileNr);
146 printf(
"ifUnknown := %d\n", ifUnknown);
147 printf(
"convertUnit := %d\n", convertUnit);
155 for(ai=ffi; ai<argc; ai++) {
157 strcpy(petfile, argv[ai]);
160 if(verbose>1) printf(
"reading %s\n", petfile);
163 fprintf(stderr,
"Warning: %s\n", img.
statmsg);
171 if(verbose>2) printf(
"existing calibration unit := %d\n", img.
unit);
174 if(verbose>2) printf(
"print the unit and do nothing else, as requested\n");
175 fprintf(stdout,
"# filename := %s\n", petfile);
176 fprintf(stdout,
"unit := %s\n", imgunit);
182 if(ifUnknown!=0 && img.
unit!=0 && convertUnit==0) {
183 if(verbose>2) printf(
"unit exists already; do nothing, as requested\n");
185 fprintf(stderr,
"%s : unit '%s' is not replaced\n",
193 if(verbose>2) printf(
"convert concentrations to new units\n");
196 fprintf(stderr,
"%s : cannot convert unknown unit.\n", petfile);
202 fprintf(stderr,
"%s: unit is already %s\n", petfile, newunit);
209 fprintf(stdout,
"%s : unit '%s' converted to '%s'\n",
210 petfile, imgunit, newunit);
213 fprintf(stderr,
"%s: warning: cannot convert unit %s to %s\n",
214 petfile, imgunit, newunit);
218 if(verbose>2) printf(
"set the unit but keep the concentrations\n");
222 fprintf(stdout,
"%s : unit '%s' replaced by '%s'\n",
223 petfile, imgunit, newunit);
226 fprintf(stderr,
"%s: warning: cannot set unit.\n", petfile);
232 if(verbose>0) printf(
"Writing image file %s\n", petfile);
234 fprintf(stderr,
"Error: %s\n", img.
statmsg);
241 fprintf(stderr,
"Error: no file(s) could be processed.\n");
void imgEmpty(IMG *image)
int imgConvertUnit(IMG *img, char *unit)
int imgRead(const char *fname, IMG *img)
int imgWrite(const char *fname, IMG *img)
int imgSetUnit(IMG *img, char *unit)
char * imgUnit(int dunit)
int imgUnitId(char *unit)
Header file for libtpcimgio.
Header file for libtpcimgp.
Header file for libtpcmisc.
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)