Browse Source

dvec abstraction, #1/11, reorder

pre-master-46
rlar 10 years ago
parent
commit
08ad3f6ab5
  1. 3
      src/frontend/com_compose.c
  2. 16
      src/frontend/com_fft.c
  3. 8
      src/frontend/com_let.c
  4. 7
      src/frontend/define.c
  5. 22
      src/frontend/evaluate.c
  6. 6
      src/frontend/fourier.c
  7. 4
      src/frontend/interp.c
  8. 6
      src/frontend/parse.c
  9. 17
      src/frontend/plotting/plotit.c
  10. 5
      src/frontend/postcoms.c
  11. 8
      src/frontend/spec.c
  12. 20
      src/frontend/vectors.c

3
src/frontend/com_compose.c

@ -454,7 +454,6 @@ com_compose(wordlist *wl)
result = alloc(struct dvec);
ZERO(result, struct dvec);
result->v_name = resname;
resname = NULL; /* resname storage has been consumed */
result->v_type = type;
if (realflag) {
@ -466,6 +465,8 @@ com_compose(wordlist *wl)
}
result->v_length = length;
resname = NULL; /* resname storage has been consumed */
result->v_numdims = 1;
result->v_dims[0] = length;

16
src/frontend/com_fft.c

@ -128,15 +128,15 @@ com_fft(wordlist *wl)
plot_cur->pl_name = copy("Spectrum");
plot_cur->pl_date = copy(datestring());
freq = TMALLOC(double, fpts);
f = alloc(struct dvec);
ZERO(f, struct dvec);
f->v_name = copy("frequency");
f->v_type = SV_FREQUENCY;
f->v_flags = (VF_REAL | VF_PERMANENT | VF_PRINT);
f->v_length = fpts;
f->v_realdata = freq;
f->v_realdata = TMALLOC(double, fpts);
vec_new(f);
freq = f->v_realdata;
for (i = 0; i<fpts; i++)
#ifdef HAVE_LIBFFTW3
@ -149,15 +149,15 @@ com_fft(wordlist *wl)
fdvec = TMALLOC(ngcomplex_t *, ngood);
for (i = 0, vec = vlist; i<ngood; i++) {
tdvec[i] = vec->v_realdata; /* real input data */
fdvec[i] = TMALLOC(ngcomplex_t, fpts); /* complex output data */
f = alloc(struct dvec);
ZERO(f, struct dvec);
f->v_name = vec_basename(vec);
f->v_type = SV_NOTYPE;
f->v_flags = (VF_COMPLEX | VF_PERMANENT);
f->v_length = fpts;
f->v_compdata = fdvec[i];
f->v_compdata = TMALLOC(ngcomplex_t, fpts);
vec_new(f);
fdvec[i] = f->v_compdata; /* complex output data */
vec = vec->v_link2;
}
@ -354,15 +354,15 @@ com_psd(wordlist *wl)
plot_cur->pl_name = copy("PSD");
plot_cur->pl_date = copy(datestring());
freq = TMALLOC(double, fpts);
f = alloc(struct dvec);
ZERO(f, struct dvec);
f->v_name = copy("frequency");
f->v_type = SV_FREQUENCY;
f->v_flags = (VF_REAL | VF_PERMANENT | VF_PRINT);
f->v_length = fpts;
f->v_realdata = freq;
f->v_realdata = TMALLOC(double, fpts);
vec_new(f);
freq = f->v_realdata;
#ifdef HAVE_LIBFFTW3
for (i = 0; i <= fpts; i++)
@ -376,15 +376,15 @@ com_psd(wordlist *wl)
fdvec = TMALLOC(ngcomplex_t*, ngood);
for (i = 0, vec = vlist; i<ngood; i++) {
tdvec[i] = vec->v_realdata; /* real input data */
fdvec[i] = TMALLOC(ngcomplex_t, fpts); /* complex output data */
f = alloc(struct dvec);
ZERO(f, struct dvec);
f->v_name = vec_basename(vec);
f->v_type = SV_NOTYPE; //vec->v_type;
f->v_flags = (VF_COMPLEX | VF_PERMANENT);
f->v_length = fpts;
f->v_compdata = fdvec[i];
f->v_compdata = TMALLOC(ngcomplex_t, fpts);
vec_new(f);
fdvec[i] = f->v_compdata; /* complex output data */
vec = vec->v_link2;
}

