;---------------------------------------------------------------------------- ; SCCS/s.elim_mult_centers.pro 1.5 01/05/08 12:51:27 ; ; function elim_mult_centers ; ; Purpose: ; Given a vector of pressures, and corresponding vectors of lon. and lat. ; where those pressures are at, looks to see if any two points are "too" ; close to each other. If they are, then the one with the lower (or ; higher, as set by the Type keyword) pressure is retained. The 1-D ; vector returned is of the locations (in terms of subscripting of the ; original pressure vector) that have been retained. ; ; This function is typically used for eliminating multiple high or low ; centers that has been identified by an automated pressure center ; finding algorithm. ; ; File I/O: ; None. ; ; Entry and Exit States: ; N/A. ; ; Input Parameter: ; in_press Pressure (in hPa) at locations defined by in_lon and ; in_lat. Floating or double array of any dimension. ; Unchanged by procedure. ; in_lon Longitude of points given by in_press (in decimal deg). ; Floating or double array. Same dimensions as in_press. ; Unchanged by procedure. ; in_lat Latitude of points given by in_press (in decimal deg). ; Floating or double array. Same dimensions as in_press. ; Unchanged by procedure. ; ; Output Parameter: ; out_loc Vector of the locations of retained locations, as ; described above. Created. 1-D integer vector of ; array indices, in terms of the input array in_press. ; If none of the pressures are "too close" to each other, ; out_loc will end up being just a vector of the indices ; of all the elements in in_press. ; ; Keywords (optional unless otherwise noted): ; COUNT A named variable that returns the number of elements ; in out_loc. Created/overwritten by procedure. ; SEARCH_RAD Radius defining the region from a point the procedure ; searches to try and determine whether a given location ; is too close to other locations. In meters. Not ; changed by function. This can either be a scalar ; (which is applied to all locations) or a vector of the ; same size as in_press that gives Search_Rad to use ; for each location. Default is 800e3 meters. ; TYPE Required. If set to 1, then the function retains the ; higher of the pressures; if set to -1, then the function ; retains the lower of the pressures. ; ; Revision History: ; - 20 Apr 2001: Orig. ver. by Johnny Lin, CIRES/Univ. of Colo. Email: ; air_jlin@yahoo.com. Passed moderately reasonable tests. ; ; Notes: ; - Written for IDL 5.2.1. ; - Copyright (c) 2001 Johnny Lin. For licensing and contact information ; see http://www.johnny-lin.com/lib.html. ; - No procedures called with _Extra keyword invoked. ; - User-written procedures called: DISTANCE. ; - No common blocks are used in this program. ;---------------------------------------------------------------------------- FUNCTION ELIM_MULT_CENTERS, in_press, in_lon, in_lat $ , COUNT = out_count $ , SEARCH_RAD = in_search_rad $ , TYPE = in_type $ , _EXTRA = extra ; -------------------- Error Check and Parameter Setting -------------------- ON_ERROR, 0 if (N_PARAMS() ne 3) then MESSAGE, 'error-bad param list' press = in_press ;- Protect input lon = in_lon lat = in_lat npress = N_ELEMENTS(press) ;- Total num. elements in press if (npress ne N_ELEMENTS(lon)) then MESSAGE, 'error--bad dimension match' if (npress ne N_ELEMENTS(lat)) then MESSAGE, 'error--bad dimension match' if (N_ELEMENTS(in_search_rad) ge 1) then $ ;- Set min. search rad. (in search_rad = in_search_rad $ ; m): Default is 800 km else $ search_rad = 800e3 if (N_ELEMENTS(in_type) eq 0) then $ ;- Set which type of center MESSAGE, 'error--type is required' $ ; to retain (low or high) else $ type = in_type ; --------------------- Find Multiple Center Situations --------------------- ; ; Method: All permutations of the values of press are tested pairwise ; against to see each other to see if they are less than Search_Rad apart. ; If so, it is assumed that they are not actually separate systems, and ; the value with the lowest (highest) value is retained as describing the ; true low (high) center. ; ; NB: If a case exists where the min. (or max.) of the points that are ; within Search_Rad of each other applies to more than one point, it is ; assumed that both are centers, and a warning message is printed out. ; This should be an extremely rare situation, since press is floating pt. for i=0L,npress-1L do begin ;- Loop through all npress pts. (begin) dist_from_i = $ ;+ Dist. each pt. is f/ i DISTANCE( REPLICATE(lon[i], npress) $ , REPLICATE(lat[i], npress) $ , lon, lat ) same_loc = WHERE( dist_from_i le search_rad $ ;+ Loc. of pts. too close , sl_count ) ; (i.e. same press. sys.) if (sl_count eq 1) then begin ;+ Case of lone center with if (N_ELEMENTS(out_loc) eq 0) then $ ; no other candidates near out_loc = [same_loc] $ else $ out_loc = [out_loc, same_loc] endif if (sl_count gt 1) then begin same_press = press[same_loc] ;+ Press. at pts. too close if (type gt 0) then begin keep_pts = WHERE( same_press eq MAX(same_press) $ ;+ High centers , ep_count) endif else begin keep_pts = WHERE( same_press eq MIN(same_press) $ ;+ Low centers , ep_count ) endelse if (ep_count gt 0) then begin ;+ Add keep_pts to out_loc if (N_ELEMENTS(out_loc) eq 0) then $ out_loc = [same_loc[keep_pts]] $ else $ out_loc = [out_loc, same_loc[keep_pts]] if (ep_count gt 1) then $ PRINT, '*** warning--same pressure in mult center ***' endif endif endfor ;- Loop through all npress pts. (end) ; ---------------------------- Clean-Up and Output -------------------------- tmp_count = N_ELEMENTS(out_loc) ;- If no mult. centers are elim., just if (tmp_count eq 0) then begin ; return all indices of press. If mult. out_loc = LINDGEN(npress) ; centers are elim., sort unique values. endif else begin out_loc = out_loc[UNIQ( out_loc, SORT(out_loc) )] endelse out_count = N_ELEMENTS(out_loc) RETURN, out_loc END ; ===== end of function ===== ; ========== end file ==========