;+ ; NAME: ; oc_getline_hd ; ; PURPOSE: (one line) ; Return the raw catalog line from HD catalog for a given ID or IDs. ; ; DESCRIPTION: ; Return the raw catalog line from HD catalog for a given ID or IDs. ; The catalog line is a single line of text which is human-readable, ; although it must be carefully interpreted. ; ; This routine searches through the catalog using grep. For small catalogs ; like this, grep is fast enough. ; ; ; CATEGORY: ; Star catalogs ; ; CALLING SEQUENCE: ; lines = oc_getline_hd( ids [, NSTARS=nstars] [, /VERBOSE]) ; ; INPUTS: ; IDs -- A list of HD ID's. Scalar or vector. ; IDs must be in HD format and are recommended to be strings, rather ; than numerical values, due to precision and wraparound. ; ; OPTIONAL INPUT PARAMETERS: ; None ; ; KEYWORD INPUT PARAMETERS: ; /VERBOSE -- If set, print diagnostics to screen. ; ; KEYWORD OUTPUT PARAMETERS: ; NSTARS -- Returns the number of successfully-retrieved lines. ; ; OUTPUTS: ; If input is a scalar, then output is a single string. ; If input is a vector, then output is an array of strings. ; If a star is not found, returned value is ''. ; ; COMMON BLOCKS: ; None ; ; SIDE EFFECTS: ; None ; ; RESTRICTIONS: ; HD catalog must be available at $WCS_CATDIR/hd/catalog.dat . ; ; EXAMPLE: ; print, oc_getline_hd(['430', '1000']) ; ; MODIFICATION HISTORY: ; Written 2-Nov-2005 by Henry Throop, SwRI ; Modified 27-Feb-2006 by HBT. Improved documentation and formatting. ; Modified 05-Mar-2006 by LAY. Change nstars to count (consistent ; with oc_getline_ucac2) ; Modified 15-Mar-2006 by HBT. Undid LAY's nstars change (hah!), ; as it already was consistent w/ ucac2. ; Modifoed 23 Apr 2006 by LAY. Finished the undoing of nstars ; (increment nstars, not count) and ; chane spawn to call to nthline - ; lookup table ; ;- function oc_getline_hd, ids, NSTARS=nstars, VERBOSE=verbose catalog = 'hd/catalog.dat' path_catalog = getenv('WCS_CATDIR') nstars = 0 num_ids = sizex(ids) lines = strarr(num_ids) ids_lon = arr2lon(ids) ; convert all IDS to long for i = 0L, num_ids-1 do begin id = ids_lon[i] ;---------------------------------------------------- ; id_pad = string(long(id), format='(I6)') ; line = '' ; ; KEEPING OLD DISCUSSION ABOUT grep FOR HISTORICAL REASONS ; Search the catalog using grep. The /NOSHELL syntax speeds up the spawn ; process, but does require that arguments be passed in as an array, rather ; than a string. ; ; There is one odd behavior: If grep doesn't match a line, it sometimes takes ; much longer than if it does. For instance, 'print, oc_getstar_hd(2d6)' can ; take several seconds. No idea why. It's odd but has no useful consequence. ; ; spawn, /NOSHELL, ['grep', '^' + id_pad, path_catalog + '/' + catalog],line ; ;---------------------------------------------------- line = nthline(path_catalog+'/'+catalog, id - 1) ; If no line matched, act as needed ; if (line[0] eq '') or (id_pad eq '******') then begin if (line[0] eq '') then begin if (keyword_set(VERBOSE)) then print, 'Error: star ' + st(id) + $ ' not found in HD catalog' line = '' end $ ; If line is found, incrememnt counter else nstars = nstars + 1 lines[i] = line end ; Return argument in the same form as passed in if is_array(ids) then return, lines if not(is_array(ids)) then return, lines[0] end