TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpctac
tacunits.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include "
tpcift.h
"
8
/*****************************************************************************/
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <math.h>
12
#include <time.h>
13
#include <string.h>
14
/*****************************************************************************/
15
#include "
tpctac.h
"
16
/*****************************************************************************/
17
18
/*****************************************************************************/
23
int
tacXUnitConvert
(
25
TAC
*tac,
27
const
int
u,
29
TPCSTATUS
*status
30
) {
31
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
32
if
(verbose>0) {printf(
"%s(%s)\n"
, __func__,
unitName
(u)); fflush(stdout);}
33
if
(tac==NULL || tac->
sampleNr
<1) {
34
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
35
return
TPCERROR_NO_DATA
;
36
}
37
38
/* If both units are unknown, then return suitable error code */
39
if
(u==
UNIT_UNKNOWN
&& tac->
tunit
==
UNIT_UNKNOWN
) {
40
if
(verbose>1) {printf(
" unknown x units\n"
); fflush(stdout);}
41
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_UNKNOWN_UNIT
);
42
return
TPCERROR_UNKNOWN_UNIT
;
43
}
44
45
/* Determine the correction factor */
46
double
cf;
47
cf=
unitConversionFactor
(tac->
tunit
, u);
48
if
(isnan(cf)) {
49
if
(verbose>1) {printf(
" cannot make x conversion factor\n"
); fflush(stdout);}
50
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_INCOMPATIBLE_UNIT
);
51
return
TPCERROR_INCOMPATIBLE_UNIT
;
52
}
53
54
/* Multiply x values */
55
if
(verbose>1) {printf(
" converting x with factor %g\n"
, cf); fflush(stdout);}
56
for
(
int
i=0; i<tac->
sampleNr
; i++) {
57
tac->
x
[i]*=cf; tac->
x1
[i]*=cf; tac->
x2
[i]*=cf;
58
}
59
/* Set new unit */
60
tac->
tunit
=u;
61
62
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
63
return
(
TPCERROR_OK
);
64
}
65
/*****************************************************************************/
66
67
/*****************************************************************************/
72
int
tacYUnitConvert
(
74
TAC
*tac,
76
const
int
u,
78
TPCSTATUS
*status
79
) {
80
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
81
if
(verbose>0) printf(
"%s(%s)\n"
, __func__,
unitName
(u));
82
if
(tac==NULL || tac->
sampleNr
<1 || tac->
tacNr
<1) {
83
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
84
return
TPCERROR_NO_DATA
;
85
}
86
87
/* If both units are unknown, then return suitable error code */
88
if
(u==
UNIT_UNKNOWN
&& tac->
cunit
==
UNIT_UNKNOWN
) {
89
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_UNKNOWN_UNIT
);
90
return
TPCERROR_UNKNOWN_UNIT
;
91
}
92
93
/* Determine the correction factor */
94
double
cf;
95
cf=
unitConversionFactor
(tac->
cunit
, u);
96
if
(isnan(cf)) {
97
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_INCOMPATIBLE_UNIT
);
98
return
TPCERROR_INCOMPATIBLE_UNIT
;
99
}
100
101
/* Multiply y values */
102
for
(
int
j=0; j<tac->
tacNr
; j++) {
103
for
(
int
i=0; i<tac->
sampleNr
; i++) {
104
tac->
c
[j].
y
[i]*=cf;
105
}
106
}
107
/* Set new unit */
108
tac->
cunit
=u;
109
110
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
111
return
(
TPCERROR_OK
);
112
}
113
/*****************************************************************************/
114
115
/*****************************************************************************/
121
int
tacYUnitVolume2Mass
(
123
TAC
*tac,
125
const
double
density,
127
TPCSTATUS
*status
128
) {
129
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
130
if
(verbose>0) {printf(
"%s(%g)\n"
, __func__, density); fflush(stdout);}
131
if
(tac==NULL || tac->
sampleNr
<1 || tac->
tacNr
<1 || !(density>0.0)) {
132
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
133
return
TPCERROR_NO_DATA
;
134
}
135
136
/* Check that unit contains volume in divider */
137
if
(!
unitDividerHasVolume
(tac->
cunit
)) {
138
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_INCOMPATIBLE_UNIT
);
139
return
TPCERROR_INCOMPATIBLE_UNIT
;
140
}
141
142
/* Try to convert the unit */
143
int
uu=
unitDividerMassVolumeConversion
(tac->
cunit
);
144
if
(uu==
UNIT_UNKNOWN
) {
145
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_INCOMPATIBLE_UNIT
);
146
return
TPCERROR_INCOMPATIBLE_UNIT
;
147
}
148
149
/* Divide y values with the density */
150
for
(
int
j=0; j<tac->
tacNr
; j++) {
151
for
(
int
i=0; i<tac->
sampleNr
; i++) {
152
tac->
c
[j].
y
[i]/=density;
153
}
154
}
155
/* Set new unit */
156
tac->
cunit
=uu;
157
158
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
159
return
(
TPCERROR_OK
);
160
}
161
/*****************************************************************************/
162
163
/*****************************************************************************/
169
int
tacYUnitMass2Volume
(
171
TAC
*tac,
173
const
double
density,
175
TPCSTATUS
*status
176
) {
177
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
178
if
(verbose>0) {printf(
"%s(%g)\n"
, __func__, density); fflush(stdout);}
179
if
(tac==NULL || tac->
sampleNr
<1 || tac->
tacNr
<1 || !(density>0.0)) {
180
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
181
return
TPCERROR_NO_DATA
;
182
}
183
184
/* Check that unit contains mass in divider */
185
if
(!
unitDividerHasMass
(tac->
cunit
)) {
186
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_INCOMPATIBLE_UNIT
);
187
return
TPCERROR_INCOMPATIBLE_UNIT
;
188
}
189
190
/* Try to convert the unit */
191
int
uu=
unitDividerMassVolumeConversion
(tac->
cunit
);
192
if
(uu==
UNIT_UNKNOWN
) {
193
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_INCOMPATIBLE_UNIT
);
194
return
TPCERROR_INCOMPATIBLE_UNIT
;
195
}
196
197
/* Multiply y values with the density */
198
for
(
int
j=0; j<tac->
tacNr
; j++) {
199
for
(
int
i=0; i<tac->
sampleNr
; i++) {
200
tac->
c
[j].
y
[i]*=density;
201
}
202
}
203
/* Set new unit */
204
tac->
cunit
=uu;
205
206
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
207
return
(
TPCERROR_OK
);
208
}
209
/*****************************************************************************/
210
211
/*****************************************************************************/
statusSet
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition
statusmsg.c:142
TACC::y
double * y
Definition
tpctac.h:75
TAC
Definition
tpctac.h:87
TAC::x
double * x
Definition
tpctac.h:97
TAC::cunit
unit cunit
Definition
tpctac.h:105
TAC::sampleNr
int sampleNr
Definition
tpctac.h:89
TAC::c
TACC * c
Definition
tpctac.h:117
TAC::x2
double * x2
Definition
tpctac.h:101
TAC::tunit
unit tunit
Definition
tpctac.h:109
TAC::x1
double * x1
Definition
tpctac.h:99
TAC::tacNr
int tacNr
Definition
tpctac.h:91
TPCSTATUS
Definition
tpcextensions.h:241
TPCSTATUS::verbose
int verbose
Verbose level, used by statusPrint() etc.
Definition
tpcextensions.h:242
tacYUnitConvert
int tacYUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
Definition
tacunits.c:72
tacYUnitMass2Volume
int tacYUnitMass2Volume(TAC *tac, const double density, TPCSTATUS *status)
Definition
tacunits.c:169
tacXUnitConvert
int tacXUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
Definition
tacunits.c:23
tacYUnitVolume2Mass
int tacYUnitVolume2Mass(TAC *tac, const double density, TPCSTATUS *status)
Definition
tacunits.c:121
UNIT_UNKNOWN
@ UNIT_UNKNOWN
Unknown unit.
Definition
tpcextensions.h:85
TPCERROR_UNKNOWN_UNIT
@ TPCERROR_UNKNOWN_UNIT
Unknown data unit.
Definition
tpcextensions.h:226
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
TPCERROR_INCOMPATIBLE_UNIT
@ TPCERROR_INCOMPATIBLE_UNIT
Incompatible units.
Definition
tpcextensions.h:215
TPCERROR_NO_DATA
@ TPCERROR_NO_DATA
File contains no data.
Definition
tpcextensions.h:203
unitConversionFactor
double unitConversionFactor(const int u1, const int u2)
Definition
units.c:487
unitName
char * unitName(int unit_code)
Definition
units.c:143
unitDividerHasVolume
int unitDividerHasVolume(int u)
Definition
units.c:678
unitDividerMassVolumeConversion
int unitDividerMassVolumeConversion(int u)
Definition
units.c:775
unitDividerHasMass
int unitDividerHasMass(int u)
Definition
units.c:694
tpcift.h
Header file for library libtpcift.
tpctac.h
Header file for library libtpctac.
Generated on
for TPCCLIB by
1.17.0