dvec abstraction, #11/11, introduce `dvec_realloc()'
This commit is contained in:
parent
c2a7821449
commit
df70661c3a
|
|
@ -40,6 +40,29 @@ dvec_alloc(char *name, int type, short flags, int length, void *storage)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
dvec_realloc(struct dvec *v, int length, void *storage)
|
||||
{
|
||||
if (isreal(v)) {
|
||||
if (storage) {
|
||||
tfree(v->v_realdata);
|
||||
v->v_realdata = (double *) storage;
|
||||
} else {
|
||||
v->v_realdata = TREALLOC(double, v->v_realdata, length);
|
||||
}
|
||||
} else {
|
||||
if (storage) {
|
||||
tfree(v->v_compdata);
|
||||
v->v_compdata = (ngcomplex_t *) storage;
|
||||
} else {
|
||||
v->v_compdata = TREALLOC(ngcomplex_t, v->v_compdata, length);
|
||||
}
|
||||
}
|
||||
|
||||
v->v_length = length;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dvec_trunc(struct dvec *v, int length)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -96,13 +96,7 @@ xtend(struct dvec *v, int length)
|
|||
|
||||
i = v->v_length;
|
||||
|
||||
if (isreal(v)) {
|
||||
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;
|
||||
}
|
||||
dvec_realloc(v, length, NULL);
|
||||
|
||||
if (isreal(v)) {
|
||||
double d = NAN;
|
||||
|
|
@ -138,15 +132,12 @@ compress(struct dvec *d, double *xcomp, double *xind)
|
|||
if (isreal(d)) {
|
||||
double *dd = TMALLOC(double, newlen);
|
||||
bcopy(d->v_realdata + ilo, dd, (size_t) newlen * sizeof(double));
|
||||
tfree(d->v_realdata);
|
||||
d->v_realdata = dd;
|
||||
dvec_realloc(d, newlen, dd);
|
||||
} else {
|
||||
ngcomplex_t *cc = TMALLOC(ngcomplex_t, newlen);
|
||||
bcopy(d->v_compdata + ilo, cc, (size_t) newlen * sizeof(ngcomplex_t));
|
||||
tfree(d->v_compdata);
|
||||
d->v_compdata = cc;
|
||||
dvec_realloc(d, newlen, cc);
|
||||
}
|
||||
d->v_length = newlen;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -938,9 +929,7 @@ plotit(wordlist *wl, char *hcopy, char *devname)
|
|||
goto quit;
|
||||
}
|
||||
|
||||
tfree(v->v_realdata);
|
||||
v->v_realdata = newdata;
|
||||
v->v_length = newlen;
|
||||
dvec_realloc(v, newlen, newdata);
|
||||
|
||||
/* Why go to all this trouble if agraf ignores it? */
|
||||
nointerp = TRUE;
|
||||
|
|
|
|||
|
|
@ -576,8 +576,7 @@ vec_get(const char *vec_name)
|
|||
for (nv = vv->va_vlist; nv; nv = nv->va_next)
|
||||
i++;
|
||||
|
||||
d->v_realdata = TREALLOC(double, d->v_realdata, i);
|
||||
d->v_length = i;
|
||||
dvec_realloc(d, i, NULL);
|
||||
|
||||
i = 0;
|
||||
for (nv = vv->va_vlist; nv; nv = nv->va_next)
|
||||
|
|
@ -1054,8 +1053,7 @@ vec_transpose(struct dvec *v)
|
|||
}
|
||||
koffset += blocksize; /* koffset = k*blocksize = k*dim0*dim1 */
|
||||
}
|
||||
tfree(oldreal);
|
||||
v->v_realdata = newreal;
|
||||
dvec_realloc(v, v->v_length, newreal);
|
||||
} else {
|
||||
newcomp = TMALLOC(ngcomplex_t, v->v_length);
|
||||
oldcomp = v->v_compdata;
|
||||
|
|
@ -1073,8 +1071,7 @@ vec_transpose(struct dvec *v)
|
|||
}
|
||||
koffset += blocksize; /* koffset = k*blocksize = k*dim0*dim1 */
|
||||
}
|
||||
tfree(oldcomp);
|
||||
v->v_compdata = newcomp;
|
||||
dvec_realloc(v, v->v_length, newcomp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ struct dveclist {
|
|||
};
|
||||
|
||||
struct dvec *dvec_alloc(char *name, int type, short flags, int length, void *storage);
|
||||
void dvec_realloc(struct dvec *v, int length, void *storage);
|
||||
void dvec_trunc(struct dvec *v, int length);
|
||||
void dvec_free(struct dvec *);
|
||||
|
||||
|
|
|
|||
|
|
@ -174,12 +174,7 @@ oldread(char *name)
|
|||
np = i / nv;
|
||||
|
||||
for (v = pl->pl_dvecs; v; v = v->v_next) {
|
||||
v->v_length = (int) np;
|
||||
if (isreal(v)) {
|
||||
v->v_realdata = TMALLOC(double, np);
|
||||
} else {
|
||||
v->v_compdata = TMALLOC(ngcomplex_t, np);
|
||||
}
|
||||
dvec_realloc(v, (int) np, NULL);
|
||||
}
|
||||
for (i = 0; i < np; i++) {
|
||||
/* Read in the output vector for point i. If the type is
|
||||
|
|
|
|||
Loading…
Reference in New Issue