TPCCLIB
Loading...
Searching...
No Matches
dcmmlist.c
Go to the documentation of this file.
1
8/*****************************************************************************/
9#include "tpcclibConfig.h"
10/*****************************************************************************/
11#include <stdio.h>
12#include <stdlib.h>
13#include <math.h>
14#include <time.h>
15#include <string.h>
16/*****************************************************************************/
17#include "tpcextensions.h"
18#include "tpctac.h"
19#include "tpcdcm.h"
20/*****************************************************************************/
21
22/*****************************************************************************/
23static char *info[] = {
24 "List the matrices of a PET image in DICOM format.",
25 " ",
26 "NOT for production use!",
27 " ",
28 "Usage: @P [-Options] dicomfile",
29 " ",
30 "Options:",
31 " -plane=<Y|n>",
32 " List (y, default) or do not list (n) the plane (slice) number.",
33 " -frame=<Y|n>",
34 " List (y, default) or do not list (n) the frame number.",
35 " -framestart=<Y|n>",
36 " List (y, default) or do not list (n) the frame start time.",
37 " -framedur=<Y|n>",
38 " List (y, default) or do not list (n) the frame duration.",
39 " -acqdate=<y|N>",
40 " List (y) or do not list (n, default) the acquisition date.",
41 " -acqtime=<Y|n>",
42 " List (y, default) or do not list (n) the acquisition time.",
43 " -filename=<Y|n>",
44 " List (y, default) or do not list (n) the file name.",
45 " -stdoptions", // List standard options like --help, -v, etc
46 " ",
47 "See also: dcmlhdr, dcmframe",
48 " ",
49 "Keywords: image, DICOM",
50 0};
51/*****************************************************************************/
52
53/*****************************************************************************/
54/* Turn on the globbing of the command line, since it is disabled by default in
55 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
56 In Unix&Linux wildcard command line processing is enabled by default. */
57/*
58#undef _CRT_glob
59#define _CRT_glob -1
60*/
61int _dowildcard = -1;
62/*****************************************************************************/
63
64/*****************************************************************************/
68int main(int argc, char **argv)
69{
70 int ai, help=0, version=0, verbose=1;
71 char dcmfile[FILENAME_MAX];
72 int ret;
73 int listPlane=1; // 0=no, 1=yes
74 int listFrame=1; // 0=no, 1=yes
75 int listFrameStart=1; // 0=no, 1=yes
76 int listFrameDur=1; // 0=no, 1=yes
77 int listAcqDate=0; // 0=no, 1=yes
78 int listAcqTime=1; // 0=no, 1=yes
79 int listFilename=1; // 0=no, 1=yes
80
81
82 /*
83 * Get arguments
84 */
85 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
86 dcmfile[0]=(char)0;
87 /* Options */
88 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
89 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
90 char *cptr; cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(!*cptr) continue;
91 if(strncasecmp(cptr, "PLANE=", 6)==0) {
92 if((listPlane=tpcYesNo(cptr+6))>=0) continue;
93 } else if(strncasecmp(cptr, "FRAME=", 6)==0) {
94 if((listFrame=tpcYesNo(cptr+6))>=0) continue;
95 } else if(strncasecmp(cptr, "FRAMESTART=", 11)==0) {
96 if((listFrameStart=tpcYesNo(cptr+11))>=0) continue;
97 } else if(strncasecmp(cptr, "FRAMEDUR=", 9)==0) {
98 if((listFrameDur=tpcYesNo(cptr+9))>=0) continue;
99 } else if(strncasecmp(cptr, "ACQDATE=", 8)==0) {
100 if((listAcqDate=tpcYesNo(cptr+8))>=0) continue;
101 } else if(strncasecmp(cptr, "ACQTIME=", 8)==0) {
102 if((listAcqTime=tpcYesNo(cptr+8))>=0) continue;
103 } else if(strncasecmp(cptr, "FILENAME=", 9)==0) {
104 if((listFilename=tpcYesNo(cptr+9))>=0) continue;
105 }
106 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
107 return(1);
108 } else break;
109
110 TPCSTATUS status; statusInit(&status);
111 statusSet(&status, __func__, __FILE__, __LINE__, TPCERROR_OK);
112 status.verbose=verbose-3;
113
114 /* Print help or version? */
115 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
116 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
117 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
118
119 /* Process other arguments, starting from the first non-option */
120 if(ai<argc) strlcpy(dcmfile, argv[ai++], FILENAME_MAX);
121 if(ai<argc) {
122 fprintf(stderr, "Error: invalid argument '%s'.\n", argv[ai]);
123 return(1);
124 }
125 /* Did we get all the information that we need? */
126 if(!dcmfile[0]) {
127 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
128 return(1);
129 }
130
131 /* In verbose mode print arguments and options */
132 if(verbose>1) {
133 printf("dcmfile := %s\n", dcmfile);
134 printf("listPlane := %d\n", listPlane);
135 printf("listFrame := %d\n", listFrame);
136 printf("listFrameStart := %d\n", listFrameStart);
137 printf("listFrameDur := %d\n", listFrameDur);
138 printf("listAcqDate := %d\n", listAcqDate);
139 printf("listAcqTime := %d\n", listAcqTime);
140 printf("listFilename := %d\n", listFilename);
141 }
142
143 /*
144 * Get list of DICOM files belonging to the same image
145 */
146 IFT fl; iftInit(&fl);
147 ret=dcmFileList(dcmfile, &fl, &status);
148 if(ret!=TPCERROR_OK) {
149 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
150 return(2);
151 }
152 if(verbose>1) {printf("fileNr := %d\n", fl.keyNr); fflush(stdout);}
153 if(verbose>6) iftWrite(&fl, stdout, NULL);
154
155 /*
156 * Read matrix list
157 */
158 DCMML ml; dcmmlInit(&ml);
159 ret=dcmMListRead(&fl, &ml, &status);
160 if(ret!=TPCERROR_OK) {
161 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
162 iftFree(&fl); dcmmlFree(&ml); return(3);
163 }
164 /* file list is not needed later */
165 iftFree(&fl);
166
167 /*
168 * Sort the list
169 */
170 dcmmlSortByPlane(&ml, NULL);
171
172 /*
173 * Print matrix list
174 */
175 int col=0;
176 if(listPlane) {if(col>0) {printf("\t");} printf("Plane"); col++;}
177 if(listFrame) {if(col>0) {printf("\t");} printf("Frame"); col++;}
178 if(listFrameStart) {if(col>0) {printf("\t");} printf("Start"); col++;}
179 if(listFrameDur) {if(col>0) {printf("\t");} printf("Dur"); col++;}
180 if(listAcqDate) {if(col>0) {printf("\t");} printf("AcqDate"); col++;}
181 if(listAcqTime) {if(col>0) {printf("\t");} printf("AcqTime"); col++;}
182 if(listFilename) {if(col>0) {printf("\t");} printf("File"); col++;}
183 if(col==0) {
184 fprintf(stderr, "Error: all prints turned off by user.\n");
185 dcmmlFree(&ml); return(1);
186 }
187 printf("\n");
188 for(unsigned int i=0; i<ml.nr; i++) {
189 col=0;
190 if(listPlane) {if(col>0) {printf("\t");} printf("%u", ml.m[i].plane); col++;}
191 if(listFrame) {if(col>0) {printf("\t");} printf("%u", ml.m[i].frame); col++;}
192 if(listFrameStart) {if(col>0) {printf("\t");} printf("%g", ml.m[i].frameStart); col++;}
193 if(listFrameDur) {if(col>0) {printf("\t");} printf("%g", ml.m[i].frameDur); col++;}
194 if(listAcqDate) {if(col>0) {printf("\t");} printf("%s", ml.m[i].acqDate); col++;}
195 if(listAcqTime) {if(col>0) {printf("\t");} printf("%s", ml.m[i].acqTime); col++;}
196 if(listFilename) {if(col>0) {printf("\t");} printf("%s", ml.m[i].filename); col++;}
197 printf("\n");
198 }
199
200
201
202 dcmmlFree(&ml);
203 return(0);
204}
205/*****************************************************************************/
206
207/*****************************************************************************/
int dcmFileList(const char *filename, IFT *ift, TPCSTATUS *status)
List DICOM files belonging to one image.
Definition dcmfile.c:123
int dcmMListRead(IFT *ift, DCMML *ml, TPCSTATUS *status)
Definition dcmmatrix.c:120
void dcmmlInit(DCMML *d)
Definition dcmmatrix.c:54
void dcmmlFree(DCMML *d)
Definition dcmmatrix.c:70
int dcmmlSortByPlane(DCMML *d, TPCSTATUS *status)
Definition dcmmatrix.c:540
void iftFree(IFT *ift)
Definition ift.c:37
void iftInit(IFT *ift)
Definition ift.c:21
int iftWrite(IFT *ift, FILE *fp, TPCSTATUS *status)
Definition iftio.c:98
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:47
int tpcYesNo(const char *s)
Definition proginfo.c:459
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:169
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:339
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:114
void statusInit(TPCSTATUS *s)
Definition statusmsg.c:104
char * errorMsg(tpcerror e)
Definition statusmsg.c:68
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition stringext.c:632
double frameDur
Definition tpcdcm.h:188
unsigned int plane
Definition tpcdcm.h:184
double frameStart
Definition tpcdcm.h:186
char * filename
Definition tpcdcm.h:175
char acqTime[16]
Definition tpcdcm.h:179
char acqDate[16]
Definition tpcdcm.h:177
unsigned int frame
Definition tpcdcm.h:182
DCMMATRIX * m
Definition tpcdcm.h:198
unsigned int nr
Definition tpcdcm.h:194
Definition tpcift.h:43
int keyNr
Definition tpcift.h:47
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
Header file for libtpcdcm.
Header file for library libtpcextensions.
@ TPCERROR_OK
No error.
Header file for library libtpctac.