;----------------------------------------------------------------- ; cinedisplay.pro - display color cine files, with keyboard controls. ; ; setenv DISPLAY nstxwindowspc:0 ; idl ; CINEdisplay, dir='/p/nstxusr2/phantom4/',mag=1,ctb=3, loops=1000, $ ; xpos=2822, ypos=55, /verb ; ; CINEdisplay, dir='/p/nstxusr2/nstxphantom7/',mag=1,ctb=3, loops=1000, $ ; xpos=2822, ypos=55, /scale ; ; IDL> CINEdisplay, '/p/nstxusr2/miro/MIRO_130242.cin',mag=1 ; ; IDL> CINEdisplay, dir='/p/nstxusr2/miro/' ; ; IDL> CINEdisplay, '/p/nstxusr2/phantom4/NSTX_130363.cin',mag=1, ctb=3 ; ; 28-Jun-2008 hacked up to show in 8-bits on the wall, or wherever [Bill Davis] ; WRITTEN 27-Jun-2008 by Ron Bell for Lane Roquemore's Color Miro camera ;------------------------------------------------------------------ pro CINEdisplay, cine_in, dir=dir, keys=keys, rgb=rgb, pause=pause, $ loops=loops, mag=mag, charmag=charmag, gamma=gamma, $ xpos=xpos, ypos=ypos, ctb=ctb, mult=mult, scale=scale, $ help=help, verbose=verbose, debug=debug if keyword_set( help ) then begin print, "IDL> file=dialog_pickfile(filter='/p/nstxusr2/miro/MIRO_*.cin')" print, "IDL> cinedisplay,file,/keys,/large" print, " print, "'RIGHT' or '>' move forward 1 frame" print, "'LEFT' or '<' move backward 1 frame" print, "'UP' move bit level up on right frame" print, "'DOWN' move bit level down on right frame" print, "'PAGEUP' or 'L' fast forward (move ahead 10 frames)" print, "'PAGEDOWN' or 'K' fast reverse (move back 10 frames)" print, "'Q' to quit" print, "'C' to continue to end" print, "'S' to stop (resume with IDL>.cont)" return endif if n_elements( debug ) eq 0 then debug=0 if n_elements( verbose ) eq 0 then verbose=0 if n_elements( scale ) eq 0 then scale=1 if n_elements( mult ) eq 0 then begin mult=1.0 scale = 0 endif else begin scale = 1 endelse if n_elements( scale ) eq 0 then scale=0 Error_status=0 ; Establish error handler. When errors occur, the index of the ; error is returned in the variable Error_status: if not debug then CATCH, Error_status ;This statement begins the error handler: IF Error_status NE 0 THEN BEGIN PRINT, 'FROM '+proname()+':' PRINT, 'Error index: ', Error_status PRINT, 'Error message: ', !ERROR_STATE.MSG ;;; writelog, logFile, ' >>>(in sumEvents.pro) error:'+!ERROR_STATE.MSG, nlines=3 ;;; CATCH, /CANCEL stat=0 if n_elements( lun ) gt 0 then begin close, lun free_lun, lun endif wait, 5 if debug then stop return ENDIF if n_elements(ctb) eq 0 then ctb=0 if n_elements(keys) eq 0 then keys=0 if n_elements(rgb) eq 0 then rgb=0 if n_elements(pause) eq 0 then pause=0.00 if n_elements(mag) eq 0 then mag=2 if n_elements(charmag) eq 0 then charmag=2 if n_elements(xpos) eq 0 then xpos=150 if n_elements(ypos) eq 0 then ypos=50 if n_elements(loops) eq 0 then loops=1000L if n_elements(dir) eq 0 then begin CASE !version .os OF 'Win32' : dir = 'C:\MIRO_files\' ELSE : dir = '/p/nstxusr2/phantom4/' ENDCASE endif delim = get_delim() if nwords( cine_in ) ne 0 then begin cine = cine_in endif else begin cine = findlastfile( dir + delim + '*.cin') endelse p=strpos(cine,'.cin') shota=strmid(cine,p-6,6) cine_time,cine,time,fr helpm,time ; -- Check endian -- test=byte(1,0,2) if test[0] eq 1b then little_endian=1 else little_endian=0 ;on_ioerror,the_end openr,lun,cine,/get_lun, /swap_if_big_endian firstimage=0L point_lun,lun,16 readu,lun,firstimage imagecount=0UL point_lun,lun,20 readu,lun,imagecount help,firstimage,imagecount ;if ((frame lt firstimage) or (frame gt firstimage+imagecount-1)) then begin ; print,'Desired frame not available' ; goto,the_end ; free_lun,lun ;endif Compression=0U point_lun,lun,4 readu,lun,Compression ; Read pointers, i.e. offsets to Image Header, Setup, and ImageOffsets structures pointers=ulonarr(3) point_lun,lun,24 readu,lun,pointers ; Set parameters xpix=0L ypix=0L BitCount=0L biCompression=0UL SizeImage=0UL Xpix_per_meter=0L Ypix_per_meter=0L ClrImportant=0UL pps=0UL exposure=0UL pimage=ulon64arr(imagecount) aux=0UL CFA=0UL ; Read parameters point_lun,lun,pointers[0]+4 readu,lun,xpix point_lun,lun,pointers[0]+8 readu,lun,ypix point_lun,lun,pointers[0]+14 readu,lun,BitCount point_lun,lun,pointers[0]+16 readu,lun,biCompression readu,lun,SizeImage point_lun,lun,pointers[0]+24 readu,lun,Xpix_per_meter point_lun,lun,pointers[0]+28 readu,lun,Ypix_per_meter point_lun,lun,pointers[0]+36 readu,lun,ClrImportant point_lun,lun,pointers[1]+768 readu,lun,pps point_lun,lun,pointers[1]+772 readu,lun,exposure point_lun,lun,pointers[1]+808 readu,lun,CFA point_lun,lun,pointers[2] readu,lun,pimage ;point_lun,lun,pimage[frame-firstimage] ;readu,lun,aux help,compression case compression of 0: color=0 ; gray 1: color=-1 ; jpeg 2: color=1 ; uninterpolated color image endcase ;help,Compression ;help,xpix,ypix,Bitcount,biCompression,ClrImportant,pps,exposure,pimage,aux ;help,Xpix_per_meter,Ypix_per_meter ;help,CFA ;help,SizeImage if keyword_set( verbose ) then begin print, '----------------------------------------------------------------------' print, 'image size = ', xpix, ' by ', ypix print, 'compression = ', compression print, 'bitcount = ', bitcount if n_elements( imagesize ) gt 0 then print, 'image size (bytes) = ', imagesize endif ; for 8 bit ADC's if bitcount eq 8 then img=BYTARR(xpix,ypix) ; for 10 - 16 bit ADC's if bitcount gt 8 then img=UINTARR(xpix,ypix) ; Read raw image if bitcount eq 8 then begin a=bytarr(xpix,ypix) endif else begin a=uintarr(xpix,ypix) endelse sz=size(a) ix=sz[1]/2 iy=sz[2]/2 if color then begin image=uintarr(3,ix,iy) thisimage=image if rgb then im=uintarr(3,ix,iy) rx=reverse(indgen(ix)) ry=reverse(indgen(iy)) endif factor1=4.0 factor2=1.0 factor=[0.125,0.25,0.5,1.,2.,4.,8,16] nfactor=n_elements(factor) ifactor=near(factor,0.25) xsize=ix*mag*2 ysize=iy*mag*2 + !d.y_ch_size*(charmag+2.5) + 6 if color eq 1 then begin if rgb then begin window,11,xsize=xsize,ysize=ysize, xpos=xpos, ypos=ypos endif else begin window,11,xsize=xsize/2,ysize=ysize/1.8, xpos=xpos, ypos=ypos endelse endif else begin window,11,xsize=xsize,ysize=ysize, xpos=xpos, ypos=ypos endelse device,decompose=0 loadct,ctb if n_elements( gamma ) gt 0 then gamma_ct, gamma screen_title, shota, charsize=charmag, nstx=0 ;;;, charsize=charmag blackBox = replicate(colorsearch('black'), xsize, !d.y_ch_size*charMag+3) biggest = 0 smallest = 100000L if !d.name eq 'X' then wshow help,firstimage,firstimage+imagecount-1 imgRaw = temporary( a ) checkedSize = 0 for loop = 0, loops-1 do begin for frame=firstimage,firstimage+imagecount-1 do begin next_frame: point_lun, lun, pimage[frame-firstimage]+aux readu, lun, imgRaw ind = where( imgRaw gt 20000L, nfound ) if nfound gt 0 then img[ind] = 0 if debug then stop if NOT checkedSize then begin dims = size( imgRaw, /dim ) if n_elements( dims ) eq 3 then begin endif else begin endelse checkedSize = 1 endif if color eq 1 then begin img=reform(imgRaw,2,ix,2,iy,/overwrite) red=reform(img[0,*,0,*]) g1=reform(img[1,*,0,*]) g2=reform(img[0,*,1,*]) blue=reform(img[1,*,1,*]) green=NINT((g1+g2)/2.) image[0,*,*]=red image[1,*,*]=green image[2,*,*]=blue ;;; a=reform(a,xpix,ypix,/overwrite) thisimage=image[*,rx,ry] if mag gt 1 then thisImage = rebin( thisImage, 3, ix*mag, iy*mag ) tv, bytscl(thisImage), 0, !d.y_ch_size*charmag, /true ;;; xyouts,/device,xpix-20,ypix-20,shota,color=white,charsize=charmag,/center if not keys then begin if pause gt 0 then wait, pause endif endif else begin if mag gt 1 then begin dims = SIZE( imgRaw, /dim ) img = rebin( imgRaw, dims[0]*mag, dims[1]*mag ) endif else begin img = imgRaw endelse if scale then tv, img*mult, 0, !d.y_ch_size*charmag $ else tv, bytscl( img ), 0, !d.y_ch_size*charmag endelse maxim = MAX( img, MIN=minim ) biggest = biggest > maxIm smallest = smallest < maxIm if verbose then print, 'frame, min, max=', frame, minIm, maxIm if max(time) lt 0 then begin thistime=time[frame-firstimage]-time[0] endif else begin thistime=time[frame-firstimage] endelse ;;;print, thistime tv, blackBox, 0, 0 xyouts,/device, 3, 3, strtrim(string(thistime,format='(F9.4)'),2)+'s', $ color=white, charsize=charmag if keys then begin check_keyboard: response=get_kbrd(1,/KEY_NAME) case strupcase(response) of ',': begin frame=frame-1 ; move backward if frame lt firstimage then frame=firstimage+imagecount-1 goto, next_frame end '.': if frame eq firstimage+imagecount-1 then frame=firstimage ; move forward or loop back 'K': begin frame=frame-10 ; move backward if frame lt firstimage then frame=firstimage+imagecount-1 goto, next_frame end 'L': begin frame=frame+10-1 if frame ge firstimage+imagecount-1 then frame=firstimage ; move forward or loop back end 'PAGEDOWN': begin frame=frame-10 ; move backward if frame lt firstimage then frame=firstimage+imagecount-1 goto, next_frame end 'PAGEUP': begin frame=frame+10-1 if frame ge firstimage+imagecount-1 then frame=firstimage ; move forward or loop back end 'LEFT': begin frame=frame-1 ; move backward if frame lt firstimage then frame=firstimage+imagecount-1 goto, next_frame end 'RIGHT': if frame eq firstimage+imagecount-1 then frame=firstimage ; move forward or loop back 'C': keys=0 'S': stop 'W': if !d.name eq 'X' then wshow 'B': begin ifactor=ifactor+1 if ifactor gt nfactor-1 then ifactor=0 if ifactor lt 0 then ifactor=nfactor-1 frame=frame-1 ; stay on current frame end 'V': begin ifactor=ifactor-1 if ifactor lt 0 then ifactor=nfactor-1 ; frame=frame-1 ; stay on current frame end 'UP': begin ifactor=ifactor+1 if ifactor gt nfactor-1 then ifactor=0 if ifactor lt 0 then ifactor=nfactor-1 ; frame=frame-1 ; stay on current frame goto, next_frame end 'DOWN': begin ifactor=ifactor-1 if ifactor lt 0 then ifactor=nfactor-1 ; frame=frame-1 ; stay on current frame goto, next_frame end 'Q': begin free_lun,lun return end else: begin help,response help,(byte(response))[0] goto, check_keyboard end endcase if !d.name eq 'X' then wshow endif endfor wait, 1 ENDFOR if n_elements( biggest ) gt 0 then begin print, ' ' print, ' data between ', biggest, smallest print, ' ' endif close,lun free_lun, lun if !d.window gt -1 then wdelete, !d.window return the_end:& close, lun free_lun, lun message,/informational,' Error in CINEdisplay ' if !d.window gt -1 then wdelete, !d.window return end