;+ ; NAME: ; oc_star_isempty ; ; PURPOSE: (one line) ; Indicates whether a star structure is empty or not. ; ; DESCRIPTION: ; Indicates whether a star structure is empty or not, based on the contents ; of numerous fields within it. ; ; We make an educated guess as to whether the star is empty or not, based ; on the number of fields that are 0, -999, 'none', or ''. We could be ; wrong, but it's unlikely. There is not a single field that indicates ; an empty star; we require all examined fields to be empty. ; ; This routine works for *stars*. It does not work for, e.g., matching ; catalogs such as tyc2_hd. ; ; CATEGORY: ; Star catalogs ; ; CALLING SEQUENCE: ; result = is_empty(star) ; ; INPUTS: ; star -- Star structure(s). Either scalar or vector. ; ; OPTIONAL INPUT PARAMETERS: ; None ; ; KEYWORD INPUT PARAMETERS: ; None ; ; KEYWORD OUTPUT PARAMETERS: ; None ; ; OUTPUTS: ; Boolean flag, 1 or 0. Returned value is a double rather than an int, ; because IDL's not() function can return nonintuitive results on ints. ; ; Output is a scalar or vector, with one element for each element of input. ; ; COMMON BLOCKS: ; None ; ; SIDE EFFECTS: ; None ; ; RESTRICTIONS: ; None ; ; EXAMPLE: ; print, oc_star_isempty(oc_getstar_ucac2(['1.0', '1.1'])) ; Returns "1.0 0.0" because first ID is invalid. ; ; MODIFICATION HISTORY: ; Written 7-Dec-2005 by Henry Throop, SwRI ; Modified 27-Feb-2006 by HBT. Improved documentation and formatting. ; Modified 14-Apr-2006 by Leslie Young. Made loop index long. ;- function oc_star_isempty, stars, VERBOSE=verbose ; Test case: [A tough case which converts from HD -> TYC2 -> HD, and checks ; that an invalid HD ID is *still* invalid after three conversions. It is! ; This confirms proper operation of many of the conversion routines.] ; ; print, oc_star_isempty(oc_getstar_hd((oc_getrec_tyc2_hd(tyc2= $ ; (oc_getstar_tyc2((oc_getrec_tyc2_hd(hd=[0,2,3,4])).tyc)).id)).hd)) ; Result should be: 1.00000 0.00000 0.00000 0.00000 ; nstars = sizex(stars) is_empty = fltarr(nstars) for i = 0L, nstars-1 do begin ; Now go through each field, and check if it is empty. ; In general each of the stars.* fields _could_ be either a scalar or a ; vector, so we take the conservative case and check that each element is zero ; (or invalid). ; ; The idea is that each of these 'empty_*' variables must be a scalar flag, ; not an array, since we 'and' them together at the end. empty_id = total( ((stars[i].id)[*] eq '') or $ ((stars[i].id)[*] eq 'none') ) eq sizex(stars[i].id) empty_ra = total( ((stars[i].ra)[*] eq 0d) or $ ((stars[i].ra)[*] eq -999d) ) eq sizex(stars[i].ra) empty_dec = total( ((stars[i].dec)[*] eq 0d) or $ ((stars[i].dec)[*] eq -999d) ) eq sizex(stars[i].dec) empty_radot = total( ((stars[i].radot)[*] eq 0d) or $ ((stars[i].radot)[*] eq -999d) ) eq sizex(stars[i].radot) empty_decdot = total( ((stars[i].decdot)[*] eq 0d) or $ ((stars[i].decdot)[*] eq -999d) ) eq sizex(stars[i].decdot) empty_mag = total( ((stars[i].mag)[*] eq 0d) or $ ((stars[i].mag)[*] eq -999d) ) eq sizex(stars[i].mag) empty_spt = total( ((stars[i].spt)[*] eq '') or $ ((stars[i].spt)[*] eq 'none') ) eq sizex(stars[i].spt) empty_note = total( ((stars[i].note)[*] eq '') or $ ((stars[i].note)[*] eq 'none') ) eq sizex(stars[i].note) is_empty[i] = (empty_id) and (empty_ra) and (empty_dec) and $ (empty_radot) and (empty_decdot) and (empty_mag) and (empty_spt) end if is_array(stars) then return, is_empty if is_scalar(stars) then return, is_empty[0] end