PRO qSave2File_Save, state, event ;+ ; NAME: ; qSave2File_Save ; PURPOSE: ; Saves data in binary file ; CATEGORY: ; Widget qSave2File ; CALLING SEQUENCE: ; qSave2File_Save, state, event ; INPUTS: ; state array[1]; type: structure ; qSave2File state structure ; event array[1]; type: structure ; event structure send by 'Save' widget ; OUTPUTS: ; (to disk file) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; GetFileSpec, SetFileSpec, bin_write ; PROCEDURE: ; > The type of binary file is decided by checking the state.wid_type widgets ; Currently the types 'pph','nic','gif' and 'bmp' are supported ; > The file name to be used is taken from the state.wid_file widget ; ; > The data array A to be saved is taken from the user value of the state.wid_save[0] widget. ; ; > If state.call_by_qimage = 1 then only A[*,*,0] is saved. This is used by the qImage ; widget. ; > If state.wid_single = 0 then A is stored in a single file irrespective of the number of ; dimensions ; > If state.wid_single = 1 then all images in the image cube A are stored in separate files ; Each file is given a sequence number which is appended to the file name. The sequence number ; is taken from the state.wid_save widget. If this is not present then the array index of the ; 3rd array dimension is used. ; ; > Once the data are saved to disk, the qSave2File widget is destroyed. ; MODIFICATION HISTORY: ; APR-2000, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- widget_control, state.wid_save, get_uvalue=wid_save wid_id = wid_save[0] ; Widget ID is_window = wid_save[1] ; Draw widget? widget_control, state.wid_file, get_value=filename filename = filename[0] CASE is_window OF 0: BEGIN filename = GetFileSpec(filename,upto='name')+'.pph' widget_control, wid_id, get_uvalue=Array, /no_copy IF IsType(Array,/defined) THEN BEGIN sz = size(Array) widget_control, state.wid_single, get_uvalue=set CASE 1 OF state.call_by_qimage: bin_write, filename, Array[*,*,0], trailer=state.trailer 1-set : bin_write, filename, Array, trailer=state.trailer ELSE: BEGIN n = (size(Array))[3] IF n_elements(wid_save) EQ 2 THEN id = indgen(n) ELSE id = wid_save[2:*] SetFileSpec, filename name = GetFileSpec(upto='name') type = GetFileSpec(part='type') FOR i=0,n-1 DO bin_write, name+string(id[i],format='(I3.3)')+type, Array[*,*,i] END ENDCASE widget_control, wid_id, set_uvalue=Array, /no_copy ENDIF END 1: BEGIN wold = !d.window ; Remember the old window number widget_control, wid_id, get_value=wnew ; Get the window number of the draw widget IF wold NE wnew THEN wset, wnew ; Switch to draw widget get_page, filename IF wold NE wnew THEN wset, wold ; Restore the old window number END ENDCASE widget_control, event.handler, /destroy RETURN & END