FUNCTION centertrack,data,dim,average = average, pretrack = pretrack ;+ ; NAME: ; centertrack ; PURPOSE: ; Returns center-of-mass coordinates of a track or pretrack array. ; Centering is done by default for each individual timestamp. ; CALLING SEQUENCE: ; ctrack=centertrack(track,dimension,average=average,pretrack=pretrack) ; INPUTS: ; track: a two- or three-dimensional track or pretrack array ; dim: the spatial dimension of the data ; KEYWORDS: ; average: specify /average to return coordinates relative to the ; time-averaged center-of-mass ; pretrack: specify /pretrack if data is a pretrack array ; OUTPUTS: ; ctrack: an array one-to-one with the initial track file, with ; centered coordinates ; SIDE EFFECTS: ; Sweating has been documented in rare cases. ; MODIFICATION HISTORY: ; Written by Gary L. Hunter, 2009 ;- blah = data d = dim nc = n_elements(blah[*,0]) IF keyword_set(pretrack) THEN BEGIN tloc = nc-1 ENDIF ELSE BEGIN tloc = nc-2 ENDELSE IF keyword_set(average) THEN BEGIN FOR i = 0, d-1 DO blah[i, *] = blah[i, *]-mean(blah[i, *]) ENDIF ELSE begin tlist = unique(blah[tloc,sort(blah[tloc,*])]) nts = n_elements(tlist) FOR i = 0L,nts-1 DO BEGIN IF i MOD 1e2 EQ 0 THEN BEGIN print,n2s(i)+' of '+n2s(nts-1) endif wt = where(blah[tloc,*] EQ tlist[i]) FOR j = 0, d-1 DO BEGIN me = mean(blah[j, wt]) blah[j, wt] = blah[j, wt]-me endfor ENDFOR ENDELSE return,blah end