function match_index, i1, i2, point=point, expmode=expmode, dpe=dpe, res=res, $ delta=delta, pdelta=pdelta, dark=dark, _extra=_extra, debug=debug, $ pupdate=pupdate, allss=allss, porder=porder, seperation=seperation, $ ccdtemp=ccdtemp, roll_include=roll_include ;+ ; Name: match_index ; ; Purpose: return ss for 'closest' match of index1 in index2 array ; (fuzzy logic since it was written during ISAS visit) ; ; Input Parameters: ; index1, index2 - index or roadmap records ; ; Keyword Parameters: ; dpe - if set, match i1:i2 dpe ; res - if set, match i1:i2 resolution ; expmode - if set, match i1:specified mode ; point - if set, choose minimum pointing seperation (if multiple matches) ; delta - (output), deltaT for matching records ; pdelta - (output), delta Pointing (arcsecs), only if POINT is set ; ccdtemp - if set, match CCDTEMP (+/- specified degrees) ; Output: ; output are indices (lonarr) relative to index2 (-1 = no match) ; ; Calling Sequence: ; ss= match_index(index1,index2 , /res, /dpe) ; ; Match Criteria: ; filterA=flterA ; always ; filterB=filterB ; expmodeA=expmodeB ; if (dpe) then dpeB=dpe ; ; if (res) then above AND resA=resB ; ; if (point) then minimal seperation satisfying above ; Then, choose closest time satisfying above ; before/after date? ; ; 9-Dec-1994 (SLF) - SDC matches originally , but useful elsewhere? ; 10-dec-1994 (SLF) - tweaked etc... ; 17-mar-1995 (SLF) - logic correction (courtesy kevin reardon) ; 16-apr-1995 (SLF) - add SEPERATION keyword (output) ; 10-oct-1996 (SLF) - add CCD TEMP check ; 23-Jan-1998 (SLF) - include Solar Radius if /point is set ; 4-Feb-1998 (SLF) - protect agains only one SFC per filter/era ; 25-apr-1999 (SLF) - add /ROLL keyword (include roll in) made noroll default ; 27-Jan=2014 (LWA) - add /quiet to call to get_rb0p in 2 places. ; ; Side effects: - history record will be appended to index2 if ; keyword POINT is set and no history exists already ;- onlyone = 1-keyword_set(all) pupdate=keyword_set(pupdate) ; force sxt_cen call debug=keyword_set(debug) roll_include=keyword_set(roll_include) nout=n_elements(i1) narr=n_elements(i2) arrmap=lonarr(narr) + 1 ; used with POINT ; ; to avoid re-call of sxt_cen matchmap=lonarr(nout) ssout=lonarr(nout) pdelta=fltarr(nout) ; delta pointing delta=lonarr(nout)+9999999 ; deltaT (initialize large) first=1 if keyword_set(dark) then expmode=1 expm=n_elements(expmode) ne 0 if not expm then expmode=0 ; assign boolean values to keyword switches res=keyword_set(res) point=keyword_set(point) ccdt=keyword_set(ccdtemp) ; add check for resolution if /res set reschk=(['','and (gt_res(i1(i)) eq gt_res(i2))'])(res) ; if dpe set, match it (****** if dpe=1, then matchi dpeA to dpeB, hmm... *****) if n_elements(dpe) eq 0 then dpe=0 dpechk=(['','and (gt_dpe(i1(i)) eq gt_dpe(i2))', $ 'and (gt_dpe(i2) eq ' + strtrim(dpe,2) + ')'])(dpe<2) ; if expmode set, match value else match expmodeA to expmodeB expchk=(['and (gt_expmode(i1(i)) eq gt_expmode(i2)) ', $ 'and (gt_expmode(i2) eq ' + strtrim(expmode,2) + ')'])(expm) ccdtchk='' if ccdt then begin stemp=strtrim(ccdtemp,2) ccdtchk=(['',' and (abs(gt_temp_ccd(i1(i)) - gt_temp_ccd(i2)) le '+ $ stemp+")"])(ccdt) endif ; find matching filter, exp mode (optionally resolution) exestr='ss=where((gt_filta(i1(i)) eq gt_filta(i2)) ' + $ 'and (gt_filtb(i1(i)) eq gt_filtb(i2)) ' + $ expchk + reschk + dpechk + ccdtchk + ',mcnt)' for i = 0 , nout-1 do begin exestat=execute(strcompress(exestr)) if debug then stop,' after execute... matchmap(i)=mcnt ; if mcnt gt 0 then begin ; only for matches ; closest pointing if POINT switch set if point then begin ; only for multiple?? his_index,/enable his_index,i2 needcen=where(arrmap(ss),cencnt) ; if cencnt gt 0 then begin for j=0,cencnt-1 do begin ; *** VECTORIZE ** if total(i2(ss(needcen(j))).his.sun_center) eq 0 or pupdate then $ i2(ss(needcen(j))).his.sun_center=sxt_cen(i2(ss(needcen(j)))) endfor arrmap(ss(needcen))=0 ; cancel request next endif ; now compare pointing seperation sxtcen=sxt_cen(i1(i),roll=roll) chkval=[sxt_cen(i1(i)),([0,roll])(roll_include)] chkval=rebin(chkval,3,mcnt,/samp) ; permit array operation cmpval=i2(ss).his.sun_center ; calculate pix distance sep= cmpval - chkval ; pdelta (pixels) sepas=[sep*gt_pix_size(1)] ; pdelta (arcsec) sfc_diam=get_rb0p(i2(ss),/radius,/quiet) ind_diam=get_rb0p(i1(i),/radius,/quiet) ddiam=transpose([sfc_diam-ind_diam]) sepas=[ddiam,sepas] seperate=reform(sqrt( $ (sepas(0,*)^2) + $ ; SRadius (sepas(1,*)^2) + (sepas(2,*)^2) + $ ; X & Y (sepas(3,*)^2)*roll_include)) ; Z (roll) pdelta(i)=min(seperate) ; seperation dss=where(seperate eq min(seperate),mcnt) ; minimum seperation seperation=reform([seperate]) porder=sort(seperation) ss=ss(dss) endif allss=ss sss=tim2dset(i2(ss),i1(i),delta=delt) ; closest time ss=ss(sss) delta(i)=delt(0) ; time diff endif ; end matches ssout(i)=ss(0) endfor if debug then stop,"before return..." return,ssout end