Browse Source

com_fft(), com_psd(), com_spec(), cleanup storage more thoroughly

use free_pnode() instead of free_pnode_o()
drop free_pnode_o()
rlar 14 years ago
parent
commit
01ed0ac5d9
  1. 40
      src/frontend/com_fft.c
  2. 13
      src/frontend/parse.c
  3. 1
      src/frontend/parse.h
  4. 63
      src/frontend/spec.c

40
src/frontend/com_fft.c

@ -27,30 +27,30 @@ static void fftext(double*, double*, long int, long int, int);
void
com_fft(wordlist *wl)
{
ngcomplex_t **fdvec;
double **tdvec;
double *freq, *win, *time;
ngcomplex_t **fdvec = NULL;
double **tdvec = NULL;
double *freq, *win = NULL, *time;
double delta_t, span;
int fpts, i, j, tlen, ngood;
struct dvec *f, *vlist, *lv = NULL, *vec;
struct pnode *pn, *names;
struct pnode *pn, *names = NULL;
#ifdef GREEN
int mm;
#endif
double *reald, *imagd;
double *reald = NULL, *imagd = NULL;
int size, sign, order;
double scale, sigma;
if (!plot_cur || !plot_cur->pl_scale) {
fprintf(cp_err, "Error: no vectors loaded.\n");
return;
goto done;
}
if (!isreal(plot_cur->pl_scale) ||
((plot_cur->pl_scale)->v_type != SV_TIME)) {
fprintf(cp_err, "Error: fft needs real time scale\n");
return;
goto done;
}
tlen = (plot_cur->pl_scale)->v_length;
@ -150,8 +150,7 @@ com_fft(wordlist *wl)
}
} else {
fprintf(cp_err, "Warning: unknown window type %s\n", window);
tfree(win);
return;
goto done;
}
}
@ -186,11 +185,9 @@ com_fft(wordlist *wl)
ngood++;
}
}
free_pnode_o(names);
if (!ngood) {
tfree(win);
return;
}
if (!ngood)
goto done;
plot_cur = plot_alloc("spectrum");
plot_cur->pl_next = plot_list;
@ -267,12 +264,15 @@ com_fft(wordlist *wl)
#endif
}
done:
tfree(reald);
tfree(imagd);
tfree(tdvec);
tfree(fdvec);
tfree(win);
free_pnode(names);
}
@ -281,13 +281,13 @@ com_psd(wordlist *wl)
{
ngcomplex_t **fdvec = NULL;
double **tdvec = NULL;
double *freq, *win, *time, *ave;
double *freq, *win = NULL, *time, *ave;
double delta_t, span, noipower;
int mm;
unsigned long size, ngood, fpts, i, j, tlen, jj, smooth, hsmooth;
char *s;
struct dvec *f, *vlist, *lv = NULL, *vec;
struct pnode *pn, *names;
struct pnode *pn, *names = NULL;
double *reald = NULL, *imagd = NULL;
int sign, isreal;
@ -297,12 +297,12 @@ com_psd(wordlist *wl)
if (!plot_cur || !plot_cur->pl_scale) {
fprintf(cp_err, "Error: no vectors loaded.\n");
return;
goto done;
}
if (!isreal(plot_cur->pl_scale) ||
((plot_cur->pl_scale)->v_type != SV_TIME)) {
fprintf(cp_err, "Error: fft needs real time scale\n");
return;
goto done;
}
tlen = (plot_cur->pl_scale)->v_length;
@ -454,7 +454,7 @@ com_psd(wordlist *wl)
ngood++;
}
}
free_pnode_o(names);
if (!ngood)
goto done;
@ -577,6 +577,8 @@ done:
tfree(tdvec);
tfree(fdvec);
tfree(win);
free_pnode(names);
}

13
src/frontend/parse.c

