def writeXR(filename, ds, verbose=True, append=False):
    """
    Save Xarray Dataset to an HDF5 file.

    Parameters
    ----------
    filename: str
        File name to save data, with our without extension
    ds: object
        Xarray Dataset to be saved
    verbose: boolean
        Set True to enable print statements declaring success/failure,
        and optional error message
    append: boolean
        Set True to add parameters to existing dataset.
        Concatenation of existing parameters is not supported.

    Returns
    -------
    success: boolean
        Return True is file was saved successfully
    """
    try:
        # Add .h5 if missing
        if (filename.endswith(".hdf5") == False) and \
           (filename.endswith(".h5") == False) and \
           (filename.endswith(".nc") == False):
            filename += ".h5"

        if append:
            ds.to_netcdf(filename, engine='h5netcdf', mode='a')
        else:
            ds.to_netcdf(filename, engine='h5netcdf')

        if verbose:
            print(f"Finished writing to {filename}")
        success = True
    except Exception as e:
        if verbose:
            print(f"Failed to write to {filename}")
            print(e)
        success = False
    return success