fits_save_fit() can fail when no systematic errors are defined
A dataset with no systematic errors can cause fits_save_fit() to fail with an "invalid index" error. Specifically, sys_err_array2string() is the problematic function here.
For a minimum working example, consider this attempt to load a Chandra/HETGS dataset, which I extracted using TGcat:
isis> load_data("pha2",3); % this just loads the MEG -1 order spectrum
isis> fit_fun("powerlaw"); % define a simple model
isis> fits_save_fit("test.fits"); % should crash here with an "invalid index" error
The reason is as follows: fits_save_fit() attempts to write the current systematic errors to the output FITS file, and does so by calling get_sys_err_frac() and converting the output to a machine-readable string using sys_err_array2string(). However, when systematic errors have not been defined, get_sys_err_frac() returns a zero-length array, causing sys_err_array2string() to fail, in turn causing fits_save_fit() to fail.
I'm changing sys_err_array2string() to handle zero-length arrays for now, but we should think about whether fits_save_fit() should be trying to save systematic errors when none are defined.
(also, the fits_save_fit() and fits_load_fit() functions generally don't handle type 2 PHA files very well, but that really should be its own issue)