48 if ( (f = fopen(name,
"r")) != NULL ) {
50 char buf[128], *bufptr;
51 bufptr = fgets(buf,128,f);
52 sscanf( buf,
"%d", &tr->
N );
53 tr->
t = (
double*)malloc(tr->
N*
sizeof(
double));
54 tr->
s = (
float *)malloc(tr->
N*
sizeof(
float ));
55 for (
int i=0;i<tr->
N;i++)
56 n = fscanf( f,
"%lf %f\n", tr->
t+i, tr->
s+i );
60 log_msg(0, 3, 0,
"Could not open stimulus pulse file %s for reading\n", name);
78 if(tr->
t != NULL) free(tr->
t);
79 if(tr->
s != NULL) free(tr->
s);
92 double dt_o = tr->
t[1]-tr->
t[0];
94 double r_err = 0.001*dt_o;
96 for (
int i=1;i<tr->
N-1;i++) {
97 double dt_n = tr->
t[i+1]-tr->
t[i];
98 if (dt_n-dt_o > r_err)
119 int N = (int)( (tr->
t[tr->
N-1]-tr->
t[0])/dt );
120 float *s = (
float*)malloc(N*
sizeof(
float));
122 tr->
t = (
double*)malloc(tr->
N*
sizeof(
double));
123 for (
int i=0; i<tr->
N;i++) tr->
t[i] = i*tr->
dt;
149 bool tr_read =
false;
162 duration = tr->
t[tr->
N-1]-tr->
t[0];
164 duration = tr->
N*tr->
dt;
167 if (tr->
s) free(tr->
s);
168 if (tr->
t) free(tr->
t);
189 interp1(
const double *x,
const float *y,
int N,
double *xi,
float *yi,
int NI,
double dxi,
IpMeth_t meth)
192 memset(yi,0,
sizeof(
float)*NI);
195 for (
int i=0; i<NI; i++) {
198 double xv = xi!=NULL?xi[i]:x[0]+i*dxi;
201 if (xv < x[0] || xv > x[N-1])
218 yi[i] = y[i1] + (y[i2]-y[i1])/(x[i2]-x[i1])*(xv-x[i1]);
221 if ((xi[i]-x[i1])>= (x[i2]-xi[i]))
void free_trace(trace *tr)
int read_trace(trace *tr, const char *name)
void resample_trace(trace *tr, double dt)
double dt
sampling interval if equidistant samples
bool eqdist
sampling intervals are equidistant
double trace_duration(trace *tr, const char *f)
enum limpet::ip_method IpMeth_t
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
Basic utility structs and functions, mostly IO related.
manage input, output, resampling of traces
void interp1(const double *x, const float *y, int N, double *xi, float *yi, int NI, double dxi, IpMeth_t meth)
bool IsEquDistSampling(trace *tr)