;+ ; NAME: ; split_contig ; PURPOSE: (one line) ; identify runs of contiguous indices ; DESCRIPTION: ; given a list of indexes, find the number of runs of contiguous ; indices, the starting index, and the length of the run ; CATEGORY: ; occultation ; CALLING SEQUENCE: ; g0 = split_contig(j, glen, ng) ; INPUTS: ; j - list of indices ; OPTIONAL INPUT PARAMETERS: ; none ; KEYWORD INPUT PARAMETERS: ; KEYWORD OUTPUT PARAMETERS: ; none ; OUTPUTS: ; glen: length of each run ; ng : number of contiguous runs of j ; returns array indices into the first of each run. ; This array has ng elements. ; COMMON BLOCKS: ; None ; SIDE EFFECTS: ; RESTRICTIONS: ; PROCEDURE: ; MODIFICATION HISTORY: ; Written 2005 January, by Leslie Young, SwRI ;- function split_contig, j, glen, ng ng=0 glen = [1] g0 = [0] i = 0 for i=1, n_elements(j)-1 do begin if j[i] eq j[i-1]+1 then begin glen[ng] = glen[ng]+1 endif else begin ng = ng+1 glen = [glen, 1] g0 = [g0, i] endelse end ng = ng+1 return, g0 end pro split_contig_test,j g0 = split_contig(j, glen, ng) n = n_elements(j) g0str = replicate(' -',n) glenstr = strarr(n) for i=0,ng-1 do g0str[g0[i]] = g0[i] for i=0,ng-1 do glenstr[g0[i]] = glen[i] forprint, indgen(n_elements(j)), j, g0str, glenstr end