#include "brttutil.h" BUVector2 * buvector2_create (int nx, int ny, char *tag, char *handle) int buvector2_free (char *handle) int buvector2_free_tag (char *tag) void buvector2_free_vector (BUVector2 *vector) BUVector2 * buvector2_get_vector (char *handle) BUVector2 * buvector2_read(char *fname, char *tag, int line_off, int xpos, int ny, int *ypos, int lpos, char *handle) BUVector2 * buvector2_create_tsamp (int nsamp, double time, double samprate, double *data, char *tag, char *handle) BUVector2 * buvector2_create_response_fap (char *filename, char *tag, char *handle, int *err) BUVector2 * buvector2_create_from_pf (Pf *pf, char *name, char *tag, char *handle, int *err) int buvector2_resize (char *handle) BUVector2 * buvector2_copy (char *in_handle, char *tag, char *handle) int buvector2_append(char *handle, int index, double x, double *y, char *label) int buvector2_put(char *handle, int index, double x, double *y, char *label) int buvector2_puty(char *handle, int index, double *y, char *label) int buvector2_get_point(char *handle, int index, double *x, double *y, char *label) int buvector2_get_points (char *handle, int iy, int *nx, int *ny, double **xpts, int *xpts_size, double **ypts, int *ypts_size, char ***labels) int buvector2_eval(char *handle, double x, double *y) int buvector2_maxmin(char *handle, int iy, double *xmin, double *xmax, double *ymin, double *ymax) int buvector2_transform_edp (char *handle, double lonr, double latr) int buvector2_dump(char *handle) int buvector2_get_heap_size (char *tag, char *handle, long *nobjects, long *heap_total, long *cache_objects, long *cache_total, long *nmallocs, long *nreallocs, long *nstrdups, long *nfrees) int buvector2_set_cache (long max_size) BUVector2 * buvector2_stats(Tbl *buvector2_handles, char *type, char *tag, char *handle) BUVector2 * buvector2_copy_1y (char *in_handle, int yindex, char *tag, char *handle) BUVector2 * buvector2_create_tsamp_from_db (Dbptr db, double t0, double t1, char *sta, char *chan, int apply_calib, int calib_from_wfdisc, double *calib, double *calper, char *segtype, char *tag, char *handle) int buvector2_resize_y (char *handle, int ny) int buvector2_transform_invertx (char *handle) int buvector2_transform_spec (char *handle, int ndif, int iy) int buvector2_transform_ygain (char *handle, double ygain, int iy) int buvector2_fill (char *handle, int nx, int ny, double *xpts, void *vypts, char **labels ) int buvector2_maxmin2(char *handle, int iy, double xstart, double xend, double *xmin, double *xmax, double *ymin, double *ymax) long buvector2_nearest(char *handle, int iy, double x, double y)
These subroutines create and manipulate generic BRTT utility data vector2 objects (aka buvector2 objects). A buvector2 object is similar to a buvector object (buvector(3)) and consists of a set of floating dependent (Y) values, along with an optional character string label, as a function of a single independent (X) variable. Each point in the vector consists of one or more dependent (Y) values and an optional character string label for a single independent (X) value. The major difference between buvector2 objects and buvector objects is in the underlying heap memory management. buvector objects allocate and free heap memory using standard malloc(3) and free(3) every time an object needs to acquire or release heap memory. buvector2 objects will hang onto heap memory that has been previously allocated using malloc(3) and reuse that memory when a new buvector2 object is needed. Use of buvector2 objects can reduce the amount of inactive heap memory that accumulates when there are lots of object creations and destructions in the course of a program execution.
buvector2_create will create an empty buvector2 object and return a pointer to the object, or NULL if there is an error. nx and ny can be specified as positive integers to preset the memory allocation. If nx is set to 0, then the number of X points is set dynamically as data is appended. If ny is set to 0, then it is assumed there is only one dependent Y value. Note that setting ny in this call sets a fixed number of Y dependent values for subsequent calls using this object. tag can be used to specify a character string tag associated with the new object. An object handle is returned in handle and this handle is used for most subsequent calls to the new object.
buvector2_free will free the resources associated with the buvector2 object referenced by handle.
buvector2_free_tag will free the resources associated with all of the buvector2 objects whose tag is tag.
buvector2_free_vector will free the resources associated with the buvector2 object pointer vector.
buvector2_get_vector will return the buvector2 object pointer referenced by handle.
buvector2_read will create a buvector2 object by reading data values from an ASCII file with name fname and return a pointer to the object, or NULL if there is an error. tag can be used to specify a character string tag associated with the new object. An object handle is returned in handle and this handle is used for most subsequent calls to the new object. The input file must be in ASCII format with each line representing a single element (X value) in the vector. Lines starting with the # character or blank lines are ignored. The numerical values in each line must be white space delimited. The X independent data value is specified by the xpos'th numerical value (word) in each line (starting with 0). Each of the ny Y dependent values are specified by the ypos array values in each line (starting with 0). A character string label for each X independent data value can be specified with the lpos value in the same manner as the Y dependent values (-1 means no label). A line offset in the file can be specified by line_off which will cause line_off lines to be skipped at the beginning of the file before processing starts.
buvector2_create_tsamp will create a buvector2 object from a time sampled data waveform with nsamp points, sample rate samprate samples per second, epoch time of first sample time, sample values in array data, and return a pointer to the object, or NULL if there is an error. tag can be used to specify a character string tag associated with the new object. An object handle is returned in handle and this handle is used for most subsequent calls to the new object. A time sampled vector object is one in which the X dependent variable is absolute epochal time, there is a single Y dependent variable which contains the sample values and there are no data lables.
buvector2_create_response_fap will create a buvector2 object from an ASCII file with file name filename which is in either fap or fap2 external instrument response file format (see response(5)) and return a pointer to the object, or NULL if there is an error. tag can be used to specify a character string tag associated with the new object. An object handle is returned in handle and this handle is used for most subsequent calls to the new object. The frequency of the response is treated as the X independent data value and the amplitude, phase and optional error bounds are treated as the Y dependent values. Error returns, indicated by a NULL return value, are further specified in err, where a value of -1 means fatal memory allocation errors and +1 means errors parsing the input response file.
buvector2_create_from_pf will create a buvector2 object from an Antelope parameter file object, pf, and return a pointer to the object, or NULL if there is an error. The parameter file object must contain a table with name name. Each line of the table is parse as an ASCII string. The first whitespace delimited field in each string is read as the X-value and following fields are read as Y-values. tag can be used to specify a character string tag associated with the new object. An object handle is returned in handle and this handle is used for most subsequent calls to the new object.
buvector2_copy will create a buvector2 object by copying an already existing object referenced by in_handle and return a pointer to the object, or NULL if there is an error. tag can be used to specify a character string tag associated with the new object. An object handle is returned in handle and this handle is used for most subsequent calls to the new object.
buvector2_resize will double the number of points (X values) in the memory allocation for the object referenced by handle.
buvector2_append causes a new vector element to be appended after an existing element in a buvector2 object referenced by handle. The new vector element, as specified by x X-value, y Y-value array and optional label, is appended after the index'th vector element (starting with 0). If index is -1, then the new element is append at the end of the vector.
buvector2_put causes a point in a buvector2 object referenced by handle to be replaced with the X-value, as specified by x, and the list of Y-values, as specified by the y array, for the index'th X point in the vector (starting with 0). The optional character string label value can also be replaced. This will error exit if the vector is a constant time sampled vector since the X(time) values for such a vector cannot ne specified individually.
buvector2_puty causes the Y dependent values to be replaced in a buvector2 object referenced by handle. with the list of Y-values, as specified by the y array, for the index'th X point in the vector (starting with 0). The optional character string label value can also be replaced.
buvector2_get_point returns a single X-value in x, the associated Y-values in the array y and the label in label for the index'th X point in the buvector2 object referenced by handle.
buvector2_get_points returns all of the points in the buvector2 object referenced by handle. The number of points (X-values) is returned in nx. The number of Y-values is returned in ny if ny is set to -1 upon entry. Otherwise, ny upon entry specifies that only the ny'th Y-value should be returned (starting at 0). The returned X-values, Y-values and labels are referenced by xpts, xpts_size, ypts, ypts_size and labels. The returned arrays are allocated if the input values of *xpts, *ypts are NULL, or are reallocated if necessary according to the input values of *xpts_size and *ypts_size. If label is not NULL, then it is returned as a reference to a dynamically allocated array of strdup'ed labels for each of the npts values in the vector object.
buvector2_eval causes the Y dependent values, corresponding to the single x X-value, to be returned in the y array for the buvector2 object referenced by handle. Linear interpolation is used to evaluate the Y values for an X value that is not exactly equal to one of the vector points.
buvector2_maxmin returns minimum and maximum X and Y values in xmin, xmax, ymin, ymax for the buvector2 object referenced by handle. If iy is set to -1, then all of the Y-values are used to compute the maxima and minima, otherwise only the iy,th Y values are used to compute the maxima and minima.
buvector2_transform_edp will transform a vector's X-Y coordinates, assumed to be X=longitude and a single Y-value with Y=latitude, to equal distance projection coordinates relative to longitude lonr and latitude latr for the buvector2 object referenced by handle. The transformation is done to the vector coordinates in place.