TPCCLIB
Loading...
Searching...
No Matches
lmlist.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/*****************************************************************************/
16#include "libtpcmisc.h"
17#include "libtpcimgio.h"
18/*****************************************************************************/
19
20/*****************************************************************************/
21static char *info[] = {
22 "List the matrices of an ECAT 6.3 or 7.x file.",
23 " ",
24 "Usage: @P [Options] ecatfile",
25 " ",
26 "Options:",
27 " -stdoptions", // List standard options like --help, -v, etc
28 " ",
29 "Example:",
30 " @P s2345dy1.v",
31 " ",
32 "See also: esplit, efixplnr, imgdim, lmhdr, lshdr, ecat2ana, imgmlist",
33 " ",
34 "Keywords: ECAT, matrixlist, header, tool",
35 0};
36/*****************************************************************************/
37
38/*****************************************************************************/
39/* Turn on the globbing of the command line, since it is disabled by default in
40 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
41 In Unix&Linux wildcard command line processing is enabled by default. */
42/*
43#undef _CRT_glob
44#define _CRT_glob -1
45*/
46int _dowildcard = -1;
47/*****************************************************************************/
48
49/*****************************************************************************/
53int main(int argc, char **argv)
54{
55 int ai, help=0, version=0, verbose=1;
56 int ret;
57 char *cptr, ecatfile[FILENAME_MAX];
58 FILE *fp;
59 int ecat_format=0; // 6 or 7
60 ECAT63_mainheader e6_mainheader;
61 ECAT7_mainheader e7_mainheader;
62 static MATRIXLIST e6_mlist;
63 static ECAT7_MATRIXLIST e7_mlist;
64
65
66 /*
67 * Get arguments
68 */
69 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
70 ecatfile[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 for(; ai<argc; ai++) {
86 if(!ecatfile[0]) {
87 strcpy(ecatfile, argv[ai]); continue;
88 }
89 fprintf(stderr, "Error: invalid argument '%s'\n", argv[ai]);
90 return(1);
91 }
92
93 /* Is something missing? */
94 if(!ecatfile[0]) {
95 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
96 return(1);
97 }
98
99
100 /* In verbose mode print arguments and options */
101 if(verbose>1) {
102 printf("ecatfile := %s\n", ecatfile);
103 }
104
105
106 /*
107 * Open ECAT file
108 */
109 if((fp=fopen(ecatfile, "rb")) == NULL) {
110 fprintf(stderr, "Error: cannot read file %s\n", ecatfile);
111 return(2);
112 }
113
114
115 /*
116 * Read main header
117 */
118 ecat_format=0;
119 /* Try to read ECAT 7.x main header */
120 ret=ecat7ReadMainheader(fp, &e7_mainheader);
121 if(ret) {
122 fprintf(stderr, "Error: unsupported file format (%s)\n", ecatfile);
123 fclose(fp); return(3);
124 }
125 /* If header could be read, check for magic number */
126 if(strncmp(e7_mainheader.magic_number, ECAT7V_MAGICNR, 7)==0) {
127 ecat_format=7;
128 } else { // maybe this is ECAT 6.3
129 ret=ecat63ReadMainheader(fp, &e6_mainheader);
130 if(ret==0) ecat_format=6;
131 }
132 if(ecat_format==0) {
133 fprintf(stderr, "Error: unsupported file format (%s)\n", ecatfile);
134 fclose(fp); return(3);
135 }
136 if(verbose>1) printf("ecat_format := %d\n", ecat_format);
137 if(verbose>5) {
138 if(ecat_format==6)
139 ecat63PrintMainheader(&e6_mainheader, stdout);
140 else
141 ecat7PrintMainheader(&e7_mainheader, stdout);
142 printf("\n");
143 }
144
145 /*
146 * Read matrix list
147 */
148 if(ecat_format==6) {
149 ecat63InitMatlist(&e6_mlist);
150 ret=ecat63ReadMatlist(fp, &e6_mlist, verbose-1);
151 if(ret) {
152 fprintf(stderr, "Error (%d): cannot read matrix list.\n", ret);
153 fclose(fp); return 3;
154 }
155 if(e6_mlist.matrixNr<=0) {
156 fprintf(stderr, "Error: matrix list is empty.\n");
157 fclose(fp); return 3;
158 }
159 } else {
160 ecat7InitMatlist(&e7_mlist);
161 ret=ecat7ReadMatlist(fp, &e7_mlist, verbose-1);
162 if(ret) {
163 fprintf(stderr, "Error (%d): cannot read matrix list.\n", ret);
164 fclose(fp); return(4);
165 }
166 if(e7_mlist.matrixNr<=0) {
167 fprintf(stderr, "Error: matrix list is empty.\n");
168 fclose(fp); return(4);
169 }
170 }
171
172 /*
173 * Close ECAT file
174 */
175 fclose(fp);
176
177 /*
178 * Print matrix list, and free memory
179 */
180 if(ecat_format==6) {
181 ecat63PrintMatlist(&e6_mlist);
182 ecat63EmptyMatlist(&e6_mlist);
183 } else {
184 ecat7PrintMatlist(&e7_mlist);
185 ecat7EmptyMatlist(&e7_mlist);
186 }
187 printf("\n");
188
189 return(0);
190}
191/*****************************************************************************/
192
193/*****************************************************************************/
int ecat63ReadMatlist(FILE *fp, MATRIXLIST *ml, int verbose)
Definition ecat63ml.c:46
void ecat63InitMatlist(MATRIXLIST *mlist)
Definition ecat63ml.c:20
void ecat63EmptyMatlist(MATRIXLIST *mlist)
Definition ecat63ml.c:31
void ecat63PrintMatlist(MATRIXLIST *ml)
Definition ecat63ml.c:130
void ecat63PrintMainheader(ECAT63_mainheader *h, FILE *fp)
Definition ecat63p.c:16
int ecat63ReadMainheader(FILE *fp, ECAT63_mainheader *h)
Definition ecat63r.c:25
void ecat7InitMatlist(ECAT7_MATRIXLIST *mlist)
Definition ecat7ml.c:15
int ecat7ReadMatlist(FILE *fp, ECAT7_MATRIXLIST *ml, int verbose)
Definition ecat7ml.c:41
void ecat7EmptyMatlist(ECAT7_MATRIXLIST *mlist)
Definition ecat7ml.c:26
void ecat7PrintMatlist(ECAT7_MATRIXLIST *ml)
Definition ecat7ml.c:112
void ecat7PrintMainheader(ECAT7_mainheader *h, FILE *fp)
Definition ecat7p.c:16
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
char magic_number[14]