; $Id: oodisplayecho__define.pro,v 1.173 2008/03/22 00:32:33 kneller Exp $
;###############################################################################
;
;CLASS NAME:
;    pro ooDisplayEcho__define,class
;
;PURPOSE:
;               To manipulate and visualize a neutron spin echo data object (ooEcho).
;CATEGORY:
;               Data Visualization, Analysis and Manipulation.
;SUPERCLASSES:
;               myProperties
;
;METHODS:
;    ooDisplayEcho::draw
;    ooDisplayEcho::imageVirtual
;    ooDisplayEcho::imageEbVirtual
;    ooDisplayEcho::demarkQs
;    ooDisplayEcho::xout
;    ooDisplayEcho::imageSubtitle
;    ooDisplayEcho::imagetitle
;    oodisplayecho::checkforAllInfinities
;    ooDisplayEcho::plotVirtual
;    ooDisplayEcho::printWindow
;    ooDisplayEcho::setDisplayImage
;    ooDisplayEcho::updateFitvals
;    ooDisplayEcho::realify
;    ooDisplayEcho::updateIndices
;    ooDisplayEcho::keyboardUpdateIndices
;    ooDisplayEcho::keyboardEvents
;    ooDisplayEcho::mouseGuts
;    ooDisplayEcho::mouseHead
;    ooDisplayEcho::mouseEvents
;    ooDisplayEcho::boxPixel
;    ooDisplayEcho::getPositionOnImage
;    ooDisplayEcho::getPositionOnPlot
;    ooDisplayEcho::getFixed
;    ooDisplayEcho::fitButtonHandler
;    ooDisplayEcho::shiftFit
;    ooDisplayEcho::updateMaskmaker
;    ooDisplayEcho::maskEvents
;    ooDisplayEcho::makeMaskmaker
;    ooDisplayEcho::maskCleanup
;    maskBaseCleanup
;    ooDisplayEcho::maskButtonHandler
;    ooDisplayEcho::buttonEvents
;    ooDisplayEcho::CDButtonHandler
;    ooDisplayEcho::sliderEvents
;    ooDisplayEcho::drawEvents
;    ooDisplayEcho::proximityEvents
;    ooDisplayEcho::setPixelIndices
;    ooDisplayEcho::importPhases
;    ooDisplayEcho::importExportButtonHandler
;    ooDisplayEcho::listEvents
;    ooDisplayEcho::displayIQTEvents
;    displayIQTBaseCleanup
;    ooDisplayEcho::displayIQT
;    ooDisplayEcho::setBeamCenter
;    ooDisplayEcho::restoreSession
;    ooDisplayEcho::saveSession
;    ooDisplayEcho::menuEvents
;    ooDisplayEcho::resizeAuxWindow
;    ooDisplayEcho::raiseAuxWindow
;    ooDisplayEcho::lowerAuxWindow
;    ooDisplayEcho::droplistEvents
;    ooDisplayEcho::handleFixDroplist
;    ooDisplayEcho::updateFitparmWidget
;    ooDisplayEcho::handleBinning
;    ooDisplayEcho::add
;    ooDisplayEcho::textEvents
;    ooDisplayEcho::handleFitparmTextWidgetEvents
;    ooDisplayEcho::getParmsFromTextWidgets
;    ooDisplayEcho::treeEvents
;    ooDisplayEcho::do_nothing
;    ooDisplayEcho::contextMenuEvents
;    ooDisplayEcho::remove
;    ooDisplayEcho::contextEvents
;    ooDisplayEcho::createTContext
;    ooDisplayEcho::createRemoveTList
;    ooDisplayEcho::swapDataObject
;    ooDisplayEcho::resetDataParameters
;    ooDisplayEcho::atlbEvents
;    ooDisplayEcho::doNothing
;    doNothing
;    ooDisplayEcho_event
;    ooDisplayEcho::setDataParameters
;    ooDisplayEcho::reDefineWidgets
;    ooDisplayEcho::resizeWidgets
;    ooDisplayEcho::defineWidgets
;    ooDisplayEcho::setSelectDialog
;    setSelectBaseCleanup
;    ooDisplayEcho::removeSetDialog
;    removeSetBaseCleanup
;    ooDisplayEcho::setNameEvents
;    ooDisplayEcho::setNameDialog
;    setNameBaseCleanup
;    ooDisplayEcho::CalculateIQTDialog
;    ooDisplayEcho::IQTImportEvents
;    CalculateIQTBaseCleanup
;    ooDisplayEcho::mergeEvents
;    ooDisplayEcho::MergeDialog
;    MergeBaseCleanup
;    ooDisplayEcho::definePhaseImportDialog
;    PhaseImportBaseCleanup
;    ooDisplayEcho::defineImageErrorBase
;    ooDisplayEcho::resizeImageErrorBase
;    ooDisplayEcho::ImageErrorBaseCleanup;
;    ImageErrorBaseCleanup
;    ooDisplayEcho::defineDrawWidgets
;    ooDisplayEcho::defineMenus
;    ooDisplayEcho::defineTextWidgets
;    ooDisplayEcho::dropTimes
;    ooDisplayEcho::dropTimeEvents
;    ooDisplayEcho::defineCDControls
;    ooDisplayEcho::defineMaskButton
;    ooDisplayEcho::defineFitWidgets
;    ooDisplayEcho::icon
;    ooDisplayEcho::createFTWLeaf
;    ooDisplayEcho::fillSet
;    ooDisplayEcho::redefineTree
;    ooDisplayEcho::defineContextMenus
;    ooDisplayEcho::defineTree
;    ooDisplayEcho::sortDataByQ
;    ooDisplayEcho::getContainer
;    ooDisplayEcho::get_notify_ids
;    ooDisplayEcho::lastChanceToSaveSession
;    ooDisplayEchoCleanup
;    ooDisplayEcho::cleanup
;    get_font_name
;    ooDisplayEcho::readparametersfile
;    ooDisplayEcho::writeparametersfile
;    ooDisplayEcho::init
;    ooDisplayEcho__define
;
;
; AUTHOR:
; Larry Kneller
; NIST Center for Neutron Research
; 100 Bureau Drive, Gaithersburg, MD 20899
; United States
; kneller@nist.gov  301-975-8839
; Jan 24,2005
;
; LICENSE:
; The software in this file is written by an employee of
; National Institute of Standards and Technology
; as part of the DAVE software project.
;
; The DAVE software package is not subject to copyright protection
; and is in the public domain. It should be considered as an
; experimental neutron scattering data reduction, visualization, and
; analysis system. As such, the authors assume no responsibility
; whatsoever for its use, and make no guarantees, expressed or
; implied, about its quality, reliability, or any other
; characteristic. The use of certain trade names or commercial
; products does not imply any endorsement of a particular product,
; nor does it imply that the named product is necessarily the best
; product for the stated purpose. We would appreciate acknowledgment
; if the DAVE software is used of if the code in this file is
; included in another product.
;
;###############################################################################


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;
;       Title:          ooDisplayEcho.pro
;
;       Author:         Larry Kneller
;
;       Description:    This object widget is used to interact with
;                       neutron spin echo (NSE) data sets.
;
;       Last Update:    Ongoing!!!!
;
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::draw,xindex=xindex, yindex=yindex, tauindex=tauindex, $
                    textfitparms = textfitparms,$;Av = Av, Amp = Amp, PHASE = PHASE, W = W, PERIOD = PERIOD, PHO = PHO,$
                    no_update = no_update,plotxrange=plotxrange, plotyrange=plotyrange,$
                    plotzoombox = plotzoombox,writeplotdataflag=writeplotdataflag,writeplotdatafile=writeplotdatafile,$
                    tavestate=tavestate,$
                    _Extra=extra
;
;NAME:
;           ooDisplayEcho::draw
;
;PURPOSE:
;           draw method --- updates image and plot.
;PARAMETERS:
;           none
;KEYWORDS:
;           xindex[in]      x-coordinate index of selected pixel
;           yindex[in]      y-coordinate index of selected pixel
;           tauindex[in]    Fourier time index
;           Av              Fit parameters to use ifor plotting
;           Amp             in place of those available in fitparms.
;           PHASE
;           W
;           PERIOD
;           PHO
;           plotzoombox     Flag to draw a zoombox in the plot
;           textfitparms
;           no_update
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;;
    ;DRAW IMAGE AND PLOT AND ASSIGN POINTERS TO CORRECT AXES
    ;;;
    if n_elements(tavestate) eq 0 then widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= tavestate

    if n_elements(plotxrange) ne 2 then plotxrange = 0
    if n_elements(plotyrange) ne 2 then plotyrange = 0
    if n_elements(plotzoombox) eq 0 then plotzoombox = 0

    if n_elements(writeplotdatafile) eq 0 then writeplotdatafile = '' ;else print,'ooDisplayEcho::draw: '+writeplotdatafile
    if n_elements(writeplotdataflag) eq 0 then writeplotdataflag = 0
    if writeplotdataflag eq 1 then begin
        if writeplotdatafile eq '' then writeplotdataflag = 0
    endif


    ;NEED TO HANDLE CASE WHERE self.xindex IS ALREADY VALID
    device,get_decomposed = dc

    if (n_elements(xindex) eq 0) then begin
        if self.xindex lt self.detxdim then begin
            xindex = self.xindex
        endif else begin
            xindex = self.detxdim/2
        endelse
    endif

    if (n_elements(yindex) eq 0) then begin
        if self.yindex lt self.detydim then begin
            yindex = self.yindex
        endif else begin
            yindex = self.detydim/2
        endelse
    endif
    if n_elements(tauindex)  eq 0 then tauindex = self.ftChoiceIndex
    if n_elements(no_update) eq 0 then no_update = 0

    self.ftChoiceIndex = tauindex



    ;IMAGE AND FIT PARAMETER ITEMS
    if self.plotzoombox eq 0 then begin

            ;RESET IMAGE TO BE DISPLAYED
            self->setDisplayImage

        ;WHY ISN'T THE NEXT STEP AVAILABLE IN SETDISPLAYIMAGE, MAYBE AS A
        ;RETURN VALUE FOR A FUNCTION????

            ;UPDATE tauindex TO REFLECT POTENTIAL VALUE CHANGES IN setDisplayImage
            tauindex = self.ftChoiceIndex

            ;BOX CURRENTLY SELECTED PIXEL
            self->boxPixel,xindex,yindex
            ;self.mouseMotionBlock = 0

            ;COPY VIRTUAL IMAGE FROM VIRTUAL WINDOW TO REAL WINDOW
            self->realify,self.dw1pix,self.dw1id

            if self.errorImageChoice eq 1 then begin
                self->imageEbVirtual
                self->realify,self.dwebpix,self.dwebid
            endif

            if no_update ne 1 then begin
                ;UPDATES WHEN PIXEL CHOICE CHANGES.
                self->updateFitvals,self.xindex,self.yindex,self.ftChoiceIndex,tavestate=tavestate
            endif

    endif;plotzoom


    ;PLOT ITEMS
    ;DRAW PLOT TO ITS PIXMAP
    self->plotVirtual,xindex,yindex,tauindex, textfitparms = textfitparms,$
                        plotxrange = plotxrange, plotyrange=plotyrange,$
                        plotzoombox = plotzoombox,writeplotdataflag=writeplotdataflag,$
                        writeplotdatafile=writeplotdatafile,tavestate=tavestate ;$
             ;Av = Av, Amp = Amp, PHASE = PHASE, W = W, PERIOD = PERIOD, PHO = PHO


    ;COPY VIRTUAL PLOT FROM PIXMAP WINDOW TO REAL WINDOW
    self->realify,self.dw2pix,self.dw2id

    if widget_info(self.dw2auxbase,/valid_id) gt 0 then begin
        self->realify,self.dw2auxpix,self.dw2auxid
    endif


device,decomposed = dc

end;draw
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::imageVirtual
;
;NAME:
;           ooDisplayEcho::imageVirtual
;
;PURPOSE:
;           Create the virtual detector image with titles
;           in the pixmap for copy to the display window.
;PARAMETERS:
;           none.
;KEYWORDS:
;           none.


    wset,self.dw1pix


;    plotImage,bytscl(*self.im,min=0.0)
;    plotImage,bytscl(alog(bytscl(*self.im,min=0.0,max = max(*self.im))+1.0))

    ;plotImage,bytscl(bytscl(*self.im,min=min(*self.im),max = max(*self.im)))

device,get_decomposed = dc
device,decomposed=0
    tvlct,r,g,b,/get
    loadct,self.colortable,/silent


    if self.dataContainer->count() gt 0 then begin
        ft = (*((self.dataContainer->get(position=$
                    self.QChoiceIndex))->getProperty(tag=$
                        'fourierTime')))[self.ftChoiceIndex]
    endif else begin
        ft = 0.0
    endelse




    imsize = size(*self.im)
    imrange = [min(*self.im),max(*self.im)]
    if imrange[0] eq imrange[1] then imrange[1] = imrange[1]+1.0
    bottomcolor = 0;50
;    plotImage,bytscl(*self.im,min=min(*self.im),max = max(*self.im)),$
;                title = self->imageSubtitle(),$
;                subtitle = self->imagetitle(),$
;                yrange=[imsize[1],0];,$
;                ;position = [0.2, 0.2, 0.9, 0.9]

    impos = [0.24,0.20,0.9,0.9]
    cbpos = [0.20,0.13,0.9,0.16]

;040505
;WILL THE NEXT COLORS WORK WITH decomposed = 0???
;
;PLOT IMAGE SEEMS TO REQUIRE A BLACK BACKGROUND.  HOW CAN I CHANGE THIS?
tvlct,rnow,gnow,bnow,/get

;042205
;
;EXPERIMENTING WITH SETTING BACKGROUND WHITE, FOREGROUND BLACK
rnownew = rnow
gnownew = gnow
bnownew = bnow

rnownew[0] = 255L
gnownew[0] = 255L
bnownew[0] = 255L

;SET THE MAXIMUM COLOR TO BLACK
rnownew[255] = 0L
gnownew[255] = 0L
bnownew[255] = 0L

tvlct,rnownew,gnownew,bnownew

;CHANGE XOUT COLOR TO WHITE AND WE'RE ALL SET IGOR STYLE.


    black = 0L
    white = 255L + 256L*(255L + 256L*255L)

;042205
;BYTSCL TO AVOID THE MAXIMIMUM AND MINIMUM COLORS,
;SO BLACK IS AT THE BOTTOM OF DATA RANGE AND WHITE IS AT TOP OF DATA RANGE (1-254)
;WHILE WHITE IS AT THE ZEROTH COLOR AND BLACK IS AT THE TOP FOR CONVENIENCE
;OF THE GRAPH.
theim = bytscl(*self.im,top=253)+1B
;    plotImage,*self.im,range=imrange,$;bottom=black,$;bottomcolor,$
;                title = self->imageSubtitle(),$
;                subtitle = self->imagetitle(),$
;                yrange=[imsize[1],0],charsize=1.0,$;1.25,$
;                position = impos

    plotImage,theim,range=imrange,$;bottom=black,$;bottomcolor,$
                title = self->imageSubtitle(),$
                subtitle = self->imagetitle(),$
                yrange=[imsize[1],0],charsize=1.0,$;1.25,$
                $;background = 255L, color = 0L,$
                position = impos

;042505
;THE COLORS MUST BE RESET HERE SO THAT THE TOP OF THE COLOR BAR IS WHITE
;AND THE BOTTOM IS BLACK.  USE THE BACKGROUND AND COLOR KEYWORDS TO
;SET THE BACKGROUND TO WHITE AND THE AXES TO BLACK

;RESET THE COLORS
tvlct,rnow,gnow,bnow

    case self.displayIndex of
    3: format = '(f10.4)'
    8: format = '(f10.2)'
    else:format = '(I7)'
    endcase

;print,imrange

;090705
;THE NEXT LINES ARE NECESSARY TO PROTECT FROM CRASHES IN COLORBAR
;WHEN THERE ARE infinities IN THE DATA.

;010905
;WHY ARE string values assigned to imrange?
;    if imrange[1] eq double('Infinity') then imrange[1] = 10000000.0;'10000000.0'
;    if imrange[0] eq double('Infinity') then imrange[0] = 0.0;'0.0'
;    if imrange[0] eq -1.0*double('Infinity') then imrange[0] = -10000000.0;'-10000000.0'

    if finite(imrange[1]) eq 0 then imrange[1] = 10000000.0
    if finite(imrange[0]) eq 0 then imrange[0] = -10000000.0

    colorbar,range=imrange,$;bottom=bottomcolor,$
             /vertical,format=format,charsize=0.75,$
             background = 255L, color = 0L,$
             position = cbpos


;RESET THE COLORS BEFORE CALLING ANOTHER METHOD.
tvlct,rnow,gnow,bnow

    self->xout,self.ftChoiceIndex
    self->demarkQs


    ;RELEASE AXIS POINTERS FOR WINDOW
    ptr_free,self.w1xptr
    ptr_free,self.w1yptr

    ;RESET AXIS POINTERS FOR drawImage
    self.w1xptr = ptr_new(!x)           ;MUST SET THESE HERE TO ASSIGN
    self.w1yptr = ptr_new(!y)           ;POINTERS TO PROPER AXES!!!

    tvlct,r,g,b
device,decomposed = dc
end;imageVirtual
pro ooDisplayEcho::imageEbVirtual
;
;NAME:
;        ooDisplayEcho::imageEbVirtual
;
;PURPOSE:
;           Produce pixmap of error bar image with titles to copy to real window.
;PARAMETERS:
;           none
;KEYWORDS:
;           none

device,get_decomposed = dc
device,decomposed=0
    tvlct,r,g,b,/get
    loadct,self.colortable,/silent
    wset,self.dwebpix

    ;NEED TO CONSIDER A BETTER SCALE FOR THE
    ;ERROR BAR IMAGE SO IT IS ALWAYS VISIBLE.

    ft = (*((self.dataContainer->get(position=$
                self.QChoiceIndex))->getProperty(tag=$
                    'fourierTime')))[self.ftChoiceIndex]

    imebsize = size(*self.imeb)


    ;0300805
    ;
    ;CONVERT IMAGE ERROR BARS TO RELATIVE IMAGE ERROR BARS (i.e. self.imeb/self.im)
    ;---- ACTUALLY, HOLD OFF ON THIS SINCE THE IMAGE COULD EASILY BE ALL ZEROS,
    ;     WHICH WILL CRASH COLORBAR.  THIS NEEDS TO BE DONE WITH THOUGHT.
    ;


    imebrange = [min(*self.imeb),max(*self.imeb)]
    if imebrange[0] eq imebrange[1] then imebrange[1] = imebrange[1]+1
    bottomcolor = 0;50



;    imeb = *self.imeb/*self.im
;    imebrange = [min(imeb),max(imeb)]
;    if imebrange[0] eq imebrange[1] then imebrange[1] = imebrange[1]+0.0001
;    bottomcolor = 0;50


;040505
;WILL THE NEXT COLORS WORK WITH decomposed = 0???
;
;PLOT IMAGE SEEMS TO REQUIRE A BLACK BACKGROUND.  HOW CAN I CHANGE THIS?
tvlct,rnow,gnow,bnow,/get

;042205
;
;EXPERIMENTING WITH SETTING BACKGROUND WHITE, FOREGROUND BLACK
rnownew = rnow
gnownew = gnow
bnownew = bnow

rnownew[0] = 255L
gnownew[0] = 255L
bnownew[0] = 255L

;SET THE MAXIMUM COLOR TO BLACK
rnownew[255] = 0L
gnownew[255] = 0L
bnownew[255] = 0L

tvlct,rnownew,gnownew,bnownew

;CHANGE XOUT COLOR TO WHITE AND WE'RE ALL SET IGOR STYLE.

;BYTSCL TO AVOID THE MAXIMIMUM AND MINIMUM COLORS,
;SO BLACK IS AT THE BOTTOM OF DATA RANGE AND WHITE IS AT TOP OF DATA RANGE (1-254)
;WHILE WHITE IS AT THE ZEROTH COLOR AND BLACK IS AT THE TOP FOR CONVENIENCE
;OF THE GRAPH.
theim = bytscl(*self.imeb,top=253)+1B


    impos = [0.24,0.20,0.9,0.9]
    cbpos = [0.20,0.13,0.9,0.16]
    plotImage,theim,range=imebrange,$;bottom=bottomcolor,$
                title = self->imageSubtitle()+' Error Bars',$
                subtitle = self->imagetitle(),$
                yrange=[imebsize[1],0],$
                position = impos
;    plotImage,imeb,range=imebrange,bottom=bottomcolor,$
;                title = self->imageSubtitle()+' Error Bars',$
;                subtitle = self->imagetitle(),$
;                yrange=[imebsize[1],0],$
;                position = impos



    if finite(imebrange[1]) eq 0 then imebrange[1] = 10000000.0
    if finite(imebrange[0]) eq 0 then imebrange[0] = -10000000.0




    case self.displayIndex of
    3: format = '(f10.4)'
    8: format = '(f10.2)'
    else:format = '(I7)'
    endcase





    colorbar,range=imebrange,$;bottom=bottomcolor,$
             /vertical,format=format,charsize=0.75,$
             position = cbpos
;    colorbar,range=imebrange,bottom=bottomcolor,$
;             /vertical,format='(f7.4)',charsize=0.75,$
;             position = cbpos

    ;print,*self.imeb

;    plotImage,bytscl(*self.imeb,min=min(*self.imeb),max = max(*self.imeb)),$
;                title=self->imageSubtitle()+' Error Bars',$
;                subtitle = self->imagetitle(),$
;                yrange=[imebsize[1],0];,$
;
;    if (min(*self.imeb) eq max(*self.imeb)) then begin
;        minrange = min(*self.imeb)
;        maxrange = min(*self.imeb) + 1
;    endif else begin
;        minrange = min(*self.imeb)
;        maxrange = max(*self.imeb)
;    endelse
;
;    colorbar,range=[minrange,maxrange],$
;             /vertical,format = '(I7)',$
;            position = [0.2, 0.1, 0.9, 0.13]

;042205
;RESET THE COLORS
tvlct,rnow,gnow,bnow


    self->xout,self.ftChoiceIndex


    ;RELEASE AXIS POINTERS FOR WINDOW
    ptr_free,self.webxptr
    ptr_free,self.webyptr

    ;RESET AXIS POINTERS FOR Image
    self.webxptr = ptr_new(!x)           ;MUST SET THESE HERE TO ASSIGN
    self.webyptr = ptr_new(!y)           ;POINTERS TO PROPER AXES!!!

    tvlct,r,g,b
device,decomposed = dc
end;imageEbVirtual
pro ooDisplayEcho::demarkQs
;
;NAME:
;        ooDisplayEcho::demarkQs
;
;PURPOSE:
;           Show the regions of the image belonging to each Q-range.
;           Useful for seeing which pixels contribute at each Q.
;PARAMETERS:
;           none
;KEYWORDS:
;           none

    ;PLACE LINES ON IMAGE TO DENOTE REGIONS OF
    ;CONSTANT Q.
    ;PERHAPS THIS CAN BE TURNED ON/OFF WITH A BUTTON
device,get_decomposed = dc
device,decomposed=0
    tvlct,r,g,b,/get
;;;;;
    loadct,3,/silent


    if self.dataContainer->count() gt 0 then begin
        ref = (self.datacontainer)->get(position=self.QChoiceIndex)

    ;110404
    ;THE NEXT LINE NEEDS TO CREATE A MATRIX THAT INDICATES
    ;THE CONSTANT-Q ARCS ON THE BASED ON THE NUMBER OF ARCS FOR
    ;I(Q,t) _NOT_ BASED ON THE ARCFIT MATRIX!!!!
        ;ref->calculateIndexMatrix,mat=mat
        ref->calculateArcsQMatrix,arcmat=mat

    endif else begin
        mat = indgen(self.detxdim*self.detydim)/self.detxdim


    endelse

    ;NOW LOOP THROUGH AND FIND BOUNDARIES FOR THE Q REGIONS
    ;
    ;FOR EACH PIXEL, LOOK AT NEIGHBORING PIXELS AND DRAW A LINE
    ;IN BETWEEN IF THEY ARE NOT THE SAME.

    ;print,'mat=',mat

    mat = reform(mat,self.detxdim,self.detydim)

    ;print,'mat=',mat

    n_colors = max(mat) ;SET THIS NUMBER OF COLORS TO DELIMIT
                        ;THE REGIONS OF CONSTANT Q

device,decomposed=1

;    qcolor = -10
;    qcolor = 0
    thick = 2.0
    qcolor = 256L*256L*255L ;BLUE
    for i=0,self.detxdim-1 do begin
        for j=0,self.detydim-1 do begin

            if (i lt self.detxdim-1) then begin; and (i gt 0) then begin
                if (mat[i+1,j] ne mat[i,j]) then begin
                    ;thecolor = qcolor - mat[i+1,j]*10
                    thecolor = qcolor;0
                    plots,[i+1,i+1],$
                          [j,j+1],$
                          color = thecolor,$
                          thick = thick
                endif
            endif

;            if (i gt 0) then begin
;                if (mat[i-1,j] ne mat[i,j]) then begin
;                    ;thecolor = qcolor - mat[i-1,j]*10
;                    thecolor = 0
;                    plots,[i-1,i-1],$
;                            [j,j+1],$
;                            color = thecolor,$
;                            thick = 1.0
;                endif
;            endif
            if (j lt self.detydim-1) then begin;and (j gt 0) then begin
                if (mat[i,j+1] ne mat[i,j]) then begin
                    ;thecolor = qcolor - mat[i,j+1]*10
                    ;thecolor = 0
                    plots,[i,i+1],$
                          [j+1,j+1],$
                          color = thecolor,$
                          thick = thick
                endif
            endif

;            if (j gt 0) then begin
;                if (mat[i,j-1] ne mat[i,j]) then begin
;                    ;thecolor = qcolor - mat[i,j-1]*10
;                    thecolor=0
;                    plots,[i,i+1],$
;                          [j,j],$
;                          color = thecolor,$
;                          thick = 1.0
;                endif
;            endif

        endfor;j
    endfor;i
device,decomposed=0

    tvlct,r,g,b
device,decomposed = dc

end;demarkQs

pro ooDisplayEcho::xout,k
;
;NAME:
;        ooDisplayEcho::xout
;
;PURPOSE:
;           Cover over masked pixels with a specified color.
;PARAMETERS:
;           k   The selected Fourier tiem index.
;KEYWORDS:
;           none

    ;PUT X's OVER ALL MASKED PIXELS ON THE CURRENT IMAGE

;;;;;    ;GET THE CURRENT r,g,b VALUES TO
;;;;;    ;PROTECT THE COLOR TABLE OUTSIDE
;;;;;    ;OF THIS METHOD
;;;;;

device,get_decomposed = dc
device,decomposed=1
    tvlct,r,g,b,/get

;print,'ooDisplayEcho::xout r = ',r
;print,'ooDisplayEcho::xout g = ',g
;print,'ooDisplayEcho::xout b = ',b
;;;;;

;    rnew = 0*r
;    gnew = r
;    bnew = 0*r
;    tvlct,rnew,gnew,bnew

;;;;;
;;;;;    ;ASSIGN THE COLOR SPECIFIED BY THE 3 INDICES TO
;;;;;    ;THE VALUE IN THE 4th INDEX.
;;;;;    ;
;;;;;    ;WHEN THE RED TEMPERATURE COLOR TABLE IS SELECTED,
;;;;;    ;ALL COLORS ARE MAPPED ONTO THE 0-255 COLOR RANGE.
;;;;;
;;;;;    tvlct,255,0,0,0
;;;;;
;;;;;

    ;LOOP THROUGH THE MASK AND X OUT ALL OF THE
    ;MASKED PIXELS.
    ;
    ;
    ;FOR THE SELECTED PIXEL, PUT AN X OVER IT
    ;UNTIL FIGURING OUT HOW TO PUT UP A BOX.

    if self.dataContainer->count() gt 0 then begin
        ref = self.dataContainer->get(position=self.QChoiceIndex)
        tempmask = *(ref->getProperty(tag='mask2d'))
    endif else begin
        tempmask = intarr(self.detxdim*self.detydim)
    endelse

    ;mask = (*pmask)[*,k]

    case self.detydim of
    32:begin
        thick = 6.0
    end
    16:begin
        thick = 6.0
    end
    8:begin
        thick = 10.0
    end
    4:begin
        thick = 12.0
    end
    2:begin
        thick = 14.0
    end
    endcase

    ;xcolor = 1000;200;-100   ;bluish white

device,decomposed=1
    cR = 0L & cG = 150L & cB = 0L
;040205
;CHANGED THE USER MASK COLOR TO A DARKER GREEN SO IT IS VISALLY
;MORE DISTINCT FROM THE DATA.
    cG2 = 200L & cB2 = 200L
    xcolor = cR + 256L * (cG + 256L * cB)
    xcolor2 = cR + 256L * (cG2 + 256L * cB)

;    ;042205
;    ;CHANGING XCOLORS TO WORK WITH WHITE BACKGROUNDS.
;    white = 255L + 256L*(255L + 256L*255L)
;    offwhite = 200L + 256L*(200L + 256L*200L)
;    xcolor = white
;    xcolor2 = offwhite
    for i=0,self.detxdim-1 do begin
        for j=0,self.detydim-1 do begin
            ;X OVER IF MASKED
            if (tempmask)[j*self.detxdim+i,k] eq 0 then begin
                xpix = i
                ypix = j

                x_xout = [xpix,xpix+1,xpix+1,xpix,xpix]
                y_xout = [ypix,ypix,ypix+1,ypix+1,ypix]
                polyfill,x_xout,y_xout,color=xcolor,/data,linestyle=0

                ;OUTLINE THE PIXEL
                plots,[xpix,xpix+1],  [ypix,ypix],    color = 0L,thick = 0.5
                plots,[xpix+1,xpix+1],[ypix,ypix+1],  color = 0L,thick = 0.5
                plots,[xpix+1,xpix],  [ypix+1,ypix+1],color = 0L,thick = 0.5
                plots,[xpix,xpix],    [ypix+1,ypix],  color = 0L,thick = 0.5

;                plots,[xpix,xpix+1],[ypix,ypix+1],color = xcolor,thick = 2.0
;                plots,[xpix,xpix+1],[ypix+1,ypix],color = xcolor,thick = 2.0
;
;                plots,[xpix+.1,xpix+.9],[ypix+.2,ypix+.2],color = xcolor,thick = thick
;                plots,[xpix+.1,xpix+.9],[ypix+.4,ypix+.4],color = xcolor,thick = thick
;                plots,[xpix+.1,xpix+.9],[ypix+.6,ypix+.6],color = xcolor,thick = thick
;                plots,[xpix+.1,xpix+.9],[ypix+.8,ypix+.8],color = xcolor,thick = thick
;
;                plots,[xpix+.2,xpix+.2],[ypix+.1,ypix+.9],color = xcolor,thick = thick
;                plots,[xpix+.4,xpix+.4],[ypix+.1,ypix+.9],color = xcolor,thick = thick
;                plots,[xpix+.6,xpix+.6],[ypix+.1,ypix+.9],color = xcolor,thick = thick
;                plots,[xpix+.8,xpix+.8],[ypix+.1,ypix+.9],color = xcolor,thick = thick
;
            endif
            if (tempmask)[j*self.detxdim+i,k] eq -1 then begin
                xpix = i
                ypix = j

                x_xout = [xpix,xpix+1,xpix+1,xpix,xpix]
                y_xout = [ypix,ypix,ypix+1,ypix+1,ypix]
                polyfill,x_xout,y_xout,color=xcolor2

                ;OUTLINE THE PIXEL
                plots,[xpix,xpix+1],  [ypix,ypix],    color = 0L,thick = 0.5
                plots,[xpix+1,xpix+1],[ypix,ypix+1],  color = 0L,thick = 0.5
                plots,[xpix+1,xpix],  [ypix+1,ypix+1],color = 0L,thick = 0.5
                plots,[xpix,xpix],    [ypix+1,ypix],  color = 0L,thick = 0.5


;
;                plots,[xpix,xpix+1],[ypix,ypix+1],color = xcolor2,thick = 2.0
;                plots,[xpix,xpix+1],[ypix+1,ypix],color = xcolor2,thick = 2.0
;
;                plots,[xpix+.1,xpix+.9],[ypix+.2,ypix+.2],color = xcolor2,thick = thick
;                plots,[xpix+.1,xpix+.9],[ypix+.4,ypix+.4],color = xcolor2,thick = thick
;                plots,[xpix+.1,xpix+.9],[ypix+.6,ypix+.6],color = xcolor2,thick = thick
;                plots,[xpix+.1,xpix+.9],[ypix+.8,ypix+.8],color = xcolor2,thick = thick
;
;                plots,[xpix+.2,xpix+.2],[ypix+.1,ypix+.9],color = xcolor2,thick = thick
;                plots,[xpix+.4,xpix+.4],[ypix+.1,ypix+.9],color = xcolor2,thick = thick
;                plots,[xpix+.6,xpix+.6],[ypix+.1,ypix+.9],color = xcolor2,thick = thick
;                plots,[xpix+.8,xpix+.8],[ypix+.1,ypix+.9],color = xcolor2,thick = thick

            endif
        endfor;j
    endfor;i



;;;;;    ;RESTORE THE COLOR TABLE TO ITS
;;;;;    ;SETTINGS BEFORE ENTERING THIS
;;;;;    ;APPLICATION.
device,decomposed=0
    tvlct,r,g,b
;;;;;
device,decomposed = dc

end;xout


function ooDisplayEcho::imageSubtitle
;
;NAME:
;        ooDisplayEcho::imageSubtitle
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

;RETURN VALUE:
;


    if self.dataContainer->count() gt 0 then begin
        ref = self.dataContainer->get(position=self.QChoiceIndex)
        ft = (*(ref->getProperty(tag=$
                        'fourierTime')))[self.ftChoiceIndex]

        if ref->getproperty(tag='QValsSwitch') ne 1 then begin
            ;ADD Q VALUE OF THE CURRENT ARC.
;            qarcs = *(ref->getProperty(tag='qarcs'))
;            print,qarcs
;            narcs=ref->getProperty(tag='narcs')
;            print,narcs
;
;            ref->calculateArcsQMatrix,narcs=narcs,arcmat=arcmat
;            help,arcmat
;            arcmat = reform(arcmat,self.detXdim,self.detYdim)
;            help,arcmat
;            q = qarcs[arcmat[self.xindex,self.yindex]]

;            help,(*(ref->getproperty(tag='QVals')))
            qvals = (*(ref->getproperty(tag='QVals')))[*,0]
;            help,qvals
            format = '(f6.4)'


;;;;;
;            print,'June 17, 2005'
;            refxdim = ref->getproperty(tag='x_dim')
;            refydim = ref->getproperty(tag='y_dim')
;            if refxdim ne self.detxdim then begin
;                qvals = reform(qvals,refxdim,refydim)
;            endif else begin
;;;;;
                qvals = reform(qvals,self.detxdim,self.detydim)
;            endelse



            q = qvals[self.xindex,self.yindex]
            qstring = ', q[' $
                           +strtrim(string(self.xindex),2) $
                           +',' $
                           +strtrim(string(self.yindex),2)+'] =' $
                           +strtrim(string(q,format=format),2)
                           ang = 'A';STRING("305B)
            qstring = qstring+ang+'!E-1!N'
        endif else begin
            qstring = ''
        endelse

    endif else begin
        ft = 0.0
        qstring=''
    endelse



    subtitle = file_basename(self.filename) $
                            +': t = ' $;+': fourier time = '$
                            +strtrim(string(10.0^9*ft),2)+'ns' $
                            +qstring
    return,subtitle
end;imageSubtitle
function ooDisplayEcho::imagetitle
;
;NAME:
;        ooDisplayEcho::imagetitle
;
;PURPOSE:
;           Create a title for the image to be displayed.
;PARAMETERS:
;           none.
;KEYWORDS:
;           none

;RETURN VALUE:
;           The title string.

    case self.displayIndex of
        0:  begin
                title = 'Image = S(Q)'
            end
        1:  begin
                title = 'Image = Average Fit Values'
            end
        2:  begin
                title = 'Image = Amplitude Fit Values'
            end
        3:  begin
                title = 'Image = Phase Fit Values'
            end
        4:  begin
                title = 'Image = Gaussian Width Fit Values'
            end
        5:  begin
                title = 'Image = Period Fit Values';Omega Fit Values'
            end
        6:  begin
                title = 'Image = Phase Offset Fit Values'
            end
        7:  begin
                title = 'Image = Chi Squared Values'
            end
        8:  begin
                title = 'Image = Signal'
            end
        9:  begin
                title = 'Image = Magnetic'
            end
        10: begin
                title = 'Image = Spin Incoherent'
            end
        11: begin
                title = 'Image = Coherent and Isotope Incoherent'
            end
        12: begin
                title = 'Image = Sum of all contributions'
            end
        else: begin
                ;NO IMAGE SELECTED, SO JUST SHOW PHASE(0)
                title = 'Image = DEFAULT IMAGE TITLE'
            end
        endcase
    return,title
end;imageTitle


function oodisplayecho::checkforAllInfinities,y
;
;NAME:
;        ooDisplayEcho::checkforAllInfinities
;
;PURPOSE:
;       Protect plotting programs from case where all data
;       are infinite.  This is common with Signal plot.
;
;PARAMETERS:
;       y   The data to check
;KEYWORDS:
;           none.
;RETURNS:
;           The "fixed" data array.
;

        ;121905
        ;DO THE FOLLOWING TO AVOID CRASHING DUE TO ALL INFINITIES IN SIGNAL
        wh_inf = where(y eq double('Infinity'))
        wh_minf = where(y eq -double('Infinity'))
        n_inf = 0
        if wh_inf[0] ne -1 then n_inf = n_inf + n_elements(wh_inf)
        if wh_minf[0] ne -1 then n_minf = n_inf + n_elements(wh_minf)

        if n_inf eq n_elements(y) then y = dblarr(n_inf)

        return,y
end;checkforAllInfinities



pro ooDisplayEcho::plotVirtual,xindex,yindex,tauindex,textfitparms=textfitparms,$
                                plotxrange = plotxrange, plotyrange = plotyrange,$
                                plotzoombox = plotzoombox,writeplotdataflag=writeplotdataflag,$
                                writeplotdatafile=writeplotdatafile,tavestate=tavestate
             ;Av = Av, Amp = Amp, PHASE = PHASE, W = W, PERIOD = PERIOD, PHO = PHO

;
;NAME:
;        ooDisplayEcho::plotVirtual
;
;PURPOSE:
;           Produce the plot in a pixmap.  If there is a floating auxilliary plot window,
;           then produce a plot for that as well.
;           This procedure handles all the options for the plot.
;
;PARAMETERS:
;           xindex      The current pixel indices.
;           yindex
;           tauindex    The current Fourier time index.
;           Av          Fit parameters to use for plotting
;           Amp         in place of those available in fitparms.
;           PH
;           W
;           PERIOD
;           PHO
;KEYWORDS:
;           none.

;print,'ooDisplayEcho::plotvirtual'
;print,self.plotindex
;if n_elements(writeplotdataflag) gt 0 then print,writeplotdataflag

widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= timecheckboxval
widget_control,self.DEEPMASKINGCHECKBOX,get_value= DEEPMASKINGCHECKBOXval
if n_elements(tavestate) eq 0 then widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= tavestate


if n_elements(writeplotdatafile) eq 0 then writeplotdatafile = '' ;else print,'ooDisplayEcho::plotvirtual: '+writeplotdatafile

if n_elements(writeplotdataflag) eq 0 then writeplotdataflag = 0
if writeplotdataflag eq 1 then begin
    if writeplotdatafile eq '' then writeplotdataflag = 0
endif
if n_elements(plotxrange) ne 2 then plotxrange = 0
if n_elements(plotyrange) ne 2 then plotyrange = 0
if n_elements(plotzoombox) eq 0 then plotzoombox = 0

if self.plotzoomswitch eq 1 then begin
    plotxrange = [self.plotxmin,self.plotxmax]
    plotyrange = [self.plotymin,self.plotymax]
endif else begin
    plotxrange = 0
    plotyrange = 0
endelse





    ;GET INFORMATION FROM DATA OBJECT AND ADD ALL OF
    ;RELEVANT INFORMATION TO THE PLOT WINDOW.
device,get_decomposed = dc
;device,decomposed=0
;    tvlct,r,g,b,/get
;    loadct,self.colortable,/silent

device,decomposed=1
    if self.dataContainer->count() gt 0 then begin

        ref = (self.dataContainer->get(position=self.QChoiceIndex))

if obj_valid(ref) gt 0 then begin


        ;112805
        ;SET THE VALUE OF ref_magnetic TO TELL THE CASES BELOW TO SET IMAGE OPTIONS TO
        ;A GENERAL OPTION IF NECESSARY
        if obj_isa(ref,'ooEchoMagnetic') gt 0 then begin
            if ref->getproperty(tag='magnetic') eq 0 then begin
                ref_magnetic = 0
            endif else begin
                ref_magnetic = 1
            endelse
        endif else begin
            ref_magnetic = 0
        endelse
        if ref_magnetic eq 0 then begin
            if self.plotindex eq 9 then self.plotindex = 0
        endif






        ;GET THE EXTREMA FROM THE FLIPPER DOWN AND FLIPPER UP STATES
        theExtrema = ref->chirpExtremaMasked(xindex, $
                                              yindex, $
                                              tauindex,tavestate=tavestate)

        siup = (*(ref->getproperty(tag='sIup')))[xindex+yindex*self.detxdim,tauindex]
        sidown = (*(ref->getproperty(tag='sIdown')))[xindex+yindex*self.detxdim,tauindex]
;print,'symax=',sidown
;print,'symin=',siup


;print,'____________________________________________'
;print,'ooDisplayEcho::plotVirtual'

t0 = systime(1,/seconds)
        term = ref->term()
;print,'t1=',systime(1,/seconds)-t0

    ;091604
    ;
    ;GET FITPLOT SWITCH
        fitplotswitch = $
            (ref->getfitdisplaymask(tauindex))[xindex,yindex]
;print,'t2=',systime(1,/seconds)-t0


    ;ESTIMATE THE OFFSET FROM THE FLIPPER DOWN AND FLIPPER
    ;UP STATES  (NOT YET USED, BUT SHOULD BE USED FOR FITS IN
    ;            DATA OBJECT)
        theOffset = ref->chirpOffset(xindex,yindex,tauindex)
;print,'t2=',systime(1,/seconds)-t0

    ;ESTIMATE THE AMPLITUDE FROM THE FLIPPER DOWN AND FLIPPER
    ;UP STATES  (NOT YET USED, BUT SHOULD BE USED FOR FITS IN
    ;            DATA OBJECT)
        theAmplitude = ref->chirpAmplitude(xindex,yindex,tauindex)

;print,'t2=',systime(1,/seconds)-t0

    ;NEED BOTH FULL AND MASKED DATA SETS
        if self.plotupdown eq 0 then begin
            xarrOrig = ref->chirpPhases(tauindex)
            yarrOrig = ref->chirp(xindex,yindex,tauindex)
;            dbx = ref->dbx(tauindex)
;            dby = ref->dby(tauindex)
;            dbz = ref->dbz(tauindex)

            ;help,xarrOrig
            ;help,yarrOrig
        ;GET PHASE ARRAY AS X-VALUES FOR PLOT

    ;113005
;            xarr = ref->chirpPhases(tauindex)  ;WHY WAS THIS USED INSTEAD OF THE NEXT LINE?????
                                                ;IT DIDN'T MAKE SENSE.
            xarr = ref->chirpPhasesMasked(tauindex)
        ;GET THE ECHO FOR THE SELECTED PIXEL,FOURIER TIME
            yarr = ref->chirpMasked(xindex,yindex,tauindex)
            ;help,xarr
            ;help,yarr


        endif else begin
            xarrOrig = ref->chirpPhasesAll(tauindex)
;print,'________________________________'
;print,'ooDisplayEcho:: A',systime(1,/seconds)-t0
            yarrOrig = ref->chirpAll(xindex,yindex,tauindex)
;            dbx = ref->dbxAll(tauindex)
;            dby = ref->dbyAll(tauindex)
;            dbz = ref->dbzAll(tauindex)

;        ;GET PHASE ARRAY AS X-VALUES FOR PLOT
;        xarr = (self.dataContainer->get(position=$
;                    self.QChoiceIndex))->chirpPhasesMaskedAll(tauindex)
;        ;GET THE ECHO FOR THE SELECTED PIXEL,FOURIER TIME
;        yarr = (self.dataContainer->get(position=$
;                    self.QChoiceIndex))->chirpMaskedAll(xindex,yindex,tauindex)
        ;GET PHASE ARRAY AS X-VALUES FOR PLOT
            xarr = ref->chirpPhasesMaskedAll(tauindex)
        ;GET THE ECHO FOR THE SELECTED PIXEL,FOURIER TIME
            yarr = ref->chirpMaskedAll(xindex,yindex,tauindex)
;print,'t5=',systime(1,/seconds)-t0

        endelse

        ;042705
        ;SHOW ONLY ECHO RANGE OF B DATA, NOT THE Iup,down VALUES.
        dbx = ref->dbx(tauindex)
        dby = ref->dby(tauindex)
        dbz = ref->dbz(tauindex)
        xarrb = ref->chirpPhases(tauindex)
;print,'________________________________'
;print,'ooDisplayEcho:: B',systime(1,/seconds)-t0

;print,'t5a=',systime(1,/seconds)-t0


    ;CALCULATE THE ERROR ASSUMING POISSON STATISTICS
    ;(NOTE: CONGRID SEEMS TO AVERAGE THE DATA FOR REBINNING,
    ;       SO A NORMALIZATION FACTOR SHOULD BE IN ORDER
    ;       TO ACCOUNT FOR THE APPARENTLY DEGRADED STATISTICS.
    ;       THIS SHOULD BE HANDLED IN THE bin METHOD OF THE
    ;       DATA OBJECT.)



;011408
;syarr and syarrOrig are the error bars in the echo data.  
;The Idown and Iup values need to be handled differently depending on the
;choice of time averaging by the user. (See the checkbox labeled time average up/down and the method
;ooecho::report_timeaveage_state.)
;
;But even so, here we are just taking the sqrt of the data.  The eb for this display
;and for other calculations must be handled elsewhere.  
;
;Look at ooEcho::chirpMaskedAll
        syarrOrig = sqrt(yarrOrig)
        syarr = sqrt(yarr)

    ;RETRIEVE THE FIT PARAMETERS FROM THE DATA OBJECT
    ;FOR THE SELECTED PIXEL
        fitvals = ref->fitvals(xindex,yindex,tauindex)
;print,'t5b=',systime(1,/seconds)-t0

;print,'________________________________'
;print,'ooDisplayEcho:: C',systime(1,/seconds)-t0



;    ;CALCULATE THE FIT VALUES AT THE DATA POINTS
;        fit = ref->chirpfun(fitvals,tauindex)

    ;INTERPOLATE xarr TO A SUFFICIENT NUMBER OF POINTS TO SMOOTH THE
    ;PLOT OF THE FIT.
        xarrfit = ref->chirpPhases(tauindex)

;print,'t5b1=',systime(1,/seconds)-t0

        xfit = xarrfit[0] + $
            findgen(5*n_elements(xarrfit))*((xarrOrig[n_elements(xarrfit)-1]-xarrfit[0])/double(5*n_elements(xarrfit)))
;print,'t5b2=',systime(1,/seconds)-t0

        if n_elements(textfitparms) eq 6 then begin
            fitvals = textfitparms


            ;022406
            ;CHECK OMEGA v. PERIOD CONVERSION
            if fitvals[4] lt 0.0  then fitvals[4] = -1.0*fitvals[4]
            if fitvals[4] ge 10.0 then fitvals[4] = 360.0/fitvals[4]

            ;ORIGINAL LINE
;            fitvals[4] = 360.0/fitvals[4]
            ;print,'022406 oodisplayecho::plotvirtual'
        endif
;print,'________________________________'
;print,'ooDisplayEcho:: D',systime(1,/seconds)-t0

;        if n_elements(Av)     eq 1 then fitvals[0] = Av
;        if n_elements(Amp)    eq 1 then fitvals[1] = Amp
;        if n_elements(PHASE)  eq 1 then fitvals[2] = PHASE
;        if n_elements(W)      eq 1 then fitvals[3] = W
;        if n_elements(PERIOD) eq 1 then fitvals[4] = PERIOD/360.0d
;        if n_elements(PHO)    eq 1 then fitvals[5] = PHO

        yfit = chirpfun(xfit,fitvals)

        taus = ref->tau()
        fitphasevtau = ref->fitPhasevTau(xindex,yindex)
;print,'t5b3=',systime(1,/seconds)-t0

        currentPhasevTaux = [taus[tauindex]]
        currentPhasevTauy = [fitphasevTau[tauindex]]
;print,'t5b4=',systime(1,/seconds)-t0


;print,'________________________________'
;print,'ooDisplayEcho:: E',systime(1,/seconds)-t0



        fitAmpvtau = ref->fitAmpvTau(xindex,yindex)
;print,'t5b4a=',systime(1,/seconds)-t0


;print,'t5b4b=',systime(1,/seconds)-t0
        currentSignalvTaux = [taus[tauindex]]
;print,'t5b4c=',systime(1,/seconds)-t0

;print,'________________________________'
;print,'ooDisplayEcho:: F',systime(1,/seconds)-t0


;112905
    if self.plotindex eq 8 then begin
        signalvtau = ref->signalvtau(xindex,yindex,tavestate=timecheckboxval)
        signalvtau = self->checkforAllInfinities(signalvTau)
        currentSignalvTauy = [signalvTau[tauindex]]
    endif else begin
        ;print,'ONLY GET THE FIRST SIGNAL VALUE'
        signalvtau = ref->signalvtauOneTime(xindex,yindex,tauindex,tavestate=timecheckboxval)
        signalvtau = self->checkforAllInfinities(signalvTau)
        currentSignalvTauy = [signalvTau]
    endelse
;print,'________________________________'
;print,'ooDisplayEcho:: G',systime(1,/seconds)-t0

;print,'t5b5=',systime(1,/seconds)-t0


        currentAmpvTaux = [taus[tauindex]]
        currentAmpvTauy = [fitAmpvTau[tauindex]]
;print,'t5c=',systime(1,/seconds)-t0


endif else begin;obj_valid(ref)

    ;IF I GET HERE THERE WAS A PROBLEM.
    ;SET THE CURRENT WINDOW TO THE PIXMAP FOR THE PLOT
    wset,self.dw2pix
    plot,[0,0],[1,1],title='Plot Window',color=0L,background=255L+256L*(255L + 255L*256L)
    return

endelse
;print,'t6=',systime(1,/seconds)-t0

    endif else begin


        ;WHEN THERE IS NOTHING TO DISPLAY, MAKE UP SOME VALUES TO SHOW IN THE PLOT.
        theExtrema = indgen(27)
        siup = 1.0
        sidown = 1.0

        xarrOrig = indgen(27)
        yarrOrig = indgen(27)
        xarr = indgen(27)
        yarr = indgen(27)
        syarrOrig = sqrt(yarrOrig)
        syarr = sqrt(yarr)
        fit = indgen(27)
        xfit = indgen(27)
        yfit = indgen(27)

        xarrb = xarr
        dbx = indgen(27)
        dby = indgen(27)
        dbz = indgen(27)
        taus = indgen(27)
        fitphasevtau = indgen(27)
        signalvtau = indgen(27)

        currentPhasevTaux =  indgen(27)
        currentPhasevTauy =  indgen(27)
        fitAmpvtau =  indgen(27)

        currentAmpvTaux =  indgen(27)
        currentAmpvTauy =  indgen(27)
        parms = dblarr(12)

    endelse


    ;CREATE ARRAYS OF THE EXTREMA FOR PLOTTING
    hivals = dblarr(n_elements(xarr))+theExtrema[0]
    lovals = dblarr(n_elements(xarr))+theExtrema[1]
    shivals = dblarr(n_elements(xarr))+sidown
    slovals = dblarr(n_elements(xarr))+siup


    ;SET THE CURRENT WINDOW TO THE PIXMAP FOR THE PLOT
    wset,self.dw2pix

    ;PLOT ALL OF THE RELEVANT INFORMATION

    if n_elements(ref) eq 1 then begin
        subtitle = '"'+file_basename(ref->getproperty(tag='filename'))+'" '+ $
                    ref->getproperty(tag='comment')
        title = 'Q='+strtrim(string(ref->getproperty(tag='qactual'),format='(F10.5)'),2)+ 'A-1 '+ $
                   ' t='+strtrim(string((*(ref->getproperty(tag='fourierTime')))[self.ftChoiceIndex]),2)+ ' s ' + $
                   ' Element('+strtrim(string(xindex),2)+','+ $
                            strtrim(string(yindex),2)+')'

        parms = (*(ref->getproperty(tag='fitparms')))[*,self.xindex+self.detxdim*self.yindex,self.ftChoiceIndex]

        chisq = (*(ref->getproperty(tag='chisq')))[self.xindex+self.detxdim*self.yindex,self.ftChoiceIndex]

;print,"obj_isa(ref,'ooEchoMagnetic')=",obj_isa(ref,'ooEchoMagnetic')
;print,'________________________________'
;print,'ooDisplayEcho:: G1',systime(1,/seconds)-t0
        if obj_isa(ref,'ooEchoMagnetic') eq 1 then begin
            yoffset = ref->ThreeMplusNoverSix(self.xindex,self.yindex,self.ftchoiceindex)
        endif else begin
            yoffset = 0.0
        endelse
;print,'________________________________'
;print,'ooDisplayEcho:: G2',systime(1,/seconds)-t0

        format = '(%"%s%8.2f%s%6.2f")'

        if parms[5] eq 0.0 then begin
            legend = [ $
                      string('Av=',parms[0],' � ',parms[6],format=format),$
                      string('A=',parms[1],' � ',parms[7],format=format),$
                      string('PH=',parms[2],' � ',parms[8],format=format),$
                      string('W=',parms[3],' � ',parms[9],format=format),$
                      string('T=',360.0/parms[4],' � ',360.0*parms[10]/((parms[4])^2.0),format=format),$
                      string('chisq= ',chisq,format='(%"%s%10.2f")')]
        endif else begin
            legend = [ $
                      string('Av= ',parms[0],' � ',parms[6],format=format),$
                      string('A= ',parms[1],' � ',parms[7],format=format),$
                      string('PH= ',parms[2],' � ',parms[8],format=format),$
                      string('W= ',parms[3],' � ',parms[9],format=format),$
                      string('T= ',360.0/parms[4],' � ',360.0*parms[10]/((parms[4])^2.0),format=format),$
                      string('PHoffset= ',parms[5],' � ',parms[11],format=format),$
                      string('chisq= ',chisq,format='(%"%s%10.2f")')]

        endelse

    ;    legend = ['Av='+strtrim(string(parms[0]),2)+'+/-'+strtrim(string(parms[6],2)),$
    ;              'A='+strtrim(string(parms[1]),2)+'+/-'+strtrim(string(parms[7],2)),$
    ;              'PH='+strtrim(string(parms[2]),2)+'+/-'+strtrim(string(parms[8],2)),$
    ;              'W='+strtrim(string(parms[3]),2)+'+/-'+strtrim(string(parms[9],2)),$
    ;              'T='+strtrim(string(360.0/parms[4]),2)+'+/-'+strtrim(string(parms[10],2)),$
    ;              'chisq='+strtrim(string(chisq),2)]
    endif;n_elements(ref) eq 1
;print,'________________________________'
;print,'ooDisplayEcho:: H',systime(1,/seconds)-t0


    black = 0L & red = 255L & green = 256L*red & blue = 256L*green & white = red+green+blue

    xlego = 0.75
    ylego = 0.6
    if parms[5] eq 0.0 then begin
        xleg = [xlego,xlego,xlego,xlego,xlego,xlego]
        yleg = [ylego,ylego-0.06,ylego-0.12,ylego-0.18,ylego-0.24,ylego-0.30]
    endif else begin
        xleg = [xlego,xlego,xlego,xlego,xlego,xlego,xlego]
        yleg = [ylego,ylego-0.06,ylego-0.12,ylego-0.18,ylego-0.24,ylego-0.30,ylego-0.36]
    endelse
    xsub = 0.15
    ysub = 1.15

    ydelta = 0.045
;print,'________________________________'
;print,'ooDisplayEcho:: I',systime(1,/seconds)-t0

    if self.plotzoombox eq 1 then begin
        zoomxrange = [self.plotpressx,self.plotreleasex]
        zoomyrange = [self.plotpressy,self.plotreleasey]
;        print,'plotVirtual'
;        print,zoomxrange
;        print,zoomyrange
    endif else begin
;        print,'plotVirtual, plotzoombox=',plotzoombox

        zoomxrange = 0
        zoomyrange = 0
    endelse

;print,'________________________________'
;print,'ooDisplayEcho:: J',systime(1,/seconds)-t0


;print,'ooDisplayEcho::plotvirtual'
;print,self.plotindex
;print,writeplotdataflag
;print,writeplotdatafile
    plotzoombox = self.plotzoombox
    case self.plotIndex of
        0:begin
;            title = 'Plot = Counts v Phase:'+$
;                                strtrim(string(xindex),2)+','+$
;                                strtrim(string(yindex),2)


            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun
                printf,lun,'Fitparms:'
                printf,lun,transpose(legend)

                printf,lun,'Data:'
                printf,lun,'x:'
                printf,lun,xarrOrig
                printf,lun,'y:'
                printf,lun,yarrOrig
                printf,lun,'sy:'
                printf,lun,syArrOrig
                printf,lun,'Unmasked Data:'
                printf,lun,'x:'
                printf,lun,xarr
                printf,lun,'y:'
                printf,lun,yarr
                printf,lun,'sy:'
                printf,lun,syarr
                printf,lun,'fitvalues:'
                printf,lun,'x:'
                printf,lun,xfit
                printf,lun,'y:'
                printf,lun,yfit
                printf,lun,'FlipperOn/Off values:'
                printf,lun,'Up:'
                printf,lun,hivals
                printf,lun,'sUp:'
                printf,lun,shivals
                printf,lun,'Down:'
                printf,lun,lovals
                printf,lun,'sDown:'
                printf,lun,slovals

                free_lun,lun

            endif;writeplotdataflag

            LarPloterr,xarrOrig,yarrOrig,syarrOrig,$
                        xarr,yarr,syarr,xfit=xfit,yfit=yfit,$
                        yoffset=yoffset,$
                        fitplotswitch = fitplotswitch,$
                        ymax = hivals, ymin = lovals,$
                        symax = shivals, symin = slovals,$
                        xarrb = xarrb,$
                        winid = self.dw2pix,$
                        title = title,$
                        subtitle = subtitle,$
                        ytitle = 'Intensity',$
                        xtitle = 'phase',$
                        plotxrange = plotxrange,$
                        plotyrange = plotyrange,$
                        plotzoombox = plotzoombox, $
                        zoomxrange = zoomxrange, zoomyrange = zoomyrange

;            nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                        color = 0L,$
;                        psym = 0,symsize=1

            for i=0,n_elements(legend)-1 do begin
                nse_legend,self.dw2pix,xleg[i],yleg[i],legend[i],$
                            color = 0L,$
                            psym = 0,symsize=1

            endfor;i

            end;0
        1:begin         ;PLOT FIT PHASE v TAU
;            title = 'Plot = Fit Phase v. Tau:'+$
;                                strtrim(string(xindex),2)+','+$
;                                strtrim(string(yindex),2)
;help,plotxrange
            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun

                printf,lun,'times:'
                printf,lun,taus*10.0^9
                printf,lun,'phases'
                printf,lun,fitphasevtau

                free_lun,lun

            endif;writeplotdataflag



            if n_elements(plotxrange) eq 2 then begin
                plot,taus*10.0^9,fitphasevtau,psym=-4,/xlog,$
                            xrange = plotxrange,$
                            yrange = plotyrange,$
                            color = 0L,$
                            background = 255L + 256L*(255L + 256L*255L),$
                            title=title,$
                            subtitle = subtitle,$
                            xtitle = 'Fourier Time (ns)',$
                            ytitle = 'FitPhase',symsize=2,$
                            xstyle=1,ystyle=1

            endif else begin
                plot,taus*10.0^9,fitphasevtau,psym=-4,/xlog,$
                            yrange = [min(fitphasevtau),max(fitphasevtau)],$
                            color = 0L,$
                            background = 255L + 256L*(255L + 256L*255L),$
                            title=title,$
                            subtitle = subtitle,$
                            xtitle = 'Fourier Time (ns)',$
                            ytitle = 'FitPhase',symsize=2
            endelse
            oplot,currentPhasevTaux*10.0^9,$
                  currentPhasevTauy,$
                  color=0L + 256L*(255L + 256L*0L),$
                  psym=2,symsize=3

            if self.plotzoombox eq 1 then begin
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
                plots,[self.plotreleasex,self.plotreleasex],[self.plotpressy,self.plotreleasey],color=0L
                plots,[self.plotreleasex,self.plotpressx],[self.plotreleasey,self.plotreleasey],color=0L
                plots,[self.plotpressx,self.plotpressx],[self.plotreleasey,self.plotpressy],color=0L
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
            endif

;            nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                        color = 0L,$
;                        psym = 0,symsize=1
            nse_legend,self.dw2pix,0.6,0.9,'Current Image Selection',$
                        color = 0L + 256L*(255L + 256L*0L),$
                        psym = 2,symsize=2
        end;1
        2:begin     ;PLOT EVERYTHING WITH Bx
;                title = 'Plot = Counts v Phase:'+$
;                                strtrim(string(xindex),2)+','+$
;                                strtrim(string(yindex),2)

                if writeplotdataflag eq 1 then begin
                    openw,lun,writeplotdatafile,/get_lun
                    printf,lun,'Fitparms:'
                    printf,lun,transpose(legend)

                    printf,lun,'Data:'
                    printf,lun,'x:'
                    printf,lun,xarrOrig
                    printf,lun,'y:'
                    printf,lun,yarrOrig
                    printf,lun,'sy:'
                    printf,lun,syArrOrig
                    printf,lun,'Unmasked Data:'
                    printf,lun,'x:'
                    printf,lun,xarr
                    printf,lun,'y:'
                    printf,lun,yarr
                    printf,lun,'sy:'
                    printf,lun,syarr
                    printf,lun,'fitvalues:'
                    printf,lun,'x:'
                    printf,lun,xfit
                    printf,lun,'y:'
                    printf,lun,yfit
                    printf,lun,'FlipperOn/Off values:'
                    printf,lun,'Up:'
                    printf,lun,hivals
                    printf,lun,'sUp:'
                    printf,lun,shivals
                    printf,lun,'Down:'
                    printf,lun,lovals
                    printf,lun,'sDown:'
                    printf,lun,slovals
                    printf,lun,'Bx:'
                    printf,lun,'X:'
                    printf,lun,xarrb
                    printf,lun,'Y:'
                    printf,lun,dbx
                    free_lun,lun

                endif;writeplotdataflag



                LarPloterr,xarrOrig,yarrOrig,syarrOrig,$
                        xarr,yarr,syarr,xfit=xfit,yfit=yfit,$
                        yoffset=yoffset,$
                        fitplotswitch = fitplotswitch,$
                        ymax = hivals, ymin = lovals,$
                        symax = shivals, symin = slovals,$
                        bx=dbx,$
                        xarrb = xarrb,$
                        winid = self.dw2pix,$
                        title = title,$
                        subtitle = subtitle,$
                        ytitle = 'Intensity',$
                        xtitle = 'phase',$
                        plotxrange = plotxrange,$
                        plotyrange = plotyrange,$
                        plotzoombox = plotzoombox, $
                        zoomxrange = zoomxrange, zoomyrange = zoomyrange


;                nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                            color = 0L,$
;                            psym = 0,symsize=1
                for i=0,n_elements(legend)-1 do begin
                    nse_legend,self.dw2pix,xleg[i],yleg[i],legend[i],$
                                color = 0L,$
                                psym = 0,symsize=1
                endfor;i

            end;2
        3:begin     ;PLOT EVERYTHING WITH By
;            title = 'Plot = Counts v Phase:'+$
;                                strtrim(string(xindex),2)+','+$
;                                strtrim(string(yindex),2)


            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun

                printf,lun,'Fitparms:'
                printf,lun,transpose(legend)
                printf,lun,'Data:'
                printf,lun,'x:'
                printf,lun,xarrOrig
                printf,lun,'y:'
                printf,lun,yarrOrig
                printf,lun,'sy:'
                printf,lun,syArrOrig
                printf,lun,'Unmasked Data:'
                printf,lun,'x:'
                printf,lun,xarr
                printf,lun,'y:'
                printf,lun,yarr
                printf,lun,'sy:'
                printf,lun,syarr
                printf,lun,'fitvalues:'
                printf,lun,'x:'
                printf,lun,xfit
                printf,lun,'y:'
                printf,lun,yfit
                printf,lun,'FlipperOn/Off values:'
                printf,lun,'Up:'
                printf,lun,hivals
                printf,lun,'sUp:'
                printf,lun,shivals
                printf,lun,'Down:'
                printf,lun,lovals
                printf,lun,'sDown:'
                printf,lun,slovals
                printf,lun,'By:'
                printf,lun,'X:'
                printf,lun,xarrb
                printf,lun,'Y:'
                printf,lun,dby
                free_lun,lun

            endif;writeplotdataflag


            LarPloterr,xarrOrig,yarrOrig,syarrOrig,$
                        xarr,yarr,syarr,xfit=xfit,yfit=yfit,$
                        yoffset=yoffset,$
                        fitplotswitch = fitplotswitch,$
                        ymax = hivals, ymin = lovals,$
                        symax = shivals, symin = slovals,$
                        by=dby,$
                        xarrb = xarrb,$
                        winid = self.dw2pix,$
                        title = title,$;'Plot = Counts v Phase:'+$
                                $;strtrim(string(xindex),2)+','+$
                                $;strtrim(string(yindex),2),$
                        subtitle = subtitle,$
                        ytitle = 'Intensity',$
                        xtitle = 'phase',$
                        plotxrange = plotxrange,$
                        plotyrange = plotyrange,$
                        plotzoombox = plotzoombox, $
                        zoomxrange = zoomxrange, zoomyrange = zoomyrange
;                nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                            color = 0L,$
;                            psym = 0,symsize=1
                for i=0,n_elements(legend)-1 do begin
                    nse_legend,self.dw2pix,xleg[i],yleg[i],legend[i],$
                                color = 0L,$
                                psym = 0,symsize=1
                endfor;i
            end;3
        4:begin     ;PLOT EVERYTHING WITH Bz
;            title = 'Plot = Counts v Phase:'+$
;                                strtrim(string(xindex),2)+','+$
;                                strtrim(string(yindex),2)

            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun

                printf,lun,'Fitparms:'
                printf,lun,transpose(legend)
                printf,lun,'Data:'
                printf,lun,'x:'
                printf,lun,xarrOrig
                printf,lun,'y:'
                printf,lun,yarrOrig
                printf,lun,'sy:'
                printf,lun,syArrOrig
                printf,lun,'Unmasked Data:'
                printf,lun,'x:'
                printf,lun,xarr
                printf,lun,'y:'
                printf,lun,yarr
                printf,lun,'sy:'
                printf,lun,syarr
                printf,lun,'fitvalues:'
                printf,lun,'x:'
                printf,lun,xfit
                printf,lun,'y:'
                printf,lun,yfit
                printf,lun,'FlipperOn/Off values:'
                printf,lun,'Up:'
                printf,lun,hivals
                printf,lun,'sUp:'
                printf,lun,shivals
                printf,lun,'Down:'
                printf,lun,lovals
                printf,lun,'sDown:'
                printf,lun,slovals
                printf,lun,'Bz:'
                printf,lun,'X:'
                printf,lun,xarrb
                printf,lun,'Y:'
                printf,lun,dbz
                free_lun,lun

            endif;writeplotdataflag


            LarPloterr,xarrOrig,yarrOrig,syarrOrig,$
                        xarr,yarr,syarr,xfit=xfit,yfit=yfit,$
                        yoffset=yoffset,$
                        fitplotswitch = fitplotswitch,$
                        ymax = hivals, ymin = lovals,$
                        symax = shivals, symin = slovals,$
                        bz=dbz,$
                        xarrb = xarrb,$
                        winid = self.dw2pix,$
                        title = title,$;'Plot = Counts v Phase:'+$
                                $;strtrim(string(xindex),2)+','+$
                                $;strtrim(string(yindex),2),$
                        subtitle = subtitle,$
                        ytitle = 'Intensity',$
                        xtitle = 'phase',$
                        plotxrange = plotxrange,$
                        plotyrange = plotyrange,$
                        plotzoombox = plotzoombox, $
                        zoomxrange = zoomxrange, zoomyrange = zoomyrange
;                nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                            color = 0L,$
;                            psym = 0,symsize=1
                for i=0,n_elements(legend)-1 do begin
                    nse_legend,self.dw2pix,xleg[i],yleg[i],legend[i],$
                                color = 0L,$
                                psym = 0,symsize=1
                endfor;i
            end;4
        5:begin     ;PLOT EVERYTHING

            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun

                printf,lun,'Fitparms:'
                printf,lun,transpose(legend)

                printf,lun,'Data:'
                printf,lun,'x:'
                printf,lun,xarrOrig
                printf,lun,'y:'
                printf,lun,yarrOrig
                printf,lun,'sy:'
                printf,lun,syArrOrig
                printf,lun,'Unmasked Data:'
                printf,lun,'x:'
                printf,lun,xarr
                printf,lun,'y:'
                printf,lun,yarr
                printf,lun,'sy:'
                printf,lun,syarr
                printf,lun,'fitvalues:'
                printf,lun,'x:'
                printf,lun,xfit
                printf,lun,'y:'
                printf,lun,yfit
                printf,lun,'FlipperOn/Off values:'
                printf,lun,'Up:'
                printf,lun,hivals
                printf,lun,'sUp:'
                printf,lun,shivals
                printf,lun,'Down:'
                printf,lun,lovals
                printf,lun,'sDown:'
                printf,lun,slovals
                printf,lun,"B's:"
                printf,lun,'X:'
                printf,lun,xarrb
                printf,lun,'Bx:'
                printf,lun,dbx
                printf,lun,'By:'
                printf,lun,dby
                printf,lun,'Bz:'
                printf,lun,dbz
                free_lun,lun

            endif;writeplotdataflag



            LarPloterr,xarrOrig,yarrOrig,syarrOrig,$
                        xarr,yarr,syarr,xfit=xfit,yfit=yfit,$
                        yoffset=yoffset,$
                        fitplotswitch = fitplotswitch,$
                        ymax = hivals, ymin = lovals,$
                        symax = shivals, symin = slovals,$
                        bx=dbx,$
                        by=dby,$
                        bz=dbz,$
                        xarrb = xarrb,$
                        winid = self.dw2pix,$
                        title = title,$
                        subtitle = subtitle,$
                        ytitle = 'Intensity',$
                        xtitle = 'phase',$
                        plotxrange = plotxrange,$
                        plotyrange = plotyrange,$
                        plotzoombox = plotzoombox, $
                        zoomxrange = zoomxrange, zoomyrange = zoomyrange
;                nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                            color = 0L,$
;                            psym = 0,symsize=1
                for i=0,n_elements(legend)-1 do begin
                    nse_legend,self.dw2pix,xleg[i],yleg[i],legend[i],$
                                color = 0L,$
                                psym = 0,symsize=1
                endfor;i
            end;5
        6:begin     ;PLOT FIT AMPLITUDE V TAU
;            title = 'Plot = Fit Amplitude v. Tau:'+$
;                                strtrim(string(xindex),2)+','+$
;                                strtrim(string(yindex),2)


            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun

                printf,lun,'times:'
                printf,lun,taus*10.0^9
                printf,lun,'amplitudes'
                printf,lun,fitampvtau

                free_lun,lun

            endif;writeplotdataflag



            if n_elements(plotxrange) eq 2 then begin
                plot,taus*10.0^9,fitampvtau,psym=-4,$
                            yrange = plotyrange,$
                            xrange = plotxrange,$
                            color = 0L,$
                            background = 255L + 256L*(255L + 256L*255L),$
                            title=title,$;'Plot = Fit Amplitude v. Tau:'+$
                                    $;strtrim(string(xindex),2)+','+$
                                    $;strtrim(string(yindex),2),$
                            subtitle = subtitle,$
                            xtitle = 'Fourier Time (ns)',$
                            ytitle = 'Fit Apmlitude',$
                            xstyle=1, ystyle=1

            endif else begin
                plot,taus*10.0^9,fitampvtau,psym=-4,$
                            yrange = [min(fitampvtau),max(fitampvtau)],$
                            color = 0L,$
                            background = 255L + 256L*(255L + 256L*255L),$
                            title=title,$;'Plot = Fit Amplitude v. Tau:'+$
                                    $;strtrim(string(xindex),2)+','+$
                                    $;strtrim(string(yindex),2),$
                            subtitle = subtitle,$
                            xtitle = 'Fourier Time (ns)',$
                            ytitle = 'Fit Apmlitude'
            endelse
            oplot,currentAmpvTaux*10.0^9,$
                  currentAmpvTauy,$
                  color=0L + 256L*(255L + 256L*0L),$
                  psym=2,symsize=3

            if self.plotzoombox eq 1 then begin
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
                plots,[self.plotreleasex,self.plotreleasex],[self.plotpressy,self.plotreleasey],color=0L
                plots,[self.plotreleasex,self.plotpressx],[self.plotreleasey,self.plotreleasey],color=0L
                plots,[self.plotpressx,self.plotpressx],[self.plotreleasey,self.plotpressy],color=0L
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
            endif



;            nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                        color = 0L,$
;                        psym = 0,symsize=1
            end;6
        7:begin     ;COUTOURECHO

            if writeplotdataflag eq 1 then begin
                void = dialog_message('Output to file not yet available for contourEcho')
            endif;writeplotdataflag


            ref->contourEcho,xindex,yindex,tauindex,winid=self.dw2pix,$
                                            title=title,subtitle=subtitle
;            nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                        color = 0L,$
;                        psym = 0,symsize=1
        end;7
        8:begin         ;SIGNAL v TAU

            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun

                printf,lun,'times:'
                printf,lun,taus*10.0^9
                printf,lun,'signal'
                printf,lun,signalvtau

                free_lun,lun

            endif;writeplotdataflag

            if n_elements(plotxrange) eq 2 then begin
                plot,taus*10.0^9,signalvtau,psym=-4,/xlog,$
                            yrange = plotyrange,$
                            xrange = plotxrange,$
                            color = 0L,$
                            background = 255L + 256L*(255L + 256L*255L),$
                            title=title,$
                            subtitle = subtitle,$
                            xtitle = 'Fourier Time (ns)',$
                            ytitle = 'FitPhase',symsize=2,$
                            ystyle=1,xstyle=1
            endif else begin
                plot,taus*10.0^9,signalvtau,psym=-4,/xlog,$
                            yrange = [min(signalvtau),max(signalvtau)],$
                            color = 0L,$
                            background = 255L + 256L*(255L + 256L*255L),$
                            title=title,$
                            subtitle = subtitle,$
                            xtitle = 'Fourier Time (ns)',$
                            ytitle = 'FitPhase',symsize=2
            endelse

            oplot,currentSignalvTaux*10.0^9,$
                  currentSignalvTauy,$
                  color=0L + 256L*(255L + 256L*0L),$
                  psym=2,symsize=3
            if self.plotzoombox eq 1 then begin
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
                plots,[self.plotreleasex,self.plotreleasex],[self.plotpressy,self.plotreleasey],color=0L
                plots,[self.plotreleasex,self.plotpressx],[self.plotreleasey,self.plotreleasey],color=0L
                plots,[self.plotpressx,self.plotpressx],[self.plotreleasey,self.plotpressy],color=0L
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
            endif

;            nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                        color = 0L,$
;                        psym = 0,symsize=1
            nse_legend,self.dw2pix,0.6,0.9,'Current Image Selection',$
                        color = 0L + 256L*(255L + 256L*0L),$
                        psym = 2,symsize=2
        end;8
        9:begin ;MAGNETIC COMPONENTS


            dum = ref->f_polanalysisgeneral(0,image=image,eimage=eimage,plotdata=plotdata,eplotdata=eplotdata,/magq1d)
            plotcolor = [black,red,green,blue]
            plotnames = ['magnetic','spin incoh','coh & isotope incoh','total']
            legendpos = [0.0,-0.04,-0.08,-0.12]
            legendsym = [-2,-4,-5,-6]
            symsize=1


            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun

                printf,lun,'times:'
                printf,lun,taus*10.0^9
                printf,lun,'magnetic'
                printf,lun,plotdata[0*n_elements(taus):1*n_elements(taus)-1]
                printf,lun,'EB magnetic'
                printf,lun,eplotdata[0*n_elements(taus):1*n_elements(taus)-1]
                printf,lun,'spin incoh'
                printf,lun,plotdata[1*n_elements(taus):2*n_elements(taus)-1]
                printf,lun,'EB spin incoh'
                printf,lun,eplotdata[1*n_elements(taus):2*n_elements(taus)-1]
                printf,lun,'coh & isotope incoh'
                printf,lun,plotdata[2*n_elements(taus):3*n_elements(taus)-1]
                printf,lun,'EB coh & isotope incoh'
                printf,lun,eplotdata[2*n_elements(taus):3*n_elements(taus)-1]
                printf,lun,'Total'
                printf,lun,plotdata[3*n_elements(taus):4*n_elements(taus)-1]
                printf,lun,'EB Total'
                printf,lun,eplotdata[3*n_elements(taus):4*n_elements(taus)-1]

                free_lun,lun

            endif;writeplotdataflag

            if n_elements(plotxrange) eq 2 then begin
                ploty = plotdata[0*n_elements(taus):1*n_elements(taus)-1]
                plotey = eplotdata[0*n_elements(taus):1*n_elements(taus)-1]
                plot,taus,plotdata[0*n_elements(taus):1*n_elements(taus)-1],$
                            background = white,color=black,$
                            xrange=plotxrange,$
                            yrange=plotyrange,$
                            title='Components: Area averaged',psym=-2,/xlog,$
                            xtitle = 'Fourier Time',$
                            xstyle=1,ystyle=1
                errplot,taus,ploty-plotey,ploty+plotey,color=black
            endif else begin


                ploty = plotdata[0*n_elements(taus):1*n_elements(taus)-1]
                plotey = eplotdata[0*n_elements(taus):1*n_elements(taus)-1]
                plot,taus,ploty,$
                            background = white,color=black,$
                            yrange=[min(plotdata-eplotdata),max(plotdata+eplotdata)],$
                            title='Magnetic Components: Area averaged',psym=-2,/xlog,$
                            xtitle = 'Fourier Time'
                errplot,taus,ploty-plotey,ploty+plotey,color=black
            endelse


            for iii = 1,3 do begin
                ploty1 = plotdata[iii*n_elements(taus):(iii+1)*n_elements(taus)-1]
                plotey1 = eplotdata[iii*n_elements(taus):(iii+1)*n_elements(taus)-1]
                oplot,taus,ploty1,$
                      color=plotcolor[iii],$
                      psym=legendsym[iii],symsize=symsize
                errplot,taus,ploty1-plotey1,ploty1+plotey1,color=plotcolor[iii]
            endfor;iii


            if self.plotzoombox eq 1 then begin
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
                plots,[self.plotreleasex,self.plotreleasex],[self.plotpressy,self.plotreleasey],color=0L
                plots,[self.plotreleasex,self.plotpressx],[self.plotreleasey,self.plotreleasey],color=0L
                plots,[self.plotpressx,self.plotpressx],[self.plotreleasey,self.plotpressy],color=0L
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
            endif

            xo=0.55 & yo = 0.5
            for iii=0,3 do begin
                nse_legend, self.dw2pix,xo,yo+legendpos[iii],$
                            plotnames[iii],color=plotcolor[iii],psym=legendsym[iii]
            endfor;iii

        end;9
        10:begin;Magnetic components, 1 pixel


            pixel = self.detxdim*self.yindex + self.xindex
            dum = ref->f_polanalysisgeneral(0,image=image,eimage=eimage,pixel=pixel,$
                                            plotdata=plotdata,eplotdata=eplotdata,sq1dtotal=sq1dtotal)
            plotcolor = [black,red,green,blue]
            plotnames = ['magnetic','spin incoh','coh & isotope incoh','total']
            legendpos = [0.0,-0.04,-0.08,-0.12]
            legendsym = [-2,-4,-5,-6]
            symsize=1

            if writeplotdataflag eq 1 then begin
                openw,lun,writeplotdatafile,/get_lun

                printf,lun,'times:'
                printf,lun,taus*10.0^9
                printf,lun,'magnetic'
                printf,lun,plotdata[0*n_elements(taus):1*n_elements(taus)-1]
                printf,lun,'EB magnetic'
                printf,lun,eplotdata[0*n_elements(taus):1*n_elements(taus)-1]
                printf,lun,'spin incoh'
                printf,lun,plotdata[1*n_elements(taus):2*n_elements(taus)-1]
                printf,lun,'EB spin incoh'
                printf,lun,eplotdata[1*n_elements(taus):2*n_elements(taus)-1]
                printf,lun,'coh & isotope incoh'
                printf,lun,plotdata[2*n_elements(taus):3*n_elements(taus)-1]
                printf,lun,'EB coh & isotope incoh'
                printf,lun,eplotdata[2*n_elements(taus):3*n_elements(taus)-1]
                printf,lun,'Total'
                printf,lun,plotdata[3*n_elements(taus):4*n_elements(taus)-1]
                printf,lun,'EB Total'
                printf,lun,eplotdata[3*n_elements(taus):4*n_elements(taus)-1]

                free_lun,lun

            endif;writeplotdataflag
            if n_elements(plotxrange) eq 2 then begin
                ploty = plotdata[0*n_elements(taus):1*n_elements(taus)-1]
                plotey = eplotdata[0*n_elements(taus):1*n_elements(taus)-1]
                plot,taus,ploty,$
                            background = white,color=black,$
                            xrange=plotxrange,$
                            yrange=plotyrange,$
                            title='Magnetic Components: Pixel'+ $
                                    strtrim(string(xindex),2)+','+$
                                    strtrim(string(yindex),2),$
                            psym=-2,/xlog,$
                            xtitle = 'Fourier Time',$
                            xstyle=1,ystyle=1
                errplot,taus,ploty-plotey,ploty+plotey,color=black
            endif else begin
                ploty = plotdata[0*n_elements(taus):1*n_elements(taus)-1]
                plotey = eplotdata[0*n_elements(taus):1*n_elements(taus)-1]
                plot,taus,ploty,$
                            background = white,color=black,$
                            yrange=[min(plotdata-eplotdata),max(plotdata+eplotdata)],$
                            title='Magnetic Components: Pixel ['+ $
                                    strtrim(string(xindex),2)+','+$
                                    strtrim(string(yindex),2)+']',$
                            psym=-2,/xlog,$
                            xtitle = 'Fourier Time'
                errplot,taus,ploty-plotey,ploty+plotey,color=black
            endelse

;            for iii = 1,3 do begin
;;                print,'1880 ooDisplayeEcho::plotvirtual Problem seems to be in the EB calc in __fpolana...',iii
;;                print,'THE VALUES I AM TAKING TO BE EBs ARE PROBABLY NOT EBs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
;                ploty1 = plotdata[iii*n_elements(taus):(iii+1)*n_elements(taus)-1]
;;                print,ploty1
;                plotey1 = eplotdata[iii*n_elements(taus):(iii+1)*n_elements(taus)-1]
;;                print,plotey1
;                oplot,ploty1,$
;                      color=plotcolor[iii],$
;                      psym=1,$;legendsym[iii],$
;                      symsize=3
;                errplot,taus,ploty1-plotey1,ploty1+plotey1,color=plotcolor[iii]
;            endfor;iii

            for iii = 1,3 do begin
                ploty1 = plotdata[iii*n_elements(taus):(iii+1)*n_elements(taus)-1]
                plotey1 = eplotdata[iii*n_elements(taus):(iii+1)*n_elements(taus)-1]
                oplot,taus,ploty1,$
                      color=plotcolor[iii],$
                      psym=legendsym[iii],symsize=symsize
                errplot,taus,ploty1-plotey1,ploty1+plotey1,color=plotcolor[iii]
            endfor;iii


            if self.plotzoombox eq 1 then begin
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
                plots,[self.plotreleasex,self.plotreleasex],[self.plotpressy,self.plotreleasey],color=0L
                plots,[self.plotreleasex,self.plotpressx],[self.plotreleasey,self.plotreleasey],color=0L
                plots,[self.plotpressx,self.plotpressx],[self.plotreleasey,self.plotpressy],color=0L
                plots,[self.plotpressx,self.plotreleasex],[self.plotpressy,self.plotpressy],color=0L
            endif
            xo=0.55 & yo = 0.5

            for iii=0,3 do begin
                nse_legend, self.dw2pix,xo,yo+legendpos[iii],$
                            plotnames[iii],color=plotcolor[iii],psym=legendsym[iii]
            endfor;iii


        end;10
        else:begin  ;PLOT EVERYTHING
                if writeplotdataflag eq 1 then begin
                    openw,lun,writeplotdatafile,/get_lun
                    printf,lun,'Fitparms:'
                    printf,lun,transpose(legend)

                    printf,lun,'Data:'
                    printf,lun,'x:'
                    printf,lun,xarrOrig
                    printf,lun,'y:'
                    printf,lun,yarrOrig
                    printf,lun,'sy:'
                    printf,lun,syArrOrig
                    printf,lun,'Unmasked Data:'
                    printf,lun,'x:'
                    printf,lun,xarr
                    printf,lun,'y:'
                    printf,lun,yarr
                    printf,lun,'sy:'
                    printf,lun,syarr
                    printf,lun,'fitvalues:'
                    printf,lun,'x:'
                    printf,lun,xfit
                    printf,lun,'y:'
                    printf,lun,yfit
                    printf,lun,'FlipperOn/Off values:'
                    printf,lun,'Up:'
                    printf,lun,hivals
                    printf,lun,'sUp:'
                    printf,lun,shivals
                    printf,lun,'Down:'
                    printf,lun,lovals
                    printf,lun,'sDown:'
                    printf,lun,slovals
                    printf,lun,'Bx:'
                    printf,lun,'X:'
                    printf,lun,xarrb
                    printf,lun,'Y:'
                    printf,lun,dbx
                    printf,lun,'Bx:'
                    printf,lun,'X:'
                    printf,lun,xarrb
                    printf,lun,'Y:'
                    printf,lun,dby
                    printf,lun,'Bz:'
                    printf,lun,'X:'
                    printf,lun,xarrb
                    printf,lun,'Y:'
                    printf,lun,dbz
                    free_lun,lun

                endif;writeplotdataflag

            LarPloterr,xarrOrig,yarrOrig,syarrOrig,$
                        xarr,yarr,syarr,xfit=xfit,yfit=yfit,$
                        yoffset=yoffset,$
                        fitplotswitch = fitplotswitch,$
                        ymax = hivals, ymin = lovals,$
                        symax = shivals, symin = slovals,$
                        bx=dbx,$
                        by=dby,$
                        bz=dbz,$
                        xarrb = xarrb,$
                        winid = self.dw2pix,$
                        title = title,$
                        subtitle = subtitle,$
                        ytitle = 'Intensity',$
                        xtitle = 'phase',$
                        plotxrange = plotxrange,$
                        plotyrange = plotyrange,$
                        plotzoombox = plotzoombox, $
                        zoomxrange = zoomxrange, zoomyrange = zoomyrange
;            nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                        color = 0L,$
;                        psym = 0,symsize=1
            for i=0,n_elements(legend)-1 do begin
                nse_legend,self.dw2pix,xleg[i],yleg[i],legend[i],$
                            color = 0L,$
                            psym = 0,symsize=1
            endfor;i
        end
    endcase


    ;041305
    ;SET THE dw2 AXIS POINTERS HERE.
    ;RELEASE AXIS POINTERS FOR WINDOW
    ptr_free,self.w2xptr
    ptr_free,self.w2yptr

    ;RESET AXIS POINTERS
    self.w2xptr = ptr_new(!x)   ;SET THESE VALUES AT THIS POINT TO
    self.w2yptr = ptr_new(!y)   ;PREVENT AXIS CONFUSION

;device,decomposed=0
;    tvlct,r,g,b
;
;device,decomposed=1

    ;ADD OPTIONAL AuxilIARY PLOT
    if widget_info(self.dw2aux,/valid_id) gt 0 then begin
        wset,self.dw2auxpix
        switch self.plotindex of
        0:
        2:
        3:
        4:
        5:begin
            plot,taus*10.0^9,fitphasevtau,psym=-4,/xlog,$
                        yrange = [min(fitphasevtau),max(fitphasevtau)],$
                        color = 0L,$
                        background = 255L + 256L*(255L + 256L*255L),$
                        title='Plot = Fit Phase v. Tau:'+$
                                strtrim(string(xindex),2)+','+$
                                strtrim(string(yindex),2),$
                        subtitle = subtitle,$
                        xtitle = 'Fourier Time (ns)',$
                        ytitle = 'FitPhase',symsize=2
            oplot,currentPhasevTaux*10.0^9,$
                  currentPhasevTauy,$
                  color=0L + 256L*(255L + 256L*0L),$
                  psym=2,symsize=3
;            nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                        color = 0L,$
;                        psym = 0,symsize=1
            nse_legend,self.dw2auxpix,0.7,0.9,'Current Image Selection',$
                        color = 0L + 256L*(255L + 256L*0L),$
                        psym = 2,symsize=2
            break
        end;0,2,3,4,5
        1:
        6:
        8:
        9:
        10:
        11:begin
            LarPloterr,xarrOrig,yarrOrig,syarrOrig,$
                        xarr,yarr,syarr,xfit=xfit,yfit=yfit,$
                        fitplotswitch = fitplotswitch,$
                        yoffset=yoffset,$
                        ymax = hivals, ymin = lovals,$
                        symax = shivals, symin = slovals,$
                        bx=dbx,$
                        by=dby,$
                        bz=dbz,$
                        xarrb = xarrb,$
                        winid = self.dw2auxpix,$
                        title = title,$;'Plot = Counts v Phase:'+$
                                $;strtrim(string(xindex),2)+','+$
                                $;strtrim(string(yindex),2),$
                        subtitle = subtitle,$
                        ytitle = 'Intensity',$
                        xtitle = 'phase'
;                nse_legend,self.dw2pix,xsub,ysub,subtitle,$
;                            color = 0L,$
;                            psym = 0,symsize=1
                for i=0,n_elements(legend)-1 do begin
                    nse_legend,self.dw2auxpix,xleg[i],yleg[i],legend[i],$
                                color = 0L,$
                                psym = 0,symsize=1
                endfor;i
        end;1,6
        endswitch


        ;041305
        ;SET THE dw2aux AXIS POINTERS HERE.

        ;RELEASE AXIS POINTERS FOR WINDOW
        ptr_free,self.w2xauxptr
        ptr_free,self.w2yauxptr
        ;RESET AXIS POINTERS
        self.w2xauxptr = ptr_new(!x)   ;SET THESE VALUES AT THIS POINT TO
        self.w2yauxptr = ptr_new(!y)   ;PREVENT AXIS CONFUSION

    endif;AUX PLOT.

device,decomposed = dc

end;plotVirtual
pro ooDisplayEcho::printWindow,plotw=plotw,imagew=imagew,auxw=auxw
;
;NAME:
;        ooDisplayEcho::printWindow
;
;PURPOSE:
;           Print the selected window to a .ps file.
;PARAMETERS:
;           none
;KEYWORDS:
;           plotw       print plot window
;           imagew      print image window
;           auxw        print Auxiliary window
;

    if n_elements(plotw) eq 0 then plotw = 0
    if n_elements(imagew) eq 0 then imagew = 0
    if n_elements(auxw) eq 0 then auxw = 0

    if plotw eq 1 then begin
        wset,self.dw2id
        filename = 'nse_plotwin.ps'
    endif
    if imagew eq 1 then begin
        wset,self.dw1id
        filename = 'nse_imagewin.ps'
    endif
    if auxw eq 1 then begin
        wset,self.dw2auxid
        filename = 'nse_auxwin.ps'
    endif

    if ((plotw + imagew + auxw) eq 1) then begin
        result = tvrd(true=3)
        ;print,filename
        ;help,result
        nse_ps_plotter,result,filename=filename,directory=self.work_dir
    endif


end;printWindow
pro ooDisplayEcho::setDisplayImage
;
;NAME:
;        ooDisplayEcho::setDisplayImage
;
;PURPOSE:
;           Determine which image to display and produce 2d image array.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    ;;
    ;ooDisplayEcho::setDisplayImage
    ;
    ;THIS PROCEDURE DECIDES WHICH IMAGE TO DISPLAY IN THE
    ;drawImage DISPLAY.  CHOICES ARE THE INTENSITY OF THE
    ;ZEROTH PHASE FOR THE CURRENT FOURIER TIME OR ANY OF
    ;THE FIT PARAMETERS.
    ;
    ;NOTE:
    ;THIS PROCEDURE SHOULD BE CALLED ONLY BY THE draw METHOD
    ;;;

    ;FREE CURRENT PHASE(0) DATA POINTER FOR REDEFINITION
    if ptr_valid(self.ie) gt 0 then ptr_free,self.ie

    ;GET ARRAY OF PHASE DATA FOR POSSIBLE DISPLAY
    ;
    ;CHECK THAT ftChoiceIndex IS IN RANGE AND CHANGE AS NECESSARY
    theLastIndex = n_elements((*self.mye)[0,0,*])-1
    if (self.ftChoiceIndex le theLastIndex) then begin
        self.ie = ptr_new((*self.mye)[*,0,self.ftChoiceIndex])
    endif else begin
        self.ie = ptr_new((*self.mye)[*,0,theLastIndex])
        self.ftChoiceIndex = theLastIndex
    endelse

    ref = self.dataContainer->get(position=self.QChoiceIndex)
;print,obj_valid(ref)

;113005
;FIX THIS BUG SO THAT THE PROGRAM WILL OPEN!!!
if obj_valid(ref) gt 0 then begin
    ;112805
    ;SET THE VALUE OF ref_magnetic TO TELL THE CASES BELOW TO SET IMAGE OPTIONS TO
    ;A GENERAL OPTION IF NECESSARY
    if obj_isa(ref,'ooEchoMagnetic') gt 0 then begin
        if ref->getproperty(tag='magnetic') eq 0 then begin
            ref_magnetic = 0
        endif else begin
            ref_magnetic = 1
        endelse
    endif else begin
        ref_magnetic = 0
    endelse
    if ref_magnetic eq 0 then begin
        if self.displayIndex eq 9  then self.displayindex = 0
        if self.displayIndex eq 10 then self.displayindex = 0
        if self.displayIndex eq 11 then self.displayindex = 0
        if self.displayIndex eq 12 then self.displayindex = 0
    endif
endif else begin
    self.displayindex = 0
endelse

    thisMask = dindgen(self.detxDim*self.detyDim)

    ;self.ie IS SIMPLY THE ARRAY FROM WHICH THE
    ;DISPLAYED IMAGE IS DERIVED.  HOWEVER A
    ;NEW IMAGE VARIABLE SHOULD BE USED FOR EACH
    ;OF THE CASES BELOW.

    ;CREATE IMAGE BASED ON USER'S CHOICE OF IMAGE DISPLAY OPTION
    case self.displayIndex of
        0:  begin
                ;STANDARD PHASE[0] IMAGE
                ;help,*self.ie
;                im = reform(*self.ie,self.detxDim,self.detyDim)
;                                ;REFORM 3-D ARRAY INTO
;                                            ;2-D ARRAY BASED ON DETECTOR
;                                            ;DIMENSIONS

                ;nphs = n_elements((*self.mye)[0,*,theLastIndex])



                thisIm = dindgen(self.detxDim*self.detyDim)

;WHY WAS THIS USING theLastIndex???????????
;                thisIm = total((*self.mye)[*,0:ref->term()-1,theLastIndex],2)

;TRY THIS:   total will return a 2d array here.



if obj_valid(ref) gt 0 then begin
;print,'obj_valid(ref)=',obj_valid(ref)
            if ref->term() gt 1 then begin
                thisIm = total(double((*self.mye)[*,0:ref->term()-1,self.ftChoiceIndex]),2)
            endif else begin
                thisIm = double((*self.mye)[*,0,self.ftChoiceIndex])
            endelse


;help,thisim
endif else begin

    ;111605
    ;CREATE A TEMPORARY OBJECT FOR DISPLAY AND DESTROY BELOW BEFORE EXITING THE ROUTINE.
    ;

;110305

;;;;;;;;;;;;;;;;;;
;print,'MEMORY LEAK HERE???'
;print,self.datacontainer->count()
;;;;;;;;;;;;;;;;;
    ref = obj_new('ooecho',/blank)
;    help,ref
endelse





;WHY WASN'T IT THIS ALL ALONG????????????????
;WAS THIS A MISTAKE????

;110205
;THE NEXT BLOCK WAS REPLACED WITH THE ONE LINE COMMAND ABOVE
;                thisIm = double((*self.mye)[*,0,theLastIndex])
;                for i=0,self.detxDim*self.detyDim-1 do begin
;                    ;090204
;                    ;WHAT IS THE SIGNIFICANCE OF THIS SUMMATION
;                    ;AND WHY IS IT S(Q,0)?????
;                    thisIm[i] = total((*self.mye)[i,*,theLastIndex])
;                endfor;i

                im = reform(thisIm[*,*],self.detxDim,self.detyDim)
                imeb = sqrt(reform(thisIm[*,*],self.detxDim,self.detyDim))

            end
        1:  begin
                ;AVERAGE FIT PARAMETER IMAGE SELECTED
                im3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[0,*,self.ftChoiceIndex])
                imeb3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[6,*,self.ftChoiceIndex])
                im = reform(*im3d,self.detxDim,self.detyDim)
                imeb = reform(*imeb3d,self.detxDim,self.detyDim)
                if ptr_valid(im3d) gt 0 then ptr_free,im3d
                if ptr_valid(imeb3d) gt 0 then ptr_free,imeb3d
            end
        2:  begin
                ;AMPLITUDE FIT PARAMETER IMAGE SELECTED
                im3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[1,*,self.ftChoiceIndex])
                imeb3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[7,*,self.ftChoiceIndex])
                im = reform(*im3d,self.detxDim,self.detyDim)
                imeb = reform(*imeb3d,self.detxDim,self.detyDim)
                if ptr_valid(im3d) gt 0 then ptr_free,im3d
                if ptr_valid(imeb3d) gt 0 then ptr_free,imeb3d
            end
        3:  begin
                ;PHASE FIT PARAMETER IMAGE SELECTED
                ;(NOTE: DUE TO AN EARLIER MISUNDERSTANDING, THIS PARAMETER
                ;IS REFERRED TO AS 'PHASEO' ELSEWHERE IN THE CODE )
                im3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[2,*,self.ftChoiceIndex])
                imeb3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[8,*,self.ftChoiceIndex])
                im = reform(*im3d,self.detxDim,self.detyDim)
                imeb = reform(*imeb3d,self.detxDim,self.detyDim)
                if ptr_valid(im3d) gt 0 then ptr_free,im3d
                if ptr_valid(imeb3d) gt 0 then ptr_free,imeb3d
            end
        4:  begin
                ;SIGMA OR GAUSSIAN WIDTH FIT PARAMETER IMAGE SELECTED
                im3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[3,*,self.ftChoiceIndex])
                imeb3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[9,*,self.ftChoiceIndex])
                im = reform(*im3d,self.detxDim,self.detyDim)
                imeb = reform(*imeb3d,self.detxDim,self.detyDim)
                if ptr_valid(im3d) gt 0 then ptr_free,im3d
                if ptr_valid(imeb3d) gt 0 then ptr_free,imeb3d
            end
        5:  begin
                ;OMEGA OR COSINE FREQUENCY FIT PARAMETER IMAGE SELECTED
                im3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[4,*,self.ftChoiceIndex])
                imeb3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[10,*,self.ftChoiceIndex])

                ;CONVERT FROM OMEGA TO PERIOD.
;                im = reform(*im3d,self.detxDim,self.detyDim)
;                imeb = reform(*imeb3d,self.detxDim,self.detyDim)
                im = 360.0/reform(*im3d,self.detxDim,self.detyDim)
                imeb = (360.0/reform(*im3d,self.detxDim,self.detyDim))* $
                            reform(*imeb3d,self.detxDim,self.detyDim)/ $
                                reform(*im3d,self.detxDim,self.detyDim)
                if ptr_valid(im3d) gt 0 then ptr_free,im3d
                if ptr_valid(imeb3d) gt 0 then ptr_free,imeb3d
            end
        6:  begin
                ;PHASE OFFSET FIT PARAMETER IMAGE SELECTED
                ;(THIS IS REFERRED TO AS THE PHASE IN THE CODE,
                ;BUT IT IS REALLY THE PHASE OFFSET.)
                im3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[5,*,self.ftChoiceIndex])
                imeb3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'fitparms')))[11,*,self.ftChoiceIndex])
                im = reform(*im3d,self.detxDim,self.detyDim)
                imeb = reform(*imeb3d,self.detxDim,self.detyDim)
                if ptr_valid(im3d) gt 0 then ptr_free,im3d
                if ptr_valid(imeb3d) gt 0 then ptr_free,imeb3d
            end
        7:  begin   ;CHISQ
                im3d = ptr_new($
                    (*((ref)->getProperty(tag=$
                            'chisq')))[*,self.ftChoiceIndex])
                imeb3d = ptr_new($
                    (*((self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag=$
                            'chisq')))[*,self.ftChoiceIndex])
                im = reform(*im3d,self.detxDim,self.detyDim)
                imeb = reform(*imeb3d,self.detxDim,self.detyDim)
                if ptr_valid(im3d) gt 0 then ptr_free,im3d
                if ptr_valid(imeb3d) gt 0 then ptr_free,imeb3d

            end
        8:  begin   ;SIGNAL --- 060605
                ;AMPLITUDE/(Idown-Iup) IMAGE SELECTED

                amp = (*((ref)->getProperty(tag='fitparms')))[1,*,self.ftChoiceIndex]
                samp = (*((ref)->getProperty(tag='fitparms')))[7,*,self.ftChoiceIndex]
                iup = (*((ref)->getProperty(tag='Iup')))[*,self.ftChoiceIndex]
                siup = (*((ref)->getProperty(tag='sIup')))[*,self.ftChoiceIndex]
                idown = (*((ref)->getProperty(tag='Idown')))[*,self.ftChoiceIndex]
                sidown = (*((ref)->getProperty(tag='sIdown')))[*,self.ftChoiceIndex]

                sig = 2.0*amp/(Idown-Iup)

                dsig = 2.0*sqrt((samp/(Idown-Iup))^(2.0d) + $
                                (amp*sIdown/(Idown-Iup)^(2.0d))^(2.0d) + $
                                (amp*sIup/(Idown-Iup)^(2.0d))^(2.0d))


                im3d = ptr_new(sig)
                imeb3d = ptr_new(dsig)

                im = reform(*im3d,self.detxDim,self.detyDim)
                imeb = reform(*imeb3d,self.detxDim,self.detyDim)

                if ptr_valid(im3d) gt 0 then ptr_free,im3d
                if ptr_valid(imeb3d) gt 0 then ptr_free,imeb3d

            end


;112205
;SET MAGNETIC IMAGES FROM A SUB-MENU OF IMAGE OPTIONS HERE
        9:  begin
                ;magnetic image
                dum=ref->F_PolAnalysisGeneral(0,image=image,eimage=eimage,$
                                            xvals=xvals,plotdata=plotdata,$
                                            theimageindex = 0)
                im = image
                imeb = eimage
            end;9
        10: begin
                ;magnetic image
                dum=ref->F_PolAnalysisGeneral(0,image=image,eimage=eimage,$
                                            xvals=xvals,plotdata=plotdata,$
                                            theimageindex = 1)
                im = image
                imeb = eimage
            end;10
        11: begin
                ;magnetic image
                dum=ref->F_PolAnalysisGeneral(0,image=image,eimage=eimage,$
                                            xvals=xvals,plotdata=plotdata,$
                                            theimageindex = 2)
                im = image
                imeb = eimage
            end;11
        12: begin
                ;magnetic image
                dum=ref->F_PolAnalysisGeneral(0,image=image,eimage=eimage,$
                                            xvals=xvals,plotdata=plotdata,$
                                            theimageindex = 3)
                im = image
                imeb = eimage
            end;12

        else: begin
                ;NO IMAGE SELECTED, SO JUST SHOW PHASE(0)
                im = reform(*self.ie,self.detxDim,self.detyDim)
                imeb = sqrt(reform(*self.ie,self.detxDim,self.detyDim))
             end
        endcase



        ;I DO NOT UNDERSTAND HOW THIS ARRAY CAN BE A 1024
        ;ELEMENT 1D ARRAY!!!!!!
        ;
        ;HOWEVER, I HAVE TO WORK WITH IT AS IS AND WORK
        ;OUT THAT BUG LATER!!!!!!
;        theMask =reform((*((self.dataContainer->get(position=$
;                        self.QChoiceIndex))->getProperty(tag=$
;                            'mask2d')))[*,*,self.ftChoiceIndex],$
;                                self.detXdim,self.detYdim)

        if self.datacontainer->count() gt 0 then begin
            thisref = (ref)

;;;;;
;            print,'June 17, 2005'
;            refxdim = ref->getproperty(tag='x_dim')
;            refydim = ref->getproperty(tag='y_dim')
;            if refxdim ne self.detxdim then begin
;                theMask =reform((*(thisref->getProperty(tag=$
;                                'mask2d')))[*,self.ftChoiceIndex],$
;                                        refXdim,refYdim)
;
;            endif else begin
;;;;;


                theMask =reform((*(thisref->getProperty(tag=$
                                'mask2d')))[*,self.ftChoiceIndex],$
                                        self.detXdim,self.detYdim)
;            endelse

        endif else begin
            ;111605
            ;CLEANING UP MEMORY LEAK IN CASE OBJECT WAS CREATED SIMPLY FOR DISPLAY PURPOSES WHEN
            ;NO OBJECT IS AVAILABLE
            if obj_valid(ref) gt 0 then obj_destroy,ref
            theMask = intarr(self.detXdim,self.detYdim)
        endelse



;092305
    imask = where(theMask lt 1)
    notmask = where(theMask eq 1)
    selfmask = where(theMask lt 0)

    if imask[0] eq -1 then begin
        ;011005
        ;SET MASKED POINTS TO IMAGE median VALUE SO THEIR
        ;VALUES DON'T AFFECT THE COLOR SCALE.
        medim = median(im)
        ;minim = min(im)
        medimeb = median(imeb)
        ;minimeb = min(imeb)

            im = im*theMask
            imeb = imeb*theMask
    endif else begin

        if notmask[0] ne -1 then begin
            medim = median(im[notmask])
            ;minim = min(im)
            medimeb = median(imeb[notmask])
        endif else begin
            medim = 1.0;median(im[notmask])
            ;minim = min(im)
            medimeb = 1.0;median(imeb[notmask])
        endelse

        ;092305
        if selfmask[0] eq -1 then begin
            im = im*theMask
            imeb = imeb*theMask
        endif else begin
            thetotalmask = theMask
            thetotalmask[selfmask] = 0
            im = im*thetotalMask
            imeb = imeb*thetotalMask
        endelse
    endelse
;        endelse

        isz = size(im)

;092305
if imask[0] ne -1 then begin
        im[imask] = medim
        imeb[imask] = medimeb

;print,max(im)

endif else begin

        for i=0,isz[1]-1 do begin
            for j=0,isz[2]-1 do begin
                if (theMask[i,j] eq 0 or theMask[i,j] eq -1) then begin
                    ;im[i,j] = minim;CHANGE THIS TO THE AVERAGE VALUE SO THAT
                                    ;IT DOESN'T AFFECT THE COLOR TABLE.
                    im[i,j] = medim

                    imeb[i,j] = medimeb ;THIS IS FOR VISUAL PURPOSES ONLY
                                        ;THE DATA RANGE FOR THE EB PLOTIMAGE
                                        ;MUST BE SET IN A PARAMETER SET
                endif

            endfor
        endfor
endelse
        ;RESET OBJECT'S IMAGE POINTER
        if ptr_valid(self.im) gt 0 then ptr_free,self.im
        self.im = ptr_new(double(im))
        if ptr_valid(self.imeb) gt 0 then ptr_free,self.imeb
        self.imeb = ptr_new(double(imeb))

end;setDisplayImage
pro ooDisplayEcho::updateFitvals,xindex,yindex,ftIndex,dontUpdateValues=dontUpdateValues,tavestate=tavestate
;
;NAME:
;        ooDisplayEcho::updateFitvals
;
;PURPOSE:
;           Update the values in the fit parameter widgets.
;PARAMETERS:
;           xindex      Current pixel location indices.
;           yindex
;           ftIndex     Current Fourier time index
;
;KEYWORDS:
;           dontUpdateValues    Flag to tell the method not to update the values in the text widgets.
;                               The purpose is to avoid the issue on the Mac of retrieving these
;                               values from the data object when a simple change of the fix state
;                               is made.

    ;;
    ;UPDATE TEXT WIDGETS WITH CURRENT FIT VALUES
    ;;;

    
;print,'ooDisplayEcho:::updateFitvals   TEST 1 2 3'
;print,*p
    if self.dataContainer->count() gt 0 then begin

        if n_elements(tavestate) eq 0 then widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= tavestate
        
        ;GET FIT VALUES FROM DATA OBJECT FOR THESE INDICES
        ref = (self.dataContainer->get(position=self.QChoiceIndex))
        fitvals = ref->fitvals(xindex,yindex,ftindex)


        chisqtemp =(*(ref->getProperty(tag='chisq')))$
                [((ref)->getProperty(tag='x_dim')*yindex+xindex),self.ftChoiceIndex]


        idown = ref->chirpIdown(xindex,yindex,ftindex,tavestate=tavestate)
        iup = ref->chirpIup(xindex,yindex,ftindex,tavestate=tavestate)

        if (idown-iup) ne 0.0 then begin
            ratiotemp = fitvals[1]/((idown-iup)/2.0)
        endif else begin
            ratiotemp = double('Nan')
        endelse


        ;INVERT THE OMEGA FITVALUES TO PERIOD FOR DISPLAY IN
        fitvals[10] = 360.0*fitvals[10]/fitvals[4]^2
        fitvals[4] = 360.0/fitvals[4]

        ;CREATE STRING ARRAY OF FIT VALUES
        sfitVals = strtrim(string(fitvals),2)
    endif else begin
        fitvals = dblarr(12)
        widget_control,self.atwwidth,get_value = swidth
        fitvals[3] = double(swidth);702.0
        widget_control,self.atwperiod,get_value = speriod
        fitvals[4] = double(speriod);360.0
        fitvals[6:11] = 0.0
        sfitVals = strtrim(string(fitvals),2)
        chisqtemp = double('Nan')
        ratiotemp = 1.0
    endelse

    ;PLACE FIT VALUE STRINGS INTO TEXT FIELDS

;033005
;REPLACE THE NEXT COMMAND
;    widget_control,self.tw1,set_value= strtrim(string(xindex),2)+$
;                                    ','+strtrim(string(yindex),2)
    widget_control,self.tw1,set_value = '[xindex,yindex]= ['    $
                                +strtrim(string(xindex),2)+','  $
                                +strtrim(string(yindex),2)+']'  $
                                +', Pixel value ='$
                                +strtrim(string((*self.im)[xindex,yindex]),2)$
                                +',chi^2 = '+strtrim(string(chisqtemp),2)
    widget_control,self.atwconst,set_value = sfitVals[0]
    widget_control,self.atwamp,set_value = sfitVals[1]
    widget_control,self.atwphaseo,set_value = sfitVals[2]
    widget_control,self.atwsigma,set_value = sfitVals[3]
    widget_control,self.atwomega,set_value = sfitVals[4]
    widget_control,self.atwphase,set_value = $
                        strtrim(string(fitVals[5]),2)
    widget_control,self.atwchisq,set_value=strtrim(string(chisqtemp),2)
    widget_control,self.atwratio,set_value=strtrim(string(ratiotemp),2)

    ;ERROR VALUES
    widget_control,self.atweconst,set_value = sfitVals[0+6]
    widget_control,self.atweamp,set_value = sfitVals[1+6]
    widget_control,self.atwephaseo,set_value = sfitVals[2+6]
    widget_control,self.atwesigma,set_value = sfitVals[3+6]
    widget_control,self.atweomega,set_value = sfitVals[4+6]
    widget_control,self.atwephase,set_value = $
                            strtrim(string(fitVals[5+6]),2)

    if (fitvals[0] eq 200.0) then begin
        ;WRITE MESSAGE TO USER IN CASE OF POOR STATISTICS
;        widget_control,self.tw1,set_value=  "PROBABLY NO FIT "$
;                                            +"DUE TO POOR STATISTICS!"
        widget_control,self.tw1,set_value=  "NO FIT AVAILABLE."
    endif

end;updateFitVals
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::realify,winpix,winvis
;
;NAME:
;        ooDisplayEcho::realify
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;COPY VIRTUAL IMAGE FROM self.drawImage OBJECT INTO
    ;REAL IMAGE DISPLAY WINDOW

    ;SET CURRENT WINDOW TO VISIBLE WINDOW PASSED FROM USER
    wset,winvis

    ;COPY IMAGE IN VIRTUAL WINDOW TO CURRENT WINDOW
    device,copy = [0,0,!d.x_size,!d.y_size,0,0,winpix]

end;realify
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;EVENT HANDLERS
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

pro ooDisplayEcho::updateIndices,x=x,y=y,t=t
;
;NAME:
;        ooDisplayEcho::updateIndices
;
;PURPOSE:
;       Update indices and unset self.plotzoombox if indices change
;PARAMETERS:
;
;KEYWORDS:
;       x   Indices
;       y
;       t
;_EXTRA - is used to pass keywords meant for the superclass.


    if n_elements(x) eq 0 then x = self.xindex
    if n_elements(y) eq 0 then y = self.yindex
    if n_elements(t) eq 0 then t = self.ftchoiceindex


    if x ne self.xindex or $
       y ne self.yindex or $
       t ne self.ftchoiceindex then begin
        self.plotzoombox = 0
        self.plotzoomswitch = 0
    endif

    self.xindex = x
    self.yindex = y
    self.ftChoiceIndex = t



end;updateIndices

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::keyboardUpdateIndices,event
;
;NAME:
;        ooDisplayEcho::keyboardUpdateIndices
;
;PURPOSE:
;           Update current pixel index selections based on keyboard events.
;PARAMETERS:
;           event   The keyboard event for selecting a pixel.
;KEYWORDS:
;           none

    ;SET INDICES PROPERLY ON KEYBOARD EVENTS


        ;L,R,U,D,pageup,pagedown,home,end
        ;5,6,7,8,9     ,10      ,11  ,12

        ;L: DECREMENT self.xindex by 1 --- CYCLICAL
        ;R: INCREMENT self.xindex by 1 --- CYCLICAL


    ;112304
    ;U,D MUST BE REVERSED IF THE IMAGE IS FLIPPED
    ;USING THE yrange OPTION TO PLOTIMAGE.
        ;U: DECREMENT self.yindex by 1 --- CYCLICAL
        ;D: INCREMENT self.yindex by 1 --- CYCLICAL
        ;pageup:    INCREMENT self.ftChoiceIndex
        ;pagedown:  DECREMENT self.ftChoiceIndex
        ;home:      SET self.ftChoiceIndex TO 0
        ;end:       SET self.ftChoiceIndex TO MAXIMUM VALUE





    ;GET CURRENT VALUES
    xindex = self.xindex
    yindex = self.yindex
    tindex = self.ftChoiceIndex
    case event.key of
    5:  begin   ;LEFT ARROW
        xindex = xindex - 1
        if xindex lt 0 then begin
            xindex = self.detxdim - 1
            yindex = yindex - 1
            if yindex lt 0 then begin
                yindex = self.detydim - 1
            endif
        endif
    end
    6:  begin   ;RIGHT ARROW
        xindex = xindex + 1
        if xindex ge self.detxdim then begin
            xindex = 0
            yindex = yindex + 1
            if yindex ge self.detydim then begin
                yindex = 0
            endif
        endif
    end
    7:  begin   ;UP ARROW
        yindex = yindex - 1
        ;NOTE THAT THE FOLLOWING CHECK WILL NEED REVERSAL IF IT THE IMAGE IS FLIPPED.
        if yindex lt 0 then begin
            yindex = self.detydim - 1
            xindex = xindex - 1
            if xindex lt 0 then begin
                xindex = self.detxdim - 1
            endif
        endif
    end
    8:  begin   ;DOWN ARROW
        yindex = yindex + 1
        ;NOTE THAT THE FOLLOWING CHECK WILL NEED REVERSAL IF IT THE IMAGE IS FLIPPED.
        if yindex ge self.detydim then begin
            yindex = 0
            xindex = xindex + 1
            if xindex ge self.detxdim then begin
                xindex = 0
            endif
        endif
    end
    9:  begin
        tindex = tindex + 1
        if tindex ge n_elements(*self.ftChoices) then begin
            tindex = n_elements(*self.ftChoices) - 1
        endif
    end
    10: begin
        tindex = tindex - 1
        if tindex lt 0 then begin
            tindex = 0
        endif
    end
    11: begin
        tindex = n_elements(*self.ftChoices) - 1
    end
    12: begin
        tindex = 0
    end
    else:begin
        self->do_nothing
    end
    endcase

    ;SET THE INDICES TO THE NEW VALUES
    self->updateIndices,x=xindex,y=yindex,t=tindex


end;keyboardUpdateIndices
pro ooDisplayEcho::keyboardEvents,event
;
;NAME:
;        ooDisplayEcho::keyboardEvents
;
;PURPOSE:
;           Handle keyboard events from the plot and image windows.
;PARAMETERS:
;           event   The event structure to be handled.
;KEYWORDS:
;           none


    ;THIS METHOD IS MEANT TO HANDLE KEYBOARD EVENTS
    ;FROM THE IMAGE.  THIS WILL ALLOW THE USER TO
    ;ARROW OR PAGE THROUGH THE PIXELS OF THE DETECTOR.

;cursor,xcurs,ycurs,/nowait,/data
;print,xcurs,ycurs

;120105
;GET OBJ.ID TO DISTINGUISH WINDOWS.
;THIS DOES NOT SEEM TO BREAK ANYTHING BY ADDING THIS STATEMENT
    widget_control,event.id,get_uvalue=obj
    ;print,'ooDisplayEcho::keyboardEvents obj.id='+obj.id
    if event.press eq 1 then begin ;ONLY RESPOND TO PRESS
;            print,tag_names(event)
;            print,event
        ;USE THE 'm' OR 'M' KEYS TO ALTER THE MASK.
        if event.ch eq 109 or event.ch eq 77 then begin
            ;print,'MASK THIS POINT'
            ix=self.xindex
            iy=self.yindex
            it=self.ftChoiceIndex

            ref = self.datacontainer->get(position=self.qchoiceindex)
            mcurr = (*(ref->getproperty(tag='mask2d')))[ix+self.detxdim*iy,it]
            if mcurr eq 1 then begin
;033005
;CONVERT USER MASKED PIXELS TO -1
                mnew = -1;0
            endif else mnew = 1
            (*(ref->getproperty(tag='mask2d')))[ix+self.detxdim*iy,it] = mnew
        endif else begin

            if event.ch ne 0 then begin ;(event.ch eq 13 --> return key.)
                ;if self.displayindex eq 3 then begin
                    ;refit with selected phase to start.

            ;DISPLAY CONTEXT MENU ON A KEYBOARD KEY PRESS.

                        ;DISPLAY CONTEXT MENU
                        maskContextBase = WIDGET_INFO(event.ID, FIND_BY_UNAME = 'MASKCONTEXTBASE')
                        plotContextBase = WIDGET_INFO(event.ID, FIND_BY_UNAME = 'PLOTCONTEXTBASE')

                        if widget_info(maskContextBase,/valid_id) then begin
                            WIDGET_DISPLAYCONTEXTMENU, event.ID, event.X, event.Y, maskContextBase
                        endif else begin
                            WIDGET_DISPLAYCONTEXTMENU, event.ID, event.X, event.Y, plotContextBase
                        endelse

            endif else begin
                ;print,tag_names(event)
                ;print,event

                self->keyboardUpdateIndices,event

            endelse
        endelse;m or M pressed
        self->mouseHead,event

    endif;press eq 1
end;keyboardEvents
pro ooDisplayEcho::mouseGuts,myxindex = myxindex,myyindex = myyindex,$
                                    fitparms = fitparms
;
;NAME:
;        ooDisplayEcho::mouseGuts
;
;PURPOSE:
;           Routine to call each of the expected routines
;           following mouse events.
;PARAMETERS:
;           none
;KEYWORDS:
;           myxindex    The current x,y indices
;           myyindex
;           fitparms    fitparms appears to be unused.


;    print,'ooDisplayEcho::mouseGuts'

    ;THIS METHOD IS MEANT TO ENCAPSULATE THE FUNCTIONALITY
    ;OF THE ooDisplayEcho::mouseEvents EVENT HANDLER.
    ;
    ;THE PURPOSE OF THIS IS THAT THIS FUNCTIONALITY
    ;IS DESIRED IN OTHER CLASS METHODS.
    ;

    ;COPY INDEX ARGUMENTS TO PREIOUSLY NAMED INDICES
    xindex = myxindex
    yindex = myyindex
    ;GET FOURIER TIME INDEX FROM THE CLASS
    ftindex = self.ftChoiceIndex

    self->draw,xindex=xindex,yindex=yindex,tauindex=ftindex

    self->updateFitvals,xindex,yindex,ftindex

    ;050504
    self->updateMaskmaker

end;mouseGuts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::mouseHead,event,t=t
;
;NAME:
;        ooDisplayEcho::mouseHead
;
;PURPOSE:
;           Produces functionality for mouse, widget_draw, widget_button
;           and widget_tree_sel events.  Called following file tree selection.
;
;PARAMETERS:
;           event   The event structure passed here.
;KEYWORDS:
;           t       The currently selected Fourier time.



    ;FUNCTIONALITY COMMON TO ALL MOUSE EVENTS

;102804
;IS IT NECESSARY TO CALCULATE THE MOUSE POSITION
;HERE OR WILL THAT HAVE ALWAYS BEEN DONE BY THE CALLING
;METHOD???

;TRY COMMENTING OUT THE NEXT TWO LINES AND ADD THE FOLLOWING TWO LINES
;        indTemp = self->getPositionOnImage(event)
;
;        xindex = indTemp[0] & yindex = indTemp[1]

;120504
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TRY TO RUN THIS CODE BLOCK BEFOR THE REST OF THE METHOD.
;THE ORDER SHOULD NOT MATTER.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;EVENT TYPES THAT GET HERE:
        ;widget_draw
        ;widget_button
        ;widget_tree_sel
;120504
    etype = tag_names(event,/structure_name)

;print,'ooDisplayEcho::mouseHead'
;print,'etype=',etype

    if etype eq 'WIDGET_BUTTON' or etype eq 'WIDGET_DRAW' then begin
        if etype ne 'WIDGET_DRAW' then begin

            ;TIME AVERAGE CHECK SHOULD NOT BE NECESSARY ON DRAW EVENTS SINCE THE STATE
            ;SHOULD NOT BE CHANGEABLE THERE.
            checktime_aveflag = 1
            checkdeepmaskflag = 1

            ;CHECK OTHER WIDGETS, esp ftime widgets
            timestepbuttons = [self.REWBUTTONTAU,self.REVBUTTONTAU,$
                               self.FWDBUTTONTAU,self.FFWDBUTTONTAU]

            wh_timebutton = where(timestepbuttons eq event.id,wh_count)

            if wh_count ne 0 then begin
                checktime_aveflag = 0
                checkdeepmaskflag = 0
            endif

        endif else begin
            checktime_aveflag=0
            checkdeepmaskflag = 0

        endelse



        self->redefinewidgets,self.QChoiceIndex,t=self.ftChoiceIndex,checktime_aveflag=checktime_aveflag,$
                                                checkdeepmaskflag=checkdeepmaskflag
        ftindex = self.ftChoiceIndex


    endif else begin

        checktime_aveflag = 1
        checkdeepmaskflag = 1
        if event.id eq self.adwtau then checktime_aveflag = 0

        self->redefinewidgets,self.QChoiceIndex,/newsize,t=t,checktime_aveflag=checktime_aveflag,$
                                                checkdeepmaskflag=checkdeepmaskflag
        if n_elements(t) eq 0 then begin
            ftindex = 0
        endif else begin
            ftindex = t
        endelse

    endelse

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


    xindex = self.xindex    ;SET IN ooDisplayEcho::redefinewidgets
    yindex = self.yindex    ;SET IN ooDisplayEcho::redefinewidgets

    ;PLOT DATA IN WINDOW
    self->draw,xindex=xindex,yindex=yindex,tauindex=ftindex

    self->updateFitvals,xindex,yindex,ftindex
    self->updateMaskmaker

    ;SET TEXT WIDGET TO DISPLAY CURRENT POSITION IN PLOT
    chisqtemp =(*((self.dataContainer->get(position=self.QChoiceIndex))->getProperty(tag='chisq')))$
    [((self.dataContainer->get(position=self.QChoiceIndex))->getProperty(tag='x_dim')*yindex+xindex),$
        self.ftChoiceIndex]
    widget_control,self.tw1,set_value = '[xindex,yindex]= ['    $
                                +strtrim(string(xindex),2)+','  $
                                +strtrim(string(yindex),2)+']'  $
                                +', Pixel value ='$
                                +strtrim(string((*self.im)[xindex,yindex]),2)$
                                +',chi^2 = '+strtrim(string(chisqtemp),2)




;040605
;SETS EDITABILITY ON SELCTION OF OBJECT
    thetype = (self.dataContainer->get(position=self.QChoiceIndex))->getProperty(tag='type')
    ;print,'thetype=',thetype
    ;help,thetype
    transeditable = 0
    volfraceditable = 0
    case thetype of
    0:begin
        transeditable = 1
        volfraceditable = 1
    end
    1:begin;res
        transeditable = 0
        volfraceditable = 0
    end
    2:begin;dat
        transeditable = 1
        volfraceditable = 1
    end
    3:begin;cell
        transeditable = 1
        volfraceditable = 0
    end
    else:begin
        transeditable = 1
        volfraceditable = 1
    end
    endcase
    widget_control,self.atwtrans,editable = transeditable
    widget_control,self.atwvolfrac,editable = volfracseditable






;    ;EVENT TYPES THAT GET HERE:
;        ;widget_draw
;        ;widget_button
;        ;widget_tree_sel
;    etype = tag_names(event,/structure_name)
;    print,etype
;
;    if etype eq 'WIDGET_BUTTON' or etype eq 'WIDGET_DRAW' then begin
;        self->redefinewidgets,self.QChoiceIndex,t=self.ftChoiceIndex
;    endif else begin
;        self->redefinewidgets,self.QChoiceIndex,/newsize
;    endelse
end;mouseHead
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::mouseEvents,event
;
;NAME:
;        ooDisplayEcho::mouseEvents
;
;PURPOSE:
;           Handle mouse events and dispatch to the proper function.
;PARAMETERS:
;           event   The event to handle.
;KEYWORDS:
;           none.

;print,'ooDisplayEcho::mouseEvents'
;t0 = systime(1,/seconds)
;print,'_____________________'
;print,systime(1,/seconds)-t0
;print,tag_names(event)
;print,'event.type=',event.type
;print,'event.clicks=',event.clicks
;print,'event.press=',event.press
;print,systime(1,/seconds)-t0
    ;;
    ;THIS METHOD IS DESIGNED TO HANDLE EVENTS FROM THE MOUSE.
    ;;;

    if (event.type eq 0) then begin ;REACTION ON A PRESS

;        print,'NEW MOUSE PRESS EVENT'
        ;SET CLASS PIXEL INDEX VALUES BASED ON THE MOUSE EVENT
        ;THIS MUST BE DONE HERE.  01/30/04
        indTemp = self->getPositionOnImage(event)


        xindex = indTemp[0] & yindex = indTemp[1]

;102804
    ;ALWAYS SET IMAGE TO IGNORE MOUSE MOTIONS.
    self.mouseMotionBlock = 1


;021706
;        self.xindex = xindex
;        self.yindex = yindex
        self->updateIndices,x=xindex,y=yindex

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;
        ;GET I v. PHASE ARRAY AT SELECTED PIXEL
        ;;;

        ;GET THE FOURIER TIME INDEX
        ftindex = self.ftChoiceIndex

        ;GET THE PHASES (xvals) FOR THAT FOURIER TIME
        xvals=(self.dataContainer->get(position=self.QChoiceIndex))->chirpPhases(ftIndex)

        ;;
        ;USE emask FOR DISPLAY
        ;;;

        self->mouseHead,event

    endif;event.type eq 0
    if ((event.type eq 2) and (self.mouseMotionBlock ne 1)) then begin
        ;HANDLE MOUSE _MOTION_ EVENTS
        ;THIS ALLOWS USER TO SEE EXACTLY WHERE MOUSE IS IN IMAGE
        ;BEFORE CLICKING.

        ;GET MOUSE POSITION IN IMAGE
        indTemp = self->getPositionOnImage(event)

        ;SET INDEX VALUES
        xindex = indTemp[0]
        yindex = indTemp[1]


        self->boxPixel,xindex,yindex
        self->mouseHead,event

    endif;event.type eq 2 ;I.E. MOUSE MOTION

end;mouseEvents
pro ooDisplayEcho::boxPixel,xindex,yindex
;
;NAME:
;        ooDisplayEcho::boxPixel
;
;PURPOSE:
;           Draw a box around the currently selected pixel in the image.
;PARAMETERS:
;           xindex      The currently selected pixel indices.
;           yindex
;KEYWORDS:
;           none.

    ;DRAW A BOX AROUND THE PIXEL AT THE CURRENT MOUSE POSITION
    ;ON IMAGE.

        ;DRAW IMAGE TO ITS PIXMAP
        self->imageVirtual


        device,get_decomposed = dc
        device,decomposed=1

        thisBox = [[xindex,yindex],$
                   [xindex+1,yindex],$
                   [xindex+1,yindex+1],$
                   [xindex,yindex+1],$
                   [xindex,yindex]]

        purple = 255L + 256L*(0L + 256L*255L)
        yellow = 0L + 256L*(255L + 256L*255L)

        ;SET WINDOW DATA AXIS POINTERS
        !x = *self.w1xptr
        !y = *self.w1yptr
        plots,thisBox,thick=4,/data,color=yellow
        device,decomposed=dc

        ;COPY VIRTUAL IMAGE FROM PIXMAP TO REAL WINDOW
        self->realify,self.dw1pix,self.dw1id

end;boxPixel
function ooDisplayEcho::getPositionOnImage,event
;
;NAME:
;        ooDisplayEcho::getPositionOnImage
;
;PURPOSE:
;           Determine the pixel on the image where a mouse event occurred.
;PARAMETERS:
;           event   The event structure.
;KEYWORDS:
;           none
;RETURN VALUE:
;           [xindex,yindex]     The 2 elements index array.
;
    wset,self.dw1id

    ;SET WINDOW DATA AXIS POINTERS
    !x = *self.w1xptr
    !y = *self.w1yptr

    ;CONVERT MOUSE EVENT COORDINATES TO DATA COORDINATES
    dcoords = convert_coord(event.x,event.y,/device,/to_data)

    ;SET IMAGE PIXEL INDICES FROM THE DATA COORDINATES
    xindex = fix(dcoords[0]) & yindex = fix(dcoords[1])

    ;ENSURE THAT THE IMAGE PIXEL INDICES ARE IN THE
    ;RANGE OF THE IMAGE DIMENSIONS
    if (xindex ge self.detxDim) then $
                xindex = self.detxDim-1
    if (xindex le 0) then xindex = 0
    if (yindex ge self.detyDim) then $
                    yindex = self.detyDim-1
    if (yindex le 0) then yindex = 0

    ;021706
    ;self.xindex = xindex & self.yindex = yindex
    self->updateIndices,x=xindex,y=yindex


    return,[xindex,yindex]

end;getPositionOnImage
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ooDisplayEcho::getPositionOnPlot,event
;
;NAME:
;        ooDisplayEcho::getPositionOnPlot
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

;RETURN VALUE:
;

    ;SET WINDOW DATA AXIS POINTERS
    !x = *self.w2xptr
    !y = *self.w2yptr

    ;CONVERT MOUSE EVENT COORDINATES TO DATA COORDINATES
    dcoords = convert_coord(event.x,event.y,/device,/to_data)

    ;print,'mousex,mousey = ',dcoords
    return,dcoords[0:1]

end;getPositionOnPlot
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ooDisplayEcho::getFixed
;
;NAME:
;        ooDisplayEcho::getFixed
;
;PURPOSE:
;           Determine the current states of all of the droplist
;           widgets for fixing/varying of fit parameters.
;PARAMETERS:
;           none
;KEYWORDS:
;           none
;RETURN VALUE:
;           fixed   The 6 element array of 1/0 for each fit parameter.

;GET CURRENT VALUES OF THE FIXED/VARY DROPLIST WIDGETS
    fixed = intarr(6)

    ;GET LIST OF STRINGS
    widget_control,self.dropfixconst,get_value=vals
    ip = intarr(6)

    ip[0] = widget_info(self.dropfixconst,/droplist_select)
    ip[1] = widget_info(self.dropfixamp,/droplist_select)
    ip[2] = widget_info(self.dropfixphaseo,/droplist_select)
    ip[3] = widget_info(self.dropfixsigma,/droplist_select)
    ip[4] = widget_info(self.dropfixomega,/droplist_select)
    ip[5] = widget_info(self.dropfixphase,/droplist_select)


    ;THIS APPEARS TO HANDLE PROPERLY ALL OF THE fixed CASES.
    for i=0,n_elements(ip)-1 do begin
;        if stregex(vals[ip[i]],'vary',/fold_case,/boolean) then begin
        if stregex(vals[ip[i]],'v',/fold_case,/boolean) then begin
            fixed[i] = 0
        endif else begin

            ;021306
            ;THIS MUST BE EXPANDED TO HANDLE THE CASES OF FIXING
            ;FOR PIXEL (1), TIME (2), ALL T (3)

            fixed[i] = 1
        endelse
    endfor;i

    return,fixed
end;getFixed
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::fitButtonHandler,event
;
;NAME:
;        ooDisplayEcho::fitButtonHandler
;
;PURPOSE:
;           Handle button events from fit buttons.
;PARAMETERS:
;           event   The button event structure.
;KEYWORDS:
;           none

    widget_control,event.id,get_uvalue=obj
    widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value=tavestate
    ;print,event.fit

    ;NOTE 'or$' IS NOT 'or $' !!!!!
        self->setPixelIndices

        ref = self.dataContainer->get(position=self.QChoiceIndex)
        ref->storeFitparms
        ref_tavestate = tavestate;ref->report_timeaverage_state()

        fitVals = $
        (*((self.dataContainer->get(position= $
                                    self.QChoiceIndex))->getProperty(tag='fitparms')))[*,$
                                    self.xindex+self.yindex*self.detxdim,$
                                    self.ftchoiceindex]




        widget_control,self.atwconst,get_value=sconstStart
        constStart = double(sconstStart)
        widget_control,self.atwamp,get_value=sampStart
        ampStart = double(sampStart)
        widget_control,self.atwphaseo,get_value=sphaseoStart
        phaseoStart = double(sphaseoStart)
        widget_control,self.atwsigma,get_value=ssigmaStart
        sigmaStart = double(ssigmaStart)

;120904
;CONVERT PERIOD VALUE TO OMEGA
        widget_control,self.atwomega,get_value=somegaStart
        omegaStart = 360.0/double(somegaStart)

        widget_control,self.atwphase,get_value=sphaseStart
        phaseStart = double(sphaseStart)


        startparms =   [constStart,ampStart,phaseoStart,$
                        sigmaStart,omegaStart,phaseStart]



;10/19/04
;
;NOTE:  THE WRONG fitAll's HAVE BEEN CALLED HERE!!!!!
;       THIS MAY EXPLAIN ALL OF THE DIFFICULTY IN FITTING PROGRESS!!!!!
;
;   REPLACE fitAll's WITH arcFit.  IT SEEMS TO BE MORE ROBUST,
;   EVEN BEFORE MANY CHECKS HAVE BEEN IMPLEMENTED.
;
        case obj.id of
        'FITBUTTON1': begin
                        widget_control,self.tw1,$
                            set_value="FITBUTTON1 EVENT OCCURRED"
                        ref = (self.dataContainer->get(position= $
                                  self.QChoiceIndex))
                        ;ref_tavestate = ref->report_timeaverage_state()

                        ;SET THIS PIXEL'S FIXED VALUE
                        fixed = self->getFixed()
;                        (*(ref->getProperty(tag= $
;                                'fixed')))[*,self.xindex+self.yindex*self.detxdim,$
;                                self.ftchoiceindex] = fixed
;
                        ref->setFixed,fixed,x=self.xindex,y=self.yindex,t=self.ftChoiceIndex

                        result = $
                            ref->chirpFit( self.xindex,$
                                            self.yindex,$
                                            self.ftchoiceindex,$
                                            fixed=fixed,$
                                            startparms=startparms,$
                                            tavestate=ref_tavestate)
                       end
        'FITBUTTON': begin
                        ref = (self.dataContainer->get(position= $
                                  self.QChoiceIndex))
                        ref_tavestate = ref->report_timeaverage_state()

                        ;SET THIS PIXEL'S FIXED VALUE
                        fixed = self->getFixed()
                        for i=0,self.detxdim-1 do begin
                            for j=0,self.detydim-1 do begin
                                ref->setFixed,fixed,x=i,y=j,t=self.ftChoiceIndex
;
;                                (*(ref->getProperty(tag= $
;                                        'fixed')))[*,i+j*self.detxdim,$
;                                        self.ftchoiceindex] = fixed
                            endfor;j
                        endfor;i

                        ref->fitall,$
                            tauind = self.ftchoiceindex,$
                            fixed=fixed,$
                            startparms=startparms,obj=self,$
                            tavestate=ref_tavestate
                        end

        'FITBUTTONALL': begin


;NEED TO INCORPORATE THE OPTIONS PASSED BY cwo_pickmethod
;
;i.e    I NEED TO HAVE ALL METHODS, INCLUDING THE SPIRAL METHOD
;     AVAILABLE HERE AND CHOOSE BASED ON THE USER SELECTED METHOD.



    ;IF THE EVENT COMES FROM THE SELECTOR THEN ONLY FIT IF event.fit ne 0
    ;OTHERWISE ALWAYS FIT

            ;GET FIXED/VARY VALUES FROM GUI AND SET data.fixed TO
            ;THE APPROPRIATE VALUES.
                    ref = (self.dataContainer->get(position=self.QChoiceIndex))
                    ref_tavestate = ref->report_timeaverage_state()

                    fixed = self->getFixed()
                    self.fixed=fixed


                        ;032906
                        ;CHECK THE "FIXED" POSITION OF THE PHASE PARAMETER.
                        ;IF THE FIXED POSITION IS "FIX ALL PIXEL ALL T" THEN
                        ;USE THE noborrow OPTION SO THAT THE PHASES ARE NOT
                        ;BORROWED, AND THUS CHANGED, FORM ONE TIME TO THE NEXT.



;                        print,widget_info(self.dropfixphaseo,/valid_id)
;                        widget_control,self.dropfixphaseo,get_value=fixvalue
;                        print,fixvalue
;
                    phasefixindex = widget_info(self.dropfixphaseo,/droplist_select);nse_comboindex(self.dropfixphaseo)
;                        print,'phasefixindex=',phasefixindex
                    if phasefixindex eq 7 then noborrow = 1
                    if phasefixindex eq 8 then noborrow = 1



;110304
;
;THESE NEXT OPERATIONS SHOULD TAKE PLACE IN THE DATA OBJECT fitall ROUTINES!!!
                        ;CHECK GAUSSIAN WIDTH
                    if fixed[3] eq 1 then begin
                        widget_control,self.atwsigma,get_value=ssigma
                        ;dum=dialog_message('oodisplayecho::fitbuttonhandler ssigma='+ssigma)
                        sigma = double(ssigma)
;                            (*(ref->getProperty(tag= $
;                                    'fitparms')))[3,*,*] = double(ssigma)
                    endif
;
;                        for k=0,5 do begin
;                            (*(ref->getProperty(tag= $
;                                    'fixed')))[k,*,*] = fixed[k]
;                        endfor;k

                    if tag_names(event,/structure_name) eq 'CWO_PICKMETHOD_EVENT' then begin

                        ;NEED CASE STATEMENT HERE TO SELECT FITTING
                        ;OPTION.
                        if event.fit ne 0 then begin
                             case event.option of
                             'arc':begin
                                     ref->arcFit,fixed=fixed,sigma=sigma,noborrow=noborrow,tavestate=ref_tavestate
                             end;arc
                             'expand':begin
                                    ;dum=dialog_message('THIS IS SLOWER THAN AND TYPICALLY NOT AS GOOD AS "arc"')
                                    ref->fitall3,$
                                            1,$ ;chiswitch
                                            fixed=self.fixed,$
                                            sigma=sigma,$
                                            startparms=startparms,$
                                            obj=self,$
                                            noborrow=noborrow,tavestate=ref_tavestate
                             end;expand
                             'spiral':begin
                                    ref->spiralfit,noborrow=noborrow,tavestate=ref_tavestate
                                             ;,$
;                                            1,$ ;chiswitch
;                                            fixed=self.fixed,$
;                                            sigma=sigma,$
;                                            startparms=startparms,$
;                                            obj=self
                             end;spiral
                             else: begin
                                    ref->arcFit,fixed=fixed,sigma=sigma,noborrow=noborrow,tavestate=ref_tavestate
                             end;else
                             endcase

                        endif
                    endif else begin

                             thisref=(self.dataContainer->get(position=self.QChoiceIndex))
                             thisref_tavestate = thisref->report_timeaverage_state()
                             thisref->arcFit,tavestate=thisref_tavestate
                    endelse

                    self->redefineTree
                end
        'FITBUTTONALLPLUS360': begin

                            ;121404
                            ;NOW DO FIT BASED ON CHOSEN FIT METHOD
                            self->shiftfit,fixed = fixed, sigma = sigma,$
                                            /plus360, obj=self,tavestate=ref_tavestate

                            self->redefineTree
                        end
        'FITBUTTONALLMINUS360': begin
;                            ;SHIFT ALL PHASES BY -360 AND REFIT
;                            (self.dataContainer->get(position=$
;                                    self.QChoiceIndex))->lower360

                            ;121404
                            ;NOW DO FIT BASED ON CHOSEN FIT METHOD
                            self->shiftfit,fixed = fixed, sigma = sigma,$
                                            /minus360, obj=self,tavestate=ref_tavestate


                            self->redefineTree
                        end
        'FITBUTTONALLQ': begin
                            currentQ = self.QChoiceIndex
                            nQ = self.dataContainer->count()
                            self->swapDataObject,currentQ,0

                            thisref = (self.dataContainer->get(position=self.QChoiceIndex))
                            thisref_tavestate = thisref->report_timeaverage_state()

                            thisref->fitall,$
                                    fixed=self.fixed,$
                                    startparms=startparms,obj=self,tavestate=thisref_tavestate

                            for i=1,nQ-1 do begin
                                self->swapDataObject,i-1,i
                                thisref=(self.dataContainer->get(position=self.QChoiceIndex))
                                thisref->fitall,$
                                    fixed=self.fixed,$
                                    startparms=startparms,obj=self,tavestate=thisref_tavestate
                                    
                            endfor;i
                            self->swapDataObject,nQ-1,currentQ
                            self->setDataParameters,$
                                (self.dataContainer->get(position=self.QChoiceIndex)),$
                                n=self.QChoiceIndex
                            self->reDefineWidgets,self.QChoiceIndex
                            ;widget_control,self.ftree,/destroy
                            self->redefineTree

                        end
        else: begin
                widget_control,self.tw1,$
                    set_value='UNKNOWN BUTTON: '+obj.id+':'+tag_names(event)

                end
        endcase


;031506
;DRAW IS HANDLED IN self->mouseGuts CALLED BELOW.

        ;NEXT OVERLAY NEW PLOT AND SET VALUES IN
        ;FIT PARAMETERS MATRIX
;        self->draw

        if (n_elements(result) le 1) then begin;result = fitVals
            fitVals = $
                (*((self.dataContainer->get(position=self.QChoiceIndex))->getProperty(tag='fitparms')))[*,$
                                    self.xindex+self.yindex*self.detxdim,$
                                    self.ftchoiceindex]

            result = fitVals

        endif

        self->mouseGuts,myxindex = self.xindex,$
                    myyindex = self.yindex,fitparms = result

end;fitButtonHandler


pro ooDisplayEcho::shiftFit,fixed=fixed, sigma = sigma,$
                    minus360=minus360,$
                    plus360=plus360,obj=obj,tavestate=tavestate,_Extra=extra
;
;NAME:
;        ooDisplayEcho::shiftFit
;
;PURPOSE:
;               Select the approprite fit-all routine and shift phases before refit.
;PARAMETERS:
;           none
;KEYWORDS:
;           fixed       The 6 element array of 1/0 to fix/vary parameters during fit.
;           sigma       the Gaussian width to use.
;           minus360    flag to shift phases by -360 before refit.
;           plus360     flag to shift phases by +360 deg before refit.
;           obj         The display object to update if desired.



                            ;121404
                            ;NOW DO FIT BASED ON CHOSEN FIT METHOD


;    fval = widget_info((self.fitselectorobj)->getproperty(/combo),$
;            /combobox_gettext)

    ;041305
    ;UPDATING THIS NOW THAT fitselectorobj USES A BUTTON IN PLACE OF A COMBOBOX
    widget_control,(self.fitselectorobj)->getproperty(/combo),get_value=fval
    segs = strsplit(fval,/extract)  ;TO REMOVE THE ' >'


    ref = (self.dataContainer->get(position= self.QChoiceIndex))
    if n_elements(tavestate) eq 0 then tavestate=ref->report_timeaverage_state() 


    case segs[0] of
    'expand':begin
        ;072805
        ;fitall2 WAS COMMENTED OUT OF THE FILE, SO PUT A MESSAGE
        ;TO PUT THIS FIX OFF.
        ;void = dialog_message('THE EXPAND METHOD IS NOT SUPPORTED FOR SHIFTED PHASES.')

    ;USE THE SAME METHOD AS FOR smoothT  (SEE 'FITBUTTON' EVENT HANDLER)
    ;OR USE fitbutton3a (WHICH EVER IS USED FOR INDIVIDUAL t FITTING FROM fitall4(???))


        ;SET THIS PIXEL'S FIXED VALUE
        fixed = self->getFixed()

        ref->fitall,$
            tauind = self.ftchoiceindex,$
            fixed=fixed,$
            startparms=startparms,obj=self,$
            minus360 = minus360,$
            plus360 = plus360,$
            tavestate=tavestate

;        (self.dataContainer->get(position=$
;                    self.QChoiceIndex))->fitall2,$
;                    0,$ ;chiswitch
;                    fixed=self.fixed,$
;                    startparms=startparms,obj=self
    end;expand
    'arc':begin
        ref->arcFit,$
                    fixed=fixed,$
                    sigma=sigma,$
                    minus360=minus360,$
                    plus360=plus360,obj=obj,$
                    tauind = self.ftchoiceindex,$
                    tavestate=tavestate
    end
    'spiral':begin
        ref->spiralfit,$
                    fixed=fixed,$
                    sigma=sigma,$
                    minus360=minus360,$
                    plus360=plus360,obj=obj,$
                    tauind = self.ftchoiceindex,$
                    tavestate=tavestate
    end;spiral
    else:begin
        dum=dialog_message('Unknown fit method')
    end;else
    endcase

end;shiftFit



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::updateMaskmaker
;
;NAME:
;        ooDisplayEcho::updateMaskmaker
;
;PURPOSE:
;           Update the maskmaker widget following an event.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    ;print,'updateMaskmaker'
    ;IF THERE IS AN EXISTING MASKMAKER, UPDATE IT,
    ;OTHERWISE DO NOTHING.
    if self.maskBase ne 0L then begin
        ;widget_control,self.maskBase,/destroy
        ;self->makeMaskmaker
        theref = self.dataContainer->get(position=self.QChoiceIndex)

        theMask = (*(theref->getProperty(tag='mask2d')))[*,self.ftChoiceIndex]

        widget_control,self.maskmakercw,set_value=theMask

    endif

end;updateMaskmaker

pro ooDisplayEcho::maskEvents,event
;
;NAME:
;        ooDisplayEcho::maskEvents
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


;031506
;THIS METHOD APPEARS TO BE UNUSED


    ;print,'maskEvent occurred'

    ;print,tag_names(event);,/structure_name)
    ;print,event

    ;print,tag_names(event)
    ;print,event
    ;print,event.mask

    ref=self.dataContainer->get(position=self.QChoiceIndex)

    widget_control,event.id,get_value=themask

    maskptr = ref->getProperty(tag='mask2d')
    (*maskptr)[*,self.ftChoiceIndex] = themask;event.mask

    ;print,'themask'

    self->draw

end;maskEvents
pro ooDisplayEcho::makeMaskmaker
;
;NAME:
;        ooDisplayEcho::makeMaskmaker
;
;PURPOSE:
;           Create a maskmaker widget for interacting with the data mask.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    ;GET MASK

    ;POINT TO MASK MEMORY SPACE AND PASS
    ;THE REFERENCE TO cw_maskmaker

    ;CREATE A BASE IN WHICH TO DISPLAY THE cw_maskmaker

    ;print,'makeMaskMaker'
    if self.maskBase eq 0L then begin
        self.maskBase = widget_base(group_leader=self.atlb,floating=1)

        ref = self.dataContainer->get(position=self.QChoiceIndex)

        if ptr_valid(self.maskmakermask) gt 0 then ptr_free,self.maskmakermask
        self.maskmakermask = $
            ptr_new((*(ref->getProperty(tag='mask2d')))[*,self.ftChoiceIndex])

        ;help,(*(ref->getProperty(tag='mask2d')))[*,self.ftChoiceIndex]
        self.maskmakercw = cw_maskmaker(self.maskBase,$
                                            *self.maskmakermask,$
                                            $;notify_id = self.atlb,$
                                            xsize=self.plotxsize,$
                                            ysize=self.plotysize,$
                                            uname='MASKMAKER',$
                                            uvalue={object:self,$
                                                    method:'maskEvents',$
                                                    id:'MASKMAKER'})


        ;STICK EVENT AND OTHER INFORMATION INTO BASE UVALUE
        widget_control,self.maskBase,set_uvalue=$
                                        {object:self,$
                                         method:'maskEvents',$
                                         cleanup:'maskCleanup',$
                                         id:'MASKMAKER'};,$
                                         ;event:dumEvent}
        widget_control,self.maskBase,/realize



        ;050704
        ;SOMEHOW THIS CLEANUP HAS TO BE DONE IN TWO DIFFERENT
        ;CASES, ONE WHEN self.maskBase IS SEPARATELY DESTROYED
        ;AND THE OTHER WHEN OBJECT IS DESTROYED!!!!!
        xmanager,'ooDisplayEcho',self.maskBase,/no_block,$
                    cleanup='maskBaseCleanup'

    endif

end;makeMaskmaker
pro ooDisplayEcho::maskCleanup,id
;
;NAME:
;        ooDisplayEcho::maskCleanup
;
;PURPOSE:
;           Cleanup variables associated with the maskmaker widget.
;PARAMETERS:
;           id  The widget id of the maskmaker base.
;KEYWORDS:
;           none


    widget_control,id,get_uvalue=uval
    ;print,n_elements(tag_names)
    if obj_valid(uval.object) gt 0 then begin
        ptr_free,(uval.object).maskmakermask
        ;widget_control,self.maskmakercw,/destroy
        widget_control,self.maskBase,/destroy
        self.maskBase = 0L
    endif

end;maskCleanup
pro maskBaseCleanup,id
;
;NAME:
;        maskBaseCleanup
;
;PURPOSE:
;           Clean up the maskmaker widget.
;PARAMETERS:
;           id
;KEYWORDS:
;           none

    ;print,'id=',id
    widget_control,id,get_uvalue=uval
    call_method,uval.cleanup,uval.object,id

;
;    print,tag_names(uval)
;    print,uval
;    ptr_free,(uval.object).maskmakermask
;    widget_control,self.maskBase,/destroy
end;maskBaseCleanup

pro ooDisplayEcho::maskButtonHandler,event
;
;NAME:
;        ooDisplayEcho::maskButtonHandler
;
;PURPOSE:
;           Handle button events in ooDisplayEcho associated with mask control.
;PARAMETERS:
;           event
;KEYWORDS:
;           none

;050605
;NOTE THAT THE OPERATIONS IN THIS METHOD SHOULD HAVE BEEN ENCAPSULATED IN THE
;DATA OBJECT.
;
;THIS IS TRUE FOR MANY METHODS IN THIS SOFTWARE, AND IT SHOULD BE DONE
;AT SOME POINT.
;


    ;pmask = (self.dataContainer->get(position= $
    ;            self.QChoiceIndex))->getProperty(tag='mask2d')
    ;mb = obj_new('maskMaker',self.atlb,pmask)

    ;print,event.id

    widget_control,event.id,get_uvalue=uval
    ;print,uval.id


    case uval.id of
    'MASKBUTTON':self->makeMaskmaker
    'MASKBUTTONAPPLY':begin
            ;062204
            ;APPLY CURRENT MASK TO ALL FOURIER TIMES.

            ;GET THE OBJECT REFERENCE FOR THE CURRENTLY SELECTED
            ;Q-VALUE
            ref=self.dataContainer->get(position=self.QChoiceIndex)

            ;GET MASK ARRAY
            maskptr = ref->getProperty(tag='mask2d')

            ;GET THE MASK FOR THE CURRENT IMAGE
            themask = (*maskptr)[*,self.ftChoiceIndex]

            sz = size(*maskptr)

            ;ASSIGN THE MASK TO ALL OF THE IMAGES
            for i=0,sz[2]-1 do begin
                (*maskptr)[*,i] = themask
            endfor
;print,'TEST'
            self->draw
        end
    'MASKBUTTONPIXELAPPLY':begin
            ;040805
            ;APPLY CURRENT PIXEL MASKING TO ALL FOURIER TIMES.

            ;GET THE OBJECT REFERENCE FOR THE CURRENTLY SELECTED
            ;Q-VALUE
            ref=self.dataContainer->get(position=self.QChoiceIndex)

            ;GET MASK ARRAY
            maskptr = ref->getProperty(tag='mask2d')

            index = self.xindex + self.yindex*self.detxdim

            ;GET THE MASK FOR THE CURRENT IMAGE
            themask = (*maskptr)[index,self.ftChoiceIndex]

            sz = size(*maskptr)

            ;ASSIGN THE PIXEL MASK TO ALL OF THE IMAGES
;            for i=0,sz[2]-1 do begin
                ;(*maskptr)[*,i] = themask
                (*maskptr)[index,*] = themask
;            endfor

            self->draw
        end
        'MASKBUTTONSUBSEQUENTAPPLY':begin
            ;050604
            ;APPLY CURRENT MASK TO ALL SUBSEQUENT FOURIER TIMES.

            ;GET THE OBJECT REFERENCE FOR THE CURRENTLY SELECTED
            ;Q-VALUE
            ref=self.dataContainer->get(position=self.QChoiceIndex)

            ;GET MASK ARRAY
            maskptr = ref->getProperty(tag='mask2d')

            ;GET THE MASK FOR THE CURRENT IMAGE
            themask = (*maskptr)[*,self.ftChoiceIndex]

            sz = size(*maskptr)

            ;ASSIGN THE MASK TO SUBSEQUENT IMAGES
            for i=self.ftChoiceIndex,sz[2]-1 do begin
                (*maskptr)[*,i] = themask
            endfor

            self->draw
        end
        'MASKBUTTONSUBSEQUENTPIXELAPPLY':begin
            ;050605
            ;APPLY CURRENT PIXEL MASKING TO SUBSEQUENT FOURIER TIMES.

            ;GET THE OBJECT REFERENCE FOR THE CURRENTLY SELECTED
            ;Q-VALUE
            ref=self.dataContainer->get(position=self.QChoiceIndex)

            ;GET MASK ARRAY
            maskptr = ref->getProperty(tag='mask2d')

            index = self.xindex + self.yindex*self.detxdim

            ;GET THE MASK FOR THE CURRENT IMAGE
            themask = (*maskptr)[index,self.ftChoiceIndex]

            sz = size(*maskptr)

            ;ASSIGN THE PIXEL MASK TO ALL SUBSEQUENT IMAGES
                (*maskptr)[index,self.ftChoiceIndex:*] = themask

            self->draw
        end
        else:begin
        end
    endcase

end;maskButtonHandler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::buttonEvents,event
;
;NAME:
;        ooDisplayEcho::buttonEvents
;
;PURPOSE:
;           Dispatch button event to appropriate handlers.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none


    widget_control,event.id,get_uvalue=obj
    case obj.id of
        'FITBUTTON1':           self->fitButtonHandler,event
        'FITBUTTON':            self->fitButtonHandler,event
        'FITBUTTONALL':         self->fitButtonHandler,event
        'FITBUTTONALLMINUS360': self->fitButtonHandler,event
        'FITBUTTONALLPLUS360':  self->fitButtonHandler,event
        'FITBUTTONALLQ':        self->fitButtonHandler,event
        'REWBUTTONQ':           self->CDButtonHandler,event
        'REVBUTTONQ':           self->CDButtonHandler,event
        'FWDBUTTONQ':           self->CDButtonHandler,event
        'FFWDBUTTONQ':          self->CDButtonHandler,event
        'REWBUTTONTAU':         self->CDButtonHandler,event
        'REVBUTTONTAU':         self->CDButtonHandler,event
        'FWDBUTTONTAU':         self->CDButtonHandler,event
        'FFWDBUTTONTAU':        self->CDButtonHandler,event
        'MASKBUTTON':           self->maskButtonHandler,event
        'MASKBUTTONAPPLY':      self->maskButtonHandler,event
        'MASKBUTTONPIXELAPPLY':      self->maskButtonHandler,event
        'MASKBUTTONSUBSEQUENTAPPLY':      self->maskButtonHandler,event
        'MASKBUTTONSUBSEQUENTPIXELAPPLY':      self->maskButtonHandler,event
        'PHASEIMPORTBUTTON':    self->importExportButtonHandler,event
        'FITPARMRESTOREBUTTON': self->importExportButtonHandler,event
        'PLOTMASKZOOMBUTTON': self->PLOTMASKZOOMBUTTONHandler,event
        'PLOTUNZOOMBUTTON': self->PLOTUNZOOMBUTTONHandler,event ;120105
        else: begin
                widget_control,self.tw1,$
                    set_value='UNKNOWN BUTTON: '+obj.id+':'+tag_names(event)
              end
    endcase

end;buttonEvents
pro ooDisplayEcho::PLOTUNZOOMBUTTONHandler,event
;120105
;print,'ooDisplayEcho::plotunzoombuttonhandler'
    self.plotzoomswitch = 0
    self->draw
end;PLOTMASKZOOMBUTTONHandler


pro ooDisplayEcho::PLOTMASKZOOMBUTTONHandler,event

    widget_control,event.id,get_uvalue=obj
    ;print,obj.options
    widget_control,event.id,get_value=val
    wh = where(val eq obj.options)

    if wh[0] eq 1 then self.plotmaskzoomflag = 0 else self.plotmaskzoomflag = 1
    widget_control,event.id,set_value=obj.options[self.plotmaskzoomflag]

end;PLOTMASKZOOMBUTTONHandler

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::CDButtonHandler,event
;
;NAME:
;        ooDisplayEcho::CDButtonHandler
;
;PURPOSE:
;           Handle button events from "cd" widgets, which consist of
;           foward/backward buttons and a droplist widget.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none

    ;HANDLE EVENTS FOR THE BUTTONS ASSOCIATED WITH SELECTING
    ;PARTICULAR Q's, Tau's, Images, etc.


    widget_control,event.id,get_uvalue=obj

    case obj.id of
        $;Q SELECTIONS ---- NEED TO UPDATE THE CURRENT DATA OBJECT HERE
        $;                  WHEN THE Q-VALUE IS CHANGED -- USE
        $;                  USE self->reDefineWidgets AND self->setDataParameters,$
        $;                                                  self.dataSet,n=thisIndex
        $;
        $;
        $;NOW NEED TO KEEP TRACK OF PREVIOUS DATA OBJECT SO THAT
        $;IT CAN BE SAVED IN POSITION OF PREVIOUS OBJECT IN THE
        $;dataContainer --- THE IMPORTANT THING HERE IS TO SAVE
        $;ALL OF THE WORK THAT HAS ALREADY BEEN DONE ON EACH OF THE
        $;DATA OBJECTS.
        'REWBUTTONQ': begin
                            oldQIndex = self.QChoiceIndex
                            widget_control,self.adwQ,get_value=tempQ
                            self.QChoiceIndex = 0
                            widget_control,self.adwQ,$
                                set_droplist_select = self.QChoiceIndex
                            self->swapDataObject,oldQIndex,self.QChoiceIndex
;                            self->setDataParameters,$
;                                self.ech,$;self.dataContainer->get(position = self.QChoiceIndex),$
;                                n=self.QChoiceIndex
                            self->setDataParameters,$
                                (self.dataContainer->get(position=self.QChoiceIndex)),$
                                n=self.QChoiceIndex
                            ;self->reDefineWidgets,self.QChoiceIndex
                        end
        'REVBUTTONQ': begin
                            oldQIndex = self.QChoiceIndex
                            self.QChoiceIndex = self.QChoiceIndex - 1
                            widget_control,self.adwQ,get_value=tempQ
                            if self.QChoiceIndex le 0 then $
                                self.QChoiceIndex = 0
                            widget_control,self.adwQ,$
                                set_droplist_select = self.QChoiceIndex
                            self->swapDataObject,oldQIndex,self.QChoiceIndex
;                            self->setDataParameters,$
;                                self.ech,$;self.dataContainer->get(position = self.QChoiceIndex),$
;                                n=self.QChoiceIndex
                            self->setDataParameters,$
                                (self.dataContainer->get(position=self.QChoiceIndex)),$
                                n=self.QChoiceIndex
                            ;self->reDefineWidgets,self.QChoiceIndex
                        end
        'FWDBUTTONQ': begin
                            oldQIndex = self.QChoiceIndex
                            self.QChoiceIndex = self.QChoiceIndex + 1
                            widget_control,self.adwQ,get_value=tempQ
                            if self.QChoiceIndex ge n_elements(tempQ) then $
                                self.QChoiceIndex = n_elements(tempQ) -1
                            widget_control,self.adwQ,$
                                set_droplist_select = self.QChoiceIndex
                            self->swapDataObject,oldQIndex,self.QChoiceIndex
;                            self->setDataParameters,$
;                                self.ech,$;self.dataContainer->get(position = self.QChoiceIndex),$
;                                n=self.QChoiceIndex
                            self->setDataParameters,$
                                (self.dataContainer->get(position=self.QChoiceIndex)),$
                                n=self.QChoiceIndex
                            ;self->reDefineWidgets,self.QChoiceIndex
                        end
        'FFWDBUTTONQ': begin
                            oldQIndex = self.QChoiceIndex
                            widget_control,self.adwQ,get_value=tempQ
                            self.QChoiceIndex = n_elements(tempQ) -1
                            widget_control,self.adwQ,$
                                set_droplist_select = self.QChoiceIndex
                            self->swapDataObject,oldQIndex,self.QChoiceIndex
;                            self->setDataParameters,$
;                                self.ech,$;self.dataContainer->get(position = self.QChoiceIndex),$
;                                n=self.QChoiceIndex
                            self->setDataParameters,$
                                (self.dataContainer->get(position=self.QChoiceIndex)),$
                                n=self.QChoiceIndex

                            ;self->reDefineWidgets,self.QChoiceIndex
                        end
        $;TAU SELECTIONS
        'REWBUTTONTAU': begin
                            widget_control,self.adwTau,get_value=tempTau
                            self->setPixelIndices
                            self.ftChoiceIndex = 0
                            widget_control,self.adwTau,$
                                set_droplist_select = self.ftChoiceIndex
                        end
        'REVBUTTONTAU': begin
                            self.ftChoiceIndex = self.ftChoiceIndex - 1
                            widget_control,self.adwTau,get_value=tempTau
                            self->setPixelIndices
                            if self.ftChoiceIndex le 0 then $
                                self.ftChoiceIndex = 0
                            widget_control,self.adwTau,$
                                set_droplist_select = self.ftChoiceIndex
                        end
        'FWDBUTTONTAU': begin
                            self.ftChoiceIndex = self.ftChoiceIndex + 1
                            widget_control,self.adwTau,get_value=tempTau
                            self->setPixelIndices
                            if self.ftChoiceIndex ge n_elements(tempTau) then $
                                self.ftChoiceIndex = n_elements(tempTau) -1
                            widget_control,self.adwTau,$
                                set_droplist_select = self.ftChoiceIndex
                        end
        'FFWDBUTTONTAU': begin
                            widget_control,self.adwTau,get_value=tempTau
                            self->setPixelIndices
                            self.ftChoiceIndex = n_elements(tempTau) -1
                            widget_control,self.adwTau,$
                                set_droplist_select = self.ftChoiceIndex
                        end
    else: begin
            widget_control,self.tw1,$
                set_value='UNKNOWN BUTTON: '+obj.id+':'+tag_names(event)
          end
    endcase

    ;UPDATE THE MASKMAKER WINDOW AS APPROPRIATE
    ;self->updateMaskMaker

    ;UPDATE THE DISPLAY
    ;self->draw

    self->mouseHead,event

    ;print,'CDButton'+'Event'+string([13B,10B])+obj.id


end;CDButtonHandler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
pro ooDisplayEcho::sliderEvents,event
;
;NAME:
;        ooDisplayEcho::sliderEvents
;
;PURPOSE:
;           Handle events for the click-refit slider.
;PARAMETERS:
;           event   the event structure to handle.
;KEYWORDS:
;           none


    ;print,'ooDisplayEcho::sliderEvents'
    ;print,tag_names(event)
    ;print,event

    widget_control,self.clickrefitslider,get_value=val
    self.clickrefitvalue = val
    widget_control,self.clickrefitperiodslider,get_value=pval
    self.clickrefitperiodvalue = pval


end;sliderEvents
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::drawEvents,event
;
;NAME:
;        ooDisplayEcho::drawEvents
;
;PURPOSE:
;           Handle events from the draw widgets.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none

    ;HANDLES MOUSE BUTTON EVENTS ON THE DRAW WINDOWS.

    widget_control,event.id,get_uvalue=obj

    ;print,'ooDisplayEcho::drawEvents ',tag_names(event,/structure_name)
    etype = strlowcase(tag_names(event,/structure_name))

    case etype of
    'widget_draw':begin
        ;print,'event.press=',event.press
        if self.plotmousepressed eq 0 then begin
            if event.press eq 1 then begin

                if (obj.id eq "DW1") then begin
                    switch event.type of
                    0:
                    1:
                    2:begin
                        self->mouseEvents,event
                        break
                    end;0,1,2
                    5:
                    6:begin
                        self->keyboardEvents,event
                        break
                    end;5,6
                    else:begin
                        self->do_nothing
                    end;
                    endswitch

                endif;obj.id
                if (obj.id eq "DW2") then begin; and event.type eq 0) then begin


                    ;print,'self.plotmaskzoomflag=',self.plotmaskzoomflag
                    ;print,'DW2 EVENT'
                    ;print,tag_names(event)
                    ;print,event

                    case self.plotmaskzoomflag of
                    0:begin
                        switch event.type of
                        0:
                        1:
                        2:begin
                                ;120105
                                ;UPDATING PLOT MASKING TO RESPOND TO DOUBLE-CLICK
                                if event.press eq 1 and event.clicks eq 2 then begin
                                    self->proximityEvents,event,self.xindex,self.yindex
                                endif
                            ;121604
        ;                    print,tag_names(event)
        ;                    print,event
        ;                    print,'ooDisplayEcho::drawEvents self->proximityEvents,event'
                            break
                        end;0,1,2
                        5:
                        6:begin
                            ;print,'testbutton'
                            self->keyboardEvents,event
                            break
                        end;5,6
                        else:begin
                            self->do_nothing
                        end;
                        endswitch


                    end;plotmaskzoomflag of 0
                    1:begin

;120105
;COMMENTED OUT
;                        coords = convert_coord(event.x,event.y,/device,/to_data)
;                        self.plotpressx = coords[0]
;                        self.plotpressy = coords[1]
;                        self.plotreleasex = coords[0]
;                        self.plotreleasey = coords[1]
;                        ;print,coords
;                        self.plotmousepressed = 1
;                        self.plotzoombox = 1
                    end;plotmaskzoomflag of 1
                    else:
                    endcase
;    print,'ooDisplayEcho::drawEvents  test'
;    print,'event.clicks=',event.clicks

;120105
;NOW THAT MASKING IS HANDLED BY A DOUBLE CLICK,
;ALLOW ZOOM WITH ANY MOUSE DRAG, REGARDLESS OF MASK/ZOOM BUTTON STATE.

                ;011006
                ;FOR SOME REASON I HAVE TO PUT THIS wset COMMAND HERE IN
                ;CASE THE AUXILIARY WINDOW IS OPEN.
                ;CONVERT_COORDS SEEMS TO GET CONFUSED IF I DON'T.
                ;DUE TO SOME SORT OF log/lin PROBLEM.
                wset,self.dw2pix
                !x = *self.w2xptr
                !y = *self.w2yptr
                coords = convert_coord(event.x,event.y,/device,/to_data)
                self.plotpressx = coords[0]
                self.plotpressy = coords[1]
                self.plotreleasex = coords[0]
                self.plotreleasey = coords[1]

;                print,!x.type
;                print,self.plotpressx
;                print,self.plotpressy

                case self.plotindex of
                1:begin
                end;1
                6:begin
                end;6
                else:
                endcase



                ;print,coords
                self.plotmousepressed = 1
                self.plotzoombox = 1

                endif;obj.id


            endif;event.press eq 1
        endif;self.plotmousepressed eq 0


        if self.plotmousepressed eq 1 then begin
;110105
            ;HOPEFULLY I ONLY GET HERE IF THERE IS A DRAG EVENT

            if event.clicks ne 2 then begin

                ;011006
                ;FOR SOME REASON I HAVE TO PUT THIS wset COMMAND HERE IN
                ;CASE THE AUXILIARY WINDOW IS OPEN.
                wset,self.dw2pix
                !x = *self.w2xptr
                !y = *self.w2yptr
                coords = convert_coord(event.x,event.y,/device,/to_data)
                self.plotreleasex = coords[0]
                self.plotreleasey = coords[1]




                if event.release ne 0 then begin
                    ;120105
                    ;PLACE THESE OUTSIDE OF NEXT CONDITIONAL SO THEY WILL CATCH
                    ;TWO CLICKS MAKING UP DOUBLE-CLICKS.
                    self.plotmousepressed = 0
                    self.plotzoombox = 0
                    if self.plotpressx ne self.plotreleasex and self.plotpressy ne self.plotreleasey then begin
                        self.plotxmin = min([self.plotpressx,self.plotreleasex])
                        self.plotxmax = max([self.plotpressx,self.plotreleasex])
                        self.plotymin = min([self.plotpressy,self.plotreleasey])
                        self.plotymax = max([self.plotpressy,self.plotreleasey])

;                        print,'ooDisplayEcho::drawEvents  test event.clicks=',event.clicks
;                        print,'ooDisplayEcho::drawEvents  test event.press=',event.press
;                        print,'ooDisplayEcho::drawEvents  test event.release=',event.release
        ;                ;CHANGE PLOT MASKING BUTTON INTO UNZOOM
        ;                print,self.plotxmin
        ;                print,self.plotxmax
        ;                print,self.plotymin
        ;                print,self.plotymax

                        self.plotzoomswitch = 1
                    endif;self.plotpressx ne self.plotreleasex and self.plotpressy ne self.plotreleasey
    ;110905
    ;SET A FLAG TO TELL THE PLOTTING ROUTINE TO USE THE ZOOMED RANGE
                endif;event.release ne 0
                self->draw;,/plotzoombox
            endif;event.clicks eq 2
        endif


        ;120105
        ;CHANGE TO DOUBLE-CLICK REFIT FROM RIGHT CLICK REFIT ON PHASE IMAGE.
        ;NEED TO CHANGE THE NEXT SECTION TO BE AVAILABLE FOR A LEFT DOUBLE CLICK AND NOT A RIGHT CLICK
        if event.press eq 1 and event.clicks eq 2 then begin
;            print,'test,doubleclick'
;print,'obj.id=',obj.id
;print,'event.type=',event.type
            ;if (obj.id eq 'DW1') then begin ;and (self.displayindex eq 3) then begin
            case obj.id of
            'DW1':begin
                if self.displayindex eq 3 and $
                        widget_info(self.clickrefitperiodslider,/valid_id) gt 0 then begin

                    ;DOUBLE-CLICK REFIT.

                    refitTauInd = self.ftChoiceIndex

                    self->setPixelIndices


                    ;030905 ADDING THE NEXT 3 COMMANDS
                    ref = self.dataContainer->get(position=self.QChoiceIndex)
                    ref->storeFitparms
                    fitVals = $
                    (*(ref->getProperty(tag='fitparms')))[*,$
                                                self.xindex+self.yindex*self.detxdim,$
                                                self.ftchoiceindex]



                    ;GET CURRENT PARAMETER VALUES FROM WIDGET TEXT FIELDS
                    widget_control,self.atwconst,get_value=sconstStart
                    constStart = double(sconstStart)
                    widget_control,self.atwamp,get_value=sampStart
                    ampStart = double(sampStart)
;120105
;THE NEXT LINE SEEMS TO BE THE MAIN DIFFERENCE BETWEEN
;THIS CLICK REFIT AND THE FITPHASE v. TAU plot REFIT.
;COMMENT IT OUT FOR NOW.
;                    if ampStart eq 0.1 then print,ampstart & ampStart = 10.0


                    widget_control,self.atwsigma,get_value=ssigmaStart
                    sigmaStart = double(ssigmaStart)

;                    ;NOTE THE OMEGA VS. PERIOD THING.


                    DONOTREFIT = 0
                    if widget_info(self.clickrefitperiodslider,/valid_id) gt 0 then begin
                        ;GET NEW STARTING PHASE FROM CLICK ON PHASE v TAU PLOT
                        widget_control,self.clickrefitperiodslider,get_value=speriodstart
                        omegaStart = 360.0d/double(speriodstart)
                    endif else begin
                        omegaStart = 1.0d;360.0d/double(speriodstart)
                        DONOTREFIT = 1
                    endelse

                    if widget_info(self.clickrefitperiodslider,/valid_id) gt 0 then begin
                        ;GET NEW STARTING PHASE FROM CLICK ON PHASE v TAU PLOT
                        widget_control,self.clickrefitslider,get_value=sphaseostart
                        phaseoStart = double(sphaseostart)
                    endif else begin
                        widget_control,self.atwphaseo,get_value=sphaseoStart
                        phaseoStart = double(sphaseostart)
                        DONOTREFIT = 1
                    endelse

                    widget_control,self.atwphase,get_value=sphaseStart
                    phaseStart = double(sphaseStart)

                    startparms =   [constStart,ampStart,phaseoStart,$
                                    sigmaStart,omegaStart,phaseStart]


                    ;GET FIXED/VARY VALUE
                    fixed = self.fixed
                    if DONOTREFIT eq 0 then begin

                        result = ref->chirpFit( self.xindex,$
                                                          self.yindex,$
                                                          refitTauInd,$
                                                          fixed=self.fixed,$
                                                          startparms=startparms)

                    endif;DONOTREFIT EQ 0

;THESE SHOULD BE COVERED ABOVE
                    switch event.type of
                    0:begin
                        self->mouseEvents,event
                        break
                    end;0,1,2
                    else:begin
                        self->do_nothing
                    end;
                    endswitch
;            print,systime(1,/seconds)-t0

                ;END OF self.displayindex eq 3
                endif else begin
                    ;(UN)MASK THIS PIXEL ON DOUBLE CLICK


;120705
                    ix=self.xindex
                    iy=self.yindex
                    it=self.ftChoiceIndex

                    ref = self.datacontainer->get(position=self.qchoiceindex)
                    mcurr = (*(ref->getproperty(tag='mask2d')))[ix+self.detxdim*iy,it]
                    if mcurr eq 1 then begin
                        mnew = -1;0
                    endif else mnew = 1
                    (*(ref->getproperty(tag='mask2d')))[ix+self.detxdim*iy,it] = mnew

                    switch event.type of
                    0:begin
                        self->mouseEvents,event
                        break
                    end;0,1,2
                    else:begin
                        self->do_nothing
                    end;
                    endswitch


                endelse ;ALL OTHER DISPLAY INDICES

            ;endif;OBJ.ID eq 'DW1' AND SELF.DISPLAYINDEX EQ 3
            end;case obj.id of 'DW1'
            'DW2':begin
                ;print,'ooDisplayEcho::drawEvents 4381 test,doubleclick DW2?'
            end;case 'obj.id' of 'DW2'
            else:
            endcase

        endif;LEFT DOUBLE_CLICK EVENT ON PHASE IMAGE

        if event.press eq 4 then begin  ;right click
            if  (obj.id eq "DW1") then begin;and not (self.displayindex eq 3) then begin

                ;DISPLAY CONTEXT MENU
                maskContextBase = WIDGET_INFO(event.ID, FIND_BY_UNAME = 'MASKCONTEXTBASE')

                WIDGET_DISPLAYCONTEXTMENU, event.ID, event.X, event.Y, maskContextBase

            endif;RIGHT CLICK IN DW1 BUT NOT PHASE IMAGE.


            if  (obj.id eq "DW2") then begin

                    ;DISPLAY CONTEXT MENU
                    plotContextBase = WIDGET_INFO(event.ID, FIND_BY_UNAME = 'PLOTCONTEXTBASE')

                    WIDGET_DISPLAYCONTEXTMENU, event.ID, event.X, event.Y, plotContextBase




            endif;RIGHT CLICK IN DW1 BUT NOT PHASE IMAGE.

            self->draw
        endif;event.press eq 4
    end;widget_draw
    'widget_tracking':begin
        ;print,'ooDisplayEcho::drawEvents  TRACKING EVENT'
        ;SET THE IMAGE WINDOW AS THE FOCUS OF KEYBOARD EVENTS
        ;WHEN ENTERING EITHER DRAW WINDOW.
        case obj.id of
        'DW1':begin
            if event.enter eq 1 then begin
                widget_control,self.dw1,input_focus=1
                widget_control,self.tw1,set_value='arw keys navigate, "m" masks, pgup/dn changes t, dbl-clk refits for phase image'
            endif else begin
                widget_control,self.dw1,input_focus=0
            endelse
        end;'DW1'
        'DW2':begin
            if event.enter eq 1 then begin
                widget_control,self.dw2,input_focus=1
                widget_control,self.tw1,set_value='dbl-clk masks, drag-mouse to zoom'
            endif else begin
                widget_control,self.dw2,input_focus=0
            endelse
        end;'DW2'
        else:
        endcase
    end
    else:begin
    end
    endcase


end;drawEvents
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::proximityEvents,event,xind,yind
;
;NAME:
;        ooDisplayEcho::proximityEvents
;
;PURPOSE:
;           Determine the position of the closest data point on the plot following a mouse click.
;PARAMETERS:
;           event   The event structure to handle.
;           xind    The indices of the currently selected pixel.
;           yind
;KEYWORDS:
;           none

    ;HANDLE MOUSE EVENTS IN THE PLOT WINDOW

    ;
    ;052004
    ;NEED TO ADD CASE OF PROXIMITY GETTING A POINT
    ;IN THE Iup,Idown POINTS.
    ;
    ;NEED TO APPLY MASKING TO THESE AS WELL.
    ;PROBABLY NEED A SECOND MASK --- OR MAYBE
    ;JUST USE A FULL PHASE RANGE MASK.
    ;
    ;

    ;GET RANGES OF THE AXES ON THE CURRENT PLOT AND IGNORE
    ;MOUSE EVENTS OUTSIDE OF THE PLOT.
    wset,self.dw2id
    ;x AXIS MAY HAVE A LOG SCALE SO IT MUST BE CONVERTED
    ;SOMETIMES FOR THE PURPOSES OF THIS METHOD


;011006
    ;SET WINDOW DATA AXIS POINTERS
    !x = *self.w2xptr
    !y = *self.w2yptr


    if self.plotindex eq 1 or self.plotindex eq 6 then begin
        xrange = 10.0^!x.crange
        yrange = !y.crange
    endif else begin
        xrange = !x.crange
        yrange = !y.crange
    endelse

    r = self->getPositionOnPlot(event)
    ;print,'121604'
    ;print,'ooDisplayEcho::proximityEvents r=',r
    ;print,'ooDisplayEcho::proximityEvents xrange=',xrange
    ;print,'ooDisplayEcho::proximityEvents yrange=',yrange

    if  r[0] ge xrange[0] and $
        r[0] le xrange[1] and $
        r[1] ge yrange[0] and $
        r[1] le yrange[1] then begin

        switch self.plotindex of

            ;IN CASES WHERE THE FLIPPER ON/OFF POINTS ARE
            ;SHOWN, ALLOW FOR 1D MASKING OF THEM.

            ;NEED TO USE ooEcho::proximity1DAll FOR CASES
            ;WHERE FLIPPER ON/OFF POINTS ARE DISPLAYED

            ;NOTE:  ISN'T THERE JUST A TOGGLED VALUE THAT
            ;       DETERMINES WHETHER ALL THE POINTS ARE
            ;       PLOTTED.


            0:
            2:
            3:
            4:
            5:begin

                ;CHANGE ooEcho::proximity1D TO BE AWARE OF ALL
                ;DATA POINTS BUT RETURN INDEX BASED ON AN INPUT
                ;PARAMETER THAT IDENTIFIES WHETHER ALL THE POINTS
                ;OR JUST THE ECHO POINTS SHOULD BE INCLUDED.
                ;
                ;

                if self.plotupdown eq 1 then begin
                    ;LOOK AT ALL PHASE VALUES
                    phsInd =(self.dataContainer->get(position=$
                            self.QChoiceIndex))->proximity1DAll(r[0],r[1],$
                                                self.xindex,self.yindex,$
                                                self.ftChoiceIndex,$
                                                xrange,yrange)
                endif else begin
                    ;LOOK ONLY AT ECHO PHASE VALUES
                    phsInd =(self.dataContainer->get(position=$
                            self.QChoiceIndex))->proximity1D(r[0],r[1],$
                                                self.xindex,self.yindex,$
                                                self.ftChoiceIndex,$
                                                xrange,yrange)
                endelse

;110905
;print,'ooDisplayEcho::proximityevents phsInd=',phsInd
                (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setMask1D, $
                                             phsInd, $
                                             self.ftChoiceIndex


                (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,'IupdownSwitch',0
                break
            end;5
            1:begin;ADJUSTING PHASE vs. TAU ON MOUSE CLICK
                r = self->getPositionOnPlot(event)
;                print,'ooDisplayEcho::proximityEvents r=',r

                refitTauInd = (self.dataContainer->get(position=$
                    self.QChoiceIndex))->closestTauIndex(r[0]/10.0^9)

                self->setPixelIndices

                ;GET CURRENT PARAMETER VALUES FROM WIDGET TEXT FIELDS
                widget_control,self.atwconst,get_value=sconstStart
                constStart = double(sconstStart)
                widget_control,self.atwamp,get_value=sampStart
                ampStart = double(sampStart)
                widget_control,self.atwsigma,get_value=ssigmaStart
                sigmaStart = double(ssigmaStart)

    ;120904
    ;MAY WANT TO CONSTRAIN PERIOD VALUES FOR FIT HERE IF
    ;IT IS NOT A FIXED PARAMETER.
                widget_control,self.atwomega,get_value=somegaStart
                ;omegaStart = 360.0d/double(somegaStart)
;040205
;
;UPDATED THE NEXT COMMAND TO EITHER SET omega = 1 OR GET THE PERIOD
;STARTING VALUE FROM THE SLIDER AND CALCULATE OMEGA FROM THAT.
                if widget_info(self.clickrefitperiodslider,/valid_id) ne 0 then begin
                    widget_control,self.clickrefitperiodslider,get_value=periodstart
                    omegaStart = 360.0d/double(periodstart)
                endif else begin
                    omegaStart = 1.0d;0.95d;360.0d
                endelse

                widget_control,self.atwphase,get_value=sphaseStart
                phaseStart = double(sphaseStart)


                ;GET NEW STARTING PHASE FROM CLICK ON PHASE v TAU PLOT
                phaseoStart = r[1]

                startparms =   [constStart,ampStart,phaseoStart,$
                                sigmaStart,omegaStart,phaseStart]


                ;GET FIXED/VARY VALUE
                fixed = self.fixed
                ;fixed = [0,0,0,1,1,1]

                result = (self.dataContainer->get(position=$
                           self.QChoiceIndex))->chirpFit( self.xindex,$
                                                      self.yindex,$
                                                      refitTauInd,$
                                                      fixed=self.fixed,$
                                                      startparms=startparms)

                break
            end
            6:  break
        endswitch

        self->draw
    endif else begin;RANGES
        ;print,r,' IS OUTSIDE THE PLOT RANGE.'
    endelse

end;proximityEvents
pro ooDisplayEcho::setPixelIndices
;
;NAME:
;        ooDisplayEcho::setPixelIndices
;
;PURPOSE:
;           Set the current pixel indices based on the current image
;           and the last selected pixel.
;PARAMETERS:
;           none
;KEYWORDS:
;           none

    ;SET PIXEL INDICES ON BUTTON EVENTS


;021706
;SHOULD I USE self->updateIndices HERE???

        xindex = self.xindex
        yindex = self.yindex
        if xindex ge self.detxdim then begin
            self.xindex = self.detxdim/2
        endif else begin
            self.xindex = xindex
        endelse
        if yindex ge self.detydim then begin
            self.yindex = self.detydim/2
        endif else begin
            self.yindex = yindex
        endelse


end;setPixelIndices
pro ooDisplayEcho::importPhases
;
;NAME:
;        ooDisplayEcho::importPhases
;
;PURPOSE:
;           Call the dialog creation method for the phase import functionality,
;           where phases are imported from one ooEcho object to another before
;           fitting.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    ;060304


    ;NEED TO UPDATE THE PHASE IMPORT TO INCORPORATE
    ;THE INTERPOLATION OF THE RESOLUTION OBJECT PHASES
    self->definePhaseImportDialog

end;importPhases
pro ooDisplayEcho::importExportButtonHandler,event
;
;NAME:
;        ooDisplayEcho::importExportButtonHandler
;
;PURPOSE:
;           Handle events from the phase import widget.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none.


    widget_control,event.id,get_uvalue=obj
    case obj.id of
        'PHASEIMPORTBUTTON':begin
                    ;print,'PHASEIMPORTBUTTON'
                    self->importPhases
                    self->draw

                end
        'FITPARMRESTOREBUTTON':begin
                    ;RESTORE PARMS FOR CURRENT DATA OBJECT
                    ref = self.datacontainer->get(position=self.QChoiceIndex)
                    ref->revertFitparms
                    ;self->draw
                    self->reDefineTree
                    self->mouseHead,event
                end

        else: begin
                widget_control,self.tw1,$
                    set_value='UNKNOWN BUTTON: '+obj.id+':'+tag_names(event)
              end
    endcase
end;importExportButtonHandler
pro ooDisplayEcho::listEvents,event
;
;NAME:
;        ooDisplayEcho::listEvents
;
;PURPOSE:
;           Handle various "list" events.  These events may come from
;           phase import, IQT, and set selection dialogs.
;PARAMETERS:
;
;KEYWORDS:
;


;    print,'ListEvent'

    widget_control,event.id,get_uvalue=obj

    case obj.id of
        'OKBUTTON':begin

;print,'OKBUTTON????'
                        widget_control,self.phaseImportList,get_uvalue=pil
                        objIndexList = pil.list

                        index=widget_info(self.phaseImportList,$
                                            /droplist_select)


                        m=self.QChoiceIndex
                        n=objIndexList[index]

                        ;NEED TO DETERMINE HERE IF THE DIMENSIONS
                        ;OF THE CARBOPACK AND SAMPLE ARE THE
                        ;SAME.  IF SO, IMPORT PHASES DIRECTLY.
                        ;IF NOT, INTERPOLATE.
                        ;
                        ;HOLD ON. . .
                        ;WHY NOT JUST ALWAYS INTERPOLATE EXCEPT WHEN
                        ;DETECTOR BINNING IS NOT IDENTICAL????
                        ;
                        objTo = ((self.dataContainer)->get(position=m))
                        objFrom = ((self.dataContainer)->get(position=n))

                        ;060304
                        ;SUBSTITUTE THE NEXT LINE WITH THE ONE
                        ;BELOW IT.
                        ;objTo->grabPhasesFrom,objFrom

                        ;THE NEXT LINE SHOULD BE EXECUTED IN THE DATA OBJECT
                        ;objTo->getInterpPhasesFrom,objFrom

;#####################################################################
;
;021705
;CORRECT THIS NEXT SECTION TO PROPERLY HANDLE THE CHOICE OF PHASE
;FIX/VARY.

                        ;GET VALUE FROM THE "FIXED" CHECKBOX VIA WIDGET_INFO:





                        ;self.fixed = [0,0,1,1,1,1]


                        ;SUPPLY CHECKBOX ON THE PHASE IMPORT WIDGET TO DECIDE IF
                        ;PHASES WILL BE FIXED.

                        ;NEED TO ASSUME PHASES WILL BE FIXED HERE, UNLESS, SEE ABOVE

                        ;THIS MUST GET THE CURRENT VALUE OF fixed, WHICH TYPICALLY
                        ;HAS THE PHASE VALUE SET TO VARY.
                        self.fixed = self->getFixed()


                        savefixed = self.fixed


                        ;GET THE FIX/VARY PHASE VALUE FROM THE WIDGET
                        fixvaryphasedl = widget_info(self.phaseImportBase,$
                                        find_by_uname='PHASEIMPORTFIXVARYPHASE')
        ;070505
        ;NEED THIRD OPTION HERE TO CHOOSE TO FIT THE PHASE OFFSET.
                        ;self.fixed[2] = widget_info(fixvaryphasedl,/droplist_select)
                        if widget_info(fixvaryphasedl,/droplist_select) eq 2 then begin
                            ;FIT PHASE OFFSET
                            self.fixed[2] = 1
                            fitphaseoffset = 1
                        endif else begin
                            self.fixed[2] = widget_info(fixvaryphasedl,/droplist_select)
                            fitphaseoffset = 0
                        endelse


                        ;GET THE FIX/VARY PERIOD VALUE FROM THE WIDGET
                        fixvaryperioddl = widget_info(self.phaseImportBase,$
                                        find_by_uname='PHASEIMPORTFIXVARYPERIOD')

                        self.fixed[4] = widget_info(fixvaryperioddl,/droplist_select)

                        allownegamp = widget_info(self.phaseImportBase,$
                                        find_by_uname='ALLOWNEGATIVEAMPLITUDECHECKBOX')
                        widget_control,allownegamp,get_value=negamp

                        forcenegamp = widget_info(self.phaseImportBase,$
                                        find_by_uname='FORCENEGATIVEAMPLITUDECHECKBOX')
                        widget_control,forcenegamp,get_value=forcenegamp

;print,'NEGAMP=',negamp

                        widget_control,self.phaseImportBase,/destroy

                        widget_control,self.atwphase,get_value=sphaseoffset
                        ;print,sphaseoffset
                        phaseoffset = double(sphaseoffset)  ;ALWAYS 0.0 SINCE THIS TEXT BOX IS NOT SHOWN.
                        widget_control,self.atwomega,get_value=somega
                        ;print,somega

;120904
;CONVERT PERIOD TO OMEGA.
;print,omega
                        omega = 1.0/double(somega)

;print,omega
                        ;1) GET fixed VALUES FROM GUI AND PASS TO
                        ;   DATA OBJECT HERE.
                        ;
                        ;2) PASS VALUE IN PHASE OFFSET BOX IF NON-ZERO.

                        (self.dataContainer->get(position=$
                                m))->fitAllFixedPhase,$
                                objFrom,$
                                fixed=self.fixed,$
                                startparms=startparms,$
                                obj=self,$
                                phaseoffset = phaseoffset,$
                                fitphaseoffset=fitphaseoffset,$
                                omega=omega,$
                                allownegamp=negamp,$
                                forcenegamp=forcenegamp

;021406
;BY POLLING THE DATA OBJECT FOR THE fixed STATE, THERE IS NO NEED TO
;DO ANYTHING HERE TO HANDLE THE EXTRA fix/vary OPTIONS.


                        ;print,self.fixed
                        ;UPDATE ALL DISPLAYS
                        self.fixed = savefixed  ;THIS IS IRRELEVANT NOW THAT
                                                ;"fixed"
                        self->redefineTree
                        self->redefineWidgets,self.QChoiceIndex
                        self->draw


                    end
        'CANCELBUTTON':begin
                        widget_control,self.phaseImportBase,/destroy
                    end
        'PHASEIMPORTLIST':begin
                        ;THIS METHOD SHOULD BE UNNECESSARY
                        widget_control,event.id,get_value=list
                    end
        'IQTOKBUTTON':begin

                        ;GET OBJECTS FROM WIDGET SELECTIONS AND
                        ;CALCULATE I(Q,t)
                        widget_control,self.IQTImportBase,$
                                            get_uvalue=iqt

                        bkgIndexList = iqt.bkgList
                        datIndexList = iqt.datList
                        resIndexList = iqt.resList

                        bkgIndex=widget_info(self.bkgImportList,$
                                            /droplist_select)
                        datIndex=widget_info(self.datImportList,$
                                            /droplist_select)
                        resIndex=widget_info(self.resImportList,$
                                            /droplist_select)




                        m=self.QChoiceIndex
                        nbkg=bkgIndexList[bkgIndex]
                        ndat=datIndexList[datIndex]
                        nres=resIndexList[resIndex]
                        ;print,nbkg, ndat,nres
                        objDat = ((self.dataContainer)->get(position=m))
                        ;objDat = ((self.dataContainer)->get(position=ndat))
                        if nbkg ne 9999 then begin
                            objBkg = ((self.dataContainer)->get(position=nbkg))
                        endif else begin
                            ;objBkg = 0L
                        endelse
                        if nres ne 9999 then begin
                            objRes = ((self.dataContainer)->get(position=nres))
                        endif else begin
                        endelse
                        ;print,'Test1'
                        ;print,'Test2'


                        widget_control,self.IQTImportBase,/destroy

;                        objDat->CalculateIQT,bkgObj = objBkg,$
;                                             resObj = objRes,$
;                                             datObj = objDat
                        objDat->CalculateIQT2,bkgObj = objBkg,$
                                              resObj = objRes,$
                                              datObj = objDat
                        ;print,'Test3'

;
;032405
;MOVE THIS STATEMENT TO JUST BEFORE THE CALCULATION
;                        widget_control,self.IQTImportBase,/destroy

                    ;080604
                    ;WHY DOES THIS NEED ALL OF THE OBJECTS????
                    ;DOES IT PUT THE RESULT INTO ALL OF THE
                    ;INVOLVED OBJECTS? --- YES, THAT IS THE REASON.
                        objDat->sumQArcs,bkgObj = objBkg,$
                                         resObj = objRes,$
                                         datObj = objDat

                        ;NOW SHOULD SIMPLY DISPLAY THE
                        ;I(Q,t) CURVE WITH A CALL LIKE
                        ;

                        ;displayIQT,
                        self->displayIQT,self.QChoiceIndex
                    end;IQTOKBUTTON
        'IQTCANCELBUTTON':begin
                        widget_control,self.IQTImportBase,/destroy
                    end
        'IQTIMPORTLIST':begin
                        ;THIS METHOD SHOULD BE UNNECESSARY
                        widget_control,event.id,get_value=list
                        end
        'SETSELECTOKBUTTON':begin
                        ;THIS METHOD DOES ALL THE WORK.
;                        widget_control,self.setSelectList,get_uvalue=ssl
;                        objIndexList = ssl.indexlist

                        index=widget_info(self.setSelectList,$
                                            /droplist_select)

                        if index lt (self.setContainer)->count() then begin
                            theSetRef = (self.setContainer)->get(position=index)
                            theObjRef = (self.dataContainer)->get(position= $
                                                        self.QChoiceIndex)

                            ;PLACE CLONE INTO dataContainer
                            ;help,/heap,/brief
                            theClone = theObjRef->clone()
                            ;help,/heap,/brief
                            count = (self.dataContainer)->count()
                            ;help,/heap,/brief
                            (self.dataContainer)->add,theClone,$
                                                    position=count
                            ;help,/heap,/brief

                            ;PLACE ORIGINAL OBJECT INTO SET
                            type = theClone->getProperty(tag='type')
                            ind = count
                            fn = theClone->getProperty(tag='filename')
                            case type of
                                0:begin
                                    ;print,'SELECTED OBJECT IS UNTYPED.'
                                end
                                1:begin
                                    theSetRef->setProperty,resIndex=ind
                                    theSetRef->setProperty,resFilename = fn
                                end
                                2:begin
                                    theSetRef->setProperty,datIndex=ind
                                    theSetRef->setProperty,datFilename = fn
                                end
                                3:begin
                                    theSetRef->setProperty,bkgIndex=ind
                                    theSetRef->setProperty,bkgFilename = fn
                                    end
                                else:begin
                                    print,'OBJECT TYPE IS INVALID.'
                                end
                            endcase
                            ;theSetRef->setProperty,

                        endif
                        widget_control,self.setSelectBase,/destroy
                    end;SETSELECTOKBUTTON
        'SETSELECTCANCELBUTTON':begin
                        widget_control,self.setSelectBase,/destroy
                        end
        'SETSELECTLIST':begin
                        widget_control,event.id,get_value=list
                        end
        'SETREMOVEOKBUTTON':begin
                        index=widget_info(self.setRemoveList,$
                                            /droplist_select)

                        if index lt (self.setContainer)->count() then $
                            begin
                            ref = (self.setContainer)->get(position=index)
                            obj_destroy,ref
                            (self.setContainer)->remove,position=index

                            widget_control,self.removeSetBase,/destroy
                        endif

                        end
        'SETREMOVECANCELBUTTON':begin
                            widget_control,self.removeSetBase,/destroy
                        end
        'SETREMOVELIST':begin
                        widget_control,event.id,get_value=list
                        end
        else:begin
            end
    endcase


end;listEvents
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::displayIQTEvents,event
;
;NAME:
;        ooDisplayEcho::displayIQTEvents
;
;PURPOSE:
;           Handle events generated by the I(Q,t) display object compound widget.
;PARAMETERS:
;           event   The CWO_DISPLAYIQT_EVENT structure to handle.
;KEYWORDS:
;           none

    ;HANDLE EVENTS GENERATED BY IQT DISPLAY AND BY IT'S PARENT BASE.


;    print,tag_names(event)
;    print,event


    ;print,'ooDisplayEcho::displayIQTEvents'
    ;print,'IQT DISPLAY EVENT HANDLED IN ooDisplayEcho'

    etype = tag_names(event,/structure_name)


    case etype of
    'CWO_DISPLAYIQT_EVENT':begin



        ref=(self.dataContainer->get(position=$
                                        self.QChoiceIndex))



        ;091504
        if event.writeIQT eq 1 then begin
            ref->writeIQTASCII,self.data_dir;self.work_dir
            ;print,'ooDisplayEcho::displayIQTEvents WRITE IQT AT THIS POINT.'
        endif

        if event.write3Col eq 1 then begin
            ref->writeIQT3ColASCII,self.data_dir;self.work_dir
            ;print,'ooDisplayEcho::displayIQTEvents WRITE IQT AT THIS POINT.'
        endif

        if event.writeDAVE eq 1 then begin
            work_dir = self.data_dir
            dumval = ref->writeDAVE(work_dir = work_dir);self.work_dir)
            self.data_dir = work_dir
        endif

        if event.writeIgor eq 1 then begin
            work_dir = self.data_dir
            dumval = ref->writeIQTIgor(work_dir = work_dir);self.work_dir)
            self.data_dir = work_dir
        endif

        if event.closeIQT eq 1 then begin
            widget_control,self.IQTDisplayBase,/destroy
            obj_destroy,self.IQTDisplayObj
        endif;closeIQT

    end;'CWO_DISPLAYIQT_EVENT'
    'WIDGET_BASE':begin
        self.IQTDisplayObj->resize,event,xsize=event.x,ysize=event.y

    end
    'WIDGET_TRACKING':begin
    end
    else:begin
        print,'ooDisplayEcho::displayIQTEvents'
        print,'IQT DISPLAY EVENT HANDLED IN ooDisplayEcho'
        print,etype
        print,tag_names(event)
        print,event
    end
    endcase


end;displayIQTEvents
pro displayIQTBaseCleanup,id
;
;NAME:
;        displayIQTBaseCleanup
;
;PURPOSE:
;           Destroy the IQTDisplayObj when the close or x button
;           is pressed on that cwo.
;PARAMETERS:
;           id  The tlb of the IQTDisplayObj widget.
;KEYWORDS:
;           none


    widget_control,id,get_uvalue=uval
    self = uval.object
    obj_destroy,self.IQTDisplayObj

end;displayIQTBaseCleanup

pro ooDisplayEcho::displayIQT_NEW,n,_Extra=extra
;
;NAME:
;        ooDisplayEcho::displayIQT_NEW
;
;PURPOSE:
;               Pass the current data object to the I(Q,T) display object widget
;               and create the widget if it does not currently exist.
;PARAMETERS:
;               n   The position of the current object in the data container.
;KEYWORDS:
;               none.

;help,/traceback


    ;PLAN:
    ;
    ;   1) PUSH NEW OBJECT INTO cwo_displayiqt_improved OBJECT,
    ;      LET THE cwo_displayiqt_improved CLASS DO CHECKING AND PUSHING.

    datRef = (self.dataContainer->get(position=n))

    self.IQTDisplayBase = cwo_displayIQT_improved(parent,obj=obj,group_leader=self.atlb,$
                                                       dataobject=datref,$
                                                       workdir=self.work_dir,$
                                                       datadir=self.data_dir,$
                                                       _Extra=extra)
    self.IQTDisplayObj = obj

end;displayIQT_NEW




pro ooDisplayEcho::displayIQT,n
;
;NAME:
;        ooDisplayEcho::displayIQT
;
;PURPOSE:
;               Pass the current data object to the I(Q,T) display object widget
;               and create the widget if it does not currently exist.
;PARAMETERS:
;               n   The position of the current object in the data container.
;KEYWORDS:
;               none.

help,/traceback

;PLAN:
;
;   1) SEARCH FOR AN EXISTING --- OR JUST LET THE cwo_displayiqt_improved CLASS DO CHECKING AND PUSHING.
;
;   2) PUSH NEW OBJECT INTO cwo_displayiqt_improved OBJECT.
;
;   3)

    datRef = (self.dataContainer->get(position=n))

    if !version.os ne 'Win32' then begin
        resizing = 1
    endif else begin
        resizing = 1
    endelse


    device,get_screen_size=sz
    if widget_info(self.IQTDisplayBase,/valid_id) eq 0 then begin
        self.IQTDisplayBase = widget_base(group_leader = self.atlb,/row,$
                                            floating=1,$
					    xoffset = 50, yoffset=50,$
                                            tlb_size_events=resizing,$
                                            $;xsize=sz[0]/2,ysize=sz[1]/2,$
                                            title=datRef->getProperty(tag='filename'),$
                                            uvalue={object:self,$
                                                    method:'displayIQTEvents',$
                                                    id:'IQTDISPLAYBASE'})

	;CHECK WITH RICHARD THAT THIS IS AVAILABLE IN DAVE
	;centertlb,self.IQTdisplaybase
    endif


    ;print,'ooDisplayEcho::displayIQT'
    ;help,datRef
    c=cwo_displayIQT(self.IQTDisplayBase,datRef,obj_ref=cwoRef,$
                        uvalue = {object:self,$
                                  method:'displayIQTEvents',$
                                  id:'DISPLAYIQT'},$
                                  cleanup='DisplayIQTBaseCleanup')



;;THIS IS WHERE THE DATA ARE INITIALLY PASSED INTO cwo_displayIQT_Improved
;    c=cwo_displayIQT_Improved(self.IQTDisplayBase,datRef,obj_ref=cwoRef,$
;                        uvalue = {object:self,$
;                                  method:'displayIQTEvents',$
;                                  id:'DISPLAYIQT'},$
;                                  cleanup='DisplayIQTBaseCleanup')
;help,/traceback


    if widget_info(c,/valid_id) gt 0 then begin
        ;NEED TO PREVENT MULTIPLE INSTANCES OF THIS.
        ;SIMPLY SEND CURRENT DATA OBJ REF TO THE cwo
        ;AND CALL ITS draw METHOD IF THE cwo ALREADY EXISTS.
        ;
        ;OR, I CAN MAKE THE cwo A SINGLETON AND
        ;UPDATE THE DATA OBJECT EACH TIME IT IS CHANGED
        ;
        ;AND/OR I CAN HAVE A CONTAINER FOR MULTIPLE DATA OBJECTS.
        ;

        self.IQTDisplayObj = cwoRef

        widget_control,self.IQTDisplayBase,/realize

        cwoRef->draw;,datRef
        xmanager,"ooDisplayEcho",self.IQTDisplayBase,/no_block;,$
                            ;cleanup='DisplayIQTBaseCleanup'
    endif else begin
        ;print,'AN IQT Display OBJECT ALREADY EXISTS.'

    ;
    ;PROBLEM TO SOLVE:  THE NUMBER OF FOURIER TIMES AND Q VALUES ARE LIKELY
    ;TO BE DIFFERENT FOR EACH OF THE DATA OBJECTS.
    ;
    ;THIS IS A PROBLEM FOR THE cwo_displayiqt CLASS.


    ;FOR A SINGLETON, THE OBJECT SHOULD TAKE CARE OF ITSELF HERE.
;        self.IQTDisplayObj->addData,datRef


    endelse



end;displayIQT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::setBeamCenter,ifrom,ito
;
;NAME:
;        ooDisplayEcho::setBeamCenter
;
;PURPOSE:
;           Set the 'ito' beam center to be the same as the 'ifrom' beam center.
;PARAMETERS:
;           ifrom   The datacontainer position of the object with the beam center value.
;           ito     The datacontainer position of the object to set the beam center value.
;KEYWORDS:
;           none

            ;SET ALL BEAM CENTERS TO SAME VALUE ASSUMING THAT
            ;ALL OF THE DATA WILL HAVE THE SAME BEAM POSITION

            ;050704
            ;
            ;DURING DEMO THEY SAID TO USE SAME BEAM CENTER
            ;FOR A GIVEN WAVELENGTH.  SET ALL BEAM CENTERS
            ;TO SAME VALUE FOR A GIVEN WAVELENGTH.
            ;DO THIS FOR ATWBCX AND ATWBCY.
            ;
            ;NEED TO CLARIFY WHICH VALUE OF THE BEAM CENTER
            ;WILL BE USED (32x32 or 16x16, etc.)  FOR NOW
            ;ASSUME THAT THE CENTERS WILL BE SPECIFIED IN
            ;PIXELS AT CURRENT BINNING.
            ;
            ;ALSO NEED TO DO THIS ON READING A NEW FILE!!!
            ;
            lambdao = (self.dataContainer->get(position=$
                        ifrom))->getProperty(tag='lambda')


            lambda = $
                (self.dataContainer->get(position=$
                        ito))->getProperty(tag='lambda')
                ;print,lambda

            if lambda eq lambdao then begin
                ;GET ORIGINAL AND CURRENT IMAGE BINNINGS
                ;
                ;ASSUMES X,Y BINNINGS EQUAL.
                x_dim_orig = $
                (self.dataContainer->get(position=$
                        ito))->getProperty(tag='x_dim_orig')
                x_dim = $
                (self.dataContainer->get(position=$
                        ito))->getProperty(tag='x_dim')


                ;SET THE ORIGINAL BEAM CENTER (NO BINNING)
                (self.dataContainer->get(position=$
                        ito))->setProperty,'x_cen_orig',$
                        (self.dataContainer->get(position=$
                                ifrom))->getProperty(tag='x_cen_orig')
                (self.dataContainer->get(position=$
                        ito))->setProperty,'y_cen_orig',$
                        (self.dataContainer->get(position=$
                                ifrom))->getProperty(tag='y_cen_orig')
                ;SET THE BEAM CENTER FOR THE CURRENT BINNING
                (self.dataContainer->get(position=$
                        ito))->setProperty,'x_cen',$
                        (self.dataContainer->get(position=$
                                ifrom))->getProperty(tag='x_cen_orig')*$
                                (double(x_dim)/double(x_dim_orig))
                (self.dataContainer->get(position=$
                        ito))->setProperty,'y_cen',$
                        (self.dataContainer->get(position=$
                                ifrom))->getProperty(tag='y_cen_orig')*$
                                (double(x_dim)/double(x_dim_orig))
            endif;lambda eq lambdao

end;setBeamCenter
;function ooDisplayEcho::restoreSession
;MOVED TO SEPARATE FILE
;end;restoreSession
;function ooDisplayEcho::saveSession,xml=xml,sav=sav
;MOVED TO SEPARATE FILE
;end;saveSession

pro ooDisplayEcho::fileOpen,filename=filename
;
;NAME:
;        ooDisplayEcho::fileOpen
;
;PURPOSE:
;           Do the work for fileOpen
;PARAMETERS:
;           event   The button event structure to handle.
;KEYWORDS:
;           filename    Name of files to open





        if n_elements(filename) ne 0 then begin
            tempFilename = filename
        endif else begin
            tempFilename = dialog_pickfile(/read,$
                                            /must_exist,$
                                            filter='*.echo',$
                                            path=self.data_dir,$
                                            /multiple_files,$
                                            title='Select .echo files:')
        endelse


        if tempFilename[0] ne '' then begin

          ;PROGRESS BAR
          readerBase = widget_base(xoffset=300,$
                                   yoffset=300,/floating,group_leader=self.atlb)


          prog = cw_progress(readerBase,$
                                value=[n_elements(tempFilename)],$
                                title='File# ')

          widget_control,readerBase,/realize
          for n=0,n_elements(tempFilename)-1 do begin
            self.data_dir = file_dirname(tempFilename[n],$
                                        /mark_directory)
            ;ADD NEW DATA OBJECT TO dataContainer
            ;
            ;WHAT HAPPENS IF FILE DOES NOT EXIST?????
            count = self.dataContainer->count()

            widget_control,self.atwnarcs,get_value = narcs

            temp = obj_new('ooEchoMagnetic',filename = tempFilename[n],$
                                                narcs = fix(narcs),magnetic=0)



            help,temp,output = tout

            if not stregex(tout,'NULL',/fold_case,/boolean) then begin

                ;NOW THAT A VALID DATA OBJECT HAS BEEN CREATED, SET THE time average
                ;state to 0 (i.e. NOT TIME AVERAGED.)
                widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,set_value= 0


                temp->bin,factor=2


                ;092404
                ;UPDATE THE GAUSSIAN WIDTH WITH THE CURRENT
                ;VALUE FOR EACH NEW FILE READ IN.
                widget_control,self.atwwidth,get_value=swidth
                temp->setWidth,double(swidth)
                temp->setproperty,'workdir',self.work_dir
                temp->setproperty,'datadir',self.data_dir

                self.gaussianwidth = double(swidth)


                ;121905
                ;REMOVING t=0.0 BEFORE ADDING TO DISPLAY.
                thetimes = *(temp->getproperty(tag='fouriertime'))
                if (where(thetimes eq 0.0))[0] ne -1 then begin
                    newtemp = temp->removeT(0.0,/firstread)
                    self.dataContainer->add,newtemp,position = count
                    obj_destroy,temp
                endif else begin
                    self.dataContainer->add,temp,position = count
                endelse


                ;SET BEAM CENTER VALUES HERE BASED ON
                ;MATCHING LAMBDA

                lambda = (self.dataContainer->get(position= $
                        count))->getProperty(tag='lambda')
                for i=0,count-1 do begin
                    lambdao = (self.dataContainer->get(position=$
                            i))->getProperty(tag='lambda')
                    if lambda eq lambdao then begin
                        self->setBeamCenter,i,count
                    endif
                endfor;i
              endif else begin;not stregex
                dum = dialog_message('INSUFFICIENT DATA IN FILE '+tempfilename[n])
              endelse
              widget_control,prog,set_value=[n]
          endfor;n (MULTIPLE FILES)
          if not stregex(tout,'NULL',/fold_case,/boolean) then begin

              self->setDataParameters,$
                self.dataContainer->get(position=count),$
                    n = count
          endif;not stregex

        the_count = self.datacontainer->count()
;                        print,the_count
        if the_count gt 0 then begin
;113005
;add the newsize flag
              self->reDefineWidgets,count,/newsize
              self->redefineTree
              self->draw
        endif;the_count
          widget_control,readerBase,/destroy

        endif else begin
        endelse


end;ooDisplayEcho::fileOpen


pro ooDisplayEcho::menuEvents,event
;
;NAME:
;        ooDisplayEcho::menuEvents
;
;PURPOSE:
;           Handle events from the file menu.  Several of the context menus also send events here.
;PARAMETERS:
;           event   The button event structure to handle.
;KEYWORDS:
;           none
;
    widget_control,event.id,get_uvalue=obj

    case (obj.parent) of
        'FILEOPTIONS': begin
            case (obj.id) of
                'FILEOPEN': begin
                        widget_control,self.tw1,$
                            set_value=obj.id+':'+tag_names(event)
                        self->fileOpen

;                        ;063004
;                        ;SET UP TO READ MULTIPLE FILES.
;
;                        tempFilename = dialog_pickfile(/read,$
;                                                        /must_exist,$
;                                                        filter='*.echo',$
;                                                        path=self.data_dir,$
;                                                        /multiple_files)
;
;                        ;NEED TO USE THE CLONE METHOD HERE.
;                        ;SIMPLY REASSIGNING THE OBJECT REFERENCES WON'T
;                        ;WORK HERE.
;                        ;
;                        ;ALTERNATIVELY, THIS IS A GOOD TIME TO LEARN
;                        ;ABOUT o = obj_new('IDL_container')
;                        ;
;
;                        if tempFilename[0] ne '' then begin
;
;                          ;PROGRESS BAR
;                          readerBase = widget_base(xoffset=300,$
;                                                   yoffset=300,/floating,group_leader=self.atlb)
;
;
;                          prog = cw_progress(readerBase,$
;                                                value=[n_elements(tempFilename)],$
;                                                title='File# ')
;
;                          widget_control,readerBase,/realize
;                          for n=0,n_elements(tempFilename)-1 do begin
;                            self.data_dir = file_dirname(tempFilename[n],$
;                                                        /mark_directory)
;                            ;ADD NEW DATA OBJECT TO dataContainer
;                            ;
;                            ;WHAT HAPPENS IF FILE DOES NOT EXIST?????
;                            count = self.dataContainer->count()
;
;                            widget_control,self.atwnarcs,get_value = narcs
;
;;                            temp = obj_new('ooEcho',filename = tempFilename[n],narcs = fix(narcs))
;
;
;;102205
;
;
;;COMMITTED THE CODE WITH THE FOLLOWING LINE.
;;FIXED AND REPLACED WITH ABOVE LINE IN THE REPOSITORY.
;
;                            temp = obj_new('ooEchoMagnetic',filename = tempFilename[n],$
;                                                                narcs = fix(narcs),magnetic=0)
;
;
;
;                            help,temp,output = tout
;                            ;print,obj_valid(temp)
;
;                            if not stregex(tout,'NULL',/fold_case,/boolean) then begin
;
;                                ;NOW THAT A VALID DATA OBJECT HAS BEEN CREATED, SET THE time average
;                                ;state to 0 (i.e. NOT TIME AVERAGED.)
;                                widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,set_value= 0
;
;
;                                ;092404
;                                ;CHANGE DEFAULT BINNING FORM 2 TO 4
;                                ;031505
;                                ;CHANGE DEFAULT BINNING BACK TO 2
;                                temp->bin,factor=2
;;DO NOT APPLY TIME AVERAGING AT THIS STAGE UNLESS IT IS LATER REQUESTED.
;
;
;                                ;092404
;                                ;UPDATE THE GAUSSIAN WIDTH WITH THE CURRENT
;                                ;VALUE FOR EACH NEW FILE READ IN.
;                                widget_control,self.atwwidth,get_value=swidth
;                                temp->setWidth,double(swidth)
;                                temp->setproperty,'workdir',self.work_dir
;                                temp->setproperty,'datadir',self.data_dir
;
;                                self.gaussianwidth = double(swidth)
;
;
;;print,'IN ooDisplayEcho::menuEvents FILEOPEN'
;                                ;121905
;                                ;REMOVING t=0.0 BEFORE ADDING TO DISPLAY.
;                                thetimes = *(temp->getproperty(tag='fouriertime'))
;                                if (where(thetimes eq 0.0))[0] ne -1 then begin
;                                    newtemp = temp->removeT(0.0,/firstread)
;                                    self.dataContainer->add,newtemp,position = count
;                                    obj_destroy,temp
;                                endif else begin
;                                    self.dataContainer->add,temp,position = count
;                                endelse
;
;;                                self.dataContainer->add,temp,position = count
;                                ;obj_destroy,temp
;
;                                ;SET BEAM CENTER VALUES HERE BASED ON
;                                ;MATCHING LAMBDA
;
;                                lambda = (self.dataContainer->get(position= $
;                                        count))->getProperty(tag='lambda')
;                                for i=0,count-1 do begin
;                                    lambdao = (self.dataContainer->get(position=$
;                                            i))->getProperty(tag='lambda')
;                                    if lambda eq lambdao then begin
;                                        self->setBeamCenter,i,count
;                                    endif
;                                endfor;i
;                              endif else begin;not stregex
;                                dum = dialog_message('INSUFFICIENT DATA IN FILE '+tempfilename[n])
;                              endelse
;                              widget_control,prog,set_value=[n]
;                          endfor;n (MULTIPLE FILES)
;                          if not stregex(tout,'NULL',/fold_case,/boolean) then begin
;
;                              self->setDataParameters,$
;                                self.dataContainer->get(position=count),$
;                                    n = count
;                          endif;not stregex
;
;                        the_count = self.datacontainer->count()
;;                        print,the_count
;                        if the_count gt 0 then begin
;;113005
;;add the newsize flag
;                              self->reDefineWidgets,count,/newsize
;                              self->redefineTree
;                              self->draw
;                        endif;the_count
;                          widget_control,readerBase,/destroy
;
;                        endif else begin
;                        endelse

                    end;FILEOPEN
                'FILEOPENMAGNETIC': begin

                        ;print,'USING "FILEOPENMAGNETIC" HANDLER FOR THIS BUTTON.'
                        widget_control,self.tw1,$
                            set_value=obj.id+':'+tag_names(event)


                        ;063004
                        ;SET UP TO READ MULTIPLE FILES.

                        tempFilename = dialog_pickfile(/read,$
                                                        /must_exist,$
                                                        filter='*.echo',$
                                                        path=self.data_dir,$
                                                        /multiple_files)

                        ;NEED TO USE THE CLONE METHOD HERE.
                        ;SIMPLY REASSIGNING THE OBJECT REFERENCES WON'T
                        ;WORK HERE.
                        ;
                        ;ALTERNATIVELY, THIS IS A GOOD TIME TO LEARN
                        ;ABOUT o = obj_new('IDL_container')
                        ;

                        if tempFilename[0] ne '' then begin

                          ;PROGRESS BAR
                          readerBase = widget_base(xoffset=300,$
                                                   yoffset=300,/floating,group_leader=self.atlb)


                          prog = cw_progress(readerBase,$
                                                value=[n_elements(tempFilename)],$
                                                title='File# ')

                          widget_control,readerBase,/realize
                          for n=0,n_elements(tempFilename)-1 do begin
                            self.data_dir = file_dirname(tempFilename[n],$
                                                        /mark_directory)
                            ;ADD NEW DATA OBJECT TO dataContainer
                            ;
                            ;WHAT HAPPENS IF FILE DOES NOT EXIST?????
                            count = self.dataContainer->count()

                            widget_control,self.atwnarcs,get_value = narcs

                            temp = obj_new('ooEchoMagnetic',filename = tempFilename[n],$
                                                                narcs = fix(narcs),$
                                                                magnetic=1)


                            help,temp,output = tout
                            ;print,obj_valid(temp)

                            if not stregex(tout,'NULL',/fold_case,/boolean) then begin
                                temp->bin,factor=2
;DO NOT APPLY TIME AVERAGING AT THIS STAGE UNLESS IT IS LATER REQUESTED.

                                ;UPDATE THE GAUSSIAN WIDTH WITH THE CURRENT
                                ;VALUE FOR EACH NEW FILE READ IN.
                                widget_control,self.atwwidth,get_value=swidth
                                temp->setWidth,double(swidth)
                                temp->setproperty,'workdir',self.work_dir
                                temp->setproperty,'datadir',self.data_dir


                                self.gaussianwidth = double(swidth)

                                ;121905
;print,'IN ooDisplayEcho::menuEvents FILEOPENMAGNETIC'
                                ;REMOVING t=0.0 BEFORE ADDING TO DISPLAY.
                                newtemp = temp->removeT(0.0,/read)
                                self.dataContainer->add,newtemp,position = count
                                obj_destroy,temp
;                                self.dataContainer->add,temp,position = count

                                ;SET BEAM CENTER VALUES HERE BASED ON
                                ;MATCHING LAMBDA
                                lambda = (self.dataContainer->get(position= $
                                        count))->getProperty(tag='lambda')
                                for i=0,count-1 do begin
                                    lambdao = (self.dataContainer->get(position=$
                                            i))->getProperty(tag='lambda')
                                    if lambda eq lambdao then begin
                                        self->setBeamCenter,i,count
                                    endif
                                endfor;i
                              endif else begin;not stregex
                                dum = dialog_message('INSUFFICIENT DATA IN FILE '+tempfilename[n])
                              endelse
                              widget_control,prog,set_value=[n]
                          endfor;n (MULTIPLE FILES)
                          if not stregex(tout,'NULL',/fold_case,/boolean) then begin

                              self->setDataParameters,$
                                self.dataContainer->get(position=count),$
                                    n = count
                          endif;not stregex

                        the_count = self.datacontainer->count()
                        if the_count gt 0 then begin

;112805
;ADD THE NEXT LINE SO THAT THE MAGNETIC AND OTHER WIDGETS ARE UPDATED
;WHEN A SESSION FILE IS READ.
                              self->setDataParameters,ref,n=the_count-1;self.QChoiceIndex
;113005
;add the newsize flag
                              self->reDefineWidgets,count,/newsize
                              self->redefineTree
                              self->draw
                        endif;the_count
                          widget_control,readerBase,/destroy

                        endif else begin
                        endelse

                    end;FILEOPENMAGNETIC
                'FILESAVE': begin
                        widget_control,self.tw1,$
                            set_value=obj.id+':'+tag_names(event)
                    end;FILESAVE
                'SAVESESSION':begin
                    widget_control,self.tw1,$
                        set_value=obj.id+':'+tag_names(event)

                    ;AS OF 072505 ONLY ALLOW .sav FILES FOR SESSION SAVE
                    self.state_saved = self->saveSession(/sav)


                end;SAVESESSION
                'RESTORESESSION':begin
                    widget_control,self.tw1,$
                        set_value=obj.id+':'+tag_names(event)

                    if self.datacontainer->count() ne 0 then begin
                        rslt1 = self->savesession(/prerestore)
                    endif
                    rslt2 = self->restoreSession()

;;031805
;;NEED TO ADD ERROR CHECKING HERE FOR THE DATA IN THE FILE.
;;
;;NO TIME TODAY...
;
;;MAYBE point_lun CAN MAKE THIS BACKWARD COMPATIBLE.
;;TO CREATE BACKWARD COMPATIBILITY, ADD FUTURE NEW VALUES
;;TO THE END OF THE FILE ON SAVE COMMANDS.
;;THEN OLDER VERSIONS OF THE READER WILL NOT SEE THESE.
;;ONCE IDL 6.1 IS USED FOR DAVE, THESE VALUES WILL BE
;;RETRIEVED USING THE IDLffXMLDOM CLASSES.
;
                if rslt2 gt 0 then begin
;112805
;ADD THE NEXT LINE SO THAT THE MAGNETIC AND OTHER WIDGETS ARE UPDATED
;WHEN A SESSION FILE IS READ.
                              ref = self.datacontainer->get(position=0)
                              self->setDataParameters,ref,n=0;self.QChoiceIndex
                    self->reDefineWidgets,count,t=0,/newsize
                    self->redefineTree
                    self->draw
                endif



                end;RESTORESESSION
                'SAVEOBJECT':begin
                    widget_control,self.tw1,$
                        set_value=obj.id+':'+tag_names(event)

                    ref=(self.dataContainer->get(position=$
                                        self.QChoiceIndex))
                    if obj_valid(ref) then begin
                        print,self->savesession(/sav,index=self.QChoiceIndex)
                    endif else begin
                        void = dialog_message('ooDisplayEcho::menuevents INVALID DATA OBJECT')
                    endelse
                end;SAVEOBJECT
                'RESTOREOBJECT':begin
                    widget_control,self.tw1,$
                        set_value=obj.id+':'+tag_names(event)

;072505
;HERE I NEED TO CHANGE THE RESTORE TO CALL self->restoreSession(/OBJECT)
;WHERE THE OBJECT OPTION ELIMINATES THE DESTRUCTION OF THE OBJECTS IN THE
;CONTAINER, THE SINGLE OBJECT IS REMOVED FROM THE RESTORED CONTAINER AND PLACED
;IN THIS ONE, AND NONE OF THE OTHER VALUES ARE RESTORED INTO THE OBJECT DATA MEMBERS
                    result = self->restoresession(/object)


                    if result gt 0 then begin
                        self->reDefineWidgets,count,t=0,/newsize
                        self->redefineTree
                        self->draw
                    endif else begin
                        void = dialog_message('This is not a valid NSE saved object.')
                    endelse

                    ;endelse

                end;RESTOREOBJECT


                'FILEPHASEEXPORT':begin
                        widget_control,self.tw1,$
                            set_value=obj.id+':'+tag_names(event)
                        tempfn = dialog_pickfile(/write,$
                                                title='Phase export file',$
                                                path=self.work_dir,$
                                                /overwrite_prompt)

                        if tempfn ne '' then begin
                            self.work_dir = file_dirname(tempfn,/mark_directory)
                            openw,lun,tempfn,/get_lun

                            ref=(self.dataContainer->get(position=$
                                                self.QChoiceIndex))
                            pparms = ref->getProperty(tag='fitparms')

                            printf,lun,(*pparms)[2,*,*]

                            free_lun,lun,/force
                        endif else begin
                            void = dialog_message('No output file selected!')
                        endelse
                    end;FILEPHASEEXPORT
                'FILEPHASEIMPORT':begin
                        widget_control,self.tw1,$
                            set_value=obj.id+':'+tag_names(event)

                        tempfn = dialog_pickfile(/read,$
                                                title='Phase import file:',$
                                                path=self.work_dir,$
                                                /must_exist)

                        if tempfn ne '' then begin
                            self.work_dir = file_dirname(tempfn,/mark_directory)
                            openr,lun,tempfn,/get_lun

                            ref=(self.dataContainer->get(position=$
                                                self.QChoiceIndex))
                            pparms = ref->getProperty(tag='fitparms')

                            tmp = (*(ref->getProperty(tag='fitparms')))[2,*,*]
                            readf,lun,tmp

                            ;print,tmp
                            (*(ref->getProperty(tag='fitparms')))[2,*,*] = tmp
                            ;print,(*(ref->getProperty(tag='fitparms')))[2,*,*]
                            free_lun,lun,/force
                        endif else begin
                            void = dialog_message('No file selected.')
                        endelse


                    end;FILEPHASEIMPORT
                'FILEFITPARMEXPORT':begin
                        widget_control,self.tw1,$
                            set_value=obj.id+':'+tag_names(event)
                        tempfn = dialog_pickfile(/write,$
                                                title='Parameter export file:',$
                                                path=self.work_dir,$
                                                /overwrite_prompt)

                        if tempfn ne '' then begin
                            self.work_dir = file_dirname(tempfn,/mark_directory)
                            openw,lun,tempfn,/get_lun

                            ref=(self.dataContainer->get(position=$
                                                self.QChoiceIndex))
                            pparms = ref->getProperty(tag='fitparms')

                            printf,lun,(*pparms)[*,*,*]

                            free_lun,lun,/force
                        endif else begin
                            void = dialog_message('No file selected.')
                        endelse

                    end;FILEFITPARMEXPORT
                'FILEFITPARMIMPORT':begin
                        widget_control,self.tw1,$
                            set_value=obj.id+':'+tag_names(event)
                        tempfn = dialog_pickfile(/read,$
                                                title='Parameter import file:',$
                                                path=self.work_dir,$
                                                /must_exist)
                        if tempfn ne '' then begin
                            self.work_dir = file_dirname(tempfn,/mark_directory)
                            openr,lun,tempfn,/get_lun

                            ref=(self.dataContainer->get(position=$
                                                self.QChoiceIndex))
;                            pparms = ref->getProperty(tag='fitparms')

                            tmp = (*(ref->getProperty(tag='fitparms')))[*,*,*]
                            readf,lun,tmp

                            ;print,tmp
                            (*(ref->getProperty(tag='fitparms')))[*,*,*] = tmp
                            ;print,(*(ref->getProperty(tag='fitparms')))[*,*,*]
                            free_lun,lun,/force
                        endif else begin
                            void = dialog_message('No file selected.')
                        endelse
                    end;FILEFITPARMEXPORT
                'FILEIQTEXPORT':begin

                        ;091504
                        ;
                        ;UPDATING WRITE ASCII TO INCLUDE MORE
                        ;INFORMATION IN THE EXPORTED FILE.

                        ref=(self.dataContainer->get(position=$
                                            self.QChoiceIndex))
                        ref->writeIQTASCII,self.work_dir


                    end;FILEIQTEXPORT
                'FILEIQTDAVEEXPORT':begin
                        widget_control,self.tw1,$
                            set_value=obj.id+':'+tag_names(event)
                        tempfn = dialog_pickfile(/write,$
                                                title='I(Q,t) DAVE file:',$
                                                path=self.work_dir,$
                                                /overwrite_prompt)
                        self.work_dir = file_dirname(tempfn,/mark_directory)
                        ref=(self.dataContainer->get(position=$
                                            self.QChoiceIndex))

                ;120704
                ;HANDLE THE NEXT LINE IN ooEcho::writeDave
;                        if tempfn eq '' then begin
;                            fn = ref->getProperty(tag='filename')
;                            tempfn = fn+'IQT_DAVE_format.dave'
;                        endif
                        result = ref->writeDave(tempfn)

                    end;FILEIQTDAVEEXPORT

                'FILEPARAMETERSIMPORT':begin
                    self->readparametersfile
                end;FILEPARAMETERSIMPORT
                'FILEPARAMETERSEXPORT':begin
                    self->writeparametersfile
                end;FILEPARAMETERSEXPORT
                'FILEQUIT': begin
                        print,obj.id+':',tag_names(event)
                        print,obj.id+':',event

                        widget_control,self.atlb,/destroy
                        ;ooDisplayEchoCleanup,self.atlb
                    end;FILEQUIT
                else:   begin
                            widget_control,self.tw1,$
                            set_value="UNSURE OF FILEMENU CHOICE"
                        end
            endcase;obj.parent eq 'FILEOPTIONS'
        end;FILEOPTIONS
        'PLOTOPTIONS':begin
            plotzoomswitch = self.plotzoomswitch
            self.plotzoomswitch = 0
            case (obj.id) of
                'IVPHASE':begin
                        self.plotindex = 0
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;IVPHASE
                'FITPHASEVTAU':begin
                        self.plotindex = 1
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;FITPHASEVTAU
                'BXVPHASE':begin
                        self.plotindex = 2
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;BXVPHASE
                'BYVPHASE':begin
                        self.plotindex = 3
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;BYVPHASE
                'BZVPHASE':begin
                        self.plotindex = 4
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;BZVPHASE
                'ALLVPHASE':begin
                        self.plotindex = 5
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;ALLVPHASE
                'FITAMPVTAU':begin
                        self.plotindex=6
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;FITAMPVTAU
                'CONTOURECHO':begin
                        self.plotindex=7
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;CONTOURECHO
                'SIGNALVTAU':begin
                        self.plotindex=8
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;SIGNALVTAU
                'MAGNETICPLOT':begin
;112805
;MAGNETICPLOT_MENU
                        self.plotindex=9
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;MAGNETICPLOT
                'MAGNETICPLOTPIXEL':begin
;020606
;MAGNETICPLOT_MENU
                        self.plotindex=10
                        widget_control,self.tw1,set_value=$
                                obj.id+strtrim(string(self.plotindex),2)
                        self->draw
                    end;MAGNETICPLOTPIXEL

                'TOGGLEUPDOWN':begin
                        if self.plotupdown eq 1 then begin
                            self.plotupdown = 0
                        endif else begin
                            self.plotupdown = 1
                        endelse
                        self->draw
                    end;TOGGLEUPDOWN
                'TOGGLEAUXPLOT':begin
                        self.plotzoomswitch = plotzoomswitch
                        if widget_info(self.dw2auxbase,/valid_id) gt 0 then begin
                            self->lowerAuxWindow
                        endif else begin
                            self->raiseAuxWindow
                            self->draw
                        endelse

                    end;TOGGLEAUXPLOT
                'WRITEPLOTDATA':begin
                            fn = dialog_pickfile(title='Plot data output file:',$
                                                 path = self.work_dir,$
                                                 /overwrite_prompt)
                            if fn ne '' then begin
                                print,fn
                                self->draw,/writeplotdataflag,writeplotdatafile=fn
                            endif

                    end;WRITEPLOTDATA
                'EXPANDPLOTRANGES':begin

                    ;print,self.plotxmin,self.plotxmax,self.plotymin,self.plotymax
                    if self.plotzoomswitch eq 0 then begin


                        !x = *self.w2xptr
                        !y = *self.w2yptr

                        if !x.type eq 0 then begin
                            xrange = !x.crange
                        endif else begin
                            xrange = (10.0d)^(!x.crange)
                        endelse
                        if !y.type eq 0 then begin
                            yrange = !y.crange
                        endif else begin
                            yrange = (10.0d)^(!y.crange)
                        endelse

                        self.plotxmin = xrange[0]
                        self.plotxmax = xrange[1]
                        self.plotymin = yrange[0]
                        self.plotymax = yrange[1]
                    endif

                    self.plotzoomswitch = 1

                    xmin = self.plotxmin;:10000.0,$
                    xmax = self.plotxmax;:-10000.0,$     ;SAVE THE PLOT RANGES IN CASE OF ZOOM.
                    ymin = self.plotymin;:10000.0,$
                    ymax = self.plotymax;:-10000.0,$


                    dxrange = xmax - xmin
                    dyrange = ymax - ymin


                    self.plotxmin = xmin; - 0.1*dxrange
                    self.plotxmax = xmax; + 0.1*dxrange
                    self.plotymin = ymin - 0.1*dyrange
                    self.plotymax = ymax + 0.1*dyrange

                    ;print,self.plotxmin,self.plotxmax,self.plotymin,self.plotymax
                    self->draw

                 end;EXPANDPLOTRANGES
                'UNZOOMPLOT':begin
                    self.plotzoomswitch = 0
                    self->draw
                end;UNZOOMPLOT
                else:   begin
                            widget_control,self.tw1,$
                            set_value="UNSURE OF PLOTMENU CHOICE"
                        end
            endcase;obj.parent eq 'PLOTOPTIONS'
        end;PLOTOPTIONS
        'IMAGEOPTIONS': begin
            case (obj.id) of
                'SOF0':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id

                        self.displayIndex = 0
                        self->draw
                        self->lowerSlider

                    end;SOF0
                'SIGNALIMAGE':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id

                        self.displayIndex = 8
                        self->draw
                        self->lowerSlider
                end;'SIGNALIMAGE'
                'FITCONSTANT':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id

                        self.displayIndex = 1
                        self->draw
                        self->lowerSlider
                    end;FITCONSTANT
                'FITAMPLITUDE':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id

                        self.displayIndex = 2
                        self->draw
                        self->lowerSlider
                    end;FITAMPLITUDE
                'FITPHASE':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                        if widget_info(self.clickrefitslider,/valid_id) ne 0 then begin
                            ;widget_control,self.clickrefitslider,/destroy
                        endif else begin
                            self->raiseSlider
                        endelse


                        self.displayIndex = 3
                        self->draw
                    end;FITPHASE
                'FITWIDTH':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id

                        self.displayIndex = 4
                        self->lowerSlider
                        self->draw
                    end;FITWIDTH
                'FITOMEGA':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id

                        self.displayIndex = 5
                        self->draw
                        self->lowerSlider
                    end;FITOMEGA
                'FITPHASEOFFSET':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                        self.displayIndex = 6
                        self->draw
                        self->lowerSlider
                    end;FITPHASEOFFSET
                'FITCHISQ':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                        self.displayIndex = 7
                        self->draw
                        self->lowerSlider
                    end
                'MAGNETIC_CASE_0':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                        self.displayIndex = 9
                        self->draw
                        self->lowerSlider
                    end
                'MAGNETIC_CASE_1':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                        self.displayIndex = 10
                        self->draw
                        self->lowerSlider
                    end
                'MAGNETIC_CASE_2':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                        self.displayIndex = 11
                        self->draw
                        self->lowerSlider
                    end
                'MAGNETIC_CASE_3':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                        self.displayIndex = 12
                        self->draw
                        self->lowerSlider
                    end
                'IMAGEERRORBARS':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id

                        ;SWITCH IMAGE OPTIONS MENUS
                        idmenu = widget_info(self.atlb,find_by_uname="IMAGEERRORBARSMENU")

                        idcontext = widget_info(self.dw1,find_by_uname="IMAGEERRORBARSCONTEXT")



                        ;RESYNC THE STATE OF THE ERROR IMAGE IN CASE IT WAS X'ed OUT.
                        if widget_info(self.imageerrorbase,/valid_id) eq 0 then begin
                            if self.errorImageChoice eq 1 then begin
                                self.errorImageChoice = 0
                                widget_control,idmenu,set_value='Display Image Error Bars'
                                widget_control,idcontext,set_value='Display Image Error Bars'
                            endif
                        endif else begin
                            if self.errorImageChoice eq 0 then begin
                                self.errorImageChoice = 1
                                widget_control,idmenu,set_value='Turn Off Image Error Display'
                                widget_control,idcontext,set_value='Turn Off Image Error Display'
                            endif
                        endelse

                        if self.errorImageChoice eq 0 then begin
                            widget_control,idmenu,$
                                        set_value='Turn Off Image Error Display'
                            widget_control,idcontext,$
                                        set_value='Turn Off Image Error Display'

                            ;NOW DEFINE DRAW WIDGETS FOR IMAGE ERROR DISPLAY
                            self->defineImageErrorBase
                        endif else begin
                            widget_control,idmenu,set_value='Display Image Error Bars'
                            widget_control,idcontext,set_value='Display Image Error Bars'
                            widget_control,self.imageerrorbase,/destroy
                        endelse

                        self->draw
                        if widget_info(self.clickrefitslider,/valid_id) ne 0 $
                            and self.displayindex ne 3 then begin
                            widget_control,self.clickrefitslider,$
                                            get_value=crsval


                            widget_control,self.clickrefitslider,/destroy
                        endif
                    end;IMAGEERRORBARS
                else:   begin
                            widget_control,self.tw1,$
                                set_value="UNSURE OF IMAGEMENU CHOICE"
                        end
            endcase;obj.parent eq 'IMAGEOPTIONS'
        end;IMAGEOPTIONS
        'DETECTOROPTIONS':begin
            case obj.id of
                '32SQUARE':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                    end
                '64SQUARE':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                    end
                '128RECT':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                    end
                '128SQUARE':begin
                        widget_control,self.tw1,$
                                set_value=obj.parent+':'+obj.id
                    end
                else:   begin
                            widget_control,self.tw1,$
                                set_value="UNSURE OF DETECTORMENU CHOICE"
                        end
            endcase;obj.parent eq 'DETECTOROPTIONS'
        end;DETECTOROPTIONS
        'CALCULATIONOPTIONS':begin
            case obj.id of
                'CALCULATEQS':begin
                                (self.dataContainer->get(position=$
                                    self.QChoiceIndex))->calculateQVals
                        end;CALCULATEQS
                'CALCULATEI':begin
                        ;040904


                                self->CalculateIQTDialog
                                ;VALUE PASSING AND CALCULATION HANDLED
                                ;IN DIALOG EVENT HANDLER, WHICH IS
                                ;listEvents


                                ;CALCULATE I(Q,t)
                                ;HANDLE CALCULATION IN listEvents
;                                (self.dataContainer->get(position=$
;                                    self.QChoiceIndex))->calculateIQT


                                ;ONCE THIS CALCULATION IS DONE,
                                ;SUM ARCS OF Q FOR FINAL RESULT

;                                (self.dataContainer->get(position=$
;                                    self.QChoiceIndex))->sumQArcs


                                ;THEN. . .



                                ;POP UP PLOT OF I(Q,t)
                                ;
                                ;PLOT MUST ALLOW OVERLAY OF OTHER I(Q,t)
                                ;
                                ;THIS GIVES narcs DATA SETS PLOTTED VS
                                ;LOG(t)



                            end;CALCULATEI
                'CALCULATEAVERAGEWIDTH':begin
                        width = (self.dataContainer->get(position=$
                                        self.QChoiceIndex))->ChiSqWeightedAveWidth()
                    void = dialog_message('Chi-squared averaged width = '+strtrim(string(width),2),/information)
                end;'CALCULATEAVERAGEWIDTH'
                'AUTOGRAPHNSE':begin
                        self->autographNSEdialog
                        widget_control,self.tw1,$
                             set_value="OPENED AUTOGRAPHNSE"
                end;'AUTOGRAPHNSE'
                'AUTOMASKSOMETHING':begin
                        self->automasksomething
                        widget_control,self.tw1,$
                             set_value="OPENED AUTOMASKSOMETHING"
                end;'AUTOGRAPHNSE'
                'NSEDIFFRACTIONVIEWER':begin
                        NSEDiffractionViewer,group_leader=self.atlb
                        widget_control,self.tw1,$
                             set_value='OPENED NSEDIFFRACTIONVIEWER'
                end;'AUTOGRAPHNSE'
                'CALCULATESQ1D':begin
                        cw_nse_sqplot,group_leader=self.atlb,work_dir=self.work_dir

                end;'CALCULATESQ1D'
                'MERGEMULTIPLEIQT':begin
                        dum = cwo_mergeIQTToDave(group_leader=self.atlb,workdir=self.work_dir)
                end;'MERGEMULTIPLEIQT'
                else:   begin
                            widget_control,self.tw1,$
                                set_value="UNSURE OF CALCULATIONSMENU CHOICE"
                        end;else
            endcase
        end;CALCULATIONS
        'PRINTOPTIONS':begin
            case obj.id of
            'PRINTIMAGE':begin
                self->printwindow,/imagew
;                wset,self.dw1id
;                result = tvrd(true=3)
;                ;help,result
;                nse_ps_plotter,result
            end;PRINTIMAGE
            'PRINTPLOT':begin
                self->printwindow,/plotw
;                wset,self.dw2id
;                result = tvrd(true=3)
;                nse_ps_plotter,result
            end;PRINTPLOT
            'PRINTAUXPLOT':begin
                if self.dw2auxid ne 0L then begin
                    self->printwindow,/auxw
;                    wset,self.dw2auxid
;                    result = tvrd(true=3)
;                    nse_ps_plotter,result
                endif else begin
                    void = dialog_message('Auxiliary window not available.')
                endelse
            end;PRINTAUXPLOT
            else:begin
                    widget_control,self.tw1,$
                        set_value="UNSURE OF PRINTMENU CHOICE"
            end
            endcase
        end;PRINT
        'HELPOPTIONS':begin
            case obj.id of
            'NSEHELP':begin
                newevent = {id:event.id,top:self.dave_id,handler:event.handler}
                if widget_info(self.dave_id,/valid_id) gt 0 then begin
                    NSE_Help,newevent
                endif else begin
                    void = dialog_message('Help available when called from DAVE! (oodisplayecho_define ln 5932)',/info)
                endelse
            end;NSEHELP
            else:
            endcase
        end
        else:   begin
                    widget_control,self.tw1,$
                        set_value="UNSURE OF MENU CHOICE"

                end
        endcase;obj.parent

end;menuEvents

pro ooDisplayEcho::autographNSEDialog
;
;NAME:
;        ooDisplayEcho::autographNSEDialog
;
;PURPOSE:
;           Creates autographNSE dialog.
;PARAMETERS:
;           none
;KEYWORDS:
;           none

;    self.autographNSEbutton = widget_button(llb1,value='Plot and Fit D(Q)',$
;                                                tooltip='AutographNSE')

;    self->getproperty(/autographNSEbutton):begin
                    a = checkforobjinstance('cwo_autographnse',ref=ref)
                    ;print,a
                    if a eq 0 then begin
;                        base = widget_base(group_leader=self.atlb,title='AutographNSE',/floating)
;                        w = cwo_autographnse(base)
                        w = cwo_autographnse(self.atlb,workdir=self.work_dir)
                        ;widget_control,base,/realize
;                        xmanager,'autograph',w,event_handler='cwo_autographnse_event_pro',/no_block
;                                                    ;base,event_handler='cwo_autographnse_event_pro',/no_block
                    endif



end;autographNSEDialog


pro ooDisplayEcho::resizeAuxWindow,event,xsize=xsize,ysize=ysize
;
;NAME:
;        ooDisplayEcho::raiseAuxWindow
;
;PURPOSE:
;           Resizes the Auxiliary window.
;PARAMETERS:
;           event   resize event
;KEYWORDS:
;           none

;SEE ALSO LINE ~10630 FOR MAIN RESIZE OF THIS WIDGET.
;THERE IS A PROBLEM WITH KEEPING TRACK OF THE DRAW WINDOW.

;IT AFFECTS POSITION SELECTION ON IMAGE AND PLOT WINDOWS!!!!

;---WHY???????????????????????      -AXIS CONFUSION
;                               SAVE THE AXES JUST BEFORE AND JUST AFTER THE DRAW TO AUX PLOT.
;                                   FIX THIS TOMORROW!!!!

    ;print,'ooDisplayEcho::resizeAuxWindow'

    if n_elements(xsize) eq 0 then myxsize = event.x
    if n_elements(ysize) eq 0 then myysize = event.y


    winxsize = myxsize-6
    winysize = myysize-6

    if widget_info(self.dw2aux,/valid_id) gt 0 then begin
        widget_control,self.dw2aux,xsize = winxsize, ysize = winysize
    endif

    if widget_info(self.dw2auxbase,/valid_id) gt 0 then begin
        widget_control,self.dw2auxbase,xsize=myxsize,ysize=myysize
    endif
    wdelete,self.dw2auxpix
    window,/free,/pixmap,xsize=winxsize,ysize=winysize
    self.dw2auxpix = !d.window

    if n_elements(xsize) eq 0 then $
        self->draw

end;resizeAuxWindow
pro ooDisplayEcho::raiseAuxWindow
;
;NAME:
;        ooDisplayEcho::raiseAuxWindow
;
;PURPOSE:
;           Opens the Auxiliary window if not open.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    self.dw2auxbase = widget_base(group_leader=self.atlb,$
                                title='Auxiliary Plot (no user events)',$
                                tlb_size_events = 1,$
                                uvalue = self,$
                                /floating)
    self.dw2aux = widget_draw(self.dw2auxbase,xsize=self.plotxsize,ysize=self.plotysize)
    centertlb,self.dw2auxbase
    widget_control,self.dw2auxbase,/realize



    widget_control,self.dw2aux,get_value=auxid
    self.dw2auxid = auxid
    window,/free,/pixmap,xsize=self.plotxsize,ysize=self.plotysize
    self.dw2auxpix = !d.window
    xmanager,'ooDisplayEcho',self.dw2auxbase,event_handler='oodisplayecho_event',/no_block


end;raiseAuxWindow
pro ooDisplayEcho::lowerAuxWindow
;
;NAME:
;        ooDisplayEcho::lowerAuxWindow
;
;PURPOSE:
;           Closes the Auxiliary window if open.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    ;print,'lowerAuxWindow'

    if widget_info(self.dw2auxbase,/valid_id) gt 0 then begin
        widget_control,self.dw2auxbase,/destroy
        wdelete,self.dw2auxpix
    endif
end;lowerAuxWindow


pro ooDisplayEcho::lowerSlider
;
;NAME:
;        ooDisplayEcho::lowerSlider
;
;PURPOSE:
;           Closes the click-refit slider dialog.
;PARAMETERS:
;           none
;KEYWORDS:
;           none
        if widget_info(self.clickrefitslider,/valid_id) ne 0 then begin
            sliderparent = widget_info(self.clickrefitslider,/parent)
            ;widget_control,self.clickrefitslider,/destroy
            widget_control,sliderparent,/destroy
;            widget_control,sliderparent,show=0
        endif

end;lowerSlider
pro ooDisplayEcho::raiseSlider
;
;NAME:
;        ooDisplayEcho::raiseSlider
;
;PURPOSE:
;           Closes the click-refit slider dialog.
;PARAMETERS:
;           none
;KEYWORDS:
;           none
;        clickrefitbase = widget_base(self.tlb2,/row)

        clickrefitbase = widget_base(group_leader=self.atlb,/row,/floating,$
                                        title='DOUBLE-Click-Refit Start Values')
        self.clickrefitslider = cw_fslider(clickrefitbase,$;self.tlb2,$
                    minimum=-800.0,$
                    maximum=800.0,$
                    edit=1,$
                    drag=1,$
                    scroll=15.0,$
                    value=self.clickrefitvalue,$
                    title='starting phase',$
                    uvalue={object:self,$
                        method:'sliderEvents',$
                        id:'CLICKREFITSLIDER'})

        if self.clickrefitperiodvalue eq 0 then self.clickrefitperiodvalue = 360.0
        self.clickrefitperiodslider = cw_fslider(clickrefitbase,$;self.tlb2,$
                    minimum=300.0,$
                    maximum=420.0,$
                    edit=1,$
                    drag=1,$
                    scroll=5.0,$
                    value=self.clickrefitperiodvalue,$
                    title='starting period',$
                    uvalue={object:self,$
                        method:'sliderEvents',$
                        id:'CLICKREFITPERIODSLIDER'})


        widget_control,clickrefitbase,/realize

        xmanager,'ooDisplayEcho',clickrefitbase,/no_block



end;raiseSlider



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::droplistEvents,event
;
;NAME:
;        ooDisplayEcho::droplistEvents
;
;PURPOSE:
;           Handle events from teh droplist widgets in ooDisplayEcho
;PARAMETERS:
;           event   The droplist event structure to handle.
;KEYWORDS:
;           none

    widget_control,event.id,get_uvalue=obj

    case (obj.id) of
        'DROPDISPLAY': begin
                widget_control,self.tw1,$
                        set_value='DROPDISPLAY'+strtrim(string(event.index),2)

                self.displayIndex = event.index
                self->draw

            end
        'DROPDET': begin
                widget_control,self.tw1,$
                        set_value="DROPDET:"+strtrim(string(event.index),2)
                self.detChoiceIndex = event.index
            end
        'DROPFT': begin


                ;print,tag_names(event)
                ;print,event

                widget_control,self.tw1,$
                        set_value="DROPFT:"+strtrim(string(event.index),2)
                self.ftChoiceIndex = event.index
                self->mouseHead,event,t=event.index
                ;self->draw
            end
        'DROPQ': begin
                widget_control,self.tw1,$
                        set_value="DROPQ:"+strtrim(string(event.index),2)

                oldQIndex = self.QChoiceIndex
                self.QChoiceIndex = event.index
;                print,oldQIndex,self.QChoiceIndex
                ;pro ooDisplayEcho::swapDataObject,n_old,n_new
                self->swapDataObject,oldQIndex,self.QChoiceIndex
;                self->setDataParameters,$
;                    self.ech,$;self.dataContainer->get(position = self.QChoiceIndex),$
;                    n=self.QChoiceIndex
                self->setDataParameters,$
                    (self.dataContainer->get(position=self.QChoiceIndex)),$
                    n=self.QChoiceIndex

                self->reDefineWidgets,event.index
                self->draw
            end
        'DROPFIXCONST': begin
                widget_control,self.tw1,$
                        set_value="DROPFIXCONST:"+strtrim(string(event.index),2)
                self->handleFixDroplist,0,event.index
            end
        'DROPFIXAMP': begin
                widget_control,self.tw1,$
                        set_value="DROPFIXAMP:"+strtrim(string(event.index),2)
                self->handleFixDroplist,1,event.index
            end
        'DROPFIXPHASEO': begin
                widget_control,self.tw1,$
                        set_value="DROPFIXPHASEO:"+ $
                                    strtrim(string(event.index),2)
                self->handleFixDroplist,2,event.index
            end
        'DROPFIXSIGMA': begin
                widget_control,self.tw1,$
                        set_value="DROPFIXSIGMA:"+strtrim(string(event.index),2)
                self->handleFixDroplist,3,event.index
            end
        'DROPFIXOMEGA': begin
                widget_control,self.tw1,$
                        set_value="DROPFIXOMEGA:"+strtrim(string(event.index),2)
                self->handleFixDroplist,4,event.index
            end
        'DROPFIXPHASE': begin
                widget_control,self.tw1,$
                        set_value="DROPFIXPHASE:"+strtrim(string(event.index),2)
                self->handleFixDroplist,5,event.index
            end

        'DROPLIMITCONST': begin
                widget_control,self.tw1,$
                        set_value="DROPLIMITCONST:"+strtrim(string(event.index),2)
                self.limited[0] = event.index ;0 for unlimited, 1 for limited
                ;if event.index eq 1 then begin
                widget_control,self.atwminlimconst,editable=event.index
                widget_control,self.atwmaxlimconst,editable=event.index
                ;endif else begin
                ;    widget_control,self.atwminlimconst,editable=1
                ;    widget_control,self.atwmaxlimconst,editable=1
                ;endelse
            end
        'DROPLIMITAMP': begin
                widget_control,self.tw1,$
                        set_value="DROPLIMITAMP:"+strtrim(string(event.index),2)
                self.limited[1] = event.index ;0 for unlimited, 1 for limited
                ;if event.index eq 1 then begin
                widget_control,self.atwminlimamp,editable=event.index
                widget_control,self.atwmaxlimamp,editable=event.index
                ;endif else begin
                ;    widget_control,self.atwminlimamp,editable=1
                ;    widget_control,self.atwmaxlimamp,editable=1
                ;endelse
            end
        'DROPLIMITPHASEO': begin
                widget_control,self.tw1,$
                        set_value="DROPLIMITPHASEO:"+strtrim(string(event.index),2)
                self.limited[2] = event.index ;0 for unlimited, 1 for limited
                ;if event.index eq 1 then begin
                widget_control,self.atwminlimphaseo,editable=event.index
                widget_control,self.atwmaxlimphaseo,editable=event.index
                ;endif else begin
                ;    widget_control,self.atwminlimphaseo,editable=1
                ;    widget_control,self.atwmaxlimphaseo,editable=1
                ;endelse
            end
        'DROPLIMITSIGMA': begin
                widget_control,self.tw1,$
                        set_value="DROPLIMITSIGMA:"+strtrim(string(event.index),2)
                self.limited[3] = event.index ;0 for unlimited, 1 for limited
                ;if event.index eq 1 then begin
                widget_control,self.atwminlimsigma,editable=event.index
                widget_control,self.atwmaxlimsigma,editable=event.index
                ;endif else begin
                ;    widget_control,self.atwminlimsigma,editable=1
                ;    widget_control,self.atwmaxlimsigma,editable=1
                ;endelse
            end
        'DROPLIMITOMEGA': begin
                widget_control,self.tw1,$
                        set_value="DROPLIMITOMEGA:"+strtrim(string(event.index),2)
                self.limited[4] = event.index ;0 for unlimited, 1 for limited
                ;if event.index eq 1 then begin
                widget_control,self.atwminlimomega,editable=event.index
                widget_control,self.atwmaxlimomega,editable=event.index
                ;endif else begin
                ;    widget_control,self.atwminlimomega,editable=1
                ;    widget_control,self.atwmaxlimomega,editable=1
                ;endelse
            end
        'DROPLIMITPHASE': begin
                widget_control,self.tw1,$
                        set_value="DROPLIMITPHASE:"+strtrim(string(event.index),2)
                self.limited[5] = event.index ;0 for unlimited, 1 for limited
                ;if event.index eq 1 then begin
                widget_control,self.atwminlimphase,editable=event.index
                widget_control,self.atwmaxlimphase,editable=event.index
                ;endif else begin
                ;    widget_control,self.atwminlimphase,editable=1
                ;    widget_control,self.atwmaxlimphase,editable=1
                ;endelse
            end

        else:   begin
                    widget_control,self.tw1,$
                        set_value="UNSURE OF DROPWIDGET CHOICE"
                end

    endcase
    ;self->draw

end;droplistEvents

pro ooDisplayEcho::handleFixDroplist,parm,index
;
;NAME:
;        ooDisplayEcho::handleFixDroplist
;
;PURPOSE:
;               Handle events from the fix/vary droplists.
;PARAMETERS:
;               parm        The fit parameter index
;               index       The fix/vary state of the parameter, i.e. the index of the droplist state.
;KEYWORDS:
;
                ;021306
                ;AT THIS POINT I WILL NOT ADD THE STORAGE OF FIT PARMS TO THE
                ;EVENT HANDLING.  THIS MAY BE AN ISSUE, BUT IT SHOULD BE SOMETHING THE
                ;USERS RAISE, SINCE THEY REQUESTED THIS FEATURE AND THEY MAY NOT WANT
                ;A RESTORE CAPABILITY.
                ref = self.dataContainer->get(position=self.QChoiceIndex)


;print,'ooDisplayecho::handlefixdroplist'

;022306
;WHY MIGHT I GET HERE?
;
;1) PEOPLE ARE UPDATING THE VALUES IN THE TEXT BOXES TO MANUALLY CHANGE THE
;CURVE PARAMETERS TO BETTER VALUES.
;
;2) PEOPLE ARE VARYING THE FIX/VARY VALUES.
;
;IT SEEMS THAT IN EITHER CASE, THEY WANT TO SAVE THE VALUES AS STARTING POINTS FOR
;THE FITS.
;
;SO MOVE THE BOTTOM STATEMENTS TO HERE.

;                ;GET THE VALUE IN THE RELEVANT TEXT FIELD
;                parmField = [self.atwconst,self.atwamp,self.atwphaseo,$
;                             self.atwsigma,self.atwomega,self.atwphase]
;                widget_control,parmfield[parm],get_value=value
;
;
;                ;TAKE CARE OF omega/T ISSUE
;                ;
;                ;DUE TO EARLY DECISION, I FIT WITH omega INSTEAD OF period.
;                ;THAT IS MANIFESTED HERE.
;                if parm eq 4 then value = 360.0/value
;
;                ref->fixParm,parm,index,x=self.xindex,y=self.yindex,t=self.ftChoiceIndex,value=value

;WHY DOES UPDATING HAPPEN BEFORE THE VALUES IS FIXED?  DO I LOSE THE VALUE????
                self->updateFitparmWidget,parm,index;,/dontUpdateValues



                ;GET THE VALUE IN THE RELEVANT TEXT FIELD
                parmField = [self.atwconst,self.atwamp,self.atwphaseo,$
                             self.atwsigma,self.atwomega,self.atwphase]
                widget_control,parmfield[parm],get_value=value


                ;TAKE CARE OF omega/T ISSUE
                ;
                ;DUE TO EARLY DECISION, I FIT WITH omega INSTEAD OF period.
                ;THAT IS MANIFESTED HERE.
                if parm eq 4 then value = 360.0/value

                ref->fixParm,parm,index,x=self.xindex,y=self.yindex,t=self.ftChoiceIndex,value=value



end;handleFixDroplist


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::updateFitparmWidget,n,state
;
;NAME:
;        ooDisplayEcho::updateFitparmWidget
;
;PURPOSE:
;               Update the fit parameter display widgets following and event.
;PARAMETERS:
;               n       The fit parameter index
;               state   The fix/vary state of the parameter.
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


                ;print,'ooDisplayEcho::updateFitparmWidget',n,state

                ;021406
                ;CHANGE THE NEXT LINE TO REFLECT THE 8 OPTIONS
                ;self.fixed[n] = state ;0 for vary, 1 for fixed

                if state lt 8 then begin
                    self.fixed[n] = state/4 ;NOT THAT self.fixed ONLY STORES THE vary/fix OPTION, NOT THE STATE
                                            ;OF THE FIT PARM DROPLIST WIDGETS.
                endif else begin
                    if state eq 8 then begin
                        ;FIXING WITHOUT CHANGING ALL VALUES.
                        self.fixed[n] = 1;state/4

                    endif else begin
                        void = dialog_message('THE POSSIBLE Fix/Vary STATES HAVE CHANGED')
                    endelse
                endelse


                ;SET VALUE IN SELECTED DATA OBJECT AT SELECTED PIXEL
                t=self.ftChoiceIndex
                q=self.QChoiceIndex


;THE NEXT TWO LINES SHOULD ONLY BE CALLED WHEN THERE IS AN EVENT FROM THE
;DROPLIST WIDGETS, SINCE THOSE ARE UPDATED BASED ON THE VALUES IN THE
;DATA CLASS.
;                ref = self.dataContainer->get(position=q)
;                ref->fixParm,n,state,x=self.xindex,y=self.yindex,t=self.ftChoiceIndex

;THE NEXT TWO LINES BELONG IN THE DATA CLASS.
;THE ONLY WAY THESE SHOULD BE NEEDED IS ON A DROPLIST EVENT, WHICH IS HANDLED ABOVE
;AND SENT HERE.
;                pfixed = ref->getProperty(tag='fixed')
;                (*pfixed)[n,self.xindex+self.yindex*self.detxdim,t] = $
;                                                            self.fixed[n]

                case n of
                0:begin
                    id = self.atwconst
                    dwid = self.dropfixconst
                end
                1:begin
                    id = self.atwamp
                    dwid = self.dropfixamp
                end
                2:begin
                    id = self.atwphaseo
                    dwid = self.dropfixphaseo
                    ;print,state

                end
                3:begin
                    id = self.atwsigma
                    dwid = self.dropfixsigma
                end
                4:begin
                    id = self.atwomega
                    dwid = self.dropfixomega
                end
                5:begin
                    id = self.atwphase
                    dwid = self.dropfixphase
                end
                else:begin
                end
                endcase


;021305
;print,'7384 in ooDisplayEcho::updateFitparmWidget'

;WHERE CAN I ARRIVE HERE FROM????
;WILL THE FOLLOWING CONDITIONAL WORK PROPERLY FOR ALL SITUATIONS
;ARRIVING HERE????
            ;print,*p
                if state lt 4 then begin    ;eq 0 then begin
                    widget_control,id,editable = 1
                endif else begin
                    widget_control,id,editable = 0
                endelse

;                widget_control,dwid,get_va



                ;CHANGE THE NEXT LINE TO USE THE state AND NOT self.fixed
                widget_control,dwid,set_droplist_select=state;self.fixed[n]


end;updateFitparmWidget
pro ooDisplayEcho::handleBinning,factor=factor,index=index,$
                        xfactor=xfactor,yfactor=yfactor,$
                        donotrebin=donotrebin,filename=filename,$
                        default=default,newfile=newfile
;
;NAME:
;        ooDisplayEcho::handleBinning
;
;PURPOSE:
;           Handle events whenever bin is called.
;PARAMETERS:
;           none.
;KEYWORDS:
;           factor  The binning factor to return.
;           index   The index of the object to bin.


            binvals = [1,2,4,8,16]
            selectindex = nse_comboindex(self.atw1)
            factor = binvals[selectindex]
            nobj = self.datacontainer->count()

            ;MUST BE CAREFUL IN USE OF THIS SINCE IT APPLIES TO ALL DATA AND EACH OBJECT
            ;DOES NOT REVEAL ITS STATE.  PERHAPS THERE IS A WAY TO MAKE CHECK THE STATE.
            widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= timecheckboxval
            widget_control,self.DEEPMASKINGCHECKBOX,get_value= DEEPMASKINGCHECKBOXval

            if n_elements(index) eq 0 then begin
                for i = 0,nobj-1 do begin
                    ref = self.datacontainer->get(position=i)
                    ref->bin,factor=factor,timeaverage=timecheckboxval,deepmasking=DEEPMASKINGCHECKBOXval,$
                                            xfactor=xfactor,yfactor=yfactor,$
                                            donotrebin=donotrebin,filename=filename,$
                                            default=default,newfile=newfile
                endfor
            endif else begin
                    ref = self.datacontainer->get(position=index)
                    ref->bin,factor=factor,timeaverage=timecheckboxval,deepmasking=DEEPMASKINGCHECKBOXval,$
                                            xfactor=xfactor,yfactor=yfactor,$
                                            donotrebin=donotrebin,filename=filename,$
                                            default=default,newfile=newfile

            endelse

end;handleBinning

pro ooDisplayEcho::add,obj,position=position
;
;NAME:
;        ooDisplayEcho::add
;
;PURPOSE:
;           Add objects to the data container
;PARAMETERS:
;           obj         The object to add
;KEYWORDS:
;           position    The optional position to add it at.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


    void = dialog_message('ooDisplayEcho::add is not yet implemented.')
;    if n_elements(obj) eq 1 then begin
;        if obj_isa(obj,'ooEcho') gt 0 then begin
;            self.datacontainer->add,obj,position=position
;        endif
;    endif else void = dialog_message('No valid object to add.')


end;add
pro ooDisplayEcho::textEvents,event
;
;NAME:
;        ooDisplayEcho::textEvents
;
;PURPOSE:
;           Handle events from the ooDisplayEcho text widgets.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none

    widget_control,event.id,get_uvalue=obj,get_value=text

    ;;CHANGE THE NEXT LINE IN CASE text IS NOT A STRING.
    widget_control,self.tw1,$
        set_value='textEvent: ID = '+strtrim(string(obj.id),2)+', value = '  $
                                    +strtrim(string(text),2)

    ;if (obj.id eq 'ATW1') then begin
    case obj.id of
    'ATW1':begin
            ;REBINNING
;            widget_control,self.atw1,get_value = s  ;NEED TO CHECK TYPE FOR s

            ;FIXING THIS TO DEAL WITH THE PLATFORM INDEPENDENT BUTTONS.

            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG
                factor=1
                catch, /cancel
            endif
;            factor = fix(s)
;            print,'event.index=',event.index
;            print,'event.str=',event.str

            ;print,tag_names(event,/structure_name)
            ;print,tag_names(event)
            ;print,event

            binvals = [1,2,4,8,16]
            selectindex = nse_comboindex(event.id)

            factor = binvals[selectindex]
;            ;SIMPLY GET THE VALUE OF WHICHEVER BUTTON IS SELECTED.
;            widget_control,event.id,get_value=atw1val
;            print,'atw1val=',atw1val
;
;            self.atw1value = fix(atw1val)
;
;            ;THIS WILL BE SET IN self->reDefineWidgets
;;            widget_control,self.atw1,set_value=atw1val+' >'
;
;            ;factor = fix(event.str)
;
;            factor = fix(atw1val)
            self->resetDataParameters,factor
            ;120804 CHANGE NEXT LINE SO ftChoiceIndex IS PRESERVED
            ;ON A REBIN.
            self->redefineWidgets,self.QChoiceIndex,t=self.ftChoiceIndex,/resetdataparameters
            self->redefineTree
            self->updateMaskmaker
            self->draw
    end;ATW1
    'BINALLBUTTON':begin

            self->handlebinning,factor=factor
;            binvals = [1,2,4,8,16]
;            selectindex = nse_comboindex(self.atw1)
;            factor = binvals(selectindex)
;            nobj = self.datacontainer->count()
;
;            ;MUST BE CAREFUL IN USE OF THIS SINCE IT APPLIES TO ALL DATA AND EACH OBJECT
;            ;DOES NOT REVEAL ITS STATE.  PERHAPS THERE IS A WAY TO MAKE CHECK THE STATE.
;            widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= timecheckboxval
;            widget_control,self.DEEPMASKINGCHECKBOX,get_value= DEEPMASKINGCHECKBOXval
;
;
;
;            for i = 0,nobj-1 do begin
;                ref = self.datacontainer->get(position=i)
;                ref->bin,factor=factor,timeaverage=timecheckboxval,deepmasking=DEEPMASKINGCHECKBOXval
;;DO NOT APPLY TIME AVERAGING AT THIS STAGE UNLESS IT IS LATER REQUESTED.
;
;            endfor


            self->resetDataParameters,factor
            ;120804 CHANGE NEXT LINE SO ftChoiceIndex IS PRESERVED
            ;ON A REBIN.
            self->redefineWidgets,self.QChoiceIndex,t=self.ftChoiceIndex,/resetdataparameters
            self->redefineTree
            self->updateMaskmaker
            self->draw
    end;BINALLBUTTON
    'CHANGEMASKFILEBUTTON':begin

;        widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= timecheckboxval
;        widget_control,self.DEEPMASKINGCHECKBOX,get_value= DEEPMASKINGcheckboxval
;
;        ref = self.datacontainer->get(position=self.QChoiceIndex)
;
;        ref->bin,factor=factor,timeaverage=timecheckboxval,$
;                    DEEPMASKING=DEEPMASKINGcheckboxval,/newfile,filename=fn
;

        self->handleBinning,factor=factor,index=self.QChoiceIndex,$
                                filename=fn,/newfile


        print,fn

    end;'CHANGEMASKFILEBUTTON'
    'SAVEMASKBUTTON':begin
        ;031305



        ref = self.datacontainer->get(position=self.QChoiceIndex)

        dir = self.work_dir
        ref->saveMask,dir=dir
        self.work_dir = dir

    end;'SAVEMASKBUTTON'
    'DEEPMASKINGCHECKBOX':begin
;        print,'ooDisplayEcho::textEvents    DEEPMASKINGCHECKBOX'


        ;FOR NOW THE DEEPMASKING OPTION WILL CALL ALL THE SAME ITEMS THE BINALLBUTTON DOES.

            ;MUST BE CAREFUL IN USE OF THIS SINCE IT APPLIES TO ALL DATA AND EACH OBJECT
            ;DOES NOT REVEAL ITS STATE.  PERHAPS THERE IS A WAY TO MAKE CHECK THE STATE.
;            widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= timecheckboxval
;            widget_control,self.DEEPMASKINGCHECKBOX,get_value= DEEPMASKINGcheckboxval
;
;
;            ;GET FILENAME AT THE OBJECT LEVEL IF NECESSARY
;;            if DEEPMASKINGcheckboxval eq 1 then begin
;;                fn = dialog_pickfile(title='SELECT SAVED DEEP MASK FILE')
;;            endif else begin
;;                fn = ''
;;            endelse
;
;
;            binvals = [1,2,4,8,16]
;            selectindex = nse_comboindex(self.atw1)
;            factor = binvals(selectindex)
;            nobj = self.datacontainer->count()
;
;
;
;            print,'ooDisplayEcho::textEvents    timecheckboxval=',timecheckboxval
;
;
;;FOR NOW JUST APPLY TO CURRENT OBJECT.
;            ref = self.datacontainer->get(position=self.QChoiceIndex)
;            ref->bin,factor=factor,timeaverage=timecheckboxval,DEEPMASKING=DEEPMASKINGcheckboxval;,filename = fn

            self->handleBinning,factor=factor,index=self.QChoiceIndex

;            for i = 0,nobj-1 do begin
;                ref = self.datacontainer->get(position=i)
;                ref->bin,factor=factor,timeaverage=timecheckboxval,DEEPMASKING=DEEPMASKINGcheckboxval,filename = fn
;;DO NOT APPLY TIME AVERAGING AT THIS STAGE UNLESS IT IS LATER REQUESTED.
;            endfor

            self->resetDataParameters,factor,/nobin;timeaverage=timecheckboxval,DEEPMASKING=DEEPMASKINGcheckboxval,filename = fn
            ;120804 CHANGE NEXT LINE SO ftChoiceIndex IS PRESERVED
            ;ON A REBIN.
            self->redefineWidgets,self.QChoiceIndex,t=self.ftChoiceIndex,/resetdataparameters
            self->redefineTree
            self->updateMaskmaker
            self->draw





    end;DEEPMASKINGCHECKBOX
    'TRANSVOLALLBUTTON':begin

;            for i = 0,nobj-1 do begin
;                ref = self.datacontainer->get(position=i)
;                ;ref->bin,factor=factor
;            endfor

        ;GET VOLUME FRACTION VALUE AND APPLY TO ALL SPECIFIED DATA
            widget_control,self.atwvolfrac,get_value=s

            thistype = (self.dataContainer->get(position=$
                    self.QChoiceIndex))->getProperty(tag='type')

            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG
                trans = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='volfrac')
                catch, /cancel
            endif


            volfrac = double(s)
            if volfrac le 0.0d then begin
                volfrac = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='volfrac')
                widget_control,self.atwvolfrac,set_value=strtrim(string(volfrac),1)
            endif

            widget_control,self.atwtrans,get_value=s

            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG
                trans = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='transmission')
                catch, /cancel
            endif


            trans = double(s)
            if trans le 0.0d then begin
                trans = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='transmission')
                widget_control,self.atwtrans,set_value=strtrim(string(trans),1)
            endif


            for ii = 0,(self.dataContainer->count())-1 do begin
                refi = (self.dataContainer->get(position=ii))
                if refi->getProperty(tag='type') eq thistype then begin
                    refi->setProperty,'volfrac',volfrac
                    refi->setProperty,'transmission',trans
                endif
            endfor;ii
    end;TRANSVOLALLBUTTON


;102605
;
;THE NEXT EVENT HANDLING BLOCKS SHOULD ONLY BE ACCESSED IF THE CURRENT
;DATA OBJECT IS A MAGNETIC OBJECT!!!!! US obj


    'MAGNETICCHECKBOX':begin


            ;THIS IS NOT CONTROLLABLE BY THE USER!!!!
;;112805
;;THIS WILL NOT BE EDITABLE BY THE USER IN THE FUTURE.
;
;
;        ;print,'#### MagneticCheckBox ####'
;        widget_control,self.magneticcheckbox,get_value = value
;        print,obj.id+': ',value
;        print,tag_names(event,/structure_name)
;        print,tag_names(event)
;        print,event
;
;
;
;        ref = self.datacontainer->get(position=self.qchoiceindex)
;        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
;
;            ref->setproperty,'magnetic',event.value
;            widget_control,self.atwflippingratio,sensitive=event.value
;            widget_control,self.atwpolarization,sensitive=event.value
;;            widget_control,self.atwpoint_to_up_x,sensitive=event.value
;;            widget_control,self.atwpoint_to_up_y,sensitive=event.value
;;            widget_control,self.atwpoint_to_up_z,sensitive=event.value
;;            widget_control,self.atwpoint_to_down_x,sensitive=event.value
;;            widget_control,self.atwpoint_to_down_y,sensitive=event.value
;;            widget_control,self.atwpoint_to_down_z,sensitive=event.value
;            widget_control,self.magplotcontextsubmenu,sensitive=event.value
;            widget_control,self.magplotmenusubmenu,sensitive=event.value
;
;            magimageid = widget_info(self.atlb,find_by_uname='MAGNETICIMAGEOPTIONS')
;            widget_control,magimageid,sensitive=event.value
;            magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_1')
;            widget_control,magimageid,sensitive=event.value
;            magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_2')
;            widget_control,magimageid,sensitive=event.value
;            magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_3')
;            widget_control,magimageid,sensitive=event.value
;
;
;        endif else begin
;            widget_control,self.magneticcheckbox,set_value=0
;            widget_control,self.atwflippingratio,sensitive=0
;            widget_control,self.atwpolarization,sensitive=0
;;            widget_control,self.atwpoint_to_up_x,sensitive=0
;;            widget_control,self.atwpoint_to_up_y,sensitive=0
;;            widget_control,self.atwpoint_to_up_z,sensitive=0
;;            widget_control,self.atwpoint_to_down_x,sensitive=0
;;            widget_control,self.atwpoint_to_down_y,sensitive=0
;;            widget_control,self.atwpoint_to_down_z,sensitive=0
;
;            widget_control,self.magplotcontextsubmenu,sensitive=0
;            widget_control,self.magplotmenusubmenu,sensitive=0
;
;
;            magimageid = widget_info(self.atlb,find_by_uname='MAGNETICIMAGEOPTIONS')
;            widget_control,magimageid,sensitive=0
;            magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_1')
;            widget_control,magimageid,sensitive=0
;            magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_2')
;            widget_control,magimageid,sensitive=0
;            magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_3')
;            widget_control,magimageid,sensitive=0
;        endelse
;        ;IF BOX IS CHECKED THEN THE POINT_TO_UP/DOWN_X/Y/Z
;        ;FIELDS WILL BE SENSITIVE.

    end;MAGNETICCHECKBOX
    'TIMEAVERAGEUPDOWNCHECKBOX':begin
        ;void = dialog_message('In the process of allowing time averaging of up/down.')


;        ref = self.dataContainer->get(position=self.QChoiceIndex)
;
;;        widget_control,event.id,get_value=val
;;
;;        print,'TIMEAVERAGEUPDOWNCHECKBOX    value=',val,event.select
;
;
;
;        index = nse_comboindex(self.atw1)
;
;        ;GET BIN FACTOR FROM THE DROPLIST.
;        widget_control,self.atw1,get_value=val
;        factor = fix(val[index])
;
;;        print,tag_names(event)
;;        print,event
;
;        widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= checkboxval
;        widget_control,self.DEEPMASKINGCHECKBOX,get_value= DEEPMASKINGcheckboxval
;        ;print,'checkboxval=',checkboxval
;
;;TWO OTHER CASES NEED TO BE CONSIDERED HERE.
;;   1) INITIAL READ OF DATA SHOULD LOOK AT checkboxval AND RESPOND APPROPRIATELY
;;   2) FILES READ IN FROM SAVED STATES SHOULD RESPOND IN SOME APPROPRIATE FASHION.
;;
;;THE SECOND CASE SUGGESTS THAT THIS SHOULD BE APPLIED THROUGH A BUTTON.
;
;        ref->bin,factor=factor,timeaverage=checkboxval,DEEPMASKING=DEEPMASKINGcheckboxval;,filename = fn

        self->handleBinning,factor=factor,index=Self.QChoiceIndex



        self->draw
        ;WHEN THIS IS CHECKED, THE XYZ UP/DOWN SHOULD BE TIME AVERAGED.
        ;WHEN IT IS UNCHECKED, XYZ UP/DOWN SHOULD BE unTIMEAVERAGED.
        ;
        ;THIS SHOULD BE HANDLED THROUGH THE ooEcho::bin METHOD, SINCE THAT USES THE
        ;ORIGINAL DATA TO CREATE THE BINNED VERSION.  THIS WAY, THE NON-TIMEAVERAGED DATA
        ;IS ALWAYS AVAILABLE.

        ;THE BIN METHOD SHOULD BE OVERRIDDEN IN ooEchoMagnetic.
        ;THE NEW VERSION SHOULD HAVE A timeAveraged FLAG, AND THE ORIGINAL VERSION
        ;SHOULD HAVE AN _extra=extra KEYWORD ADDED IN CASE IT IS INADVERTANTLY CALLED.
        ;THE NEW VERSION SHOULD ALSO SAVE A CURRENT STATE OF THE MASK SO THAT IS UNCHANGED
        ;FROM PRIOR TO TIME AVERAGING.





    end;TIMEAVERAGEUPDOWNCHECKBOX
    'TIMEAVERAGEUPDOWNAPPLYALLBUTTON':begin

        ;THIS IS A BUTTON BECAUSE THERE IS AN AMBIGUITY ABOUT WHAT FILES SHOULD
        ;BE TIME AVERAGED WHEN READ IN.  SEE NOTE IN CHECKBOX CASE ABOVE THIS.
        ;print,'TEST1'
;        index = nse_comboindex(self.atw1)
;
;        widget_control,self.TIMEAVERAGEUPDOWNCHECKBOX,get_value= checkboxval
;        ;print,checkboxval
;
;        count = self.datacontainer->count()
;        if count gt 0 then begin
;            for i=0,count-1 do begin
;                ;print,'TEST ',i
;                ref = self.dataContainer->get(position=i)
;                ;ref->bin,timeaverage=checkboxval,donotrebin=1
;                ref->bin,timeaverage=checkboxval,DEEPMASKING=DEEPMASKINGcheckboxval;,filename = fn
;            endfor;i
;        endif
;
;

        self->handleBinning,factor=factor;,index=index


        self->draw
    end;TIMEAVERAGEUPDOWNAPPLYALLBUTTON


    'ATWFLIPPINGRATIO':begin
            ;THIS WILL ACT ON ALL MAGNETIC OBJECTS

            widget_control,self.atwflippingratio,get_value = value
            ;print,obj.id,+': ',value

            ref = self.datacontainer->get(position=self.qchoiceindex)
        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: f = ',ref->getproperty(tag='f')
            ref->setproperty,'f',event.value
            ref->setproperty,'IupdownSwitch',0
            ;print,'After: f = ',ref->getproperty(tag='f')
            self->draw
        endif else begin
        endelse

    end;ATWFLIPPINGRATIO
    'ATWPOLARIZATION':begin
            widget_control,self.atwpolarization,get_value = value
            ;print,obj.id,+': ',value
            ref = self.datacontainer->get(position=self.qchoiceindex)
        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: p = ',ref->getproperty(tag='p')
            ref->setproperty,'p',event.value
            ref->setproperty,'IupdownSwitch',0
            ;print,'After: p = ',ref->getproperty(tag='p')
            self->draw
        endif else begin
        endelse



    end;ATWPOLARIZATION
    'ATWEFF_BPW':begin
            widget_control,self.atwpolarization,get_value = value
            ;print,obj.id,+': ',value
            ref = self.datacontainer->get(position=self.qchoiceindex)
        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: eff_bpw = ',ref->getproperty(tag='eff_bpw')
            ref->setproperty,'eff_bpw',event.value
            ref->setproperty,'IupdownSwitch',0
            ;print,'After: eff_bpw = ',ref->getproperty(tag='eff_bpw')
            self->draw
        endif else begin
        endelse
    end;ATWEFF_BPW
;    'ATWEFF_BPW_X':begin
;            widget_control,self.atwpolarization,get_value = value
;            ;print,obj.id,+': ',value
;            ref = self.datacontainer->get(position=self.qchoiceindex)
;        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
;            ;print,'Before: eff_bpw = ',ref->getproperty(tag='eff_bpw')
;            ref->setproperty,'eff_bpw_x',event.value
;            ref->setproperty,'IupdownSwitch',0
;            ;print,'After: eff_bpw = ',ref->getproperty(tag='eff_bpw')
;            self->draw
;        endif else begin
;        endelse
;    end;ATWEFF_BPW_X
;    'ATWEFF_BPW_Y':begin
;            widget_control,self.atwpolarization,get_value = value
;            ;print,obj.id,+': ',value
;            ref = self.datacontainer->get(position=self.qchoiceindex)
;        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
;            ;print,'Before: eff_bpw = ',ref->getproperty(tag='eff_bpw')
;            ref->setproperty,'eff_bpw_y',event.value
;            ref->setproperty,'IupdownSwitch',0
;            ;print,'After: eff_bpw = ',ref->getproperty(tag='eff_bpw')
;            self->draw
;        endif else begin
;        endelse
;    end;ATWEFF_BPW_Y
;    'ATWEFF_BPW_Z':begin
;            widget_control,self.atwpolarization,get_value = value
;            ;print,obj.id,+': ',value
;            ref = self.datacontainer->get(position=self.qchoiceindex)
;        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
;            ;print,'Before: eff_bpw = ',ref->getproperty(tag='eff_bpw')
;            ref->setproperty,'eff_bpw_z',event.value
;            ref->setproperty,'IupdownSwitch',0
;            ;print,'After: eff_bpw = ',ref->getproperty(tag='eff_bpw')
;            self->draw
;        endif else begin
;        endelse
;    end;ATWEFF_BPW_Z

    'ATWXYZUPDOWNSCALE':begin

            widget_control,self.ATWXYZUPDOWNSCALE,get_value = value
            ;print,obj.id,+': ',value
            ref = self.datacontainer->get(position=self.qchoiceindex)
        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: point_to_up_x = ',ref->getproperty(tag='point_to_up_x')
            ;print,'Before: xyzupdownscale = ',ref->getproperty(tag='xyzupdownscale')
            ref->setproperty,'xyzupdownscale',value;event.value
            ref->setproperty,'IupdownSwitch',0
            ;print,'After: xyzupdownscale = ',ref->getproperty(tag='xyzupdownscale')
            ;print,'After: point_to_up_x = ',ref->getproperty(tag='point_to_up_x')
            self->draw
        endif else begin
        endelse


    end;ATWXYZUPDOWNSCALE
    'ATWPOINT_TO_UP_X':begin
            ;THESE WILL ACT ONLY ON THE CURRENTLY SELECTED OBJECT.

            widget_control,self.atwpoint_to_up_x,get_value = value
            ;print,obj.id,+': ',value
            ref = self.datacontainer->get(position=self.qchoiceindex)
        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: point_to_up_x = ',ref->getproperty(tag='point_to_up_x')
            ref->setproperty,'point_to_up_x',event.value
            ;print,'After: point_to_up_x = ',ref->getproperty(tag='point_to_up_x')
        endif else begin
        endelse

    end;ATWPOINT_TO_UP_X
    'ATWPOINT_TO_DOWN_X':begin
            widget_control,self.atwpoint_to_down_x,get_value = value
            ;print,obj.id,+': ',value
            ref = self.datacontainer->get(position=self.qchoiceindex)
        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: point_to_down_x = ',ref->getproperty(tag='point_to_down_x')
            ref->setproperty,'point_to_down_x',event.value
            ;print,'After: point_to_down_x = ',ref->getproperty(tag='point_to_down_x')
        endif else begin
        endelse

    end;ATWPOINT_TO_DOWN_X
    'ATWPOINT_TO_UP_Y':begin
            widget_control,self.atwpoint_to_up_y,get_value = value
            ;print,obj.id,+': ',value
            ref = self.datacontainer->get(position=self.qchoiceindex)

        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: point_to_up_y = ',ref->getproperty(tag='point_to_up_y')
            ref->setproperty,'point_to_up_y',event.value
            ;print,'After: point_to_up_y = ',ref->getproperty(tag='point_to_up_y')
        endif else begin
        endelse

    end;ATWPOINT_TO_UP_Y
    'ATWPOINT_TO_DOWN_Y':begin
            widget_control,self.atwpoint_to_down_y,get_value = value
            ;print,obj.id,+': ',value

            ref = self.datacontainer->get(position=self.qchoiceindex)
        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: point_to_down_y = ',ref->getproperty(tag='point_to_down_y')
            ref->setproperty,'point_to_down_y',event.value
            ;print,'After: point_to_down_y = ',ref->getproperty(tag='point_to_down_y')
        endif else begin
        endelse


    end;ATWPOINT_TO_DOWN_Y
    'ATWPOINT_TO_UP_Z':begin
            widget_control,self.atwpoint_to_up_z,get_value = value
            ;print,obj.id,+': ',value

            ref = self.datacontainer->get(position=self.qchoiceindex)

        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: point_to_up_z = ',ref->getproperty(tag='point_to_up_z')
            ref->setproperty,'point_to_up_z',event.value
            ;print,'After: point_to_up_z = ',ref->getproperty(tag='point_to_up_z')
        endif else begin
        endelse

    end;ATWPOINT_TO_UP_Z
    'ATWPOINT_TO_DOWN_Z':begin
            widget_control,self.atwpoint_to_down_z,get_value = value
            ;print,obj.id,+': ',value
            ref = self.datacontainer->get(position=self.qchoiceindex)
        if obj_isa(ref,'ooechomagnetic') eq 1 then begin
            ;print,'Before: point_to_down_z = ',ref->getproperty(tag='point_to_down_z')
            ref->setproperty,'point_to_down_z',event.value
            ;print,'After: point_to_down_z = ',ref->getproperty(tag='point_to_down_z')
        endif else begin
        endelse
    end;ATWPOINT_TO_DOWN_Z


    'ATWBCX':begin
            binarr = ['1','2','4','8','16']
            s = binarr[nse_comboindex(self.atw1)]
            ;widget_control,self.atw1,get_value = s  ;NEED TO CHECK TYPE FOR s
            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG
                x_cen_orig = (self.dataContainer->get(position=$
                            self.QChoiceIndex))->getProperty(tag='x_cen_orig')
                catch, /cancel
            endif


            ;GET ORIGINAL AND CURRENT IMAGE BINNINGS
            x_dim_orig = $
                    (self.dataContainer->get(position=$
                        i))->getProperty(tag='x_dim_orig')
            x_dim = $
                    (self.dataContainer->get(position=$
                        i))->getProperty(tag='x_dim')


            widget_control,self.atwbcx,get_value = x_cen_orig
            x_cen_orig = double(x_cen_orig)
            if x_cen_orig le 0.0d then begin
                x_cen_orig = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='x_cen_orig')
                widget_control,self.atwbcx,set_value=strtrim(string(x_cen_orig),1)
            endif


            (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,$
                                    'x_cen_orig',x_cen_orig

            self.beamcenxorig = x_cen_orig


            ;widget_control,self.atw1,get_value = s
            (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,'x_cen',$
                                x_cen_orig/double(s)

;            widget_control,self.atwbcx,get_value = x_cen
;            (self.dataContainer->get(position=$
;                        self.QChoiceIndex))->setProperty,'x_cen',x_cen
;



            ;SET ALL BEAM CENTERS TO SAME VALUE ASSUMING THAT
            ;ALL OF THE DATA WILL HAVE THE SAME BEAM POSITION

            ;051904
            ;
            ;SETTING DETECTOR CENTER VALUES TO BE
            ;BASED ON THE FULL DETECTOR SIZE ALWAYS.

            ;050704
            ;
            ;DURING DEMO THEY SAID TO USE SAME BEAM CENTER
            ;FOR A GIVEN WAVELENGTH.  SET ALL BEAM CENTERS
            ;TO SAME VALUE FOR A GIVEN WAVELENGTH.
            ;DO THIS FOR ATWBCX AND ATWBCY.
            ;
            ;NEED TO CLARIFY WHICH VALUE OF THE BEAM CENTER
            ;WILL BE USED (32x32 or 16x16, etc.)  FOR NOW
            ;ASSUME THAT THE CENTERS WILL BE SPECIFIED IN
            ;PIXELS AT CURRENT BINNING.
            ;
            ;ALSO NEED TO DO THIS ON READING A NEW FILE!!!
            ;
            lambdao = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='lambda')


            for i=0,self.dataContainer->count()-1 do begin

                lambda = $
                (self.dataContainer->get(position=$
                        i))->getProperty(tag='lambda')
                ;print,lambda

                if lambda eq lambdao then begin

                    self->setBeamCenter,self.QChoiceIndex,i
                    ;GET ORIGINAL AND CURRENT IMAGE BINNINGS
                    x_dim_orig = $
                    (self.dataContainer->get(position=$
                            i))->getProperty(tag='x_dim_orig')
                    x_dim = $
                    (self.dataContainer->get(position=$
                            i))->getProperty(tag='x_dim')


                    ;SET THE ORIGINAL BEAM CENTER
                    (self.dataContainer->get(position=$
                            i))->setProperty,'x_cen_orig',$
                            (self.dataContainer->get(position=$
                                    self.QChoiceIndex))->getProperty(tag='x_cen_orig')
                    ;SET THE BEAM CENTER FOR THE CURRENT BINNING
                    (self.dataContainer->get(position=$
                            i))->setProperty,'x_cen',$
                            (self.dataContainer->get(position=$
                                    self.QChoiceIndex))->getProperty(tag='x_cen_orig')*$
                                    (double(x_dim)/double(x_dim_orig))
                endif;lambda eq lambdao
            endfor;i
            self->draw
        end
    'ATWBCY':begin
            binarr = ['1','2','4','8','16']
            s = binarr[nse_comboindex(self.atw1)]

            ;widget_control,self.atw1,get_value = s  ;NEED TO CHECK TYPE FOR s
            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG
                y_cen_orig = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='y_cen_orig')
                catch, /cancel
            endif

            ;GET ORIGINAL AND CURRENT IMAGE BINNINGS
            y_dim_orig = $
                    (self.dataContainer->get(position=$
                        i))->getProperty(tag='y_dim_orig')
            y_dim = $
                    (self.dataContainer->get(position=$
                        i))->getProperty(tag='y_dim')

            widget_control,self.atwbcy,get_value = y_cen_orig


            y_cen_orig = double(y_cen_orig)
            if y_cen_orig le 0.0d then begin
                y_cen_orig = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='y_cen_orig')
                widget_control,self.atwbcy,set_value=strtrim(string(y_cen_orig),1)
            endif


            (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,'y_cen_orig',y_cen_orig


            ;widget_control,self.atw1,get_value = s
            (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,'y_cen',$
                                y_cen_orig/double(s)

            self.beamcenyorig = y_cen_orig



            ;SET ALL BEAM CENTERS TO SAME VALUE ASSUMING THAT
            ;ALL OF THE DATA WILL HAVE THE SAME BEAM POSITION

            lambdao = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='lambda')

            for i=0,self.dataContainer->count()-1 do begin
                lambda = $
                (self.dataContainer->get(position=$
                        i))->getProperty(tag='lambda')
                ;print,lambda

                if lambda eq lambdao then begin

                    ;GET ORIGINAL AND CURRENT IMAGE BINNINGS
                    y_dim_orig = $
                    (self.dataContainer->get(position=$
                            i))->getProperty(tag='y_dim_orig')
                    y_dim = $
                    (self.dataContainer->get(position=$
                            i))->getProperty(tag='y_dim')


                    ;SET THE ORIGINAL BEAM CENTER
                    (self.dataContainer->get(position=$
                            i))->setProperty,'y_cen_orig',$
                            (self.dataContainer->get(position=$
                                    self.QChoiceIndex))->getProperty(tag='y_cen_orig')
                    ;SET THE BEAM CENTER FOR THE CURRENT BINNING
                    (self.dataContainer->get(position=$
                            i))->setProperty,'y_cen',$
                            (self.dataContainer->get(position=$
                                    self.QChoiceIndex))->getProperty(tag='y_cen_orig')*$
                                    (double(y_dim)/double(y_dim_orig))
                endif;lambda eq lambdao
            endfor;i
            self->draw


        end;ATWBCY
    'ATWTRANS':begin
            widget_control,self.atwtrans,get_value=s

            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG
                trans = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='transmission')
                catch, /cancel
            endif


            trans = double(s)
            if trans le 0.0d then begin
                trans = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='transmission')
                widget_control,self.atwtrans,set_value=strtrim(string(trans),1)
            endif



            (self.dataContainer->get(position=$
                    self.QChoiceIndex))->setProperty,'transmission',trans

        end;ATWTRANS
    'ATWVOLFRAC':begin
            widget_control,self.atwvolfrac,get_value=s

            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG
                trans = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='volfrac')
                catch, /cancel
            endif


            volfrac = double(s)
            if volfrac le 0.0d then begin
                volfrac = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='volfrac')
                widget_control,self.atwvolfrac,set_value=strtrim(string(volfrac),1)
            endif

            (self.dataContainer->get(position=$
                    self.QChoiceIndex))->setProperty,'volfrac',volfrac

        end;ATWVOLFRAC
    'ATWNARCS':begin
            widget_control,self.atwnarcs,get_value=s

            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG
                narcs = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='narcs')
                catch, /cancel
            endif


            ;SET THE NUMBER OF ARCS THE SAME FOR ALL DATA SETS.
            ;THIS WILL REQUIRE THE USER TO RESET THE NUMBER OF ARCS
            ;ON CHANGING THE NUMBER OF ARCS
            ;narcs = double(s)

            narcs = fix(double(s))
            ;print,narcs

            ;DON'T ALLOW 1 ARC UNTIL ooEcho IS READY, AND NEVER ALLOW 0 ARCS

;072005
;            if narcs le 1 then begin
            if narcs lt 1 then begin
                narcs = 7
                widget_control,self.atwnarcs,set_value=strtrim(string(narcs),2)
            endif

            for n=0,self.dataContainer->count()-1 do begin
                (self.dataContainer->get(position=$
                        n))->setProperty,'narcs',narcs
            endfor
;                (self.dataContainer->get(position=$
;                        self.QChoiceIndex))->setProperty,'narcs',narcs

            self->draw      ;UPDATE DISPLAY SO Q LINES ARE DRAWN
        end;ATWNARCS
        'ATWWIDTH':begin

            ;062204
            ;
            ;SET GAUSSIAN WIDTH TO BE THE SAME FOR ALL
            ;DATA OBJECTS WITH THE CURRENT WAVELENGTH.
            ;
            ;UPDATE THE FIXED FIT PARAMETER FOR ALL DATA
            ;AND IN THE FIT PARAMETERS WIDGETS.

;            widget_control,self.atw1,get_value = s  ;NEED TO CHECK TYPE FOR s
            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG


            ;NEED TO ADD A DATA MEMBER TO ooEcho FOR THE WIDTH.
                ;SET A DEFAULT VALUE FOR THE WIDTH HERE.
                width = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='width')
                catch, /cancel
            endif

            ;GET ORIGINAL AND CURRENT IMAGE BINNINGS
            ;SET VALUES FOR WIDTH PARAMETER IN fitparms
            ;AND ALL OTHER DATA OBJECTS WITH THE SAME
            ;WAVELENGTH.

            width_orig = $
                    (self.dataContainer->get(position=$
                        i))->getProperty(tag='width')

            ;GET USER-ENTERED WITH FROM THE TEXT FIELD
            widget_control,self.atwwidth,get_value = swidth
            width = double(swidth)
            if width le 0.0d then begin
                width = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='width')
                widget_control,self.atwwidth,set_value=strtrim(string(width),1)
            endif


            self.gaussianWidth = width

            refq = (self.dataContainer->get(position=$
                                    self.QChoiceIndex))

            widthq_orig = refq->getProperty(tag='width')
            ;PLACE USER-ENTERED VALUE INTO THE CURRENT DATA OBJECT
            if widthq_orig ne width then begin
                refq->storefitparms
                refq->setProperty,'reduced',0
                refq->setWidth,width
                refq->setProperty,'width',width
            endif


            ;NOW UPDATE ALL OF THE RELEVANT DATA OBJECTS WITH THIS WIDTH
            lambdao = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='lambda')

            for i=0,self.dataContainer->count()-1 do begin
                refi = (self.dataContainer->get(position=i))
                help,refi,output=outrefi
                help,refq,output=outrefq
                if outrefi ne outrefq then begin
                    lambda = refi->getProperty(tag='lambda')
                    refi->storeFitparms

                    if lambda eq lambdao then begin
                        ;SET THE WIDTH OF THE SELECTED OBJECT TO THAT
                        ;OF THE CURRENT OBJECT
                        ;AND UPDATE THE "REDUCED" STATE IF THE VALUE CHANGED
;                        dum = dialog_message('oodisplayecho::textevents'+ $
;                                            string(refi->getProperty(tag='reduced')))
                        widthi_orig = refi->getProperty(tag='width')
                        if widthi_orig ne refq->getProperty(tag='width') then begin
                            refi->setProperty,'reduced',0
                        endif
                        refi->setProperty,'width',$
                                refq->getProperty(tag='width')
                        refi->setWidth,width;refq->getProperty(tag='width')
                    endif;lambda eq lambdao
                endif;outrefi
            endfor;i

            self->reDefineTree
            self->mouseHead,event
;            self->draw
;            self->redefineWidgets,self.QChoiceIndex

        end;ATWWIDTH
        'ATWPERIOD':begin

            ;062204
            ;
            ;SET GAUSSIAN WIDTH TO BE THE SAME FOR ALL
            ;DATA OBJECTS WITH THE CURRENT WAVELENGTH.
            ;
            ;UPDATE THE FIXED FIT PARAMETER FOR ALL DATA
            ;AND IN THE FIT PARAMETERS WIDGETS.

;            widget_control,self.atw1,get_value = s  ;NEED TO CHECK TYPE FOR s
            catch, Error_status
            ;Error handler in case of type conversion error in text field
            if (Error_status ne 0) then begin
                print, 'Error index: ', Error_status
                print, 'Error message: ', !ERROR_STATE.MSG


            ;NEED TO ADD A DATA MEMBER TO ooEcho FOR THE WIDTH.
                ;SET A DEFAULT VALUE FOR THE WIDTH HERE.
                width = self.periodvalue
;                        (self.dataContainer->get(position=$
;                        self.QChoiceIndex))->getProperty(tag='width')
                catch, /cancel
            endif

            ;GET ORIGINAL AND CURRENT IMAGE BINNINGS
            ;SET VALUES FOR WIDTH PARAMETER IN fitparms
            ;AND ALL OTHER DATA OBJECTS WITH THE SAME
            ;WAVELENGTH.

            period_orig = $
                    (self.dataContainer->get(position=$
                        i))->getProperty(tag='period')

            ;GET USER-ENTERED WITH FROM THE TEXT FIELD
            widget_control,self.atwperiod,get_value = speriod
            period = double(speriod)
            if period le 0.0d then begin
                period = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='period')
                widget_control,self.atwperiod,set_value=strtrim(string(period),1)
            endif
            self.periodvalue = period

            refq = (self.dataContainer->get(position=$
                                    self.QChoiceIndex))

            periodq_orig = refq->getProperty(tag='period')
            ;PLACE USER-ENTERED VALUE INTO THE CURRENT DATA OBJECT
            if periodq_orig ne period then begin
                refq->storefitparms
                refq->setProperty,'reduced',0
                refq->setPeriod,period
                refq->setProperty,'period',period
            endif


            ;NOW UPDATE ALL OF THE RELEVANT DATA OBJECTS WITH THIS WIDTH
            lambdao = (self.dataContainer->get(position=$
                        self.QChoiceIndex))->getProperty(tag='lambda')

            for i=0,self.dataContainer->count()-1 do begin
                refi = (self.dataContainer->get(position=i))
                help,refi,output=outrefi
                help,refq,output=outrefq
                if outrefi ne outrefq then begin
                    lambda = refi->getProperty(tag='lambda')
                    refi->storeFitparms

                    if lambda eq lambdao then begin
                        ;SET THE PERIOD OF THE SELECTED OBJECT TO THAT
                        ;OF THE CURRENT OBJECT
                        ;AND UPDATE THE "REDUCED" STATE IF THE VALUE CHANGED
                        periodi_orig = refi->getProperty(tag='period')
                        if periodi_orig ne refq->getProperty(tag='period') then begin
                            refi->setProperty,'reduced',0
                        endif
                        refi->setProperty,'period',$
                                refq->getProperty(tag='period')
                        refi->setPeriod,refq->getProperty(tag='period')
                    endif;lambda eq lambdao
                endif;outrefi
            endfor;i

            self->reDefineTree
            self->mouseHead,event

        end;ATWPERIOD
    'ATWLAMBDA':begin
        widget_control,self.atwlambda,get_value=sval
        ;val = strtrim(val,2)
        val = double(sval)
        if val le 0.0d then begin
            val = (self.dataContainer->get(position=$
                    self.QChoiceIndex))->getProperty(tag='lambda')
            widget_control,self.atwlambda,set_value=strtrim(string(val),2)
        endif


       (self.dataContainer->get(position=$
                self.QChoiceIndex))->setProperty,'lambda',val*((10.0d^(-10.0d)))
    end;ATWLAMBDA
    'ATWLAMBDADIST':begin
        widget_control,self.atwlambdadist,get_value=sval
        ;val = strtrim(sval,2)
        ;print,sval
        val = double(sval)
        ;print,val
        if val le 0.0d then begin
            val = (self.dataContainer->get(position=$
                    self.QChoiceIndex))->getProperty(tag='dlambda')
            widget_control,self.atwlambdadist,set_value=strtrim(string(val),2)
        endif


        lambda = (self.dataContainer->get(position=$
                    self.QChoiceIndex))->getProperty(tag='lambda')

       (self.dataContainer->get(position=$
                self.QChoiceIndex))->setProperty,'dlambda',$
                    (val/100.0)*lambda
    end;ATWLAMBDADIST
    'ATWCONST':begin
        self->handleFitparmTextWidgetEvents
    end;ATWCONST
    'ATWAMP':begin
        self->handleFitparmTextWidgetEvents
    end;ATWAMP
    'ATWPHASEO':begin
        self->handleFitparmTextWidgetEvents
    end;ATWPHASEO
    'ATWSIGMA':begin
        self->handleFitparmTextWidgetEvents
    end;ATWSIGMA
    'ATWOMEGA':begin
        ;print,'ooDisplayEcho::textEvents'
        self->handleFitparmTextWidgetEvents
    end;ATWOMEGA
    'ATWPHASE':begin
        self->handleFitparmTextWidgetEvents
    end;ATWPHASE
    else:begin
            widget_control,self.tw1,set_value=obj.id+': unsure of widget choice.'
        end
    endcase

end;textEvents
pro ooDisplayEcho::handleFitparmTextWidgetEvents
;
;NAME:
;        ooDisplayEcho::handleFitparmTextWidgetEvents
;
;PURPOSE:
;               Get the current values in the fit parameters text widgets
;               and apply them to the current data object
;PARAMETERS:
;               none
;KEYWORDS:
;               none

        ;022406
        parms = self->getParmsFromTextWidgets()

        ;HANDLE omega v. period ISSUE
        ;print,parms[4]
        if parms[4] lt 0.0 then parms[4] = -1.0*parms[4]
        ;print,parms[4]
        if parms[4] lt 10.0 then begin
            parms[4] = 360.0/parms[4]
            widget_control,self.atwomega,set_value=strtrim(string(parms[4]),2)
        endif

        ref = self.datacontainer->get(position=self.qchoiceindex)
        ref->setParms,parms,self.xindex,self.yindex,self.ftChoiceIndex;,parmindex=0
        ;print,(*(ref->getproperty(tag='fitparms')))[0:5,self.xindex+self.yindex*self.detxdim,self.ftchoiceindex]
        self->draw,textfitparms = parms,/no_update

end;handleFitparmTextWidgetEvents

function ooDisplayEcho::getParmsFromTextWidgets
;
;NAME:
;        ooDisplayEcho::getParmsFromTextWidgets
;
;PURPOSE:
;               Get the current values in the fit parameters text widgets
;PARAMETERS:
;               event   The file tree event structure.
;KEYWORDS:
;               none


        parms = dblarr(6)
        parms[4] = 360.0
        ref = (self.dataContainer->get(position=self.QChoiceIndex))

        ;AVERAGE
        widget_control,self.atwconst,get_value=savval
        avval = double(savval)
        if avval le 0.0 then begin
            avval = (*(ref->getProperty(tag='fitparms')))[0,self.xindex+self.yindex*self.detxdim,self.ftChoiceIndex]
        endif


        ;AMPLITUDE
        widget_control,self.atwamp,get_value=sampval
        ampval = double(sampval)


        if ampval le 0.0 then begin
            ;CHECK IF THE OBJECT REFERENCE IS A HYDROGENATED SAMPLE AND ALLOW NEGATIVE AMPLITUDES IF IT IS.
            hydrogenated = ref->checkHydrogenated(self.xindex,self.yindex,self.ftchoiceindex)
            if hydrogenated eq 0 then $
                ampval = (*(ref->getProperty(tag='fitparms')))[1,self.xindex+self.yindex*self.detxdim,self.ftChoiceIndex]
        endif


        ;PHASE
        widget_control,self.atwphaseo,get_value=sval
        phase = double(sval)

        ;if phase eq 0.0d then begin
        ;    phase = (*(ref->getProperty(tag='fitparms')))[2,self.xindex+self.yindex*self.detxdim,self.ftChoiceIndex]
        ;endif


        ;WIDTH
        widget_control,self.atwsigma,get_value=sval
        width = double(sval)
        if width le 0.0 then begin
            width = (*(ref->getProperty(tag='fitparms')))[3,self.xindex+self.yindex*self.detxdim,self.ftChoiceIndex]
        endif


        ;PERIOD
        widget_control,self.atwomega,get_value=sval
        period = double(sval)
        if period le 0.0 then begin

            ;022306
            period = -1.0*period
            ;if period
            ;period = 360.0/(*(ref->getProperty(tag='fitparms')))[4,self.xindex+self.yindex*self.detxdim,self.ftChoiceIndex]
        endif

        ;PHASE OFFSET
        widget_control,self.atwphase,get_value=sval
        phaseoffset = double(sval)
        if phaseoffset le 0.0 then begin
            phaseoffset = (*(ref->getProperty(tag='fitparms')))[5,self.xindex+self.yindex*self.detxdim,self.ftChoiceIndex]
        endif


        parms = [avval,ampval,phase,width,period,phaseoffset]

        return,parms
end;getParmsFromTextWidgets
pro ooDisplayEcho::treeEvents,event
;
;NAME:
;        ooDisplayEcho::treeEvents
;
;PURPOSE:
;               Handle events from the file tree.
;PARAMETERS:
;               event   The file tree event structure.
;KEYWORDS:
;               none

    widget_control,event.id,get_uvalue = obj
;    print,'treeEvent occurred. '+obj.id+string(obj.element)
    widget_control,self.tw1,set_value=obj.id;+string(obj.index)
;print,'022406 ooDisplayEcho::treeEvents'
;print,tag_names(event,/structure_name)
;print,tag_names(event)
;print,event

    if (tag_names(event, /STRUCTURE_NAME) eq 'WIDGET_TREE_SEL') then begin

        if (obj.id eq 'FTW') then begin
            ;ONLY MAKE CHANGES IF THE SELECTED TREE LEAF CHANGES.
            refnew = self.datacontainer->get(position=obj.index)

            ntnew = refnew->getproperty(tag = 'no_of_fourier_times')
            refold = self.datacontainer->get(position=self.qChoiceIndex)
            ntold = refold->getproperty(tag = 'no_of_fourier_times')
            if obj.index ne self.QChoiceIndex $
                or ntnew ne ntold $
                    or self.datacontainer->count() eq 0 then begin


                self.QChoiceIndexOld = self.QChoiceIndex
                self.ftChoiceIndexOld = self.ftChoiceIndex

                oldQIndex = self.QChoiceIndex
;120804

                self->swapDataObject,oldQIndex,obj.index

                ;DOES swapDataObject CHANGE SELECTED FOURIER TIME?
                ;AND DOES IT CALL mouseHead OR SIMILAR?

;            self->reDefineWidgets,obj.index
;            self->updateMaskmaker

                self->mouseHead,event
            ;UPDATE THE DISPLAY
;            self->draw
            endif else begin
                self->mouseHead,event,t=self.ftchoiceindex
            endelse


        endif;FTW
    endif

    IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_CONTEXT') THEN begin
        self->contextEvents,event
    ENDIF

end;treeEvents
pro ooDisplayEcho::do_nothing,event
;
;NAME:
;        ooDisplayEcho::do_nothing
;
;PURPOSE:
;           A "do nothing" method for events that should have no effects.
;PARAMETERS:
;           event   The event passed to this method.  Only necessary for
;                   the syntax of event handlers.
;KEYWORDS:
;           none

    ;EVENT HANDLING METHOD WHEN NOTHING IS TO BE DONE.
    print,'Doing nothing.'
end;do_nothing




;021505
;#####################################################
;THREE NEW PROCEDURES TO ADD TO THE HEADER.
;#####################################################
pro ooDisplayEcho_removeTEvents,event
    widget_control,event.handler,get_uvalue=uval
    ;print,event.id

    ;print,uval.id

    self=uval.object
    self->removeTEvents,event
end;
pro ooDisplayEcho::removeTEvents,event
;
;NAME:
;           ooDisplayEcho::removeTEvents
;
;PURPOSE:
;           Create a list widget to remove Fourier Times
;           Events will be handled by ooDisplayEcho::removeTEvents
;PARAMETERS:
;           event   Event to handle.
;KEYWORDS:
;           none
;

    ;print,'ooDisplayEcho::removeTEvents REMOVING FOURIER TIME EVENTS'
    ;print,tag_names(event)
    ;print,event


    if event.close eq 1 then begin
        ;print,'ooDisplayEcho::removeTEvents event.top=',event.top
        widget_control,event.top,/destroy


    endif else begin
        if event.t ne '-1' then begin
            oldIndex = self.QChoiceIndex

            tremove = (((10.0d)^(-9.0d))*float(event.t))
            ;print,'tremove=',tremove
            origdataobj = self.datacontainer->get(position=self.QChoiceIndex)
;print,'obj_isa(origdataobj,"ooechomagnetic") = ',obj_isa(origdataobj,"ooechomagnetic")

            ;SHOULD CONVERT ooEcho::getProperty TO BE CASE INSENSITIVE
            ;print,origdataobj->getproperty(tag='fourierTime')

;print,'ooDisplayEcho::removeTEvents: orig ',origdataobj->getproperty(tag='point_to_down_z')
            new_dataobj = origdataobj->removeT(tremove)
;print,'ooDisplayEcho::removeTEvents: orig ',origdataobj->getproperty(tag='point_to_down_z')
;print,'ooDisplayEcho::removeTEvents: new  ',new_dataobj->getproperty(tag='point_to_down_z')


            if obj_valid(new_dataobj) then begin
;                print,'ooDisplayEcho::removeTEvents new_dataobj is VALID'
                newIndex = self.datacontainer->count()
                self.datacontainer->add,new_dataobj,position=newIndex
                self.QChoiceIndex = newIndex


;                self->swapDataObject,oldIndex,newIndex
;                self->mouseHead,event
                self->reDefineWidgets,count
                self->redefineTree
                self->draw



            endif
        endif;event.t
    endelse

end;removeTEvents
function ooDisplayEcho::createRemoveTList
;
;NAME:
;        ooDisplayEcho::createRemoveTList
;
;PURPOSE:
;           Create a list widget to remove Fourier Times
;           Events will be handled by ooDisplayEcho::removeTEvents
;PARAMETERS:
;           none
;KEYWORDS:
;           none
;RETURN VALUE:
;           1 success, 0 for failure
;

            ;CHECK FOR EXISTING removet DIALOG.
            n=checkforobjinstance('cwo_removetlist',ref=dref)
            ;print,'ooDisplayEcho::contextEvents # of existing dialogs ='+string(n)

;            ;IF ONE EXISTS GET ITS BASE AND DESTROY IT.
;            if n eq 1 then begin
;                removetbase=dref[0]->getproperty(/tlb)
;                obj_destroy,dref[0]
;            endif else begin
;                removetbase=widget_base(xsize=100,ysize=100,group_leader=self.atlb,$
;                                        title='SELECT FOURIER TIMES FOR REMOVAL',/modal)
;            endelse
;
                removetbase=widget_base(group_leader=self.atlb,xsize=250,$
                                        title='SELECT FOURIER TIMES FOR REMOVAL',/modal)

            ;print,'removetbase=',removetbase
            widget_control,removetbase,/realize

            ref = self.datacontainer->get(position=self.QChoiceIndex)
            taus = ((10.0)^(9.0))*(*(ref->getproperty(tag='fourierTime')))

            vals = strtrim(string(taus),2)

            ;DEFINE THE NEW DIALOG
            wid = cwo_removetlist(removetbase,$
                                    obj_ref=obj_ref,$
                                    value=vals)
;            print,wid
;            print,obj_ref->getproperty(/tlb)
;            help,obj_ref


        if widget_info(wid,/valid_id) ne 0 then begin
            uval = {object:self,method:'removeTEvents',id:'REMOVETDIALOG',obj_ref:obj_ref}
            widget_control,wid,set_uvalue=uval
            widget_control,removetbase,set_uvalue=uval

            xmanager,'createRemoveTList',wid,event_handler='ooDisplayEcho_removeTEvents',/no_block

            return,1
        endif else return,0

end;createRemoveTList


;#############################################################################################



pro ooDisplayEcho::contextMenuEvents,event
;
;NAME:
;        ooDisplayEcho::contextMenuEvents
;
;PURPOSE:
;               Handle events generated by context menu event buttons.
;               Note: Some context menus are copies of file menus (e.g. image options),
;                     so their events for to ooDisplayEcho::menuEvents
;PARAMETERS:
;               event   The event structure to handle.
;KEYWORDS:
;               none

    ;HANDLE EVENTS GENERATED BY CONTEXT MENU BUTTONS.


;    print,tag_names(event)
;    print,event
;    sel_id = widget_info(event.handler,/tree_select)
;    print,self.atlb
;    print,'sel_id = ',sel_id


    widget_control,event.id,get_uvalue = obj
    widget_control,self.tw1,set_value=obj.id

    case obj.id of
        'UNTYPED':begin
                (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,'type',0

                widget_control,self.atwtrans,editable = 1
                widget_control,self.atwvolfrac,editable = 1
                self->redefineTree
            end
        'RESOLUTION':begin
                (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,'type',1
                widget_control,self.atwtrans,editable = 0
                widget_control,self.atwvolfrac,editable = 0
                self->redefineTree
            end
        'RAWDATA':begin
                (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,'type',2
                widget_control,self.atwtrans,editable = 1
                widget_control,self.atwvolfrac,editable = 1
                self->redefineTree
            end
        'BACKGROUND':begin
                (self.dataContainer->get(position=$
                        self.QChoiceIndex))->setProperty,'type',3
                widget_control,self.atwtrans,editable = 1
                widget_control,self.atwvolfrac,editable = 0
                self->redefineTree
            end
        'QNEWSET':begin
                widget_control,self.treeSelectID,get_value=text
                segs = strsplit(text,'=',/extract)
                theQ = double(segs[1])
                pos = (self.setContainer)->count()
                theName = 'Set'+strtrim(pos,2)

                otemp = obj_new('ooDisplayEchoTreeSet',q=theQ,$
                                                        name=theName)

                (self.setContainer)->add,otemp,position=pos
                self->redefineTree
            end;QNEWSET

        'SETIQTCALC': begin
                        print,'SET UP TO CALCULATE I(Q,T) FOR THIS SET'
                    end
        'SETCHANGENAME': begin
                        widget_control,self.treeSelectID,get_uvalue=uval
                        index=uval.index
                        self->setNameDialog,index
                        self->redefineTree
                    end;SETCHANGENAME
        'SETREMOVESET': begin
                        ;print,'SET UP SET REMOVAL DIALOG'
                        ;self->removeSetDialog
                        widget_control,self.treeSelectID,get_uvalue=uval
                        index=uval.index
                        ref = (self.setContainer)->get(position=index)
                        obj_destroy,ref
                        (self.setContainer)->remove,position=index
                        self->redefineTree
                    end;SETREMOVESET
        'SETSETQVALUE': begin
                        print,'SET UP Q-VALUE CHANGE DIALOG'
                    end;SETSETQVALUE
        'SETREMOVEOBJECT': begin
                        print,'SET UP DIALOG TO REMOVE AN INDIVIDUAL' $
                            +'OBJECT FROM THE SELECTED SET.'
                    end;SETREMOVEOBJECT

        'ASSIGNOBJ': begin
                        ;self.treeSelectID = sel_id
                        ;self.treeSelectVal = val
                        self->setSelectDialog
                        self->redefineTree

                end;ASSIGNOBJ
        'REMOVEOBJ': begin
                        self->remove
                end;REMOVEOBJ
        'DUPLICATEOBJ':begin
                        self->duplicateCurrentObject
        end;DUPLICATEOBJ
        'REMOVEMULTIPLEOBJ':begin

                    ;FIGURE OUT WHICH LEAVES ARE SELECTED
                    sel_id = widget_info(self.ftree,/tree_select)

                    ;GET THE POSITIONS IN self.dataContainer OF THE FILES THAT ARE SELECTED
                    selectindices = [-1]
                    for i=0,n_elements(sel_id)-1 do begin
                        widget_control,sel_id[i],get_uvalue=uval
                        if uval.id eq 'FTW' then begin
                            selectindices = [selectindices,uval.index]
                        endif
                    end;i
                    if n_elements(selectindices) gt 1 then begin
                        selectindices = selectindices[1:*]

                        selected = reverse(selectindices[sort(selectindices)])

                        ;NOW REMOVE THE OBJECTS FROM THE END TO THE BEGINNING.
                        for i=0,n_elements(selected)-1 do begin
                            self->remove,dataObjIndex=selected[i]
                        endfor;i
                    endif

                end;REMOVEMULTIPLEOBJ
        'MERGEOBJ': begin
                self->mergeDialog
                self->redefineTree

            end;MERGEOBJ
        'REMOVEFOURIERTIMEMENU':begin
             print,'ooDisplayEcho::contextEvents ',self->createRemoveTList()

        end;REMOVEFOURIERTIMEMENU
        'SAVEFITPARAMETERS':begin
                ref = self.datacontainer->get(position=self.QChoiceIndex)
                ref->writeFitparmsToFile,/nomasked
            end;SAVEFITPARAMETERS
        'SAVEDATAITEMS':begin
                ref = self.datacontainer->get(position=self.QChoiceIndex)
                ref->outputEchoDataItems

        end;SAVEDATAITEMS

        'REMOVEFOURIERTIME':begin
;                print,tag_names(event)
;                print,event
;                print,event.id


             print,'ooDisplayEcho::contextEvents ',self->createTContext()

                widget_control,event.id,get_uvalue=uval
                ;print,'uval.time = ',uval.time



                ref = self.datacontainer->get(position=self.QChoiceIndex)




                ;ref->removeFourierTime,uval.time
                self.datacontainer->add,ref->removeT(uval.time),position=self.datacontainer->count()
;                print,string(13b)+string(13b)
;                print,'ONCE YOU REMOVE A FOURIER TIME YOU MUST '
;                print,'UPDATE THE DISPLAY TO REFLECT THE NEW STATUS'
;                print,'OF THE CURRENT DATA OBJECT.'
;                print,'IS THIS UPDATE CONTAINED IN ooDisplayEcho::redefineTree?'
;                print,'IS THERE A CALL TO draw???'
;                print,string(13b)+string(13b)




                self->redefineTree
                self->reDefineWidgets;,n,t=t,newsize=newsize


        end;REMOVEFOURIERTIME

        'KEEPQ': self->do_nothing,event     ;CREATING GROUPS AND ASSIGNING
        'OBJNEWSET': begin
                    ;PRINT Q VALUE OF SELECTED LEAF
                        ;self.treeSelectID = sel_id
                        ;self.treeSelectVal = val
                        widget_control,self.treeSelectID,get_uvalue=uval
                        dataObjIndex = uval.index

                ;GET WIDGET ID OF Q LEAF
                parent = widget_info(self.treeSelectID,/parent)

                ;GET Q VALUE FROM THE Q LEAF
                widget_control,parent,get_value=text
                ;print,'OBJNEWSET'
                ;print,text
                segs = strsplit(text,'=',/extract)
                ;print,segs
                theQ = double(segs[1])
                setpos = (self.setContainer)->count()
                theName = 'Set'+strtrim(setpos,2)
                otemp = obj_new('ooDisplayEchoTreeSet',q=theQ,$
                                                        name=theName,$
                                                        container=self.dataContainer,$
                                                        index=dataObjIndex $
                                                        )

                ;ASSIGN THE SELECTED OBJECT TO THE TREE BASED ON TYPE
                ;IF NO TYPE THEN NO ASSIGNMENT --- HANDLED IN SET INIT
                ;


                (self.setContainer)->add,otemp,position=setpos
                self->redefineTree

                ;
                ;
                ;
                ;HANDLE THIS EVENT WITH THE FOLLOWING:
                    ; - CREATE NEW FOLDER WITH THIS Q
                    ; - MOVE SELECTED LEAF INTO NEW FOLDER
                ;
                ;
                ;

                    self->do_nothing,event
                ;CREATE NEW SET OBJECT.
                ;UPDATE TREE.
                end
        'SEND_IQTS_TO_PAN':begin

;022406
                print,'___________________________________________________________'
                print,'ooDisplayEcho::contextMenuEvents'
                print,'___________________________________________________________'
                print,'SEND THE I(Q,t) DATA TO PAN FOR SELECTED OBJECTS.'
                widget_control,event.id,get_uvalue = obj
                widget_control,self.tw1,set_value=obj.id
                ;print,'obj.id=',obj.id

                ;FIGURE OUT WHICH LEAVES ARE SELECTED
                sel_id = widget_info(self.ftree,/tree_select);event.id,/tree_select)
                ;print,'sel_id=',sel_id

                ;NOW GET THE RELEVANT DATA OBJECTS
                for i=0,n_elements(sel_id)-1 do begin

                    widget_control,sel_id[i],get_uvalue = obj,get_value=val

                    ;ONLY SELECT THE TREE LEAVES THAT ARE DATA OBJECTS (NOT FOLDERS)
                    if obj.id eq 'FTW' then begin
                        print,obj.index
                        ref = self.datacontainer->get(position=obj.index)
                        print,file_basename(ref->getproperty(tag='filename'))
                        print,val

                        ;NOW CREATE THE DAVE POINTER(S) TO SEND TO PAN


                    endif
                endfor;i

        end;SEND_IQTS_TO_PAN
        'FIT_ALL_SETS_WITH_SAME_RESOLUTION':begin

                print,'SEND THE I(Q,t) DATA TO PAN FOR SELECTED OBJECTS.'
                widget_control,event.id,get_uvalue = obj
                widget_control,self.tw1,set_value=obj.id
                ;print,'obj.id=',obj.id

                ;FIGURE OUT WHICH LEAVES ARE SELECTED
                sel_id = widget_info(self.ftree,/tree_select);event.id,/tree_select)
                ;print,'sel_id=',sel_id

                ;NOW GET THE RELEVANT DATA OBJECTS
                for i=0,n_elements(sel_id)-1 do begin

                    widget_control,sel_id[i],get_uvalue = obj,get_value=val

                    ;ONLY SELECT THE TREE LEAVES THAT ARE DATA OBJECTS (NOT FOLDERS)
                    if obj.id eq 'FTW' then begin
                        print,obj.index
                        ref = self.datacontainer->get(position=obj.index)
                        print,file_basename(ref->getproperty(tag='filename'))
                        print,val
                    endif


                endfor;i

        end;FIT_ALL_SETS_WITH_SAME_RESOLUTION
        else: begin                         ;TO GROUPS.
                self->do_nothing,event      ;050704
                print,'ooDisplayEcho::contextMenuEvents do nothing'
            end
    endcase;obj.id

    ;print,'Context Menu Events'
end;contextMenuEvents

pro ooDisplayEcho::remove,dataObjIndex=dataObjIndex
;
;NAME:
;        ooDisplayEcho::remove
;
;PURPOSE:
;           Handle both single and multiple removes.
;PARAMETERS:
;           none
;KEYWORDS:
;           dataObjIndex    Index of the data object to remove from the self.dataContainer


        ;CHECK IF OBJECT IN SET.  IF IT IS
        ;THEN REMOVE THE INDEX FROM THAT SET AND DESTROY THE
        ;OBJECT


            if n_elements(dataObjIndex) eq 0 then begin
                widget_control,self.treeSelectID,get_uvalue=uval
                dataObjIndex = uval.index
            endif

            ;REMOVE DATA OBJECT POSITION FROM ALL SETS
            ;_AND_ DECREMENT ALL HIGHER INDICES
            ;FILENAMES SHOULD BE OK.
            for i=0,(self.setContainer)->count()-1 do begin
                ref = (self.setContainer)->get(position=i)
                if ref->getProperty(/resIndex) ge dataObjIndex $
                    then begin
                        if ref->getProperty(/resIndex) eq dataObjIndex then begin
                            ref->setProperty,resIndex = -1
                        endif
                        if ref->getProperty(/resIndex) eq dataObjIndex then begin
                            ref->setProperty,resIndex = ref->getProperty(/resIndex)-1
                        endif
                endif

                if ref->getProperty(/datIndex) eq dataObjIndex $
                    then begin
                        if ref->getProperty(/datIndex) eq dataObjIndex then begin
                            ref->setProperty,datIndex =-1
                        endif
                        if ref->getProperty(/datIndex) eq dataObjIndex then begin
                            ref->setProperty,datIndex = ref->getProperty(/datIndex)-1
                        endif
                endif
                if ref->getProperty(/bkgIndex) eq dataObjIndex $
                    then begin
                        if ref->getProperty(/bkgIndex) eq dataObjIndex  then begin
                            ref->setProperty,bkgIndex =-1
                        endif
                        if ref->getProperty(/bkgIndex) eq dataObjIndex then begin
                            ref->setProperty,bkgIndex = ref->getProperty(/bkgIndex)-1
                        endif
                endif
            endfor;i
            ;UPDATE LIST OF SET MEMBERS
            if ptr_valid(self.setMembers) gt 0 then begin
                temp = [-1]
                ptr_free,self.setMembers
            endif else begin
                temp = [-1]
            endelse
            for i=0,(self.setContainer)->count()-1 do begin
                ref = (self.setContainer)->get(position=i)
                temp = [temp,ref->getProperty(/resIndex),$
                             ref->getProperty(/datIndex),$
                             ref->getProperty(/bkgIndex)]
            endfor;i
            self.setMembers = ptr_new(temp)

            ;DELETE OBJECT
            objRef = (self.dataContainer)->get(position=dataObjIndex)
            (self.dataContainer)->remove,position=dataObjIndex
            obj_destroy,objRef

            self->redefineTree
            if (self.dataContainer)->count() gt 0 then begin
                self->reDefineWidgets,newsize=1,t=0;,n,t=t
            endif


end;ooDisplayEcho::remove

pro ooDisplayEcho::duplicateCurrentObject
;
;NAME:
;        ooDisplayEcho::duplicateCurrentObject
;
;PURPOSE:
;           Duplicate the current data object and place copy in tree.
;PARAMETERS:
;           none
;KEYWORDS:
;           none

    if self.dataContainer->count() gt 0 then begin
        ref  = self.datacontainer->get(position=self.QChoiceIndex)
        temp = ref->clone()
        self.datacontainer->add,temp
        self->redefineTree
        self->reDefineWidgets
    endif


end;


pro ooDisplayEcho::contextEvents,event
;
;NAME:
;        ooDisplayEcho::contextEvents
;
;PURPOSE:
;           Decide which context menu to display and display it
;           when a context event occurs.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none

;    print,TAG_NAMES(event, /STRUCTURE_NAME)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;GET INDEX NUMBER OF SELECTED TREE WIDGET

    ;FIGURE OUT WHICH LEAF WAS SELECTED
    sel_id = widget_info(event.id,/tree_select)

    print,'sel_id=',sel_id

    if n_elements(sel_id) eq 1 then begin

            widget_control,sel_id,get_value=val

            ;print,'ooDisplayEcho::contextEvents  '

            ;print,sel_id,' ',val
            self.treeSelectID = sel_id
            self.treeSelectVal = val
            ;GET UVALUE OF SELECTED LEAF AND DISPLAY APPROPRIATE MENU
            widget_control,sel_id,get_uvalue=uval
                case uval.id of
                'FTW':   $
                    begin
                        ;GET CONTEXT MENU AND DISPLAY.
                        par = widget_info(sel_id,/parent)
                        widget_control,par,get_uvalue=puval
                        if puval.id eq 'QTW' then begin
                            context_base = widget_info(event.top, $
                                                       find_by_uname = 'FTW_MENU')
                        endif else begin
                            context_base = widget_info(event.top, $
                                                       find_by_uname = 'FTW_MENU_S')
                        endelse


        ;MOVE THE createTContext CALL TO contextMenuEvents
        ;                ;NOW DESTROY THE PREVIOUS FOURIER TIME REMOVAL CONTEXT MENU
        ;                ;AND CREATE A NEW ONE TO ADD TO THE MENU TO BE DISPLAYED HERE.
        ;                print,'ooDisplayEcho::contextEvents ',self->createTContext()

                        widget_displaycontextmenu,  event.id, $
                                                    event.x, event.y, $
                                                    context_base
                    end
                'STW':   $
                    begin
                        ;GET CONTEXT MENU AND DISPLAY.
                        context_base = widget_info(event.top, $
                                                    find_by_uname = 'STW_MENU')
                        widget_displaycontextmenu,  event.id, $
                                                    event.x, event.y, $
                                                    context_base
                    end
                'QTW':   $
                    begin
                        ;GET CONTEXT MENU AND DISPLAY.
                        context_base = widget_info(event.top, $
                                                   find_by_uname = 'QTW_MENU')
                        widget_displaycontextmenu, event.id, $
                                                    event.x, event.y, $
                                                    context_base
                    end
                else: begin
                        widget_control,sel_id,get_uvalue=uval
                        print,'TREE WIDGET UNKNOWN'
                        ;print,uval
                    end
                endcase
    endif else begin
        ;MULTIPLE SELECTION

        context_base = widget_info(event.top, $
                                   find_by_uname = 'FTW_MULTI_MENU')
        widget_displaycontextmenu, event.id, $
                                    event.x, event.y, $
                                    context_base


        print,'022406   ooDisplayEcho::contextEvents'
        print,'Multiple selections:
        print,'_______________________________'
        for i=0,n_elements(sel_id)-1 do begin
            print,'sel_id[',i,']=',sel_id[i]
            widget_control,sel_id[i],get_value=val
            print,'val=',val

        endfor;i
    endelse
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;        widget_control,self.ftree,/destroy
;        self->treeDefine
end;contextEvents




function ooDisplayEcho::createTContext;,parent,vals
;
;NAME:
;        ooDisplayEcho::createTContext;
;
;PURPOSE:
;           Create a context submenu to list the Fourier times available
;           for removal from the selected data object.
;PARAMETERS:
;           none
;KEYWORDS:
;           none
;RETURN VALUE:
;           The parent of this menu.



    ;011105
    ;
    ;THIS WILL BE USED FOR FOURIER TIME SELECTION FOR REMOVAL.
    ;
    ;
    ;THIS FUNCTION WILL CREATE THE CONTEXT MENU ON THE FLY, AND
    ;EVENTS FROM THE BUTTONS WILL HAVE TO SELECT THE CHOSEN BUTTON
    ;FROM THE LIST OF FOURIER TIMES EITHER BY STRING COMPARISON OR
    ;BY NUMERICAL VALUE.
    ;
    ;
    ;TYPE OF PARENT SHOULD BE EXAMINED AT RUN TIME.
    ;IF THE PARENT IS A CONTEXT MENU THEN DON'T CREATE A CONTEXT BASE,
    ;OTHERWISE CREATE A CONTEXT BASE.
    ;
    ;
    ;

    ;IN PRINCIPAL THE parent CAN BE SUBMITTED VIA THE ARGUMENT FOR
    ;MORE FLEXIBILITY FOR CONTEXT-MENU LOCATIONS LATER ON.
    parent = self.removeFourierTimeMenu
    ;print,widget_info(parent,/valid_id)

    ;DESTROY OLD MENU IF IT STILL EXISTS
    oldcb = widget_info(self.removeFourierTimeMenu,/child)
    ;print,widget_info(oldcb,/valid_id)
    if widget_info(oldcb,/valid_id) gt 0 then widget_control,oldcb,/destroy

    ;print,widget_info(self.removeFourierTimeMenu,/valid_id)



    ;GET THE FOURIER TIMES AND CREATE A STRING ARRAY FOR MENU LABELS
    fourierTime = *((self.datacontainer->get(position=self.QChoiceIndex))->getProperty(tag='fourierTime'))
    vals = strtrim(string(fourierTime*(10.0)^9),2)


    ;THE NEXT STEP CRASHES IN X11 DISPLAYS.
    ;CREATE THE MENU
    cb = widget_button(parent,value='Choose Time (ns) to Remove',/menu)
    for i=0,n_elements(vals)-1 do begin
        button = widget_button(cb)
        theval = vals[i];+' butID='+strtrim(string(button),2)
        theuval = {object:self,method:'contextMenuEvents',id:'REMOVEFOURIERTIME',time:fourierTime[i]}
        widget_control,button,set_value = theval
        widget_control,button,set_uvalue=theuval
        ;set_uvalue FOR ooDisplayEcho
    endfor


    return,parent
end;createTContext



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::swapDataObject,n_old,n_new
;
;NAME:
;        ooDisplayEcho::swapDataObject
;
;PURPOSE:
;           To swap the current data object selection with a new one and
;           update all of the widgets in ooDisplayEcho
;PARAMETERS:
;           n_old       not used
;           n_new       Ths position of the new data object in the container.
;KEYWORDS:
;           none.

    ;THE PURPOSE OF THIS METHOD IS TO PUT THE CURRENT DATA OBJECT
    ;INTO THE dataContainer AND PULL OUT THE NEXT OBJECT.
;    print,self.dataContainer->count(),'test'

;    print,'step1'
;    help,/heap,/brief
;    dummy = self.datacontainer->get(position=n_old)
;    self.dataContainer->remove,position=n_old
;    obj_destroy,dummy



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;THIS METHOD PRODUCES A MASSIVE MEMORY LEAK EACH TIME
    ;IT IS RUN --- ~6 obj & 85 ptr on each pass!!!!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;    print,'step2'
;    help,/heap,/brief

;    self.dataContainer->add,self.ech->clone(),position=n_old


;    if obj_valid(self.ech) gt 1 then obj_destroy,self.ech
;    self.ech = (self.dataContainer->get(position=n_new))->clone()
;    self->setDataParameters,self.ech,n=n_new

;    print,'step3'
;    help,/heap,/brief



    ;THERE SEEMS TO BE A PROBLEM WITH THE CD CONTROLS
    ;THAT TAKES THE FILE INDEX OUT OF RANGE AND CAUSES
    ;A CRASH HERE.
    ;
    ;PROTECT AGAINST THIS FOR NOW BY VERIFYING THAT THE GIVEN INDEX IS
    ;WITHIN THE TOTAL COUNT.

    count = self.dataContainer->count()
    if n_new le count-1 then begin
        ;120804
        ;WHAT HAPPENS HERE IF THE SELECTED N_NEW IS SAME
        ;AS OLD QCHOICEINDEX???   WHY IS setDataParameters CALLED
        ;INSTEAD OF resetDataParameters???
        self->setDataParameters, $
                (self.dataContainer->get(position=n_new)),n=n_new
    endif else begin
        void = dialog_message('ATTEMPT TO ACCESS INVALID DATA OBJECT.')
        self->setDataParameters,(self.dataContainer->get(position=$
                        count-1)),n=count-1
    endelse

    ;self->updateMaskmaker
;    print,'step4'
;    help,/heap,/brief

    self.plotzoomswitch = 0

end;swapDataObject
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::resetDataParameters,factor,nobin=nobin;timeaverage=timecheckboxval,DEEPMASKING=DEEPMASKINGcheckboxval,filename = fn
;
;NAME:
;        ooDisplayEcho::resetDataParameters
;
;PURPOSE:
;               Bin the data object and update various parameters
;               for the display object.
;PARAMETERS:
;               factor      THE NEW BIN FACTOR
;KEYWORDS:
;               none
;

    detDim=32   ;MAKE THIS DEPEND ON DETECTOR LATER
                ;WILL HAVE TO CHOOSE DETECTOR FIRST,
                ;SO PERHAPS displayEcho WILL HAVE TO CALL
                ;READ ECHO THEN DISPLAY TEMPORARY GUI
                ;TO GET INITIAL PARAMETERS FROM USER
                ;SUCH AS DETECTOR CENTER AND DETECTOR CHOICE

    if n_elements(nobin) eq 0 then nobin = 0

    if ((detDim mod factor) eq 0) then begin


        ;NEED TO ALTER THE NEXT FEW LINES TO TAKE
        ;ADVANTAGE OF THE FACT THAT EACH ECHO
        ;OBJECT KEEPS TRACK OF ITS OWN ORIGINAL
        ;SIZE AND INFORMATION (AS THEY SHOULD!!!)
        ref = (self.dataContainer->get(position=self.QChoiceIndex))

;        print,'Before bin:',ref->getproperty(tag='point_to_down_z')

        if nobin eq 0 then begin    ;DON'T REBIN IF A BINNING OCCURRED JUST BEFORE COMING HERE.
;            (self.dataContainer->get(position=self.QChoiceIndex))->bin,$
;                                                            factor=factor


            self->handleBinning,factor=factor,index=self.QChoiceIndex

        endif

;        print,'After bin:',ref->getproperty(tag='point_to_down_z')

        self.detxDim = ref->getProperty(tag='x_dim')
        self.detyDim = ref->getProperty(tag='y_dim')

        ;RESET INDICES TO PREVENT HITTING OUTSIDE DATA MATRIX
        ;self.xindex = self.detxDim/2 & self.yindex = self.detyDim/2
        self->updateIndices,x=self.detXDim/2,y=self.detYDim/2

        ;;
        ;USE emask FOR DISPLAY
        if ptr_valid(self.mye) gt 0 then ptr_free,self.mye
;        self.mye = ptr_new(*(self.ech->getProperty(tag='emask')))
        self.mye = ptr_new(*( ref->getProperty(tag='emask')))
        if ptr_valid(self.ie) gt 0 then ptr_free,self.ie
        self.ie = ptr_new((*(self.mye))[*,0,self.ftChoiceIndex])
        im = reform(*self.ie,self.detxDim,self.detyDim)
                                        ;REFORM 3-D ARRAY INTO
                                        ;2-D ARRAY BASED ON DETECTOR
                                        ;DIMENSIONS

        if ptr_valid(self.im) gt 0 then ptr_free,self.im
        self.im = ptr_new(double(im))
        if ptr_valid(self.phase) gt 0 then ptr_free,self.phase
;        self.phase = ptr_new(self.ech->getProperty(tag='phase'))
;        self.no_of_phases = self.ech->getProperty(tag='no_of_phases')
;        self.no_of_fourier_times = self.ech->getProperty(tag='no_of_fourier_times')

        self.phase = ptr_new(ref->getProperty(tag='phase'))
        self.no_of_phases = ref->getProperty(tag='no_of_phases')
        self.no_of_fourier_times = ref->getProperty(tag='no_of_fourier_times')


;        widget_control,self.atwbcx, set_value = strtrim(string(self.beamCenxOrig/factor),2)
;        widget_control,self.atwbcy, set_value = strtrim(string(self.beamCenyOrig/factor),2)

        ;print,'SETTING self.atwbcx & y'
        widget_control,self.atwbcx, set_value = strtrim(string(self.beamCenxOrig),2)
        widget_control,self.atwbcy, set_value = strtrim(string(self.beamCenyOrig),2)



    endif else begin
        widget_control,self.atw1,get_value=atwarr
        if n_elements(atwarr) ne 5 then begin
            widget_control,self.atw1,set_value=['1','2','4','8','16']
        endif
        ;widget_control,self.atw1,set_value='Enter a power of 2 le 16!'
        void = dialog_message('Enter a power of 2 le 16!')
    endelse

end;resetDataParameters


pro ooDisplayEcho::atlbEvents,event
;
;NAME:
;        ooDisplayEcho::atlbEvents
;
;PURPOSE:
;           Handle events from the top level base of the display object.
;           This is mainly intended to handle resize events.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none

;           INTERCEPT TLB RESIZE EVENTS AND RETAIN FIXED TLB SIZE.
;102804
;            widget_control,event.top,get_uvalue=uval
    ename = tag_names(event,/structure_name)

    ;if ename ne 'WIDGET_KBRD_FOCUS' then $
;        print,'ooDisplayEcho::atlbEvents,eventname = ', ename

    if ename eq 'WIDGET_BASE' then begin



        case event.id of
        self.atlb:begin
            self->resizeWidgets,event


            widget_control,event.top,$
                                xsize=self.atlbxsize,$
                                ysize=self.atlbysize



        end;self.atlb
        self.IQTDisplayBase:begin

            ;THESE EVENTS SHOULD NEVER ARRIVE HERE.
            ;print,self.IQTDisplayBase
            ;print,event.id
            widget_control,event.top,$
                                xsize=event.x,$;self.atlbxsize,$
                                ysize=event.y ;self.atlbysize
            self.IQTDisplayObj->resize,event,xsize=event.x,ysize=event.y
        end
        else:begin
            print,'ooDisplayEcho::atlbEvents event type=',tag_names(event,/structure_name)
        end
        endcase

    endif;WIDGET_BASE

;021505
;COMMENT OUT THE NEXT CODE FOR NOW.
;
;DOES THIS METHOD AFFECT ANYTHING BUT oodisplayecho<-atlb  AND cwo_displayiqt?
;        widget_control,event.top,$
;                            xsize=self.atlbxsize,$
;                            ysize=self.atlbysize

;WHY DOES IT WORK ON PC BUT NOT ON MAC FOR cwo_displayiqt???

;            widget_control,event.top,xsize=800,ysize=600


    ;NEED TO HANDLE KEYBOARD EVENTS HERE SO ALL ARROW EVENTS AFFECT
    ;THE POSITION ON THE IMAGE.

            self->draw



end;atlbEvents
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::doNothing,event
;
;NAME:
;        ooDisplayEcho::doNothing
;
;PURPOSE:
;               A "do nothing"  event handler.
;PARAMETERS:
;               event   The event structure.
;KEYWORDS:
;               none

end;doNothing
pro doNothing,event
;
;NAME:
;        doNothing
;
;PURPOSE:
;           A "do nothing" method outside of the class.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none

end;doNothing
pro ooDisplayEcho_event,event
;
;NAME:
;        ooDisplayEcho_event
;
;PURPOSE:
;           Catch all events produced by the ooDisplayEcho object
;           and dispatch them to proper event handlers.
;           This is also a gate-keeper in that it catches and
;           blocks many events when the program has no data objects.
;PARAMETERS:
;           event   The event structure which will allow access to the
;                   uvalue and the object/method to call.
;KEYWORDS:
;           none


    ;THIS IS THE MAIN EVENT HANDLER FOR THE OBJECT WIDGET.
    ;WHILE THIS IS NOT A CLASS METHOD, THE FOLLOWING
    ;CODE ALLOWS ME TO CONCISELY USE CLASS METHODS TO
    ;HANDLE EVENTS FOR INDIVIDUAL WIDGETS IN THE OBJECT WIDGET.

    ;SEE ROB'S BOOK "APPLICATION DEVELOPMENT IN IDL II", p.35


catch, catchError
if (catchError ne 0) then begin
    ;;print, 'Error handled!'
    eTitle = 'NSE Reduction: Error encountered'
    eMsg = 'An error or unusual condition was encountered at ooDisplayEcho_event!'
    eMsg = [eMsg,'Please, report the following to the DAVE team:']
    eMsg = [eMsg,!error_state.msg]
    void = dialog_message(/error,eMsg,title=eTitle,dialog_parent=event.top)
    catch, /cancel
    return
endif

    widget_control,event.id,get_uvalue=cmd
    help,cmd,output=out


;    print,'ooDisplayEcho_event event ='
;    print,tag_names(event,/structure_name)
;    print,tag_names(event)
;    print,event
    if stregex(out,'UNDEFINED',/boolean) then begin
        doNothing,event
    endif else begin
        eventname = tag_names(event,/structure_name)

        if eventname eq 'CW_PROGRESS_EVENT' then begin
            ;print,tag_names(event)
            ;print,event
        endif

;        if stregex(eventname,'WIDGET_BASE',/boolean) then begin

;print,'out=',out
;print,obj_valid(cmd)
        if stregex(out,'OODISPLAYECHO',/fold_case,/boolean) then begin
;           INTERCEPT TLB RESIZE EVENTS AND RETAIN FIXED TLB SIZE.
;102804
            ;print,out
            ;print,eventname
            case event.id of
            cmd->getProperty(/dw2auxbase):cmd->resizeAuxWindow,event
            cmd->getProperty(/imageerrorbase):cmd->resizeImageErrorBase,event
            cmd->getProperty(/atlb):cmd->atlbEvents,event
            else:
            endcase


        endif else begin
;            if eventname eq 'CWO_REMOVETLIST_EVENT' then begin
;                widget_control,event.id,get_uvalue=cmd
;                call_method,cmd.method,cmd.object,event
;
;            endif else begin

;                print,'oodisplayecho_event out = ',out
;                print,'oodisplayecho_event eventname = ',eventname
                container = obj_new()
                (cmd.object)->getContainer,container
                count = container->count()

                ;(cmd.object)->setproperty,state_saved = 0

                if count gt 0 then begin
                    if cmd.id eq 'FILEQUIT' then begin

                        ;THIS IS REDUNDANT BECAUSE OF THE SAME CALL IN ooDisplayEchoCleanup
                        ;030905
                        ;(cmd.object)->lastChanceToSaveSession
                        print,'QUITTING'

                    endif
                    call_method,cmd.method,cmd.object,event;cmd.id
                endif else begin
                    ;IF NO DATA OBJECTS, FIGURE OUT WHAT TO DO WHEN
                    ;AN EVENT SHOULD BE HANDLED.
                    case cmd.id of
                    'FILEOPEN':begin
                                call_method,cmd.method,cmd.object,event
                        end
;102605
                    'FILEOPENMAGNETIC':begin
                                call_method,cmd.method,cmd.object,event
                        end
                    'FILEQUIT':begin
                                ;NO SAVE PROMPT SINCE NO DATA IN THIS CASE.
                                call_method,cmd.method,cmd.object,event
                        end
                    'RESTORESESSION':begin
                                call_method,cmd.method,cmd.object,event
                        end
                    'RESTOREOBJECT':begin
                                call_method,cmd.method,cmd.object,event
                        end
                    'AUTOGRAPHNSE':begin
                                call_method,cmd.method,cmd.object,event
                        end
                    'NSEDIFFRACTIONVIEWER':begin
                                call_method,cmd.method,cmd.object,event
                        end
                    'FILEPARAMETERSIMPORT':begin
                                call_method,cmd.method,cmd.object,event
                        end
                    'NSEHELP':begin
                                call_method,cmd.method,cmd.object,event
                        end
                    'MERGEMULTIPLEIQT':begin
                                call_method,cmd.method,cmd.object,event
                        end
                    else:begin
                            doNothing,event
                            ;msg = dialog_message('NO DATA AVAILABLE. OPEN A FILE OR QUIT.')
                        end
                    endcase;cmd.id
                endelse;OBJECT
;            endelse;CWO_REMOVETLIST_EVENT
        endelse;count gt 0
    endelse;stregex(out,'UNDEFINED',/boolean)

end;ooDisplayEcho_event
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;CLASS INITIALIZATION METHODS
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::setDataParameters,ech,n=n
;
;NAME:
;        ooDisplayEcho::setDataParameters
;
;PURPOSE:
;               This method sets data parameters for the ooDisplayEcho data object
;               during object initialization.
;
;               CALLED BY ooDisplayEcho::swapDataObjects
;PARAMETERS:
;               ech     Confusing.  This seems to be only used once below, and
;                       It is inconsistently used.
;                       Perhaps this method is never used.
;                       Add a message dialog below to see if it comes up during
;                       normal use.
;
;                       Used by swapDataObject, reDefineWidgets, CDButtonHandler
;
;KEYWORDS:
;               n       The data object position in the data container.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;THIS SECTION OF init DEALS WITH THE ooEcho DATA OBJECT SPECIFICALLY.
;PERHAPS THIS CAN BE REDONE AS A PROCEDURE SO THAT IF I DEFINE
;A REBIN METHOD WITHIN displayEcho IT CAN CALL THAT TO CALL
;THE bin METHOD OF THE ooEcho OBJECT AND SET THE NEW PARAMETERS
;BOTH IN THE ooEcho OBJECT AND IN self.
;
;
;ALSO, THIS METHOD PROBABLY SHOULD HANDLE SWITCH
;FROM ONE Q VALUE TO ANOTHER.
;
;
;TO DO THIS, AN ECHO OBJECT CAN BE SIMPLY PASSED TO THIS
;PROCEDURE.  FOR EXAMPLE, IF I HAVE AN ARRAY OF ECHO
;OBJECTS, I CAN SIMPLE PASS THE CURRENT ELEMENT (BASED
;ON THE Q-SELECTION) TO THIS
;
;   (SEE resetDataParameters above)
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;    help,ech
;    help,ech[2]


    ;THE DIALOG ON THE NEXT LINE IS DISPLAYED FREQUENTLY IN RUNNING
    ;ooDisplayEcho, SO THIS METHOD IS USED.
    ;dum = dialog_message("ooDisplayEcho::setDataParameters     I don't think this is used.  LRK 01/25/05")


;print,'ooDisplayEcho::setDataParameters 102705'

    if (n_elements(n) eq 1) then begin
        if (self.dataContainer->count() lt n) then begin
            print,'NOT ENOUGH ELEMENTS IN THE DATA CONTAINER'
            n = 0
        endif else begin
            n = n
        endelse

    endif else begin
        n = 0
    endelse

;    if (obj_valid(self.ech) ne 0) then obj_destroy,self.ech
;    self.ech = (self.dataContainer->get(position = n))->clone()

    ;SET CURRENT DATA OBJECT TO THE nTH OBJECT
    if obj_valid(self.ech) gt 1 then obj_destroy,self.ech
;    self.ech = ech->clone()
    if obj_valid(self.echorig) gt 1 then obj_destroy,self.echorig
;    self.echorig = ech->clone()

    if ptr_valid(self.detChoices) gt 0 then ptr_free,self.detChoices
    self.detChoices = ptr_new(['32x32','64x64','128x64','128x128'])

    if ptr_valid(self.displayChoices) gt 0 then ptr_free,self.displayChoices
    self.displayChoices = ptr_new([ 'Sum(I(phase))',$
                                    'fit average',$
                                    'fit amplitude',$
                                    'fit phase',$
                                    'fit width',$
                                    'fit omega',$
                                    'fit offset'])

    ;070104
    ;CHANGE NEXT STATEMENT TO PRESERVE PREVIOUSLY CHOSE
    ;PLOTTING STATE
    if self.plotIndex eq 0 or self.plotIndex eq 5 then begin
        self.plotIndex = 5
    endif

    self.plotupdown = 1
    self.detChoiceIndex = 0
    self.ftChoiceIndex = 0
    self.QChoiceIndex = n

    ;WHEN SWITCHING TO MULTIPLE DATA OBJECTS THE DATA OBJECT
    ;REFERENCES ARE DYING SOMEWHERE. -- FIND THIS
    if ptr_valid(self.ftChoices) gt 0 then ptr_free,self.ftChoices
    self.ftChoices = ptr_new(indgen(ech->getProperty(tag='no_of_fourier_times')))

    ;print,file_basename(ech->getproperty(tag='filename'))

    detDim=32   ;MAKE THIS DEPEND ON DETECTOR LATER
                ;WILL HAVE TO CHOOSE DETECTOR FIRST,
                ;SO PERHAPS displayEcho WILL HAVE TO CALL
                ;READ ECHO THEN DISPLAY TEMPORARY GUI
                ;TO GET INITIAL PARAMETERS FROM USER
                ;SUCH AS DETECTOR CENTER AND DETECTOR CHOICE

;    self.detxDim = self.ech->getProperty(tag='x_dim')
;    self.detyDim = self.ech->getProperty(tag='y_dim')

    ref = (self.dataContainer->get(position=self.QChoiceIndex))


;help,ref

    ;print,file_basename(ref->getproperty(tag='filename'))
    if obj_isa(ref,'ooEchoMagnetic') gt 0 then begin
        case ref->getproperty(tag='magnetic') of
        0:begin
            if widget_info(self.magneticcheckbox,/valid_id) gt 0 then begin
                widget_control,self.magneticcheckbox,set_value=[0],sensitive=0
;120205
;                widget_control,self.magneticcheckbox,set_value=0,sensitive=0

                widget_control,self.atwxyzupdownscale,sensitive=0
;                widget_control,self.atwpoint_to_up_x,sensitive=0
;                widget_control,self.atwpoint_to_up_y,sensitive=0
;                widget_control,self.atwpoint_to_up_z,sensitive=0
;                widget_control,self.atwpoint_to_down_x,sensitive=0
;                widget_control,self.atwpoint_to_down_y,sensitive=0
;                widget_control,self.atwpoint_to_down_z,sensitive=0
                widget_control,self.atwpolarization,sensitive=0
                widget_control,self.atwflippingratio,sensitive=0

                if widget_info(self.atweff_bpw,/valid_id) gt 0 then $
                    widget_control,self.atweff_bpw,sensitive=0
                if widget_info(self.atweff_bpw_x,/valid_id) gt 0 then $
                    widget_control,self.atweff_bpw_x,sensitive=0
                if widget_info(self.atweff_bpw_y,/valid_id) gt 0 then $
                    widget_control,self.atweff_bpw_y,sensitive=0
                if widget_info(self.atweff_bpw_z,/valid_id) gt 0 then $
                    widget_control,self.atweff_bpw_z,sensitive=0

                magimageid = widget_info(self.atlb,find_by_uname='MAGNETICIMAGEOPTIONS_MENU')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_0_MENU')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_1_MENU')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_2_MENU')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_3_MENU')
                widget_control,magimageid,sensitive=0

                magimageid = widget_info(self.atlb,find_by_uname='MAGNETICIMAGEOPTIONS_CONTEXT')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_0_CONTEXT')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_1_CONTEXT')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_2_CONTEXT')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_3_CONTEXT')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETICPLOT_CONTEXT')
                widget_control,magimageid,sensitive=0
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETICPLOT_MENU')
                widget_control,magimageid,sensitive=0

            endif
        end;0
        1:begin
            if widget_info(self.magneticcheckbox,/valid_id) gt 0 then begin
                widget_control,self.magneticcheckbox,set_value=[1],sensitive=0
;120205
                ;widget_control,self.magneticcheckbox,set_value=1,sensitive=0

;                widget_control,self.atwpoint_to_up_x,sensitive=0,set_value=ref->getproperty(tag='point_to_up_x')
;                widget_control,self.atwpoint_to_up_y,sensitive=0,set_value=ref->getproperty(tag='point_to_up_y')
;                widget_control,self.atwpoint_to_up_z,sensitive=0,set_value=ref->getproperty(tag='point_to_up_z')
;                widget_control,self.atwpoint_to_down_x,sensitive=0,set_value=ref->getproperty(tag='point_to_down_x')
;                widget_control,self.atwpoint_to_down_y,sensitive=0,set_value=ref->getproperty(tag='point_to_down_y')
;                widget_control,self.atwpoint_to_down_z,sensitive=0,set_value=ref->getproperty(tag='point_to_down_z')

                widget_control,self.atwxyzupdownscale,sensitive=1,$
                                set_value=ref->getproperty(tag='xyzupdownscale')
                widget_control,self.atwpolarization,sensitive=1,set_value=ref->getproperty(tag='p')
                widget_control,self.atwflippingratio,sensitive=1,set_value=ref->getproperty(tag='f')

                if widget_info(self.atweff_bpw,/valid_id) gt 0 then $
                    widget_control,self.atweff_bpw,sensitive=1,set_value=ref->getproperty(tag='eff_bpw')
                if widget_info(self.atweff_bpw_x,/valid_id) gt 0 then $
                    widget_control,self.atweff_bpw_x,sensitive=1,set_value=ref->getproperty(tag='eff_bpw_x')
                if widget_info(self.atweff_bpw_y,/valid_id) gt 0 then $
                    widget_control,self.atweff_bpw_y,sensitive=1,set_value=ref->getproperty(tag='eff_bpw_y')
                if widget_info(self.atweff_bpw_z,/valid_id) gt 0 then $
                    widget_control,self.atweff_bpw_z,sensitive=1,set_value=ref->getproperty(tag='eff_bpw_z')




                magimageid = widget_info(self.atlb,find_by_uname='MAGNETICIMAGEOPTIONS_MENU')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_0_MENU')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_1_MENU')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_2_MENU')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_3_MENU')
                widget_control,magimageid,sensitive=1

                magimageid = widget_info(self.atlb,find_by_uname='MAGNETICIMAGEOPTIONS_CONTEXT')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_0_CONTEXT')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_1_CONTEXT')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_2_CONTEXT')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETIC_CASE_3_CONTEXT')
                widget_control,magimageid,sensitive=1

                magimageid = widget_info(self.atlb,find_by_uname='MAGNETICPLOT_CONTEXT')
                widget_control,magimageid,sensitive=1
                magimageid = widget_info(self.atlb,find_by_uname='MAGNETICPLOT_MENU')
                widget_control,magimageid,sensitive=1

            endif
        end;1
        else:
        endcase
    endif;obj_isa(ref,'ooEchoMagnetic')


    self.detxDim = ref->getProperty(tag='x_dim');$
    self.detyDim = ref->getProperty(tag='y_dim');$

    if self.xindex ge self.detxDim then self.xindex = self.detxDim/2
    if self.yindex ge self.detyDim then self.yindex = self.detyDim/2

    self.nDataObj = self.dataContainer->count()

    ;;
    ;USE emask FOR DISPLAY
    ;;;
    if (ptr_valid(self.mye) gt 0) then ptr_free,self.mye
    myemask = *(ref->getproperty(tag='emask'))

    self.mye = ptr_new(myemask);$

    if (ptr_valid(self.ie) gt 0) then ptr_free,self.ie
    self.ie = ptr_new((*(self.mye))[*,0,self.ftChoiceIndex])
    im = reform(*self.ie,self.detxDim,self.detyDim)
                                        ;REFORM 3-D ARRAY INTO
                                        ;2-D ARRAY BASED ON DETECTOR
                                        ;DIMENSIONS


    self.filename = ref->getproperty(tag='filename');((self.dataContainer->get(position=self.QChoiceIndex))->getProperty(tag='filename'))
    self.comment = ref->getproperty(tag='comment');((self.dataContainer->get(position=self.QChoiceIndex))->getProperty(tag='comment'))






    if ptr_valid(self.im) gt 0 then ptr_free,self.im
    self.im = ptr_new(double(im))

    if ptr_valid(self.phase) gt 0 then ptr_free,self.phase
    self.phase = ptr_new((*((ref)->getProperty(tag='phase'))))
    self.no_of_phases = ((ref)->getProperty(tag='no_of_phases'))
    self.no_of_fourier_times = ((ref)->getProperty(tag='no_of_fourier_times'))
    self.startparms = (*((ref)->getProperty(tag='fitparms')))[0:5,$
                      (self.detydim/2)*self.detxdim+self.detxdim/2,0]

    self.lambda  = ref->getProperty(tag='lambda')
    self.dlambda = ref->getProperty(tag='dlambda')



    ;I THINK WE WILL NEED TO GET BEAM CENTER FROM USER
    ;FOR NOW JUST SET INITIAL VALUES
;    self.beamCenxOrig = $
;        (ref)->getProperty(tag='x_cen')
;    self.beamCenyOrig = $
;        (ref)->getProperty(tag='y_cen')

    ;021005
    ;
    ;I THINK THE LINES ABOVE WERE A MISTAKE BASED ON CURRENT IMPLEMENTATION AND I AM
    ;REPLACING THEM WITH THE LINES BELOW.
    self.beamCenxOrig = ref->getProperty(tag='x_cen_orig')
    self.beamCenyOrig = ref->getProperty(tag='y_cen_orig')
end;setDataParameters

pro ooDisplayEcho::setSelectDialog
;
;NAME:
;        ooDisplayEcho::setSelectDialog
;
;PURPOSE:
;           Intended to be used to set up a dialog for adding objects to an existing set.
;           The set feature was not fully or correctly implemented as of today (01/25/05).
;PARAMETERS:
;           none
;KEYWORDS:
;           none

    ;;
    ;THIS DIALOG WILL SELECT WHICH SET TO PUT THE
    ;CALLING DATA OBJECT INTO.
    ;;;

    if (self.setContainer)->count() gt 0 then begin

        ;WILL NEED TO SET THIS TO USE ONLY SELECT Q-VALUES LATER
        names = sindgen(self.setContainer->count())
        for i=0,self.setContainer->count()-1 do begin
            names[i] = (self.setContainer->get(position=i))->getProperty(/name)
        endfor;i
        setIndices = indgen(self.setContainer->count())

        names = [names,'NO SET']


        self.setSelectBase = widget_base(group_leader = self.atlb,$
                                            xsize=200,ysize=400,$
                                            /modal,/grid_layout,$
                                            title='SELECT SET FOR ASSIGNMENT',$
                                            /base_align_right)

        subBase = widget_base(self.setSelectBase,/column)
        self.setSelectList = widget_droplist(subBase,$
                                            value=names,$
                                            ysize=25,xsize = 190,$
                                            title = 'Set Choices',$
                                            uvalue = {object:self,$
                                                      method:'listEvents',$
                                                      id:'SETSELECTLIST',$
                                                      setlist:setIndices})
        okbutton = widget_button(subbase,value='OK',$
                                    xsize=190,ysize=50,$
                                    uvalue = {object:self,$
                                              method:'listEvents',$
                                              id:'SETSELECTOKBUTTON',$
                                              setlist:setIndices})

        cancelButton = widget_button(subBase,value = 'Cancel',$
                                             xsize=190,ysize=50,$
                                             uvalue = {object:self,$
                                                       method:'listEvents',$
                                                       id:'SETSELECTCANCELBUTTON',$
                                                       setlist:setIndices})


        widget_control,self.setSelectBase,/realize

        ;CREATE DUMMY EVENT STRUCTURE FOR EVENT HANDLING
        dumEvent = { WIDGET_DROPLIST,$
                         ID:self.setSelectBase,$
                         TOP:self.setSelectBase,$
                         HANDLER:0L, INDEX:0L }

        ;STICK EVENT AND OTHER INFORMATION INTO BASE UVALUE
        widget_control,self.setSelectBase,set_uvalue=$
                                            {object:self,$
                                             method:'listEvents',$
                                             id:'SSACANCELBUTTON',$
                                             setlist:setIndices,$
                                             event:dumEvent}

        xmanager,"ooDisplayEcho",self.setSelectBase,/no_block,$
                    cleanup='setSelectBaseCleanup'

    endif else begin
        void = widget_message('No Suitable Sets Available.')
    endelse


end;setSelectDialog
pro setSelectBaseCleanup,base
;
;NAME:
;        setSelectBaseCleanup
;
;PURPOSE:
;           Clean up the data in a set selection dialog.
;           I expect this method is not currently used/implemented (01/25/05).
;
;PARAMETERS:
;           base    id of base which is being destroyed.
;KEYWORDS:
;           none

    ;CALLED WHEN [X] EVENT OCCURS.
    ;print,'selectSetDialog Cleanup'
    widget_control,base,get_uvalue=ssa
    call_method,ssa.method,ssa.object,ssa.event
end;setSelectBaseCleanup
pro ooDisplayEcho::removeSetDialog
;
;NAME:
;        ooDisplayEcho::removeSetDialog
;
;PURPOSE:
;           Produce dialog for removal of a set of data objects.
;           The "set" features are not currently used/implemented (01/25/05).
;PARAMETERS:
;           none
;KEYWORDS:
;           none

    ;;
    ;THIS DIALOG WILL SELECT WHICH SET TO REMOVE
    ;
    ;
    ;IF CLONES ARE PUT INTO SETS THEN THERE IS NO
    ;REASON TO HAVE THIS METHOD.  SIMPLY DESTROY THE CLONE!!!
    ;;;

    if (self.setContainer)->count() gt 0 then begin

        ;WILL NEED TO SET THIS TO USE ONLY SELECT Q-VALUES LATER
        names = sindgen(self.setContainer->count())
        for i=0,self.setContainer->count()-1 do begin
            names[i] = (self.setContainer->get(position=i))->getProperty(/name)
        endfor;i
        setIndices = indgen(self.setContainer->count())


        self.removeSetBase = widget_base(group_leader = self.atlb,$
                                            xsize=200,ysize=400,$
                                            /modal,/grid_layout,$
                                            title='SELECT SET FOR REMOVAL',$
                                            /base_align_right)

        subBase = widget_base(self.removeSetBase,/column)
        self.removeSetList = widget_droplist(subBase,$
                                            value=names,$
                                            ysize=25,xsize = 190,$
                                            title = 'Set Choices',$
                                            uvalue = {object:self,$
                                                      method:'listEvents',$
                                                      id:'SETREMOVELIST',$
                                                      setlist:setIndices})
        okbutton = widget_button(subbase,value='OK',$
                                    xsize=190,ysize=50,$
                                    uvalue = {object:self,$
                                              method:'listEvents',$
                                              id:'SETREMOVEOKBUTTON',$
                                              setlist:setIndices})

        cancelButton = widget_button(subBase,value = 'Cancel',$
                                             xsize=190,ysize=50,$
                                             uvalue = {object:self,$
                                                       method:'listEvents',$
                                                       id:'SETREMOVECANCELBUTTON',$
                                                       setlist:setIndices})


        widget_control,self.removeSetBase,/realize

        ;CREATE DUMMY EVENT STRUCTURE FOR EVENT HANDLING
        dumEvent = { WIDGET_DROPLIST,$
                         ID:self.setSelectBase,$
                         TOP:self.setSelectBase,$
                         HANDLER:0L, INDEX:0L }

        ;STICK EVENT AND OTHER INFORMATION INTO BASE UVALUE
        widget_control,self.setSelectBase,set_uvalue=$
                                            {object:self,$
                                             method:'listEvents',$
                                             id:'SSACANCELBUTTON',$
                                             setlist:setIndices,$
                                             event:dumEvent}

        xmanager,"ooDisplayEcho",self.setSelectBase,/no_block,$
                    cleanup='setSelectBaseCleanup'

    endif else begin
        void = widget_message('No Suitable Sets Available.')
    endelse


end;removeSetDialog
pro removeSetBaseCleanup,base
;
;NAME:
;        removeSetBaseCleanup
;
;PURPOSE:
;           Clean up a remove set dialog.
;           Not currently used/implemented (01/25/05)
;PARAMETERS:
;           base    Widget id of the base for cleanup.
;KEYWORDS:
;           none

    ;CALLED WHEN [X] EVENT OCCURS.
    print,'removeSetDialog Cleanup'
    widget_control,base,get_uvalue=ssa
    call_method,ssa.method,ssa.object,ssa.event
end;removeSetBaseCleanup
pro ooDisplayEcho::setNameEvents,event
;
;NAME:
;        ooDisplayEcho::setNameEvents
;
;PURPOSE:
;           Apply a name to a "set" of data objects.
;PARAMETERS:
;           event   The event structure being handled.
;KEYWORDS:
;           none

    ;HANDLE EVENT FOR THE setNameDialog
    widget_control,event.id,get_uvalue=obj
    print,"Set Name Event Occurred."
    ;print,obj.id
    ;print,obj.index
    case obj.id of
    'SETNAMEFIELD':begin
                ;print,'THIS EVENT OCCURRED!!!'
                        ;SET NEW NAME OF A SET
                        widget_control,self.setNameField,$
                                        get_value=newName,$
                                        get_uvalue=uval
                ;print,newName
                ;print,uval.index
                        index = uval.index
                        if index lt (self.setContainer)->count() then $
                         begin
                            theSetRef = $
                                (self.setContainer)->get(position=index)
                            theSetRef->setProperty,name=newName
                            self->redefineTree
                        endif

                    end
    'SETNAMEOKBUTTON':begin
                        ;SET NEW NAME OF A SET
                        widget_control,self.setNameField,$
                                        get_value=newName,$
                                        get_uvalue=uval
                        ;widget_control,self.setNameField,get_uvalue=uval
                        index = uval.index

                        if index lt (self.setContainer)->count() then begin
                            theSetRef = $
                                (self.setContainer)->get(position=index)
                            theSetRef->setProperty,name=newName
                        endif
                        widget_control,self.setNameBase,/destroy
                        self->redefineTree
                    end;SETNAMEOKBUTTON
    'SETNAMECANCELBUTTON':begin
                        widget_control,self.setNameBase,/destroy
                    end;SETNAMECANCELBUTTON
    else:begin
            widget_control,self.tw1,set_value=obj.id+': unsure of widget choice.'
        end
    endcase
end;setNameEvents


pro ooDisplayEcho::setNameDialog,index
;
;NAME:
;        ooDisplayEcho::setNameDialog
;
;PURPOSE:
;           A dialog for setting the name of a "set" of data objects.
;PARAMETERS:
;           index   Index of the "set" object in the setContainer.
;KEYWORDS:
;           none

    ;;
    ;THIS DIALOG WILL ALLOW THE USER TO CHANGE THE
    ;NAME OF A SELECTED SET TO SOMETHING MEANINGFUL.
    ;;;


    ;DO I GET INDEX HERE OR IN CONTEXT EVENT HANDLER????

    if (self.setContainer)->count() gt index then begin

        setRef = self.setContainer->get(position=index)

        nameOrig = setRef->getProperty(/name)

        self.setNameBase = widget_base(group_leader = self.atlb,$
                                            xsize=350,ysize=200,$
                                            /modal,/grid_layout,$
                                            title='CHANGE NAME OF SET',$
                                            /base_align_right)

        subBase = widget_base(self.setNameBase,/column)
        self.setNameField = cw_field(subBase,$
                                        /return_events,$
                                        value=nameOrig,$
                                        xsize = 40,$
                                        ysize = 1,$
                                        title = 'Set name = ',$
                                        uvalue = {object:self,$
                                                  method:'setNameEvents',$
                                                  id:'SETNAMEFIELD',$
                                                  index:index})

        okbutton = widget_button(subbase,value='OK',$
                                    xsize=20,ysize=40,$
                                    uvalue = {object:self,$
                                              method:'setNameEvents',$
                                              id:'SETNAMEOKBUTTON',$
                                              index:index})

        cancelButton = widget_button(subBase,$
                                        value = 'Cancel',$
                                        xsize=20,ysize=40,$
                                        uvalue = {object:self,$
                                                  method:'setNameEvents',$
                                                  id:'SETNAMECANCELBUTTON',$
                                                  index:index})


        widget_control,self.setNameBase,/realize

        ;CREATE DUMMY EVENT STRUCTURE FOR EVENT HANDLING
        dumEvent = { WIDGET_NAME,$
                         ID:self.setNameBase,$
                         TOP:self.setNameBase,$
                         HANDLER:0L }

        ;STICK EVENT AND OTHER INFORMATION INTO BASE UVALUE
        widget_control,self.setNameBase,set_uvalue=$
                                            {object:self,$
                                             method:'setNameEvents',$
                                             id:'SETNAMECANCELBUTTON',$
                                             index:index,$
                                             event:dumEvent}

        xmanager,"ooDisplayEcho",self.setNameBase,/no_block,$
                    cleanup='setNameBaseCleanup'

    endif else begin
        void = widget_message('Selcted Set Not Available.')
    endelse


end;setNameDialog
pro setNameBaseCleanup,base
;
;NAME:
;        setNameBaseCleanup
;
;PURPOSE:
;           Cleanup routine for the dialog for naming a "set" of data objects.
;PARAMETERS:
;           base    The widget id of the base to clean up.
;KEYWORDS:
;           none

    ;CALLED WHEN [X] EVENT OCCURS.
    print,'setNameDialog Cleanup'
    widget_control,base,get_uvalue=sn
    call_method,sn.method,sn.object,sn.event
end;setNameBaseCleanup


pro ooDisplayEcho::CalculateIQTDialog
;
;NAME:
;        ooDisplayEcho::CalculateIQTDialog
;
;PURPOSE:
;           Provide a dialog for beginning the calculation of I(Q,t).
;           This allows the user to select the sample, cell and resolution data
;           objects to use in the calculation.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    ;;
    ;THIS DIALOG WILL BE USED TO SELECT THE DATA
    ;OBJECTS USED TO CALCULATE I(Q,t) FOR THE
    ;SELECTED SET OF OBJECTS.
    ;
    ;THIS DIALOG IS CALLED BY THE menuEvents METHOD
    ;
    ;THE RESULTING DATA WILL BE STORED IN THE
    ;S VARIABLE IN THE 'data' TYPE OBJECT
    ;;;

    ;;
    ;
    ;NEED AN EVENT HANDLER TO SET THE SELECTED PHASES
    ;
    ;;;

    theBkgList = ['']
    theDatList = ['']
    theResList = ['']
    bkgIndexList = [0]
    datIndexList = [0]
    resIndexList = [0]
    refo = (self.dataContainer->get(position=self.QChoiceIndex))
    for i = 0,self.dataContainer->count()-1 do begin
        ;GET LIST OF DATA FILES WITH THE CORRECT SIZE
        refi = self.dataContainer->get(position=i)
        if (refo->matches(refi) $
                    ) $;and (i ne self.QChoiceIndex))$
                        then begin
                            type = refi->getProperty(tag='type')
                                    ;self.QChoiceIndex))->getProperty(tag='type')

                            ;print,type
                            case type of
                            0:begin;untyped
                                if (i eq self.QChoiceIndex) then begin
                                    theBkgList[0] = file_basename(refi->getProperty(tag='filename'))
                                    bkgIndexList[0] = i
                                    theBkgList = ['',theBkgList]
                                    bkgIndexList = [0,bkgIndexList]
                                    theDatList[0] = file_basename(refi->getProperty(tag='filename'))
                                    datIndexList[0] = i
                                    theDatList = ['',theDatList]
                                    datIndexList = [0,datIndexList]
                                    theResList[0] = file_basename(refi->getProperty(tag='filename'))
                                    resIndexList[0] = i
                                    theResList = ['',theResList]
                                    resIndexList = [0,resIndexList]
                                endif else begin
                                    theBkgList = $
                                        [theBkgList,file_basename(refi->getProperty(tag='filename'))]
                                    bkgIndexList = [bkgIndexList,i]
                                    theDatList = $
                                        [theDatList,file_basename(refi->getProperty(tag='filename'))]
                                    datIndexList = [datIndexList,i]
                                    theResList = $
                                        [theResList,file_basename(refi->getProperty(tag='filename'))]
                                    resIndexList = [resIndexList,i]
                                endelse
                            end;0
                            1:begin;resolution
                                if i eq self.QChoiceIndex then begin
                                    theResList[0] = file_basename(refi->getProperty(tag='filename'))
                                    resIndexList[0] = i
                                    theResList = ['',theResList]
                                    resIndexList = [0,resIndexList]
                                endif else begin
                                    theResList = $
                                        [theResList,file_basename(refi->getProperty(tag='filename'))]
                                    resIndexList = [resIndexList,i]
                                endelse
                            end;1
                            2:begin;data
                                if i eq self.QChoiceIndex then begin
                                    theDatList[0] = file_basename(refi->getProperty(tag='filename'))
                                    datIndexList[0] = i
                                    theDatList = ['',theDatList]
                                    datIndexList = [0,datIndexList]
                                endif else begin
                                    theDatList = $
                                        [theDatList,file_basename(refi->getProperty(tag='filename'))]
                                    datIndexList = [datIndexList,i]
                                endelse
                            end;2
                            3:begin;background
                                if i eq self.QChoiceIndex then begin
                                    theBkgList[0] = file_basename(refi->getProperty(tag='filename'))
                                    bkgIndexList[0] = i
                                    theBkgList = ['',theBkgList]
                                    bkgIndexList = [0,bkgIndexList]
                                endif else begin
                                    theBkgList = $
                                        [theBkgList,file_basename(refi->getProperty(tag='filename'))]
                                    bkgIndexList = [bkgIndexList,i]
                                endelse
                            end;3
                            endcase;type
        endif;match
    endfor;i

    ;ADD OPTIONS FOR NO FILE IN EACH OF THESE
    theResList = [theResList,'None']
    resIndexList = [resIndexList,9999]
    theBkgList = [theBkgList,'None']
    bkgIndexList = [bkgIndexList,9999]
    ;theDatList = [theDatList,'None']


    ;CREATE DIALOG
    if n_elements(theDatList) gt 1 then begin
        theDatList = theDatList[1:*]
        datIndexList = datIndexList[1:*]

        if !version.os eq 'Win32' then begin
            basexsize = 230
            baseysize = 320
        endif else begin
            basexsize=330
            baseysize=400
        endelse

        ;021406
        ;ELIMINATE THE SIZE RESTRICTION HERE.
        self.IQTImportBase = widget_base(group_leader = self.atlb,/row,$
                                            $;xsize=basexsize,ysize=baseysize,$
                                            /modal,$;/grid_layout,$
                                            title='SELECT DATA FOR I(Q,t) Calculation',$
                                            /base_align_right)

        subBase = widget_base(self.IQTImportBase,/column)
        self.datImportList = widget_droplist(subBase,$
                                            value=theDatList,$
                                            ysize=25,xsize = 220,$
                                            title = 'Sample Choices',$;'Data Set Choices',$
                                            uvalue = {object:self,$
                                                       method:'IQTDialogEvents',$
                                                       $;method:'listEvents',$
                                                      id:'DATIMPORTLIST',$
                                                      list:datIndexList})

        ;IF THESE HAVE ZERO ELEMENTS THEN
        ;self.resImportList WILL BE A MESSAGE, NOT A LIST
        if n_elements(theResList) gt 0 then begin
            theResList = theResList[1:*]
            ResIndexList = resIndexList[1:*]
            self.resImportList = widget_droplist(subBase,$
                                                value=theResList,$
                                                ysize=25,xsize = 220,$
                                                title = 'Resolution Choices',$
                                                uvalue = {object:self,$
                                                           method:'IQTDialogEvents',$
                                                           $;method:'listEvents',$
                                                          id:'RESIMPORTLIST',$
                                                          list:resIndexList})
        endif else begin
            self.resImportList = widget_label(subBase,$
                                value='No Resolution Set Available!')
        endelse
        ;IF THESE HAVE ZERO ELEMENTS THEN
        ;self.bkgImportList WILL BE A MESSAGE, NOT A LIST
        if n_elements(theBkgList) gt 0 then begin
            theBkgList = theBkgList[1:*]
            bkgIndexList = bkgIndexList[1:*]


            self.bkgImportList = widget_droplist(subBase,$
                                                value=theBkgList,$
                                                ysize=25,xsize = 220,$
                                                title = 'Cell Choices',$;'Background Choices',$
                                                uvalue = {object:self,$
                                                           method:'IQTDialogEvents',$
                                                           $;method:'listEvents',$
                                                          id:'BKGIMPORTLIST',$
                                                          list:bkgIndexList})
        endif else begin
            self.bkgImportList = widget_label(subBase,$
                                value='No Background Set Available!')
        endelse


        narcs = (self.dataContainer->get(position=datIndexList[0]))->getProperty(tag='narcs')
        sampletransmission = (self.dataContainer->get(position=datIndexList[0]))->getProperty(tag='transmission')
        samplevolumefraction = (self.dataContainer->get(position=datIndexList[0]))->getProperty(tag='volfrac')
        if bkgIndexList[0] ne 9999 then begin
            celltransmission = (self.dataContainer->get(position=bkgIndexList[0]))->getProperty(tag='transmission')
        endif else begin
            celltransmission = 1.0
        endelse

        arcsfield = cw_field(subbase,value=narcs,xsize=8,/return_events,$
                                            /integer,title='Number of Q Arcs',/row,$
                                             uname='IQTARCSFIELD',$
                                             uvalue = {object:self,$
                                                       method:'IQTDialogEvents',$
                                                       id:'IQTARCSFIELD',$
                                                       list:datIndexList})



        samtrans = cw_field(subbase,value=sampletransmission,xsize=8,$
                                            /floating,title='Sample Trans',/row,$
                                             uname='SAMPLETRANSMISSION',$
                                             uvalue = {object:self,$
                                                       method:'IQTDialogEvents',$
                                                       id:'SAMPLETRANSMISSION',$
                                                       list:datIndexList})

        samvolfrac = cw_field(subbase,value=samplevolumefraction,xsize=8,$
                                            /floating,title='Sample Volfrac',/row,$
                                             uname='SAMPLEVOLUMEFRACTION',$
                                             uvalue = {object:self,$
                                                       method:'IQTDialogEvents',$
                                                       id:'SAMPLEVOLUMEFRACTION',$
                                                       list:datIndexList})

        celltrans = cw_field(subbase,value=celltransmission,xsize=8,$
                                            /floating,title='Cell Trans',/row,$
                                             uname='CELLTRANSMISSION',$
                                             uvalue = {object:self,$
                                                       method:'IQTDialogEvents',$
                                                       id:'CELLTRANSMISSION',$
                                                       list:bkgIndexList})

        ECHOAVERAGENORMLABEL     = widget_label(subbase,$
                                   value='Next option for G. Ehlers. NOTE: EB Calculated using usual normalization.')
        ECHOAVERAGENORMALIZATION = cw_bgroup(subbase,$
                                        'Use Echo Average for Normalization',$
                                        /row, /nonexclusive,$
                                        set_value=0,$
                                        uname='ECHOAVERAGENORMALIZATION',$
                                        uvalue={object:self,$
                                                method:'IQTDialogEvents',$
                                                id:'ECHOAVERAGENORMALIZATION'})



        if (n_elements(theResList) gt 0) and $
           (n_elements(theBkgList) gt 0) then begin
            okButton = widget_button(subBase,value = 'OK',$
                                         xsize=230,ysize=50,$
                                         uvalue = {object:self,$
                                                   method:'IQTDialogEvents',$
                                                   $;method:'listEvents',$
                                                   id:'IQTOKBUTTON',$
                                                   bkglist:bkgIndexList,$
                                                   datlist:datIndexList,$
                                                   reslist:resIndexList})
        endif else begin
            okButton = widget_button(subBase,value = 'NOT OK',$
                                         xsize=230,ysize=50,$
                                         uvalue = {object:self,$
                                                   method:'IQTDialogEvents',$
                                                   $;method:'listEvents',$
                                                   id:'IQTCANCELBUTTON',$
                                                   list:bkgIndexList})
        endelse

        cancelButton = widget_button(subBase,value = 'Cancel',$
                                             xsize=230,ysize=50,$
                                             uvalue = {object:self,$
                                                       method:'IQTDialogEvents',$
                                                       $;method:'listEvents',$
                                                       id:'IQTCANCELBUTTON',$
                                                       list:bkgIndexList})

        widget_control,self.IQTImportBase,/realize

        ;CREATE DUMMY EVENT STRUCTURE FOR EVENT HANDLING
        dumEvent = { WIDGET_DROPLIST,$
                         ID:self.IQTImportBase,$
                         TOP:self.IQTImportBase,$
                         HANDLER:0L, INDEX:0L }

        ;STICK EVENT AND OTHER INFORMATION INTO BASE UVALUE
        widget_control,self.IQTImportBase,set_uvalue=$
                                            {object:self,$
                                             method:'listEvents',$
                                             id:'IQTCANCELBUTTON',$
                                             bkglist:bkgIndexList,$
                                             datlist:datIndexList,$
                                             reslist:resIndexList,$
                                             event:dumEvent}

        xmanager,"ooDisplayEcho",self.IQTImportBase,/no_block,$
                    cleanup='CalculateIQTBaseCleanup'

    endif else begin
        void = widget_message('No Suitable Data Objects.')
    endelse

    ;041504

end;CalculateIQTDialog
pro ooDisplayEcho::IQTDialogEvents,event
;
;NAME:
;        IQTDialogEvents
;
;PURPOSE:
;           Handle events for the CalculateIQT dialog.
;           This will take over events handled in listEvents.
;
;PARAMETERS:
;           event    The event to handle
;KEYWORDS:
;           none
;


    widget_control,event.id,get_uvalue=obj

    case obj.id of
        'IQTOKBUTTON':begin

                        ;GET OBJECTS FROM WIDGET SELECTIONS AND
                        ;CALCULATE I(Q,t)
                        widget_control,self.IQTImportBase,$
                                            get_uvalue=iqt

                        bkgIndexList = iqt.bkgList
                        datIndexList = iqt.datList
                        resIndexList = iqt.resList

                        bkgIndex=widget_info(self.bkgImportList,$
                                            /droplist_select)
                        datIndex=widget_info(self.datImportList,$
                                            /droplist_select)
                        resIndex=widget_info(self.resImportList,$
                                            /droplist_select)



                        ;GET NUMERICAL VALUES FROM FIELDS
                        arcsf = widget_info(self.IQTImportBase,find_by_uname='IQTARCSFIELD')
                        samtrans = widget_info(self.IQTImportBase,find_by_uname='SAMPLETRANSMISSION')
                        samvolfrac = widget_info(self.IQTImportBase,find_by_uname='SAMPLEVOLUMEFRACTION')
                        celtrans = widget_info(self.IQTImportBase,find_by_uname='CELLTRANSMISSION')
                        echoAverageOption = widget_info(self.IQTImportBase,find_by_uname='ECHOAVERAGENORMALIZATION')
                        widget_control,arcsf,get_value=narcs
                        widget_control,samtrans,get_value=sampletrans
                        widget_control,samvolfrac,get_value=samplevolfrac
                        widget_control,celtrans,get_value=celltrans
                        if echoAverageOption ne 0L then begin
                            widget_control,echoAverageOption,get_value=echoAverageOpt
                        endif else begin
                            echoAverageOpt = 0
                        endelse

                        ;print,sampletrans

;072005
;                        if narcs le 1 then begin
;                            void = dialog_message('narcs too small, setting to 2.')
;                            narcs = 2
;                        endif
                        if narcs lt 1 then begin
                            void = dialog_message('narcs too small, setting to 1.')
                            narcs = 1
                        endif
                        if narcs gt 16 then begin
                            void = dialog_message('narcs too big, setting to 16.')
                            narcs = 16
                        endif



                        ;GET OBJECTS AND APPLY THE TRANSMISSION AND VOLFRAC VALUES
                        nbkg=bkgIndexList[bkgIndex]
                        ndat=datIndexList[datIndex]
                        nres=resIndexList[resIndex]

                        ;042105
                        ;
                        self.QChoiceIndex = ndat
                        m=self.QChoiceIndex


                        ;print,nbkg, ndat,nres
                        objDat = ((self.dataContainer)->get(position=m))
                        objDat->setProperty,'transmission',sampletrans
                        objDat->setProperty,'volfrac',samplevolfrac
                        objDat->setProperty,'narcs',narcs
                        ;objDat = ((self.dataContainer)->get(position=ndat))
                        if nbkg ne 9999 then begin
                            objBkg = ((self.dataContainer)->get(position=nbkg))
                            objBkg->setProperty,'transmission',celltrans
                            objBkg->setProperty,'narcs',narcs
                        endif else begin
                            ;objBkg = 0L
                        endelse
                        if nres ne 9999 then begin
                            objRes = ((self.dataContainer)->get(position=nres))
                            objRes->setProperty,'narcs',narcs
                        endif else begin
                        endelse
                        ;print,'Test1'
                        ;print,'Test2'


;                            sampletransmission = ref->getProperty(tag='transmission')
;                            samplevolumefraction = ref->getProperty(tag='volfrac')

                        widget_control,self.IQTImportBase,/destroy

;                        objDat->CalculateIQT,bkgObj = objBkg,$
;                                             resObj = objRes,$
;                                             datObj = objDat
                        objDat->CalculateIQT2,bkgObj = objBkg,$
                                              resObj = objRes,$
                                              datObj = objDat,$
                                              echoAverageOpt = echoAverageOpt

;
;032405
;MOVE THIS STATEMENT TO JUST BEFORE THE CALCULATION
;                        widget_control,self.IQTImportBase,/destroy

                    ;080604
                    ;WHY DOES THIS NEED ALL OF THE OBJECTS????
                    ;DOES IT PUT THE RESULT INTO ALL OF THE
                    ;INVOLVED OBJECTS? --- YES, THAT IS THE REASON.
                        objDat->sumQArcs,bkgObj = objBkg,$
                                         resObj = objRes,$
                                         datObj = objDat

                        iqtresult = *(objdat->getProperty(tag='IQT'))
                        siqtresult = *(objdat->getProperty(tag='sIQT'))


                        ;NOW SHOULD SIMPLY DISPLAY THE
                        ;I(Q,t) CURVE WITH A CALL LIKE
                        ;

                        ;displayIQT,

;110906 CHANGE THE NEXT LINE BELOW
;                        self->displayIQT,self.QChoiceIndex

                        self->displayIQT_NEW,self.QChoiceIndex

                    end;IQTOKBUTTON
        'IQTCANCELBUTTON':begin
                        widget_control,self.IQTImportBase,/destroy
                    end
        'IQTIMPORTLIST':begin
                        ;THIS METHOD SHOULD BE UNNECESSARY
                        widget_control,event.id,get_value=list
                        end
        'DATIMPORTLIST':begin
                            widget_control,self.IQTImportBase,$
                                                get_uvalue=iqt

                            trans = widget_info(self.IQTImportBase,find_by_uname='SAMPLETRANSMISSION')
                            volfrac = widget_info(self.IQTImportBase,find_by_uname='SAMPLEVOLUMEFRACTION')
                            datIndex=widget_info(self.datImportList,$
                                                        /droplist_select)


                            datIndexList = iqt.datList

                            datIndex=widget_info(self.datImportList,$
                                                /droplist_select)
                            ndat=datIndexList[datIndex]
                            ref = (self.dataContainer->get(position=ndat))
                            sampletransmission = ref->getProperty(tag='transmission')
                            samplevolumefraction = ref->getProperty(tag='volfrac')

                            widget_control,trans,set_value=sampletransmission
                            widget_control,volfrac,set_value=samplevolumefraction
                        end
        'RESIMPORTLIST':begin
;                            print,'RESIMPORTLIST'
;                            print,tag_names(event)
;                            print,event
                        end
        'BKGIMPORTLIST':begin
                            widget_control,self.IQTImportBase,$
                                                get_uvalue=iqt

                            trans = widget_info(self.IQTImportBase,find_by_uname='CELLTRANSMISSION')
                            nkgIndex=widget_info(self.bkgImportList,$
                                                        /droplist_select)


                            bkgIndexList = iqt.bkgList

                            bkgIndex=widget_info(self.bkgImportList,$
                                                /droplist_select)
                            nbkg=bkgIndexList[bkgIndex]
                            if nbkg ne 9999 then begin
                                ref = (self.dataContainer->get(position=nbkg))
                                celltransmission = ref->getProperty(tag='transmission')
                                widget_control,trans,set_value=celltransmission
                            endif else begin
                                widget_control,trans,set_value=double('Nan')
                            endelse
                        end

        'IQTARCSFIELD':begin
                            widget_control,self.IQTImportBase,$
                                                get_uvalue=iqt

                            arcsf = widget_info(self.IQTImportBase,find_by_uname='IQTARCSFIELD')
                            widget_control,arcsf,get_value=narcs
                            if narcs lt 1 then narcs = 1
                            if narcs gt 16 then narcs = 16
                            widget_control,arcsf,set_value=narcs
                        end
        'ECHOAVERAGENORMALIZATION':begin
        end
        else:begin
                print,'UNKNOWN EVENT AT IQTImportEvents'
            end
    endcase


end;IQTImportEvents



pro CalculateIQTBaseCleanup,base
;
;NAME:
;        CalculateIQTBaseCleanup
;
;PURPOSE:
;           Clean up the dialog for selecting data objects for I(Q,t) calculation.
;PARAMETERS:
;           base    The id of the base to clean up.
;KEYWORDS:
;           none

    ;CALLED WHEN [X] EVENT OCCURS.
    ;print,'IQT Cleanup'

    ;THIS IS ALSO CALLED WHEN A cwo_displayiqt OBJECT IS DESTROYED.

    widget_control,base,get_uvalue=iqt
    call_method,iqt.method,iqt.object,iqt.event
end;CalculateIQTBaseCleanup

pro ooDisplayEcho::mergeEvents,event
;
;NAME:
;        ooDisplayEcho::mergeEvents
;
;PURPOSE:
;           Handle the events from the mergeSet dialog.
;           Here set refers to a single data object.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           none


    widget_control,event.id,get_uvalue=uval

    case uval.id of
        'MERGEOKBUTTON':begin
                        ;GET OBJECT FROM WIDGET SELECTION AND
                        ;MERGE WITH CURRENTLY SELECTED DATA
                        ;OBJECT IF IT IS VALID.
                        ;
                        ;IF THE RESULTING OBJECT IS VALID THEN
                        ;ADD IT TO THE DATA CONTAINER AND
                        ;REFRESH THE DATA TREE.

                        widget_control,self.mergeBase,$
                                            get_uvalue=merge
                        objIndexList = merge.objList

                        objIndex=widget_info(self.mergeList,$
                                            /droplist_select)

                        m=self.QChoiceIndex
                        nobj=objIndexList[objIndex]
                        ;print,objIndexList
                        ;print,'NOBJ = ',nobj

                        ;print,nbkg, ndat,nres
                        current = ((self.dataContainer)->get(position= $
                                                                m))

                        if nobj ne 9999 then begin
                            ;print,'NOT 9999'
                            newObj = $
                                current->merge(((self.dataContainer)->get(position=nobj)))
                        endif else begin
                            ;print,'9999'
                            newObj = 0L
                        endelse

                        if obj_valid(newObj) gt 0 then begin
                            ;print,'VALID'
                            (self.dataContainer)->add,newObj
                            self->redefineTree
                        endif else begin
                            print,'NEW OBJECT NOT CREATED!'
                        endelse


                        widget_control,self.mergeBase,/destroy
                    end
        'MERGECANCELBUTTON':begin
                        widget_control,self.mergeBase,/destroy
                    end
        'OBJMERGELIST':begin
                        ;THIS METHOD SHOULD BE UNNECESSARY
                        widget_control,event.id,get_value=list
                    end
    endcase
end;mergeEvents
pro ooDisplayEcho::MergeDialog
;
;NAME:
;        ooDisplayEcho::MergeDialog
;
;PURPOSE:
;           Produce a dialog for selecting data objects to merge.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    ;;
    ;THIS DIALOG WILL BE USED TO SELECT THE DATA
    ;OBJECT TO MERGE WITH THE CURRENT DATA OBJECT
    ;
    ;THIS DIALOG IS CALLED BY THE contextMenuEvents METHOD
    ;
    ;;;

    theObjList = ['']
    objIndexList = [0]

    myType = (self.dataContainer->get(position=$
                self.QChoiceIndex))->getProperty(tag= $
                    'type')
    myQ = (self.dataContainer->get(position=$
                self.QChoiceIndex))->getProperty(tag= $
                    'q')

    myX_dim = (self.dataContainer->get(position=$
                self.QChoiceIndex))->getProperty(tag= $
                    'x_dim')
    myY_dim = (self.dataContainer->get(position=$
                self.QChoiceIndex))->getProperty(tag= $
                    'y_dim')

    myIndex = self.QChoiceIndex

    myname = file_basename((self.dataContainer->get(position=$
                self.QChoiceIndex))->getProperty(tag= $
                    'filename'))

    for i = 0,self.dataContainer->count()-1 do begin
        if i ne myIndex then begin
            ;GET LIST OF DATA WITH THE CORRECT TYPE
            objType = (self.dataContainer->get(position= $
                                        i))->getProperty(tag='type')
            objQ = (self.dataContainer->get(position= $
                                        i))->getProperty(tag='q')
            objX_dim = (self.dataContainer->get(position= $
                                        i))->getProperty(tag='x_dim')
            objY_dim = (self.dataContainer->get(position= $
                                        i))->getProperty(tag='y_dim')
            if (myType eq objType) or (objType eq 0) then begin
                if (myQ eq objQ) then begin
                    if (myX_dim eq objX_dim) and (myY_dim eq objY_dim) then begin
                        theObjList = [theObjList, $
                                        file_basename((self.dataContainer->get(position= $
                                                i))->getProperty(tag='filename'))]
                        objIndexList = [objIndexList,i]
                    endif;dimension check
                endif;Q check
            endif;type check
        endif;index check
    endfor;i

    ;ADD OPTIONS FOR NO FILE IN EACH OF THESE
    theObjList = [theObjList,'None']
    objIndexList = [objIndexList,9999]


    ;CREATE DIALOG
    if n_elements(theObjList) gt 1 then begin
        theObjList = theObjList[1:*]
        objIndexList = objIndexList[1:*]

        self.MergeBase = widget_base(group_leader = self.atlb,$
                                            xsize=200,ysize=400,$
                                            /modal,/grid_layout,$
                                            title='MERGE '+myname+' WITH:',$;title='SELECT DATA FOR MERGE',$
                                            /base_align_right)

        subBase = widget_base(self.MergeBase,/column)
        self.mergeList = widget_droplist(subBase,$
                                            value=theObjList,$
                                            ysize=25,xsize = 190,$
                                            title = 'Data Set Choices',$
                                            uvalue = {object:self,$
                                                      method:'mergeEvents',$
                                                      id:'OBJMERGELIST',$
                                                      list:objIndexList})

        ;IF THESE HAVE ZERO ELEMENTS THEN
        ;self.objImportList WILL BE A MESSAGE, NOT A LIST
        if (n_elements(theObjList) gt 0) then begin
            okButton = widget_button(subBase,value = 'OK',$
                                         xsize=190,ysize=50,$
                                         uvalue = {object:self,$
                                                   method:'mergeEvents',$
                                                   id:'MERGEOKBUTTON',$
                                                   objlist:objIndexList})
        endif else begin
            okButton = widget_button(subBase,value = 'NOT OK',$
                                         xsize=190,ysize=50,$
                                         uvalue = {object:self,$
                                                   method:'mergeEvents',$
                                                   id:'MERGECANCELBUTTON',$
                                                   list:objIndexList})
        endelse

        cancelButton = widget_button(subBase,value = 'Cancel',$
                                             xsize=190,ysize=50,$
                                             uvalue = {object:self,$
                                                       method:'mergeEvents',$
                                                       id:'MERGECANCELBUTTON',$
                                                       list:objIndexList})


        widget_control,self.MergeBase,/realize

        ;CREATE DUMMY EVENT STRUCTURE FOR EVENT HANDLING
        dumEvent = { WIDGET_DROPLIST,$
                         ID:self.mergeBase,$
                         TOP:self.mergeBase,$
                         HANDLER:0L, INDEX:0L }

        ;STICK EVENT AND OTHER INFORMATION INTO BASE UVALUE
        widget_control,self.MergeBase,set_uvalue=$
                                            {object:self,$
                                             method:'mergeEvents',$
                                             id:'MERGECANCELBUTTON',$
                                             objlist:objIndexList,$
                                             event:dumEvent}

        xmanager,"ooDisplayEcho",self.MergeBase,/no_block,$
                    cleanup='MergeBaseCleanup'

    endif else begin
        void = widget_message('No Suitable Data Objects.')
    endelse

    ;051904

end;MergeDialog
pro MergeBaseCleanup,base
;
;NAME:
;        MergeBaseCleanup
;
;PURPOSE:
;           Cleanup method for the merge dialog.
;PARAMETERS:
;           base    The id of the top level base of the merge dialog.
;KEYWORDS:
;           none

    print,'Merge Cleanup'
    widget_control,base,get_uvalue=merge
    call_method,merge.method,merge.object,merge.event
end;MergeBaseCleanup



pro ooDisplayEcho::definePhaseImportDialog
;
;NAME:
;        ooDisplayEcho::definePhaseImportDialog
;
;PURPOSE:
;           Create a dialog to select the data object to import phases from
;           for fitting.
;PARAMETERS:
;           none
;KEYWORDS:
;           none


    ;;
    ;
    ;NEED AN EVENT HANDLER TO SET THE SELECTED PHASES
    ;
    ;;;

    refo = self.dataContainer->get(position=self.QChoiceIndex)
    theList = ['']
    objIndexList = [0]
    for i = 0,self.dataContainer->count()-1 do begin
        refi = self.dataContainer->get(position=i)
        if (refo)->matches(refi) $
                    and (i ne self.QChoiceIndex) $
                        and (refi->getproperty(tag='type') ne 3) $ ;ONLY SELECT FROM NON-CELL DATA
                            then begin
;                            print,$
;                            (self.dataContainer->get(position=$
;                                i))->getProperty(tag='filename')

                            ;ADD SUCCESSFUL ITEMS TO THE LIST, BUT ADD RESOLUTION FILES TO BEGINNING.
                            if (refi->getproperty(tag='type') eq 1) and $
                                (n_elements(theList) gt 1) then begin
                                theList[0] =file_basename(refi->getProperty(tag='filename'))
                                objIndexList[0] = i
                                theList = $
                                    ['',theList]
                                objIndexList = [0,objIndexList]
                            endif else begin
                                theList = $
                                    [theList,file_basename(refi->getProperty(tag='filename'))]
                                objIndexList = [objIndexList,i]
                            endelse

        endif
    endfor
    if n_elements(theList) gt 1 then begin
        theList = theList[1:*]
        objIndexList = objIndexList[1:*]

        self.phaseImportBase = widget_base(group_leader = self.atlb,$
                                            $;xsize=156,ysize=140,$
                                            /modal,/col,$;/grid_layout,$
                                            title='SELECT PHASE SET')

        subBase = widget_base(self.phaseImportBase,/column)
        self.phaseImportList = widget_droplist(subBase,$
                                            value=theList,$
                                            ysize=25,xsize = 250,$
                                            uvalue = {object:self,$
                                                      method:'listEvents',$
                                                      id:'PHASEIMPORTLIST',$
                                                      list:objIndexList})

        fixvaryphaselist = widget_droplist(subBase,$
                                            title='phase',$
                                            value=['vary','fix','fit phase offset (constant phase)'],$
                                            ysize=25,xsize = 250,$
                                            uname = 'PHASEIMPORTFIXVARYPHASE',$
                                            uvalue = {object:self,$
                                                      method:'doNothing',$
                                                      id:'PHASEIMPORTFIXVARYPHASE',$
                                                      list:objIndexList})

;111405
;SET FIX/VARY BASED ON OBJ TYPE:
;0
;
refotype = refo->getproperty(tag='type')
;print,'refotype=',refotype
        widget_control,fixvaryphaselist, SET_DROPLIST_SELECT=0

        fixvaryperiodlist = widget_droplist(subBase,$
                                            title='period',$
                                            value=['vary','fix'],$
                                            ysize=25,xsize = 250,$
                                            uname = 'PHASEIMPORTFIXVARYPERIOD',$
                                            uvalue = {object:self,$
                                                      method:'doNothing',$
                                                      id:'PHASEIMPORTFIXVARYPERIOD',$
                                                      list:objIndexList})
        widget_control,fixvaryperiodlist, SET_DROPLIST_SELECT=1



        allowNegAmpCheckbox = cw_bgroup(subBase,$
                                        'Allow Small Opposite-Sign Amplitudes',$
                                        /nonexclusive,$
                                        /no_release,$
                                        uname = 'ALLOWNEGATIVEAMPLITUDECHECKBOX',$
                                        uvalue = {object:self,$
                                                  method:'doNothing',$
                                                  id:'ALLOWNEGATIVEAMPLITUDECHECKBOX',$
                                                  list:objIndexList})
        forceNegAmpCheckbox = cw_bgroup(subBase,$
                                        'Force Negative Amplitudes',$
                                        /nonexclusive,$
                                        /no_release,$
                                        uname = 'FORCENEGATIVEAMPLITUDECHECKBOX',$
                                        uvalue = {object:self,$
                                                  method:'doNothing',$
                                                  id:'FORCENEGATIVEAMPLITUDECHECKBOX',$
                                                  list:objIndexList})
        widget_control,allownegampcheckbox,set_value=1

        okButton = widget_button(subBase,value = 'OK',$
                                         xsize=150,ysize=50,$
                                         uvalue = {object:self,$
                                                   method:'listEvents',$
                                                   id:'OKBUTTON',$
                                                   list:objIndexList})
        cancelButton = widget_button(subBase,value = 'Cancel',$
                                             xsize=150,ysize=50,$
                                             uvalue = {object:self,$
                                                       method:'listEvents',$
                                                       id:'CANCELBUTTON',$
                                                       list:objIndexList})


        widget_control,self.phaseImportBase,/realize


        ;CREATE DUMMY EVENT STRUCTURE FOR EVENT HANDLING
        dumEvent = { WIDGET_DROPLIST,$
                         ID:self.phaseImportBase,$
                         TOP:self.phaseImportBase,$
                         HANDLER:0L, INDEX:0L }

        ;STICK EVENT AND OTHER INFORMATION INTO BASE UVALUE
        widget_control,self.phaseImportBase,set_uvalue=$
                                            {object:self,$
                                             method:'listEvents',$
                                             id:'CANCELBUTTON',$
                                             list:objIndexList,$
                                             event:dumEvent}


        xmanager,"ooDisplayEcho",self.phaseImportBase,/no_block,$
                    cleanup='phaseImportBaseCleanup'

    endif else begin

        void = widget_message('No Suitable Data Objects.')
    endelse

end;definePhaseImportDialog
pro PhaseImportBaseCleanup,base
;
;NAME:
;        PhaseImportBaseCleanup
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;CALLED WHEN [X] EVENT OCCURS.
    print,'pib Cleanup'
    widget_control,base,get_uvalue=pib
;    print,base,self.atlb
    call_method,pib.method,pib.object,pib.event

end;PhaseImportBaseCleanup

pro ooDisplayEcho::defineImageErrorBase
;
;NAME:
;        ooDisplayEcho::defineImageErrorBase
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;DEFINES THE BASE AND DRAW WIDGETS AND REALIZES IT

    ;NOW DEFINE DRAW WIDGETS FOR IMAGE ERROR DISPLAY
    self.imageerrorbase = widget_base(group_leader = self.atlb,$
                                        title='Image Error Bars',$
                                        tlb_size_events=1,$
                                        floating=1,$
                                        xsize=self.plotxsize,$
                                        ysize=self.plotysize,$
                                        uvalue=self)
;                                        uvalue={object:self,$
;                                                method:'ImageErrorBaseCleanup'})
    self.imageerrordw = widget_draw(self.imageerrorbase,$
                                    xsize=self.plotxsize,$
                                    ysize=self.plotysize)
    window,/free,/pixmap,xsize=(*self.geomPlot).xsize,$
                        ysize=(*self.geomPlot).ysize
    self.dwebpix = !d.window

    widget_control,self.imageerrorbase,/realize

    widget_control,self.imageerrordw,get_value=dummy
    self.dwebid = dummy
    self->realify,self.dwebpix,self.dwebid

    xmanager,"ooDisplayEcho",self.imageerrorbase,event_handler='oodisplayecho_event',$
                cleanup="ImageErrorBaseCleanup",/no_block


    self.errorImageChoice = 1

end;defineImageErrorBase
pro ooDisplayEcho::resizeImageErrorBase,event,xsize=xsize,ysize=ysize
;
;NAME:
;        ooDisplayEcho::resizeImageErrorBase
;
;PURPOSE:
;       Resize the image error bars display.
;
;PARAMETERS:
;       event   Event that caused resize
;KEYWORDS:
;       xsize
;       ysize

    ;print,'ooDisplayEcho::resizeImageErrorBase'

    if n_elements(xsize) eq 0 then myxsize = event.x
    if n_elements(ysize) eq 0 then myysize = event.y


    winxsize = myxsize-6
    winysize = myysize-6

    if widget_info(self.imageerrordw,/valid_id) gt 0 then begin
        widget_control,self.imageerrordw,xsize = winxsize, ysize = winysize
    endif

    if widget_info(self.imageerrorbase,/valid_id) gt 0 then begin
        widget_control,self.imageerrorbase,xsize=myxsize,ysize=myysize
    endif
    wdelete,self.dwebpix
    window,/free,/pixmap,xsize=winxsize,ysize=winysize
    self.dwebpix = !d.window

    if n_elements(xsize) eq 0 then $
        self->draw


end;resizeImageErrorBase
pro ooDisplayEcho::ImageErrorBaseCleanup;,event
;
;NAME:
;        ooDisplayEcho::ImageErrorBaseCleanup;
;
;PURPOSE:
;           TO DESTROY THE IMAGE ERROR BAR WIDGET AND TO UPDATE THE
;           self.errorImageChoice FLAG AND THE WIDGETS WHICH USE IT.
;
;PARAMETERS:
;
;KEYWORDS:
;


    ;DESTROY BASE
    widget_control,self.imageerrorbase,/destroy

    ;SET ERROR BAR FLAG TO OFF.
    self.errorImageChoice = 0

    ;SWITCH IMAGE OPTIONS MENUS
    id1 = widget_info(self.atlb,find_by_uname="IMAGEERRORBARSMENU")

    id2 = widget_info(self.dw1,find_by_uname="IMAGEERRORBARSCONTEXT")


    widget_control,id1,set_value='Display Image Error Bars'
    widget_control,id2,set_value='Display Image Error Bars'


end;ImageErrorBaseCleanup
pro ImageErrorBaseCleanup,base
;
;NAME:
;        ImageErrorBaseCleanup
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.



    ;011305
    ;
    ;THIS CRASHES WHEN THE PARENT APP IS DESTROYED FIRST.
    ;
    ;Group leader appears correct, and it's xmanager appears
    ;to assign the proper cleanup to it.

    ;CALLED WHEN [X] EVENT OCCURS.
    print,'ieb Cleanup'
    widget_control,base,get_uvalue=ieb
    if obj_valid(ieb) gt 0 then begin
        call_method,'ImageErrorBaseCleanup',ieb;ieb.method,ieb.object
    endif else begin
        widget_control,base,/destroy
    endelse

end;ImageErrorBaseCleanup

pro ooDisplayEcho::defineDrawWidgets
;
;NAME:
;        ooDisplayEcho::defineDrawWidgets
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;;
    ;DRAWING AND PLOTTING WIDGETS (self.tlb2)
    ;;;
    ;self.tlb2 = widget_base(self.atlb,/col)


;THIS SLIDER WILL ONLY BE DISPLAYED IF THE PHASE IMAGE IS SHOWN.

;    self.clickrefitslider = cw_fslider(self.tlb2,$
;                                        minimum=-800.0,$
;                                        maximum=800.0,$
;                                        scroll=45.0,$
;                                        value=0.0,$
;                                        title='alt-click starting phase',$
;                                        uvalue={object:self,$
;                                            method:'sliderEvents',$
;                                            id:'CLICKREFITSLIDER'})



    ;011005
    ;SET UP A BASE FOR THE DRAW WIDGET SO THAT I CAN GET CONTEXT EVENTS
    ;FOR MASK ADJUSTMENTS.
;    dw1Base = widget_base(self.tlb2,/context_events,xsize = self.plotxsize, ysize=self.plotysize)
;    contextBase = WIDGET_BASE(dw1Base, /CONTEXT_MENU)
;
;    ;SET UP THE NEXT TWO BUTTONS TO BE IDENTICAL TO THE 'Alter Mask' AND 'Apply Mask. . .' BUTTONS.
;    button1 = WIDGET_BUTTON(contextBase, VALUE='Alter Mask',$
;                                                uvalue={object:self,$
;                                                        method:'buttonEvents',$
;                                                        id:'MASKBUTTON'})
;    button2 = WIDGET_BUTTON(contextBase, VALUE='Apply Mask to All Fourier Times',$
;                                    uvalue={object:self,$
;                                            method:'buttonEvents',$
;                                            id:'MASKBUTTONAPPLY'})



    self.dw1 = widget_draw(self.tlb2,xsize=self.plotxsize,$
;    self.dw1 = widget_draw(dw1Base,xsize=self.plotxsize,$
                                     ysize=self.plotysize,$
                                     /button_events,$
                                    $;/motion_events,$
                                    keyboard_events=1,$
                                    tracking_events=1,$
                                    uname="DW1",$
                                    $;tooltip='arrow keys navigate, "m" masks, pgup/down changes t, rightclick refits for phase image',$
                                    uvalue={object:self,$
                                            method:'drawEvents',$
                                            id:'DW1'})


    maskContextBase = WIDGET_BASE(self.dw1, /CONTEXT_MENU,/col,$
                                        uname = 'MASKCONTEXTBASE',$
                                        uvalue={object:self,$
                                                method:'drawEvents',$
                                                id:'MASKCONTEXTBASE'})

    image_bttn0 = widget_button(maskContextBase,value='Image Options',/menu)
    ;SET UP THE NEXT BUTTONS TO BE IDENTICAL TO THE 'Alter Mask' AND 'Apply Mask. . .' BUTTONS.
    ;image_bttn1 = widget_button(maskContextBase, value='S(detx,dety)',$
    image_bttn1 = widget_button(image_bttn0, value='S(Q(x,y),t=0)',$
                                uname="SOF0",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SOF0',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn2 = widget_button(image_bttn0, value='Signal',$
                                uname="SIGNALIMAGE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SIGNALIMAGE',$
                                        parent:'IMAGEOPTIONS'})
    ;image_bttn2 = widget_button(maskContextBase, value='P0 - AVERAGE',$
    image_bttn2 = widget_button(image_bttn0, value='Av - AVERAGE',$;'P0 - AVERAGE',$
                                uname="FITCONSTANT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITCONSTANT',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn3 = widget_button(image_bttn0, value='A - AMPLITUDE',$;'P1 - AMPLITUDE',$
                                uname="FITAMPLITUDE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITAMPLITUDE',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn4 = widget_button(image_bttn0, value='PH - PHASE',$;'P2 - PHASE',$
                                uname="FITPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITPHASE',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn5 = widget_button(image_bttn0, value='W - ECHO GAUSSIAN WIDTH',$;'P3 - ECHO GAUSSIAN WIDTH',$
                                uname="FITWIDTH",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITWIDTH',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn6 = widget_button(image_bttn0, value='T - PERIOD',$;'P4 - PERIOD',$;OMEGA = 360/(ECHO PERIOD)',$
                                uname="FITOMEGA",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITOMEGA',$
                                        parent:'IMAGEOPTIONS'})
;    image_bttn6 = widget_button(image_bttn0, value='P5 - PHASE OFFSET',$
;                                uname="FITPHASEOFFSET",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FITPHASEOFFSET',$
;                                        parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn0, value='CHISQ',$
                                uname="FITCHISQ",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITCHISQ',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn6m = widget_button(image_bttn0, value='MAGNETIC IMAGE OPTIONS',$
                                 uname="MAGNETICIMAGEOPTIONS_CONTEXT",$
                                 /menu,sensitive=0,$
                                 uvalue={object:self,$
                                         method:'menuEvents',$
                                         id:'"MAGNETICIMAGEOPTIONS"',$
                                         parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn6m, value='Magnetic',$
                                uname='MAGNETIC_CASE_0_CONTEXT',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETIC_CASE_0',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn6m, value='Spin Incoherent',$
                                uname='MAGNETIC_CASE_1_CONTEXT',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETIC_CASE_1',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn6m, value='Coherent and Isotope Incoherent',$
                                uname='MAGNETIC_CASE_2_CONTEXT',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETIC_CASE_2',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn6m, value='Total',$
                                uname='MAGNETIC_CASE_3_CONTEXT',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETIC_CASE_3',$
                                        parent:'IMAGEOPTIONS'})




    image_bttn6 = widget_button(maskContextBase, value='DISPLAY IMAGE ERROR BARS',$
                                uname="IMAGEERRORBARSCONTEXT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'IMAGEERRORBARS',$
                                        parent:'IMAGEOPTIONS'})


;033005
;REMOVE NEXT BUTTON
;
;    button1 = WIDGET_BUTTON(maskContextBase, VALUE='Alter Mask',$
;                                                uvalue={object:self,$
;                                                        method:'buttonEvents',$
;                                                        id:'MASKBUTTON'})
    button2 = WIDGET_BUTTON(maskContextBase, VALUE='Apply Mask to All Fourier Times',$
                                            uvalue={object:self,$
                                                    method:'buttonEvents',$
                                                    id:'MASKBUTTONAPPLY'})

    button2 = WIDGET_BUTTON(maskContextBase, VALUE='Apply masking of this pixel at All Fourier Times',$
                                            uvalue={object:self,$
                                                    method:'buttonEvents',$
                                                    id:'MASKBUTTONPIXELAPPLY'})

    button2 = WIDGET_BUTTON(maskContextBase, VALUE='Apply Mask to SUBSEQUENT Fourier Times',$
                                            uvalue={object:self,$
                                                    method:'buttonEvents',$
                                                    id:'MASKBUTTONSUBSEQUENTAPPLY'})

    button2 = WIDGET_BUTTON(maskContextBase, VALUE='Apply masking of this pixel at SUBSEQUENT Fourier Times',$
                                            uvalue={object:self,$
                                                    method:'buttonEvents',$
                                                    id:'MASKBUTTONSUBSEQUENTPIXELAPPLY'})


    button2 = WIDGET_BUTTON(maskContextBase, VALUE='Save Mask to File',$
                                            uvalue={object:self,$
                                                    method:'textEvents',$
                                                    id:'SAVEMASKBUTTON'})



    self.tw1 = widget_text(self.tlb2,value="8,8",uvalue="TW1",uname="TW1")


    self->defineCDControls,base=self.tlb2


    self.dw2 = widget_draw(self.tlb2,xsize=self.plotxsize,$
                                     ysize=self.plotysize,$
                                     /button_events,$
                                     keyboard_event=1,$
                                    tracking_events=1,$
                                    /motion_events,$
                                    uname="DW2",$
                                    uvalue={object:self,$
                                            method:'drawEvents',$
                                            id:'DW2'})


    ;011005 SET UP PLOT OPTIONS FROM CONTEXT MENU.
    plotContextBase = WIDGET_BASE(self.dw2, /CONTEXT_MENU,/col,$
                                        uname = 'PLOTCONTEXTBASE',$
                                        uvalue={object:self,$
                                                method:'drawEvents',$
                                                id:'PLOTCONTEXTBASE'})

    plotcontextmenu = widget_button(plotContextBase, value='Plot Choices',/menu,$;value='Plot Options',/menu,$
                                        xsize=50,$
                                        uname="PLOTCONTEXTMENU",$
                                        uvalue={object:self,$
                                                method:'menuEvents',$
                                                id:'PLOTCONTEXTMENU',$
                                                parent:'PLOTOPTIONS'})

    plot_bttn1 = widget_button(plotContextMenu, value='I v. Phase',$
                                uname="IVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'IVPHASE',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(plotContextMenu, value='Fit Phase v. Fourier Time',$
                                uname="FITPHASEVTAU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITPHASEVTAU',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(plotContextMenu, value='Fit Amplitude v. Fourier Time',$
                                uname="FITAMPVTAU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITAMPVTAU',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(plotContextMenu, value='Signal v. Fourier Time',$
                                uname="SIGNALVTAU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SIGNALVTAU',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn3 = widget_button(plotContextMenu, value='B_x v. Phase',$
                                uname="BXVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'BXVPHASE',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn4 = widget_button(plotContextMenu, value='B_y v. Phase',$
                                uname="BYVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'BYVPHASE',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn5 = widget_button(plotContextMenu, value='B_z v. Phase',$
                                uname="BZVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'BZVPHASE',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn6 = widget_button(plotContextMenu, value='All v. Phase',$
                                uname="ALLVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'ALLVPHASE',$
                                        parent:'PLOTOPTIONS'})

;020606
;ADD THE FOLLOWING PLOT FOR MAGNETIC PARAMETERS
    self.magplotcontextsubmenu = widget_button(plotContextMenu, value='Magnetic Parameters',$
                                uname="MAGNETICPLOT_CONTEXT",$
                                /menu,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETICPLOTPARAMETERSMENU',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(self.magplotcontextsubmenu, value='Area Averaged',$
                                uname="MAGNETICPLOT_CONTEXT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETICPLOT',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(self.magplotcontextsubmenu, value='Pixel',$
                                uname="MAGNETICPLOT_CONTEXT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETICPLOTPIXEL',$
                                        parent:'PLOTOPTIONS'})

    plot_bttn2 = widget_button(plotContextMenu, value='Contour Echo',$
                                uname="CONTOURECHO",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'CONTOURECHO',$
                                        parent:'PLOTOPTIONS'})

    plot_bttn7 = widget_button(plotContextBase, value='Toggle DISPLAY OF f_on/f_off',$
                                uname="TOGGLEUPDOWN",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'TOGGLEUPDOWN',$
                                        parent:'PLOTOPTIONS'})

    plot_bttn8 = widget_button(plotContextBase, value='Toggle Auxiliary Plot',$
                                uname="TOGGLEAUXPLOT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'TOGGLEAUXPLOT',$
                                        parent:'PLOTOPTIONS'})


    plot_bttn8 = widget_button(plotContextBase, value='Write plot data to file',$
                                uname="WRITEPLOTDATA",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'WRITEPLOTDATA',$
                                        parent:'PLOTOPTIONS'})


    plot_bttn8 = widget_button(plotContextBase, value='Expand Range 20%',$
                                uname='EXPANDPLOTRANGES',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'EXPANDPLOTRANGES',$
                                        parent:'PLOTOPTIONS'})


    plot_bttn8 = widget_button(plotContextBase, value='Unzoom Plot',$
                                uname='UNZOOMPLOT',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'UNZOOMPLOT',$
                                        parent:'PLOTOPTIONS'})




    ;SET THIS FOR INITIAL SIZE AND REDO THIS
    ;IN A RESIZE EVENT HANDLER
    if ptr_valid(self.geomBase) gt 0 then ptr_free,self.geomBase
    self.geomBase = ptr_new(widget_info(self.atlb,/geometry))
    if ptr_valid(self.geomImage) gt 0 then ptr_free,self.geomImage
    self.geomImage = ptr_new(widget_info(self.dw1,/geometry))
    if ptr_valid(self.geomPlot) gt 0 then ptr_free,self.geomPlot
    self.geomPlot = ptr_new(widget_info(self.dw2,/geometry))


    ;CREATE PIXMAP WINDOW FOR DOUBLE BUFFERING OF IMAGE WINDOW
    window,/free,/pixmap,xsize=(*self.geomImage).xsize,$
                        ysize=(*self.geomImage).ysize
    self.dw1pix = !d.window

    ;CREATE PIXMAP WINDOW FOR DOUBLE BUFFERING OF PLOT WINDOW
    window,/free,/pixmap,xsize=(*self.geomPlot).xsize,$
                        ysize=(*self.geomPlot).ysize
    self.dw2pix = !d.window
    ;widget_control,self.dw1pix,get_value=self.dw1pixid


;    self.tw1 = widget_text(self.tlb2,value="8,8",uvalue="TW1",uname="TW1")
;



    ;021005
    ;MOVE THIS TO self->defineWidgets
    ;widget_control,self.atlb,/realize


    widget_control,self.dw1,get_value=dummy
    self.dw1id = dummy
    widget_control,self.dw2,get_value=dummy
    self.dw2id = dummy
    widget_control,self.tw1,get_value=dummy
    self.tw1id = dummy

    ;widget_control,self.atw1,get_value=dummy2
    ;NOW THAT THIS IS A COMBOBOX
    dummy2 = widget_info(self.atw1,/combobox_gettext)

    self.atw1id = dummy2
    widget_control,self.atwbcx,get_value=dummy3
    self.atwbcxid = dummy3
    widget_control,self.atwbcy,get_value=dummy4
    self.atwbcyid = dummy4
    widget_control,self.atwlambda,get_value=dummy5
    self.atwlambdaid = dummy5
    if widget_info(self.atwlambdadist,/valid_id) gt 0 then begin
        widget_control,self.atwlambdadist,get_value=dummy6
        self.atwlambddistaid = dummy6
    endif else begin
        self.atwlambddistaid = 0
    endelse

    ;DEFINE IMAGE AND PLOT AXIS STRUCTURES
    wset,self.dw1id
    if ptr_valid(self.w1xptr) gt 0 then ptr_free,self.w1xptr
    if ptr_valid(self.w1yptr) gt 0 then ptr_free,self.w1yptr
    self.w1xptr = ptr_new(!x)   ;SET THESE VALUES AT POINT OF EVENT TO
    self.w1yptr = ptr_new(!y)   ;PREVENT AXIS CONFUSION

    wset,self.dw2id
    if ptr_valid(self.w2xptr) gt 0 then ptr_free,self.w2xptr
    if ptr_valid(self.w2yptr) gt 0 then ptr_free,self.w2yptr
    self.w2xptr = ptr_new(!x)   ;SET THESE VALUES AT POINT OF EVENT TO
    self.w2yptr = ptr_new(!y)   ;PREVENT AXIS CONFUSION

;    ;NOW DEFINE DRAW WIDGETS FOR IMAGE ERROR DISPLAY
;    self.imageerrorbase = widget_base(group_leader = self.atlb,$
;                                        xsize=400,ysize=400)
;    self.imageerrordw = widget_draw(self.imageerrorbase,$
;                                    xsize=400,ysize=400)
;    window,/free,/pixmap,xsize=(*self.geomPlot).xsize,$
;                        ysize=(*self.geomPlot).ysize
;    self.dwebpix = !d.window
;    widget_control,self.imageerrordw,get_value=dummy
;    self.dwebid = dummy



end;defineDrawWidgets
pro ooDisplayEcho::defineMenus,bar
;
;NAME:
;        ooDisplayEcho::defineMenus
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    file_menu = widget_button(bar, value='File', /menu)
    openfile_bttn1 = widget_button(file_menu, value='Open .echo File(s)',$
                                uname="FILEOPEN",$
                                $;/menu,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FILEOPEN',$
                                        parent:'FILEOPTIONS'})

;110705
;THE OBJECT TYPE IS NOW DETERMINED AUTOMATICALLY, SO ELIMINATE THE
;NEXT TWO BUTTONS AND REINSTATE THE ABOVE TO Button AND NOT MENU STATUE.


;    file_bttn1 = widget_button(openfile_bttn1, value='Open .echo File(s)',$
;                                uname="FILEOPEN",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILEOPEN',$
;                                        parent:'FILEOPTIONS'})
;    file_bttn1 = widget_button(openfile_bttn1, value='Open magnetic .echo File(s)',$
;                                uname="FILEOPENMAGNETIC",$
;                                sensitive=1,$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILEOPENMAGNETIC',$
;                                        parent:'FILEOPTIONS'})





;    file_bttn1 = widget_button(file_menu, value='Save',$
;                                uname="FILESAVE",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILESAVE',$
;                                        parent:'FILEOPTIONS'})


    file_button1 = widget_button(file_menu,value='Save Session',$
                                uname="SAVESESSION",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SAVESESSION',$
                                        parent:'FILEOPTIONS'})

    file_button1 = widget_button(file_menu,value='Restore Session',$
                                uname="RESTORESESSION",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'RESTORESESSION',$
                                        parent:'FILEOPTIONS'})

    file_button1 = widget_button(file_menu,value='Save Object',$
                                uname="SAVEOBJECT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SAVEOBJECT',$
                                        parent:'FILEOPTIONS'})

    file_button1 = widget_button(file_menu,value='Restore Object',$
                                uname="RESTOREOBJECT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'RESTOREOBJECT',$
                                        parent:'FILEOPTIONS'})

;111704
;NOW THAT OBJECT AND SESSION SAVE/RESTORE ARE
;AVAILABLE, THE NEXT FOUR ITEMS ARE OBSOLETE.

;    file_button1 = widget_button(file_menu,value='Export Phases',$
;                                uname="FILEPHASEEXPORT",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILEPHASEEXPORT',$
;                                        parent:'FILEOPTIONS'})
;
;    file_button1 = widget_button(file_menu,value='Import Phases from File',$
;                                uname="FILEPHASEIMPORT",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILEPHASEIMPORT',$
;                                        parent:'FILEOPTIONS'})
;
;    file_button1 = widget_button(file_menu,value='Export FIT PARAMETERS',$
;                                uname="FILEFITPARMEXPORT",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILEFITPARMEXPORT',$
;                                        parent:'FILEOPTIONS'})
;
;    file_button1 = widget_button(file_menu,value='Import FIT PARAMETERS',$
;                                uname="FILEFITPARMIMPORT",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILEFITPARMIMPORT',$
;                                        parent:'FILEOPTIONS'})


;072605
;COMMENT OUT THE NEXT TWO WIDGETS SINCE THEY GENERALLY WOULD NOT BE USED.
;    file_button1 = widget_button(file_menu,value='Export I(Q,t) (ASCII)',$
;                                uname="FILEIQTEXPORT",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILEIQTEXPORT',$
;                                        parent:'FILEOPTIONS'})
;
;    file_button1 = widget_button(file_menu,value='Export I(Q,t) (DAVE)',$
;                                uname="FILEIQTDAVEEXPORT",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FILEIQTDAVEEXPORT',$
;                                        parent:'FILEOPTIONS'})




    file_button1 = widget_button(file_menu,value='Import Parameters File',$
                                uname="FILEPARAMETERSIMPORT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FILEPARAMETERSIMPORT',$
                                        parent:'FILEOPTIONS'})


    file_button1 = widget_button(file_menu,value='Export Parameters File',$
                                uname="FILEPARAMETERSEXPORT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FILEPARAMETERSEXPORT',$
                                        parent:'FILEOPTIONS'})



    file_bttn1 = widget_button(file_menu, value='Quit',$
                                uname="FILEQUIT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FILEQUIT',$
                                        parent:'FILEOPTIONS'})


    plotoptions_menu = widget_button(bar, value='Plot Options', /menu)
    plot_bttn1 = widget_button(plotoptions_menu, value='I v. Phase',$
                                uname="IVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'IVPHASE',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(plotoptions_menu, value='Fit Phase v. Fourier Time',$
                                uname="FITPHASEVTAU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITPHASEVTAU',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(plotoptions_menu, value='Fit Amplitude v. Fourier Time',$
                                uname="FITAMPVTAU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITAMPVTAU',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(plotoptions_menu, value='Signal v. Fourier Time',$
                                uname="SIGNALVTAU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SIGNALVTAU',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn3 = widget_button(plotoptions_menu, value='B_x v. Phase',$
                                uname="BXVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'BXVPHASE',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn4 = widget_button(plotoptions_menu, value='B_y v. Phase',$
                                uname="BYVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'BYVPHASE',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn5 = widget_button(plotoptions_menu, value='B_z v. Phase',$
                                uname="BZVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'BZVPHASE',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn6 = widget_button(plotoptions_menu, value='All v. Phase',$
                                uname="ALLVPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'ALLVPHASE',$
                                        parent:'PLOTOPTIONS'})


;;112805
;;ADD THE FOLLOWING PLOT FOR MAGNETIC PARAMETERS
;    plot_bttn2 = widget_button(plotoptions_menu, value='Magnetic Parameters',$
;                                uname="MAGNETICPLOT_MENU",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'MAGNETICPLOT',$
;                                        parent:'PLOTOPTIONS'})
;


;020606
;ADD THE FOLLOWING PLOT FOR MAGNETIC PARAMETERS
    self.magplotmenusubmenu = widget_button(plotoptions_Menu, value='Magnetic Parameters',$
                                uname="MAGNETICPLOT_CONTEXT",$
                                /menu,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETICPLOTPARAMETERSMENU',$
                                        parent:'PLOTOPTIONS'})


    plot_bttn2 = widget_button(self.magplotmenusubmenu, value='Area Averaged',$
                                uname="MAGNETICPLOT_MENU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETICPLOT',$
                                        parent:'PLOTOPTIONS'})
    plot_bttn2 = widget_button(self.magplotmenusubmenu, value='Pixel',$
                                uname="MAGNETICPLOT_MENU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETICPLOTPIXEL',$
                                        parent:'PLOTOPTIONS'})






;    plot_bttn2 = widget_button(plotoptions_menu, value='Contour Echo',$
;                                uname="CONTOURECHO",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'CONTOURECHO',$
;                                        parent:'PLOTOPTIONS'})


    plot_bttn7 = widget_button(plotoptions_menu, value='Toggle Up/Down Display',$
                                uname="TOGGLEUPDOWN",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'TOGGLEUPDOWN',$
                                        parent:'PLOTOPTIONS'})

    plot_bttn8 = widget_button(plotoptions_menu, value='Toggle Auxiliary Plot',$
                                uname="TOGGLEAUXPLOT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'TOGGLEAUXPLOT',$
                                        parent:'PLOTOPTIONS'})



    imageoptions_menu = widget_button(bar, value='Image Options', /menu)
    image_bttn1 = widget_button(imageoptions_menu, value='S(Q(x,y),t=0)',$
                                uname="SOF0",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SOF0',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn2 = widget_button(imageoptions_menu, value='Signal',$
                                uname="SIGNALIMAGE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SIGNALIMAGE',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn2 = widget_button(imageoptions_menu, value='Av - AVERAGE',$;'P0 - AVERAGE',$
                                uname="FITCONSTANT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITCONSTANT',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn3 = widget_button(imageoptions_menu, value='A - AMPLITUDE',$;'P1 - AMPLITUDE',$
                                uname="FITAMPLITUDE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITAMPLITUDE',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn4 = widget_button(imageoptions_menu, value='PH - PHASE',$;'P2 - PHASE',$
                                uname="FITPHASE",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITPHASE',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn5 = widget_button(imageoptions_menu, value='W - ECHO GAUSSIAN WIDTH',$;'P3 - ECHO GAUSSIAN WIDTH',$
                                uname="FITWIDTH",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITWIDTH',$
                                        parent:'IMAGEOPTIONS'})
    image_bttn6 = widget_button(imageoptions_menu, value='T - PERIOD',$;'P4 - PERIOD',$;OMEGA = 360/(ECHO PERIOD)',$
                                uname="FITOMEGA",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITOMEGA',$
                                        parent:'IMAGEOPTIONS'})
;    image_bttn6 = widget_button(imageoptions_menu, value='P5 - PHASE OFFSET',$
;                                uname="FITPHASEOFFSET",$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'FITPHASEOFFSET',$
;                                        parent:'IMAGEOPTIONS'})
    image_bttn6 = widget_button(imageoptions_menu, value='CHISQ',$
                                uname="FITCHISQ",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'FITCHISQ',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn6m = widget_button(imageoptions_menu, value='MAGNETIC IMAGE OPTIONS',$
                                 uname="MAGNETICIMAGEOPTIONS_MENU",$
                                 /menu,sensitive=0,$
                                 uvalue={object:self,$
                                         method:'menuEvents',$
                                         id:'"MAGNETICIMAGEOPTIONS"',$
                                         parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn6m, value='Magnetic',$
                                uname='MAGNETIC_CASE_0_MENU',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETIC_CASE_0',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn6m, value='Spin Incoherent',$
                                uname='MAGNETIC_CASE_1_MENU',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETIC_CASE_1',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn6m, value='Coherent and Isotope Incoherent',$
                                uname='MAGNETIC_CASE_2_MENU',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETIC_CASE_2',$
                                        parent:'IMAGEOPTIONS'})

    image_bttn6 = widget_button(image_bttn6m, value='Total',$
                                uname='MAGNETIC_CASE_3_MENU',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MAGNETIC_CASE_3',$
                                        parent:'IMAGEOPTIONS'})



    image_bttn6 = widget_button(imageoptions_menu, value='DISPLAY IMAGE ERROR BARS',$
                                uname="IMAGEERRORBARSMENU",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'IMAGEERRORBARS',$
                                        parent:'IMAGEOPTIONS'})
    self.errorImageChoice = 0



    detectoroptions_menu = widget_button(bar, value='Detector Options', /menu)
    detector_bttn1 = widget_button(detectoroptions_menu, value='32x32',$
                                uname='32SQUARE',$
                                sensitive=1,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'32SQUARE',$
                                        parent:'DETECTOROPTIONS'})
    detector_bttn2 = widget_button(detectoroptions_menu, value='64x64',$
                                uname='64SQUARE',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'64SQUARE',$
                                        parent:'DETECTOROPTIONS'})
    detector_bttn3 = widget_button(detectoroptions_menu, value='128x64',$
                                uname='128RECT',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'128RECT',$
                                        parent:'DETECTOROPTIONS'})
    detector_bttn4 = widget_button(detectoroptions_menu, value='128x128',$
                                uname='128SQUARE',$
                                sensitive=0,$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'128SQUARE',$
                                        parent:'DETECTOROPTIONS'})

    calculations_menu = widget_button(bar, value='Calculations', /menu)
;    calculations_bttn2 = widget_button(calculations_menu,$
;                                value='Calculate Q Values',$
;                                uname='CALCULATEQS',$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'CALCULATEQS',$
;                                        parent:'CALCULATIONOPTIONS'})
    calculations_bttn1 = widget_button(calculations_menu,$
                                value='Calculate I(Q,t)',$
                                uname='CALCULATEI',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'CALCULATEI',$
                                        parent:'CALCULATIONOPTIONS'})

    calculations_bttn1 = widget_button(calculations_menu,$
                                value='AutomaskSomething - Alter global mask based on selected criteria',$
                                uname='AUTOMASKSOMETHING',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'AUTOMASKSOMETHING',$
                                        parent:'CALCULATIONOPTIONS'})

    calculations_bttn1 = widget_button(calculations_menu,$
                                value='NSE Diffraction Viewer',$
                                uname='NSEDIFFRACTIONVIEWER',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'NSEDIFFRACTIONVIEWER',$
                                        parent:'CALCULATIONOPTIONS'})


    calculations_bttn1 = widget_button(calculations_menu,$
                                value='AutographNSE - Plot and Fit D(Q) from I(Q,t) Files',$
                                uname='AUTOGRAPHNSE',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'AUTOGRAPHNSE',$
                                        parent:'CALCULATIONOPTIONS'})

;    self.autographNSEbutton = widget_button(llb1,value='Plot and Fit D(Q)',$
;                                                tooltip='AutographNSE')



    calculations_bttn1 = widget_button(calculations_menu,$
                                value='Calculate Average Width',$
                                uname='CALCULATEAVERAGEWIDTH',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'CALCULATEAVERAGEWIDTH',$
                                        parent:'CALCULATIONOPTIONS'})

    calculations_bttn1 = widget_button(calculations_menu,$
                                value='Calculate Unscaled 1d S(Q,t=0)',$
                                uname='CALCULATESQ1D',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'CALCULATESQ1D',$
                                        parent:'CALCULATIONOPTIONS'})


    calculations_bttn1 = widget_button(calculations_menu,$
                                value='Merge Multiple I(Q,t) into DAVE',$
                                uname='MERGEMULTIPLEIQT',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'MERGEMULTIPLEIQT',$
                                        parent:'CALCULATIONOPTIONS'})




    print_menu = widget_button(bar, value='Printing', /menu)
    print_bttn1 = widget_button(print_menu,$
                                value='Print Image',$
                                uname='PRINTIMAGE',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'PRINTIMAGE',$
                                        parent:'PRINTOPTIONS'})

    print_bttn1 = widget_button(print_menu,$
                                value='Print Plot',$
                                uname='PRINTPLOT',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'PRINTPLOT',$
                                        parent:'PRINTOPTIONS'})

    print_bttn1 = widget_button(print_menu,$
                                value='Print Auxiliary Plot',$
                                uname='PRINTAUXPLOT',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'PRINTAUXPLOT',$
                                        parent:'PRINTOPTIONS'})

    help_menu = widget_button(bar, value='Help', /menu)
    help_bttn1 = widget_button(help_menu,$
                                value='Help on NSE',$
                                uname='NSEHELP',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'NSEHELP',$
                                        parent:'HELPOPTIONS'})



end;defineMenus
pro ooDisplayEcho::defineTextWidgets
;
;NAME:
;        ooDisplayEcho::defineTextWidgets
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;;
    ;TEXT WIDGETS FOR DETECTOR PARAMETERS (self.tlb1)
    ;;;


    ;092204
    ;
    ;PROBLEMS WITH REAL ESTATE
    ;
    ;ADD SUGGESTIONS TO EACH OF THE WIDGETS HERE TO
    ;IMPROVE THE USE OF SPACE.

    ;
    ;092204
    ;
    ;SUGGESTION
    ;
    ;MOVE THE NEXT LINE TO A STATUS BAR OR TEXT BOX UNDER PLOTS
;    self.atwfile = cw_field(self.tlb1a2,/noedit,$
    self.atwfile = cw_field(self.tlb1a3,/noedit,/column,$
                                value=file_basename(self.filename)+': '+$
                                    self.comment,$
                                uname='ATWFILE',$
                                $;font = 'TIMES',$
                                uvalue={object:self,$
                                    method:'textEvents',$
                                    id:'ATWFILE'},$
                                title='Current Filename')
;    void = widget_label(self.tlb1a2,value='Current Filename')
;    self.atwfile = widget_text(self.tlb1a2,$
;                                value=file_basename(self.filename)+': '+$
;                                    self.comment,$
;                                uname='ATWFILE',$
;                                uvalue={object:self,$
;                                    method:'textEvents',$
;                                    id:'ATWFILE'})
;    self.adw0 = widget_droplist(self.tlb1a2,$
;                                value=*self.displayChoices,$
;                                title="Select Image to Display",$
;                                uname="DROPDISPLAY",$
;                                uvalue={object:self,$
;                                        method:'droplistEvents',$
;                                        id:'DROPDISPLAY'})
;    self.atl0 = widget_label(self.tlb1a2,value="Detector Choices")
;    self.adw1 = widget_droplist(self.tlb1a2,$
;                                value=*self.detChoices,$
;                                title="Select Detector Size",$
;                                uname="DROPDET",$
;                                uvalue={object:self,$
;                                method:'droplistEvents',$
;                                id:'DROPDET'})

    ;UPDATE 040704


    ;092204
    ;
    ;SUGGESTION:
    ;
    ;KEEP HERE AND ADD BUTTON TO APPLY THIS FACTOR
    ;TO ALL DATA SETS

    ;121404
    ;CONVERT TO A DROPLIST OR COMBOBOX AND HAVE BUTTON
    ;TO APPLY TO ALL DATA SETS.

;    self.atw1 = cw_field(self.tlb1a2,/return_events,$
;                        value='4',uname='ATW1',/column,$
;                                $;font = 'HELVETICA',$
;                                $;fieldfont='HELVETICA',$
;                        uvalue={object:self,$
;                                method:'textEvents',$
;                                id:'ATW1'},$
;                        title = 'Binning/blocking Factor')
;;;;;;    void = widget_label(self.tlb1a2,value='Binning/blocking Factor')
;;;;;;
;;;;;;
;;;;;;    ;THE COMBOBOX WIDGET SEEMS TO HAVE A PROBLEM ON THE MAC!!!
;;;;;;    ;TRY TO REPLACE IT WITH THE cw_pdmenu WIDGET.
;;;;;;
;;;;;;
;;;;;;    ;RICHARD SUGGESTS THAT THE PROBLEM IS THAT THERE IS A "FROM" AND A "TO"
;;;;;;    ;EVENT THAT OCCUR IN X11, AND I NEED TO HANDLE BOTH OF THESE.
;;;;;;
;;;;;;;040605
;;;;;;    binningsubbase = widget_base()
;;;;;;    self.binall = widget_button()
;;;;;;    self.atw1 = WIDGET_COMBOBOX(self.tlb1a2, $;/EDITABLE, $
;;;;;;                                /NO_COPY, $
;;;;;;                                /SENSITIVE, $
;;;;;;                                UVALUE={object:self,$
;;;;;;                                        method:'textEvents',$
;;;;;;                                        id:'ATW1'},$
;;;;;;                                VALUE=['1','2','4','8','16'])
;;;;;;    widget_control,self.atw1,combobox_index = 2



;    self.atw1 = WIDGET_BUTTON(self.tlb1a2,/menu, $
;                                /NO_COPY, $
;                                /SENSITIVE, xsize=50,$
;                                UVALUE={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATW1'},$
;                                VALUE='4 >')
;
;    child = WIDGET_BUTTON(self.atw1, $
;                                /SENSITIVE,xsize=25,$
;                                UVALUE={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATW1'},$
;                                VALUE='1')
;    child = WIDGET_BUTTON(self.atw1, $
;                                /SENSITIVE, xsize=25,$
;                                UVALUE={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATW1'},$
;                                VALUE='2')
;    child = WIDGET_BUTTON(self.atw1, $
;                                /SENSITIVE, xsize=25,$
;                                UVALUE={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATW1'},$
;                                VALUE='4')
;    child = WIDGET_BUTTON(self.atw1, $
;                                /SENSITIVE, xsize=25,$
;                                UVALUE={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATW1'},$
;                                VALUE='8')
;    child = WIDGET_BUTTON(self.atw1, $
;                                /SENSITIVE, xsize=25,$
;                                UVALUE={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATW1'},$
;                                VALUE='16')
;    self.atw1value = 4
;    widget_control,self.atw1,set_value='4 >'


;    atw1desc = REPLICATE({ flags:0, name:'' }, 6)
;    atw1desc.flags = [1,0,0,0,0,2]
;    atw1desc.name = ['Binning/blocking Factor','1','2','4','8','16']
;

;   self.atw1 = cw_pdmenu(self.tlb1a2,atw1desc,$
;                               UVALUE={object:self,$
;                                       method:'textEvents',$
;                                       id:'ATW1'},$
;                                                )

 ;   self.atw1display = widget_text,







;    self.atl1 = widget_label(self.tlb1a2,value='Binning/blocking Factor')
;    self.atw1 = widget_text(self.tlb1a2,/editable,$
;                        value='1',uname='ATW1',$
;                        uvalue={object:self,method:'textEvents',id:'ATW1'});uvalue='ATW1',



    ;
    ;092204
    ;
    ;SUGGESTION
    ;
    ;MOVE TO DROPDOWN MENU CONTROLLED TEXT BOX WITH OTHER
    ;ITEMS IN THIS SECTION AND HAVE AN "APPLY TO ALL" BUTTON
    ;(BEAM CENTER VALUES, LAMBDA, dLAMBDA, )
    self.atwbcx = cw_field(self.tlb1a2,/return_events,/column,$
                                value=strtrim(string(16.0),2),$;value=strtrim(string(self.beamCenxOrig),2),$
                                uname='ATWBCX',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWBCX'},$
                                title='Full Scale Beam Center X')
;    self.atl2 = widget_label(self.tlb1a2,value='Beam Center X')
;    self.atwbcx = widget_text(self.tlb1a2,/editable,$
;                                value=string(self.beamCenxOrig),$
;                                uname='ATWBCX',$
;                                uvalue={object:self,method:'textEvents',id:'ATWBCX'});uvalue='ATWBCX',$

    ;
    ;092204
    ;
    ;SUGGESTION:
    ;
    ;MOVE TO DROPDOWN MENU CONTROLLED TEXT BOX WITH OTHER
    ;ITEMS IN THIS SECTION AND HAVE AN "APPLY TO ALL" BUTTON
    ;THIS MIGHT BE LABELED "GENERAL PARAMETERS"
    self.atwbcy = cw_field(self.tlb1a2,/return_events,/column,$
                                value=strtrim(string(16.0),2),$;value=strtrim(string(self.beamCenyOrig),2),$
                                uname='ATWBCY',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWBCY'},$
                                title='Full Scale Beam Center Y')
;    self.atl3 = widget_label(self.tlb1a2,value='Beam Center Y')
;    self.atwbcy = widget_text(self.tlb1a2,/editable,$
;                                value=string(self.beamCenyOrig),$
;                                uname='ATWBCY',$
;                                uvalue={object:self,method:'textEvents',id:'ATWBCY'});uvalue='ATWBCY',$






    void = widget_label(self.tlb1a3,value='Binning/blocking Factor')


    ;THE COMBOBOX WIDGET SEEMS TO HAVE A PROBLEM ON THE MAC!!!
    ;TRY TO REPLACE IT WITH THE cw_pdmenu WIDGET.


    ;RICHARD SUGGESTS THAT THE PROBLEM IS THAT THERE IS A "FROM" AND A "TO"
    ;EVENT THAT OCCUR IN X11, AND I NEED TO HANDLE BOTH OF THESE.

;040605
    binningsubbase = widget_base(self.tlb1a3,/row)
    self.atw1 = WIDGET_COMBOBOX(binningsubbase, $;/EDITABLE, $
                                /NO_COPY, $
                                /SENSITIVE, $
                                UVALUE={object:self,$
                                        method:'textEvents',$
                                        id:'ATW1'},$
                                VALUE=['1','2','4','8','16'])
;    self.atw1 = WIDGET_COMBOBOX(self.tlb1a3, $;/EDITABLE, $
;                                /NO_COPY, $
;                                /SENSITIVE, $
;                                UVALUE={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATW1'},$
;                                VALUE=['1','2','4','8','16'])
    widget_control,self.atw1,combobox_index = 2
    buttonysize = 20
    self.binallbutton = widget_button(binningsubbase,value = 'Apply Binning to all data',$
                                        tooltip='Apply binning to all current data.',$
                                        ysize = buttonysize,$
                                        UVALUE={object:self,$
                                                method:'textEvents',$
                                                id:'BINALLBUTTON'})

;    self.binallbutton = widget_button(self.tlb1a3,value = 'Apply Bin factor to all data',$
;                                        UVALUE={object:self,$
;                                                method:'textEvents',$
;                                                id:'BINALLBUTTON'})


    DEEPMASKINGsubbase = widget_base(self.tlb1a3,/row)

    self.DEEPMASKINGCHECKBOX = cw_bgroup(DEEPMASKINGsubbase,$
                                        'Apply Deep Masking',$;,'apply to all data'], $
                                        $;ysize = buttonysize,$
                                        /row, /nonexclusive,$
                                        $;/no_release,$
                                        $;frame=1,$
                                        set_value=0,$
                                        uname='DEEPMASKINGCHECKBOX',$
                                        uvalue={object:self,$
                                                method:'textEvents',$
                                                id:'DEEPMASKINGCHECKBOX'})

    CHANGEMASKFILEBUTTON = widget_button(DEEPMASKINGSUBBASE,$
                                         value='New deep mask file',$
                                         uname='CHANGEMASKFILEBUTTON',$
                                         uvalue={object:self,$
                                                 method:'textEvents',$
                                                 id:'CHANGEMASKFILEBUTTON'})


    void = widget_label(self.tlb1a3,value='Transmission')
    self.atwtrans = widget_text(self.tlb1a3,editable=1,$
                                value=strtrim(string(1.0),2),$
                                uname='ATWTRANS',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWTRANS'})



    void = widget_label(self.tlb1a3,value='Volume Fraction')
    self.atwvolfrac = widget_text(self.tlb1a3,editable=1,$
                                value=strtrim(string(1.0),2),$
                                uname='ATWVOLFRAC',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWVOLFRAC'})

    self.transvolallbutton = widget_button(self.tlb1a3,value = 'Apply Trans and volfrac',$
                                        ysize = buttonysize,$
                                        tooltip = 'Apply trans and volfrac to all current data with same type.',$
                                        UVALUE={object:self,$
                                                method:'textEvents',$
                                                id:'TRANSVOLALLBUTTON'})


    ;
    ;092204
    ;
    ;SUGGESTION:
    ;
    ;MOVE TO DROPDOWN MENU CONTROLLED TEXT BOX WITH OTHER
    ;ITEMS IN THIS SECTION AND HAVE AN "APPLY TO ALL" BUTTON
    ;THIS MIGHT BE LABELED "SAMPLE PARAMETERS"
;    self.atwtrans = cw_field(self.tlb1a2,/return_events,$
;;;;;    self.atwtrans = cw_field(self.tlb1a3,/return_events,/column,$
;;;;;                                value=strtrim(string(1.0),2),$
;;;;;                                uname='ATWTRANS',$
;;;;;                                uvalue={object:self,$
;;;;;                                        method:'textEvents',$
;;;;;                                        id:'ATWTRANS'},$
;;;;;                                title='Transmission')
;;;;;
;;;;;
;;;;;
;;;;;    ;
;;;;;    ;092204
;;;;;    ;
;;;;;    ;SUGGESTION:
;;;;;    ;
;;;;;    ;MOVE TO DROPDOWN MENU CONTROLLED TEXT BOX WITH OTHER
;;;;;    ;ITEMS IN THIS SECTION AND HAVE AN "APPLY TO ALL" BUTTON
;;;;;    ;THIS MIGHT BE LABELED "SAMPLE PARAMETERS"
;;;;;;    self.atwvolfrac = cw_field(self.tlb1a2,/return_events,$
;;;;;    self.atwvolfrac = cw_field(self.tlb1a3,/return_events,/column,$
;;;;;                                value=strtrim(string(1.0),2),$
;;;;;                                uname='ATWVOLFRAC',$
;;;;;                                uvalue={object:self,$
;;;;;                                        method:'textEvents',$
;;;;;                                        id:'ATWVOLFRAC'},$
;;;;;                                title='Volume Fraction')
;;;;;

;
;    void = widget_label(self.tlb1a2,value='Transmission')
;    self.atwtrans = widget_text(self.tlb1a2,/editable,$
;                                value=string(self.beamCenyOrig),$
;                                uname='ATWTRANS',$
;                                uvalue={object:self,method:'textEvents',id:'ATWTRANS'});uvalue='ATWBCY',$

    ;
    ;092204
    ;
    ;SUGGESTION:
    ;
    ;MOVE TO DROPDOWN MENU CONTROLLED TEXT BOX WITH OTHER
    ;ITEMS IN THIS SECTION AND HAVE AN "APPLY TO ALL" BUTTON
    ;THIS MIGHT BE LABELED "SAMPLE PARAMETERS"
    self.atwnarcs = cw_field(self.tlb1a2,/return_events,/column,$
                                value=strtrim(string(5),2),$
                                uname='ATWNARCS',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWNARCS'},$
                                title='Number of Q Arcs')

    ;
    ;092204
    ;
    ;SUGGESTION:
    ;
    ;MOVE TO DROPDOWN MENU CONTROLLED TEXT BOX WITH OTHER
    ;ITEMS IN THIS SECTION AND HAVE AN "APPLY TO ALL" BUTTON
    ;THIS MIGHT BE LABELED "GENERAL PARAMETERS"
    self.atwwidth = cw_field(self.tlb1a2,/return_events,/column,$
                                value=strtrim(string(702.0),2),$
                                uname='ATWWIDTH',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWWIDTH'},$
                                title='GAUSSIAN WIDTH OF ECHOES')

    self.atwperiod = cw_field(self.tlb1a2,/return_events,/column,$
                                value=strtrim(string(360.0),2),$
                                uname='ATWPERIOD',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWPERIOD'},$
                                title='PERIOD OF ECHOES')
;    self.atwphaseoffset = cw_field(self.tlb1a2,/return_events,/column,$
;                                value=strtrim(string(0.0),2),$
;                                uname='ATWPHASEOFFSET',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWPHASEOFFSET'},$
;                                title='PHASE OFFSET OF ECHOES')

    ;
    ;092204
    ;
    ;SUGGESTION:
    ;
    ;MOVE TO DROPDOWN MENU CONTROLLED TEXT BOX WITH OTHER
    ;ITEMS IN THIS SECTION AND HAVE AN "APPLY TO ALL" BUTTON
    ;THIS MIGHT BE LABELED "GENERAL PARAMETERS"
    ;
    ;NOTE: THIS PARAMETER IS TAKEN FROM THE DATA FILE.


;092504
;NEED TO MAKE THIS EDITABLE
    self.atwlambda = cw_field(self.tlb1a2,/return_events,/column,$;/noedit,$
                                value=strtrim(string(self.lambda*(10.0^10)),2),$
                                uname='ATWLAMBDA',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWLAMBDA'},$
                                title = 'Lambda (Angstrom)')

;    self.atl4 = widget_label(self.tlb1a2,value='Lambda (Angstrom)')
;    self.atwlambda = widget_text(self.tlb1a2,/editable,$
;                                value=string(self.lambda*(10.0^10)),$
;                                uname='ATWLAMBDA',$
;                                uvalue={object:self,method:'textEvents',id:'ATWLAMBDA'});uvalue='ATWLAMBDA',$


    ;
    ;092204
    ;
    ;SUGGESTION:
    ;
    ;MOVE TO DROPDOWN MENU CONTROLLED TEXT BOX WITH OTHER
    ;ITEMS IN THIS SECTION AND HAVE AN "APPLY TO ALL" BUTTON
    ;THIS MIGHT BE LABELED "GENERAL PARAMETERS"
    ;
    ;NOTE:  THIS PARAMETER IS READ FROM THE DATA FILE BUT
    ;       SHOULD BE SET BY THE USER.


;092504
;NEED TO MAKE THIS EDITABLE
;102605
;THIS IS AN UNUSED FIELD WHICH MIGHT BE DISPENSED WITH.
;    self.atwlambdadist = cw_field(self.tlb1a2,/return_events,/column,$;/noedit,$
;                                value=strtrim(string(100.0*self.dlambda/self.lambda),2),$
;                                uname='ATWLAMBDADIST',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWLAMBDADIST'},$
;                                title = 'Lambda Distribution (%)')


;102605
;e.g. from fws_analysis__define.pro:
;depVar = ['time (min)','T (K) sample', 'T (K) control'];, 'Q (A-1)']
;self.depVarGroup = cw_bgroup(self.colBase2, depVar, /col, /exclusive,$
;         label_top='Independent variable',/no_release,$
;         frame=1,set_value=1,/return_index, $
;         uvalue = {object:self,method:'selVar'})
    magneticlabel = ['nonmagnetic','magnetic'];['No','Yes']

;120205
;REPLACE WITH A SINGLE NONEXCLUSIVE BGROUP CHECKBOX.

;    self.magneticcheckbox = cw_bgroup(self.tlb1a3, magneticlabel, $
;                                        /row, /exclusive,$
;                                        ;label_top='Magnetic Data?',$
;                                        /no_release,$
;                                        frame=1,$
;                                        set_value=0,$
;                                        /return_index,$
;                                        uname='MAGNETICCHECKBOX',$
;                                        uvalue={object:self,$
;                                                method:'textEvents',$
;                                                id:'MAGNETICCHECKBOX'})
;


    timeaveragesubbase = widget_base(self.tlb1a3,/row)

    self.TIMEAVERAGEUPDOWNCHECKBOX = cw_bgroup(timeaveragesubbase,$
                                        'time average up/down',$;,'apply to all data'], $
                                        $;ysize = buttonysize,$
                                        /row, /nonexclusive,$
                                        $;/no_release,$
                                        $;frame=1,$
                                        set_value=0,$
                                        uname='TIMEAVERAGEUPDOWNCHECKBOX',$
                                        uvalue={object:self,$
                                                method:'textEvents',$
                                                id:'TIMEAVERAGEUPDOWNCHECKBOX'})

    self.TIMEAVERAGEUPDOWNAPPLYALLBUTTON = widget_button(timeaveragesubbase,$
                                                            value='Apply t_ave to all data',$
                                                            tooltip='Apply Time Averaging State to all current data.',$
                                                            ysize = buttonysize,$
                                                            uname='TIMEAVERAGEUPDOWNAPPLYALLBUTTON',$
                                                            uvalue={object:self,$
                                                                    method:'textEvents',$
                                                                    id:'TIMEAVERAGEUPDOWNAPPLYALLBUTTON'})



magneticbase = widget_base(self.tlb1a3,frame=1,/col)
;magneticSubBase = widget_base(magneticbase,/row)
    self.magneticcheckbox = cw_bgroup(magneticbase, 'magnetic', $
                                        /row, /nonexclusive,$
                                        /no_release,$
                                        $;frame=1,$
                                        set_value=0,$
                                        uname='MAGNETICCHECKBOX',$
                                        uvalue={object:self,$
                                                method:'textEvents',$
                                                id:'MAGNETICCHECKBOX'})


    self.ATWFLIPPINGRATIO = cw_field(magneticbase,/return_events,/row,$;/noedit,$
                                value=0.97,$
                                uname='ATWFLIPPINGRATIO',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWFLIPPINGRATIO'},$
                                title = 'f (Flipping Ratio)',/floating,xsize=10,ysize=1)

    self.ATWPOLARIZATION = cw_field(magneticbase,/return_events,/row,$;/noedit,$
                                value=0.8,$
                                uname='ATWPOLARIZATION',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWPOLARIZATION'},$
                                title = 'P (Polarization)',/floating,xsize=10,ysize=1)


    eff_bpwbase = widget_base(magneticbase,/row)
    self.ATWEFF_BPW = cw_field(magneticbase,/return_events,/row,$;/noedit,$
                                value=0.81,$
                                uname='ATWEFF_BPW',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWEFF_BPW'},$
                                title = 'Eff_BPW',/floating,xsize=10,ysize=1)

;    self.ATWEFF_BPW_X = cw_field(eff_bpwbase,/return_events,/col,$;/noedit,$
;                                value=0.81,$
;                                uname='ATWEFF_BPW_X',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWEFF_BPW_X'},$
;                                title = 'Eff_BPW_X',/floating,xsize=10,ysize=1)
;    self.ATWEFF_BPW_Y = cw_field(eff_bpwbase,/return_events,/col,$;/noedit,$
;                                value=0.81,$
;                                uname='ATWEFF_BPW_Y',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWEFF_BPW_Y'},$
;                                title = 'Eff_BPW_Y',/floating,xsize=10,ysize=1)
;    self.ATWEFF_BPW_Z = cw_field(eff_bpwbase,/return_events,/col,$;/noedit,$
;                                value=0.81,$
;                                uname='ATWEFF_BPW_Z',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWEFF_BPW_Z'},$
;                                title = 'Eff_BPW_Z',/floating,xsize=10,ysize=1)



    self.atwxyzupdownscale = cw_field(magneticbase,/return_events,/row,$;/noedit,$
                                value=1.0,$
                                uname='ATWXYZUPDOWNSCALE',$
                                uvalue={object:self,$
                                        method:'textEvents',$
                                        id:'ATWXYZUPDOWNSCALE'},$
                                title = 'X,Y,Z Up/Down Scale',/floating,xsize=10,ysize=1)

;
;    self.ATWPOINT_TO_UP_X = cw_field(magneticbase,/return_events,/row,$;/noedit,$
;                                value=11,$
;                                uname='ATWPOINT_TO_UP_X',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWPOINT_TO_UP_X'},$
;                                title = 'Point_to_UP_X',/integer,xsize=10,ysize=1)
;
;
;    self.ATWPOINT_TO_DOWN_X = cw_field(magneticbase,/return_events,/row,$;/noedit,$
;                                value=12,$
;                                uname='ATWPOINT_TO_DOWN_X',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWPOINT_TO_DOWN_X'},$
;                                title = 'Point_to_DOWN_X',/integer,xsize=10,ysize=1)
;
;    self.ATWPOINT_TO_UP_Y = cw_field(magneticbase,/return_events,/row,$;/noedit,$
;                                value=13,$
;                                uname='ATWPOINT_TO_UP_Y',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWPOINT_TO_UP_Y'},$
;                                title = 'Point_to_up_Y',/integer,xsize=10,ysize=1)
;
;    self.ATWPOINT_TO_DOWN_Y = cw_field(magneticbase,/return_events,/row,$;/noedit,$
;                                value=14,$
;                                uname='ATWPOINT_TO_DOWN_Y',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWPOINT_TO_DOWN_Y'},$
;                                title = 'Point_to_DOWN_Y',/integer,xsize=10,ysize=1)
;
;    self.ATWPOINT_TO_UP_Z = cw_field(magneticbase,/return_events,/row,$;/noedit,$
;                                value=15,$
;                                uname='ATWPOINT_TO_UP_Z',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWPOINT_TO_UP_Z'},$
;                                title = 'Point_to_up_Z',/integer,xsize=10,ysize=1)
;
;    self.ATWPOINT_TO_DOWN_Z = cw_field(magneticbase,/return_events,/row,$;/noedit,$
;                                value=16,$
;                                uname='ATWPOINT_TO_DOWN_Z',$
;                                uvalue={object:self,$
;                                        method:'textEvents',$
;                                        id:'ATWPOINT_TO_DOWN_Z'},$
;                                title = 'Point_to_DOWN_Z',/integer,xsize=10,ysize=1)
;
;
;



;    self.atl5 = widget_label(self.tlb1a2,value='Lambda Distribution (%)')
;    self.atwlambdadist = widget_text(self.tlb1a2,/editable,$
;                                value=string(100.0*self.dlambda/self.lambda),$
;                                uname='ATWLAMBDADIST',$
;                                uvalue={object:self,method:'textEvents',id:'ATWLAMBDADIST'});uvalue='ATWLAMBDADIST',$

end;defineTextWidgets

pro ooDisplayEcho::dropTimes,event
;
;NAME:
;        ooDisplayEcho::dropTimes
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;THIS PROCEDURE WILL RECEIVE EVENTS FROM THE NEWLY CREATED dropTimes CONTEXT MENU AND
    ;DROP THE SPECIFIED FOURIER TIME FROM THE CURRENTLY SELECTED DATA OBJECT.

    widget_control,event.id,get_uvalue = uval

    ;print,'ooDisplayEcho::dropTimes uval.id=',uval.id
    st = strtrim(string(*((self.datacontainer->get(position=self.QChoiceIndex))->getProperty(tag='fourierTime'))),2)
    ;print,st
    ;print,where(st eq uval.id)


 ;FOR BETTER CONTROL, THE PARENT OF THIS MENU SHOULD BE A CLASS MEMBER VARIABLE!!!!!!!
    parent = widget_info(event.id,/parent)
    ;print,'parent=',parent

    for i=0,n_elements(st)-1 do begin
        id = widget_info(parent,find_by_uname='DROPTIMEBUTTON'+st[i])
        ;print,id
        widget_control,id,/destroy
    endfor


;011805
;DO I UPDATE DISPLAY HERE???





end;dropTimes
pro ooDisplayEcho::dropTimeEvents,event
;
;NAME:
;        ooDisplayEcho::dropTimeEvents
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    ;AS SOON AS THIS EVENT HAPPENS, CREATE THE SUBWIDGETS OF THE
    ;DROPTIMEBASE.
;print,'8805 oodisplayecho::dropTimeEvents'
;print,tag_names(event,/structure_name)
;print,tag_names(event)
;print,event
;    print,'ooDisplayEcho::DROPTIMEEVENT'
    st = strtrim(string(*((self.datacontainer->get(position=self.QChoiceIndex))->getProperty(tag='fourierTime'))),2)
;    print,transpose(st)




;020105
;
;    ;DON'T DO THIS!!!! IT IS A MESS DUE TO A PROBLEM WITH DESTOYING THESE WIDGETS!!!
;   ;ALSO THERE SEEMS TO BE ISSUES WITH X11!!!
;   IF I DON'T CREATE THIS, THE ooDisplayEcho::dropTimes METHOD ABOVE SHOULD NEVER BE ACCESSED.
;
;    dtb = widget_info(event.top,find_by_uname='DROPTIMEBASE')
;
;
;
;    ;POPULATE DROPTIME CONTEXT MENU
;    for i=0,n_elements(st)-1 do begin
;        newbut = widget_button(dtb,value=st[i],uname = 'DROPTIMEBUTTON'+st[i],$
;                                uvalue={object:self,$
;                                        method:'dropTimes',$
;                                        id:st[i]})
;
;
;    endfor;i

;print,'8805 oodisplayecho::dropTimeEvents'
;print,tag_names(event,/structure_name)
;print,tag_names(event)
;print,event
;;   ;DISPLAY DROPTIME CONTEXT MENU
;;   WIDGET_DISPLAYCONTEXTMENU, event.ID, event.X, event.Y, dtb
;;


end;dropTimeEvents


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::reDefineWidgets,n,t=t,newsize=newsize,resetdataparameters=resetdataparameters,$
                            checktime_aveflag=checktime_aveflag,checkdeepmaskflag=checkdeepmaskflag
;
;NAME:
;        ooDisplayEcho::reDefineWidgets
;
;PURPOSE:
;               Update all widgets in ooDisplayEcho after some event.
;PARAMETERS:
;               n   Presumably a data object index, but appears to be unused below.
;
;KEYWORDS:
;           t           Selected Fourier time.
;           newsize     Flag for possible dimension change from previous selected data set to current one.
;           resetdataparameters
;           checktime_aveflag   Flag to check for time averaging to set checkbox
;           checkdeepmaskflag   Flag to check object for deepmasking.
;;
;RESET WIDGETS AS NECESSARY ON OPENING OF A
;NEW DATA SET
;;;

;    if (obj_valid(self.ech) ne 0) then obj_destroy,self.ech
;    self.ech = (self.dataContainer->get(position=n))->clone()
;    self.filename = self.ech->getProperty(tag='filename')



    ;print,'4967 ooDisplayEcho::reDefineWidgets'

    if n_elements(checktime_aveflag) eq 0 then checktime_aveflag = 0
    if n_elements(checkdeepmaskflag) eq 0 then checkdeepmaskflag = 0

    ;IN CASE THE SIZE OF THE DATA SET IS DIFFERENT FROM
    ;THE PREVIOUS SET THE newsize CODE BLOCK SHOULD BE RUN.
    if n_elements(newsize) ne 0 then begin

        ;120504
        ;THE NEXT STEP ACCOUNTS FOR CASES
        ;WHERE THE NEWLY READ OBJECT HAS
        ;A DIFFERENT SIZE FROM THE CURRENTLY
        ;SELECTED OBJECT
;        self.QChoiceIndex = 0

        if self.QChoiceIndex ge self.datacontainer->count() then self.QChoiceIndex = 0
        zeroref = self.datacontainer->get(position=self.QChoiceIndex)
        self.detXdim = zeroref->getproperty(tag='x_dim')
        self.detYdim = zeroref->getproperty(tag='y_dim')
;        self.xindex = self.detXdim/2
;        self.yindex = self.detYdim/2
        self->updateIndices,x=self.detXDim/2,y=self.detYDim/2

        if ptr_valid(self.mye) then ptr_free,self.mye
        tempe = *(zeroref->getproperty(tag='e'))
        self.mye = ptr_new(tempe)

    endif;newsize
    ;print,zz[ptr_new(4)]

    if n_elements(resetdataparameters) eq 0 then resetdataparameters = 0



    if self.QChoiceIndex ge self.dataContainer->count() then $
        self.QChoiceIndex = self.dataContainer->count()-1

    if self.QChoiceIndex lt 0 then self.QChoiceIndex = 0




    ref = self.dataContainer->get(position=self.QChoiceIndex)

    self.filename = ref->getProperty(tag='filename')
    thisTitle = 'NSE Data Reduction';   Current Data File = '$
                    ;+self.filename

    ;NEED TO DISPLAY THE FILE NAMES SOMEWHERE OTHER THEN THE
    ;TLB TITLE.

    widget_control,self.atwfile,set_value=file_basename(self.filename) $
                                        +': '+self.comment


    ;UPDATE TLB TITLE TO REFLECT --- THIS DOES NOT WORK!!!
    ;THERE IS NO set_title OPTION IN widget_control.

    ;widget_control,self.atlb,set_title = thisTitle

    ;THE NEXT PART MAY BE BETTER HANDLED BY ASSOCIATING
    ;A Q-VALUE AND FILE NAME WITH EACH DATA FILE READ
    ;AND USING THE Q-INDEX DROPLIST TO ACCESS THEM.
    ;
    ;THIS NEEDS TO BE VARIABLE AND PASSABLE TO THE FITTING ROUTINE




    ;SET DROPLIST INDEX WIDGETS
    tempTauInd = widget_info(self.adwTau,/droplist_select)

    ;UPDATE 040704
;    widget_control,self.adwQ,set_value = string(indgen(self.nDataObj)),$
;                                               set_droplist_select = n


    ;widget_control,self.adwTau,set_droplist_select=tempTauInd

    ;UPDATE 040704
    tauVals = *(ref->getProperty(tag='fourierTime'))
    ;print,tauVals

    if n_elements(t) gt 0 then begin
        self.ftChoiceIndex = t[0]
    endif
    if self.ftChoiceIndex ge n_elements(tauVals)-1 then begin
        self.ftChoiceIndex = n_elements(tauVals)-1
    endif
    if self.ftChoiceIndex le 0 then begin
        self.ftChoiceIndex = 0
    endif




;110204
;
;SHOULD SET UP NEXT LINE TO SET SELECT=0 ONLY WHEN SELF.QCHOICEINDEX CHANGES.
    if n_elements(t) eq 0 then begin
        if self.QChoiceIndex ne self.QChoiceIndexOld then begin
            widget_control,self.adwTau,set_droplist_select=0
        endif else begin
            widget_control,self.adwTau,set_droplist_select=self.ftChoiceIndexOld
        endelse
        widget_control,self.adwTau,set_value=strtrim(string(10.0^9*tauVals),2)
    endif else begin
        widget_control,self.adwTau,set_value=strtrim(string(10.0^9*tauVals),2)
        widget_control,self.adwTau,set_droplist_select=t
    endelse



    ;SET VALUES IN CONSTANTS SECTION
    num = ref->getProperty(tag = 'x_dim_orig')
    denom = ref->getProperty(tag = 'x_dim')
    binFactor = num/denom


;THE NEXT LINES DEALT WITH self.atw1 WHEN IT WAS A combobox.
;THIS IS NO LONGER THE CASE DUE TO AN INCOMPATIBILTY WITH X11.
;NOW IT IS SET UP AS A SERIES OF BUTTONS.

;021005
;RETURN TO COMBOBOX AND SEE WHAT WENT WRONG.


    widget_control,self.atw1,get_value=atw1arr

    if n_elements(atw1arr) ne 5 then begin
        atw1arr = ['1','2','4','8','16']
        widget_control,self.atw1,set_value=strtrim(string(atw1arr),2)
    endif

;    print,'where(atw1arr eq strtrim(string(binFactor),2)) = ', $
;                    where(atw1arr eq strtrim(string(binFactor),2))
    atw1index = where(atw1arr eq strtrim(string(binFactor),2))


;;;;;widget_control,self.atw1,set_value=strtrim(string(binFactor),2)+' >'
    widget_control,self.atw1,set_combobox_select = atw1index[0]
;    help,atw1index
;    print,'SET self.atw1,set_combobox_select = ',atw1index[0]


    if resetdataparameters ne 1 then begin
        widget_control,self.atwbcx,set_value=strtrim(string(ref->getProperty(tag='x_cen_orig')),2)
        widget_control,self.atwbcy,set_value=strtrim(string(ref->getProperty(tag='y_cen_orig')),2)
    endif


    widget_control,self.atwtrans,$
        set_value=strtrim(string(ref->getProperty(tag='transmission')),2)
    widget_control,self.atwvolfrac,$
        set_value=strtrim(string(ref->getProperty(tag='volfrac')),2)


;121505
    narcs = (self.dataContainer->get(position=self.QChoiceIndex))->getProperty(tag='narcs')
            if narcs lt 1 or narcs gt 16 then begin
                narcs = 7
                widget_control,self.atwnarcs,set_value=strtrim(string(narcs),2)
            endif

    widget_control,self.atwnarcs,$
        set_value=strtrim(string(narcs),2)

;040605
;SETS EDITABILITY ON SELECTION OF OBJECT
    thetype = (self.dataContainer->get(position=self.QChoiceIndex))->getProperty(tag='type')
    transeditable = 0
    volfraceditable = 0
    case thetype of
    0:begin
        transeditable = 1
        volfraceditable = 1
    end
    1:begin;res
        transeditable = 0
        volfraceditable = 0
    end
    2:begin;dat
        transeditable = 1
        volfraceditable = 1
    end
    3:begin;cell
        transeditable = 1
        volfraceditable = 0
    end
    else:begin
        transeditable = 1
        volfraceditable = 1
    end
    endcase
    widget_control,self.atwtrans,editable = transeditable
    widget_control,self.atwvolfrac,editable = volfraceditable
;    help,/traceback

    ;WILL THERE BE A DEEPMASKINGCHECK HERE?????

    if checktime_aveflag eq 1 then begin
        widget_control,self.timeaverageupdowncheckbox,set_value=ref->report_timeaverage_state()
    endif

    if checkdeepmaskflag eq 1 then begin
        widget_control,self.deepmaskingcheckbox,set_value=ref->report_Deepmask_state()
    endif



    self.lambda = (self.dataContainer->get(position=$
                            self.QChoiceIndex))->getProperty(tag='lambda')
    self.dlambda = (self.dataContainer->get(position=$
                            self.QChoiceIndex))->getProperty(tag='dlambda')


    widget_control,self.atwlambda,set_value=strtrim(string(self.lambda*10.0^10),2)
    ;102605
    if widget_info(self.atwlambdadist,/valid_id) gt 0 then begin
        widget_control,self.atwlambdadist,set_value=strtrim(string(100.0*self.dlambda/self.lambda),2)
    endif


    ;SET VALUES IN FIT PARAMETER WIDGETS
    ;self.fixed = [0,0,0,1,1,1]

    t = self.ftChoiceIndex
    ref = self.dataContainer->get(position=self.QChoiceIndex)
    pfixed = (ref->getProperty(tag='fixed'))



;021306
;THE NEXT ITEM MUST BE CORRECTED SOMEHOW TO REFLECT 8 CHOICES!!!!
    self.fixed = (*pfixed)[*,self.xindex+self.yindex*self.detxdim,t]
;I THINK IT WAS CORRECTED ELSEWHERE AND WORKS FINE HERE NOW.


    fixedstate = ref->getFixVaryState(self.xindex,self.yindex,self.ftChoiceIndex)





;TEMPORARY FIX, MULTIPLY self.fixed BY 4
    for iii=0,n_elements(self.fixed)-1 do begin
        self->updateFitparmWidget,iii,fixedstate[iii];4*self.fixed[iii]
    endfor;iii


    thenewbasetitle = 'NSE Data Reduction     ' + $
                        file_basename(ref->getProperty(tag='filename')) + $
                        ': ' + $
                        ref->getProperty(tag='comment')

    widget_control,self.atlb,base_set_title=thenewbasetitle





;    widget_control,self.dropfixconst,set_droplist_select=self.fixed[0]
;    widget_control,self.dropfixamp,set_droplist_select=self.fixed[1]
;    widget_control,self.dropfixphaseo,set_droplist_select=self.fixed[2]
;    widget_control,self.dropfixsigma,set_droplist_select=self.fixed[3]
;    widget_control,self.dropfixomega,set_droplist_select=self.fixed[4]
;    widget_control,self.dropfixphase,set_droplist_select=self.fixed[5]

    ;self->reDefineTree

end;reDefineWidgets

pro ooDisplayEcho::resizeWidgets,event,lastresize=lastresize
;
;NAME:
;        ooDisplayEcho::resizeWidgets
;
;PURPOSE:
;           Handle resizing aspect of atlbevents.
;PARAMETERS:
;           event   The event structure to handle.
;KEYWORDS:
;           lastresize  On Mac and Linux, the resize events don't seem
;                       to be triggered the same way as on Windows,
;                       so this keyword will be used on a second resizing
;                       called for non-Win32 systems.






    if n_elements(lastresize) eq 0 then lastresize = 0


             ;UPDATE SIZES OF WINDOW ON RESIZE EVENTS.
;021105
;CALCULATE THE WINDOW SIZES

;040505
;
;GETTING SCREEN SIZE TO TRY TO LIMIT GROWTH ON A MAC
            r = get_screen_size()


            if !version.os eq 'Win32' then begin
                xresizemagic = 0
                yresizemagic = 0
            endif else begin
                xresizemagic = 10
                yresizemagic = 40
            endelse

                                            ;013105
            if event.x lt 770 then begin    ;DROP SIZES FROM 800x600 TO 770x500 FOR MAC X11
                self.atlbxsize=770
            endif else begin
                if event.x ge (r[0]-50) then begin
                    self.atlbxsize=r[0]-50
                endif else begin
                    self.atlbxsize=event.x-xresizemagic
                endelse
            endelse
            if event.y lt 550 then begin
                self.atlbysize=550
            endif else begin
                if event.y ge (r[1]-50) then begin
                    self.atlbysize=r[1]-50
                endif else begin
                    self.atlbysize=event.y-yresizemagic
                endelse
            endelse


    self.filetreeysize = min([550,self.atlbysize - self.ypadding])
    self.tabsysize = min([550,self.atlbysize - self.ypadding])




    if n_elements(plotxsize) gt 0 then begin
        self.plotxsize = plotxsize
    endif else begin
        self.plotxsize = fix(self.atlbxsize - $;self.filetreexsize - $
                            self.filetreexpadding - self.tabsxsize - self.tabsxpadding - self.xpadding-self.magicxpadding)
    endelse


    ;033005
    ;MOVE CLICK REFIT SLIDERS TO A SEPARATE FLOATING DIALOG
    if n_elements(plotysize) gt 0 then begin
        self.plotysize = plotysize
    endif else begin
;        self.plotysize = fix((self.atlbysize - self.ypadding - $
;                            self.clickphaseysize - self.taucdysize - self.tw1ysize-self.magicypadding)/2)
        self.plotysize = fix((self.atlbysize - self.ypadding - $
                            self.taucdysize - self.tw1ysize-self.magicypadding)/2)
    endelse

    self.drawbasexsize = self.plotxsize
    self.drawbaseysize = 2*self.plotysize + self.taucdysize + self.tw1ysize;+ self.clickphaseysize + self.tw1ysize



;021105
;NOW ADJUST THE WINDOW SIZES
            widget_control,self.dw1,xsize= self.plotxsize,ysize=self.plotysize
            widget_control,self.dw2,xsize= self.plotxsize,ysize=self.plotysize
;060605
;;;;;            if widget_info(self.dw2aux,/valid_id) gt 0 then $
;;;;;                widget_control,self.dw2aux,xsize= self.plotxsize,ysize=self.plotysize

            if ptr_valid(self.geomImage) gt 0 then ptr_free,self.geomImage
            self.geomImage = ptr_new(widget_info(self.dw1,/geometry))
            if ptr_valid(self.geomPlot) gt 0 then ptr_free,self.geomPlot
            self.geomPlot = ptr_new(widget_info(self.dw2,/geometry))

    ;RUN THIS WIDGET A SECOND TIME ON Mac AND UNIX.
    if !Version.OS ne 'Win32' and lastresize eq 0 then begin
        self->resizeWidgets,event,lastresize=1
    endif else begin
;            wdelete,self.dw1pix & wdelete,self.dw2pix
            wdelete,self.dw1pix
            wdelete,self.dw2pix
;060605
;;;;;            if widget_info(self.dw2auxpix,/valid_id) ne 0 then $
;;;;;                wdelete,self.dw2auxpix

            ;CREATE PIXMAP WINDOW FOR DOUBLE BUFFERING OF IMAGE WINDOW
            window,/free,/pixmap,xsize=self.plotxsize,$
                                ysize=self.plotysize
            self.dw1pix = !d.window
            ;RELEASE AXIS POINTERS FOR WINDOW
            ptr_free,self.w1xptr
            ptr_free,self.w1yptr

            ;RESET AXIS POINTERS
            self.w1xptr = ptr_new(!x)   ;SET THESE VALUES AT THIS POINT TO
            self.w1yptr = ptr_new(!y)   ;PREVENT AXIS CONFUSION


            ;CREATE PIXMAP WINDOW FOR DOUBLE BUFFERING OF PLOT WINDOW
            window,/free,/pixmap,xsize=self.plotxsize,$
                                ysize=self.plotysize
            self.dw2pix = !d.window

            ;RELEASE AXIS POINTERS FOR WINDOW
            ptr_free,self.w2xptr
            ptr_free,self.w2yptr

            ;RESET AXIS POINTERS
            self.w2xptr = ptr_new(!x)   ;SET THESE VALUES AT THIS POINT TO
            self.w2yptr = ptr_new(!y)   ;PREVENT AXIS CONFUSION


;060605
;            self->resizeAuxWindow,event,xsize=self.plotxsize,ysize=self.plotysize
            ;CREATE PIXMAP WINDOW FOR DOUBLE BUFFERING OF PLOT WINDOW
;;;;;            window,/free,/pixmap,xsize=self.plotxsize,$
;;;;;                                ysize=self.plotysize
;;;;;            self.dw2auxpix = !d.window

;;;;;            ;RELEASE AXIS POINTERS FOR WINDOW
;;;;;            ptr_free,self.w2xauxptr
;;;;;            ptr_free,self.w2yauxptr
;;;;;
;;;;;            ;RESET AXIS POINTERS
;;;;;            self.w2xauxptr = ptr_new(!x)   ;SET THESE VALUES AT THIS POINT TO
;;;;;            self.w2yauxptr = ptr_new(!y)   ;PREVENT AXIS CONFUSION

;060605
;OMIT THIS RESIZE OF AUX WINDOW ON GENERAL RESIZE SINCE USER CHOOSES SIZE.
;ALSO OMIT THE RELATED RESIZE COMMANDS ABOVE.
;
;;;;;            if widget_info(self.dw2auxbase,/valid_id) gt 0 then $
;;;;;                widget_control,self.dw2auxbase,xsize= self.plotxsize,ysize=self.plotysize

;;            window,self.dw2pix,xsize=self.plotxsize,ysize=self.plotysize
;            ;widget_control,self.dw1pix,get_value=self.dw1pixid
    endelse





end;resizeWidgets


pro ooDisplayEcho::defineCDControls,base=base
;
;NAME:
;        ooDisplayEcho::defineCDControls
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;CREATE CD CONTROLS FOR SELECTING FILE,TAU INDICES

    ;void = widget_label(self.tlb1a2,value='Q Values')
;;
;REMOVE THE Q SELECTION CD CONTROLS SINCE THEY ARE REDUNDANT
;;;
;;    qTempBase = widget_base(self.tlb1a2,/row)
;;    void = widget_label(qTempBase,value='Data File Index',xsize=100)
;;    self.rewbuttonq = widget_button(qTempBase,$
;;                                    value = '|<',$
;;                                    uvalue={object:self,$
;;                                            method:'buttonEvents',$
;;                                            id:'REWBUTTONQ'})
;;    self.revbuttonq = widget_button(qTempBase,$
;;                                    value = '<',$
;;                                    uvalue={object:self,$
;;                                            method:'buttonEvents',$
;;                                            id:'REVBUTTONQ'})
;;    self.adwQ = widget_droplist(qTempBase,$
;;                                value=string(indgen(self.nDataObj+1)),$;CHANGE TO QChoices WHEN READY
;;                                $;title="Select Q Value Index",$
;;                                $;event_pro="displayEcho_droplistevent",$
;;                                xsize = 100,$
;;                                uname="DROPQ",$
;;                                uvalue={object:self,$
;;                                        method:'droplistEvents',$
;;                                        id:'DROPQ'})
;;    self.fwdbuttonq = widget_button(qTempBase,$
;;                                    value = '>',$
;;                                    uvalue={object:self,$
;;                                            method:'buttonEvents',$
;;                                            id:'FWDBUTTONQ'})
;;    self.ffwdbuttonq = widget_button(qTempBase,$
;;                                    value = '>|',$
;;                                    uvalue={object:self,$
;;                                            method:'buttonEvents',$
;;                                            id:'FFWDBUTTONQ'})
    ;self.atl6 = widget_label(self.tlb1a2,value='Fourier Time Index')



;092204
;
;OBVIOUSLY THIS SHOULD BE A COMPOUND WIDGET!!!
;


    buttonysize = 20
;    tauTempBase = widget_base(self.tlb1a2,/row)
;    tauTempBase = widget_base(self.tlb1b,/row)
;    self.atl6 = widget_label(tauTempBase,value='Fourier Time (ns)');,xsize=95)

    if n_elements(base) eq 0 then base=self.tlb1b

    ;self.atl6 = widget_label(base,value='Fourier Time (ns)',/align_left);,xsize=95)
    tauTempBase = widget_base(base,/row,/KBRD_FOCUS_EVENTS,$;/context_events,$  ;CONTEXT EVENTS HERE RUIN X11 VERSION!!!
                                    uname='DROPTIMEBASE',$
                                    uvalue={object:self,$
                                            method:'dropTimeEvents',$
                                            id:'DROPTIMEBASE'})

;020105
;
;THIS CONTEXT BASE DOES NOT WORK PROPERLY.  FOR SOME REASON SUB-BUTTONS
;ARE NOT DESTROYED WITH A CALL TO widget_control,id,/destroy, SO I
;END UP WITH A HUGE NUMBER OF BUTTONS FLOATING AROUND AFTER A COUPLE CALLS.
;
;;;    ;011005
;;;    ;SET UP BASE FOR CONTEXT MENU HERE AND POPULATE WITH BUTTONS WHEN CALLED.
;;;    ;i.e. IN THE METHOD dropTimeEvents
;;;    ;
;;;
;;;    contextBase = widget_base(tauTempBase,/context_menu,$
;;;                                    uname='DROPTIMEBASE',$
;;;                                    uvalue={object:self,$
;;;                                            method:'dropTimeEvents',$
;;;                                            id:'DROPTIMEBASE'})
;;;



    self.atl6 = widget_label(tauTempBase,$
                                value='Fourier Time (ns)',$
                                /align_left)

    self.rewbuttontau = widget_button(tauTempBase,$
                                    value = '|<',$
                                    ysize=buttonysize,$
                                    uvalue={object:self,$
                                            method:'buttonEvents',$
                                            id:'REWBUTTONTAU'})
    self.revbuttontau = widget_button(tauTempBase,$
                                    value = '<',$
                                    ysize=buttonysize,$
                                    uvalue={object:self,$
                                            method:'buttonEvents',$
                                            id:'REVBUTTONTAU'})


    ;UPDATE 040704
    tauVals = *((self.datacontainer->get(position=self.QChoiceIndex))->getProperty(tag='fourierTime'))
    ;print,tauVals
;    widget_control,self.adwTau,set_droplist_select=0
;    widget_control,self.adwTau,set_value=string(10.0^9*tauVals)


    self.adwTau = widget_droplist(tauTempBase,$
                                $;value=string(*self.ftChoices),$
                                value=strtrim(string(10.0^9*tauVals),2),$
                                $;title="Select Fourier Time Index",$
                                $;event_pro="displayEcho_droplistevent",$
                                xsize = 100,$
                                uname="DROPFT",$
                                uvalue={object:self,method:'droplistEvents',id:'DROPFT'});uvalue='DROPFT',$

    self.fwdbuttontau = widget_button(tauTempBase,$
                                        value = '>',$
                                        ysize=buttonysize,$
                                        uvalue={object:self,$
                                                method:'buttonEvents',$
                                                id:'FWDBUTTONTAU'})
    self.ffwdbuttontau = widget_button(tauTempBase,$
                                        value = '>|',$
                                        ysize=buttonysize,$
                                        uvalue={object:self,$
                                                method:'buttonEvents',$
                                                id:'FFWDBUTTONTAU'})

;    self.PLOTMASKZOOMBUTTON = widget_button(tauTempBase,$
;                                        value = 'Plot Masking',$
;                                        ysize=buttonysize,$
;                                        uvalue={object:self,$
;                                                method:'buttonEvents',$
;                                                id:'PLOTMASKZOOMBUTTON',$
;                                                options:['Plot Masking','Plot Zooming']})

;120105
;NOT NEEDED SINCE IT IS IN THE CONTEXT MENU.
;
;    self.PLOTUNZOOMBUTTON = widget_button(tauTempBase,$
;                                        value = 'Unzoom Plot',$
;                                        ysize=buttonysize,$
;                                        uvalue={object:self,$
;                                                method:'buttonEvents',$
;                                                id:'PLOTUNZOOMBUTTON',$
;                                                options:['Plot Masking','Plot Zooming']})


end;defineCDControls
pro ooDisplayEcho::defineMaskButton
;
;NAME:
;        ooDisplayEcho::defineMaskButton
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    buttonysize=20

    ;self.tlb1a2 IS THE GENERAL PROPERTIES TAB.
    ;self.tlb1a3 IS THE SAMPLE PROPERTIES TAB.


    self.maskButton = widget_button(self.tlb1a3,$
                                    value = 'Alter Mask',$
                                    ysize=buttonysize,$
                                    uvalue={object:self,$
                                            method:'buttonEvents',$
                                            id:'MASKBUTTON'})

    maskButtonApply = widget_button(self.tlb1a3,$
                                    value = 'Apply Mask to All Fourier Times',$
                                    ysize=buttonysize,$
                                    uvalue={object:self,$
                                            method:'buttonEvents',$
                                            id:'MASKBUTTONAPPLY'})

end;defineMaskButton
pro ooDisplayEcho::defineFitWidgets,plotxsize=plotxsize,plotysize=plotysize
;
;NAME:
;        ooDisplayEcho::defineFitWidgets
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.



    ;092104
    ;
    ;NEED TO ALTER LAYOUT TO FIT EVERYTHING FOR MAC X11 WINDOW!!!


;092404
;ADD subbase TO THE UPCOMING self.thetabs

    ;CREATE NEW BASE LAYOUT TO ACCOMODATE THE BUTTONS AND FIELDS.
    subbase = widget_base(self.tlb1b,/col)
    leftbase = widget_base(subbase,/col) ;PUT ALL ACTION BUTTONS HERE.
    rightbase = widget_base(subbase,/col);PUT FIT PARAMETERS HERE.





    ;;
    ;TEXT AND BUTTON WIDGETS FOR FIT PARAMETERS AND LIMITS
    ;;;


    buttonysize = 20

;    self.phaseImportButton = widget_button(self.tlb1b,$
;                                            $;value = 'Import Phases AND FIT ALL TAU',$

;    self.phaseImportButton = widget_button(leftbase,$
;                                            $;value = 'Import Phases AND FIT ALL TAU',$
;                                            value = 'IMPORT PHASES and FIT',$
;                                            ysize=buttonysize,$
;                                            uvalue={object:self,$
;                                                    method:'buttonEvents',$
;                                                    id:'PHASEIMPORTBUTTON'})



    ;THE EVENT HANDLER FOR THIS BUTTON SHOULD
    ;   1) POP UP A WINDOW WITH AVAILABLE FILES WITH THE SAME
    ;      Q, no_of_fourier_times, x_dim, y_dim  (use info = dataObj->matchInfo())
    ;   2) IF A PHASE ARRAY IS SELECTED:
    ;        SET self.fixed = [0,0,1,1,1,1] (CHECK FORM OF self.chirpFun)
    ;        AND UPDATE THE FIT WIDGETS
    ;   3) WHEN THE PHASE ARRAY IS SELECTED, THE PHASE VALUES
    ;      ARE SIMPLY REPLACED IN A STATEMENT LIKE
    ;      (*self.fitparms)[2,*,*] = dataObj->phaseArray()
    ;   4) THERE WILL BE A FITTING ROUTINE THAT FITS THE OFFSET
    ;      (P[5]) FOR THE CENTRAL PIXEL AND THEN FIXES THE VALUE
    ;      FOR THE ENTIRE ARRAY: (*self.fitparms)[2,*,*] = newOffset
    ;      THIS FIT SHOULD OCCUR AFTER THE OTHER PARAMETERS
    ;      ARE SET BY EARLIER FITS.  PERHAPS THERE SHOULD BE A
    ;      SEPARATE fitall ROUTINE IN THE DATA CLASS THAT GOES THROUGH
    ;      THE RIGHT STEPS.
    ;
    ;
    ;
    ;
    ;   AFTER THIS THERE MUST BE A CONVERT TO Q OPTION
    ;
    ;   AN EXPORT OPTION FOR FIT PARAMETERS (TO SAVE REDUCTION STATES)
    ;
    ;   AN EXPORT OPTION FOR S(Q,t)
    ;
    ;   A CALCULATE S(Q,t) OPTION THAT CHECKS ON LAMBDA, XCEN, YCEN,
    ;   AND KNOWS DETECTOR SIZE AND SAMPLE-TO-DETECTOR DISTANCE
    ;   (CHECK NICK'S CODE FOR THIS)
    ;
    ;




    options = ['arc','spiral','expand']
    fieldnames = ['t1','t2']
    self.fitselector = cwo_pickmethod(leftbase,options,fieldnames,$
                            ysize=30,$
                            obj_ref=the_pickmethod_obj_ref,frame=2,$
                            uvalue={object:self,$
                                    method:'buttonEvents',$
                                    id:'FITBUTTONALL'})

    self.fitselectorobj = the_pickmethod_obj_ref

;    tempButtonBase = widget_base(self.tlb1b,/row)
    tempButtonBase = widget_base(leftbase,/row)
    ;void = widget_label(tempButtonBase,value='Fit opts:')
    self.fitbutton1 = widget_button(tempButtonBase,$
                                    value = 'fit pixel',$;value = 'fit single pixel',$
                                    tooltip = 'Fit the echo at the selected pixel',$
                                    ysize=buttonysize,$
                                    uvalue={object:self,$
                                            method:'buttonEvents',$
                                            id:'FITBUTTON1'})
    self.fitbutton = widget_button(tempButtonBase,$
                                    $;value = 'Fit All Echoes (This Tau)',$
                                    value = 'smooth t',$;value = 'smooth phases (this t)',$
                                    tooltip = 'Fit all echoes at this Fourier time and "smooth" phases.',$
                                    ysize=buttonysize,$
                                    uvalue={object:self,$
                                            method:'buttonEvents',$
                                            id:'FITBUTTON'})


;110304
;
;REMOVING THE NEXT BUTTON SINCE IT IS NOW REDUNDANT
;DUE TO THE cwo_pickmethod WIDGET.
;
;
;    self.fitbuttonall = widget_button(tempButtonBase,$
;                                    $;value = 'Fit All Echoes (This Data File)',$
;                                    value = 'All',$
;                                    tooltip = 'Fit all echoes in this file)',$
;                                    ysize=buttonysize,$
;                                    uvalue={object:self,$
;                                            method:'buttonEvents',$
;                                            id:'FITBUTTONALL'})
;    self.fitbuttonallQ = widget_button(tempButtonBase,$
;                                    value = 'Fit All Data',$
;                                    uvalue={object:self,$
;                                            method:'buttonEvents',$
;                                            id:'FITBUTTONALLQ'})

;    tempButtonBase2 = widget_base(self.tlb1b,/row)

    tempButtonBase2 = widget_base(leftbase,/row)



;120604
;
;REMOVE NEXT TWO BUTTONS FOR NOW.
;121404 Dobrin wants these.
;    self.fitbuttonallminus360 = widget_button(tempButtonBase2,$
    self.fitbuttonallminus360 = widget_button(tempButtonBase,$
                                    value = '-360 refit',$
                                    tooltip = 'Shift all phases -360deg and refit',$
                                    ysize=buttonysize,$
                                    uvalue={object:self,$
                                            method:'buttonEvents',$
                                            id:'FITBUTTONALLMINUS360'})
;    self.fitbuttonallplus360 = widget_button(tempButtonBase2,$
    self.fitbuttonallplus360 = widget_button(tempButtonBase,$
                                    value = '+360 refit',$
                                    tooltip = 'Shift all phases +360deg and refit',$
                                    ysize=buttonysize,$
                                    uvalue={object:self,$
                                            method:'buttonEvents',$
                                            id:'FITBUTTONALLPLUS360'})

    self.phaseImportButton = widget_button(leftbase,$
                                            $;value = 'Import Phases AND FIT ALL TAU',$
                                            value = 'IMPORT PHASES',$
                                            tooltip = 'Fit all echoes using phases from another data set',$
                                            ysize=buttonysize,$
                                            uvalue={object:self,$
                                                    method:'buttonEvents',$
                                                    id:'PHASEIMPORTBUTTON'})

;    options = ['arc','spiral','expand']
;    fieldnames = ['t1','t2']
;    self.fitselector = cwo_pickmethod(leftbase,options,fieldnames,$
;                            obj_ref=the_pickmethod_obj_ref,frame=2,$
;                            uvalue={object:self,$
;                                    method:'buttonEvents',$
;                                    id:'FITBUTTONALL'})
    restoreBut = widget_button(leftbase,value='Restore Previous Fitparms',$
                                            tooltip = 'Restore fit parameters to the values just before the most recent action.',$
                                            uvalue={object:self,$
                                                    method:'buttonEvents',$
                                                    id:'FITPARMRESTOREBUTTON'})

    widget_control,self.fitselector,set_uvalue={object:self,$
                                    method:'buttonEvents',$
                                    id:'FITBUTTONALL'}




    ;THIS NEEDS TO BE VARIABLE AND PASSABLE TO THE FITTING ROUTINE

;021306
;    fixvary = ['vary','fix']

    self.fixed = [0,0,0,1,1,1]

    if !version.os ne 'Win32' then begin
        fixvary = ['v this pix this t','v this pix all t',$
                   'v all pix this t','v all pix all t',$
                   'f this pix this t','f this pix all t',$
                   'f all pix this t','f all pix all t',$
                   'f all to C Vals']
        atl1atext ='Fit/Start Parameters: f=fix, v=vary, C = current'
    endif else begin
        fixvary = ['vary this pixel this t','vary this pixel all t',$
                   'vary all pixel this t','vary all pixel all t',$
                   'fix this pixel this t','fix this pixel all t',$
                   'fix all pixel this t','fix all pixel all t',$
                   'fix all to Current Vals']
        atl1atext ='Fit/Start Parameters: '
    endelse




    tempBase = widget_base(rightbase,/row)
    self.atl1a = widget_label(tempBase,value=atl1atext)
    ;self.atl1a = widget_label(tempBase,value='Parameter Limits')
    ;CONSTANT FIT PARAMETER
;    self.constbase = widget_base(self.tlb1b,/row)
    self.constbase = widget_base(rightbase,/row)
    self.dropfixconst = widget_droplist(self.constbase,$
                                value=fixvary,$
                                uname="DROPFIXCONST",$
                                uvalue={object:self,$
                                        method:'droplistEvents',$
                                        id:'DROPFIXCONST'})
    widget_control,self.dropfixconst,set_droplist_select=0;self.fixed[0]

    twxsize = 8

;    void = widget_label(self.constbase,value='AVERAGE',xsize = 70)
    void = widget_button(self.constbase,value='Av',$;'P0',$
                            xsize = 20,$
                            tooltip='AVERAGE')
    self.atwconst = widget_text(self.constbase,/editable,$
                                value=strtrim(string((self.startparms)[0]),2),$
                                uname='ATWCONST',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWCONST'})
    void = widget_label(self.constbase,value='�')
    self.atweconst = widget_text(self.constbase,$
                                value='0.0',$
                                uname='ATWECONST',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWECONST'})


    ;AMPLITUDE FIT PARAMETER
;    self.ampbase = widget_base(self.tlb1b,/row)
    self.ampbase = widget_base(rightbase,/row)
;    self.dropfixAmpPcheck = cw_bgroup(self.ampbase)
    self.dropfixamp = widget_droplist(self.ampbase,$
                                value=fixvary,$
                                uname="DROPFIXAMP",$
                                uvalue={object:self,$
                                        method:'droplistEvents',$
                                        id:'DROPFIXAMP'})
    widget_control,self.dropfixamp,set_droplist_select=0;self.fixed[1]

;    void = widget_label(self.ampbase,value='AMPLITUDE',xsize = 70)
    void = widget_button(self.ampbase,value='A',$;'P1',$
                xsize = 20,$
                tooltip='AMPLITUDE')
    self.atwamp = widget_text(self.ampbase,/editable,$
                                value=strtrim(string((self.startparms)[1]),2),$
                                uname='ATWAMP',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWAMP'})
    void = widget_label(self.ampbase,value='�')
    self.atweamp = widget_text(self.ampbase,$
                                value='0.0',$
                                uname='ATWEAMP',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWEAMP'})

    ;PHASEo FIT PARAMETER
;    self.phaseobase = widget_base(self.tlb1b,/row)
    self.phaseobase = widget_base(rightbase,/row)
    self.dropfixphaseo = widget_droplist(self.phaseobase,$
                                value=fixvary,$
                                uname="DROPFIXPHASEO",$
                                uvalue={object:self,$
                                        method:'droplistEvents',$
                                        id:'DROPFIXPHASEO'})
    widget_control,self.dropfixphaseo,set_droplist_select=0;self.fixed[2]

;    void = widget_label(self.phaseobase,value='PHASEo',xsize = 70)
    void = widget_button(self.phaseobase,value='PH',$;'P2',$
                        xsize = 20,$
                        tooltip='PHASE')
    self.atwphaseo = widget_text(self.phaseobase,/editable,$
                                value=strtrim(string((self.startparms)[2]),2),$
                                uname='ATWPHASEO',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWPHASEO'})
    void = widget_label(self.phaseobase,value='�')
    self.atwephaseo = widget_text(self.phaseobase,$
                                value='0.0',$
                                uname='ATWEPHASEO',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWEPHASEO'})


;
;092204
;
;THESE NEXT THREE SHOULD BE PLACED BENEATH THE PLOTS FOR NOW.
;
;IS THIS METHOD RUN BEFORE OR AFTER THE DRAW WIDGETS ARE
;CREATED???  IT MUST BE RUN AFTER FOR THIS TO WORK.
;
;SET THEM UNDER self.tlb2

;092404
;
;IMPLEMENTING TAB WIDGETS.  PLACE ALL FIT WIDGETS ON THE
;rightbase SO THAT THEY SHOW UP ON THE TABS.
;

    ;SIGMA FIT PARAMETER
;    self.sigmabase = widget_base(self.tlb1b,/row)


    self.sigmabase = widget_base(rightbase,/row)
;    self.sigmabase = widget_base(self.tlb2,/row)
    self.dropfixsigma = widget_droplist(self.sigmabase,$
                                value=fixvary,$
                                uname="DROPFIXSIGMA",$
                                uvalue={object:self,$
                                        method:'droplistEvents',$
                                        id:'DROPFIXSIGMA'})

    widget_control,self.dropfixsigma,set_droplist_select=4;self.fixed[3]
;    void = widget_label(self.sigmabase,value='SIGMA',xsize = 70)
;    void = widget_label(self.sigmabase,value='WIDTH',xsize = 70)
    void = widget_button(self.sigmabase,value='W',$;'P3',$
                            xsize = 20,$
                            tooltip='GAUSSIAN WIDTH')
    self.atwsigma = widget_text(self.sigmabase,$
                                value=strtrim(string((self.startparms)[3]),2),$
                                uname='ATWSIGMA',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWSIGMA'})
    void = widget_label(self.sigmabase,value='�')
    self.atwesigma = widget_text(self.sigmabase,$
                                value='0.0',$
                                uname='ATWESIGMA',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWESIGMA'})

    ;OMEGA FIT PARAMETER
;    self.omegabase = widget_base(self.tlb1b,/row)
    self.omegabase = widget_base(rightbase,/row)
;    self.omegabase = widget_base(self.tlb2,/row)
    self.dropfixomega = widget_droplist(self.omegabase,$
                                value=fixvary,$
                                uname="DROPFIXOMEGA",$
                                uvalue={object:self,$
                                        method:'droplistEvents',$
                                        id:'DROPFIXOMEGA'})
    widget_control,self.dropfixomega,set_droplist_select=0;self.fixed[4]

;    void = widget_label(self.omegabase,value='OMEGA',xsize = 70)
;    void = widget_label(self.omegabase,value='360/period',xsize = 70)
;    void = widget_label(self.omegabase,value='P4',xsize = 15,tooltip = 'omega = 360deg/period')


;120904
;
;SO NOT TO BREAK ANY OF THE ooEcho CODE, I WILL CONVERT THIS
;TO DISPLAY THE PERIOD VALUE HERE, BUT I WILL REVERSE-ENGINEER
;ALL THE OTHER PLACES IN ooDisplayEcho TO AGREE WITH THIS.
;
;    void = widget_button(self.omegabase,value='P4',xsize = 20,$
;                    tooltip = 'OMEGA = 360deg/(ECHO PERIOD)')
;    self.atwomega = widget_text(self.omegabase,$
;                                value=strtrim(string((self.startparms)[4]),2),$
;                                uname='ATWOMEGA',xsize = 12,$
;                                uvalue={object: self,$
;                                                method:'textEvents',$
;                                                id:'ATWOMEGA'})
    void = widget_button(self.omegabase,value='T',$;'P4',$
                    xsize = 20,$
                    tooltip = 'ECHO PERIOD')
    self.atwomega = widget_text(self.omegabase,$
                                value=strtrim(string((360.0/self.startparms)[4]),2),$
                                uname='ATWOMEGA',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWOMEGA'})
    void = widget_label(self.omegabase,value='�')
    self.atweomega = widget_text(self.omegabase,$
                                value='0.0',$
                                uname='ATWEOMEGA',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWEOMEGA'})

    ;PHASE FIT PARAMETER
;    self.phasebase = widget_base(self.tlb1b,/row)
;    self.phasebase = widget_base(rightbase,/row)


;033005
;MAKE THIS STILL EXIST TO KEEP METHODS DEPENDENT ON IT FROM
;CRASHING, BUT MAKE IT DISAPPEAR
    self.phasebase = widget_base(group_leader = self.atlb,/row)


;    self.phasebase = widget_base(self.tlb2,/row)
    self.dropfixphase = widget_droplist(self.phasebase,$
                                value=fixvary,$
                                uname="DROPFIXPHASE",$
                                uvalue={object:self,$
                                        method:'droplistEvents',$
                                        id:'DROPFIXPHASE'})
    widget_control,self.dropfixphase,set_droplist_select=4;self.fixed[5]

;    void = widget_label(self.phasebase,value='PHASE',xsize = 70)
;    void = widget_label(self.phasebase,value='PHASE OFFSET',xsize = 70)
    void = widget_button(self.phasebase,value='OS',$;'P5',$
                        xsize = 20,$
                        tooltip = 'PHASE OFFSET')
    self.atwphase = widget_text(self.phasebase,$
                                value=strtrim(string((self.startparms)[5]),2),$
                                uname='ATWPHASE',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWPHASE'})
    void = widget_label(self.phasebase,value='�')
    self.atwephase = widget_text(self.phasebase,$
                                value='0.0',$
                                uname='ATWEPHASE',xsize = twxsize,$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWEPHASE'})


    self.atwchisq = cw_field(rightbase,title='chi squared',$
                                xsize=twxsize,/row,$
                                /noedit,value='Nan',$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWCHISQ'})


    self.atwratio = cw_field(rightbase,title='A/(fon-foff)',$
                                xsize=twxsize,/row,$
                                /noedit,value='1.0',$
                                uvalue={object: self,$
                                                method:'textEvents',$
                                                id:'ATWRATIO'})


;092104
;    void = widget_label(self.tlb1b,$
;    void = widget_label(rightbase,$
;            value='I = B ')

;    void = widget_label(rightbase,$
;            value='I = B - A*exp(-1.0*((phase - phaseo+offset)/(2.0*sigma))^2)')


eqn1 = 'I=Av-Aexp(-(((phase-PH)/W)^2)/2)*'
eqn2 = 'cos((360/T)*(phase-PH))'



;033005
;REMOVE MENTION OF P5
    void = widget_label(rightbase,$
            value=eqn1)
    void = widget_label(rightbase,$
            value=eqn2)

;    void = widget_label(rightbase,$
;            value='I = P0 ')
;
;    void = widget_label(rightbase,$
;            value=' - P1*exp(-1.0*((phase - P2)/(2.0*P3))^2)')
;
;    void = widget_label(rightbase,$
;            value='*cos((360/P4)*(phase-P2))')

;;    void = widget_label(rightbase,$
;;            value=' - P1*exp(-1.0*((phase - P2+P5)/(2.0*P3))^2)')
;;
;;    void = widget_label(rightbase,$
;;            value='*cos((360/P4)*(phase-P2+P5))')
;;;            value='y = const - amp*exp(-1.0*((X - phaseo)/(2.0*sigma))^2)'$
;;;                    +'*cos(omega*(X+phaseo+phase))')

    ;;
    ;LIMITS WIDGETS
    ;;;
;;;;;    void = widget_label(self.tlb1b,value='PARAMETER LIMITS')
;;;;;    limorno = ['unlimited','limited']
    self.limited = [0,0,0,0,0,0]
    self.maskBase = 0L

;;;;;    ;CONSTANT FIT PARAMETER LIMITS
;;;;;    self.limconstbase = widget_base(self.tlb1b,/row)
;;;;;    self.droplimitconst = widget_droplist(self.limconstbase,$
;;;;;                                value=limorno,$
;;;;;                                uname="DROPLIMITCONST",$
;;;;;                                uvalue={object:self,$
;;;;;                                        method:'droplistEvents',$
;;;;;                                        id:'DROPLIMITCONST'})
;;;;;    widget_control,self.droplimitconst,set_droplist_select=self.limited[0]
;;;;;    void = widget_label(self.limconstbase,value='CONST LIMS',xsize = 90)
;;;;;    ;void = widget_label(self.constbase,value='CONST LIMS',xsize = 90)
;;;;;    self.atwminlimconst = widget_text(self.limconstbase,$
;;;;;    $;self.atwminlimconst = widget_text(self.constbase,$
;;;;;                                editable = self.limited[0],$
;;;;;                                value='1.0',$
;;;;;                                uname='ATWMINLIMCONST',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMINLIMCONST'})
;;;;;    void = widget_label(self.limconstbase,value='->')
;;;;;    ;void = widget_label(self.constbase,value='->')
;;;;;    self.atwmaxlimconst = widget_text(self.limconstbase,$
;;;;;    $;self.atwmaxlimconst = widget_text(self.constbase,$
;;;;;                                editable = self.limited[0],$
;;;;;                                value='5000.0',$
;;;;;                                uname='ATWMAXLIMCONST',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMAXLIMCONST'})
;;;;;
;;;;;    ;AMPLITUDE FIT PARAMETER LIMITS
;;;;;    self.limampbase = widget_base(self.tlb1b,/row)
;;;;;    self.droplimitamp = widget_droplist(self.limampbase,$
;;;;;                                value=limorno,$
;;;;;                                uname="DROPLIMITAMP",$
;;;;;                                uvalue={object:self,$
;;;;;                                        method:'droplistEvents',$
;;;;;                                        id:'DROPLIMITAMP'})
;;;;;    widget_control,self.droplimitamp,set_droplist_select=self.limited[1]
;;;;;    void = widget_label(self.limampbase,value='AMPLITUDE LIMS',xsize = 90)
;;;;;    self.atwminlimamp = widget_text(self.limampbase,$
;;;;;                                editable = self.limited[1],$
;;;;;                                value='10.0',$
;;;;;                                uname='ATWMINLIMAMP',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMINLIMAMP'})
;;;;;    void = widget_label(self.limampbase,value='->')
;;;;;    self.atwmaxlimamp = widget_text(self.limampbase,$
;;;;;                                editable = self.limited[1],$
;;;;;                                value='20000.0',$
;;;;;                                uname='ATWMAXLIMAMP',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMAXLIMAMP'})
;;;;;
;;;;;    ;PHASEO FIT PARAMETER LIMITS
;;;;;    self.limphaseobase = widget_base(self.tlb1b,/row)
;;;;;    self.droplimitphaseo = widget_droplist(self.limphaseobase,$
;;;;;                                value=limorno,$
;;;;;                                uname="DROPLIMITPHASEO",$
;;;;;                                uvalue={object:self,$
;;;;;                                        method:'droplistEvents',$
;;;;;                                        id:'DROPLIMITPHASEO'})
;;;;;    widget_control,self.droplimitphaseo,set_droplist_select=self.limited[2]
;;;;;    void = widget_label(self.limphaseobase,value='PHASEO LIMS',xsize = 90)
;;;;;    self.atwminlimphaseo = widget_text(self.limphaseobase,$
;;;;;                                editable = self.limited[2],$
;;;;;                                value='-1999.0',$
;;;;;                                uname='ATWMINLIMPHASEO',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMINLIMPHASEO'})
;;;;;    void = widget_label(self.limphaseobase,value='->')
;;;;;    self.atwmaxlimphaseo = widget_text(self.limphaseobase,$
;;;;;                                editable = self.limited[2],$
;;;;;                                value='2000.0',$
;;;;;                                uname='ATWMAXLIMPHASEO',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMAXLIMPHASEO'})
;;;;;
;;;;;    ;SIGMA FIT PARAMETER LIMITS
;;;;;    self.limsigmabase = widget_base(self.tlb1b,/row)
;;;;;    self.droplimitsigma = widget_droplist(self.limsigmabase,$
;;;;;                                value=limorno,$
;;;;;                                uname="DROPLIMITASIGMA",$
;;;;;                                uvalue={object:self,$
;;;;;                                        method:'droplistEvents',$
;;;;;                                        id:'DROPLIMITSIGMA'})
;;;;;    widget_control,self.droplimitsigma,set_droplist_select=self.limited[3]
;;;;;    void = widget_label(self.limsigmabase,value='SIGMA LIMS',xsize = 90)
;;;;;    self.atwminlimsigma = widget_text(self.limsigmabase,$
;;;;;                                editable = self.limited[3],$
;;;;;                                value='10.0',$
;;;;;                                uname='ATWMINLIMSIGMA',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMINLIMSIGMA'})
;;;;;    void = widget_label(self.limsigmabase,value='->')
;;;;;    self.atwmaxlimsigma = widget_text(self.limsigmabase,$
;;;;;                                editable = self.limited[3],$
;;;;;                                value='20000.0',$
;;;;;                                uname='ATWMAXLIMSIGMA',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMAXLIMSIGMA'})
;;;;;
;;;;;    ;OMEGA FIT PARAMETER LIMITS
;;;;;    self.limomegabase = widget_base(self.tlb1b,/row)
;;;;;    self.droplimitomega = widget_droplist(self.limomegabase,$
;;;;;                                value=limorno,$
;;;;;                                uname="DROPLIMITOMEGA",$
;;;;;                                uvalue={object:self,$
;;;;;                                        method:'droplistEvents',$
;;;;;                                        id:'DROPLIMITOMEGA'})
;;;;;    widget_control,self.droplimitomega,set_droplist_select=self.limited[4]
;;;;;    void = widget_label(self.limomegabase,value='OMEGA LIMS',xsize = 90)
;;;;;    self.atwminlimomega = widget_text(self.limomegabase,$
;;;;;                                editable = self.limited[4],$
;;;;;                                value='0.5',$
;;;;;                                uname='ATWMINLIMOMEGA',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMINLIMOMEGA'})
;;;;;    void = widget_label(self.limomegabase,value='->')
;;;;;    self.atwmaxlimomega = widget_text(self.limomegabase,$
;;;;;                                editable = self.limited[4],$
;;;;;                                value='10.0',$
;;;;;                                uname='ATWMAXLIMOMEGA',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMAXLIMOMEGA'})
;;;;;
;;;;;    ;PHASE FIT PARAMETER LIMITS
;;;;;    self.limphasebase = widget_base(self.tlb1b,/row)
;;;;;    self.droplimitphase = widget_droplist(self.limphasebase,$
;;;;;                                value=limorno,$
;;;;;                                uname="DROPLIMITPHASE",$
;;;;;                                uvalue={object:self,$
;;;;;                                        method:'droplistEvents',$
;;;;;                                        id:'DROPLIMITPHASE'})
;;;;;    widget_control,self.droplimitphase,set_droplist_select=self.limited[5]
;;;;;    void = widget_label(self.limphasebase,value='PHASE LIMS',xsize = 90)
;;;;;    self.atwminlimphase = widget_text(self.limphasebase,$
;;;;;                                editable = self.limited[5],$
;;;;;                                value='-1999.0',$
;;;;;                                uname='ATWMINLIMPHASE',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMINLIMPHASE'})
;;;;;    void = widget_label(self.limphasebase,value='->')
;;;;;    self.atwmaxlimphase = widget_text(self.limphasebase,$
;;;;;                                editable = self.limited[5],$
;;;;;                                value='2000.0',$
;;;;;                                uname='ATWMAXLIMPHASE',xsize = 7,$
;;;;;                                uvalue={object: self,$
;;;;;                                                method:'textEvents',$
;;;;;                                                id:'ATWMAXLIMPHASE'})

end;defineFitWidgets
function ooDisplayEcho::icon,reduced,type
;
;NAME:
;        ooDisplayEcho::icon
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

;RETURN VALUE:
;

    i = intarr(16,16,3)

    if reduced ne 0 then begin
        i[*,*,0] = 0
        i[*,*,1] = 255
        i[*,*,2] = 0
    endif else begin
        i[*,*,0] = 255
        i[*,*,1] = 0
        i[*,*,2] = 0
    endelse

    case type of
    0:  begin       ;UNTYPED
        i[4:11,4:11,0] = 0
        i[4:11,4:11,1] = 0
        i[4:11,4:11,2] = 0
    end
    1:  begin       ;RESOLUTION
        i[4:11,4:11,0] = 255
        i[4:11,4:11,1] = 0
        i[4:11,4:11,2] = 0
    end
    2:  begin       ;DATA
        i[4:11,4:11,0] = 0
        i[4:11,4:11,1] = 255
        i[4:11,4:11,2] = 0
    end
    3:  begin       ;BACKGROUND
        i[4:11,4:11,0] = 0
        i[4:11,4:11,1] = 0
        i[4:11,4:11,2] = 255
    end
    endcase

    return,i
end;icon
pro ooDisplayEcho::createFTWLeaf,wid_id,parent,pos,element
;
;NAME:
;        ooDisplayEcho::createFTWLeaf
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    ;CREATE THE BOTTOM-MOST LEAVES ON THE DATA TREE

    ;print,'COUNT=',(self.dataContainer)->count()
    ;print,'POS  =',pos
    if pos lt (self.dataContainer)->count() then begin
        theRef = self.dataContainer->get(position=pos)
        comment = theRef->getProperty(tag='comment')
        filename =  file_basename(theRef->getProperty(tag='filename'))
        type =  theRef->getProperty(tag='type')
        reduced =  theRef->getProperty(tag='reduced')
        wid_id = widget_tree(parent,value=filename+': '+comment,$
                                        group_leader=parent,$
                                        bitmap = self->icon(reduced,type),$
                                        uvalue={object:self,$
                                                method:'treeEvents',$
                                                id:'FTW',$
                                                element:element,$
                                                index:pos})

    endif;pos
        ;ARE group_leader OR element USED FOR ANYTHING?
        ;IN DESTROYING SETS, HAVING A GROUP LEADER AS THE
        ;PARENT INSTEAD OF THE TOP Q VALUE COULD CAUSE
        ;A DATA OBJECT TO BE ACCIDENTALLY DESTROYED IF A
        ;SET IS DELETED.

end;createFTWLeaf
pro ooDisplayEcho::fillSet,theRef,parent,wid_id,pos
;
;NAME:
;        ooDisplayEcho::fillSet
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    ;FILL THE SET OBJECT INDICATED BY theRef WHICH HAS
    ;A LEAF WITH ID=parent.  pos AND wid_id CORRESPOND TO
    ;THE POSITION IN THE dataContainer AND THE ID OF
    ;THE RESULTING LEAF.

;    if ptr_valid(self.setMembers) gt 0 then begin


;
;
;WHY DOES THIS PROCEDURE CAUSE AN INFINITE LOOP ONCE A
;SET LEAF IS ALREADY CREATED????????????????
;
;IT WAS AN ISSUE WITH THE pos PARAMETER

    if n_elements(*self.setMembers) gt 0 then begin
        temp = *self.setMembers
        ;print,temp
        ;d=dialog_message('wait')
        ptr_free,self.setMembers
    endif else begin
        temp = [-1]
    endelse
    if (theRef->getProperty(/resIndex) ne -1) then begin
        objpos = theRef->getProperty(/resIndex)
        temp = [temp,objpos]
        self->createFTWLeaf,wid_id,parent,objpos,objpos
    endif;resIndex
    if (theRef->getProperty(/datIndex) ne -1) then begin
        objpos = theRef->getProperty(/datIndex)
        temp = [temp,objpos]
        self->createFTWLeaf,wid_id,parent,objpos,objpos
    endif;datIndex
    if (theRef->getProperty(/bkgIndex) ne -1) then begin
        objpos = theRef->getProperty(/bkgIndex)
        temp = [temp,objpos]
        self->createFTWLeaf,wid_id,parent,objpos,objpos
    endif;bkgIndex
    ;print,temp
    self.setMembers = ptr_new(temp)
    ;print,*self.setMembers

end;fillSet

pro ooDisplayEcho::redefineTree
;
;NAME:
;        ooDisplayEcho::redefineTree
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    ;CREATE TREE OF DATA FILES IN TREE UNDER
    ;ASSOCIATED Q VALUES

    ;DETERMINE WHICH Q FOLDERS ARE EXPANDED AND
    ;SAVE THEIR STATES FOR REINSTATEMENT ON
    ;REPRODUCTION OF THE TREE.

    ;
    ;ALSO NEED TO LOOK INTO SETS.  PERHAPS THE SETS
    ;SHOULD SIMPLY REFER TO THE POSITION NUMBERS IN THE
    ;self.dataContainer RATHER THAN CONTAINING THEIR OWN
    ;SEPARATE COPIES.  self.dataContainer COULD CONTAIN
    ;ALL OF THE DATA OBJECTS AND
    ;
    ;THE set OBJECTS WILL REFER TO THE POSITIONS OF THE
    ;DATA OBJECTS.
    ;



    if self.QChoiceIndex ge self.datacontainer->count() then $
        self.QChoiceIndex = self.datacontainer->count()-1
    if self.QChoiceIndex lt 0 then self.QChoiceIndex = 0

    self.state_saved = 0

    qinfo = {expandedVal:1,qval:0.0D}
    expVals = intarr(n_elements(*self.qtw))+1

    ;GET THE VALUES FROM THE uvalue STRUCTURE
    values = dblarr(n_elements(*self.qtw))

    ;DETERMINE THE EXPANSION STATES OF THE Q FOLDERS
    for i=0,n_elements(*self.qtw)-1 do begin
        if (*self.qtw)[0] ne -1 then begin
            expvals[i] = widget_info((*self.qtw)[i],/tree_expanded)
            widget_control,(*self.qtw)[i],get_uvalue=uval
            values[i] = uval.qvalue
        endif
    endfor;i


    ;DESTROY CURRENT TREE
    widget_control,self.ftree,/destroy


    ;CREATE NEW TREE
    self.ftree = widget_tree(self.tlb1a1,/align_left,/sensitive,$;tab_mode=1,$
                            /context_events,$
                            multiple=1,$
                            uname='FTREE',$
                            xsize = self.filetreexsize,$
                            ysize = self.filetreeysize,$
                            $;ysize = (self.plotysize),$
                            $;              xsize=fix((3*self.plotxsize)/8),$
                            uvalue={object:self,$
                                    method:'treeEvents',$
                                    id:'FTREE',$
                                    element:0})


    widget_control,self.ftree,set_uvalue={object:self,$
                                    method:'treeEvents',$
                                    id:'FTREE',$
                                    element:0,$
                                    ContextBase_ID:0}


    ;GET NUMBER OF Obj'S FROM THE DATA CONTAINER
    nObj = self.dataContainer->count()

    ;GET THE Q VALUES FROM THE OBJECTS
    if nobj gt 0 then begin
        ;print,'______________________'
        ;print,'ooDisplayEcho::redefineTree'
        ;print,0,(self.dataContainer->get(position=0))->getProperty(tag='filename')
        qArr = (self.dataContainer->get(position=0))->getProperty(tag='q')
        for i=1,nObj-1 do begin
            ;print,i,(self.dataContainer->get(position=i))->getProperty(tag='filename')
            newQ =(self.dataContainer->get(position=i))->getProperty(tag='q')
            ;print,newQ
            qArr = [qArr,newQ]
        endfor;i


        ;GET SORTED INDICES FOR Q VALUES
        qArrSort = sort(qArr)

        ;CREATE SORTED Q ARRAY
        qArrOrdered = $
            (self.dataContainer->get(position=qArrSort[0]))->getProperty(tag='q')
        for i = 1,n_elements(qArr)-1 do begin
            qArrOrdered = [qArrOrdered,$
                (self.dataContainer->get(position=qArrSort[i]))->getProperty(tag='q')]
        endfor

        ;GET UNIQ INDICES FOR SORTED Q ARRAY
        ;uniq PRODUCES AN ARRAY OF THE _LAST_ INDEX OF EACH
        ;UNIQUE SECTION
        qArrUniq = uniq(qArrOrdered)

        qtw = lindgen(n_elements(qArrUniq))
        ftw = lindgen(n_elements(qArrOrdered))

        nsets =(self.setContainer)->count()
        if nsets gt 0 then stw = lindgen(nsets)

        ;CREATE ZEROTH Q WIDGET WITH SUBWIDGETS
        if where(values eq qArrOrdered[qArrUniq[0]]) ge 0 then begin
            ;print,expVals(where(values eq qArrOrdered[qArrUniq[0]]))
            expanded = expVals(where(values eq qArrOrdered[qArrUniq[0]]))
        endif else begin
            if (self.dataContainer)->count() gt 1 then begin
                expanded = 1
            endif else begin
                expanded = 1
            endelse
        endelse
        qtw[0] = widget_tree(self.ftree,/folder,expanded=expanded,$
                          value='Q = '+$
                                strtrim(string(qArrOrdered[qArrUniq[0]]),2),$
                          uvalue={object:self,$
                                  method:'treeEvents',$
                                  id:'QTW',$
                                  element:0,$
                                  qvalue:qArrOrdered[qArrUniq[0]]})

        ;CREATE AN ARRAY OF INDICES TO INDICATE WHICH
        ;MEMBERS OF THE DATA CONTAINER ARE ALREADY
        ;ASSIGNED TO SETS.
        ;
        ;THEN DO A SINGLE FOR LOOP TO PICK OUT THE ONES THAT
        ;BELONG TO SETS AND THE ONES THAT BELONG TO Q ONLY.

        ;051104
        ;CREATE SET TREE LEAVES AND SUBLEAVES

        if ptr_valid(self.setMembers) gt 0 then begin
            temp = *self.setMembers
            ptr_free,self.setMembers
            self.setMembers = ptr_new([-1])
        endif else begin
            temp = [-1]
            ptr_free,self.setMembers
            self.setMembers = ptr_new([-1])
        endelse


        ;CREATE AND FILL SETS FOR THE ZEROTH Q VALUE
        for j=0,self.setContainer->count()-1 do begin
            if ((self.setContainer->get(position=j))->getProperty(/q) $
                    eq qArrOrdered[qArrUniq[0]]) then begin

                theRef = (self.setContainer->get(position=j))
                theName = theRef->getProperty(/name)

                stw[j] = widget_tree(qtw[0],value=theName,/folder,$
                                            /expanded,$
                                            group_leader=qtw[0],$
                                            uvalue={object:self,$
                                                    method:'treeEvents',$
                                                    id:'STW',$
                                                    element:j,$
                                                    index:j})
                ;print,'pos=',pos
                self->fillSet,theRef,stw[j],wid_id,j;pos
                ;print,*self.setMembers
            endif;
        endfor;j


        ;ADD FILE TREE LEAVES FOR ALL DATA OBJECTS
        ;NOT ASSIGNED TO SETS
        ;
        ;print,'qArrUniq[0]',qArrUniq[0]
        for j=0,qArrUniq[0] do begin

            ;ooDisplayEcho::createFTWLeaf,wid_id,parent,pos,element

            ;CHECK THAT THIS OBJECT IS NOT ASSIGNED TO A SET
            matches = 0
            ;print,'HERE NOW!!!'
            ;print,'*self.setMembers=',*self.setMembers
            for ii=0,n_elements(*self.setMembers)-1 do begin
                ;print,j,'*self.setMembers=',*self.setMembers
                if j eq (*self.setMembers)[ii] then matches = matches + 1
                ;print,'matches =',matches
                ;print,'j=',j
                ;print,'(*self.setMembers)[ii]=',(*self.setMembers)[ii]
            endfor;ii

            ;CREATE A LEAF FOR THIS OBJECT IF IT IS NOT IN A SET
            if (matches eq 0) then begin
                self->createFTWLeaf,ftw[j],qtw[0],qArrSort[j],j
            endif;matches

        endfor;j

        ;CREATE OTHER Q WIDGETS WITH SUBWIDGETS
        for i = 1,n_elements(qArrUniq)-1 do begin
            ;GET PREVIOUS EXPANSION STATE OF Q FOLDERS
            if where(values eq qArrOrdered[qArrUniq[i]]) ge 0 then begin
                expanded = expVals(where(values eq qArrOrdered[qArrUniq[i]]))
            endif else begin
                expanded = 1
            endelse
            qtw[i] = widget_tree(self.ftree,$
                                value='Q = '+$
                                    strtrim(string(qArrOrdered[qArrUniq[i]]),2),$
                                /folder,expanded = expanded,$
                                uvalue={object:self,$
                                        method:'treeEvents',$
                                        id:'QTW',$
                                        element:i,$
                                        qvalue:qArrOrdered[qArrUniq[i]]})

            ;CREATE AND FILL SETS FOR THE Q VALUES
            for j=0,self.setContainer->count()-1 do begin
                if ((self.setContainer->get(position=j))->getProperty(/q) $
                        eq qArrOrdered[qArrUniq[i]]) then begin

                    theRef = (self.setContainer)->get(position= j)
                    theName = theRef->getProperty(/name)

                    stw[j] = widget_tree(qtw[i],value=theName,/folder,$
                                            /expanded,$
                                            group_leader=qtw[i],$
                                            uvalue={object:self,$
                                                    method:'treeEvents',$
                                                    id:'STW',$
                                                    element:j,$
                                                    index:j})

                    self->fillSet,theRef,stw[j],wid_id,j
                    ;print,'*self.setMembers=',*self.setMembers

                endif;
            endfor;j

            ;CREATE THE FILE TREE LEAVES
            ;print,'qArrUniq[i-1]',qArrUniq[i-1]
            for j=qArrUniq[i-1]+1,qArrUniq[i] do begin

                matches = 0
                ;print,'*self.setMembers=',*self.setMembers
                for ii=0,n_elements(*self.setMembers)-1 do begin
                    ;print,j,'*self.setMembers=',*self.setMembers
                    if j eq (*self.setMembers)[ii] then matches = matches + 1
                    ;print,j,(*self.setMembers)[ii]
                endfor;ii

                if (matches eq 0) then begin
                    self->createFTWLeaf,ftw[j],qtw[i],qArrSort[j],j
                endif;matches
            endfor;j
        endfor;i

        ;SET POINTERS TO THE WIDGET ID ARRAYS
        ;
        ; --- ARE THESE VALUES NECESSARY?????
        if ptr_valid(self.qtw) gt 0 then ptr_free,self.qtw
        self.qtw=ptr_new(qtw)
        if ptr_valid(self.ftw) gt 0 then ptr_free,self.ftw
        self.ftw=ptr_new(ftw)

    endif else begin    ;nObj gt 0
        ;DEFINE NECESSARY VALUES WITH NO ELEMENTS.
        qtw = [-1]
        if ptr_valid(self.qtw) gt 0 then ptr_free,self.qtw
        self.qtw=ptr_new(qtw)
        ftw = [-1]
        if ptr_valid(self.ftw) gt 0 then ptr_free,self.ftw
        self.ftw=ptr_new(ftw)

    endelse

end;redefineTree


pro oodisplayecho_contextmenudestroy,id
;
;NAME:
;        ooDisplayEcho_ontextmenudestroy
;
;PURPOSE:
;           Announce when a context menu is destroyed and provide a traceback
;           by crashing on print of a null pointer.
;
;           THIS IS USED FOR TESTING ONLY.
;
;PARAMETERS:
;
;KEYWORDS:
;

    ;ANNOUNCE WHEN A CONTEXT MENU DIES.

;    print,id
;    print,*p

end;oodisplayecho_contextmenudestroy

pro ooDisplayEcho::defineContextMenus
;
;NAME:
;        ooDisplayEcho::defineContextMenus
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    ;
    ;
    ;UPDATE THIS TO DEAL WITH THE CONCEPT OF SETS.
    ;
    ;

    contextBaseS = widget_base(self.atlb,/context_menu,uname='STW_MENU',/col)
    button1S = widget_button(contextBaseS,value='CALCULATE I(Q,t)',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'SETIQTCALC'})
    button2S = widget_button(contextBaseS,value='Change Name',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'SETCHANGENAME'})
    button3S = widget_button(contextBaseS,value='Remove Set',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'SETREMOVESET'})
;    button4S = widget_button(contextBaseS,value='Remove Object From Set',$
;                                        uvalue = {object:self,$
;                                                  method:'contextMenuEvents',$
;                                                  id:'SETREMOVEOBJECT'})
;    button5S = widget_button(contextBaseS,value='Change Q Value ',$
;                                        uvalue = {object:self,$
;                                                  method:'contextMenuEvents',$
;                                                  id:'SETSETQVALUE'})



;###########################################################################################
;022406
;
    contextBaseF_multi = WIDGET_BASE(self.atlb, /CONTEXT_MENU,uname='FTW_MULTI_MENU',$
                                     kill_notify='oodisplayecho_contextmenudestroy',/col)

    noInfoMulti = widget_button(contextBaseF_multi,value='Multi menu button',$
                                            uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'FTW_MULTI_MENU_BUTTON_1'})
    noInfoMulti = widget_button(contextBaseF_multi,value='see ooDisplayEcho::contextMenuEvents',$
                                            uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'FTW_MULTI_MENU_BUTTON_2'})
    noInfoMulti = widget_button(contextBaseF_multi,value='For event handling information.',$
                                            uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'FTW_MULTI_MENU_BUTTON_3'})

    noInfoMulti = widget_button(contextBaseF_multi,value='REMOVE SELECTED OBJECTS (IMPLEMENTED)',$
                                            uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'REMOVEMULTIPLEOBJ'})

    noInfoMulti = widget_button(contextBaseF_multi,value='SEND_IQTS_TO_PAN',$
                                            uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'SEND_IQTS_TO_PAN'})
    noInfoMulti = widget_button(contextBaseF_multi,value='FIT_ALL_SETS_WITH_SAME_RESOLUTION',$
                                            uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'FIT_ALL_SETS_WITH_SAME_RESOLUTION'})



;WANT TO ADD A MULTIPLE SELECTION CONTEXT MENU
;###########################################################################################


    contextBaseF = WIDGET_BASE(self.atlb, /CONTEXT_MENU,uname='FTW_MENU',kill_notify='oodisplayecho_contextmenudestroy',/col)
    setTypeButton = widget_button(contextBaseF,$
                                        value='Select data set type',/menu)

    button1F = WIDGET_BUTTON(setTypeButton,$;contextBaseF, $
                                        VALUE='Untyped',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'UNTYPED'})
    button2F = WIDGET_BUTTON(setTypeButton,$;contextBaseF, $
                                        VALUE='Resolution',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'RESOLUTION'})
    button3F = WIDGET_BUTTON(setTypeButton,$;contextBaseF, $
                                        VALUE='Sample',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'RAWDATA'})
    button4F = WIDGET_BUTTON(setTypeButton,$;contextBaseF, $
                                        VALUE='Cell',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'BACKGROUND'})
;050704
;111704
;
;COMMENT OUT A FEW OF THE NEXT BUTTONS FOR NOW
;UNTIL SETS AND MERGING ARE AVAILABLE AND DEBUGGED.

;061505
;;;;
;;;;    setOperationsButton = widget_button(contextBaseF,value='Set Operations',/menu)
;;;;
;;;;    button5F = WIDGET_BUTTON(setOperationsButton,$;contextBaseF, $
;;;;                                        VALUE='Assign Object to a Set',$
;;;;                                        sensitive=0,$
;;;;                                        uvalue = {object:self,$
;;;;                                                  method:'contextMenuEvents',$
;;;;                                                  id:'ASSIGNOBJ'})
;;;;
;;;;    button7F = WIDGET_BUTTON(setOperationsButton,$;contextBaseF, $
;;;;                                        VALUE='Create New Set',$
;;;;                                        sensitive=0,$
;;;;                                        uvalue = {object:self,$
;;;;                                                  method:'contextMenuEvents',$
;;;;                                                  id:'OBJNEWSET'})

    objOperationsButton = widget_button(contextBaseF,value='Object Operations',/menu)


    button6Fa = WIDGET_BUTTON(objOperationsButton,$;contextBaseF, $
                                        VALUE='Merge Objects',$
                                        sensitive=1,$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'MERGEOBJ'})

    button6F = WIDGET_BUTTON(objOperationsButton,$;contextBaseF, $
                                        VALUE='Remove Object',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'REMOVEOBJ'})

    button6F = WIDGET_BUTTON(objOperationsButton,$;contextBaseF, $
                                        VALUE='Duplicate Object',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'DUPLICATEOBJ'})


    file_button1 = widget_button(objOperationsButton,$;contextBaseF,$
                                value='Save Object',$
                                uname="SAVEOBJECT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'SAVEOBJECT',$
                                        parent:'FILEOPTIONS'})

    file_button1 = widget_button(objOperationsButton,$;contextBaseF,$
                                value='Restore Object',$
                                uname="RESTOREOBJECT",$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'RESTOREOBJECT',$
                                        parent:'FILEOPTIONS'})




    ;CHANGE THE NEXT BUTTON TO CALL A LIST WIDGET.
    button6Fb = WIDGET_BUTTON(contextBaseF, VALUE='Remove Fourier Times',$
                                        sensitive=1,menu=0,$;menu=1,$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'REMOVEFOURIERTIMEMENU'});,$
                                                  ;kill_notify='oodisplayecho_contextmenudestroy')


    self.removeFourierTimeMenu = button6Fb
    ;print,'oodisplayecho::defineContextMenus self.removeFourierTimeMenu='+string(self.removeFourierTimeMenu)


    ;ADD I(Q,t) CALCULATION BUTTONS TO THE CONTEXT MENUS
;    button8F = widget_button(contextBaseF,$
;                                value='Calculate Q Values',$
;                                uname='CALCULATEQS',$
;                                uvalue={object:self,$
;                                        method:'menuEvents',$
;                                        id:'CALCULATEQS',$
;                                        parent:'CALCULATIONOPTIONS'})


    button8Fit = widget_button(contextBaseF,$
                             $;value = 'Import Phases AND FIT ALL TAU',$
                             value = 'Fit Operations',/menu)
    button8F = widget_button(button8Fit,$;contextBaseF,$
                             $;value = 'Import Phases AND FIT ALL TAU',$
                             value = 'IMPORT PHASES (Sample,Cell)',$
                             $;tooltip = 'Fit all echoes using phases from another data set',$
                             $;ysize=buttonysize,$
                             uvalue={object:self,$
                             method:'buttonEvents',$
                             id:'PHASEIMPORTBUTTON'})
    button8F = widget_button(button8Fit,$;contextBaseF,$
                             $;value = 'Import Phases AND FIT ALL TAU',$
                             value = 'Fit Echoes (Resolution)',$
                             $;tooltip = 'Fit all echoes using phases from another data set',$
                             $;ysize=buttonysize,$
                             uvalue={object:self,$
                                     method:'buttonEvents',$
                                     id:'FITBUTTONALL'})

;    self.fitselector = cwo_pickmethod(leftbase,options,fieldnames,$
;                            ysize=30,$
;                            obj_ref=the_pickmethod_obj_ref,frame=2,$
;                            uvalue={object:self,$
;                                    method:'buttonEvents',$
;                                    id:'FITBUTTONALL'})





    button9F = widget_button(contextBaseF,$
                                value='Calculate I(Q,t)',$
                                uname='CALCULATEI',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'CALCULATEI',$
                                        parent:'CALCULATIONOPTIONS'})


    contextsaveutilities = widget_button(contextBaseF, VALUE='Save Utilities',$
                                        sensitive=1,menu=1,$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'SAVEUTILITIES'});,$

    button6Fb = WIDGET_BUTTON(contextsaveutilities, VALUE='Save Fit Parameters',$
                                        sensitive=1,menu=0,$;menu=1,$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'SAVEFITPARAMETERS'})
    button6Fb = WIDGET_BUTTON(contextsaveutilities, VALUE='Save Data Items',$
                                        sensitive=1,menu=0,$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'SAVEDATAITEMS'})








    contextBaseFS = WIDGET_BASE(self.atlb, /CONTEXT_MENU,uname='FTW_MENU_S',/col)
;    button1FS = WIDGET_BUTTON(contextBaseFS, VALUE='Untyped',$
;                                        uvalue = {object:self,$
;                                                  method:'contextMenuEvents',$
;                                                  id:'UNTYPED'})
    button2FS = WIDGET_BUTTON(contextBaseFS, VALUE='Resolution',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'RESOLUTION'})
    button3FS = WIDGET_BUTTON(contextBaseFS, VALUE='Sample',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'RAWDATA'})
    button4FS = WIDGET_BUTTON(contextBaseFS, VALUE='Background',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'BACKGROUND'})
    button5FS = WIDGET_BUTTON(contextBaseFS, VALUE='Assign Object to a Set',$
                                        sensitive=0,$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'ASSIGNOBJ'})
    button6FS = WIDGET_BUTTON(contextBaseFS, VALUE='Remove Object',$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'REMOVEOBJ'})
    button6FSa = WIDGET_BUTTON(contextBaseFS, VALUE='Merge Objects',$
                                        sensitive=0,$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'MERGEOBJ'})


    ;ADD I(Q,t) CALCULATION BUTTONS TO THE CONTEXT MENUS
    button7FS = widget_button(contextBaseFS,$
                                sensitive=0,$
                                value='Calculate Q Values',$
                                uname='CALCULATEQS',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'CALCULATEQS',$
                                        parent:'CALCULATIONOPTIONS'})
    button8FS = widget_button(contextBaseFS,$
                                value='Calculate I(Q,t)',$
                                uname='CALCULATEI',$
                                uvalue={object:self,$
                                        method:'menuEvents',$
                                        id:'CALCULATEI',$
                                        parent:'CALCULATIONOPTIONS'})


    contextBaseQ = WIDGET_BASE(self.atlb, /CONTEXT_MENU,uname='QTW_MENU')
    button1Q = WIDGET_BUTTON(contextBaseQ, VALUE='Create New Set',$
                                        sensitive=0,$
                                        uvalue = {object:self,$
                                                  method:'contextMenuEvents',$
                                                  id:'QNEWSET'})
;    button2Q = WIDGET_BUTTON(contextBaseQ, VALUE='Remove This Q',$
;                                        sensitive=0,$
;                                        uvalue = {object:self,$
;                                                  method:'contextMenuEvents',$
;                                                  id:'REMOVEQ'})
;    button3Q = WIDGET_BUTTON(contextBaseQ, VALUE='Keep This Q',$
;                                        sensitive=0,$
;                                        uvalue = {object:self,$
;                                                  method:'contextMenuEvents',$
;                                                  id:'KEEPQ'})

end;defineContextMenus
pro ooDisplayEcho::defineTree
;
;NAME:
;        ooDisplayEcho::defineTree
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    ;CREATE TREE OF DATA FILES IN TREE UNDER
    ;ASSOCIATED Q VALUES

    self.ftree = widget_tree(self.tlb1a1,/align_left,/sensitive,$;tab_mode=1,$
                            /context_events,$
                            uname='FTREE',$
                            multiple=1,$
                            $;ysize = 350,xsize=150,$
                            ysize = self.filetreeysize,$
                            xsize = self.filetreexsize,$
                            uvalue={object:self,$
                                    method:'treeEvents',$
                                    id:'FTREE',$
                                    element:0,$
                                    ContextBase_ID:0})

    self->defineContextMenus

    ;GET NUMBER OF Obj'S FROM THE DATA CONTAINER
    nObj = self.dataContainer->count()
    qArr = (self.dataContainer->get(position=0))->getProperty(tag='q')
    for i=1,nObj-1 do begin
        newQ =(self.dataContainer->get(position=i))->getProperty(tag='q')
        qArr = [qArr,newQ]
    endfor;i


    ;GET SORTED INDICES FOR Q VALUES
    qArrSort = sort(qArr)

    ;CREATE SORTED Q ARRAY
    qArrOrdered = $
        (self.dataContainer->get(position=qArrSort[0]))->getProperty(tag='q')
    for i = 1,n_elements(qArr)-1 do begin
        qArrOrdered = [qArrOrdered,$
            (self.dataContainer->get(position=qArrSort[i]))->getProperty(tag='q')]
    endfor


    ;GET UNIQ INDICES FOR SORTED Q ARRAY
    ;uniq PRODUCES AN ARRAY OF THE _LAST_ INDEX OF EACH
    ;UNIQUE SECTION
    qArrUniq = uniq(qArrOrdered)

    ;PRINT UNIQUE ORDERED Q VALUES
    qtw = lindgen(n_elements(qArrUniq))
    ftw = lindgen(n_elements(qArrOrdered))

    ;CREATE ZEROTH Q WIDGET WITH SUBWIDGETS
    qtw[0] = widget_tree(self.ftree,/folder,$
                      /expanded,$
                      value='Q = '+strtrim(string(qArrOrdered[qArrUniq[0]]),2),$
                      uvalue={object:self,$
                              method:'treeEvents',$
                              id:'QTW',$
                              element:0,$
                              qvalue:qArrOrdered[qArrUniq[0]]})

    for j=0,qArrUniq[0] do begin
        comment = (self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='comment')
        filename =  file_basename((self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='filename'))
        type =  (self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='type')
        reduced =  (self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='reduced')
        ftw[j] = widget_tree(qtw[0],value=filename+': '+comment,$
                                        group_leader=qtw[0],$
                                        bitmap = self->icon(reduced,type),$
                                        uvalue={object:self,$
                                                    method:'treeEvents',$
                                                    id:'FTW',$
                                                    element:j,$
                                                    index:qArrSort[j]})

    endfor;j

    ;CREATE OTHER Q WIDGETS WITH SUBWIDGETS
    for i = 1,n_elements(qArrUniq)-1 do begin
        qtw[i] = widget_tree(self.ftree,$
                            value='Q = '+strtrim(string(qArrOrdered[qArrUniq[i]]),2),$
                            /folder,/expanded,$
                            uvalue={object:self,$
                                        method:'treeEvents',$
                                        id:'QTW',$
                                        element:i,$
                                        qvalue:qArrOrdered[qArrUniq[i]]})

        for j=qArrUniq[i-1]+1,qArrUniq[i] do begin
            comment = (self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='comment')
            filename =file_basename((self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='filename'))

            self.data_dir = file_dirname((self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='filename'))

            type =  (self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='type')
            reduced =  (self.dataContainer->get(position=qArrSort[j]))->getProperty(tag='reduced')

            ftw[j] = widget_tree(qtw[i],value=filename+': '+comment,$
                                        group_leader=qtw[0],$
                                        bitmap = self->icon(reduced,type),$
                                        uvalue={object:self,$
                                                    method:'treeEvents',$
                                                    id:'FTW',$
                                                    element:j,$
                                                    index:qArrSort[j]})
        endfor;j
    endfor;i

    ;SET POINTERS TO THE WIDGET ID ARRAYS
    if ptr_valid(self.qtw) gt 0 then ptr_free,self.qtw
    self.qtw=ptr_new(qtw)
    if ptr_valid(self.ftw) gt 0 then ptr_free,self.ftw
    self.ftw=ptr_new(ftw)

end;defineTree
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::sortDataByQ
;
;NAME:
;        ooDisplayEcho::sortDataByQ
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    ;print,'ooDisplayEcho::sortDataByQ CALLED'


    ;051104
    ;
    ;NEED TO SORT WITH SET INFORMATION TOO.  ADD FIELD TO
    ;ooEcho DATA OBJECTS TO IDENTIFY THEIR SETS.  OR IDENTIFY
    ;THE FILENAMES IN THE SET OBJECTS.
    ;

    ;THIS DOES NOT YET WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


    ;ORDER DATA OBJECTS IN self.dataContainer BY Q

    ;GET NUMBER OF Obj'S FROM THE DATA CONTAINER
    nObj = self.dataContainer->count()
;    qArr = (self.dataContainer->get(position=0))->getProperty(tag='q')
;    for i=1,nObj-1 do begin
;        newQ =(self.dataContainer->get(position=i))->getProperty(tag='q')
;        qArr = [qArr,newQ]
;    endfor;i
;
;    ;GET SORTED INDICES FOR Q VALUES
;    qArrSort = sort(qArr)
;
;    print,qArrSort




;    ;MOVE OBJECTS AWAY FROM CURRENT POSITIONS
;    tmp = obj_new()
;    self.dataContainer->add,tmp,position=nObj
;
    for i=0,nObj-1 do begin


    ;THIS DOES NOT YET WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


        ;GET Q VALUES
        qArr = (self.dataContainer->get(position=0))->getProperty(tag='q')
        for j=0,nObj-1 do begin
            newQ =(self.dataContainer->get(position=j))->getProperty(tag='q')
            qArr = [qArr,newQ]
        endfor;j
        minVal = min(qArr[i:*],minIndex)

        self.dataContainer->move,minIndex,i
    endfor;i


    ;THIS DOES NOT YET WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end;sortDataByQ
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::getContainer,dataContainer
;
;NAME:
;        ooDisplayEcho::getContainer
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;print,'TEST'
    ;help,self.dataContainer

    ;RETURN THE DATA CONTAINER
    dataContainer = self.dataContainer

end;getContainer




;#######################################################
pro ooDisplayEcho::defineWidgets,plotxsize=plotxsize,$
                                 plotysize=plotysize
;
;NAME:
;        ooDisplayEcho::defineWidgets
;
;PURPOSE:
;           Define the widgets in an ooDisplayEcho object on initialization.
;           May be called by event handlers as necessary.
;PARAMETERS:
;           none
;KEYWORDS:
;           plotxsize   xsize of plot window
;           plotysize   ysize of plot window
;


;;
;DEFINE WIDGETS WHEN CALLED BY INIT
;
;   MAY BE CALLABLE BY EVENT HANDLERS AS NECESSARY
;;;


    ;090104 --- THIS SECTION WILL NEED FIXING FOR MAC X11
    ;WHY DID I CHOOSE 2.7? FOR ROB'S LAPTOP?
    device,get_screen_size=sz

    print,'device,get_screen_size=',sz


;092204
;THESE NUMBERS MUST COME FROM THE ABOVE COMMAND.
;COMMENT OUT THE NEXT TWO LINES SOON!!!!!!!!!!!!

    ;FOR TESTING PURPOSES
    sz[0] = fix(0.8*sz[0]);800
    sz[1] = fix(0.8*sz[1]);600



;    if !Version.OS eq 'Win32' then begin
;        if sz[0] gt 930 then sz[0] = 900
;        if sz[1] gt 720 then sz[1] = 700
;    endif else begin
;        sz[0] = 700
;        sz[1] = 500
;    endelse

    self.atlbxsize = sz[0]
    self.atlbysize = sz[1]



    ;print,'plotxsize,plotysize=',self.plotxsize,self.plotysize



;    self.filename = self.ech->getProperty(tag='filename')
    self.filename = $
    (self.dataContainer->get(position=$
                self.QChoiceIndex))->getProperty(tag='filename')

    ;THE NEXT PART MAY BE BETTER HANDLED BY ASSOCIATING
    ;A Q-VALUE AND FILE NAME WITH EACH DATA FILE READ
    ;AND USING THE Q-INDEX DROPLIST TO ACCESS THEM.
    ;
    ;BUT FOR NOW . . .
    thisTitle = 'NSE Data Reduction';   Current Data File = '$
                    ;+self.filename



    if !Version.OS eq 'Win32' then begin
        self.taucdysize = 28
        self.clickphaseysize = 0;67
        self.tw1ysize = 22
        self.filetreexpadding = 4
        self.filetreeypadding = 26
        self.tabsxpadding = 8
        self.tabsypadding = 30
        self.magicxpadding = 25
        self.magicypadding = 0
        tlb_size_events = 1
        standardsize = 300
    endif else begin
        self.taucdysize = 41
        self.clickphaseysize = 0;81
        self.tw1ysize = 31
        self.tabsxpadding = 4
        self.tabsypadding = 24
        self.filetreexpadding = 0
        self.filetreeypadding = 0
        self.magicxpadding = 25
        self.magicypadding = 30
        tlb_size_events = 1
        standardsize = 340
    endelse


    self.atlb = widget_base(/row,title=thisTitle,TLB_SIZE_EVENTS=tlb_size_events,$
                            group_leader = self.group_leader,   $
                            $;xsize=800, ysize=600,$;/TLB_KILL_REQUEST_EVENTS,$
                            xsize=self.atlbxsize,$
                            ysize=self.atlbysize,$
                            mbar = bar,$
                            KBRD_FOCUS_EVENTS = 1, $
                            uvalue=self);{obj:self,$
                                    ;method:'atlbEvents',$
                                    ;id:'ATLB'})   ;TOP LEVEL BASE

    geom = widget_info(self.atlb,/geometry)
;    print,tag_names(geom)
;    print,geom

    self.xpadding = geom.scr_xsize-geom.xsize
    self.ypadding = geom.scr_ysize-geom.ysize



;    self.filetreexsize = 150
    self.filetreexsize = standardsize - self.ypadding
;    self.filetreeysize = min([500,self.atlbysize - self.ypadding])
    self.tabsxsize = standardsize
    self.tabsysize = min([550,self.atlbysize - self.ypadding])
    self.filetreeysize = self.tabsysize - self.ypadding
    ;padding = 30


    if n_elements(plotxsize) gt 0 then begin
        self.plotxsize = plotxsize
    endif else begin
        ;self.plotxsize = fix(self.atlbxsize/2.7)
        self.plotxsize = fix(self.atlbxsize - $;self.filetreexsize - $
                            self.filetreexpadding - self.tabsxsize - self.tabsxpadding - self.xpadding-self.magicxpadding)
    endelse

    if n_elements(plotysize) gt 0 then begin
        self.plotysize = plotysize
    endif else begin
        ;self.plotysize = fix(self.atlbysize/2.4)
        ;self.plotysize = fix(self.atlbysize/2.2 - ypadding - clickphasesize)
        self.plotysize = fix((self.atlbysize - self.ypadding - $
                            self.clickphaseysize - self.taucdysize - self.tw1ysize-self.magicypadding)/2)
    endelse

    self.drawbasexsize = self.plotxsize
    self.drawbaseysize = 2*self.plotysize + self.taucdysize + self.tw1ysize;self.clickphaseysize + self.tw1ysize



;    print,'self.atlbxsize=',self.atlbxsize
;    print,'self.atlbysize=',self.atlbysize
;    print,'self.plotysize=',self.plotysize





;MAKE DUMMY BUTTONS TO SET WIDGET SIZES
dumbutton = lonarr(3)
    self.tlb1 = widget_base(self.atlb,/col)     ;
    self.tlb1a = widget_base(self.tlb1,/row,frame=2)


    ;092404 ADDING TAB WIDGET TO SAVE REAL ESTATE
    self.thetabs = widget_tab(self.tlb1a,$
                                    xsize=self.tabsxsize-self.tabsxpadding,$
                                    ysize=self.tabsysize-self.tabsypadding,$
                                    uvalue = {object:self,$
                                              method:'doNothing',$
                                              id:'THETABS'})



;    self.tlb1a1 = widget_base(self.tlb1a,/col,frame=2,$
    self.tlb1a1 = widget_base(self.thetabs,/col,frame=2,$
                                xsize=self.filetreexsize-self.filetreexpadding,$
                                ysize=self.filetreeysize-self.filetreeypadding,$
                                title='DATA FILES')   ;fileTree

;    dumbutton[0] = widget_button(self.tlb1a1,value='tree width = ~150',$
    dumbutton[0] = widget_button(self.tlb1a1,value='tree width = ~'+strtrim(string(standardsize),2),$
                                    xsize=self.filetreexsize-self.filetreexpadding)

;    ;092404 ADDING TAB WIDGET TO SAVE REAL ESTATE
;    self.thetabs = widget_tab(self.tlb1a,$
;                                    xsize=self.tabsxsize-self.tabsxpadding,$
;                                    ysize=self.tabsysize-self.tabsypadding,$
;                                    uvalue = {object:self,$
;                                              method:'doNothing',$
;                                              id:'THETABS'})


    ;MUST I SET THE SIZE ON THE FIRST WIDGET SO SPACE IS RESERVED ON OTHER TABS???
    self.tlb1a2 = widget_base(self.thetabs,/col,frame=2,$
                                $;xsize=self.tabsxsize-self.tabsxpadding,$
                                $;ysize=self.tabsysize-self.tabsypadding,$
                                $;/base_align_right,$
                                title='GENERAL') ;textWidgets
    dumbutton[1] = widget_button(self.tlb1a2,value='tree width = ~330',$
                                    xsize=self.tabsxsize-self.tabsxpadding)

    self.tlb1a3 = widget_base(self.thetabs,/col,frame=2,$
                                $;xsize=self.tabsxsize-self.tabsxpadding,$
                                $;ysize=self.tabsysize-self.tabsypadding,$
                                /base_align_left,$
                                title='DATA SET');SAMPLE') ;textWidgets
;092404
;    self.tlb1a2 = widget_base(self.tlb1a,/col,frame=2,xsize=330,$
;                                /base_align_right) ;textWidgets


;    self.tlb1a2 = widget_base(self.tlb1a,row=3,$
;                                /grid_layout,frame=2)



    ;020105
    ;X11 DOES NOT ALLOW SCROLL BARS ON THESE BASES!!!!
    self.tlb1b = widget_base(self.thetabs,/col,frame=2,$
                            $;ysize=self.tabsysize-self.tabsypadding,$
                            $;xsize=self.tabsxsize-self.tabsxpadding,$
                            title='FITTING',/base_align_left);,x_scroll_size=250)    ;fitWidgets

;092404
;    self.tlb1b = widget_base(self.tlb1,/col,frame=2)    ;fitWidgets

;020905
;DEFINE AN xsize FOR self.tlb2
    self.tlb2 = widget_base(self.atlb,/col);,ysize=self.drawbaseysize,xsize=self.drawbasexsize)
    dumbutton[2] = widget_button(self.tlb2,value='draw width = ~250',$
                                    xsize=self.drawbasexsize)
;
;;REALIZE THE ATLB HERE
;    widget_control,self.atlb,/realize


;NOTIFY THE USER OF GUI BUILDING PROGRESS
progb = widget_base(/floating,group_leader = self.atlb,title='BUILDING GUI')
progw = cw_progress(progb,value=[7],title='STEP ')
widget_control,progb,/realize


    self->defineTree
widget_control,progw,set_value=[1]

    self->defineMenus,bar
widget_control,progw,set_value=[2]

    self->defineTextWidgets
widget_control,progw,set_value=[3]

;033005
;ELIMINATE THE MASK BUTTONS HERE.
    ;self->defineMaskButton
widget_control,progw,set_value=[4]

    ;self->defineCDControls


;;092204 THE NEXT TWO CALLS HAVE BEEN SWAPPED TODAY TO
;;       TRY TO MAKE SPACE FOR ALL OF THE FIT WIDGETS.
;    self->defineDrawWidgets
;widget_control,progw,set_value=[5]

    self->defineFitWidgets
widget_control,progw,set_value=[5]


;021105
;THE MOVE TO REALIZE THE BASE HERE SEEMS TO MAKE OPENING THE
;PROGRAM FASTER ON THE MAC.
;
;;REALIZE THE ATLB HERE
    widget_control,self.atlb,/realize

;
;DEFINE THE DRAW WIDGETS HERE.
    self->defineDrawWidgets
widget_control,progw,set_value=[6]




    ;LATER:
    ;DISPLAY FOURIER TIME VS Q FOR POSSIBLE SCAN SELECTION

    self->draw

    widget_control,self.atlb,set_uvalue=self

    ;START EVENT MANAGER/PREPARE EVENT LOOP
    xmanager,"ooDisplayEcho",self.atlb,$
                cleanup="ooDisplayEchoCleanup",/no_block


;DESTROY dumbutton
for i = 0,n_elements(dumbutton)-1 do begin
    widget_control,dumbutton[i],/destroy
endfor;i

;DESTROY PROGRESS WIDGET.
widget_control,progw,set_value=[7]
widget_control,progb,/destroy

end;defineWidgets




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ooDisplayEcho::get_notify_ids
;
;NAME:
;        ooDisplayEcho::get_notify_ids
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

;RETURN VALUE:
;
    return,self.notify_ids
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::lastChanceToSaveSession
;
;NAME:
;        ooDisplayEcho::lastChanceToSaveSession
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;print,'8308 ooDisplayEcho::lastChanceToSaveSession'

    print,'Save session on exit = ',self->saveSession(/exitflag)

end;lastChanceToSaveSession

pro ooDisplayEchoCleanup,tlb
;
;NAME:
;        ooDisplayEchoCleanup
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;print,'8308 ooDisplayEchoCleanup'
    ;CALLED WHEN [X] EVENT OCCURS, BUT AFTER THE
    ;ATLB IS DESTROYED ALREADY.  IT IS TOO LATE TO SAVE AT THIS POINT.
    ;THIS CLEANUP METHOD CANNOT BE A CLASS METHOD, SO IT
    ;MUST CALL THE OBJECT'S CLEANUP METHOD.

    ;dum = dialog_message('Destruction is now inevitable.')

    print,'tlb Cleanup'
    widget_control,tlb,get_uvalue=self

    if obj_valid(self) then begin
        ;PROMPT FOR SAVE BEFORE QUITTING
        ;container = obj_new()
        ;ref = self->getproperty(/datacontainer)
        ;count = ref->count()
        self->lastChanceToSaveSession
        s = size(self->get_notify_ids())
        if s[0] ne 0L then begin
            n = self->get_notify_ids()
            nse_info = {NSE_EVENT,  $
                        id:(self->get_notify_ids())[0],     $
                        top:(self->get_notify_ids())[1],    $
                        handler:0L                          }
        endif
        if widget_info(n[0],/valid_id) then begin
            widget_control,n[0],send_event = nse_info
        endif
    endif
    obj_destroy,self
    return
end;ooDisplayEchoCleanup
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ooDisplayEcho::cleanup
;
;NAME:
;        ooDisplayEcho::cleanup
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

    ;print,'ooDisplayEcho Cleanup'

    ;self->maskCleanup,self.maskBase
    if ptr_valid(self.maskmakermask) gt 0 then ptr_free,self.maskmakermask
    ptr_free,self.displayChoices
    ptr_free,self.detChoices
    ptr_free,self.ftChoices
    ptr_free,self.mye
    ptr_free,self.ie
    ptr_free,self.im
    ptr_free,self.imeb
    ptr_free,self.geomBase
    ptr_free,self.geomImage
    ptr_free,self.geomPlot
    ptr_free,self.w1xptr
    ptr_free,self.w1yptr
    ptr_free,self.w2xptr
    ptr_free,self.w2yptr
    ptr_free,self.phase
    ptr_free,self.qtw
    ptr_free,self.ftw
    obj_destroy,self.drawImage
    obj_destroy,self.drawPlot
    ptr_free,self.setMembers

    if (ptr_valid(self.dataSet) gt 0) then begin
        for i=0,n_elements(*self.dataSet) do begin
            if (obj_valid((*self.dataSet)[i]) gt 0) then $
                        obj_destroy,(*self.dataSet)[i]
        endfor
        ptr_free,self.dataSet
    endif
    if (obj_valid(self.IQTDisplayObj)) then obj_destroy,self.IQTDisplayObj


;111605
;    ref = self.datacontainer->get(/all)
;    if n_elements(ref) gt 0 and total(obj_valid(ref)) eq n_elements(ref) then obj_destroy,ref
    while self.datacontainer->count() gt 0 do begin
        ref = self.datacontainer->get(position=0)
        self.datacontainer->remove,position=0
        if obj_valid(ref) gt 0 then obj_destroy,ref
    endwhile
    if (obj_valid(self.dataContainer) gt 0) then obj_destroy,self.dataContainer
    if (obj_valid(self.setContainer) gt 0) then obj_destroy,self.setContainer
    if (obj_valid(self.ech) gt 0) then obj_destroy,self.ech
    if (obj_valid(self.echorig) gt 0) then obj_destroy,self.echorig
    if (obj_valid(self.fitselectorobj) gt 0) then $
                            obj_destroy,self.fitselectorobj

end;cleanup
function get_font_name, $
        helvetica=helvetica, times=times, courier=courier, $
        tiny=tiny, small=small, medium=medium, large=large, huge=huge, $
        size=size, $
        bold=bold, italic=italic, $
        dpi75=dpi75, dpi100=dpi100
;
;NAME:
;        get_font_name
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

;RETURN VALUE:
;

; Returns the name of the font with the specified characteristics
;
;
;METHOD FROM GUMLEY VIA THE IDL-PVWAVE GOOGLE GROUP.
;1997/11/22

if (!version.os_family eq 'Windows') then begin
font = ''
if keyword_set(helvetica) then font = font + 'Helvetica' else $
if keyword_set(times)     then font = font + 'Times' else $
if keyword_set(courier)   then font = font + 'Courier' else $
                               font = font + 'MS San Serif'

if keyword_set(bold) then font = font + '*Bold'
if keyword_set(italic) then font = font + '*Italic'
if keyword_set(tiny)   then size=0
if keyword_set(small)  then size=1
if keyword_set(medium) then size=2
if keyword_set(large)  then size=3
if keyword_set(huge)   then size=4
if (n_elements(size) eq 0) then size=2
font_size_strings = ['12', '14', '16', '18', '20']
size = (size > 0) < (n_elements(font_size_strings)-1)
font = font + '*' + font_size_strings(size)
return, font

endif else if (!version.os_family eq 'Mac') then begin
   font='Helvetica'
   return, font
endif else begin

; VMS and Unix
font = '-adobe-'
if keyword_set(helvetica) then font = font + 'helvetica-' else $
if keyword_set(times)     then font = font + 'times-' else $
if keyword_set(courier)   then font = font + 'courier-' else $
                               font = font + 'helvetica-'

if keyword_set(bold) then font = font + 'bold-' else font = font + 'medium-'
if keyword_set(italic) then font = font + 'o-' else font = font + 'r-'
font = font + 'normal--*-'

if keyword_set(tiny)   then size=0
if keyword_set(small)  then size=1
if keyword_set(medium) then size=2
if keyword_set(large)  then size=3
if keyword_set(huge)   then size=4
if (n_elements(size) eq 0) then size=2
font_size_strings = ['80-', '100-', '120-', '140-', '180-']
size = (size > 0) < (n_elements(font_size_strings)-1)
font = font + font_size_strings(size)

if keyword_set(dpi100) then font = font + '100-100-' else $
if keyword_set(dpi75) then font = font + '75-75-' else $
                            font = font + '*-*-'
font = font + '*-*-iso8859-1'
return, font
endelse

end;get_font_name


pro ooDisplayEcho::readParametersFile,fn
;
;NAME:
;        ooDisplayEcho::readParametersFile
;
;PURPOSE:
;       Enter a set of parameters from an ASCII file for the program.
;PARAMETERS:
;       fn  Filename
;KEYWORDS:
;

    if n_elements(fn) ne 1 then begin
        fn = dialog_pickfile(title='Choose Parameters File',path=self.work_dir,filter = '*.nse')
    endif
    if fn ne '' then begin

        lines = file_lines(fn)
        line = ''
        openr,lun,fn,/get_lun
        help,lun,/file,output=out


        catch, Error_status
        ;Error handler in case of type conversion error in text field
        if (Error_status ne 0) then begin
            print, 'Error index: ', Error_status
            print, 'Error message: ', !ERROR_STATE.MSG
            void = dialog_message('There was a problem reading the .nse file.')
            catch, /cancel
        endif

        if stregex(out[0],'Closed',/fold_case) eq -1 then begin

            ;READ COMMENT LINES
            readf,lun,line
            readf,lun,line


    ;Gaussian_Width	702.00
    ;Beam_Center_X	15.36
    ;Beam_Center_Y	14.66
    ;Echo_Period	360.0
    ;Work_Directory	.
    ;Data_Directory	.

            ;GAUSSIAN WIDTH
            readf,lun,line
            segs = strsplit(line,/extract)
            widget_control,self.atwwidth,set_value=segs[1]
            self.gaussianwidth = double(segs[1])



            ;print,segs[1]


            ;BEAM CENTER X
            readf,lun,line
            segs = strsplit(line,/extract)
            widget_control,self.atwbcx,set_value=segs[1]
            self.beamcenxorig = double(segs[1])
            ;print,segs[1]

            ;BEAM CENTER Y
            readf,lun,line
            segs = strsplit(line,/extract)
            widget_control,self.atwbcy,set_value=segs[1]
            self.beamcenyorig = double(segs[1])
            ;print,segs[1]

            ;PERIOD VALUE
            readf,lun,line
            segs = strsplit(line,/extract)
            widget_control,self.atwperiod,set_value=segs[1]
            self.periodvalue = double(segs[1])
            ;print,segs[1]

            ;WORKING DIRECTORY
            readf,lun,line
            segs = strsplit(line,/extract)
            self.work_dir = segs[1]
            ;print,segs[1]

            ;DATA DIRECTORY
            readf,lun,line
            segs = strsplit(line,/extract)
            self.data_dir = segs[1]
            ;print,segs[1]

            if self.datacontainer->count() gt 0 then begin
                for i=0,self.datacontainer->count()-1 do begin
                    ref = self.datacontainer->get(position=i)
                    ref->setwidth,self.gaussianwidth
                    ref->setperiod,self.periodvalue
                    ref->setproperty,'beam_cen_x',self.beamcenxorig
                    ref->setproperty,'x_cen',self.beamcenxorig
                    ref->setproperty,'x_cen_orig',self.beamcenxorig
                    ref->setproperty,'beam_cen_y',self.beamcenyorig
                    ref->setproperty,'y_cen',self.beamcenyorig
                    ref->setproperty,'y_cen_orig',self.beamcenyorig
                    ref->setproperty,'datadir',self.data_dir
                    ref->setproperty,'workdir',self.work_dir
                endfor;i
            endif

        endif
        free_lun,lun
    endif else begin
        void = dialog_message('Please enter a valid parameters file.')
    endelse

end;readParametersFile
pro ooDisplayEcho::writeParametersFile,fn
;
;NAME:
;        ooDisplayEcho::writeParametersFile
;
;PURPOSE:
;       Write a set of parameters to an ASCII file.
;PARAMETERS:
;       fn  Filename
;KEYWORDS:
;

    if n_elements(fn) ne 1 then begin
        fn = dialog_pickfile(title='Choose Parameters File',path=self.work_dir, $
                             filter = '*.nse',/overwrite_prompt)
    endif


;APPEND .nse EXTENSION IF NECESSARY
    fnlen = strlen(fn)
    if fnlen ge 4 then begin
        fn_ext = strmid(fn,fnlen-4,4)
        print,'fn_ext',fn_ext
        if strupcase(fn_ext) ne '.NSE' then begin
            fn = fn+'.nse'
        endif
    endif else begin
        if fn ne '' then begin
            fn = fn+'.nse'
        endif else begin
            void = dialog_message('NO OUTPUT FILE OR INVALID OUTPUT FILE SELECTED.')
            return
        endelse
    endelse

    if fn ne '' then begin

;        lines = file_lines(fn)
;        line = ''
        openw,lun,fn,/get_lun
        help,lun,/file,output=out

        printf,lun,'#SPIN ECHO PARAMETERS FILE'
        printf,lun,'#Edit as necessary to keep the values current for yourself.'
        printf,lun,'Gaussian_Width     ',self.gaussianwidth
        printf,lun,'Beam_Center_X      ',self.beamcenxorig
        printf,lun,'Beam_Center_Y      ',self.beamcenyorig
        printf,lun,'Echo_Period        ',self.periodvalue
        printf,lun,'Work_Directory     ',self.work_dir
        printf,lun,'Data_Directory     ',self.data_dir

        free_lun,lun
    endif else begin
        void = dialog_message('Please enter a valid parameters file.')
    endelse

end;writeParametersFile


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;ooDisplayEcho::init
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ooDisplayEcho::init,ech,plotxsize=plotxsize,plotysize=plotysize, $
    group_leader = group_leader,    $
    notify_ids = notify_ids,        $
    data_dir = data_dir,            $
    work_dir = work_dir,            $
    parametersfile = parametersfile,$
    dave_id = dave_id
;
;NAME:
;        ooDisplayEcho::init
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.

;RETURN VALUE:
;

;092204
;
;THESE FONT ADJUSTMENTS AFFECTED ALL OF DAVE ONCE THEY
;WERE USED!!!
;
    ;092104
    ;SET FONT SIZES FOR THE WIDGET.
;;;;    default_font = get_font_name(/TINY, /TIMES)
;;;;    button_font = get_font_name(/MEDIUM, /TIMES, /BOLD)
;;;;    label_font = get_font_name(/SMALL, /TIMES)
;;;;;    default_font = get_font_name(/SMALL, /HELVETICA)
;;;;;    button_font = get_font_name(/LARGE, /HELVETICA, /BOLD)
;;;;;    label_font = get_font_name(/MEDIUM, /HELVETICA)
;;;;
;;;;    !P.charsize = 0.75
;;;;    ;!P.font = label_font
;;;;
;;;;
;;;;    widget_control, default_font=default_font


;101304
;
;UPDATING TO OPEN THE GUI WITH A BLANK DATA OBJECT AND
;THEN DELETE THE OBJECT.

    ; Initialize the members related to instantiation of this
    ; widget object class from the DAVE environment.


device,get_decomposed = dc
;ALLOW USE OF COLOR TABLE
device,decomposed = 0
    if n_elements(group_leader) eq 0 then group_leader = 0L
    if n_elements(notify_ids) eq 0 then notify_ids = [0L,0L]
    if n_elements(work_dir) eq 0 then work_dir = ''
    if n_elements(data_dir) eq 0 then data_dir = ''
    if n_elements(parametersfile) eq 0 then parametersfile = ''
    if n_elements(dave_id) eq 0 then dave_id = 0L
    self.dave_id = dave_id

    device,get_screen_size=sz

    if n_elements(plotxsize) gt 0 then plotxsize = sz[0]/3
    if n_elements(plotysize) gt 0 then plotysize = sz[1]/3
    self.work_dir = work_dir
    self.data_dir = data_dir
    self.notify_ids = notify_ids
    self.group_leader = group_leader

    self.colorTable = 3     ;RED TEMPERATURE

    self.dataContainer = obj_new('IDL_container')
    self.setContainer = obj_new('IDL_container')
    loadct,self.colorTable


    o = obj_new('ooEcho',/blank)
    o->bin,factor=4       ;092404 --- SET DEFAULT BINNING TO 4
    self.dataContainer->add,o,position=0

    self->setDataParameters,o,n=0

    self->defineWidgets,plotxsize=plotxsize,plotysize=plotysize

    ref=self.dataContainer->get(position=0)
    self.dataContainer->remove,position=0


    if parametersfile ne '' then begin
        self->readParametersFile,parametersfile
    endif

    self->redefinetree

    obj_destroy,ref

device,decomposed=dc
    return,1
end;init
pro ooDisplayEcho__define,class
;
;NAME:
;        ooDisplayEcho__define
;
;PURPOSE:
;
;PARAMETERS:
;
;KEYWORDS:
;
;_EXTRA - is used to pass keywords meant for the superclass.


    class = {ooDisplayEcho,$
                inherits myProperties,$
                dave_id:0L,$                ;WIDGET ID OF DAVE'S TLB
                filename : '',$             ;FILE NAME OF CURRENT DATA OBJECT
                data_dir:'',            $
                work_dir:'',            $
                state_saved:0,$             ;INDICATOR OF SAVED STATE OR NOT.
                comment : '',$
                dataset : ptr_new(),$       ;POINTER TO AN ARRAY OF DATA OBJECTS
                dataContainer : obj_new(),$ ;THE DATA CONTAINER FOR THE SET
                $;                          ;OF DATA OBJECTS
                nDataObj : 0,$              ;NUMBER OF DATA OBJECTS
                setContainer : obj_new(),$  ;CONTAINER FOR THE SETS IN THE
                $;                          ;DATA TREE
                setMembers : ptr_new([-1]),$;POSITIONS OF MEMBERS OF SETS
                $;                          ;IN THE dataContainer
                ech : obj_new(),$           ;ECHO OBJECT FOR OPERATIONS
                echorig : obj_new(),$       ;SAVED ECHO OBJECT FOR RESTORE
                detChoices : ptr_new(),$    ;DETECTOR OPTIONS ARRAY
                ftChoices : ptr_new(),$     ;FOURIER TIMES
                displayChoices : ptr_new(),$;IMAGE DISPLAY OPTIONS
                displayIndex : 0,$          ;INDEX OF WHAT IMAGE TO DISPLAY
                imageTitle : 'Title',$      ;TITLE OF THE DISPLAYED IMAGE
                errorImageChoice:0,$        ;FLAG FOR DISPLAYING IMAGE ERROR
                plotxsize : 330,$           ;SIZE OF PLOT AND IMAGE WINDOWS
                plotysize : 330,$
                plotIndex : 5,$             ;PLOT DISPLAY CHOICES
                plotupdown : 1,$            ;TOGGLE SWITCH FOR UP/DOWN PLOTTING
                detChoiceIndex: 0,$         ;SELECTED DETECTOR INDEX
                ftChoiceIndex: 0,$          ;SELECTED FOURIER TIME INDEX
                ftChoiceIndexOld:0,$        ;PREVIOUSLY SELECTED TIME INDEX
                QChoiceIndex: 0,$           ;CURRENT Q INDEX
                QChoiceIndexOld: 100,$      ;PREVIOUS Q INDEX
                treeSelectID: 0L,$          ;LAST TREE LEAF SELECTED
                treeSelectVal: '',$         ;VALUE OF LAST TREE LEAF SELECTED
                xindex:0,$                  ;X AND Y INDICES OF CURRENT
                yindex:0,$                  ;PIXEL
                detxDim : 0,$               ;X DIMENSION OF DETECTOR
                detyDim : 0,$               ;Y DIMENSION OF DETECTOR
                beamCenxOrig : 13.0,$       ;BEAM CENTER IN X DIMENSION
                beamCenyOrig : 13.0,$       ;BEAM CENTER IN Y DIMENSION
                lambda : 6.0,$              ;WAVELENGTH FROM DATA OBJECT
                dlambda : 3.0,$             ;WAVELENGTH DISTRIBUTION
                mye : ptr_new(),$           ;4-D ECHO ARRAY
                ie : ptr_new(),$            ;3-D ARRAY AT SELECTED FOURIER TIME
                im : ptr_new(),$            ;2-D ARRAY FOR IMAGE DISPLAY
                imeb : ptr_new(),$          ;2-D ARRAY ERROR BAR VALUES
                geomBase : ptr_new(),$      ;GEOMETRY OF TL BASE WIDGET
                geomImage : ptr_new(),$     ;GEOMETRY OF IMAGE DRAW WIDGET
                geomPlot : ptr_new(),$      ;GEOMETRY OF PLOT DRAW WIDGET
                atlb : 0L,$                 ;TOP LEVEL BASE
                atlbxsize : 800,$
                atlbysize : 600,$
                $;THE NEXT ITEMS ARE USED TO ADJUST THE GUI GEOMETRY.
                xpadding : 4.0,$
                ypadding : 4.0,$
                filetreexsize : 150,$
                filetreeysize : 500,$
                tabsxsize : 330,$
                tabsysize : 500,$
                taucdysize : 28,$
                clickphaseysize : 67,$
                tw1ysize : 22,$
                filetreexpadding : 4,$
                filetreeypadding : 26,$
                tabsxpadding : 8,$
                tabsypadding : 30 ,$
                magicxpadding : 50,$
                magicypadding : 50,$
                drawbasexsize : 330,$
                drawbaseysize : 330,$
                $;
                $;
                colorTable:4,$
                mouseMotionBlock:0,$
                thetabs : 0L,$              ;TAB WIDGET TO ORGANIZE SPACE
                $;DETECTOR PARAMETERS WIDGETS
                tlb1 : 0L,$                 ;BUTTON AND TEXT FIELD BASE
                tlb1a : 0L,$
                tlb1a1 : 0L,$               ;FILE TREE WIDGET BASE
                ftree : 0L,$
                qtw : ptr_new(),$           ;ARRAY OF TREE WIDGETS FOR UNIQUE Q VALS
                ftw : ptr_new(),$           ;ARRAY OF TREE WIDGETS FOR FILE NAMES
                tlb1a2 : 0L,$               ;GENERAL PROPERTIES BASE
                tlb1a3 : 0L,$               ;SAMPLE PROPERTIES BASE
                atl0 : 0L,$
                atwfile : 0L,$              ;TEXT WIDGET FOR FILENAME DISPLAY
                adw0 : 0L,$                 ;DROPLIST WIDGET FOR IMAGE DISPLAY CHOICE
                adw1 : 0L,$                 ;DROPLIST WIDGET FOR DETECTOR CHOICES
                adwTau : 0L,$               ;DROPLIST WIDGET FOR FOURIER TIME CHOICES
                adwQ : 0L,$                 ;DROPLIST WIDGET FOR Q VALUES
                rewbuttonq : 0L,$           ;BUTTONS FOR RUNNING THROUGH
                revbuttonq : 0L,$           ;Q AND TAU VALUES
                fwdbuttonq : 0L,$
                ffwdbuttonq : 0L,$
                rewbuttontau : 0L,$
                revbuttontau : 0L,$
                fwdbuttontau : 0L,$
                ffwdbuttontau : 0L,$
                PLOTMASKZOOMBUTTON : 0L,$
                plotmaskzoomflag : 0,$
                ;
                plotzoomswitch:0,$
                plotunzoombutton:0L,$
                ;
                plotpressx:0.0,$        ;POSITIONS OF PRESS AND RELEASE
                plotpressy:0.0,$        ;ON PLOT --- USE NORMALIZED COORDINATES!!!
                plotreleasex:0.0,$
                plotreleasey:0.0,$
                plotmousepressed:0,$    ;FLAG TO TELL WHETHER MOUSE IS PRESSED FOR DRAGGING
                plotxmin:10000.0,$
                plotxmax:-10000.0,$     ;SAVE THE PLOT RANGES IN CASE OF ZOOM.
                plotymin:10000.0,$
                plotymax:-10000.0,$
                plotzoombox:0,$
                plotzoomed:0,$
                atwscaleupdownxyz:0L,$
                scaleupdownxyz:1.0,$
                maskbutton : 0L,$
                maskBase : 0L,$
                maskmakercw : 0L,$
                maskmakermask : ptr_new(),$
                atl1 : 0L,$
                atw1 : 0L,$
                atw1value : 0,$
                binallbutton : 0L,$
                transvolallbutton : 0L,$
                atl2 : 0L,$
                atwbcx : 0L,$
                atl3 : 0L,$
                atwbcy : 0L,$
                atwwidth : 0L,$
                gaussianwidth : 702.0,$
                atwperiod : 0L,$        ;SET PERIOD VALUE FOR ALL DATA
                periodvalue : 360.0,$
                atwphaseoffset : 0L,$   ;SET PHASE OFFSET FOR ALL DATA
                atwtrans : 0L,$
                atwvolfrac : 0L,$
                atl4 : 0L,$
                atwnarcs : 0L,$
                atwlambda : 0L,$
                atl5 : 0L,$
                atwlambdadist : 0L,$
                atl6 : 0L,$
                tlb2 : 0L,$                 ;DATA DISPLAY BASE
                magplotcontextsubmenu:0L,$  ;MAGNETIC WIDGETS
                magplotmenusubmenu:0L,$
                magneticcheckbox:0L,$
                DEEPMASKINGCHECKBOX:0L,$
                TIMEAVERAGEUPDOWNCHECKBOX:0L,$
                TIMEAVERAGEUPDOWNAPPLYALLBUTTON:0L,$
                atwflippingratio:0L,$
                atwpolarization:0L,$
                atweff_bpw:0L,$
                atweff_bpw_x:0L,$
                atweff_bpw_y:0L,$
                atweff_bpw_z:0L,$
                atwpoint_to_up_x:0L,$
                atwpoint_to_down_x:0L,$
                atwpoint_to_up_y:0L,$
                atwpoint_to_down_y:0L,$
                atwpoint_to_up_z:0L,$
                atwpoint_to_down_z:0L,$
                atwxyzupdownscale:0L,$
                dw1 : 0L,$                  ;DRAW WIDGET FOR IMAGE
                dw2 : 0L,$                  ;DRAW WIDGET FOR PLOT
                dw1pix : 0L,$               ;VIRTUAL WINDOW FOR IMAGE
                dw2pix : 0L,$               ;VIRTUAL WINDOW FOR PLOT
                dw2auxpix:0L,$              ;
                dw2aux : 0L,$               ;AuxilIARY WINDOWS, DRAW WIDGET AND BASE FOR FLOATING PLOT.
                dw2auxid : 0L,$             ;
                dw2auxbase : 0L,$           ;
                imageerrorbase : 0L,$       ;BASE FOR IMAGE ERROR
                imageerrordw : 0L,$         ;DRAW WIDGET FOR IMAGE EB
                dwebpix : 0L,$
                dwebid : 0L,$
                $;FIT PARAMETERS WIDGETS
                phaseimportbutton : 0L,$    ;BUTTON TO IMPORT PHASES FROM ANOTHER DATA OBJECT
                phaseImportBase : 0L,$      ;MODAL DIALOG FOR SELECTING PHASES TO
                phaseImportList : 0L,$      ;IMPORT
                $
                removeSetBase : 0L,$
                removeSetList : 0L,$
                setSelectBase : 0L,$
                setSelectList : 0L,$
                setNameBase : 0L,$
                setNameField : 0L,$
                mergeBase : 0L,$
                mergeList : 0L,$
                removeFourierTimeMenu : 0L,$
                IQTDisplayObj : obj_new(),$
                IQTDisplayBase : 0L,$
                IQTImportBase : 0L,$
                datImportList : 0L,$
                resImportList : 0L,$
                bkgImportList : 0L,$
                tlb1b : 0L,$
                fitbuttonallQ : 0L,$        ;BUTTON TO FIT EVERYTHING
                fitbuttonallminus360 : 0L,$ ;BUTTON TO FIT EVERYTHING FOR CURRENT FILE AFTER SHIFTING PHASES BY -360
                fitbuttonallplus360 : 0L,$  ;BUTTON TO FIT EVERYTHING FOR CURRENT FILE AFTER SHIFTING PHASES BY -360
                fitselector:0L,$    ;CWO TO SELECT TYPE OF FIT
                fitselectorobj:obj_new(),$
                fitbuttonall : 0L,$         ;BUTTON TO FIT EVERYTHING FOR CURRENT FILE
                fitbutton:0L,$              ;BUTTON TO FIT ALL ECHOES FOR CURRENT TAU
                fitbutton1:0L,$             ;BUTTON TO FIT THIS ECHO ONLY
                clickrefitbase:0L,$
                clickrefitslider:0L,$       ;VALUE SLIDER FOR CLICK REFIT.
                clickrefitvalue:0L,$
                clickrefitperiodslider:0L,$ ;VALUE SLIDER FOR PERIOD ON CLICK REFIT.
                clickrefitperiodvalue:0L,$
                atl1a : 0L,$
                $;
                fixed:intarr(6),$           ;ARRAY TO PASS TO FIT FUNCTION
                $;                          ;TO SELECT WHETHER TO VARY PARMS
                startparms : dblarr(6),$
                $;
                $;CONST FIT PARAMETER
                constbase : 0L,$
                dropfixconst : 0L,$
                atwconst : 0L,$
                atweconst : 0L,$
                $;AMPLITUDE FIT PARAMETER
                ampbase : 0L,$
                dropfixamp : 0L,$
                atwamp : 0L,$
                atweamp : 0L,$
                $;PHASEo FIT PARAMETER
                phaseobase : 0L,$
                dropfixphaseo : 0L,$
                atwphaseo : 0L,$
                atwephaseo : 0L,$
                $;SIGMA FIT PARAMETER
                sigmabase : 0L,$
                dropfixsigma : 0L,$
                atwsigma : 0L,$
                atwesigma : 0L,$
                $;OMEGA FIT PARAMETER
                omegabase : 0L,$
                dropfixomega : 0L,$
                atwomega  : 0L,$
                atweomega  : 0L,$
                $;PHASE FIT PARAMETER
                phasebase  : 0L,$
                dropfixphase : 0L,$
                atwphase  : 0L,$
                atwephase : 0L,$
                $;ADDITIONAL RESULTS FIELDS
                atwchisq : 0L,$
                atwratio : 0L,$
                $;FIT PARAMETER LIMITS
                limited:intarr(6),$         ;ARRAY TO PASS TO FIT FUNCTION
                $;                          ;TO SELECT WHETHER TO LIMIT PARMS
                $;CONSTANT LIMITS
                limconstbase : 0L,$
                droplimitconst : 0L,$
                atwminlimconst  : 0L,$
                atwmaxlimconst : 0L,$
                $;AMPLITUDE LIMITS
                limampbase : 0L,$
                droplimitamp : 0L,$
                atwminlimamp  : 0L,$
                atwmaxlimamp : 0L,$
                $;PHASEO LIMITS
                limphaseobase : 0L,$
                droplimitphaseo : 0L,$
                atwminlimphaseo  : 0L,$
                atwmaxlimphaseo : 0L,$
                $;SIGMA LIMITS
                limsigmabase : 0L,$
                droplimitsigma : 0L,$
                atwminlimsigma  : 0L,$
                atwmaxlimsigma : 0L,$
                $;OMEGA LIMITS
                limomegabase : 0L,$
                droplimitomega : 0L,$
                atwminlimomega  : 0L,$
                atwmaxlimomega : 0L,$
                $;PHASE LIMITS
                limphasebase : 0L,$
                droplimitphase : 0L,$
                atwminlimphase  : 0L,$
                atwmaxlimphase : 0L,$
                $;DRAW WIDGETS
                tw1 : 0L,$
                dw1id:0L,$                  ;DRAW WIDGET IDs
                dw2id:0L,$
                tw1id:0L,$
                atw1id:0L,$
                atwbcxid:0L,$
                atwbcyid:0L,$
                atwlambdaid:0L,$
                atwlambddistaid:0L,$
                w1xptr : ptr_new(),$   ;SET THESE VALUES AT POINT OF EVENT TO
                w1yptr : ptr_new(),$   ;PREVENT AXIS CONFUSION
                webxptr : ptr_new(),$  ;SET THESE VALUES AT POINT OF EVENT TO
                webyptr : ptr_new(),$  ;PREVENT AXIS CONFUSION
                w2xptr : ptr_new(),$   ;SET THESE VALUES AT POINT OF EVENT TO
                w2yptr : ptr_new(),$   ;PREVENT AXIS CONFUSION
                w2xauxptr : ptr_new(),$   ;SET THESE VALUES AT THIS POINT TO
                w2yauxptr : ptr_new(),$   ;PREVENT AXIS CONFUSION
                phase : ptr_new(),$;ech->getProperty(tag='phase')
                no_of_phases : 0,$
                no_of_fourier_times : 0,$
                drawImage : obj_new(),$
                notify_ids:lonarr(2),   $
                group_leader:0L,        $
                drawPlot : obj_new()};, $
                ;inherits myproperties $
                ;}


end;define


