pro dbfind_sort,it,type,svals,list, FULLSTRING = fullstring, COUNT = number ;+ ; NAME: ; DBFIND_SORT ; PURPOSE: ; Subroutine of DBFIND to perform a search using sorted values ; EXPLANATION: ; This is a subroutine of dbfind and is not a standalone procedure ; It is used to limit the search using sorted values ; ; CALLING SEQUENCE: ; dbfind_sort, it, type, svals, list, [/FULLSTRING, COUNT = ] ; ; INPUT: ; it - item number, scalar ; type - type of search (output from dbfparse) ; svals - search values (output from dbfparse) ; ; INPUT/OUTPUT: ; list - found entries ; ; OPTIONAL INPUT KEYWORD: ; /FULLSTRING - By default, one has a match if a search string is ; included in any part of a database value (substring match). ; But if /FULLSTRING is set, then all characters in the database ; value must match the search string (excluding leading and ; trailing blanks). Both types of string searches are case ; insensitive. ; OPTIONAL OUTPUT KEYWORD ; Count - Integer scalar giving the number of matches found ; SYSTEM VARIABLES: ; The obsolete system variable !err is set to number of good values ; !ERR = -2 for an invalid search ; REVISION HISTORY: ; D. Lindler July,1987 ; William Thompson, GSFC/CDS (ARC), 30 May 1994 ; Added support for external (IEEE) data format ; William Thompson, GSFC, 14 March 1995 Added keyword FULLSTRING ; Converted to IDL V5.0 W. Landsman September 1997 ; Minimize use of obsolete !ERR variable W. Landsman February 2000 ; Added COUNT keyword, deprecate !ERR W. Landsman March 2000 ;- ;---------------------------------------------------------------------------- ; READ EVERY 512TH VALUE IN SORTED VALUES ; ; get item info ; itnum = db_item_info('itemnumber',it) ;item number in this dbno index_type = db_item_info('index',it) ; ; get unit number of index file and read header info ; unit = db_info('UNIT_DBX',0) external = db_info('EXTERNAL',0) pi = assoc(unit,lonarr(2)) h = pi[0] if external then ieee_to_host,h pi = assoc(unit,lonarr(7,h[0]),8) header = pi[0] if external then ieee_to_host,header items = header[0,*] pos = where(items EQ itnum) & pos=pos[0] ; ; find starting location to read ; sblock = header[3,pos] sbyte = 512L*sblock nv = (db_info('ENTRIES',0)+511)/512 ; ; create mapped i/o variable ; dtype = db_item_info('IDLTYPE',it) p = assoc(unit,make_array( size=[1,nv,dtype[0],0],/NOZERO), sbyte) numbyte = [0,1,2,4,4,8,0] num_bytes = numbyte[ dtype[0] ] ; ; read values from file (for every 512th entry) ; values=p[0] if external then ieee_to_host,values ; ;------------------------------------------------------------------ ; CONVERT INPUT SVALS TO CORRECT DATA TYPE ; ; determine data type of values to be searched ; s=size(values) & nv = N_elements(values) ; ; convert svals ; nvals = type>2 sv=replicate(values[0],nvals) for i=0L,nvals-1 do sv[i]=strtrim(svals[i],2) sv0 = sv[0] & sv1 = sv[1] ; ;-------------------------------------------------------------------------- ; FIND RANGE OF VALID SUBSCRIPTS IN LIST ; ; case type of 0: begin ;value=sv0 good = where(values LT sv0, N) if N LT 1 then first=0 else first= N-1 good = where(values GT sv0, N) if N LT 1 then last=nv else last=good[0] end -1: begin ;value>sv0 good = where(values LT sv0, N) if N LT 1 then first=0 else first= N-1 last = nv end -2: begin ;value