TPCCLIB
Loading...
Searching...
No Matches
taclist.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 <string.h>
13#include <math.h>
14/*****************************************************************************/
15#include "tpcextensions.h"
16#include "tpcift.h"
17#include "tpctac.h"
18/*****************************************************************************/
19
20/*****************************************************************************/
21static char *info[] = {
22 "List on screen the specified or all TACs of a TAC data file.",
23 "The concentrations are shown, if file contains <5 samples (time frames).",
24 "Accepts at least PMOD, DFT, and SIF formats.",
25 " ",
26 "Usage: @P [options] filename [tacname1 [tacname2...]] [> outputfile]",
27 " ",
28 "Options:",
29 " -nv",
30 " Do not print region volume.",
31 " -nn",
32 " Do not print region name.",
33 " -na",
34 " Activity concentrations are never printed.",
35 " -ift",
36 " Interfile-type print.",
37 " -weights",
38 " List weights with Interfile-type print.",
39 " -stdoptions", // List standard options like --help, -v, etc
40 " ",
41 "Example:",
42 " @P iea345.tac cer",
43 " ",
44 "See also: tacmatch, tacformat, tacren, tacnames, dft2csv, tac2svg, tacsort",
45 " ",
46 "Keywords: TAC, SIF, tool",
47 0};
48/*****************************************************************************/
49
50/*****************************************************************************/
51/* Turn on the globbing of the command line, since it is disabled by default in
52 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
53 In Unix&Linux wildcard command line processing is enabled by default. */
54/*
55#undef _CRT_glob
56#define _CRT_glob -1
57*/
58int _dowildcard = -1;
59/*****************************************************************************/
60
61/*****************************************************************************/
65int main(int argc, char **argv)
66{
67 int ai, help=0, version=0, verbose=1;
68 int ret;
69 int printVol=1, printName=1, printType=0, printAct=1, printWeights=0;
70 char *cptr, tacfile[FILENAME_MAX];
71
72
73
74 /*
75 * Get arguments
76 */
77 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
78 tacfile[0]=(char)0;
79 /* Options */
80 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
81 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
82 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(!*cptr) continue;
83 if(strcasecmp(cptr, "NV")==0) {
84 printVol=0; continue;
85 } else if(strcasecmp(cptr, "NN")==0) {
86 printName=0; continue;
87 } else if(strcasecmp(cptr, "NA")==0) {
88 printAct=0; continue;
89 } else if(strncasecmp(cptr, "WEIGHTS", 1)==0) {
90 printWeights=1; continue;
91 } else if(strcasecmp(cptr, "IFT")==0) {
92 printType=1; continue;
93 }
94 fprintf(stderr, "Error: invalid option '%s'\n", argv[ai]);
95 return(1);
96 } else break; // tac name argument may start with '-'
97
98 /* Print help or version? */
99 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
100 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
101 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
102
103 /* In verbose mode print arguments and options */
104 if(verbose>1) {
105 printf("print_name := %d\n", printName);
106 printf("print_volume := %d\n", printVol);
107 printf("print_value := %d\n", printAct);
108 printf("print_type := %d\n", printType);
109 printf("print_weight := %d\n", printWeights);
110 }
111
112 TPCSTATUS status; statusInit(&status);
113 statusSet(&status, __func__, __FILE__, __LINE__, TPCERROR_OK);
114 status.verbose=verbose-1;
115
116 /* Process other arguments, starting from the first non-option */
117 TAC tac; tacInit(&tac);
118 int n=0, m;
119 for(; ai<argc; ai++) {
120 if(!tacfile[0]) {
121 strlcpy(tacfile, argv[ai], FILENAME_MAX);
122 /* Read TAC file */
123 if(verbose>1) printf("reading %s\n", tacfile);
124 ret=tacRead(&tac, tacfile, &status);
125 if(ret) {
126 fprintf(stderr, "Error (%d): %s\n", ret, errorMsg(status.error));
127 tacFree(&tac); return(2);
128 }
129 if(verbose>0) {
130 printf("fileformat := %s\n", tacFormattxt(tac.format));
131 printf("tacNr := %d\n", tac.tacNr);
132 printf("sampleNr := %d\n", tac.sampleNr);
133 }
134 } else { /* Next parameters are region names; select them */
135 m=tacSelectTACs(&tac, argv[ai], 0, &status);
136 if(verbose>0) printf("%d tac(s) match name '%s'\n", m, argv[ai]);
137 n++;
138 }
139 }
140 /* Check that we got what we need */
141 if(!tacfile[0]) {tpcPrintUsage(argv[0], info, stderr); tacFree(&tac); return(1);}
142 if(printType==0 && printWeights) {
143 fprintf(stderr, "Warning: weights can only be listed in Interfile-style.\n");
144 fflush(stderr);
145 }
146
147 /* If TAC names were specified but none matched, then that is an error */
148 if(n>0 && tacSelectedTACs(&tac)<1) {
149 fprintf(stderr, "Error: specified TAC names were not found.\n");
150 tacFree(&tac); return(3);
151 }
152
153 /* If no tac names were specified, then select all TACs */
154 if(n==0) m=tacSelectTACs(&tac, NULL, 0, &status);
155
156
157 /*
158 * List all selected TACs
159 */
160
161 /* Print title (not in silent mode or when printing IFT) */
162 if(verbose>=0 && printType==0) {
163 printf("Nr\t");
164 if(printName!=0) printf("TAC-name\t");
165 if(printVol!=0) printf("Volume\t");
166 n=5; if(printVol==0) n++;
167 if(printAct!=0 && tac.sampleNr<n) {
168 printf("TAC-values");
169 if(tac.cunit!=UNIT_UNKNOWN) printf("[%s]", unitName(tac.cunit));
170 }
171 printf("\n");
172 }
173
174 /* If SIF out, then print header info */
175 if(printType==1) {
176 iftWrite(&tac.h, stdout, NULL);
177 }
178
179 /* List selected ROIs */
180 for(int ri=0; ri<tac.tacNr; ri++) if(tac.c[ri].sw) {
181 if(printType==0) {
182 printf("%d", ri+1);
183 if(printName) {
184 if(strlen(tac.c[ri].name)>0) printf("\t%s", tac.c[ri].name);
185 else printf("\t--------");
186 }
187 n=5; if(printVol==0) n++;
188 if(printAct!=0 && tac.sampleNr<n) {
189 if(printVol) printf("\t%g", tac.c[ri].size);
190 for(int fi=0; fi<tac.sampleNr; fi++)
191 printf("\t%.3e", tac.c[ri].y[fi]);
192 printf("\n");
193 } else {
194 if(printVol) printf("\t%g\n", tac.c[ri].size);
195 else printf("\n");
196 }
197 } else { /* IFT format */
198 if(printName) printf("tacname[%d] := %s\n", ri+1, tac.c[ri].name);
199 if(printVol) printf("volume[%d] := %g\n", ri+1, tac.c[ri].size);
200 if(printAct!=0) {
201 for(int fi=0; fi<tac.sampleNr; fi++)
202 printf("value[%d][%d] := %g\n", ri+1, fi+1, tac.c[ri].y[fi]);
203 }
204 }
205 }
206 fflush(stdout);
207
208 /* List weights */
209 if(printType!=0 && printWeights) {
210 printf("weights := ");
211 if(tacIsWeighted(&tac)) printf("yes\n"); else printf("no\n");
212 if(tacIsWeighted(&tac)) {
213 for(int fi=0; fi<tac.sampleNr; fi++)
214 printf("weight[%d] := %g\n", fi+1, tac.w[fi]);
215 }
216 fflush(stdout);
217 }
218
219 tacFree(&tac);
220 return(0);
221}
222/*****************************************************************************/
223
224/*****************************************************************************/
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 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
char sw
Definition tpctac.h:77
char name[MAX_TACNAME_LEN+1]
Definition tpctac.h:81
double * y
Definition tpctac.h:75
double size
Definition tpctac.h:71
Definition tpctac.h:87
unit cunit
Definition tpctac.h:105
tacformat format
Definition tpctac.h:93
int sampleNr
Definition tpctac.h:89
IFT h
Optional (but often useful) header information.
Definition tpctac.h:141
double * w
Definition tpctac.h:111
TACC * c
Definition tpctac.h:117
int tacNr
Definition tpctac.h:91
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
void tacFree(TAC *tac)
Definition tac.c:106
void tacInit(TAC *tac)
Definition tac.c:24
int tacRead(TAC *d, const char *fname, TPCSTATUS *status)
Definition tacio.c:413
char * tacFormattxt(tacformat c)
Definition tacio.c:98
int tacSelectedTACs(TAC *d)
Definition tacselect.c:103
int tacSelectTACs(TAC *d, const char *region_name, int reset, TPCSTATUS *status)
Definition tacselect.c:24
int tacIsWeighted(TAC *tac)
Definition tacw.c:24
Header file for library libtpcextensions.
@ UNIT_UNKNOWN
Unknown unit.
@ TPCERROR_OK
No error.
char * unitName(int unit_code)
Definition units.c:143
Header file for library libtpcift.
Header file for library libtpctac.