45 for(
int i=0; i<tr->
N; i++ )
46 if( tr->
dt*i >= whenceforth )
66 tr->
t = (
double*)malloc(tr->
N*
sizeof(
double));
67 tr->
s = (
float *)malloc(tr->
N*
sizeof(
float ));
68 tr->
t[0] = 0 ; tr->
s[0] = 0 ;
69 tr->
t[1] = 0.1 ; tr->
s[1] = st ;
70 tr->
t[2] = 1 ; tr->
s[2] = st ;
71 tr->
t[3] = 1.1 ; tr->
s[3] = 0 ;
72 tr->
t[4] = delay ; tr->
s[4] = 0 ;
73 tr->
t[5] = delay+0.1 ; tr->
s[5] =
clamp ;
74 tr->
t[6] = delay+dur ; tr->
s[6] =
clamp ;
75 tr->
t[7] = delay+dur+0.1 ; tr->
s[7] = 0 ;
95 if ( (f = fopen(name,
"r")) != NULL ) {
97 char buf[128], *bufptr;
98 bufptr = fgets(buf,128,f);
99 sscanf( buf,
"%d", &tr->
N );
100 tr->
t = (
double*)malloc(tr->
N*
sizeof(
double));
101 tr->
s = (
float *)malloc(tr->
N*
sizeof(
float ));
102 for (
int i=0;i<tr->
N;i++)
103 n = fscanf( f,
"%lf %f\n", tr->
t+i, tr->
s+i );
107 log_msg(0, 3, 0,
"Could not open stimulus pulse file %s for reading\n", name);
125 if(tr->
t != NULL) free(tr->
t);
126 if(tr->
s != NULL) free(tr->
s);
139 double dt_o = tr->
t[1]-tr->
t[0];
141 double r_err = 0.001*dt_o;
143 for (
int i=1;i<tr->
N-1;i++) {
144 double dt_n = tr->
t[i+1]-tr->
t[i];
145 if (dt_n-dt_o > r_err)
166 int N = (int)( (tr->
t[tr->
N-1]-tr->
t[0])/dt )+1;
167 float *s = (
float*)malloc(N*
sizeof(
float));
169 tr->
t = (
double*)malloc(tr->
N*
sizeof(
double));
170 for (
int i=0; i<tr->
N;i++) tr->
t[i] = i*tr->
dt;
196 bool tr_read =
false;
209 duration = tr->
t[tr->
N-1]-tr->
t[0];
211 duration = tr->
N*tr->
dt;
214 if (tr->
s) free(tr->
s);
215 if (tr->
t) free(tr->
t);
236 interp1(
const double *x,
const float *y,
int N,
double *xi,
float *yi,
int NI,
double dxi,
IpMeth_t meth)
239 memset(yi,0,
sizeof(
float)*NI);
242 for (
int i=0; i<NI; i++) {
245 double xv = xi!=NULL?xi[i]:x[0]+i*dxi;
248 if (xv < x[0] || xv > x[N-1])
265 yi[i] = y[i1] + (y[i2]-y[i1])/(x[i2]-x[i1])*(xv-x[i1]);
268 if ((xi[i]-x[i1])>= (x[i2]-xi[i]))
Basic utility structs and functions, mostly IO related.
#define log_msg(F, L, O,...)
V clamp(const V val, const W start, const W end)
Clamp a value into an interval [start, end].
int mk_RRC_trace(trace *tr, float st, float delay, float clamp, float dur)
make a trace for a repolarization reserve current calculation
double trace_duration(trace *tr, const char *f)
void resample_trace(trace *tr, double dt)
void free_trace(trace *tr)
void set_trace_amp(trace *tr, float val, float whenceforth)
change the amplitude of part of a trace
void interp1(const double *x, const float *y, int N, double *xi, float *yi, int NI, double dxi, IpMeth_t meth)
int read_trace(trace *tr, const char *name)
bool IsEquDistSampling(trace *tr)
enum limpet::ip_method IpMeth_t
manage input, output, resampling of traces
double dt
sampling interval if equidistant samples
bool eqdist
sampling intervals are equidistant