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

BFM for SRTM. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcextensions.h"
#include "tpctac.h"
#include "tpccm.h"
#include "tpcbfm.h"

Go to the source code of this file.

Functions

int bfmSRTM (double *t, double *cri, const int n, const int bfNr, const double t3min, const double t3max, TAC *bf, TPCSTATUS *status)

Detailed Description

BFM for SRTM.

Definition in file bf_srtm.c.

Function Documentation

◆ bfmSRTM()

int bfmSRTM ( double * t,
double * cri,
const int n,
const int bfNr,
const double t3min,
const double t3max,
TAC * bf,
TPCSTATUS * status )

Calculate set of basis functions for SRTM.

Todo
Add tests.
Returns
enum tpcerror (TPCERROR_OK when successful).
See also
bfm1TCM
Parameters
tPointer to array containing PET sample (frame middle) times.
criPointer to array containing integral of reference tissue input concentration values at each sample time, AUC 0-t. AUC must have been calculated using values that are NOT corrected for decay.
nNr of samples (array lengths).
bfNrNr of basis functions to calculate.
t3minMinimum of theta3.
t3maxMaximum of theta3.
bfPointer to output TAC, to be allocated and filled with basis functions in here.
statusPointer to status data; enter NULL if not needed

Definition at line 26 of file bf_srtm.c.

45 {
46 int verbose=0; if(status!=NULL) verbose=status->verbose;
47 if(verbose>0) printf("%s(t, cri, %d, %d, %g, %g, bf)\n", __func__, n, bfNr, t3min, t3max);
48 if(t==NULL || cri==NULL || bf==NULL) {
49 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
50 return TPCERROR_FAIL;
51 }
52 if(n<2 || bfNr<1) {
53 if(verbose>1) printf("invalid sample or BF number\n");
54 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_TOO_FEW);
55 return TPCERROR_TOO_FEW;
56 }
57 if(t3min<1.0E-10 || t3min>=t3max) { // range cannot be computed otherwise
58 if(verbose>1) printf("invalid theta3 range\n");
59 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_INVALID_VALUE);
61 }
62
63 int ret;
64
65 /* Allocate memory for basis functions */
66 if(verbose>1) printf("allocating memory for basis functions\n");
67 tacFree(bf);
68 ret=tacAllocate(bf, n, bfNr);
69 if(ret!=TPCERROR_OK) {
70 statusSet(status, __func__, __FILE__, __LINE__, ret);
71 return ret;
72 }
73 /* Copy and set information fields */
74 bf->tacNr=bfNr; bf->sampleNr=n;
76 bf->isframe=0;
77 for(int bi=0; bi<bf->tacNr; bi++) sprintf(bf->c[bi].name, "B%5.5d", bi+1);
78 for(int fi=0; fi<bf->sampleNr; fi++) bf->x[fi]=t[fi];
79 /* Compute theta3 values to size fields */
80 {
81 if(verbose>1) printf("computing theta3 values\n");
82 double a, b, c;
83 a=log10(t3min); b=log10(t3max); c=(b-a)/(double)(bfNr-1);
84 for(int bi=0; bi<bf->tacNr; bi++) {
85 bf->c[bi].size=pow(10.0, (double)bi*c+a);
86 }
87 }
88 if(verbose>2) {
89 printf("bf_t3_range := %g - %g\n", bf->c[0].size, bf->c[bf->tacNr-1].size);
90 printf("bf_t3_gaps := %g - %g\n", bf->c[1].size-bf->c[0].size,
91 bf->c[bf->tacNr-1].size-bf->c[bf->tacNr-2].size);
92 }
93
94 /* Calculate the basis functions */
95 if(verbose>1) printf("computing basis functions\n");
96 ret=0;
97 for(int bi=0; bi<bf->tacNr && !ret; bi++) {
98 if(verbose>99) printf(" theta3=%g\n", bf->c[bi].size);
99 ret=simC1_i(t, cri, n, 1.0, bf->c[bi].size, bf->c[bi].y);
100 }
101 if(ret) {
102 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_INVALID_VALUE);
104 }
105
106 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
107 return(TPCERROR_OK);
108}
int simC1_i(double *t, double *cai, const int nr, const double k1, const double k2, double *ct)
Definition sim1cm.c:164
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
char name[MAX_TACNAME_LEN+1]
Definition tpctac.h:81
double * y
Definition tpctac.h:75
double size
Definition tpctac.h:71
double * x
Definition tpctac.h:97
tacformat format
Definition tpctac.h:93
int sampleNr
Definition tpctac.h:89
int isframe
Definition tpctac.h:95
TACC * c
Definition tpctac.h:117
int tacNr
Definition tpctac.h:91
int verbose
Verbose level, used by statusPrint() etc.
void tacFree(TAC *tac)
Definition tac.c:106
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
Definition tac.c:130
@ TPCERROR_INVALID_VALUE
Invalid value.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OK
No error.
@ TPCERROR_TOO_FEW
File contains too few samples.
@ TAC_FORMAT_TSV_UK
UK TSV (point as decimal separator).
Definition tpctac.h:37