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

Check and set units of PET data. More...

#include "libtpcmisc.h"

Go to the source code of this file.

Functions

int petCunitId (const char *unit)
 
int petTunitId (const char *timeunit)
 
char * petCunit (int cunit)
 
char * petTunit (int tunit)
 
int cunitFromFilename (char *fname)
 

Detailed Description

Check and set units of PET data.

Author
Vesa Oikonen

Definition in file petunits.c.

Function Documentation

◆ cunitFromFilename()

int cunitFromFilename ( char * fname)

Tries to find calibration unit from filename.

Returns
Returns CUNIT, which is CUNIT_UNKNOWN if not successful.
See also
petCunitId, petTunitId, petCunit, petTunit
Parameters
fnamePointer to file name, where calibration unit is tried to be found.

Definition at line 242 of file petunits.c.

245 {
246 char *cptr;
247
248 if(fname==NULL || strlen(fname)<3) return CUNIT_UNKNOWN;
249 for(int i=0; i<2; i++) {
250 if(i==0) /* First, look in the extension */
251 {cptr=strrchr(fname, '.'); if(cptr==NULL) {cptr=fname; i++;}}
252 else /* Then, look into whole filename */
253 cptr=fname;
254 if(strcasestr(cptr, "KBQ")!=NULL) return CUNIT_KBQ_PER_ML;
255 if(strcasestr(cptr, "MBQ")!=NULL) return CUNIT_MBQ_PER_ML;
256 if(strcasestr(cptr, "BQ")!=NULL) return CUNIT_BQ_PER_ML;
257 if(strcasestr(cptr, "NCI")!=NULL) return CUNIT_NCI_PER_ML;
258 if(strcasestr(cptr, "KCPS")!=NULL) return CUNIT_KCPS;
259 if(strcasestr(cptr, "CPS")!=NULL) return CUNIT_CPS;
260 }
261 return CUNIT_UNKNOWN;
262}
char * strcasestr(const char *haystack, const char *needle)
Definition strext.c:279

◆ petCunit()

char * petCunit ( int cunit)

Return pointer to string describing the calibration data units.

See also
petCunitId, petTunitId, petTunit, cunitFromFilename
Parameters
cunitindex of PET_data units_string[].

Definition at line 211 of file petunits.c.

214 {
215 int n=0;
216 while(cunit_string[n]!=0) n++;
217 if(cunit<0 || cunit>n-1) return(cunit_string[CUNIT_UNKNOWN]);
218 else return(cunit_string[cunit]);
219}

Referenced by csv2dft_linkset(), dftGetPmodTitle(), and imgUnit().

◆ petCunitId()

int petCunitId ( const char * unit)

Identify the specified units string as PET data unit.

Returns
Returns the unit id number.
See also
petTunitId, petCunit, petTunit, cunitFromFilename

Definition at line 74 of file petunits.c.

