TPCCLIB
Loading...
Searching...
No Matches
upet2sif.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 "Constructs a scan information file (SIF) from Siemens Inveon/microPET",
25 "image header.",
26 "MicroPET image consists of two files with extension .img and .img.hdr;",
27 "only header file is needed here.",
28 " ",
29 "Usage: @P [Options] <MicroPET header file> <SIF filename>",
30 " ",
31 "Options:",
32 " -stdoptions", // List standard options like --help, -v, etc
33 " ",
34 "Example:",
35 " @P ae72.pet.img.hdr ae72.sif",
36 " ",
37 "See also: upet2e7, tacframe, tacweigh, eframe, sifcat, sifisot",
38 " ",
39 "Keywords: SIF, image, time, MicroPET, Inveon",
40 0};
41/*****************************************************************************/
42
43/*****************************************************************************/
44/* Turn on the globbing of the command line, since it is disabled by default in
45 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
46 In Unix&Linux wildcard command line processing is enabled by default. */
47/*
48#undef _CRT_glob
49#define _CRT_glob -1
50*/
51int _dowildcard = -1;
52/*****************************************************************************/
53
54/*****************************************************************************/
58int main(int argc, char *argv[])
59{
60 int ai, help=0, version=0, verbose=1;
61 char *cptr, upetheader[FILENAME_MAX];
62 char siffile[FILENAME_MAX], upetname[FILENAME_MAX];
63
64
65
66 /*
67 * Get arguments
68 */
69 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
70 upetname[0]=siffile[0]=upetheader[0]=(char)0;
71 /* Options */
72 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') { /* options */
73 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
74 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
75 fprintf(stderr, "Error: invalid option '%s'\n", argv[ai]);
76 return(1);
77 } else break;
78
79 /* Print help or version? */
80 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
81 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
82 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
83
84 /* Process other arguments, starting from the first non-option */
85 if(ai<argc) {strlcpy(upetname, argv[ai++], FILENAME_MAX);}
86 if(ai<argc) {strlcpy(siffile, argv[ai++], FILENAME_MAX);}
87 if(ai<argc) {fprintf(stderr, "Error: too many arguments.\n"); return(1);}
88
89 /* Did we get all the information that we need? */
90 if(!siffile[0]) {
91 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
92 return(1);
93 }
94
95 /* In verbose mode print options */
96 if(verbose>1) {
97 printf("upetname := %s\n", upetname);
98 printf("siffile := %s\n", siffile);
99 fflush(stdout);
100 }
101
102 /*
103 * Make sure that we have the header file name
104 */
105 if(upetExists(upetname, upetheader, NULL, verbose-1)<1) {
106 fprintf(stderr, "Error: %s does not exist or is not Inveon/MicroPET header.\n",
107 upetname);
108 return(2);
109 }
110
111
112 /*
113 * Open Micropet Header
114 */
115 FILE *fp;
116 if((fp=fopen(upetheader, "r"))==NULL) {
117 fprintf(stderr, "Error: cannot open %s for reading.\n", upetheader);
118 return(3);
119 }
120
121 /*
122 * Read SIF
123 */
124 SIF sif; sifInit(&sif);
125 if(verbose>1) printf("reading scan information for SIF\n");
126 if(imgGetMicropetSIF(fp, &sif)!=0) {
127 fprintf(stderr, "Error: non-supported header file %s.\n", upetheader);
128 fclose(fp);
129 return(4);
130 }
131 /* Close header file */
132 fclose(fp);
133
134 /* Set study number */
135 studynr_from_fname2(upetname, sif.studynr, 0);
136 //studynr_in_fname(upetname, sif.studynr);
137
138 /*
139 * Write SIF
140 */
141 if(sifWrite(&sif, siffile)!=0) {
142 fprintf(stderr, "Error: cannot write %s.\n", siffile);
143 return(11);
144 }
145 if(verbose>0) fprintf(stdout, "SIF saved in %s\n", siffile);
146
147 return(0);
148}
149/*****************************************************************************/
150
151/*****************************************************************************/
int imgGetMicropetSIF(FILE *fp, SIF *sif)
Definition img_upet.c:517
Header file for libtpcimgio.
int sifWrite(SIF *data, char *filename)
Definition sifio.c:145
void sifInit(SIF *data)
Definition sif.c:17
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
int studynr_from_fname2(char *fname, char *studynr, int force)
Definition studynr.c:67
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
char studynr[MAX_STUDYNR_LEN+1]