; $Id: ; ; Copyright (c) 1995, Research Systems, Inc. All rights reserved. ; Unauthorized reproduction prohibited. ;+ ; NAME: ; GetImage ; ; PURPOSE: ; This procedure retrieves an image file from the examples/data directory. ; ; CATEGORY: ; Examples General. ; ; CALLING SEQUENCE: ; GetImage, newdata ; ; KEYWORD PARAMETERS: ; ; OUTPUTS: ; newdata:The image data is returned in this variable. ; ; COMMON BLOCKS: ; GF: ; ; RESTRICTIONS: ; This procedure can only be used to reference the example data. ; ; PROCEDURE: ; ; EXAMPLE: ; GetImage, frames, DESCRIPTION=description, $ ; DIMENSIONS=dimensions, SUBDIR = ["examples","data"], $ ; /THREE_DIM, TITLE="Select Animation", /ASSOC_IT ; ; MODIFICATION HISTORY: Written by: WSO, RSI, January 1995 ;- ;------------------------------------------------------ ; procedure GetImageEventHdlr ;------------------------------------------------------ PRO GetImageEventHdlr, event COMMON GF, selection WIDGET_CONTROL, event.id, GET_UVALUE = selected CASE selected OF "FILELST": BEGIN selection = event.index ; If double clicking on a list item - emulate OK button IF event.clicks EQ 2 THEN BEGIN selection = selection + 1 WIDGET_CONTROL, event.top, SENSITIVE = 0 WIDGET_CONTROL, event.top, /DESTROY ENDIF END "OK": BEGIN selection = selection + 1 WIDGET_CONTROL, event.top, SENSITIVE = 0 WIDGET_CONTROL, event.top, /DESTROY END "CANCEL": BEGIN WIDGET_CONTROL, event.top, /DESTROY selection = 0 END ENDCASE END ;---------- end of procedure GetImageEventHdlr ------------ ;------------------------------------------------------ ; procedure GetImage ;------------------------------------------------------ PRO GetImage, newdata, DESCRIPTION = description, $ DIMENSIONS = dimensions, ONE_DIM = one_dim, TWO_DIM = two_dim, $ THREE_DIM = three_dim, TITLE = title, FILENAME = filename, $ OFILENAME = ofilename, ASSOC_IT = assoc_it, $ SUBDIRECTORY = subdirectory COMMON GF, selection datapath = FILEPATH("", SUBDIRECTORY=subdirectory) name = '' dim = LONARR(3) des = '' del = '' numfiles = 0L one_mask = 1 two_mask = 2 three_mask = 4 newdata = 0 description = 0 dimensions = 0 IF (KEYWORD_SET(filename)) THEN BEGIN OPENR, unit, datapath + "data.txt", /GET_LUN READF, unit, numfiles IF (numfiles NE 0) THEN BEGIN goodindex = 0 nameindex = 0 WHILE((nameindex LT (numfiles)) AND (goodindex EQ 0)) DO BEGIN READF, unit, name, dim, des, del IF (name EQ filename) THEN $ goodindex = 1 IF (del NE '*') THEN $ MESSAGE, "* delimiter not found in data.txt" ENDWHILE FREE_LUN, unit IF (goodindex NE 0) THEN BEGIN ofilename = filename OPENR, unit, datapath + filename, /GET_LUN, /BLOCK IF KEYWORD_SET(assoc_it) THEN $ newdata = ASSOC(unit, BYTARR(dim(0),dim(1))) $ ELSE BEGIN newdata = BYTARR(dim(0), dim(1), dim(2)) READU, unit, newdata FREE_LUN, unit ENDELSE description = des dimensions = dim ENDIF ENDIF ENDIF $ ELSE $ IF ((XRegistered("GetImage") EQ 0)) THEN BEGIN FILTER = 0 IF KEYWORD_SET(one_dim) THEN $ filter = filter OR one_mask IF KEYWORD_SET(two_dim) THEN $ filter = filter OR two_mask OR three_mask IF KEYWORD_SET(three_dim) THEN $ filter = filter OR three_mask IF (FILTER EQ 0) THEN $ filter = one_mask + two_mask + three_mask OPENR, unit, datapath + "data.txt", /GET_LUN READF, unit, numfiles IF (numfiles NE 0) THEN BEGIN names = STRARR(numfiles) descriptions = STRARR(numfiles) dimensions = LONARR(3, numfiles) goodindex = 0 FOR nameindex = 0, numfiles - 1 DO BEGIN READF, unit, name, dim, des, del tempfilt = 0 IF dim(0) GT 1 THEN $ tempfilt = one_mask IF dim(1) GT 1 THEN $ tempfilt = two_mask ; Restrict animations to more than 2 images IF dim(2) GT 2 THEN $ tempfilt = three_mask IF ((tempfilt AND filter) NE 0) THEN BEGIN names(goodindex) = name dimensions(*, goodindex) = dim descriptions(goodindex) = des goodindex = goodindex + 1 ENDIF IF (del NE '*') THEN $ button = WIDGET_MESSAGE("* delimiter not found in data.txt", /ERROR) ENDFOR FREE_LUN, unit neworder = SORT(names(0:goodindex-1)) names = names(neworder) descriptions = descriptions(neworder) dimensions = dimensions(*, neworder) IF (NOT(KEYWORD_SET(title))) THEN $ title = "Please Select an Image" loadbase = WIDGET_BASE(TITLE=title, /COLUMN, TLB_FRAME_ATTR=1, $ YOFFSET=40, XOFFSET=20) ; XPAD = 50, YPAD = 50, SPACE = 20, /MODAL, ) ; loadbox = WIDGET_BASE(loadbase, /COLUMN, FRAME=0, SPACE=10) loadlist = WIDGET_LIST(loadbase, VALUE=descriptions, $ UVALUE="FILELST", YSIZE=10) buttonbase = WIDGET_BASE(loadbase, /ROW) loadok = WIDGET_BUTTON(buttonbase, VALUE=" OK ", UVALUE="OK") loadcancel = WIDGET_BUTTON(buttonbase, VALUE="Cancel", $ UVALUE="CANCEL") WIDGET_CONTROL, loadbase, /REALIZE selection = 0 WIDGET_CONTROL, loadlist, SET_LIST_SELECT=selection Xmanager, "GetImage", loadbase, GROUP_LEADER=GROUP, /MODAL, $ EVENT_HANDLER="GetImageEventHdlr" IF (selection NE 0) THEN BEGIN IF ((NOT(KEYWORD_SET(three_dim))) AND $ (dimensions(2, selection-1) NE 1)) THEN $ dimensions(2, selection-1) = 1 OPENR, unit, datapath + names(selection - 1), /GET_LUN, /BLOCK ofilename = names(selection - 1) IF KEYWORD_SET(assoc_it) THEN $ newdata = ASSOC(unit, BYTARR(dimensions(0, selection-1), $ dimensions(1, selection-1))) $ ELSE BEGIN newdata = BYTARR(dimensions(0, selection - 1), $ dimensions(1, selection - 1), $ dimensions(2, selection - 1)) READU, unit, newdata FREE_LUN, unit ENDELSE description = descriptions(selection - 1) dimensions = dimensions(*,selection - 1) ENDIF ENDIF ENDIF END ;------------- end of procedure GetImage --------------