PRO getcycles,n,t,filtlist,typelist,texplist,cycle,cyclen $ ,debug=debug,cont=cont ; Identify the first images or image pairs of repeated sequences. ; With DOS-controlled image acquisition, typical exposure times ; are 1, 10, and 60 s, with correponding inter-image elapsed times ; of 5, 14, and 64 s; any consistently- occurring elapsed times ; much longer than these probably indicate the end of a data-taking ; sequence and the start of another one. With operator-controlled ; image acquisition, exposure times are similar, but images are ; acquired continuously without dropping back to DOS (so no longer ; intervals between images to pinpoint cycle starts). IF KEYWORD_SET(cont) THEN BEGIN ; Continuous data acquisition requires a different definition of a ; cycle and different methods of identifying the start of a cycle. ; Start with discontinuities in filter sequences. fseq0=TRANSPOSE(filtlist(0,*)) ; sequence of Cam 0 filters fseq1=TRANSPOSE(filtlist(1,*)) ; sequence of Cam 1 filters ; Remove artificial discontinuities caused by missed images; assume ; only one camera misses an image at a time wneg=WHERE(fseq0 EQ -1,nwneg) IF nwneg GT 0 THEN fseq0(wneg)=fseq1(wneg) wneg=WHERE(fseq1 EQ -1,nwneg) IF nwneg GT 0 THEN fseq1(wneg)=fseq0(wneg) fchng0=fseq0-SHIFT(fseq0,1) ; Cam 0 filter change fchng1=fseq1-SHIFT(fseq1,1) ; Cam 1 filter change ; Now find negative values of fchng# fcycle=WHERE((fchng0 LT 0) AND (fchng1 LT 0),nf) ; ; Now look for changes in image type ; tseq0=TRANSPOSE(typelist(0,*)) ; sequence of Cam 0 image types tseq1=TRANSPOSE(typelist(1,*)) ; sequence of Cam 1 image types ; As above, remove artificial discontinuities wneg=WHERE(tseq0 EQ -1,nwneg) IF nwneg GT 0 THEN tseq0(wneg)=tseq1(wneg) wneg=WHERE(tseq1 EQ -1,nwneg) IF nwneg GT 0 THEN tseq1(wneg)=tseq0(wneg) tchng0=tseq0-SHIFT(tseq0,1) ; Cam 0 image type change tchng1=tseq1-SHIFT(tseq1,1) ; Cam 1 image type change tcycle=WHERE((tchng0 NE 0) AND (tchng1 NE 0),nt) ; ; Now merge the two definitions to try to catch all possible ; types of cycle. ; cycle=[fcycle,tcycle] cycle=cycle(uniq(cycle,SORT(cycle))) HELP,fcycle,tcycle,cycle STOP ; ENDIF ELSE BEGIN ; dt=(t(*,0)-SHIFT(t(*,0),1))>0 ; ; Try decreasing threshold time below 75 s if no cycles identified. ; thresh=75 REPEAT BEGIN cycle=[WHERE(dt GT thresh),n] ; extra element simplifies finding ; last image in last cycle tcyclen=(cycle-SHIFT(cycle,1))>0 success=(N_ELEMENTS(cycle) GT 2) AND $ (N_ELEMENTS(cycle) GT n/7) AND $ (MAX(tcyclen) LT 7) thresh=thresh-1 ENDREP UNTIL success OR (thresh LT 67) IF success $ THEN MESSAGE,STRING(thresh+1 $ ,FORMAT='("Cycles detected with ",I2,' $ +'"-s threshold")') $ ,/INFORMATIONAL ; If the above technique doesn't work, we probably have continuous ; image acquisition without dropping back to DOS. Try another tack. ; IF (((N_ELEMENTS(cycle) EQ 2) AND (MAX(cycle-[-1,n]) EQ 0)) OR $ ; (N_ELEMENTS(cycle) LT n/7)) THEN BEGIN ; flag=0 ; cycle=tryshift(filtlist,typelist,texplist,flag,debug=debug) ; ENDIF ; IF N_ELEMENTS(flag) EQ 0 THEN flag=0 ; IF flag AND NOT KEYWORD_SET(debug) THEN $ ; PRINT,'Had a spot of trouble sorting out the cycles, you know' ENDELSE IF cycle(0) NE 0 $ ; first cycle SHOULD start at image 0 THEN cycle=[0,cycle] cyclen=(cycle-SHIFT(cycle,1))>0 cycle=cycle(0:N_ELEMENTS(cycle)-2) cyclen=cyclen(1:*) HELP,cycle,cyclen STOP RETURN END