/idl/heiles_all/goddard_jan2007/pro/database/dbget.pro

http://github.com/charleshull6/c_soft · Prolog · 103 lines · 91 code · 12 blank · 0 comment · 17 complexity · b9b6a5c1452f0455de5d90617473b3e8 MD5 · raw file

  1. function dbget,item,values,listin,SILENT=silent, FULLSTRING = fullstring, $
  2. Count = count
  3. ;+
  4. ; NAME:
  5. ; DBGET
  6. ; PURPOSE:
  7. ; Find entry numbers which contain specified values of a given item.
  8. ; EXPLANATION:
  9. ; DBGET() is useful as an alternative to DBFIND() when the desired
  10. ; search values are not easily expressed as a string.
  11. ;
  12. ; CALLING SEQUENCE:
  13. ; list = dbget( item, values, [ listin ], /SILENT, /FULLSTRING )
  14. ;
  15. ; INPUTS:
  16. ; item - Item name or number
  17. ; values - scalar or vector containing item values to search for.
  18. ;
  19. ; OPTIONAL INPUTS:
  20. ; listin - list of entries to be searched. If not supplied, or
  21. ; set to -1, then all entries are searched
  22. ;
  23. ; OUTPUT:
  24. ; list - vector giving the entry number of entries containing desired
  25. ; item values. The number of elements in LIST may be different
  26. ; from that of VALUE, since a value might be located zero, once,
  27. ; or many times in the database. Use the function DBMATCH if a
  28. ; one to one correspondence is desired between VALUES and LIST.
  29. ; OPTIONAL INPUT KEYWORDS:
  30. ; /SILENT - If this keyword is set, then DBGET will not display
  31. ; the number of entries found
  32. ; /FULLSTRING - By default, one has a match if a search string is
  33. ; included in any part of a database value (substring match).
  34. ; But if /FULLSTRING is set, then all characters in the database
  35. ; value must match the search string (excluding leading and
  36. ; trailing blanks). Both types of string searches are case
  37. ; insensitive.
  38. ; OPTIONAL OUTPUT KEYWORD:
  39. ; COUNT - Integer scalar giving the number of valid matches
  40. ;
  41. ; RESTRICTIONS:
  42. ; When linked databases are opened together, DBGET can only be used to
  43. ; search on items in the primary database.
  44. ; EXAMPLE:
  45. ; Get info on selected HD stars in Bright Star catalogue
  46. ;
  47. ; IDL> dbopen, 'YALE_BS'
  48. ; IDL> hdno = [1141,2363,3574,4128,6192,6314,6668] ;Desired HD numbers
  49. ; IDL> list = dbget( 'HD', hdno ) ;Get corresponding entry numbers
  50. ;
  51. ; SYSTEM VARIABLES:
  52. ; The obsolete system variable !ERR is set to number of entries found
  53. ; REVISION HISTORY:
  54. ; Written, W. Landsman STX February, 1989
  55. ; William Thompson, GSFC, 14 March 1995 Added keyword FULLSTRING
  56. ; Converted to IDL V5.0 W. Landsman September 1997
  57. ; Added COUNT keyword, deprecate !ERR W. Landsman March 2000
  58. ; Fix bug introduced March 2000 W. Landsman November 2000
  59. ;-
  60. ;
  61. On_error,2 ;Return to caller
  62. if N_params() LT 2 then begin
  63. print,'Syntax -- list = ' + $
  64. 'DBGET( item, values, [listin, /SILENT, /FULLSTRING, Count=]'
  65. return,-1
  66. endif
  67. if N_params() LT 3 then listin = lonarr(1)-1
  68. nvals = N_elements(values)
  69. if nvals EQ 0 then message,'No search values supplied'
  70. db_item, item, itnum
  71. index = db_item_info( 'INDEX', itnum)
  72. list = listin
  73. if nvals EQ 1 then val = [values,values] $ ;Need at least 2 elements
  74. else val = values
  75. if index[0] GE 2 then begin ;Sorted item
  76. if N_elements(list) EQ 1 then list = lonarr(1) + list
  77. dbfind_sort, itnum[0], nvals, val, list, $
  78. FULLSTRING = fullstring, Count =count
  79. endif else begin ;Non-sorted item
  80. dbext, list, itnum, itvals
  81. dbsearch, nvals, val, itvals, good, FULLSTRING = fullstring, Count = count
  82. if list[0] NE -1 then list = list[good] else list = good+1
  83. endelse
  84. if count LE 0 then begin
  85. if not keyword_set(SILENT) then $
  86. print, 'No entries found by DBGET in ' + db_info( 'NAME',0 )
  87. list = intarr(1)
  88. endif else if not keyword_set( SILENT ) then $
  89. print,count,' entries found in '+db_info('name',0)
  90. return, list[ sort(list) ]
  91. end