;+ ; Return a vector of channel numbers appropriate for the given data container. ; ; If nregion is not set or is 0, all channels are returned. If nregion is set ; and is not zero then regions must be provided. Ignores any regions or ; parts of region that extend beyond the end of the data container. ; ; @param dc {in}{required}{type=data container} The data container to ; use. ; @param nregion {in}{optional}{type=integer} The number of regions to ; use. If not set, the all channels are returned. ; @param regions {in}{optional}{type=2D array} Limit the channel ; numbers returned to only those channels that fall in these regions. ; This assumes the regions follows the same rules as used in ; !g.nregions. That the regions don't overlap and are properly sorted ; with the first channel of each region at regions[0,*] and the last ; channel of each region at regions[1,*]. The nregion argument ; determines how many regions are used here. If nregion is supplied ; and is > 0 then regions is required. ; ; @examples ;
;    ; equivalent to dindgen(n_elements(*dc.data_ptr))
;    c = get_chans(dc)
;    ; get the chans corresponding to recently set global regions
;    c = get_chans(dc, !g.nregions, !g.regions)
;  
; ; @returns Array of channel numbers. Returns -1 if there was a ; problem. ; ; @uses data_valid ; ; @version $Id: get_chans.pro,v 1.1 2004/12/08 03:50:36 bgarwood Exp $ ;- function get_chans, dc, nregion, regions compile_opt idl2 ; argument check here, dc valid nmax = data_valid(dc) - 1 result = -1 if (nmax < 0) then begin message, 'no valid data in dc', /info return, result endif if (n_elements(nregion) eq 0) then nregion = 0 if (nregion gt 0) then begin start = regions[0,0] stop = regions[1,0] if (start le nmax) then begin stop = stop gt nmax ? nmax : stop result = seq(start,stop) for i=1,(nregion-1) do begin start = regions[0,i] stop = regions[1,i] if (start gt nmax) then break stop = stop gt nmax ? nmax : stop result = [result,seq(start,stop)] endfor endif endif else begin result = lindgen(n_elements(*dc.data_ptr)) endelse return, result end