36#define MAXPATHLEN (MAX_PATH*4)
49 : ymin(FLT_MAX), ymax(-FLT_MAX), mean_x_spacing(1.0)
55 if (
data.size()==0)
return;
62 typedef vector < Pair >::const_iterator Ptype;
63 for (Ptype p =
data.begin(); p !=
data.end(); p++) {
72 size_t n =
data.size();
79 FILE *in = fopen(filename.c_str(),
"rb");
87 char tmp_str[MAXPATHLEN];
89 while (fgets(buf, MAXPATHLEN, in)) {
94 if (sscanf(buf,
" %f%[^.0-9-]%f", &
x, tmp_str, &
y) != 3) {
111 FILE *out = fopen(filename.c_str(),
"wb");
113 LOGERR(
"cannot open xydata file '%s' to write", filename.c_str());
117 typedef vector < Pair >::const_iterator Ptype;
118 for (Ptype p =
data.begin(); p !=
data.end(); p++) {
119 fprintf(out,
"%1.6g\t%1.6g\n", p->x, p->y);
131 size_t n =
data.size();
132 float x0 =
data[0].x;
133 float xn =
data[n - 1].x;
135 if (maxx <= minx || minx >= xn || maxx <= x0) {
136 LOGERR(
"incorrect minx, maxx=%f,%f for this XYData range [%f,%f]",
146 for (
size_t i = 0; i < n; i++) {
149 float selfy =
data[i].y;
153 norm1 += selfy * selfy;
158 float result = scc /
sqrt(norm1 * norm2);
165 for (
int i=0; i<n; i++) {
168 data[i].y=exp(-
x*
x/(width*width));
176 int nx = (int)
data.size();
178 if (
x<
data[0].
x)
return outzero?0.0f:
data[0].y;
179 if (
x>
data[nx-1].
x)
return outzero?0.0f:
data[nx-1].y;
185 while (s>0 &&
data[s].
x >
x) s--;
186 while (s<(nx-1) &&
data[s + 1].x <
x ) s++;
187 if (s>nx-2)
return outzero?0.0f:
data[nx-1].y;
190 float y =
data[s].y * (1 - f) +
data[s + 1].
y * f;
196 if (
data.size()==0)
return 0.0;
197 if (
data.size()==1)
return data[0].y;
200 int nx = (int)
data.size();
208 while (s>0 &&
data[s].
x >
x) s--;
209 while (s<(nx-2) &&
data[s + 1].x <
x ) s++;
222 if (s==0 &&s2==nx-1)
return data[nx/2].y;
255 for (std::vector<Pair>::iterator it =
data.begin() ; it+1 <
data.end(); ++it) {
256 while (it+1<
data.end() && it->x==(it+1)->x) {
271 if(xlist.size() != ylist.size()) {
275 for(
unsigned int i=0; i<xlist.size(); ++i) {
276 data.push_back(
Pair(xlist[i], ylist[i]));
287 vector<Pair>::const_iterator cit;
288 for(cit=
data.begin(); cit!=
data.end(); ++cit) {
289 list.push_back( (*cit).x);
290 list.push_back( (*cit).y);
298 if(list.size()%2==1) {
303 for(
unsigned int i=0; i<list.size(); i+=2) {
304 data.push_back(
Pair(list[i], list[i+1]));
313 vector<Pair>::const_iterator cit;
314 for(cit=
data.begin(); cit!=
data.end(); ++cit) {
315 xlist.push_back( (*cit).x);
324 vector<Pair>::const_iterator cit;
325 for(cit=
data.begin(); cit!=
data.end(); ++cit) {
326 ylist.push_back( (*cit).y);
XYData defines a 1D (x,y) data set.
void make_gauss(int n, float xmax, float width)
float calc_correlation(XYData *xy, float minx, float maxx) const
float get_yatx(float x, bool outzero=true)
float get_yatx_smooth(float x, int smoothing)
void insort(float x, float y)
int write_file(const string &filename) const
void set_xy_list(const vector< float > &xlist, const vector< float > &ylist)
bool is_validx(float x) const
vector< float > get_xlist() const
vector< float > get_state() const
int read_file(const string &filename)
vector< float > get_ylist() const
void set_state(vector< float >)
EMData * sqrt() const
return square root of current image
#define InvalidParameterException(desc)
#define FileAccessException(filename)