;+ ; Project : SOHO - CDS / RHESSI ; ; Name : SAME_DATA2 ; ; Purpose : Check if two variables are identical. ; ; Explanation : Checks if the values contained in the 2 inputs are the same. ; Works on any type of data input. ; ; Use : IDL> if same_data(a,b) then print,'a and b are identical' ; ; Inputs : a - first input ; b - second input ; ; Outputs : Function returns 1 for identity, 0 otherwise. ; ; Category : Util, numerical ; ; Written : C D Pike, RAL, 22-Feb-95 ; ; Modified : Accept string arrays. CDP, 9-Nov-95 ; ; A.Csillaghy for rhessi, csillag@ssl.berkeley.edu 2001 ; Elim calls to datatype which are very slow ; correct problem w/ string checking ; some speeding stuff ; Richard.schwartz@gsfc.nasa.gov - avoid unnecessary calls to match_struct ; Zarro (EER/GSFC) - added check for non-existent input and returned boolean ;- function same_data2, a, b, notype_check=notype_check ;-- get this out of the way first if (n_elements(a) eq 0) and (n_elements(b) eq 0) then return,1b ; ; get data type ; ;typea = datatype(a, 1) ;typeb = datatype(b, 1) ; acs changed datatype to size /type for speed ; ; acs changed this for having additonal test of dimension ; size_a = size( a, /STRUCTURE ) size_b = size( b, /STRUCTURE ) ;Check for n_elements, n_dimensions, and dimensions diff = (total( size_a.dimensions - size_b.dimensions) ne 0) or $ (size_a.n_elements ne size_b.n_elements ) or $ (size_a.n_dimensions ne size_b.n_dimensions ) ;If DIFF is set, then it fails all tests If diff THEN return, 0b ;If type is in question, add some more basic tests IF NOT keyword_set( NOTYPE_CHECK) and $ ((size_a.type_name ne size_b.type_name) or $ (size_a.type ne size_b.type)) THEN return, 0b ; now we have to check explicitly for pointers that would go through ; match struct IF keyword_set( NOTYPE_CHECK ) THEN BEGIN IF ( size_a.type GT 0 AND size_a.type LE 6 ) or $ ( size_a.type EQ 9 ) OR $ ( size_a.type GE 12 AND size_a.type LE 15 ) THEN BEGIN IF size_b.type EQ 0 OR $ size_b.type EQ 7 OR size_b.type EQ 8 OR $ size_b.type EQ 10 OR size_b.type EQ 11 THEN return, 0b ENDIF ELSE BEGIN ; for all other cases they type MUST match IF size_b.type NE size_a.type THEN return, 0b ENDELSE ENDIF case size_a.type of 7: begin for i=0, size_a.n_elements-1 do begin if a[i] ne b[i] then return, 0b endfor return, 1b end 8: return, match_struct(a, b) else: begin stat = where( a eq b, npix) if npix ne size_a.n_elements then return, 0b END ENDCASE return, 1b end