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

Create PAR data for use in testing TPCCLIB. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcpar.h"

Go to the source code of this file.

Functions

int parExampleTTACs (PAR *d, int type, TPCSTATUS *status)
 
int parExamplePerfectBolus (PAR *d, TPCSTATUS *status)
 

Detailed Description

Create PAR data for use in testing TPCCLIB.

Definition in file parexample.c.

Function Documentation

◆ parExamplePerfectBolus()

int parExamplePerfectBolus ( PAR * d,
TPCSTATUS * status )

Create PAR data containing function parameters for perfect bolus TAC, starting from zero and approaching zero after the peak.

Note
For use in algorithm and software tests.

Creates Gamma variate function (gammav) function with zero delay and with p[1]=1. Maximum is at 1.2 s and max value is 100 kBq/mL. Integral from 0 to infinity is 326.19382 (p[0]*p[2]^2).

Returns
enum tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
See also
parInit, parExampleTTACs, simBTAC
Parameters
dPointer to initiated PAR struct, which will be allocated and filled here; any previous content will be deleted.
statusPointer to status data; enter NULL if not needed

Definition at line 120 of file parexample.c.

126 {
127 int verbose=0; if(status!=NULL) verbose=status->verbose;
128 if(verbose>0) printf("%s(par)\n", __func__);
129
130 /* Check that required data exists */
131 if(d==NULL) {
132 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
133 return TPCERROR_NO_DATA;
134 }
135 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
136
137 int ret, pi, parNr;
138
139 /* Allocate memory */
140 parNr=modelParNr(modelCodeIndex("gammav"));
141 ret=parAllocate(d, parNr, 1); if(ret!=TPCERROR_OK) return(ret);
142 d->tacNr=1; d->parNr=4;
144 /* Set header fields */
145 iftPut(&d->h, "studynr", "ptac1401", 1, NULL);
146 iftPut(&d->h, "analysis_time", "2016-07-05 15:40:03", 1, NULL);
147 iftPut(&d->h, "program", "libtpcpar (c) 2016", 1, NULL);
148 iftPut(&d->h, "datafile","ptac1401.tac",1,NULL);
149 iftPut(&d->h, "weighting", "no", 1, NULL);
150 iftPut(&d->h, "unit", unitName(UNIT_KBQ_PER_ML), 1, NULL);
151 iftPut(&d->h, "timeunit", unitName(UNIT_SEC), 1, NULL);
152 /* Set parameter names */
153 pi=0; strcpy(d->n[pi].name, "A"); d->n[pi].unit=UNIT_KBQ_PER_ML;
154 pi++; strcpy(d->n[pi].name, "B"); d->n[pi].unit=UNIT_UNITLESS;
155 pi++; strcpy(d->n[pi].name, "C"); d->n[pi].unit=UNIT_PER_SEC;
156 pi++; strcpy(d->n[pi].name, "tDelay"); d->n[pi].unit=UNIT_SEC;
157 /* Set region names */
158 sprintf(d->r[0].name, "bolus");
159 /* Set regional fit options */
160 d->r[0].model=modelCodeIndex("gammav");
161 d->r[0].fitNr=parNr;
162 d->r[0].dataNr=100;
163 d->r[0].start=0.0;
164 d->r[0].end=60.0;
165 d->r[0].wss=0.0E+000;
166 /* Set parameter values and region names */
167 pi=0; d->r[0].p[pi]=226.523;
168 pi++; d->r[0].p[pi]=1.0;
169 pi++; d->r[0].p[pi]=1.2;
170 pi++; d->r[0].p[pi]=0.0;
171
172 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
173 return TPCERROR_OK;
174}
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
Definition ift.c:63
unsigned int modelParNr(const unsigned int code)
Definition modell.c:255
unsigned int modelCodeIndex(const char *s)
Definition modell.c:236
int parAllocate(PAR *par, int parNr, int tacNr)
Definition par.c:108
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
int format
Definition tpcpar.h:103
IFT h
Optional (but often useful) header information.
Definition tpcpar.h:148
int parNr
Definition tpcpar.h:109
int tacNr
Definition tpcpar.h:105
PARR * r
Definition tpcpar.h:115
PARN * n
Definition tpcpar.h:113
int unit
Definition tpcpar.h:87
char name[MAX_PARNAME_LEN+1]
Definition tpcpar.h:83
double wss
Definition tpcpar.h:73
int fitNr
Definition tpcpar.h:59
char name[MAX_TACNAME_LEN+1]
Definition tpcpar.h:50
int dataNr
Definition tpcpar.h:63
unsigned int model
Definition tpcpar.h:48
double * p
Definition tpcpar.h:65
double start
Definition tpcpar.h:52
double end
Definition tpcpar.h:54
int verbose
Verbose level, used by statusPrint() etc.
@ UNIT_PER_SEC
1/s
@ UNIT_KBQ_PER_ML
kBq/mL
@ UNIT_UNITLESS
Unitless.
@ UNIT_SEC
seconds
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.
char * unitName(int unit_code)
Definition units.c:143
@ PAR_FORMAT_CSV_INT
International CSV.
Definition tpcpar.h:32

