;+ ; NAME: ; wheremincontig ; PURPOSE: (one line) ; find minimum value within runs of contiguous indices ; DESCRIPTION: ; given a list of indexes and a list of values ; return indices g s.t. j[g] has the smallest distance ; for a run of contiguous j's (one per group of contiguous j's) ; CATEGORY: ; occultation ; CALLING SEQUENCE: ; gmin = whereimcontig(i, d, ng) ; INPUTS: ; j - list of indices ; d - list of values ; OPTIONAL INPUT PARAMETERS: ; none ; KEYWORD INPUT PARAMETERS: ; KEYWORD OUTPUT PARAMETERS: ; none ; OUTPUTS: ; ng : number of contiguous runs of j ; returns array indices into the minimum value of d within ; each contiguous run. This array has ng elements. ; COMMON BLOCKS: ; None ; SIDE EFFECTS: ; RESTRICTIONS: ; PROCEDURE: ; MODIFICATION HISTORY: ; Written 2005 January, by Leslie Young, SwRI ;- function wheremincontig, j, d, ng g = split_contig(j, glen, ng) gmin = lindgen(ng) for h=0, ng-1 do begin if glen[h] eq 1 then begin gmin[h] = g[h] endif else begin g0 = g[h] g1 = g0 + glen[h] - 1 dd = d[g0:g1] dmin = min(dd, lmin) gmin[h] = g0 + lmin endelse endfor return, gmin end pro wheremincontig_test j = [0,1,2,3, 6,7, 10, 23,24] n = n_elements(j) d = round(randomu(seed,n)*100) g0 = split_contig(j, glen, ng) gmin = wheremincontig(j, d, ng2) g0str = replicate(' -',n) glenstr = replicate(' -',n) gminstr = replicate(' -',n) for i=0,ng-1 do g0str[g0[i]] = g0[i] for i=0,ng-1 do glenstr[g0[i]] = glen[i] for i=0,ng2-1 do gminstr[gmin[i]] = gmin[i] forprint, indgen(n), j, d, g0str, glenstr, gminstr end