TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcpar
parcomb.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 "
tpcpar.h
"
14
/*****************************************************************************/
15
16
/*****************************************************************************/
22
int
parSelectByAnother
(
24
PAR
*d1,
26
PAR
*d2,
28
int
*pn,
30
int
*pr,
32
TPCSTATUS
*status
33
) {
34
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
35
if
(verbose>0) printf(
"%s()\n"
, __func__);
36
if
(pn!=NULL) *pn=0;
37
if
(pr!=NULL) *pr=0;
38
/* Check that required data exists */
39
if
(d1==NULL || d1->
parNr
<1 || d1->
tacNr
<1) {
40
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
41
return
TPCERROR_NO_DATA
;
42
}
43
/* Unselect all */
44
for
(
int
i=0; i<d1->
parNr
; i++) d1->
n
[i].
sw
=0;
45
for
(
int
i=0; i<d1->
tacNr
; i++) d1->
r
[i].
sw
=0;
46
/* If no data to compare to, then that is it */
47
if
(d2==NULL || d2->
parNr
<1 || d2->
tacNr
<1) {
48
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
49
return
TPCERROR_OK
;
50
}
51
52
/* Search for parameter names */
53
for
(
int
i=0; i<d1->
parNr
; i++) {
54
if
(
strnlen
(d1->
n
[i].
name
, 1)<1)
continue
;
55
for
(
int
j=0; j<d2->
parNr
; j++) {
56
if
(
strnlen
(d2->
n
[j].
name
, 1)<1)
continue
;
57
if
(strcasecmp(d1->
n
[i].
name
, d2->
n
[j].
name
)==0) {d1->
n
[i].
sw
=1;
continue
;}
58
/* Allow mixed '-' and '_' */
59
char
*buf1, *buf2;
60
buf1=
strdup
(d1->
n
[i].
name
);
strReplaceChar
(buf1,
'-'
,
'_'
);
61
buf2=
strdup
(d2->
n
[j].
name
);
strReplaceChar
(buf2,
'-'
,
'_'
);
62
int
ret=strcasecmp(buf1, buf2);
63
free(buf1); free(buf2);
64
if
(ret==0) {d1->
n
[i].
sw
=1;
continue
;}
65
}
66
}
67
68
/* Search for TAC names */
69
for
(
int
i=0; i<d1->
tacNr
; i++) {
70
if
(
strnlen
(d1->
r
[i].
name
, 1)<1)
continue
;
71
for
(
int
j=0; j<d2->
tacNr
; j++) {
72
if
(
strnlen
(d2->
r
[j].
name
, 1)<1)
continue
;
73
if
(strcasecmp(d1->
r
[i].
name
, d2->
r
[j].
name
)==0) {d1->
r
[i].
sw
=1;
continue
;}
74
/* Allow mixed '-' and '_' */
75
char
*buf1, *buf2;
76
buf1=
strdup
(d1->
r
[i].
name
);
strReplaceChar
(buf1,
'-'
,
'_'
);
77
buf2=
strdup
(d2->
r
[j].
name
);
strReplaceChar
(buf2,
'-'
,
'_'
);
78
int
ret=strcasecmp(buf1, buf2);
79
free(buf1); free(buf2);
80
if
(ret==0) {d1->
r
[i].
sw
=1;
continue
;}
81
}
82
}
83
84
/* Count the selected numbers, if needed */
85
if
(pn!=NULL) *pn=
parSelectedParameters
(d1);
86
if
(pr!=NULL) *pr=
parSelectedTACs
(d1);
87
88
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
89
return
TPCERROR_OK
;
90
}
91
/*****************************************************************************/
92
93
/*****************************************************************************/
99
int
parCombineTACs
(
101
PAR
*d1,
103
PAR
*d2,
105
TPCSTATUS
*status
106
) {
107
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
108
if
(verbose>0) printf(
"%s()\n"
, __func__);
109
110
/* Check what there is to copy */
111
int
tacNr;
112
int
ret=
parSelectByAnother
(d1, d2, NULL, &tacNr, status);
113
if
(ret!=
TPCERROR_OK
)
return
(ret);
114
if
(tacNr<1) {
115
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
116
return
TPCERROR_NO_DATA
;
117
}
118
int
parNr=d2->
parNr
;
119
if
(verbose>1) printf(
"%d TACs and %d parameters to copy.\n"
, tacNr, parNr);
120
121
/* Allocate memory for the new parameters */
122
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
123
ret=
parAllocateMore
(d1, parNr, 0);
124
if
(ret!=
TPCERROR_OK
)
return
(ret);
125
126
/* Copy new parameter names */
127
for
(
int
i=0; i<d2->
parNr
; i++) {
128
strcpy(d1->
n
[i+d1->
parNr
].
name
, d2->
n
[i].
name
);
129
d1->
n
[i+d1->
parNr
].
unit
=d2->
n
[i].
unit
;
130
d1->
n
[i+d1->
parNr
].
lim1
=d2->
n
[i].
lim1
;
131
d1->
n
[i+d1->
parNr
].
lim2
=d2->
n
[i].
lim2
;
132
d1->
n
[i+d1->
parNr
].
tol
=d2->
n
[i].
tol
;
133
}
134
135
/* Copy contents for common TACs */
136
for
(
int
i=0; i<d1->
tacNr
; i++) {
137
/* find matching TAC name */
138
if
(
strnlen
(d1->
r
[i].
name
, 1)<1)
continue
;
139
int
j;
140
for
(j=0; j<d2->
tacNr
; j++) {
141
if
(
strnlen
(d2->
r
[j].
name
, 1)<1)
continue
;
142
if
(strcasecmp(d1->
r
[i].
name
, d2->
r
[j].
name
)==0)
break
;
143
/* Allow mixed '-' and '_' */
144
char
*buf1, *buf2;
145
buf1=
strdup
(d1->
r
[i].
name
);
strReplaceChar
(buf1,
'-'
,
'_'
);
146
buf2=
strdup
(d2->
r
[j].
name
);
strReplaceChar
(buf2,
'-'
,
'_'
);
147
int
ret=strcasecmp(buf1, buf2);
148
free(buf1); free(buf2);
149
if
(ret==0)
break
;
150
}
151
if
(j==d2->
tacNr
)
continue
;
// matching name not found, leave values as NaN
152
153
/* Copy new parameter values */
154
for
(
int
k=0; k<d2->
parNr
; k++) {
155
d1->
r
[i].
p
[k+d1->
parNr
]=d2->
r
[j].
p
[k];
156
d1->
r
[i].
sd
[k+d1->
parNr
]=d2->
r
[j].
sd
[k];
157
d1->
r
[i].
cl1
[k+d1->
parNr
]=d2->
r
[j].
cl1
[k];
158
d1->
r
[i].
cl2
[k+d1->
parNr
]=d2->
r
[j].
cl2
[k];
159
}
160
}
161
162
d1->
parNr
+=d2->
parNr
;
163
164
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
165
return
TPCERROR_OK
;
166
}
167
/*****************************************************************************/
168
169
/*****************************************************************************/
parAllocateMore
int parAllocateMore(PAR *par, int parNr, int tacNr)
Definition
par.c:183
parSelectByAnother
int parSelectByAnother(PAR *d1, PAR *d2, int *pn, int *pr, TPCSTATUS *status)
Definition
parcomb.c:22
parCombineTACs
int parCombineTACs(PAR *d1, PAR *d2, TPCSTATUS *status)
Definition
parcomb.c:99
parSelectedTACs
int parSelectedTACs(PAR *d)
Definition
parselect.c:100
parSelectedParameters
int parSelectedParameters(PAR *d)
Definition
parselect.c:199
statusSet
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition
statusmsg.c:142
strReplaceChar
void strReplaceChar(char *s, char c1, char c2)
Definition
stringext.c:134
strdup
char * strdup(const char *s)
Definition
stringext.c:185
strnlen
size_t strnlen(const char *s, size_t n)
Definition
stringext.c:565
PAR
Definition
tpcpar.h:100
PAR::parNr
int parNr
Definition
tpcpar.h:108
PAR::tacNr
int tacNr
Definition
tpcpar.h:104
PAR::r
PARR * r
Definition
tpcpar.h:114
PAR::n
PARN * n
Definition
tpcpar.h:112
PARN::unit
int unit
Definition
tpcpar.h:86
PARN::lim2
double lim2
Definition
tpcpar.h:90
PARN::sw
char sw
Definition
tpcpar.h:94
PARN::tol
double tol
Definition
tpcpar.h:92
PARN::name
char name[MAX_PARNAME_LEN+1]
Definition
tpcpar.h:82
PARN::lim1
double lim1
Definition
tpcpar.h:88
PARR::name
char name[MAX_TACNAME_LEN+1]
Definition
tpcpar.h:50
PARR::cl2
double * cl2
Definition
tpcpar.h:70
PARR::sw
char sw
Definition
tpcpar.h:74
PARR::p
double * p
Definition
tpcpar.h:64
PARR::sd
double * sd
Definition
tpcpar.h:66
PARR::cl1
double * cl1
Definition
tpcpar.h:68
TPCSTATUS
Definition
tpcextensions.h:241
TPCSTATUS::verbose
int verbose
Verbose level, used by statusPrint() etc.
Definition
tpcextensions.h:242
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
TPCERROR_NO_DATA
@ TPCERROR_NO_DATA
File contains no data.
Definition
tpcextensions.h:203
tpcpar.h
Header file for libtpcpar.
Generated on
for TPCCLIB by
1.17.0