@ -445,19 +445,6 @@ free_pnode_x(struct pnode *t)
}
/* here is the original free_node, which is needed in spec.c and com_fft.c */
void
free_pnode_o(struct pnode *t)
{
if (!t)
return;
free_pnode(t->pn_left);
free_pnode(t->pn_right);
free_pnode(t->pn_next);
tfree(t);
}
static void
db_print_func(FILE *fdst, struct func *f)
{

1
src/frontend/parse.h

@ -13,6 +13,5 @@
#define free_pnode(ptr) free_pnode_x(ptr); ptr=NULL;
#endif
void free_pnode_o(struct pnode *t);
#endif

63
src/frontend/spec.c

@ -22,32 +22,32 @@ Author: 1994 Anthony E. Parker, Department of Electronics, Macquarie Uni.
void
com_spec(wordlist *wl)
{
ngcomplex_t **fdvec;
double **tdvec;
double *freq, *win, *time, *dc;
ngcomplex_t **fdvec = NULL;
double **tdvec = NULL;
double *freq, *win = NULL, *time, *dc = NULL;
double startf, stopf, stepf, span;
int fpts, i, j, k, tlen, ngood;
bool trace;
char *s;
struct dvec *f, *vlist, *lv = NULL, *vec;
struct pnode *pn, *names;
struct pnode *pn, *names = NULL;
if (!plot_cur || !plot_cur->pl_scale) {
fprintf(cp_err, "Error: no vectors loaded.\n");
return;
goto done;
}
if (!isreal(plot_cur->pl_scale) ||
((plot_cur->pl_scale)->v_type != SV_TIME)) {
fprintf(cp_err, "Error: spec needs real time scale\n");
return;
goto done;
}
s = wl->wl_word;
tlen = (plot_cur->pl_scale)->v_length;
if ((freq = ft_numparse(&s, FALSE)) == NULL || (*freq < 0.0)) {
fprintf(cp_err, "Error: bad start freq %s\n", wl->wl_word);
return;
goto done;
}
startf = *freq;
@ -55,7 +55,7 @@ com_spec(wordlist *wl)
s = wl->wl_word;
if ((freq = ft_numparse(&s, FALSE)) == NULL || (*freq <= startf)) {
fprintf(cp_err, "Error: bad stop freq %s\n", wl->wl_word);
return;
goto done;
}
stopf = *freq;
@ -63,7 +63,7 @@ com_spec(wordlist *wl)
s = wl->wl_word;
if ((freq = ft_numparse(&s, FALSE)) == NULL || !(*freq <= (stopf-startf))) {
fprintf(cp_err, "Error: bad step freq %s\n", wl->wl_word);
return;
goto done;
}
stepf = *freq;
@ -74,7 +74,7 @@ com_spec(wordlist *wl)
fprintf(cp_err,
"Error: nyquist limit exceeded, try stop freq less than %e Hz\n",
tlen/2/span);
return;
goto done;
}
span = ((int)(span*stepf*1.000000000001))/stepf;
if (span > 0) {
@ -85,7 +85,7 @@ com_spec(wordlist *wl)
} else {
fprintf(cp_err, "Error: time span limits step freq to %1.1e Hz\n",
1/(time[tlen-1] - time[0]));
return;
goto done;
}
win = TMALLOC(double, tlen);
{
@ -161,8 +161,7 @@ com_spec(wordlist *wl)
}
} else {
fprintf(cp_err, "Warning: unknown window type %s\n", window);
tfree(win);
return;
goto done;
}
}
@ -197,11 +196,9 @@ com_spec(wordlist *wl)
ngood++;
}
}
free_pnode_o(names); /* h_vogt 081206 */
if (!ngood) {
tfree(win);
return;
}
if (!ngood)
goto done;
plot_cur = plot_alloc("spectrum");
plot_cur->pl_next = plot_list;
@ -271,6 +268,7 @@ com_spec(wordlist *wl)
SetAnalyse("spec", (int)(j * 1000./ fpts));
#endif
}
if (startf == 0) {
freq[0] = 0;
for (i = 0; i < ngood; i++) {
@ -278,23 +276,28 @@ com_spec(wordlist *wl)
fdvec[i][0].cx_imag = 0;
}
}
if (trace)
fprintf(cp_err, " \r");
#ifdef KEEPWINDOW
f = alloc(struct dvec);
ZERO(f, struct dvec);
f->v_name = copy("win");
f->v_type = SV_NOTYPE;
f->v_flags = (VF_REAL | VF_PERMANENT);
f->v_length = tlen;
f->v_realdata = win;
win = NULL;
vec_new(f);
#endif
done:
tfree(dc);
tfree(tdvec);
tfree(fdvec);
#ifdef KEEPWINDOW
f = alloc(struct dvec);
ZERO(f, struct dvec);
f->v_name = copy("win");
f->v_type = SV_NOTYPE;
f->v_flags = (VF_REAL | VF_PERMANENT);
f->v_length = tlen;
f->v_realdata = win;
vec_new(f);
#else
tfree(win);
#endif
free_pnode(names);
}
Loading…
Cancel
Save