75{
76 if(unit==NULL) return CUNIT_UNKNOWN;
77 if(strlen(unit)==0) return CUNIT_UNKNOWN;
78 else if(strcasecmp(unit, "unknown")==0) return CUNIT_UNKNOWN;
79 else if(strcasecmp(unit, "cnts/sec")==0) return CUNIT_CPS;
80 else if(strcasecmp(unit, "counts/sec")==0) return CUNIT_CPS;
81 else if(strcasecmp(unit, "ECAT counts/sec")==0) return CUNIT_CPS;
82 else if(strcasecmp(unit, "cps")==0) return CUNIT_CPS;
83 else if(strcasecmp(unit, "counts")==0) return CUNIT_COUNTS;
84 else if(strcasecmp(unit, "cnts")==0) return CUNIT_COUNTS;
85 else if(strcasecmp(unit, "kBq/cc")==0) return CUNIT_KBQ_PER_ML;
86 else if(strcasecmp(unit, "kBqcc")==0) return CUNIT_KBQ_PER_ML;
87 else if(strcasecmp(unit, "kBq/mL")==0) return CUNIT_KBQ_PER_ML;
88 else if(strcasecmp(unit, "kBqmL")==0) return CUNIT_KBQ_PER_ML;
89 else if(strcasecmp(unit, "sec*kBq/cc")==0) return CUNIT_SEC_KBQ_PER_ML;
90 else if(strcasecmp(unit, "sec*kBq/mL")==0) return CUNIT_SEC_KBQ_PER_ML;
91 else if(strcasecmp(unit, "integral")==0) return CUNIT_SEC_KBQ_PER_ML;
92 else if(strcasecmp(unit, "1/sec")==0) return CUNIT_PER_SEC;
93 else if(strcasecmp(unit, "1/s")==0) return CUNIT_PER_SEC;
94 else if(strcasecmp(unit, "s-1")==0) return CUNIT_PER_SEC;
95 else if(strcasecmp(unit, "1/min")==0) return CUNIT_PER_MIN;
96 else if(strcasecmp(unit, "min-1")==0) return CUNIT_PER_MIN;
97 else if(strcasecmp(unit, "mL/mL")==0) return CUNIT_ML_PER_ML;
98 else if(strcasecmp(unit, "mL/cc")==0) return CUNIT_ML_PER_ML;
99 else if(strcasecmp(unit, "mL/dL")==0) return CUNIT_ML_PER_DL;
100 else if(strcasecmp(unit, "mL/100mL")==0) return CUNIT_ML_PER_DL;
101 else if(strcasecmp(unit, "mL/(mL*min)")==0) return CUNIT_ML_PER_ML_PER_MIN;
102 else if(strcasecmp(unit, "mL/(min*mL)")==0) return CUNIT_ML_PER_ML_PER_MIN;
103 else if(strcasecmp(unit, "mL/(cc*min)")==0) return CUNIT_ML_PER_ML_PER_MIN;
104 else if(strcasecmp(unit, "mL/(min*cc)")==0) return CUNIT_ML_PER_ML_PER_MIN;
105 else if(strcasecmp(unit, "mL/mL/min")==0) return CUNIT_ML_PER_ML_PER_MIN;
106 else if(strcasecmp(unit, "mL/min/mL")==0) return CUNIT_ML_PER_ML_PER_MIN;
107 else if(strcasecmp(unit, "mL/cc/min")==0) return CUNIT_ML_PER_ML_PER_MIN;
108 else if(strcasecmp(unit, "mL/min/cc")==0) return CUNIT_ML_PER_ML_PER_MIN;
109 else if(strcasecmp(unit, "mL/(dL*min)")==0) return CUNIT_ML_PER_DL_PER_MIN;
110 else if(strcasecmp(unit, "mL/(min*dL)")==0) return CUNIT_ML_PER_DL_PER_MIN;
111 else if(strcasecmp(unit, "mL/(100mL*min)")==0) return CUNIT_ML_PER_DL_PER_MIN;
112 else if(strcasecmp(unit, "mL/(min*100mL)")==0) return CUNIT_ML_PER_DL_PER_MIN;
113 else if(strcasecmp(unit, "mL/dL/min")==0) return CUNIT_ML_PER_DL_PER_MIN;
114 else if(strcasecmp(unit, "mL/min/dL")==0) return CUNIT_ML_PER_DL_PER_MIN;
115 else if(strcasecmp(unit, "mL/100mL/min")==0) return CUNIT_ML_PER_DL_PER_MIN;
116 else if(strcasecmp(unit, "mL/min/100mL")==0) return CUNIT_ML_PER_DL_PER_MIN;
117 else if(strcasecmp(unit, "unitless")==0) return CUNIT_UNITLESS;
118 else if(strcasecmp(unit, "1/1")==0) return CUNIT_UNITLESS;
119 else if(strcasecmp(unit, "Hounsfield Unit")==0) return CUNIT_HU;
120 else if(strcasecmp(unit, "HU")==0) return CUNIT_HU;
121 else if(strcasecmp(unit, "nCi/cc")==0) return CUNIT_NCI_PER_ML;
122 else if(strcasecmp(unit, "nCicc")==0) return CUNIT_NCI_PER_ML;
123 else if(strcasecmp(unit, "nCi/mL")==0) return CUNIT_NCI_PER_ML;
124 else if(strcasecmp(unit, "nCimL")==0) return CUNIT_NCI_PER_ML;
125 else if(strcasecmp(unit, "MBq/cc")==0) return CUNIT_MBQ_PER_ML;
126 else if(strcasecmp(unit, "MBqcc")==0) return CUNIT_MBQ_PER_ML;
127 else if(strcasecmp(unit, "MBq/mL")==0) return CUNIT_MBQ_PER_ML;
128 else if(strcasecmp(unit, "MBqmL")==0) return CUNIT_MBQ_PER_ML;
129 else if(strcasecmp(unit, "Bq/cc")==0) return CUNIT_BQ_PER_ML;
130 else if(strcasecmp(unit, "Bqcc")==0) return CUNIT_BQ_PER_ML;
131 else if(strcasecmp(unit, "Bq/mL")==0) return CUNIT_BQ_PER_ML;
132 else if(strcasecmp(unit, "BqmL")==0) return CUNIT_BQ_PER_ML;
133 else if(strcasecmp(unit, "uCi/cc")==0) return CUNIT_UCI_PER_ML;
134 else if(strcasecmp(unit, "uCicc")==0) return CUNIT_UCI_PER_ML;
135 else if(strcasecmp(unit, "uCi/mL")==0) return CUNIT_UCI_PER_ML;
136 else if(strcasecmp(unit, "uCimL")==0) return CUNIT_UCI_PER_ML;
137 else if(strcasecmp(unit, "umol/(100g*min)")==0) return CUNIT_UMOL_PER_MIN_PER_100G;
138 else if(strcasecmp(unit, "umol/(min*100g)")==0) return CUNIT_UMOL_PER_MIN_PER_100G;
139 else if(strcasecmp(unit, "umol/100g/min")==0) return CUNIT_UMOL_PER_MIN_PER_100G;
140 else if(strcasecmp(unit, "umol/min/100g")==0) return CUNIT_UMOL_PER_MIN_PER_100G;
141 else if(strcasecmp(unit, "umol/(dL*min)")==0) return CUNIT_UMOL_PER_MIN_PER_100G;
142 else if(strcasecmp(unit, "umol/(min*dL)")==0) return CUNIT_UMOL_PER_MIN_PER_100G;
143 else if(strcasecmp(unit, "umol/dL/min")==0) return CUNIT_UMOL_PER_MIN_PER_100G;
144 else if(strcasecmp(unit, "umol/min/dL")==0) return CUNIT_UMOL_PER_MIN_PER_100G;
145 else if(strcasecmp(unit, "mg/(100g*min)")==0) return CUNIT_MG_PER_MIN_PER_100G;
146 else if(strcasecmp(unit, "mg/(min*100g)")==0) return CUNIT_MG_PER_MIN_PER_100G;
147 else if(strcasecmp(unit, "mg/100g/min")==0) return CUNIT_MG_PER_MIN_PER_100G;
148 else if(strcasecmp(unit, "mg/min/100g")==0) return CUNIT_MG_PER_MIN_PER_100G;
149 else if(strcasecmp(unit, "mg/(dL*min)")==0) return CUNIT_MG_PER_MIN_PER_100G;
150 else if(strcasecmp(unit, "mg/(min*dL)")==0) return CUNIT_MG_PER_MIN_PER_100G;
151 else if(strcasecmp(unit, "mg/dL/min")==0) return CUNIT_MG_PER_MIN_PER_100G;
152 else if(strcasecmp(unit, "mg/min/dL")==0) return CUNIT_MG_PER_MIN_PER_100G;
153 else if(strcasecmp(unit, "%")==0) return CUNIT_PERCENTAGE;
154 else if(strcasecmp(unit, "kcps")==0) return CUNIT_KCPS;
155 else if(strcasecmp(unit, "min*kBq/cc")==0) return CUNIT_MIN_KBQ_PER_ML;
156 else if(strcasecmp(unit, "min*kBq/mL")==0) return CUNIT_MIN_KBQ_PER_ML;
157 else if(strcasecmp(unit, "Bq")==0) return CUNIT_BQ;
158 else if(strcasecmp(unit, "kBq")==0) return CUNIT_KBQ;
159 else if(strcasecmp(unit, "MBq")==0) return CUNIT_MBQ;
160 else if(strcasecmp(unit, "GBq")==0) return CUNIT_GBQ;
161 else if(strcasecmp(unit, "nCi")==0) return CUNIT_NCI;
162 else if(strcasecmp(unit, "uCi")==0) return CUNIT_UCI;
163 else if(strcasecmp(unit, "mCi")==0) return CUNIT_MCI;
164 else if(strcasecmp(unit, "%ID")==0) return CUNIT_PID;
165 else if(strcasecmp(unit, "% ID")==0) return CUNIT_PID;
166 else if(strcasecmp(unit, "%ID/g")==0) return CUNIT_PIDM;
167 else if(strcasecmp(unit, "% ID/g")==0) return CUNIT_PIDM;
168 else if(strcasecmp(unit, "%ID/mL")==0) return CUNIT_PIDV;
169 else if(strcasecmp(unit, "% ID/mL")==0) return CUNIT_PIDV;
170 else if(strcasecmp(unit, "%ID/cc")==0) return CUNIT_PIDV;
171 else if(strcasecmp(unit, "% ID/cc")==0) return CUNIT_PIDV;
172 else if(strcasecmp(unit, "g/mL")==0) return CUNIT_G_PER_ML;
173 else if(strcasecmp(unit, "g/cc")==0) return CUNIT_G_PER_ML;
174 else if(strncasecmp(unit, "SUV", 3)==0) return CUNIT_G_PER_ML;
175 else if(strcasecmp(unit, "mL/g")==0) return CUNIT_ML_PER_G;
176 else if(strcasecmp(unit, "cc/g")==0) return CUNIT_ML_PER_G;
177
178 return CUNIT_UNKNOWN;
179}

