Better support for writing RATs, re #4903

Updated from 4903.9.diff to apply to latest trunk.
 * track thematic/athematic RAT type
 * Write RATs for Imagine/HFA output by default
 * Copy RATs during gdalwarp file-creation as well (if using nearest).
 * Copy RATs during gdal_translate VRT-path as well.
 * but, discard RATs if the operation makes them invalid
gdal_calc: convert data types earlier so output numbers don't get wrapped to the input data-type.

Includes a test