Better handling of encoding during writing.

Some encodings cannot be written with libmseed. Now raises appropriate
errors.
Test that the correct exceptions are raised
Also test setting the encoding via the trace stats.