Referenced by csv2dft_a(), csv2dft_linkset(), cunit_check_dft_vs_img(), dftGetPmodTitle(), dftReadinput(), dftReadModelingData(), dftReadReference(), dftSetComments(), dftTimeIntegral(), dftUnitConversion(), and dftWrite().

◆ petTunit()

char * petTunit ( int tunit)

Return pointer to string describing the time unit.

See also
petCunitId, petTunitId, petCunit, cunitFromFilename
Parameters
tunitindex of PET_time unit_string[].

Definition at line 226 of file petunits.c.

229 {
230 int n=0;
231 while(tunit_string[n]!=0) n++;
232 if(tunit<0 || tunit>n-1) return(tunit_string[TUNIT_UNKNOWN]);
233 else return(tunit_string[tunit]);
234}

Referenced by check_times_dft_vs_dft(), csv2dft_linkset(), dftInterpolateForIMG(), dftMatchTimeunits(), dftSetComments(), dftWrite(), dftWriteHTML(), fitWrite(), imgReadModelingData(), res_allocate_with_dft(), and tsvRead().

◆ petTunitId()

int petTunitId ( const char * timeunit)

Identifies the specified string as PET time (x axis) units.

Returns
Returns the timeunit id number.
See also
petCunitId, petCunit, petTunit, cunitFromFilename

