-
Notifications
You must be signed in to change notification settings - Fork 6
/
utils.h
198 lines (167 loc) · 4.75 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
COPYRIGHT
Copyright (C) 2015-2016 Kyle Briggs (kbrig035<at>uottawa.ca)
This file is part of CUSUM.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UTILS_H_INCLUDED
#define UTILS_H_INCLUDED
#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>
#include<stdint.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<limits.h>
#define EPS 1e-50
#define STRLENGTH 1024
#define HEAD -1000
#define NUMTYPES 10
#define CUSUM 0
#define STEPRESPONSE 1
#define BADBASELINE 2
#define TOOLONG 3
#define TOOSHORT 4
#define BADLEVELS 5
#define BADTRACE 6
#define BADPADDING 7
#define FITERR 8
#define FITSTEP 9
//#define DEBUG
struct Chimera
{
double samplerate;
double TIAgain;
double preADCgain;
double currentoffset;
double ADCvref;
int ADCbits;
};
typedef struct Chimera chimera;
struct Cusumlevel
{
double current;
double stdev;
int64_t length;
struct Cusumlevel *next;
};
typedef struct Cusumlevel cusumlevel;
struct Histostruct
{
double **histogram;
int64_t numbins;
double offset;
double delta;
};
typedef struct Histostruct histostruct;
struct Event
{
int64_t index;
int64_t start;
int64_t finish;
int64_t length;
int type;
double area;
double baseline_before;
double baseline_after;
double average_blockage;
double max_blockage;
int64_t max_length;
double *signal;
double *filtered_signal;
double binsize;
int64_t padding_before;
int64_t padding_after;
int numlevels;
double threshold;
double rc1;
double rc2;
double residual;
double maxdeviation;
struct Edge *first_edge;
struct Cusumlevel *first_level;
};
typedef struct Event event;
struct Edge
{
int64_t location;
int64_t type;
struct Edge *next;
};
typedef struct Edge edge;
struct Configuration
{
char filepath[STRLENGTH]; //input file
char outputfolder[STRLENGTH];
char eventsfolder[STRLENGTH];
char eventsfile[STRLENGTH];
char ratefile[STRLENGTH];
char logfile[STRLENGTH];
//file reading parameters
int64_t start;
int64_t finish;
int64_t readlength;
//filter parameters
int usefilter;
int eventfilter;
double cutoff;
int64_t samplingfreq;
int64_t order; //must be even
//detection parameters
double threshold;
double hysteresis;
int64_t event_minpoints;
int64_t event_maxpoints;
double binsize;
double baseline_min;
double baseline_max;
int event_direction;
double cusum_min_threshold;
double cusum_max_threshold;
double cusum_delta;
double cusum_minstep;
int64_t subevent_minpoints;
int64_t stepfit_samples;
int64_t maxiters;
int attempt_recovery;
int datatype;
chimera *daqsetup;
};
typedef struct Configuration configuration;
FILE *fopen64_and_check(const char *fname, const char *mode, int error);
void *calloc_and_check(size_t num, size_t size, char *msg);
inline int signum(double num);
inline double my_min(double a, double b);
inline double my_max(double a, double b);
inline int64_t intmin(int64_t a, int64_t b);
inline int64_t intmax(int64_t a, int64_t b);
inline double d_abs(double num); //absolute value of a number
double ARL(int64_t length, double sigma, double mun, double h);
int64_t count_edges(edge *head_edge);
edge *initialize_edges(void);
edge *add_edge(edge *current, int64_t location, int type);
void free_edges(edge *current);
event *initialize_events(void);
event *add_event(event *current, int64_t start, int64_t finish, int64_t index);
void free_single_event(event *current);
cusumlevel *add_cusum_level(cusumlevel *lastlevel, double current, int64_t length);
void free_levels(cusumlevel *current);
cusumlevel *initialize_levels(void);
double signal_max(double *signal, int64_t length);
double signal_min(double *signal, int64_t length);
double signal_average(double *signal, int64_t length);
double signal_extreme(double *signal, int64_t length, double sign);
double signal_variance(double *signal, int64_t length);
int64_t get_filesize(FILE *input, int datatype);
inline void progressbar(int64_t pos, int64_t finish, const char *msg, double elapsed);
#endif // UTILS_H_INCLUDED