How to reverse the order of bands in a file programmatically
This Help Article provides a code example of how to reverse the order of the bands in a file programmatically.
Occasionally, you may receive a file with the bands in the reverse order (longer to shorter wavelengths). If the file contains many bands, it can be tedious using the New File Builder to move the bands into place. The simple piece of code below can reverse the order of the bands and create a new file with all the important previous file information (band names, wavelengths, map info, etc.).
-------------------------------
pro reverse_bands
compile_opt idl2
;select the input file and gather some info
envi_select, fid=fid, dims=dims, pos=pos, title = 'Select input file'
;generate an array of file ids, one for each band that will be written
out_fids=lonarr(n_elements(pos))
;populate the array with the same file id since all bands will come from the same source
out_fids[*] = fid
;generate the reverse of the band array
new_pos = reverse(lindgen(n_elements(pos)))
;write a new ENVI file, change the output file name as desired
envi_doit, 'cf_doit', dims=dims, fid=out_fids, pos=new_pos, out_name='reverse_file.img'
end
Review on 12/31/2013 MM