|
|
@ -7,35 +7,51 @@ dvec_alloc(char *name, int type, short flags, int length, void *storage) |
|
|
{ |
|
|
{ |
|
|
struct dvec *rv = TMALLOC(struct dvec, 1); |
|
|
struct dvec *rv = TMALLOC(struct dvec, 1); |
|
|
|
|
|
|
|
|
if (!rv) |
|
|
|
|
|
|
|
|
/* If the allocation failed, return NULL as a failure flag. |
|
|
|
|
|
* As of 2019-03, TMALLOC will not return on failure, so this check is |
|
|
|
|
|
* redundant, but it may be useful if it is decided to allow the |
|
|
|
|
|
* allocation functions to return NULL on failure and handle recovery |
|
|
|
|
|
* by the calling functions */ |
|
|
|
|
|
if (!rv) { |
|
|
return NULL; |
|
|
return NULL; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Set all fields to 0 */ |
|
|
ZERO(rv, struct dvec); |
|
|
ZERO(rv, struct dvec); |
|
|
|
|
|
|
|
|
|
|
|
/* Set information on the vector from parameters. Note that storage for |
|
|
|
|
|
* the name string belongs to the dvec when this function returns. */ |
|
|
rv->v_name = name; |
|
|
rv->v_name = name; |
|
|
rv->v_type = type; |
|
|
rv->v_type = type; |
|
|
rv->v_flags = flags; |
|
|
rv->v_flags = flags; |
|
|
rv->v_length = length; |
|
|
rv->v_length = length; |
|
|
rv->v_alloc_length = length; |
|
|
rv->v_alloc_length = length; |
|
|
|
|
|
|
|
|
if (!length) { |
|
|
|
|
|
|
|
|
if (length == 0) { /* Redundant due to ZERO() call above */ |
|
|
rv->v_realdata = NULL; |
|
|
rv->v_realdata = NULL; |
|
|
rv->v_compdata = NULL; |
|
|
rv->v_compdata = NULL; |
|
|
} else if (flags & VF_REAL) { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else if (flags & VF_REAL) { |
|
|
|
|
|
/* Vector consists of real data. Use the supplied storage if given |
|
|
|
|
|
* or allocate if not */ |
|
|
rv->v_realdata = storage |
|
|
rv->v_realdata = storage |
|
|
? (double *) storage |
|
|
? (double *) storage |
|
|
: TMALLOC(double, length); |
|
|
: TMALLOC(double, length); |
|
|
rv->v_compdata = NULL; |
|
|
rv->v_compdata = NULL; |
|
|
} else if (flags & VF_COMPLEX) { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else if (flags & VF_COMPLEX) { |
|
|
|
|
|
/* Vector holds complex data. Perform actions as for real data */ |
|
|
rv->v_realdata = NULL; |
|
|
rv->v_realdata = NULL; |
|
|
rv->v_compdata = storage |
|
|
rv->v_compdata = storage |
|
|
? (ngcomplex_t *) storage |
|
|
? (ngcomplex_t *) storage |
|
|
: TMALLOC(ngcomplex_t, length); |
|
|
: TMALLOC(ngcomplex_t, length); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Set remaining fields to none/unknown. Again not required due to |
|
|
|
|
|
* the ZERO() call */ |
|
|
rv->v_plot = NULL; |
|
|
rv->v_plot = NULL; |
|
|
rv->v_scale = NULL; |
|
|
rv->v_scale = NULL; |
|
|
rv->v_numdims = 0; |
|
|
|
|
|
|
|
|
rv->v_numdims = 0; /* Really "unknown" */ |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|