;+ ; ; @file_comments ; ; @categories ; ; @param EVENT ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ; ; @todo ; seb: documenter EVENT ; ;- PRO selectfile_event, event ; compile_opt idl2, strictarrsubs ; @common ; widget_control, event.id, get_uvalue = eventuvalue ; default definition of messenger when selectfile_event is called ; directly without calling xmanager widget_control, event.handler, get_uvalue = messenger *messenger = -1 IF chkstru(eventuvalue, 'name') EQ 0 THEN return case eventuvalue.name of ; cancel button 'Global Cancel':BEGIN widget_control, event.handler, get_uvalue = messenger *messenger = -1 widget_control, event.handler, /destroy END ; data file informations 'datafilename':BEGIN widget_control, event.id, get_value = filename filename = isafile(filename = filename[0], /onlync, iodirectory = iodir $ , title = 'data file name', /tryfind, /fully_qualify_path) if size(filename, /type) NE 7 then BEGIN widget_control, event.id, set_value = '' return ENDIF widget_control, event.id, set_value = filename END 'browse datafilename':BEGIN filename = isafile(/onlync, title = 'data file name', /tryfind, /fully_qualify_path, iodirectory = iodir) if size(filename, /type) NE 7 then return widget_control, widget_info(event.handler, find_by_uname = 'datafilename') $ , set_value = filename END ; switch automatic/by and mesh definition buttons 'gridload':BEGIN IF event.select EQ 1 THEN BEGIN widget_control, widget_info(event.handler, find_by_uname = 'argtxt'), set_value = '' widget_control, widget_info(event.handler, find_by_uname = 'kwdtxt'), set_value = '' widget_control, widget_info(event.handler, find_by_uname = 'kwd base'), sensitive = 1 CASE event.value OF 'via initnetcdf':BEGIN widget_control, widget_info(event.handler, find_by_uname = 'meshload'), set_value = 'initncdf', editable = 0 widget_control, widget_info(event.handler, find_by_uname = 'arg base'), sensitive = 0 widget_control, widget_info(event.handler, find_by_uname = 'kwdlab'), set_value = 'initncdf keywords:' END 'via perso':BEGIN widget_control, widget_info(event.handler, find_by_uname = 'meshload'), set_value = '', editable = 1 widget_control, widget_info(event.handler, find_by_uname = 'arg base'), sensitive = 1 widget_control, widget_info(event.handler, find_by_uname = 'kwdlab'), set_value = 'keywords of IDL procedure:' END ENDCASE ENDIF END ; name of the procedure or batch file 'meshload':BEGIN widget_control, event.id, get_value = filename filename = find(filename[0], /onlypro, /firstfound) if filename EQ 'NOT FOUND' then begin widget_control, event.id, set_value = '' return endif CASE protype(filename) OF ; this is a procedure 'proc':BEGIN widget_control, widget_info(event.handler, find_by_uname = 'arg base'), sensitive = 1 widget_control, widget_info(event.handler, find_by_uname = 'kwd base'), sensitive = 1 widget_control, widget_info(event.handler, find_by_uname = 'kwdlab'), set_value = file_basename(filename, '.pro')+' keywords:' END ; this is a function, this case is not accepted 'func':BEGIN widget_control, event.id, set_value = '' return END ; this is an IDL batch file 'batch':BEGIN widget_control, widget_info(event.handler, find_by_uname = 'arg base'), sensitive = 0 widget_control, widget_info(event.handler, find_by_uname = 'kwd base'), sensitive = 0 widget_control, widget_info(event.handler, find_by_uname = 'kwdlab'), set_value = 'no keywords:' END ENDCASE widget_control, widget_info(event.handler, find_by_uname = 'argtxt'), set_value = '' widget_control, widget_info(event.handler, find_by_uname = 'kwdtxt'), set_value = '' widget_control, event.id, set_value = file_basename(filename, '.pro') END 'browse meshload':BEGIN filename = isafile(iodir = homedir, /onlypro, title = 'to load the grid file') if size(filename, /type) NE 7 then return meshload_id = widget_info(event.handler, find_by_uname = 'meshload') widget_control, meshload_id, set_value = filename selectfile_event, {ID:meshload_id, TOP:event.top, HANDLER:event.handler} END ; 'Lets Go!' button 'Lets Go!':BEGIN widget_control, widget_info(event.handler, find_by_uname = 'datafilename') $ , get_value = datafilename datafilename = datafilename[0] IF datafilename EQ '' THEN return datafilename = isafile(filename = datafilename, /tryfind, /onlync $ , title = 'data file name', /fully_qualify_path) if size(datafilename, /type) NE 7 then BEGIN widget_control, widget_info(event.handler, find_by_uname = 'datafilename') $ , set_value = '' return ENDIF widget_control, widget_info(event.handler, find_by_uname = 'gridload') $ , get_value = gridload widget_control, widget_info(event.handler, find_by_uname = 'argtxt') $ , get_value = argtxt argtxt = strtrim(argtxt[0], 2) IF strpos(argtxt, ',') EQ 0 THEN argtxt = strmid(argtxt, 1) widget_control, widget_info(event.handler, find_by_uname = 'kwdtxt') $ , get_value = kwdtxt kwdtxt = strtrim(kwdtxt[0], 2) IF strpos(kwdtxt, ',') EQ 0 THEN kwdtxt = strmid(kwdtxt, 1) CASE gridload[0] OF 'via perso':BEGIN meshload_id = widget_info(event.handler, find_by_uname = 'meshload') widget_control, meshload_id, get_value = meshload meshload = meshload[0] IF meshload EQ '' THEN return meshload = find(meshload[0], /onlypro, /firstfound) if meshload EQ 'NOT FOUND' then begin widget_control, meshload_id, set_value = '' return endif END 'via initnetcdf':meshload = datafilename ENDCASE IF strlen(argtxt) NE 0 THEN meshload = meshload + ', ' + argtxt IF strlen(kwdtxt) NE 0 THEN meshload = meshload + ', ' + kwdtxt widget_control, event.handler, get_uvalue = messenger *messenger = create_struct('datafilename', datafilename, 'meshload', meshload) widget_control, event.handler, /destroy END ELSE: endcase return end ; ;+ ; ; @file_comments ; ; @categories ; ; @param DATAFILENAME ; ; ; @param IDLFILE ; ; ; @param ARGSPRO ; ; @keyword _EXTRA ; Used to pass keywords ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ; ; @todo ; seb: documenter les params ; ;- FUNCTION selectfile, datafilename, idlfile, argspro, _EXTRA=ex ; compile_opt idl2, strictarrsubs ; @common ; ; We create a pointer in the uvalue to recuperate answers at setted ; questions atthe time of the use of this widget. So when the widget ; is deleted in the procedure ...event.pro, the variable on which the ; pointer pointed (contained in the uvalue of the widget) is not ; deleted and we can recuperate the result! ; messenger = ptr_new(/allocate_heap) base = widget_base(/column, title = 'selectfile', /align_center, uvalue = messenger, _EXTRA = ex) ; cancel button dummyid = widget_button(base, value = 'Cancel', uvalue = {name:'Global Cancel'}) ; data file informations basea = widget_base(base, /row, /align_center) dummyid = widget_label(basea, value = 'Data file name: ') database = widget_text(basea, value = '', uvalue = {name:'datafilename'} $ , uname = 'datafilename', xsize = 45, /EDITABLE) dummyid = widget_button(basea, value = 'Browse', uvalue = {name:'browse datafilename'}) ; switch automatic/by and mesh definition buttons baseb = widget_base(base, /row, /align_center) gdldid = cw_bgroup(baseb, ['automatic grid construction with initncdf.pro' $ , 'grid construction with other IDL batch or procedure'] $ , /exclusive, set_value = 0, uvalue = {name:'gridload'} $ , uname = 'gridload', button_uvalue = ['via initnetcdf', 'via perso']) ; name of the procedure or batch file basec = widget_base(base, /row, /align_center, uname = 'pro base') dummyid = widget_label(basec, value = 'IDL batch file of procedure') basemeshload = widget_text(basec, value = 'initncdf', uvalue = {name:'meshload'} $ , uname = 'meshload', xsize = 45, editable = 0) dummyid = widget_button(basec, value = 'Browse', uvalue = {name:'browse meshload'}) ; arguments informations based = widget_base(base, /row, /align_center, uname = 'arg base', sensitive = 0) dummyid = widget_label(based, value = 'procedure arguments') argbase = widget_text(based, value = '', uvalue = {name:'argtxt'} $ , uname = 'argtxt', xsize = 45, /EDITABLE) ; keyword informations basee = widget_base(base, /row, /align_center, uname = 'kwd base') dummyid = widget_label(basee, uname = 'kwdlab', value = ' keywords of initncdf:') dummyid = widget_text(basee, value = '' $ , uvalue = {name:'kwdtxt'}, uname = 'kwdtxt', xsize = 45, /EDITABLE) ; 'Lets Go!' button basego = widget_button(base, value = 'Lets Go!', uvalue = {name:'Lets Go!'}) ;------------------------------------------------------------ IF n_elements(datafilename) NE 0 THEN BEGIN widget_control, database, set_value = datafilename selectfile_event, {ID:database, TOP:base, HANDLER:base} ENDIF IF n_elements(idlfile) NE 0 THEN BEGIN idlfile = isafile(filename = idlfile, /onlypro, title = '.pro file used to define the grid?') widget_control, basemeshload, set_value = idlfile selectfile_event, {ID:basemeshload, TOP:base, HANDLER:base} widget_control, basemeshload, get_value = idlfile2 widget_control, gdldid, set_value = 1 ENDIF IF n_elements(argspro) NE 0 THEN widget_control, argbase, set_value = argspro ;------------------------------------------------------------ IF n_elements(datafilename) EQ 0 THEN BEGIN widget_control, base, /realize xmanager, 'selectfile', base, event_handler = 'selectfile_event', no_block = 0 ENDIF ELSE selectfile_event, {ID:basego, TOP:base, HANDLER:base} ;------------------------------------------------------------ ; get back the information from selectfile_event res = *messenger ptr_free, messenger if size(res, /type) NE 8 then return, -1 loadgrid, res.meshload, _extra = ex ccreadparameters = {funclec_name:'read_ncdf' $ , jpidta:jpidta, jpjdta:jpjdta, jpkdta:jpkdta $ , ixmindta:ixmindta, ixmaxdta:ixmaxdta $ , iymindta:iymindta, iymaxdta:iymaxdta $ , izmindta:izmindta, izmaxdta:izmaxdta} res3 = scanfile(res.datafilename, _extra = ex) if size(res3, /type) NE 8 then return, -1 return, {fileparameters:res3, readparameters:ccreadparameters, meshparameters:ccmeshparameters} end