TPCCLIB
Loading...
Searching...
No Matches
units_check.c File Reference

Check and set data units for PET modelling. More...

#include "libtpcmodext.h"

Go to the source code of this file.

Functions

int cunit_check_dft_vs_img (DFT *dft, IMG *img, char *errmsg, int verbose)

Detailed Description

Check and set data units for PET modelling.

Author
Vesa Oikonen

Definition in file units_check.c.

Function Documentation

◆ cunit_check_dft_vs_img()

int cunit_check_dft_vs_img ( DFT * dft,
IMG * img,
char * errmsg,
int verbose )

Check that calibration units in IMG (PET image) and DFT (input TAC) are the same, and if not, then try to convert DFT calibration unit to IMG unit. If input unit is unknown, then assume it is the same as the PET unit.

Returns
Returns 0 if successful, >0 in case of error, and <0 in case of a warning or error message to user is suggested.
Parameters
dftPointer to DFT.
imgPointer to IMG.
errmsgChar pointer to string (at least of length 128) where possible error description or warning is copied; set to NULL if not necessary.
verboseVerbose level; if zero, then nothing is printed to stderr or stdout.

Definition at line 18 of file units_check.c.

28 {
29 int iunit, punit;
30
31 if(verbose>0) printf("calibration_unit_check_dft_vs_img()\n");
32 if(errmsg!=NULL) sprintf(errmsg, "program error");
33 if(dft==NULL || img==NULL) return 1;
34
35 iunit=petCunitId(dft->unit); // identify input file unit
36 punit=img->unit;
37
38 if(iunit==CUNIT_UNKNOWN) { // Input file unit is unknown
39 // If PET unit is not known either, give a warning
40 if(punit==CUNIT_UNKNOWN) {
41 if(errmsg!=NULL) sprintf(errmsg, "unknown concentration units");
42 return -1;
43 } else { // Set to PET unit, and give a warning
44 if(errmsg!=NULL)
45 sprintf(errmsg, "unknown input concentration unit, now set to PET unit");
46 strcpy(dft->unit, imgUnit(img->unit));
47 return -2;
48 }
49 }
50
51 // Input unit is known; if PET unit is not, then give a warning
52 if(punit==CUNIT_UNKNOWN) {
53 if(errmsg!=NULL) sprintf(errmsg, "unknown concentration units in PET data");
54 return -3;
55 }
56
57 // Both units are known, so convert input data if necessary/possible
58 if(iunit==CUNIT_KBQ_PER_ML) { // input is in units kBq/ml
59 // If PET unit is the same, then everything is fine
60 if(punit==CUNIT_KBQ_PER_ML) {
61 if(errmsg!=NULL)
62 sprintf(errmsg, "input and PET data have the same concentration units.\n");
63 return 0;
64 } else if(punit==CUNIT_BQ_PER_ML) { // image is in Bq/ml, convert input
65 dftUnitConversion(dft, CUNIT_BQ_PER_ML);
66 if(errmsg!=NULL)
67 sprintf(errmsg, "input units converted to %s\n", dft->unit);
68 return 0;
69 } else { // image is in some other units, just give a warning for now
70 if(errmsg!=NULL)
71 sprintf(errmsg, "different concentration units in input and PET data");
72 return -4;
73 }
74 } else if(iunit==CUNIT_BQ_PER_ML) { // input is in units Bq/ml
75 // If PET unit is the same, then everything is fine
76 if(punit==CUNIT_BQ_PER_ML) {
77 if(errmsg!=NULL)
78 sprintf(errmsg, "input and PET data have the same concentration units.\n");
79 return 0;
80 } else if(punit==CUNIT_KBQ_PER_ML) { // image is in kBq/ml, convert input
81 dftUnitConversion(dft, CUNIT_KBQ_PER_ML);
82 if(errmsg!=NULL)
83 sprintf(errmsg, "input units converted to %s\n", dft->unit);
84 return 0;
85 } else { // image is in some other units, just give a warning for now
86 if(errmsg!=NULL)
87 sprintf(errmsg, "different concentration units in input and PET data");
88 return -4;
89 }
90 } else { // input unit is known, but not kBq/ml or Bq/ml
91 if(errmsg!=NULL)
92 sprintf(errmsg, "check the concentration units in input and PET data");
93 return -5;
94 }
95
96 return 0;
97}
int dftUnitConversion(DFT *dft, int dunit)
Definition dftunit.c:25
char * imgUnit(int dunit)
Definition imgunits.c:315
int petCunitId(const char *unit)
Definition petunits.c:74
char unit[MAX_UNITS_LEN+1]
char unit

Referenced by imgReadModelingData().