PRO qView_Save2File, state, event, wid_send=wid_send, send_event=send_event ;+ ; NAME: ; qView_Save2File ; PURPOSE: ; Save the currently loaded image cube to disk. ; CATEGORY: ; Widget qView ; CALLING SEQUENCE: ; qView_Save2File, state ; INPUTS: ; state array[1]; type: structure ; qView state structure ; OUTPUTS: ; (to disk) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; qView_ImageInfo, bin_write, SetFileSpec, GetFileSpec ; PROCEDURE: ; The IDL 'pickfile' dialog is used to select a directory and a filename ; (default directory is $TUB; default file name is qview.pph). ; Each image from the image cube is written into a separate binary file. ; A sequence number is added after the selected file name as an I3.3 integer, ; i.e. qview001.pph. The sequence number is based on the file index for ; each image. ; ; The binary files can be read using ; status = bin_read(file_name, img, /header) ; qView uses this read statement for files with extension '.pph' ; STATE INFO USED: ; widget_control, state.wid_data, get_uvalue=data, /no_copy ; STATE INFO MODIFIED: ; widget_control, state.wid_data, set_uvalue=data, /no_copy ; MODIFICATION HISTORY: ; FEB-2000, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- status = qImage_TriggerSend(event, state.wid_view, state.wid_save, wid_send, send_event) CASE status OF 0B: ; No qImage widget exists (yet) 1B: RETURN ; Return to event handler to send 'send_event' to 'wid_send' 2B: qView_SetInfo, state, event ; Process QIMAGE_SEND event ENDCASE CASE qView_GetInfo(state, offset=offset, subdim=subdim, zoom=zoom, box=box, $ zhilo=zhilo, fixz=fixz, zlog=zlog) OF 0: BEGIN widget_control, state.wid_data, get_uvalue=data, /no_copy movie = data widget_control, state.wid_data, set_uvalue=data, /no_copy fake_state = [0,0] END 1: BEGIN box = ((box-offset#[1,1]) > 0) < (subdim-1)#[1,1] widget_control, state.wid_data, get_uvalue=data, /no_copy movie = MagnifyArray(data[box[0]:box[2], box[1]:box[3],*], zoom, dims=2) widget_control, state.wid_data, set_uvalue=data, /no_copy fake_state = [fixz, zlog, zhilo] END ENDCASE file = dialog_pickfile(/write, file='qview.pph', $ path=filepath(root=getenv('TUB'),''), group=state.wid_data) IF file NE '' THEN BEGIN movie = qImage_cw_MinMax(fake_state, movie, /nostate, /to_byte) img = qView_ImageInfo(state, /number, /list) ; List of selected files nimg = img[0] img = img[1:*] SetFileSpec, file name = GetFileSpec(upto='name') type = GetFileSpec(from='type', upto='type') ; the way IDL handles ppm using write_ppm disregards the color table ; so i get the color table, then use write_image to include the right ; color table tvlct, r, g, b, /get widget_control, state.wid_pick, get_uvalue=allfiles ;get filenames frames = strarr(n_elements(allfiles)) ; make an array to put the split filenames into to send them safely to mk_flick print, "Creating images for video..." FOR i=0,nimg-1 DO BEGIN SetFileSpec, allfiles[i] frames[i] = GetFileSpec(from='name',upto='name') timetest = strsplit(frames[i], "_", /extract) IF n_elements(timetest) EQ 4 THEN BEGIN ; assume file names give possible time stamp ; and convert frames[i] to contain timestamp rather ; than file name. frames[i] = timetest[2]+' '+ timeset(year=fix(strcompress(timetest[1],/rem)),doy=fix(strcompress(timetest[2], /rem)),hour=fix(strmid(timetest[3],0,2)), minute=fix(strmid(timetest[3],2,2)), sec=fix(strmid(timetest[3],4,2)),/stringt,/ymd,upto=timeunit(/sec)) ; create a time string ENDIF ELSE IF I EQ 0 THEN print, 'File list does not appear to contain data for time stamping.' CASE type OF '.pph': bin_write, name+string(img[i],format='(I4.4)')+type, movie[*,*,i] '.gif': write_gif, name+string(img[i],format='(I4.4)')+type, movie[*,*,i] '.avi': write_image, name+string(img[i],format='(I4.4)')+'.ppm','PPM', reverse(movie[*,*,i],2), r,g,b ; rgb preserves color table and reverse flips the image vertically (ppm writes the image upside down...) '.png': write_png, name+string(img[i],format='(I4.4)')+type, movie[*,*,i] ELSE : ENDCASE ENDFOR CASE type OF '.png': mk_flick, name+'.mng', name+'*'+type, delay=10, /loop, /png '.gif': mk_flick, name+'.gif', name+'*'+type, delay=10, /loop, /gif '.avi': BEGIN fpsbits = qSlider([1,30,13,300,1300,1000], ["FPS", "BitRate"]) IF isArray(fpsbits) THEN BEGIN mk_flick, name+'.avi', name+'*.ppm', /avi, fps=fpsbits[0], bits=fpsbits[1], /timestamp, frames=frames ENDIF ELSE BEGIN print, 'File not saved, widget canceled or closed.' RETURN ENDELSE END ELSE: ENDCASE ENDIF RETURN & END