◆ parExampleTTACs()

int parExampleTTACs ( PAR * d,
int type,
TPCSTATUS * status )

Create PAR data containing function parameters for typical-looking PET TTACs for use in algorithm and software tests.

Creates three fengm2 functions with zero delay.

Returns
enum tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
See also
parInit, parExamplePerfectBolus
Parameters
dPointer to initiated PAR struct, which will be allocated and filled here; any previous content will be deleted.
typeTTAC type; currently unused
statusPointer to status data; enter NULL if not needed

Definition at line 24 of file parexample.c.

32 {
33 int verbose=0; if(status!=NULL) verbose=status->verbose;
34 if(verbose>0) printf("%s(par, %d)\n", __func__, type);
35
36 /* Check that required data exists */
37 if(d==NULL) {
38 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
39 return TPCERROR_NO_DATA;
40 }
41 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
42
43 int ret, pi, ri, parNr;
44
45 /* Allocate memory */
46 parNr=modelParNr(modelCodeIndex("fengm2"));
47 ret=parAllocate(d, parNr, 3); if(ret!=TPCERROR_OK) return(ret);
48 d->tacNr=3; d->parNr=5;
50 /* Set header fields */
51 iftPut(&d->h, "studynr", "ttac1313", 1, NULL);
52 iftPut(&d->h, "analysis_time", "2016-07-01 15:05:43", 1, NULL);
53 iftPut(&d->h, "program", "libtpcpar (c) 2016", 1, NULL);
54 iftPut(&d->h, "datafile","ttac1313.tac",1,NULL);
55 iftPut(&d->h, "weighting", "no", 1, NULL);
56 iftPut(&d->h, "unit", unitName(UNIT_KBQ_PER_ML), 1, NULL);
57 iftPut(&d->h, "timeunit", unitName(UNIT_MIN), 1, NULL);
58 /* Set parameter names */
59 pi=0; strcpy(d->n[pi].name, "A1"); d->n[pi].unit=UNIT_KBQ_PER_ML;
60 pi++; strcpy(d->n[pi].name, "L1"); d->n[pi].unit=UNIT_PER_MIN;
61 pi++; strcpy(d->n[pi].name, "A2"); d->n[pi].unit=UNIT_KBQ_PER_ML;
62 pi++; strcpy(d->n[pi].name, "L2"); d->n[pi].unit=UNIT_PER_MIN;
63 pi++; strcpy(d->n[pi].name, "A3"); d->n[pi].unit=UNIT_KBQ_PER_ML;
64 pi++; strcpy(d->n[pi].name, "L4"); d->n[pi].unit=UNIT_PER_MIN;
65 pi++; strcpy(d->n[pi].name, "tDelay"); d->n[pi].unit=UNIT_MIN;
66 /* Set regional fit options */
67 for(ri=0; ri<d->tacNr; ri++) {
68 d->r[ri].model=modelCodeIndex("fengm2");
69 d->r[ri].fitNr=parNr;
70 d->r[ri].dataNr=100;
71 d->r[ri].start=0.0;
72 d->r[ri].end=60.0;
73 d->r[ri].wss=0.0E+000;
74 }
75 /* Set parameter values and region names */
76 ri=0;
77 strcpy(d->r[ri].name, "fast");
78 pi=0; d->r[ri].p[pi]=200.;
79 pi++; d->r[ri].p[pi]=-0.8;
80 pi++; d->r[ri].p[pi]=50.;
81 pi++; d->r[ri].p[pi]=-0.2;
82 pi++; d->r[ri].p[pi]=20.;
83 pi++; d->r[ri].p[pi]=-0.005;
84 pi++; d->r[ri].p[pi]=0.0;
85 ri++;
86 strcpy(d->r[ri].name, "moder");
87 pi=0; d->r[ri].p[pi]=50.;
88 pi++; d->r[ri].p[pi]=-0.2;
89 pi++; d->r[ri].p[pi]=50.;
90 pi++; d->r[ri].p[pi]=-0.02;
91 pi++; d->r[ri].p[pi]=3.;
92 pi++; d->r[ri].p[pi]=-0.001;
93 pi++; d->r[ri].p[pi]=0.0;
94 ri++;
95 strcpy(d->r[ri].name, "slow");
96 pi=0; d->r[ri].p[pi]=5.;
97 pi++; d->r[ri].p[pi]=-0.05;
98 pi++; d->r[ri].p[pi]=70.;
99 pi++; d->r[ri].p[pi]=-0.001;
100 pi++; d->r[ri].p[pi]=30.;
101 pi++; d->r[ri].p[pi]=-0.0005;
102 pi++; d->r[ri].p[pi]=0.0;
103
104 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
105 return TPCERROR_OK;
106}
@ UNIT_MIN
minutes
@ UNIT_PER_MIN
1/min