TPCCLIB
Loading...
Searching...
No Matches
upet2e7.c
Go to the documentation of this file.
1
7/*****************************************************************************/
8#include "tpcclibConfig.h"
9/*****************************************************************************/
10#include <stdio.h>
11#include <stdlib.h>
12#include <math.h>
13#include <string.h>
14#include <time.h>
15#include <unistd.h>
16/*****************************************************************************/
17#include "libtpcmisc.h"
18#include "libtpcimgio.h"
19#include "libtpcimgp.h"
20/*****************************************************************************/
21
22/*****************************************************************************/
23static char *info[] = {
24 "Conversion of Siemens Inveon/MicroPET CT or PET image to ECAT 7",
25 "image volume format.",
26 "MicroPET image consists of two files with extension .img and img.hdr;",
27 "both are required in conversion.",
28 "Note that also Analyze and dual file format NIfTI images consist",
29 "of equally named two files.",
30 " ",
31 "Usage: @P [Options] <MicroPET image> [ECAT filename]",
32 " ",
33 "Options:",
34 " -stdoptions", // List standard options like --help, -v, etc
35 " ",
36 "Example:",
37 " @P ae72.pet.img ae72.v",
38 " ",
39 "See also: upet2sif, nii2ecat, ana2ecat, flat2img, img2flat",
40 " ",
41 "Keywords: image, format conversion, MicroPET, Inveon",
42 0};
43/*****************************************************************************/
44
45/*****************************************************************************/
46/* Turn on the globbing of the command line, since it is disabled by default in
47 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
48 In Unix&Linux wildcard command line processing is enabled by default. */
49/*
50#undef _CRT_glob
51#define _CRT_glob -1
52*/
53int _dowildcard = -1;
54/*****************************************************************************/
55
56/*****************************************************************************/
60int main(int argc, char *argv[])
61{
62 int ai, help=0, version=0, verbose=1;
63 char *cptr;
64 char ecatfile[FILENAME_MAX], upetname[FILENAME_MAX];
65 int ret;
66
67
68 /*
69 * Get arguments
70 */
71 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
72 upetname[0]=ecatfile[0]=(char)0;
73 /* Options */
74 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') { /* options */
75 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
76 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
77 fprintf(stderr, "Error: invalid option '%s'\n", argv[ai]);
78 return(1);
79 } else break;
80
81 /* Print help or version? */
82 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
83 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
84 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
85
86 /* Process other arguments, starting from the first non-option */
87 if(ai<argc) {strlcpy(upetname, argv[ai++], FILENAME_MAX);}
88 if(ai<argc) {strlcpy(ecatfile, argv[ai++], FILENAME_MAX);}
89 if(ai<argc) {fprintf(stderr, "Error: too many arguments.\n"); return(1);}
90
91 /* Did we get all the information that we need? */
92 if(!upetname[0]) {
93 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
94 return(1);
95 }
96
97 /* In verbose mode print options */
98 if(verbose>1) {
99 printf("upetname := %s\n", upetname);
100 if(ecatfile[0]) printf("ecatfile := %s\n", ecatfile);
101 fflush(stdout);
102 }
103
104 /*
105 * Make sure that we have the header and image files
106 */
107 char upetheader[FILENAME_MAX], upetimage[FILENAME_MAX];
108 ret=upetExists(upetname, upetheader, upetimage, verbose-1);
109 if(ret<1) {
110 fprintf(stderr, "Error: %s does not exist or is not Inveon/MicroPET image.\n",
111 upetname);
112 return(2);
113 } else if(ret<2) {
114 fprintf(stderr, "Error: Inveon/MicroPET image %s not found.\n",
115 upetname);
116 return(2);
117 }
118 if(verbose>1) {
119 printf("upetheader := %s\n", upetheader);
120 printf("upetimage := %s\n", upetimage);
121 fflush(stdout);
122 }
123 /* Make ECAT filename, if not given by user */
124 if(!ecatfile[0]) {
125 strcpy(ecatfile, upetimage);
126 cptr=strrchr(ecatfile, '.');
127 if(cptr!=NULL) {
128 if(strncasecmp(cptr, ".IMG", 4)==0) *cptr=(char)0;
129 }
130 strcat(ecatfile, ".v");
131 if(verbose>1) printf("ecatfile := %s\n", ecatfile);
132 }
133
134 /*
135 * Convert image
136 */
137 if(verbose>0) {
138 fprintf(stdout, " converting %s ...\n", upetname);
139 fflush(stdout);
140 }
141 ret=imgMicropetToEcat7(upetname, ecatfile, verbose-1);
142 if(ret!=STATUS_OK) {
143 fprintf(stderr, "Error: %s\n", imgStatus(ret));
144 return(11);
145 }
146 if(verbose>0) {
147 fprintf(stdout, " Image saved in ECAT format in %s\n", ecatfile);
148 fflush(stdout);
149 }
150
151 return(0);
152}
153/*****************************************************************************/
154
155/*****************************************************************************/
char * imgStatus(int status_index)
Definition img.c:330
int imgMicropetToEcat7(char *upetname, char *ecatfile, int verbose)
Definition img_upet.c:15
Header file for libtpcimgio.
int upetExists(const char *upetname, char *hdrfile, char *imgfile, int verbose)
Definition micropet.c:86
Header file for libtpcimgp.
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition strext.c:245
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:213
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:383
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:158