TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcimage
imagesif.c
Go to the documentation of this file.
1
6
/*****************************************************************************/
7
#include "tpcclibConfig.h"
8
/*****************************************************************************/
9
#include "
tpcimage.h
"
10
/*****************************************************************************/
11
12
/*****************************************************************************/
18
int
imgToSIF
(
20
IMG
*img,
25
TAC
*sif,
27
int
copy_header,
29
int
copy_frames,
32
int
copy_counts,
34
int
verbose
35
) {
36
if
(verbose>0) {
37
printf(
"%s(img, sif, %d, %d, %d, ...)\n"
, __func__, copy_header, copy_frames, copy_counts);
38
fflush(stdout);
39
}
40
41
if
(img==NULL || sif==NULL)
return
(
TPCERROR_FAIL
);
42
43
/* Verify that IMG contains frame times */
44
if
(!
imgHasTimes
(img)) {
45
if
(verbose>0) printf(
" image does not contain frame times.\n"
);
46
/* If not, then frame times cannot be copied */
47
copy_frames=0;
48
/* and counts can not be created */
49
if
(copy_counts==2) copy_counts=1;
50
}
51
52
/* Check if count data needs to be created */
53
if
(copy_counts==2 &&
imgHasCounts
(img)!=0) copy_counts=1;
54
55
/* Verify that IMG contains isotope information */
56
if
(img->
isot
==
ISOTOPE_UNKNOWN
) {
57
if
(verbose>0) printf(
" image does not contain isotope halflife.\n"
);
58
/* not, then count data can not be created */
59
if
(copy_counts==2) copy_counts=1;
60
}
61
62
/* Allocate memory for SIF if necessary */
63
int
ret=0;
64
if
(sif->
sampleNr
<1 || sif->
tacNr
<1) {
65
ret=
tacAllocate
(sif, img->
dimt
, 2);
66
sif->
sampleNr
=img->
dimt
; sif->
tacNr
=2;
67
}
else
if
((copy_frames || copy_counts) && sif->
sampleNr
!=img->
dimt
) {
68
if
(sif->
sampleNr
<img->
dimt
)
69
ret=
tacAllocateMoreSamples
(sif, img->
dimt
-sif->
sampleNr
);
70
sif->
sampleNr
=img->
dimt
;
71
}
72
if
((copy_frames || copy_counts) && sif->
tacNr
<2) {
73
ret=
tacAllocateMore
(sif, 2-sif->
tacNr
);
74
sif->
tacNr
=2;
75
}
76
if
(ret!=0)
return
(
TPCERROR_OUT_OF_MEMORY
);
77
78
/* Copy SIF header */
79
if
(copy_header) {
80
if
(verbose>1) printf(
" copying header fields.\n"
);
81
tacSetHeaderScanstarttime
(&sif->
h
, img->
scanStart
);
82
tacSetHeaderStudynr
(&sif->
h
, img->
studyNr
);
83
tacSetIsotope
(sif, img->
isot
);
84
}
85
86
/* Copy frame times */
87
if
(copy_frames) {
88
if
(verbose>1) printf(
" copying frame times.\n"
);
89
for
(
int
i=0; i<img->
dimt
; i++) {
90
sif->
x1
[i]=img->
x1
[i]; sif->
x2
[i]=img->
x2
[i]; sif->
x
[i]=img->
x
[i];
91
}
92
sif->
tunit
=
UNIT_SEC
;
93
}
94
95
/* Copy counts */
96
if
(copy_counts==1) {
97
if
(verbose>1) printf(
" copying count data.\n"
);
98
for
(
int
i=0; i<img->
dimt
; i++) {
99
sif->
c
[0].
y
[i]=img->
prompts
[i];
100
sif->
c
[1].
y
[i]=img->
randoms
[i];
101
}
102
}
103
104
/* Create counts, if required and possible */
105
if
(copy_counts==2) {
106
if
(verbose>1) printf(
" creating count data.\n"
);
107
108
fprintf(stderr,
"Warning: imgToSIF() does not yet guess counts.\n"
); fflush(stderr);
109
110
for
(
int
i=0; i<img->
dimt
; i++) {
111
sif->
c
[0].
y
[i]=0.0;
112
sif->
c
[1].
y
[i]=0.0;
113
}
114
}
115
116
return
(
TPCERROR_OK
);
117
}
118
/*****************************************************************************/
119
120
/*****************************************************************************/
126
int
imgFromSIF
(
128
IMG
*img,
130
TAC
*sif,
132
int
copy_header,
134
int
copy_frames,
136
int
copy_counts,
138
int
verbose
139
) {
140
if
(verbose>0) {
141
printf(
"%s(img, sif, %d, %d, %d, ...)\n"
, __func__, copy_header, copy_frames, copy_counts);
142
fflush(stdout);
143
}
144
145
if
(sif==NULL || img==NULL)
return
(
TPCERROR_FAIL
);
146
147
if
(copy_header) {
148
if
(verbose>1) printf(
" copying header.\n"
);
149
int
ret=
tacGetHeaderScanstarttime
(&sif->
h
, img->
scanStart
, NULL);
150
if
(ret!=
TPCERROR_OK
&& verbose>0) fprintf(stderr,
"Warning: cannot read scan start time in SIF\n"
);
151
img->
isot
=
tacGetIsotope
(sif);
152
if
(img->
isot
==
ISOTOPE_UNKNOWN
&& verbose>0) fprintf(stderr,
"Warning: cannot read isotope in SIF\n"
);
153
ret=
tacGetHeaderStudynr
(&sif->
h
, img->
studyNr
, NULL);
154
}
155
156
if
(copy_frames) {
157
if
(verbose>1) printf(
" copying frame times.\n"
);
158
if
(!sif->
isframe
|| sif->
sampleNr
!=img->
dimt
)
return
(
TPCERROR_INVALID_FORMAT
);
159
for
(
int
fi=0; fi<img->
dimt
; fi++) {
160
img->
x1
[fi]=sif->
x1
[fi];
161
img->
x2
[fi]=sif->
x2
[fi];
162
img->
x
[fi]=0.5*(img->
x1
[fi]+img->
x2
[fi]);
163
}
164
img->
tunit
=sif->
tunit
;
165
}
166
167
if
(copy_counts) {
168
if
(verbose>1) printf(
" copying count data.\n"
);
169
if
(sif->
format
!=
TAC_FORMAT_SIF
|| !sif->
isframe
|| sif->
sampleNr
!=img->
dimt
)
170
return
(
TPCERROR_INVALID_FORMAT
);
171
if
(sif->
tacNr
<4)
return
(
TPCERROR_INVALID_FORMAT
);
172
for
(
int
fi=0; fi<img->
dimt
; fi++) {
173
img->
prompts
[fi]=sif->
c
[0].
y
[fi];
174
img->
randoms
[fi]=sif->
c
[1].
y
[fi];
175
}
176
img->
weighting
=
WEIGHTING_OFF
;
177
if
(sif->
weighting
!=
WEIGHTING_OFF
&& sif->
weighting
!=
WEIGHTING_UNKNOWN
) {
178
for
(
int
fi=0; fi<img->
dimt
; fi++)
179
img->
weight
[fi]=sif->
w
[fi];
180
img->
weighting
=sif->
weighting
;
181
}
182
}
183
184
return
(
TPCERROR_OK
);
185
}
186
/*****************************************************************************/
187
188
/*****************************************************************************/
imgHasTimes
int imgHasTimes(IMG *img)
Definition
image.c:235
imgHasCounts
int imgHasCounts(IMG *img)
Definition
image.c:251
imgToSIF
int imgToSIF(IMG *img, TAC *sif, int copy_header, int copy_frames, int copy_counts, int verbose)
Definition
imagesif.c:18
imgFromSIF
int imgFromSIF(IMG *img, TAC *sif, int copy_header, int copy_frames, int copy_counts, int verbose)
Definition
imagesif.c:126
IMG
Definition
tpcimage.h:82
IMG::x1
float * x1
Definition
tpcimage.h:180
IMG::x2
float * x2
Definition
tpcimage.h:182
IMG::prompts
float * prompts
Definition
tpcimage.h:195
IMG::dimt
unsigned short int dimt
Definition
tpcimage.h:110
IMG::weight
float * weight
Definition
tpcimage.h:193
IMG::weighting
weights weighting
Definition
tpcimage.h:191
IMG::scanStart
char scanStart[20]
Definition
tpcimage.h:94
IMG::x
float * x
Definition
tpcimage.h:184
IMG::studyNr
char studyNr[MAX_STUDYNR_LEN+1]
Definition
tpcimage.h:85
IMG::randoms
float * randoms
Definition
tpcimage.h:197
IMG::isot
isotope isot
Definition
tpcimage.h:88
IMG::tunit
unit tunit
Definition
tpcimage.h:205
TACC::y
double * y
Definition
tpctac.h:75
TAC
Definition
tpctac.h:87
TAC::x
double * x
Definition
tpctac.h:97
TAC::format
tacformat format
Definition
tpctac.h:93
TAC::sampleNr
int sampleNr
Definition
tpctac.h:89
TAC::h
IFT h
Optional (but often useful) header information.
Definition
tpctac.h:141
TAC::w
double * w
Definition
tpctac.h:111
TAC::isframe
int isframe
Definition
tpctac.h:95
TAC::c
TACC * c
Definition
tpctac.h:117
TAC::weighting
weights weighting
Definition
tpctac.h:115
TAC::x2
double * x2
Definition
tpctac.h:101
TAC::tunit
unit tunit
Definition
tpctac.h:109
TAC::x1
double * x1
Definition
tpctac.h:99
TAC::tacNr
int tacNr
Definition
tpctac.h:91
tacAllocate
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
Definition
tac.c:130
tacAllocateMoreSamples
int tacAllocateMoreSamples(TAC *tac, int addNr)
Allocate memory for more samples in TAC data.
Definition
tac.c:435
tacAllocateMore
int tacAllocateMore(TAC *tac, int tacNr)
Definition
tac.c:178
tacGetIsotope
int tacGetIsotope(TAC *tac)
Definition
tacdc.c:25
tacSetIsotope
void tacSetIsotope(TAC *tac, int isotope)
Definition
tacdc.c:41
tacSetHeaderScanstarttime
int tacSetHeaderScanstarttime(IFT *h, const char *s)
Definition
tacift.c:427
tacGetHeaderScanstarttime
int tacGetHeaderScanstarttime(IFT *h, char *s, TPCSTATUS *status)
Definition
tacift.c:372
tacGetHeaderStudynr
int tacGetHeaderStudynr(IFT *h, char *s, TPCSTATUS *status)
Definition
tacift.c:26
tacSetHeaderStudynr
int tacSetHeaderStudynr(IFT *h, const char *s)
Definition
tacift.c:79
WEIGHTING_OFF
@ WEIGHTING_OFF
Not weighted or weights not available (weights for all included samples are 1.0).
Definition
tpcextensions.h:54
WEIGHTING_UNKNOWN
@ WEIGHTING_UNKNOWN
Not known; usually assumed that not weighted.
Definition
tpcextensions.h:53
UNIT_SEC
@ UNIT_SEC
seconds
Definition
tpcextensions.h:89
TPCERROR_FAIL
@ TPCERROR_FAIL
General error.
Definition
tpcextensions.h:192
TPCERROR_INVALID_FORMAT
@ TPCERROR_INVALID_FORMAT
Invalid file format.
Definition
tpcextensions.h:201
TPCERROR_OUT_OF_MEMORY
@ TPCERROR_OUT_OF_MEMORY
Cannot allocate memory.
Definition
tpcextensions.h:193
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
tpcimage.h
Header file for libtpcimage.
ISOTOPE_UNKNOWN
@ ISOTOPE_UNKNOWN
Unknown.
Definition
tpcisotope.h:51
TAC_FORMAT_SIF
@ TAC_FORMAT_SIF
Scan information file.
Definition
tpctac.h:43
Generated on
for TPCCLIB by
1.17.0