TPCCLIB
Loading...
Searching...
No Matches
siflist.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 <string.h>
15#include <unistd.h>
16#include <time.h>
17/*****************************************************************************/
18#include "libtpcmisc.h"
19#include "libtpcimgio.h"
20/*****************************************************************************/
21
22/*****************************************************************************/
23static char *info[] = {
24 "Lists the information in a SIF file.",
25 " ",
26 "Usage: @P [Options] sif",
27 " ",
28 "Options:",
29 " -i=<Br76|Cu62|C11|Ga68|Ge68|F18|N13|O15|Rb2>",
30 " Isotope, in case it is needed but not given inside SIF file.",
31 " -decay=<corrected|non-corrected>",
32 " Weights are calculated for TACs corrected or non-corrected (default)",
33 " for physical decay.",
34 " -stdoptions", // List standard options like --help, -v, etc
35 " ",
36 "See also: sifisot, sifcat, eframe, tacframe, tacformat, taclist, tacweigh",
37 " ",
38 "Keywords: image, SIF, time, head-curve",
39 0};
40/*****************************************************************************/
41
42/*****************************************************************************/
43/* Turn on the globbing of the command line, since it is disabled by default in
44 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
45 In Unix&Linux wildcard command line processing is enabled by default. */
46/*
47#undef _CRT_glob
48#define _CRT_glob -1
49*/
50int _dowildcard = -1;
51/*****************************************************************************/
52
53/*****************************************************************************/
57int main(int argc, char **argv)
58{
59 int ai, help=0, version=0, verbose=1;
60 int ret, decay_corrected=0;
61 char *cptr, siffile[FILENAME_MAX];
62 double halflife=-1.0;
63
64
65 /*
66 * Get arguments
67 */
68 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
69 siffile[0]=(char)0;
70 /* Options */
71 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') { /* options */
72 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
73 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
74 if(strncasecmp(cptr, "I=", 2)==0) {
75 cptr+=2; halflife=60.*hlFromIsotope(cptr); if(halflife>0.0) continue;
76 } else if(strncasecmp(cptr, "DECAY=", 6)==0) {
77 cptr+=6;
78 if(strncasecmp(cptr, "C", 1)==0 || strncasecmp(cptr, "Y", 1)==0) {
79 decay_corrected=1; continue;}
80 else if(strncasecmp(cptr, "N", 1)==0) {decay_corrected=0; continue;}
81 }
82 /* We should not be here */
83 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
84 return(1);
85 } else break;
86
87 /* Print help or version? */
88 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
89 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
90 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
91
92 /* Process other arguments, starting from the first non-option */
93 if(ai<argc) {strlcpy(siffile, argv[ai], FILENAME_MAX); ai++;}
94 if(ai<argc) {fprintf(stderr, "Error: too many arguments.\n"); return(1);}
95
96 /* Is something missing or wrong? */
97 if(!siffile[0]) {
98 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
99 return(1);
100 }
101
102 /* In verbose mode print arguments and options */
103 if(verbose>1) {
104 printf("siffile := %s\n", siffile);
105 printf("decay_corrected := %d\n", decay_corrected);
106 if(halflife>0) printf("halflife := %g\n", halflife);
107 }
108
109
110 /*
111 * Read sif file
112 */
113 if(verbose>1) printf("reading file %s\n", siffile);
114 if(verbose>2) SIF_TEST=1;
115 SIF sif; sifInit(&sif);
116 ret=sifRead(siffile, &sif);
117 if(ret) {
118 fprintf(stderr, "Error (%d) in reading '%s': %s\n", ret, siffile, siferrmsg);
119 sifEmpty(&sif);
120 return(2);
121 }
122 /* Get halflife from SIF file, if available */
123 if(halflife<0.0 && strlen(sif.isotope_name)>0) {
124 halflife=60.*hlFromIsotope(sif.isotope_name);
125 if(verbose>1) printf("halflife := %g\n", halflife);
126 }
127
128
129 /*
130 * Calculate SIF weights
131 */
132 if(sif.colNr>2) {
133 if(verbose>1) printf("calculating weights\n");
134 /* If weights are calculated for decay corrected TACs, then check that
135 we have the halflife */
136 if(decay_corrected!=0 && halflife<=0.0) {
137 fprintf(stderr, "Error: isotope is required for decay correction.\n");
138 sifEmpty(&sif); return(3);
139 }
140 /* If weights are calculated for TACs not corrected for decay, then
141 set halflife=0 */
142 if(decay_corrected==0) halflife=0.0;
143 sifWeight(&sif, halflife);
144 }
145 if(verbose>2) printf("halflife := %g\n", halflife);
146
147
148 /*
149 * Print SIF data
150 */
151 if(verbose>10) printf("printing SIF contents\n");
152 sifPrint(&sif);
153
154
155 /*
156 * Free memory
157 */
158 if(verbose>10) printf("exiting\n");
159 sifEmpty(&sif);
160
161 return(0);
162}
163/*****************************************************************************/
164
165/*****************************************************************************/
double hlFromIsotope(char *isocode)
Definition halflife.c:55
Header file for libtpcimgio.
void sifInit(SIF *data)
Definition sif.c:17
int SIF_TEST
Definition sif.c:6
void sifPrint(SIF *data)
Definition sifio.c:234
void sifWeight(SIF *data, double halflife)
Calculate weights for frames in SIF data based on true counts. Weights are normalized to have an aver...
Definition weight.c:28
void sifEmpty(SIF *data)
Definition sif.c:33
int sifRead(char *filename, SIF *data)
Definition sifio.c:21
char siferrmsg[128]
Definition sif.c:7
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
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 isotope_name[8]
int colNr