TPCCLIB
Loading...
Searching...
No Matches
bf_srtm.c
Go to the documentation of this file.
1
4/*****************************************************************************/
5#include "tpcclibConfig.h"
6/*****************************************************************************/
7#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10#include <time.h>
11#include <string.h>
12/*****************************************************************************/
13#include "tpcextensions.h"
14#include "tpctac.h"
15#include "tpccm.h"
16/*****************************************************************************/
17#include "tpcbfm.h"
18/*****************************************************************************/
19
20/*****************************************************************************/
28 double *t,
32 double *cri,
34 const int n,
36 const int bfNr,
38 const double t3min,
40 const double t3max,
42 TAC *bf,
44 TPCSTATUS *status
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}
109/*****************************************************************************/
110
111/*****************************************************************************/
int bfmSRTM(double *t, double *cri, const int n, const int bfNr, const double t3min, const double t3max, TAC *bf, TPCSTATUS *status)
Definition bf_srtm.c:26
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
Definition tpctac.h:87
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
Header file for libtpcbfm.
Header file for libtpccm.
Header file for library libtpcextensions.
@ TPCERROR_INVALID_VALUE
Invalid value.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OK
No error.
@ TPCERROR_TOO_FEW
File contains too few samples.
Header file for library libtpctac.
@ TAC_FORMAT_TSV_UK
UK TSV (point as decimal separator)
Definition tpctac.h:37