Main Page
Related Pages
Data Structures
Files
File List
Globals
imgunit.c
Go to the documentation of this file.
1
/******************************************************************************
2
3
Copyright (c) 2006-2011 Turku PET Centre
4
5
Library: imgunit
6
Description: Functions for setting image calibration unit.
7
8
This library is free software; you can redistribute it and/or
9
modify it under the terms of the GNU Lesser General Public
10
License as published by the Free Software Foundation; either
11
version 2.1 of the License, or (at your option) any later version.
12
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
See the GNU Lesser General Public License for more details:
17
http://www.gnu.org/copyleft/lesser.html
18
19
You should have received a copy of the GNU Lesser General Public License
20
along with this library/program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23
Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi
24
25
Modification history:
26
2006-10-30 Vesa Oikonen
27
First created.
28
2007-02-02 VO
29
imgUnitId() identifies more unit strings.
30
Added more IMG units.
31
Functions imgUnitFromEcat7() and imgUnit() rewritten.
32
2007-17-07 Harri Merisaari
33
Modified for optional ANSi compatibility
34
2008-07-24 VO
35
Added function imgSetUnit().
36
2010-05-11 VO
37
Function imgUnitFromEcat7() tries to identify unit with imgUnitId()
38
always when ECAT 7 calibration_units is 2; previosly in these cases
39
unit was assumed to be unknown.
40
2011-02-04 VO
41
imgUnitToEcat7() writes label "unitless" in the header, previosly header
42
was marked to contain no data_units label.
43
44
45
******************************************************************************/
46
#include <stdio.h>
47
#include <stdlib.h>
48
#include <math.h>
49
#include <time.h>
50
#include <string.h>
51
#include <strings.h>
52
#include <ctype.h>
53
#include <float.h>
54
/*****************************************************************************/
55
#include "
img.h
"
56
#include "
substitutions.h
"
57
/*****************************************************************************/
58
#include "
include/imgunit.h
"
59
/*****************************************************************************/
61
static
char
*
img_unit_string
[] = {
62
/* 0 */
"unknown"
,
63
/* 1 */
"cnts/sec"
,
64
/* 2 */
"counts"
,
65
/* 3 */
"kBq/mL"
,
66
/* 4 */
"sec*kBq/mL"
,
67
/* 5 */
"1/sec"
,
68
/* 6 */
"1/min"
,
69
/* 7 */
"mL/mL"
,
70
/* 8 */
"mL/dL"
,
71
/* 9 */
"mL/(mL*min)"
,
72
/* 10 */
"mL/(dL*min)"
,
73
/* 11 */
"unitless"
,
74
/* 12 */
"nCi/mL"
,
75
/* 13 */
"MBq/mL"
,
76
/* 14 */
"Bq/cc"
,
77
/* 15 */
"uCi/cc"
,
78
/* 16 */
"umol/(100g*min)"
,
79
/* 17 */
"mg/(100g*min)"
,
80
0
81
};
82
/*****************************************************************************/
83
84
/*****************************************************************************/
91
int
imgUnitId
(
char
*unit) {
92
if
(unit==NULL)
return
(-1);
93
if
(strlen(unit)==0)
return
IMGUNIT_UNKNOWN
;
94
else
if
(strcasecmp(unit,
"unknown"
)==0)
return
IMGUNIT_UNKNOWN
;
95
else
if
(strcasecmp(unit,
"cnts/sec"
)==0)
return
IMGUNIT_CPS
;
96
else
if
(strcasecmp(unit,
"counts/sec"
)==0)
return
IMGUNIT_CPS
;
97
else
if
(strcasecmp(unit,
"ECAT counts/sec"
)==0)
return
IMGUNIT_CPS
;
98
else
if
(strcasecmp(unit,
"cps"
)==0)
return
IMGUNIT_CPS
;
99
else
if
(strcasecmp(unit,
"counts"
)==0)
return
IMGUNIT_COUNTS
;
100
else
if
(strcasecmp(unit,
"cnts"
)==0)
return
IMGUNIT_COUNTS
;
101
else
if
(strcasecmp(unit,
"kBq/cc"
)==0)
return
IMGUNIT_KBQ_PER_ML
;
102
else
if
(strcasecmp(unit,
"kBq/mL"
)==0)
return
IMGUNIT_KBQ_PER_ML
;
103
else
if
(strcasecmp(unit,
"sec*kBq/cc"
)==0)
return
IMGUNIT_SEC_KBQ_PER_ML
;
104
else
if
(strcasecmp(unit,
"sec*kBq/mL"
)==0)
return
IMGUNIT_SEC_KBQ_PER_ML
;
105
else
if
(strcasecmp(unit,
"integral"
)==0)
return
IMGUNIT_SEC_KBQ_PER_ML
;
106
else
if
(strcasecmp(unit,
"1/sec"
)==0)
return
IMGUNIT_PER_SEC
;
107
else
if
(strcasecmp(unit,
"1/s"
)==0)
return
IMGUNIT_PER_SEC
;
108
else
if
(strcasecmp(unit,
"s-1"
)==0)
return
IMGUNIT_PER_SEC
;
109
else
if
(strcasecmp(unit,
"1/min"
)==0)
return
IMGUNIT_PER_MIN
;
110
else
if
(strcasecmp(unit,
"min-1"
)==0)
return
IMGUNIT_PER_MIN
;
111
else
if
(strcasecmp(unit,
"mL/mL"
)==0)
return
IMGUNIT_ML_PER_ML
;
112
else
if
(strcasecmp(unit,
"mL/cc"
)==0)
return
IMGUNIT_ML_PER_ML
;
113
else
if
(strcasecmp(unit,
"mL/dL"
)==0)
return
IMGUNIT_ML_PER_DL
;
114
else
if
(strcasecmp(unit,
"mL/100mL"
)==0)
return
IMGUNIT_ML_PER_DL
;
115
else
if
(strcasecmp(unit,
"mL/(mL*min)"
)==0)
return
IMGUNIT_ML_PER_ML_PER_MIN
;
116
else
if
(strcasecmp(unit,
"mL/(min*mL)"
)==0)
return
IMGUNIT_ML_PER_ML_PER_MIN
;
117
else
if
(strcasecmp(unit,
"mL/(cc*min)"
)==0)
return
IMGUNIT_ML_PER_ML_PER_MIN
;
118
else
if
(strcasecmp(unit,
"mL/(min*cc)"
)==0)
return
IMGUNIT_ML_PER_ML_PER_MIN
;
119
else
if
(strcasecmp(unit,
"mL/mL/min"
)==0)
return
IMGUNIT_ML_PER_ML_PER_MIN
;
120
else
if
(strcasecmp(unit,
"mL/min/mL"
)==0)
return
IMGUNIT_ML_PER_ML_PER_MIN
;
121
else
if
(strcasecmp(unit,
"mL/cc/min"
)==0)
return
IMGUNIT_ML_PER_ML_PER_MIN
;
122
else
if
(strcasecmp(unit,
"mL/min/cc"
)==0)
return
IMGUNIT_ML_PER_ML_PER_MIN
;
123
else
if
(strcasecmp(unit,
"mL/(dL*min)"
)==0)
return
IMGUNIT_ML_PER_DL_PER_MIN
;
124
else
if
(strcasecmp(unit,
"mL/(min*dL)"
)==0)
return
IMGUNIT_ML_PER_DL_PER_MIN
;
125
else
if
(strcasecmp(unit,
"mL/(100mL*min)"
)==0)
return
IMGUNIT_ML_PER_DL_PER_MIN
;
126
else
if
(strcasecmp(unit,
"mL/(min*100mL)"
)==0)
return
IMGUNIT_ML_PER_DL_PER_MIN
;
127
else
if
(strcasecmp(unit,
"mL/dL/min"
)==0)
return
IMGUNIT_ML_PER_DL_PER_MIN
;
128
else
if
(strcasecmp(unit,
"mL/min/dL"
)==0)
return
IMGUNIT_ML_PER_DL_PER_MIN
;
129
else
if
(strcasecmp(unit,
"mL/100mL/min"
)==0)
return
IMGUNIT_ML_PER_DL_PER_MIN
;
130
else
if
(strcasecmp(unit,
"mL/min/100mL"
)==0)
return
IMGUNIT_ML_PER_DL_PER_MIN
;
131
else
if
(strcasecmp(unit,
"unitless"
)==0)
return
IMGUNIT_UNITLESS
;
132
else
if
(strcasecmp(unit,
"nCi/cc"
)==0)
return
IMGUNIT_NCI_PER_ML
;
133
else
if
(strcasecmp(unit,
"nCi/mL"
)==0)
return
IMGUNIT_NCI_PER_ML
;
134
else
if
(strcasecmp(unit,
"MBq/cc"
)==0)
return
IMGUNIT_MBQ_PER_ML
;
135
else
if
(strcasecmp(unit,
"MBq/mL"
)==0)
return
IMGUNIT_MBQ_PER_ML
;
136
else
if
(strcasecmp(unit,
"Bq/cc"
)==0)
return
IMGUNIT_BQ_PER_ML
;
137
else
if
(strcasecmp(unit,
"Bq/mL"
)==0)
return
IMGUNIT_BQ_PER_ML
;
138
else
if
(strcasecmp(unit,
"uCi/cc"
)==0)
return
IMGUNIT_UCI_PER_ML
;
139
else
if
(strcasecmp(unit,
"uCi/mL"
)==0)
return
IMGUNIT_UCI_PER_ML
;
140
else
if
(strcasecmp(unit,
"umol/(100g*min)"
)==0)
return
IMGUNIT_UMOL_PER_MIN_PER_100G
;
141
else
if
(strcasecmp(unit,
"umol/(min*100g)"
)==0)
return
IMGUNIT_UMOL_PER_MIN_PER_100G
;
142
else
if
(strcasecmp(unit,
"umol/100g/min"
)==0)
return
IMGUNIT_UMOL_PER_MIN_PER_100G
;
143
else
if
(strcasecmp(unit,
"umol/min/100g"
)==0)
return
IMGUNIT_UMOL_PER_MIN_PER_100G
;
144
else
if
(strcasecmp(unit,
"mg/(100g*min)"
)==0)
return
IMGUNIT_MG_PER_MIN_PER_100G
;
145
else
if
(strcasecmp(unit,
"mg/(min*100g)"
)==0)
return
IMGUNIT_MG_PER_MIN_PER_100G
;
146
else
if
(strcasecmp(unit,
"mg/100g/min"
)==0)
return
IMGUNIT_MG_PER_MIN_PER_100G
;
147
else
if
(strcasecmp(unit,
"mg/min/100g"
)==0)
return
IMGUNIT_MG_PER_MIN_PER_100G
;
148
149
return
(-3);
150
}
151
/*****************************************************************************/
152
153
/*****************************************************************************/
160
void
imgUnitFromEcat
(
IMG
*img,
int
ecat_unit) {
161
switch
(ecat_unit) {
162
case
0:
/* Unknown */
163
img->
unit
=
IMGUNIT_UNKNOWN
;
break
;
164
case
1:
/* MBq/mL */
165
img->
unit
=
IMGUNIT_MBQ_PER_ML
;
break
;
166
case
2:
/* ECAT counts */
167
img->
unit
=
IMGUNIT_COUNTS
;
break
;
168
case
3:
/* uCi/ml */
169
img->
unit
=
IMGUNIT_UCI_PER_ML
;
break
;
170
case
4:
/* LMRGlu */
171
img->
unit
=
IMGUNIT_UNKNOWN
;
break
;
172
case
5:
/* LMRUGlu umol/min/100g */
173
img->
unit
=
IMGUNIT_UMOL_PER_MIN_PER_100G
;
break
;
174
case
6:
/* LMRUGlu mg/min/100g */
175
img->
unit
=
IMGUNIT_MG_PER_MIN_PER_100G
;
break
;
176
case
7:
/* nCi/mL */
177
img->
unit
=
IMGUNIT_NCI_PER_ML
;
break
;
178
case
8:
/* Well counts */
179
img->
unit
=
IMGUNIT_CPS
;
break
;
180
case
9:
/* Becquerels */
181
img->
unit
=
IMGUNIT_BQ_PER_ML
;
break
;
182
case
10:
/* kBq/mL */
183
img->
unit
=
IMGUNIT_KBQ_PER_ML
;
break
;
184
case
11:
/* 1/min */
185
img->
unit
=
IMGUNIT_PER_MIN
;
break
;
186
case
12:
/* mL/min/100g */
187
img->
unit
=
IMGUNIT_ML_PER_DL_PER_MIN
;
break
;
188
case
13:
/* sec*kBq/mL */
189
img->
unit
=
IMGUNIT_SEC_KBQ_PER_ML
;
break
;
190
case
14:
/* sec*nCi/mL */
191
img->
unit
=
IMGUNIT_UNKNOWN
;
break
;
192
case
15:
/* 1/sec */
193
img->
unit
=
IMGUNIT_PER_SEC
;
break
;
194
case
16:
/* Unitless */
195
img->
unit
=
IMGUNIT_UNITLESS
;
break
;
196
case
17:
/* Unknown */
197
default
:
198
img->
unit
=
IMGUNIT_UNKNOWN
;
break
;
199
}
200
}
201
/*****************************************************************************/
202
203
/*****************************************************************************/
210
void
imgUnitFromEcat7
(
IMG
*img,
ECAT7_mainheader
*h) {
211
if
(h->
calibration_units
==0) {
/* Not calibrated */
212
img->
unit
=1;
213
}
else
if
(h->
calibration_units
==1) {
214
if
(h->
calibration_units_label
==0)
215
img->
unit
=
IMGUNIT_BQ_PER_ML
;
216
else
217
img->
unit
=
imgUnitId
(h->
data_units
);
218
}
else
if
(h->
calibration_units
==2) {
219
img->
unit
=
imgUnitId
(h->
data_units
);
220
}
else
{
221
img->
unit
=
IMGUNIT_UNKNOWN
;
222
}
223
}
224
/*****************************************************************************/
225
226
/*****************************************************************************/
233
int
imgUnitToEcat6
(
IMG
*img) {
234
int
ecat_unit;
235
switch
(img->
unit
) {
236
case
IMGUNIT_CPS
: ecat_unit=9;
break
;
237
case
IMGUNIT_COUNTS
: ecat_unit=2;
break
;
238
case
IMGUNIT_KBQ_PER_ML
: ecat_unit=10;
break
;
239
case
IMGUNIT_SEC_KBQ_PER_ML
: ecat_unit=13;
break
;
240
case
IMGUNIT_PER_SEC
: ecat_unit=15;
break
;
241
case
IMGUNIT_PER_MIN
: ecat_unit=11;
break
;
242
case
IMGUNIT_ML_PER_ML
: ecat_unit=16;
break
;
243
case
IMGUNIT_ML_PER_DL
: ecat_unit=16;
break
;
244
case
IMGUNIT_ML_PER_ML_PER_MIN
: ecat_unit=11;
break
;
245
case
IMGUNIT_ML_PER_DL_PER_MIN
: ecat_unit=12;
break
;
246
case
IMGUNIT_UNITLESS
: ecat_unit=16;
break
;
247
case
IMGUNIT_NCI_PER_ML
: ecat_unit=7;
break
;
248
case
IMGUNIT_MBQ_PER_ML
: ecat_unit=1;
break
;
249
case
IMGUNIT_BQ_PER_ML
: ecat_unit=9;
break
;
250
case
IMGUNIT_UCI_PER_ML
: ecat_unit=3;
break
;
251
case
IMGUNIT_UMOL_PER_MIN_PER_100G
: ecat_unit=5;
break
;
252
case
IMGUNIT_MG_PER_MIN_PER_100G
: ecat_unit=6;
break
;
253
default
: ecat_unit=0;
break
;
254
}
255
return
(ecat_unit);
256
}
257
/*****************************************************************************/
258
259
/*****************************************************************************/
266
void
imgUnitToEcat7
(
IMG
*img,
ECAT7_mainheader
*h) {
267
switch
(img->
unit
) {
268
case
IMGUNIT_CPS
:
269
case
IMGUNIT_COUNTS
:
270
h->
calibration_units
=0;
271
h->
calibration_units_label
=1;
272
strcpy(h->
data_units
,
"ECAT counts/sec"
);
273
break
;
274
case
IMGUNIT_KBQ_PER_ML
:
275
h->
calibration_units
=1;
276
h->
calibration_units_label
=1;
277
strcpy(h->
data_units
,
"kBq/cc"
);
278
break
;
279
case
IMGUNIT_SEC_KBQ_PER_ML
:
280
h->
calibration_units
=2;
281
h->
calibration_units_label
=1;
282
strcpy(h->
data_units
,
"sec*kBq/mL"
);
283
break
;
284
case
IMGUNIT_PER_SEC
:
285
h->
calibration_units
=2;
286
h->
calibration_units_label
=1;
287
strcpy(h->
data_units
,
"1/sec"
);
288
break
;
289
case
IMGUNIT_PER_MIN
:
290
h->
calibration_units
=2;
291
h->
calibration_units_label
=1;
292
strcpy(h->
data_units
,
"1/min"
);
293
break
;
294
case
IMGUNIT_ML_PER_ML
:
295
h->
calibration_units
=2;
296
h->
calibration_units_label
=1;
297
strcpy(h->
data_units
,
"mL/mL"
);
298
break
;
299
case
IMGUNIT_ML_PER_DL
:
300
h->
calibration_units
=2;
301
h->
calibration_units_label
=1;
302
strcpy(h->
data_units
,
"mL/dL"
);
303
break
;
304
case
IMGUNIT_ML_PER_ML_PER_MIN
:
305
h->
calibration_units
=2;
306
h->
calibration_units_label
=1;
307
strcpy(h->
data_units
,
"mL/(mL*min)"
);
308
break
;
309
case
IMGUNIT_ML_PER_DL_PER_MIN
:
310
h->
calibration_units
=2;
311
h->
calibration_units_label
=1;
312
strcpy(h->
data_units
,
"mL/(dL*min)"
);
313
break
;
314
case
IMGUNIT_UNITLESS
:
315
h->
calibration_units
=1;
316
h->
calibration_units_label
=1;
317
strcpy(h->
data_units
,
"unitless"
);
318
break
;
319
case
IMGUNIT_NCI_PER_ML
:
320
h->
calibration_units
=1;
321
h->
calibration_units_label
=1;
322
strcpy(h->
data_units
,
"nCi/cc"
);
323
break
;
324
case
IMGUNIT_MBQ_PER_ML
:
325
h->
calibration_units
=1;
326
h->
calibration_units_label
=1;
327
strcpy(h->
data_units
,
"MBq/cc"
);
328
break
;
329
case
IMGUNIT_BQ_PER_ML
:
330
h->
calibration_units
=1;
331
h->
calibration_units_label
=1;
332
strcpy(h->
data_units
,
"Bq/cc"
);
333
break
;
334
case
IMGUNIT_UCI_PER_ML
:
335
h->
calibration_units
=1;
336
h->
calibration_units_label
=1;
337
strcpy(h->
data_units
,
"uCi/cc"
);
338
break
;
339
case
IMGUNIT_UMOL_PER_MIN_PER_100G
:
340
h->
calibration_units
=1;
341
h->
calibration_units_label
=1;
342
strcpy(h->
data_units
,
"umol/min/100g"
);
343
break
;
344
case
IMGUNIT_MG_PER_MIN_PER_100G
:
345
h->
calibration_units
=1;
346
h->
calibration_units_label
=1;
347
strcpy(h->
data_units
,
"mg/min/100g"
);
348
break
;
349
default
:
350
h->
calibration_units
=2;
351
h->
calibration_units_label
=0;
352
strcpy(h->
data_units
,
""
);
353
break
;
354
}
355
}
356
/*****************************************************************************/
357
358
/*****************************************************************************/
365
char
*
imgUnit
(
int
dunit) {
366
int
n=0;
367
while
(
img_unit_string
[n]!=0) n++;
368
if
(dunit<0 || dunit>n-1)
return
(
img_unit_string
[
IMGUNIT_UNKNOWN
]);
369
else
return
(
img_unit_string
[dunit]);
370
}
371
/*****************************************************************************/
372
373
/*****************************************************************************/
377
int
imgSetUnit
(
IMG
*img,
char
*unit)
378
{
379
int
new_unit;
380
381
if
(img==NULL || unit==NULL)
return
(1);
382
new_unit=
imgUnitId
(unit);
if
(new_unit<0)
return
(1-new_unit);
383
img->
unit
=new_unit;
384
return
(0);
385
}
386
/*****************************************************************************/
387
388
/*****************************************************************************/
389
Generated by
1.8.3.1