double dEl; dEl = gan_vec_get_el ( pvx, 1 ); /* returns x[1], x = (x[0] x[1] ... )^T */This sets dEl to the second element of vector pvx (zero is the first). To set an element to a specific value use
gan_vec_set_el ( pvx, 2, 3.0 ); /* set x[2] to 3, x = (x[0] x[1] ... )^T */This sets the third element of vector pvx to 3. There are also routines to increment or decrement an element of a vector:
gan_vec_inc_el ( pvx, 0, 2.5 ); /* x_0 += 2.5, x = (x[0] x[1] ... )^T */ gan_vec_dec_el ( pvx, 4, 5.0 ); /* x_4 -= 5.0, x = (x[0] x[1] ... )^T */which respectively increment the first element by 2.5 and subtract 5 from the fifth element of pvx.
Error detection: gan_vec_set_el(), gan_vec_inc_el() and gan_vec_dec_el() all return boolean values, with GAN_FALSE returned on failure, in which case the Gandalf error handler is invoked. The most likely failure mode is accessing an element outside the bounds of the vector. If NDEBUG is set then no error checking is done. gan_vec_get_el() operates similarly, but returns DBL_MAX on error.