Working with NaN's in TAC struct.
More...
#include "tpcclibConfig.h"
#include "tpcift.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpctac.h"
Go to the source code of this file.
Working with NaN's in TAC struct.
Definition in file tacnan.c.
◆ tacFixNaNs()
| int tacFixNaNs |
( |
TAC * | tac | ) |
|
Fix missing y values in TAC structure by interpolation. X values cannot be fixed. Extrapolation of the last missing values is not possible, but beginning can be estimated assuming first point (0,0).
- See also
- tacXNaNs, tacYNaNs, tacNotNaNs, tacDeleteMissingSamples
- Returns
- Returns 0 if missing values could be filled with reasonable values.
- Parameters
-
| tac | Pointer to TAC structure. |
Definition at line 121 of file tacnan.c.
124 {
127
128 int ri, fi, fj;
129 double x1, x2, y1, y2, x, y;
130
132 if(tac->
isframe) x=0.5*(tac->
x1[fi]+tac->
x2[fi]);
else x=tac->
x[fi];
133 if(x>0.0) continue;
134 for(ri=0; ri<tac->
tacNr; ri++)
135 if(!isfinite(tac->
c[ri].
y[fi])) tac->
c[ri].
y[fi]=0.0;
136 }
137
139 x1=x2=y1=y2=nan("");
141 if(tac->
isframe) x=0.5*(tac->
x1[fi]+tac->
x2[fi]);
else x=tac->
x[fi];
142
143 if(isfinite(tac->
c[ri].
y[fi])) {y1=tac->
c[ri].
y[fi]; x1=x;
continue;}
144
145
146 x2=y2=nan("");
147 for(fj=fi+1; fj<tac->
sampleNr; fj++) {
148 if(!isfinite(tac->
c[ri].
y[fj]))
continue;
149 if(tac->
isframe) x2=0.5*(tac->
x1[fj]+tac->
x2[fj]);
else x2=tac->
x[fj];
151 break;
152 }
153
154 if(!isfinite(x2)) return(3);
155
156 if(!isfinite(x1)) x1=y1=0.0;
157
158 if(x2==x1) y=0.5*(y1+y2); else y=y2-(x2-x)*(y2-y1)/(x2-x1);
160 }
161 }
162
163 return(0);
164}
int tacYNaNs(TAC *tac, const int i)
◆ tacNaNs()
◆ tacNotNaNs()
| int tacNotNaNs |
( |
TAC * | tac, |
|
|
const int | i ) |
Check TAC structure for missing sample times and values.
- See also
- tacNaNs, tacXNaNs, tacYNaNs, tacFixNaNs
- Returns
- Returns the number of samples which do not contain missing x or y values.
- Parameters
-
| tac | Pointer to TAC structure. |
| i | Index of TAC to test; <0 to test all TACs. |
Definition at line 84 of file tacnan.c.
89 {
91
92 int ri, fi, nan_nr=0;
94
96 if(!isfinite(tac->
x1[fi])) {nan_nr++;
continue;}
97 if(!isfinite(tac->
x2[fi])) {nan_nr++;
continue;}
98 } else {
99 if(!isfinite(tac->
x[fi])) {nan_nr++;
continue;}
100 }
101
102 if(i>=0) {
103 if(!isfinite(tac->
c[i].
y[fi])) nan_nr++;
104 continue;
105 }
106 for(ri=0; ri<tac->
tacNr; ri++)
107 if(!isfinite(tac->
c[ri].
y[fi])) {nan_nr++;
break;}
108 }
110}
◆ tacNthSample()
| int tacNthSample |
( |
TAC * | tac, |
|
|
const int | sn, |
|
|
const int | i ) |
Search the Nth sample (1..n) in TAC structure which does not contain missing x or y values. Use tacNotNaNs to get the number of existing samples in TAC.
- See also
- tacNotNaNs, tacFixNaNs
- Returns
- Returns the sample index, or <1 if not available.
- Parameters
-
| tac | Pointer to TAC structure. |
| sn | Number (1..n) of sample to search for; 1 to search for the first one, tacNotNaNs(&tac, -1) to search for the last one. |
| i | Index of TAC to test; <0 to test all TACs |
Definition at line 173 of file tacnan.c.
181 {
183 if(sn<1 || sn>tac->
sampleNr)
return(-1);
184
185 int ri, fi, n=0;
187
189 if(!isfinite(tac->
x1[fi]) || !isfinite(tac->
x2[fi]))
continue;
190 } else {
191 if(!isfinite(tac->
x[fi]))
continue;
192 }
193
194 if(i>=0) {
195 if(!isfinite(tac->
c[i].
y[fi]))
continue;
196 } else {
197 for(ri=0; ri<tac->
tacNr; ri++)
if(!isfinite(tac->
c[ri].
y[fi]))
break;
198 if(ri!=tac->
tacNr)
continue;
199 }
200 n++;
201 if(n==sn) return(fi);
202 }
203 return(-1);
204}
◆ tacXNaNs()
| int tacXNaNs |
( |
TAC * | tac | ) |
|
Check TAC structure for missing sample times (x, or x1 and x2).
- See also
- tacDeleteMissingSamples, tacIsX, tacSetX
- Returns
- Returns the number of missing values that were found.
- Parameters
-
| tac | Pointer to TAC structure. |
Definition at line 23 of file tacnan.c.
26 {
27 if(tac==NULL || tac->
sampleNr<1)
return(0);
28
29 int fi, nan_nr=0;
32 if(!isfinite(tac->
x1[fi])) nan_nr++;
33 if(!isfinite(tac->
x2[fi])) nan_nr++;
34 }
35 } else {
37 if(!isfinite(tac->
x[fi])) nan_nr++;
38 }
39 }
40 return(nan_nr);
41}
Referenced by tacDelay(), tacFixNaNs(), tacInterpolate(), tacInterpolateInto(), tacIsXContiguous(), tacNaNs(), tacSetXContiguous(), tacSortByTime(), and tacVerifyTimeOrder().
◆ tacYNaNs()
| int tacYNaNs |
( |
TAC * | tac, |
|
|
const int | i ) |
Check TAC structure for missing sample values (y).
- See also
- tacNaNs, tacFixNaNs
- Returns
- Returns the number of missing values that were found.
- Parameters
-
| tac | Pointer to TAC structure. |
| i | Index of TAC to test; <0 to test all TACs. |
Definition at line 47 of file tacnan.c.
52 {
54
55 int ri, fi, nan_nr=0;
56 if(i>=0) {
58 if(!isfinite(tac->
c[i].
y[fi])) nan_nr++;
59 return(nan_nr);
60 }
61 for(ri=0; ri<tac->
tacNr; ri++)
63 if(!isfinite(tac->
c[ri].
y[fi])) nan_nr++;
64 return(nan_nr);
65}
Referenced by tacDelay(), tacFixNaNs(), and tacNaNs().