FUNCTION tryshift,filtlist,typelist,texplist,flag,debug=debug ; Attempt to determine the start points of Polar Camera image ; acquisition cycles from lists of filters, image types, and exposure ; times, by shift arrays of these parameters until repetitions are ; exhibited. This technique is necessary when image acquisition ; under KI occurs continuously without interruption by DOS activities. ; First, repair the effects of missing images, by replacing -1 ; wherever it occurs in the image type or exposure time lists with ; the corresponding parameter for the other camera. FOR c=0,1 DO BEGIN ; Unfortunately, we don't know what filter was missed. neg=WHERE(typelist(*,c) EQ -1,nneg) IF nneg GT 0 THEN typelist(neg,c)=typelist(neg,1-c) neg=WHERE(texplist(*,c) EQ -1,nneg) IF nneg GT 0 THEN texplist(neg,c)=texplist(neg,1-c) ENDFOR ; To make things simple, put all parameters into a single array. asize=SIZE(filtlist) npairs=asize(1) allp=INTARR(npairs,6) allp(0,0)=filtlist allp(0,2)=typelist allp(0,4)=texplist ; By definition, the first cycle starts with the first pair of ; images: pair 0. cycle=[0] shifts=[0] ptr=0 maxshift=12 ; safe first guess ; Try to identify a probable cycle length. Heuristically, look ; for repetition of dark frames. Take the most frequently-occurring ; number of images from one dark frame to the next. wdark=WHERE(typelist EQ 3,nwdark) IF nwdark GT 0 THEN bshift=MEDIAN(wdark-SHIFT(wdark,1)) ELSE bshift=2 ; Now try shifting parameter arrays by increasing amounts, until ; all parameters repeat. flag=0B WHILE ptr LT npairs DO BEGIN ; loop through all pairs in image lists shift=0 REPEAT BEGIN shift=shift+1 sallp=allp-SHIFT(allp,-shift,0) sub=sallp(ptr:ptr+shift-1,*) tdiff=TOTAL(ABS(sub)) IF KEYWORD_SET(debug) THEN PRINT,ptr,shift,tdiff ENDREP UNTIL (((ABS(tdiff) LT 2) AND (shift GT bshift/2)) OR $ (shift EQ maxshift) OR (ptr+shift GE npairs)) ; If no normal cycle has been found in 12 pairs, do damage ; control by assuming most probably cycle length and going on. IF ((shift EQ maxshift) AND (tdiff NE 0)) THEN BEGIN MESSAGE,'Messy cycle starting at pair '+STRTRIM(ptr,2) $ ,/INFORMATIONAL flag=1B IF N_ELEMENTS(shifts) GT 2 THEN BEGIN sh_hist=HISTOGRAM(shifts,MIN=0,MAX=maxshift) best=MAX(sh_hist,shift) ENDIF ELSE shift=bshift ENDIF ; Update arrays of cycle start points and lengths, and pointer ; to start of current cycle cycle=[cycle,ptr+shift] shifts=[shifts,shift] ptr=ptr+shift ENDWHILE RETURN,[cycle,npairs] END