Definition at line 187 of file petunits.c.

188{
189 if(timeunit==NULL) return TUNIT_UNKNOWN;
190 if(strlen(timeunit)==0) return TUNIT_UNKNOWN;
191 else if(strcasecmp(timeunit, "unknown")==0) return TUNIT_UNKNOWN;
192 else if(strncasecmp(timeunit, "seconds", 3)==0) return TUNIT_SEC;
193 else if(strcmp(timeunit, "s")==0) return TUNIT_SEC;
194 else if(strncasecmp(timeunit, "minutes", 3)==0) return TUNIT_MIN;
195 else if(strcasecmp(timeunit, "um")==0) return TUNIT_UM;
196 else if(strcasecmp(timeunit, "mm")==0) return TUNIT_MM;
197 else if(strcasecmp(timeunit, "cm")==0) return TUNIT_CM;
198 else if(strcasecmp(timeunit, "m")==0) return TUNIT_M;
199 else if(strcasecmp(timeunit, "h")==0) return TUNIT_HOUR;
200 else if(strcasecmp(timeunit, "months")==0) return TUNIT_MONTH;
201 else if(strcasecmp(timeunit, "y")==0) return TUNIT_YEAR;
202 else if(strcasecmp(timeunit, "msec")==0) return TUNIT_MSEC;
203 return TUNIT_UNKNOWN;
204}

Referenced by csv2dft_linkset(), dft_fill_hdr_from_IFT(), dftGetPmodTitle(), dftRead(), dftTimeunitToDFT(), and fitRead().