PRO generate_polynomial_basis_1dvec, xsize, fx, x0, polyterms, hires, polybasis, status
; Description: This module generates a set of one-dimensional polynomial basis functions for a coordinate
; vector of length "xsize" pixels. The one-dimensional vector coordinate x is related to
; a transformed coordinate X as follows:
;
; X = fx*(x - x0)
;
; The polynomial basis functions, corresponding to the polynomial terms "polyterms",
; are calculated as a function of the transformed coordinate X, and they are stored in
; the output array "polybasis". The pixel values in the polynomial basis functions are
; calculated from a grid that samples the basis functions at "hires" times the resolution
; of the vector pixels, which gives the user the option of accurately calculating the
; integrals over the discrete pixels.
;
; Input Parameters:
;
; xsize - INTEGER/LONG - The length (pix) of the polynomial basis functions. This parameter must be
; positive.
; fx - FLOAT/DOUBLE - The x coordinate scale factor as defined above. This parameter must be non-zero.
; x0 - FLOAT/DOUBLE - The x coordinate offset (pix) as defined above.
; polyterms - INTEGER/LONG VECTOR - A one-dimensional vector of length "nterms" that contains the
; exponents of the x spatial variable for each polynomial term. All
; values in this vector must be non-negative.
; hires - INTEGER/LONG - The oversampling factor to be used to calculate the polynomial basis
; functions. This parameter must be positive. The minimum allowed value of
; "1" corresponds to no oversampling.
;
; Output Parameters:
;
; polybasis - DOUBLE ARRAY - A two-dimensional array of size "nterms" by "xsize" elements, where
; "nterms" is the number of polynomial terms in the input parameter
; "polyterms". This array contains the "nterms" polynomial basis
; functions (which are vectors) corresponding to each polynomial term.
; Hence the vector "polybasis[i,*]" is the polynomial basis function
; corresponding to the ith polynomial term.
; status - INTEGER - If the module successfully generated the polynomial basis function array, then
; "status" is returned with a value of "1", otherwise it is returned with a
; value of "0".
;
; N.B: In DanIDL, I adopt a pixel coordinate system such that the origin of the coordinate system is
; at the left hand side of the left hand pixel in a vector. Therefore, the centre of the left
; hand pixel in a vector has an x coordinate of 0.5 in this coordinate system. For each full
; pixel moved to the right in the vector, the x pixel coordinate increments by 1.
;
; Author: Dan Bramich (dan.bramich@hotmail.co.uk)
;
; History:
;
; 10/12/2010 - Module created (dmb).
;Set the default output parameter values
;Check that "xsize" is a positive number of the correct type
;Check that "fx" and "x0" are numbers of the correct type, and that "fx" is non-zero
;Check that "polyterms" is a one-dimensional vector of the correct number type, and that it has no
;negative elements
;Check that "hires" is a positive number of the correct type
;Determine the unique set of powers of x
;If the only unique power of x is "0"
;Generate the output polynomial basis function array
;Set "status" to "1" and finish
;Generate the transformed coordinate vector for the oversampled polynomial basis functions
;Set up the output polynomial basis function array
;For each unique power of x
;Extract the current unique power of x
;Determine the set of like polynomial terms
;If the current unique power of x is "0"
;Generate and store the polynomial basis function corresponding to the current unique power of x
;If the current unique power of x is not "0"
;Generate the oversampled polynomial basis function corresponding to the current unique power of x
;Bin the oversampled polynomial basis function by the oversampling factor "hires"
;Store the polynomial basis function corresponding to the current unique power of x
;Set "status" to "1"