TPCCLIB
Loading...
Searching...
No Matches
lshdr.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 <unistd.h>
15#include <time.h>
16/*****************************************************************************/
17#include "libtpcmisc.h"
18#include "libtpcimgio.h"
19/*****************************************************************************/
20
21/*****************************************************************************/
22static char *info[] = {
23 "List the subheader(s) of an ECAT 6 or 7 file.",
24 " ",
25 "Usage: @P [Options] ecatfile",
26 " ",
27 "Options:",
28 " -plane=<plane>",
29 " List only specified plane; by default all planes in 2D data.",
30 " -frame=<frame>",
31 " List only specified frame; by default all frames.",
32 " -stdoptions", // List standard options like --help, -v, etc
33 " ",
34 "Example:",
35 " @P -frame=1 s2345dy1.img",
36 " ",
37 "See also: lmhdr, lmlist, eframe, egetstrt, imgunit, e7evhdr",
38 " ",
39 "Keywords: ECAT, header",
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 int ret;
62 int frame=-1, plane=-1;
63 char *cptr, ecatfile[FILENAME_MAX];
64 FILE *fp;
65 ECAT63_mainheader e6_mainheader;
66 ECAT7_mainheader e7_mainheader;
67 int ecat_format=0; // 6 or 7
68
69
70 /*
71 * Get arguments
72 */
73 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
74 ecatfile[0]=(char)0;
75 /* Options */
76 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') { /* options */
77 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
78 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
79 if(strncasecmp(cptr, "PLANE=", 6)==0) {
80 plane=atoi(cptr+6); if(plane>0) continue;
81 } else if(strncasecmp(cptr, "FRAME=", 6)==0) {
82 frame=atoi(cptr+6); if(frame>0) continue;
83 }
84 fprintf(stderr, "Error: invalid option %s\n", argv[ai]);
85 return(1);
86 } else break;
87
88 /* Print help or version? */
89 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
90 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
91 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
92
93 /* Process other arguments, starting from the first non-option */
94 for(; ai<argc; ai++) {
95 if(!ecatfile[0]) {
96 strcpy(ecatfile, argv[ai]); continue;
97 } else if(frame<0) {
98 frame=atoi(argv[ai]); if(frame>0) continue;
99 } else if(plane<0) {
100 plane=atoi(argv[ai]); if(plane>0) continue;
101 }
102 fprintf(stderr, "Error: invalid argument '%s'\n", argv[ai]);
103 return(1);
104 }
105
106
107 /* Is something missing? */
108 if(!ecatfile[0]) {
109 fprintf(stderr, "Error: missing command-line argument; try %s --help\n", argv[0]);
110 return(1);
111 }
112
113
114 /* In verbose mode print arguments and options */
115 if(verbose>1) {
116 printf("ecatfile := %s\n", ecatfile);
117 printf("plane := %d\n", plane);
118 printf("frame := %d\n", frame);
119 }
120
121 if(verbose>2) ECAT7_TEST=ECAT63_TEST=verbose-2;
122
123
124 /*
125 * Open ECAT file
126 */
127 if((fp=fopen(ecatfile, "rb")) == NULL) {
128 fprintf(stderr, "Error: cannot read file %s\n", ecatfile);
129 return(2);
130 }
131
132 /*
133 * Read main header
134 */
135 ecat_format=0;
136 /* Try to read ECAT 7.x main header */
137 ret=ecat7ReadMainheader(fp, &e7_mainheader);
138 if(ret) {
139 fprintf(stderr, "Error: unsupported file format (%s)\n", ecatfile);
140 fclose(fp); return(3);
141 }
142 /* If header could be read, check for magic number */
143 if(strncmp(e7_mainheader.magic_number, ECAT7V_MAGICNR, 7)==0) {
144 ecat_format=7;
145 } else { // maybe this is ECAT 6.3
146 ret=ecat63ReadMainheader(fp, &e6_mainheader);
147 if(ret==0) ecat_format=6;
148 }
149 if(ecat_format==0) {
150 fprintf(stderr, "Error: unsupported file format (%s)\n", ecatfile);
151 fclose(fp); return(3);
152 }
153 if(verbose>1) printf("ecat_format := %d\n", ecat_format);
154 if(verbose>5) {
155 if(ecat_format==6)
156 ecat63PrintMainheader(&e6_mainheader, stdout);
157 else
158 ecat7PrintMainheader(&e7_mainheader, stdout);
159 printf("\n");
160 }
161
162
163 /*
164 * Read and print subheaders
165 */
166 if(ecat_format==6) {
167 if(verbose>1) {
168 char tmp[32];
169 if(e6_mainheader.file_type==1) strcpy(tmp, "sinogram");
170 else if(e6_mainheader.file_type==2) strcpy(tmp, "image");
171 else if(e6_mainheader.file_type==3) strcpy(tmp, "attenuation");
172 else if(e6_mainheader.file_type==4) strcpy(tmp, "normalization");
173 else strcpy(tmp, "unknown");
174 fprintf(stdout, "file_type := %d (%s)\n", e6_mainheader.file_type, tmp);
175 }
176 ret=ecat6PrintSubheader(e6_mainheader, fp, plane, frame, stdout);
177 } else {
178 if(verbose>1) fprintf(stdout, "file_type := %d (%s)\n",
179 e7_mainheader.file_type, ecat7filetype(e7_mainheader.file_type) );
180 ret=ecat7PrintSubheader(e7_mainheader, fp, plane, frame, stdout);
181 }
182 fclose(fp);
183 printf("\n");
184
185 return(0);
186}
187/*****************************************************************************/
188
189/*****************************************************************************/
int ECAT63_TEST
Definition ecat63h.c:6
void ecat63PrintMainheader(ECAT63_mainheader *h, FILE *fp)
Definition ecat63p.c:16
int ecat6PrintSubheader(ECAT63_mainheader mh, FILE *fp, int plane, int frame, FILE *ofp)
Definition ecat63p.c:293
int ecat63ReadMainheader(FILE *fp, ECAT63_mainheader *h)
Definition ecat63r.c:25
int ECAT7_TEST
Definition ecat7h.c:6
char * ecat7filetype(short int file_type)
Definition ecat7p.c:447
void ecat7PrintMainheader(ECAT7_mainheader *h, FILE *fp)
Definition ecat7p.c:16
int ecat7PrintSubheader(ECAT7_mainheader mh, FILE *fp, int plane, int frame, FILE *ofp)
Definition ecat7p.c:506
int ecat7ReadMainheader(FILE *fp, ECAT7_mainheader *h)
Definition ecat7r.c:15
Header file for libtpcimgio.
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
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
short int file_type
char magic_number[14]