Any overlapping regions between orders and exposures must be set to the same level. This could be accomplished by normalizing the continuum for all orders of each spectrum, for example. You could also scale the orders in a manner such that all the levels match, or simply clip off any overlapping regions (set error to "-1"). If the orders are not matched in some manner you will see discontinuities in the final spectrum.
You can also use the program "spim2" to help you match spectra between orders and exposures.
The error spectrum filename is found by assuming flux,error pairs such as: Flux-*.fits and Err-*.fits, or F-*.fits and E-*.fits, or FF-*.fits and FE-*.fits, or *.fits and *e.fits. Your filenames must be in one of these formats.
The data values are averaged and interpolated such that the
approximate average level of the original 2-D spectra are maintained.
For each new bin, a sum is created from all whole and fractional
original pixels which fall within the new bin, and this sum is
divided by the total number of whole and fractional pixels contributing.
Note: for example, if a half pixel falls within the new bin, half of the
flux of that original pixel adds to the sum, and half a pixel is added to
the pixel total.
The error values are found by
converting to variances, creating a variance
sum from all whole and partial original pixels which
fall within the new bin, taking the square root of this
sum, and then dividing by the total number of pixels contributing.
Note: this tends to overestimate the error slightly since
it neglects the correlation between the rebinned pixels. A slight
correction factor may be needed when fitting features of the
spectrum using a chi-squared minimization.