8
src/frontend/com_let.c

@ -167,6 +167,10 @@ com_let(wordlist *wl)
n->v_type = t->v_type;
n->v_flags = (t->v_flags | VF_PERMANENT);
n->v_length = t->v_length;
if (isreal(t))
n->v_realdata = TMALLOC(double, n->v_length);
else
n->v_compdata = TMALLOC(ngcomplex_t, n->v_length);
if ((t->v_numdims) <= 1) { // changed from "!t->v_numdims" by Friedrich Schmidt
n->v_numdims = 1;
@ -177,10 +181,6 @@ com_let(wordlist *wl)
n->v_dims[i] = t->v_dims[i];
}
if (isreal(t))
n->v_realdata = TMALLOC(double, n->v_length);
else
n->v_compdata = TMALLOC(ngcomplex_t, n->v_length);
newvec = 1;
vec_new(n);
}

7
src/frontend/define.c

@ -167,14 +167,17 @@ savetree(struct pnode *pn)
pn->pn_value->v_length = d->v_length;
pn->pn_value->v_type = d->v_type;
pn->pn_value->v_flags = d->v_flags;
if (isreal(d))
pn->pn_value->v_realdata = TMALLOC(double, d->v_length);
else
pn->pn_value->v_compdata = TMALLOC(ngcomplex_t, d->v_length);
pn->pn_value->v_plot = NULL; /* this dvec isn't member of any plot */
if (isreal(d)) {
pn->pn_value->v_realdata = TMALLOC(double, d->v_length);
bcopy(d->v_realdata,
pn->pn_value->v_realdata,
sizeof(double) * (size_t) d->v_length);
} else {
pn->pn_value->v_compdata = TMALLOC(ngcomplex_t, d->v_length);
bcopy(d->v_compdata,
pn->pn_value->v_compdata,
sizeof(ngcomplex_t) * (size_t) d->v_length);

22
src/frontend/evaluate.c

@ -620,11 +620,15 @@ op_range(struct pnode *arg1, struct pnode *arg2)
res->v_name = mkcname('R', v->v_name, ind->v_name);
res->v_type = v->v_type;
res->v_flags = v->v_flags;
res->v_length = len;
if (isreal(res))
res->v_realdata = TMALLOC(double, len);
else
res->v_compdata = TMALLOC(ngcomplex_t, len);
res->v_gridtype = v->v_gridtype;
res->v_plottype = v->v_plottype;
res->v_defcolor = v->v_defcolor;
res->v_length = len;
res->v_scale = /* nscale; */ scale;
/* Dave says get rid of this
res->v_numdims = v->v_numdims;
@ -634,11 +638,6 @@ op_range(struct pnode *arg1, struct pnode *arg2)
res->v_numdims = 1;
res->v_dims[0] = len;
if (isreal(res))
res->v_realdata = TMALLOC(double, len);
else
res->v_compdata = TMALLOC(ngcomplex_t, len);
/* Toss in the data */
j = 0;
@ -777,11 +776,15 @@ op_ind(struct pnode *arg1, struct pnode *arg2)
res->v_name = mkcname('[', v->v_name, ind->v_name);
res->v_type = v->v_type;
res->v_flags = v->v_flags;
res->v_length = length;
if (isreal(res))
res->v_realdata = TMALLOC(double, length);
else
res->v_compdata = TMALLOC(ngcomplex_t, length);
res->v_defcolor = v->v_defcolor;
res->v_gridtype = v->v_gridtype;
res->v_plottype = v->v_plottype;
res->v_length = length;
res->v_numdims = newdim;
if (up != down) {
for (i = 0; i < newdim; i++)
@ -792,11 +795,6 @@ op_ind(struct pnode *arg1, struct pnode *arg2)
res->v_dims[i] = v->v_dims[i + 1];
}
if (isreal(res))
res->v_realdata = TMALLOC(double, length);
else
res->v_compdata = TMALLOC(ngcomplex_t, length);
/* And toss in the new data */
for (j = 0; j < up - down + 1; j++) {
if (rev)

6
src/frontend/fourier.c

@ -191,20 +191,20 @@ fourier(wordlist *wl, struct plot *current_plot)
/* create and assign a new vector n */
/* with size 3 * nfreqs in current plot */
/* generate name for new vector, using vec->name */
n = alloc(struct dvec);
ZERO(n, struct dvec);
/* generate name for new vector, using vec->name */
n->v_name = tprintf("fourier%d%d", callstof, newveccount);
n->v_type = SV_NOTYPE;
n->v_flags = (VF_REAL | VF_PERMANENT);
n->v_length = 3 * nfreqs;
n->v_realdata = TMALLOC(double, n->v_length);
n->v_numdims = 2;
n->v_dims[0] = 3;
n->v_dims[1] = nfreqs;
n->v_realdata = TMALLOC(double, n->v_length);
vec_new(n);
/* store data in vector: freq, mag, phase */

4
src/frontend/interp.c

@ -36,15 +36,15 @@ lincopy(struct dvec *ov, double *newscale, int newlen, struct dvec *oldscale)
v->v_flags = ov->v_flags;
v->v_flags |= VF_PERMANENT;
v->v_length = newlen;
v->v_realdata = TMALLOC(double, newlen);
nd = TMALLOC(double, newlen);
nd = v->v_realdata;
if (!ft_interpolate(ov->v_realdata, nd, oldscale->v_realdata,
oldscale->v_length, newscale, newlen, 1))
{
fprintf(cp_err, "Error: can't interpolate %s\n", ov->v_name);
return;
}
v->v_realdata = nd;
vec_new(v);
}

6
src/frontend/parse.c

@ -344,9 +344,11 @@ PP_mknnode(double number)
v->v_type = SV_NOTYPE;
v->v_flags = VF_REAL;
v->v_realdata = TMALLOC(double, 1);
*v->v_realdata = number;
v->v_length = 1;
v->v_plot = NULL;
v->v_realdata[0] = number;
vec_new(v);
p = alloc_pnode();
@ -368,8 +370,8 @@ PP_mksnode(const char *string)
if (v == NULL) {
nv = alloc(struct dvec);
ZERO(nv, struct dvec);
p->pn_value = nv;
nv->v_name = copy(string);
p->pn_value = nv;
return (p);
}

17
src/frontend/plotting/plotit.c

@ -97,17 +97,21 @@ xtend(struct dvec *v, int length)
i = v->v_length;
if (isreal(v)) {
double d = NAN;
v->v_realdata = TREALLOC(double, v->v_realdata, length);
v->v_length = length;
} else {
v->v_compdata = TREALLOC(ngcomplex_t, v->v_compdata, length);
v->v_length = length;
}
if (isreal(v)) {
double d = NAN;
if (i > 0)
d = v->v_realdata[i - 1];
while (i < length)
v->v_realdata[i++] = d;
} else {
ngcomplex_t c = {NAN, NAN};
v->v_compdata = TREALLOC(ngcomplex_t, v->v_compdata, length);
v->v_length = length;
if (i > 0)
c = v->v_compdata[i - 1];
while (i < length)
@ -910,18 +914,19 @@ plotit(wordlist *wl, char *hcopy, char *devname)
{
int newlen = (int)((tstop - tstart) / tstep + 1.5);
double *newscale = TMALLOC(double, newlen);
double *newscale;
struct dvec *newv_scale = alloc(struct dvec);
struct dvec *v;
newv_scale->v_name = copy(vecs->v_scale->v_name);
newv_scale->v_flags = vecs->v_scale->v_flags;
newv_scale->v_type = vecs->v_scale->v_type;
newv_scale->v_gridtype = vecs->v_scale->v_gridtype;
newv_scale->v_length = newlen;
newv_scale->v_name = copy(vecs->v_scale->v_name);
newv_scale->v_realdata = newscale;
newv_scale->v_realdata = TMALLOC(double, newlen);
newscale = newv_scale->v_realdata;
for (i = 0, ttime = tstart; i < newlen; i++, ttime += tstep)
newscale[i] = ttime;

5
src/frontend/postcoms.c

@ -770,10 +770,10 @@ com_cross(wordlist *wl)
v->v_length = i;
if (comp) {
v->v_flags = VF_COMPLEX;
v->v_flags = VF_COMPLEX | VF_PERMANENT;
v->v_compdata = TMALLOC(ngcomplex_t, i);
} else {
v->v_flags = VF_REAL;
v->v_flags = VF_REAL | VF_PERMANENT;
v->v_realdata = TMALLOC(double, i);
}
@ -795,7 +795,6 @@ com_cross(wordlist *wl)
}
}
vec_new(v);
v->v_flags |= VF_PERMANENT;
cp_addkword(CT_VECTOR, v->v_name);
done:

8
src/frontend/spec.c

@ -207,29 +207,29 @@ com_spec(wordlist *wl)
plot_cur->pl_name = copy("Spectrum");
plot_cur->pl_date = copy(datestring());
freq = TMALLOC(double, fpts);
f = alloc(struct dvec);
ZERO(f, struct dvec);
f->v_name = copy("frequency");
f->v_type = SV_FREQUENCY;
f->v_flags = (VF_REAL | VF_PERMANENT | VF_PRINT);
f->v_length = fpts;
f->v_realdata = freq;
f->v_realdata = TMALLOC(double, fpts);
vec_new(f);
freq = f->v_realdata;
tdvec = TMALLOC(double *, ngood);
fdvec = TMALLOC(ngcomplex_t *, ngood);
for (i = 0, vec = vlist; i < ngood; i++) {
tdvec[i] = vec->v_realdata;
fdvec[i] = TMALLOC(ngcomplex_t, fpts);
f = alloc(struct dvec);
ZERO(f, struct dvec);
f->v_name = vec_basename(vec);
f->v_type = vec->v_type;
f->v_flags = (VF_COMPLEX | VF_PERMANENT);
f->v_length = fpts;
f->v_compdata = fdvec[i];
f->v_compdata = TMALLOC(ngcomplex_t, fpts);
vec_new(f);
fdvec[i] = f->v_compdata;
vec = vec->v_link2;
}

20
src/frontend/vectors.c

@ -690,23 +690,26 @@ vec_copy(struct dvec *v)
nv->v_type = v->v_type;
nv->v_flags = v->v_flags & ~VF_PERMANENT;
nv->v_length = v->v_length;
if (isreal(v)) {
nv->v_realdata = TMALLOC(double, v->v_length);
bcopy(v->v_realdata, nv->v_realdata,
sizeof(double) * (size_t) v->v_length);
nv->v_compdata = NULL;
} else {
nv->v_realdata = NULL;
nv->v_compdata = TMALLOC(ngcomplex_t, v->v_length);
}
if (isreal(v))
bcopy(v->v_realdata, nv->v_realdata,
sizeof(double) * (size_t) v->v_length);
else
bcopy(v->v_compdata, nv->v_compdata,
sizeof(ngcomplex_t) * (size_t) v->v_length);
}
nv->v_minsignal = v->v_minsignal;
nv->v_maxsignal = v->v_maxsignal;
nv->v_gridtype = v->v_gridtype;
nv->v_plottype = v->v_plottype;
nv->v_length = v->v_length;
/* Modified to copy the rlength of origin to destination vecor
* instead of always putting it to 0.
@ -1125,6 +1128,12 @@ vec_mkfamily(struct dvec *v)
d->v_name = tprintf("%s%s", v->v_name, buf2);
d->v_type = v->v_type;
d->v_flags = v->v_flags;
d->v_length = size;
if (isreal(v))
d->v_realdata = TMALLOC(double, size);
else
d->v_compdata = TMALLOC(ngcomplex_t, size);
d->v_minsignal = v->v_minsignal;
d->v_maxsignal = v->v_maxsignal;
d->v_gridtype = v->v_gridtype;
@ -1135,13 +1144,10 @@ vec_mkfamily(struct dvec *v)
*/
d->v_numdims = 1;
d->v_dims[0] = size;
d->v_length = size;
if (isreal(v)) {
d->v_realdata = TMALLOC(double, size);
bcopy(v->v_realdata + size*i, d->v_realdata, (size_t) size * sizeof(double));
} else {
d->v_compdata = TMALLOC(ngcomplex_t, size);
bcopy(v->v_compdata + size*i, d->v_compdata, (size_t) size * sizeof(ngcomplex_t));
}
/* Add one to the counter. */

Loading…
Cancel
Save