;
; NAME:
;       PLOT_TXT_PROFILES 
;
; PURPOSE:
;       This procedure reads text files containing one or more profiles
;       (created by image_profiles) and plots them.
;
; CALLING SEQUENCE:
;       PLOT_TXT_PROFILES 
;
; INPUTS:
;       None
;
;
; OUTPUTS:
;       None
;
; OPTIONAL OUTPUTS:
;       Plot(s) May be saved in PostScript files or sent to a printer. 
;
; CALLED ROUTINES:
;       TXTPROF2STRUCT function.
;
; MODIFICATION HISTORY:
;               Written  Ed Esfandiari, NRL
;   Version 1   aee  Apr 06, 1999    Initial release.
;

function get_help
 help_info=[$
 ' This Widgitized IDL routine reads text files containing one or more',$
 'profiles (created by image_profiles) and plots them. To use it, enter a',$
 'filename (either manually or use the "PickFile" button) and then press',$
 '"Read This File" button. For files containing multiple profiles, you will',$
 'be asked to select only one profile at a time. To read in two or more',$
 'profiles from the same file, you need to press the "Read This File" two',$
 'or more times and each time select a new profile. You may change the',$
 'filename to read in other profiles.',$
 '',$
 ' The profiles that are read in are accumulated and displayed using P01, P02,',$ 
 'P03, P04, etc. notations as the "Available profiles:". The structure of',$
 'the most recently read profile is displayed below the "Available profiles"',$
 'section. The displayed profile is the active profile. The plot command',$
 'always uses the active profile. Next section describes how to change the',$
 'active profile.',$
 '',$
 ' To make a plot, adjust any of the plot parameters listed under the plot',$
 'window. Use "plot", "Plot_io", or "oplot" as well as any of the available',$
 'profiles such as P01, P02, etc. to setup the plot command. The profile name',$
 'shown in the "profile" box between "plot" and "psym" is the active profile',$
 'that will be plotted. To make a different profile active, edit the "profile"',$
 'box. For example, to change the active profile from P02 to P01, type in P01',$
 'in place of P02. The displayed structure also changes to reflect the newly',$
 'selected active profile. When satisfied with the selections, press the',$
 '      "Select plot parameters from above and PRESS HERE to plot"',$
 'button to actually plot the profile. A maximum of 20 profiles may be',$
 'overplotted.',$'
 '',$
 ' The displayed plot(s) may also be saved in a PostScript file or sent to a',$
 'printer of choice.',$
 '',$
 ' Send mail to esfandiari@susim.nrl.navy.mil for questions or help.']

 return,help_info
end


function get_type,s,tag_val
  case (s(tag_val)) of
    0: t='UNDEFINED'
    1: t='BYTE    '
    2: t='INT     '
    3: t='LONG    '
    4: t='FLOAT   '
    5: t='DOUBLE  '
    6: t='COMPLEX '
    7: t='STRING  '
    8: t='STRUCT  '
  end
  return, t
end


function get_size,s,scal_val,tag_val
  case (s(0)) of
    0: begin
        if(s(tag_val) ne 7) then begin
          t='          '+strtrim(string(scal_val),1)
        endif else begin
          if(strlen(scal_val) gt 50) then scal_val=strmid(scal_val,0,50)+'..'
          t="    '"+strtrim(string(scal_val),1)+"'"
        end
       end
    1: t='    Array('+strtrim(string(s(1)),1)+')'
    2: t='    Array('+strtrim(string(s(1)),1)+', '+strtrim(string(s(2)),1)+')'
    3: t='    Array('+strtrim(string(s(1)),1)+', '+strtrim(string(s(2)),1)+ $
                    ', '+strtrim(string(s(3)),1)+')'
  end
  return, t
end


pro show_st,ids,st            
    tags=tag_names(st)
    ntags=n_tags(st)
    maxl= max(strlen(tags))+2
    for i=0, ntags-1 do begin
      out= execute("s= size(st."+tags(i)+")")
      tag_val= n_elements(s)-2
      elem=n_elements(s)-1
      tag= tags(i)
      for j=1,maxl-strlen(tag) do tag= tag+' '
      if(s(0) eq 0) then out= execute("scal_val= st."+tags(i))
;      info= tag+get_type(s,tag_val)+get_size(s,scal_val,tag_val)
      info= tag+get_size(s,scal_val,tag_val)
      WIDGET_CONTROL,ids(i),SET_VALUE=info
    end
  return
end

pro plot_txt_profiles_event,event
  common all_data,f_lev,func,p_values,avl_profs,ps_values,c_values,$
         x_styles,y_styles,origname,filename,splots,ver,pind,prof_num,use_func,$
         pv,lsv,psv,cv,plt_cmnd,f_st,set_st,set_elem,subtype,level,ucmnd,uexe,$
         ptname,prname,s_values,red,green,blue,sxyouts
  common all_ids, file_id,st_id,day_id,ver_id,cyc_id,rd_id,set_id,plt_id,$
         x_id,y_id,c_id,mkp_id,pt_id,pn_id,sv_id,sn_id,er_id,d_id,mtle_id,$
         xtle_id,ytle_id,xsyl_id,xmn_id,xmx_id,ysyl_id,ymn_id,ymx_id,$
         l0,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,diag,$
         cp_id,uex_id,s_id,avl_id,P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,$
         P12,P13,P14,P15,P16,P17,P18,P19,P20

 WIDGET_CONTROL, event.id, GET_UVALUE=uval
 WIDGET_CONTROL, event.top, GET_UVALUE=struct   ; get structure from UVALUE


 case (uval) of
  'done': begin
            file=findfile('dummy.ps')
            sz= size(file)
            if(sz(0) eq 1) then spawn,'/bin/rm dummy.ps'
            ; Load the original color table into display divice:
            tvlct,red,green,blue 
            WIDGET_CONTROL, /DESTROY, struct.pbase
          end
  'help': begin
            xdisplayfile,TITLE='Help',GROUP=event.top, HEIGHT=30, WIDTH=80,$
                         TEXT= get_help()
        end
  'f_name': begin
            WIDGET_CONTROL, file_id, GET_VALUE=filename
            filename= filename(0)
          end
  'get_prof': begin
           WIDGET_CONTROL, set_id, GET_VALUE= prof_num
           prof_num= strupcase(strtrim(prof_num(0),2))
           if(strlen(prof_num) eq 3) then begin
             tmp= avl_profs & tmp(0)= ','+tmp(0)
             avl= where(tmp eq ','+prof_num,cnt)
             if(cnt eq 0) then begin
               WIDGET_CONTROL, diag, SET_VALUE= 'Invalid profile request.' 
               return
             end
             WIDGET_CONTROL, diag, SET_VALUE= 'Active profile: '+prof_num 
             stat= execute("f_st= "+prof_num) 
             WIDGET_CONTROL, l0,SET_VALUE= prof_num+":"
             show_st,[l1,l2,l3,l4,l5,l6,l7,l8,l9,l10],f_st            
           end
       end
  'pval': begin
            pv= strtrim(p_values(event.index),2)
        end
  'linestyle': begin
            lsv= s_values(event.index)
         end
  'psym': begin
            psv= ps_values(event.index)
         end
  'color': begin
           cv= c_values(event.index)
         end
  'splot': begin
            sz= size(f_st)
            if(sz(1) ne 7) then begin
               if(pv ne 'oplot') then begin
                 !mtitle= f_st.mtitle
                 !xtitle= f_st.xtitle
                 !ytitle= f_st.ytitle
                 WIDGET_CONTROL, cp_id,SET_VALUE= prof_num
               endif else begin
                 WIDGET_CONTROL, cp_id,GET_VALUE= cplots
                 WIDGET_CONTROL, cp_id,SET_VALUE= cplots(0)+','+prof_num
               endelse
                plt_cmnd=pv+',f_st.xarr,f_st.yarr,psym='+psv+',linestyle='+lsv+$
                         ',color='+cv
                res=execute(plt_cmnd)
                if(pv eq 'plot_io' or pv eq 'plot') then pind= -1
                pind= pind+1
                if(pind ge 20) then begin 
                  WIDGET_CONTROL, diag,$
                     SET_VALUE='Only up to 20 oplots are allowed.'
                  return
                end
                splots(pind)= plt_cmnd

                font='12x24'
                xloc= string((pind+1)*11+30,'(i3)')
                xyouts='disp_txt,"            "+f_st.xyout,font,'+ $
                       xloc+',def_color='+cv
                res=execute(xyouts)
 
                sxyouts(pind)= xyouts

                WIDGET_CONTROL, diag, SET_VALUE= pv+' done.'
 
            endif else begin
              WIDGET_CONTROL, diag, SET_VALUE= 'Must read in a txt file, first.'
            endelse
         end
  'prnt': begin
            if(pind eq -1) then begin
              WIDGET_CONTROL, diag, SET_VALUE= 'Nothing to print!'
              return
            end
            ans= WIDGET_MESSAGE('Print to '+prname+'?',/question)
            if(ans ne "Yes") then return
            WIDGET_CONTROL, diag, SET_VALUE= 'Printing Plot(s).........'
            WIDGET_CONTROL, /hour
            set_plot,'ps'
            device,/landscape,filename= 'dummy.ps'
            WIDGET_CONTROL, cp_id, GET_VALUE= plt_profs
            pfs= str_sep(plt_profs(0),',')
            ypos=[240,230,220,210,200,190,180,170,160,150,140,130,120,110,100,$
                  90,80,70,60,50]
            for i=0,pind do begin
              pc=str_sep(splots(i),',')
              pstr=pc(0)+','+pfs(i)+'.xarr'+','+pfs(i)+'.yarr'+','+pc(3)+','+ $
                   pc(4)+','+pc(5)
              print,pstr
              res=execute(pstr)
              xystr= 'xyouts,100,'+string(ypos(i),'(i3)')+','+pfs(i)+'.xyout'+ $
                     ','+pc(5)+',/device'
              print,xystr
              res=execute(xystr)
            end
            device,/close_file
            set_plot,'x'
            spawn,'lp -o nobanner -d '+prname+' dummy.ps',/sh
            WIDGET_CONTROL, diag, SET_VALUE= 'Print done.'
       end
  'pr_nm': begin
             WIDGET_CONTROL, pn_id, GET_VALUE= prname
         end
  'save': begin
            if(pind eq -1) then begin
              WIDGET_CONTROL, diag, SET_VALUE= 'Nothing to save!'
              return
            end
            ans= WIDGET_MESSAGE('Save in '+ptname+'?',/question)
            if(ans ne "Yes") then return
            WIDGET_CONTROL, diag, SET_VALUE= 'Saving plot(s).........'
            WIDGET_CONTROL, /hour
            set_plot,'ps'
            device,/landscape,filename= ptname
            WIDGET_CONTROL, cp_id, GET_VALUE= plt_profs
            pfs= str_sep(plt_profs(0),',')
            ypos=[240,230,220,210,200,190,180,170,160,150,140,130,120,110,100,$
                  90,80,70,60,50]
            for i=0,pind do begin
              pc=str_sep(splots(i),',')
              pstr=pc(0)+','+pfs(i)+'.xarr'+','+pfs(i)+'.yarr'+','+pc(3)+','+ $
                   pc(4)+','+pc(5)
              print,pstr
              res=execute(pstr)
              xystr= 'xyouts,100,'+string(ypos(i),'(i3)')+','+pfs(i)+'.xyout'+ $
                     ','+pc(5)+',/device'
              print,xystr
              res=execute(xystr)
            end
            device,/close_file
            set_plot,'x'
            WIDGET_CONTROL, diag, SET_VALUE= 'Save done.'
        end
  'sv_nm': begin
             WIDGET_CONTROL, sn_id, GET_VALUE= ptname
         end
  'erase': begin
             erase
             pind= -1 ; initialize plot index
             WIDGET_CONTROL, cp_id, SET_VALUE= ''
             WIDGET_CONTROL, diag, SET_VALUE= ''
         end
  'xstyle': begin
             !x.style= fix(x_styles(event.index))
          end
  'xmin': begin
            WIDGET_CONTROL, xmn_id, GET_VALUE= tmp
            !xmin= float(tmp(0))
        end
  'xmax': begin
            WIDGET_CONTROL, xmx_id, GET_VALUE= tmp
            !xmax= float(tmp(0))
        end
  'ystyle': begin
             !y.style= fix(y_styles(event.index))
          end
  'ymin': begin
            WIDGET_CONTROL, ymn_id, GET_VALUE= tmp
            !ymin= float(tmp(0))
        end
  'ymax': begin
            WIDGET_CONTROL, ymx_id, GET_VALUE= tmp
            !ymax= float(tmp(0))
        end
  'pick': begin
            filename= pickfile()
            WIDGET_CONTROL, file_id, SET_VALUE=filename
         end
  'read': begin
           WIDGET_CONTROL, /hour

           file= findfile(filename)
           if (filename eq '' or strlen(file(0)) eq 0) then begin
             msg= widget_message('Provide a valid txt filename.')
             WIDGET_CONTROL, diag, SET_VALUE= 'Provide a valid txt filename.'
           endif else begin
             WIDGET_CONTROL, diag, SET_VALUE= 'Reading '+filename+' .....'
             p_st= txtprof2struct(filename,/silent)
             pz=size(p_st)
             if(pz(1) eq 7) then begin
               msg= widget_message(p_st)
               WIDGET_CONTROL, diag, SET_VALUE= 'Provide a valid txt filename.'
               return
             end 
             if(avl_profs(0) eq "NA") then begin 
               avl_profs(0)= 'P01' 
               p01= p_st
             endif else begin
               el= n_elements(avl_profs)+1
               stat=execute("p"+string(el,'(i2.2)')+"= p_st")
               stat=execute("avl_profs= [avl_profs,',P"+string(el,'(i2.2)')+"']")
             endelse

             WIDGET_CONTROL, avl_id, SET_VALUE= avl_profs
;             WIDGET_CONTROL, diag, SET_VALUE= 'Done.'
             f_st= p_st
             prof_num= avl_profs(n_elements(avl_profs)-1)
             if(strpos(prof_num,',') eq 0) then prof_num= strmid(prof_num,1,3)
             WIDGET_CONTROL, l0,SET_VALUE= prof_num+":"
             show_st,[l1,l2,l3,l4,l5,l6,l7,l8,l9,l10],f_st            
             WIDGET_CONTROL, set_id, SET_VALUE= prof_num 
             WIDGET_CONTROL, diag, SET_VALUE= 'Active profile: '+prof_num

           endelse
        end
 endcase

end
 



pro plot_txt_profiles
  common all_data,f_lev,func,p_values,avl_profs,ps_values,c_values,$
         x_styles,y_styles,origname,filename,splots,ver,pind,prof_num,use_func,$
         pv,lsv,psv,cv,plt_cmnd,f_st,set_st,set_elem,subtype,level,ucmnd,uexe,$
         ptname,prname,s_values,red,green,blue,sxyouts
  common all_ids, file_id,st_id,day_id,ver_id,cyc_id,rd_id,set_id,plt_id,$
         x_id,y_id,c_id,mkp_id,pt_id,pn_id,sv_id,sn_id,er_id,d_id,mtle_id,$
         xtle_id,ytle_id,xsyl_id,xmn_id,xmx_id,ysyl_id,ymn_id,ymx_id,$
         l0,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,diag,$
         cp_id,uex_id,s_id,avl_id,P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,$
         P12,P13,P14,P15,P16,P17,P18,P19,P20

;      Save the original color table to be restored at the end:
       tvlct,/get,red,green,blue

;  Create a color table of Black, White, Red, Green, Blue, Yellow, Cyan, and
;  Magenta and load it into the display device:
;         B,W,R,G,B,Y,C,M
       r=[0,1,1,0,0,1,0,1]
       g=[0,1,0,1,0,1,1,0]
       b=[0,1,0,0,1,0,1,1]
       tvlct,255*r,255*g,255*b



    f_st= ''
    set_elem= 0
    pind= -1 ; initialize plot index.
    splots= strarr(20)
    sxyouts= strarr(20)

    tle= 'plot_txt_profiles - A tool to plot profiles contained in text file(s).'

    font='-adobe-times-bold-r-normal--14-140-75-75-p-77-iso8859-1'

;   Declare base as a row:

    pbase= widget_base(title=tle,xoffset=0,/row,/frame)

;   Now devide the base row into two columns lcol and rcol:

    row1= widget_base(pbase,/COL)
    rc= widget_base(row1,/ROW)

    blks='                                 '
    txt= widget_label(rc,value=blks+blks)
    exit=  WIDGET_BUTTON(rc, VALUE='Done',UVALUE='done',/frame)
    txt= widget_label(rc,value='                     ')
    hlp= WIDGET_BUTTON(rc, VALUE='Help',UVALUE='help',/frame)


    row2= widget_base(row1,/ROW)

    lcol= widget_base(row2,/COL,/frame)
    rcol= widget_base(row2,/COL,/frame)
   
    lrow=widget_base(lcol,/ROW)
    rrow=widget_base(rcol,/ROW)
    colb1= widget_base(lrow,/COLUMN)
    rowb1= widget_base(colb1,/ROW)

    avl_profs=["NA"]
    prof_num= avl_profs(0)

    r1= widget_base(rowb1,/ROW,/FRAME)
    dd= widget_base(r1,/ROW)
    r2=widget_base(dd,/COL)
    pick_id= WIDGET_BUTTON(r2,VALUE='PickFile',UVALUE='pick')
  
    lab= WIDGET_LABEL(r2,VALUE="Enter a filename (manually or by PickFile)")
;    filename='22026913.txt'
    filename=''
    file_id= WIDGET_TEXT(r2,UVALUE='f_name',VALUE=filename,/EDITABLE, $
             /ALL_EVENTS,xsize=35,/SCROLL)

    lab= WIDGET_LABEL(dd,VALUE='  ')
    rd_id= WIDGET_BUTTON(dd,VALUE='Read This File',UVALUE='read',/frame)
    lab= WIDGET_LABEL(dd,VALUE='  ')

    ee= widget_base(colb1,/COL) ; not used, for spacing only.
    ee1= widget_base(colb1,/COL) ; not used, for spacing only.

    cc= widget_base(colb1,/COL,/FRAME)
    cc0= widget_base(cc,/ROW)
    txt= WIDGET_LABEL(cc0,value='Available profiles:')
    avl_id= widget_text(cc0,VALUE=avl_profs,xsize=30,FONT=font)

    cc1= widget_base(cc,/ROW)
    l0= WIDGET_LABEL(cc1,VALUE='            ',/align_left,FONT=font)  

    cc3= widget_base(cc,/COL,/frame)
    b= '                                                   '
    l1= WIDGET_LABEL(cc3,VALUE="PARENT          "+b,/align_left)
    l2= WIDGET_LABEL(cc3,VALUE="CAMERA          "+b,/align_left) 
    l3= WIDGET_LABEL(cc3,VALUE="FTSNAME         "+b,/align_left)
    l4= WIDGET_LABEL(cc3,VALUE="DATE            "+b,/align_left)
    l5= WIDGET_LABEL(cc3,VALUE="MTITLE          "+b,/align_left)
    l6= WIDGET_LABEL(cc3,VALUE="XTITLE          "+b,/align_left)
    l7= WIDGET_LABEL(cc3,VALUE="YTITLE          "+b,/align_left)
    l8= WIDGET_LABEL(cc3,VALUE="XYOUT           "+b,/align_left)
    l9= WIDGET_LABEL(cc3,VALUE="XARR            "+b,/align_left)
    l10=WIDGET_LABEL(cc3,VALUE="YARR            "+b,/align_left)
     
;    helps_win,f_st

    ff= widget_base(colb1,/COL) ; not used, for spacing only.
    ff1= widget_base(colb1,/COL) ; not used, for spacing only.

    mm= widget_base(colb1,/COL)
    mm2= widget_base(mm,/ROW)
    txt= WIDGET_LABEL(mm2,VALUE='Currently Plotted:')
    cp_id= WIDGET_TEXT(mm2, VALUE='',xsize=45)

    gg= widget_base(colb1,/COL) ; not used, for spacing only.
    gg1= widget_base(colb1,/COL) ; not used, for spacing only.

    bb= widget_base(colb1,/COL,/FRAME)
    bb1= widget_base(bb,/ROW)
    txt= WIDGET_LABEL(bb1,VALUE="       ")
    pt_id= WIDGET_BUTTON(bb1,VALUE="Print Plot",UVALUE='prnt',/frame)
    txt= WIDGET_LABEL(bb1,VALUE=" -> ")
    prname='hp4-247'
    pn_id= WIDGET_TEXT(bb1,UVALUE='pr_nm',VALUE=prname,xsize=18,/EDITABLE,$
                       /ALL_EVENTS)
    bb2= widget_base(bb,/ROW)
    txt= WIDGET_LABEL(bb2,VALUE="       ")
    sv_id= WIDGET_BUTTON(bb2,VALUE="Save Plot",UVALUE='save',/frame)
    txt= WIDGET_LABEL(bb2,VALUE=" -> ")
    ptname='plot.ps'
    sn_id= WIDGET_TEXT(bb2,UVALUE='sv_nm',VALUE=ptname,xsize=18,/EDITABLE,$
                       /ALL_EVENTS)

    aa= widget_base(colb1,/COL) ; not used, for spacing only.
    aa1= widget_base(colb1,/COL) ; not used, for spacing only.
    

    rr= widget_base(rrow,/COLUMN)
    er_id= WIDGET_BUTTON(rr, VALUE='Erase Plot(s)',UVALUE='erase',/frame)

    d_id= WIDGET_DRAW(rr,xsize=495,ysize=300,retain=2,/frame)

    rr3= widget_base(rr,/ROW)
    x_styles= ['1','0']
    !x.style= 1
    xsyl_id= cw_bselector(rr3,UVALUE='xstyle',x_styles,label_left='          !X.style:')
    !xmin= 0.0
    txt= WIDGET_LABEL(rr3,value="      !Xmin:")
    xmn_id= WIDGET_TEXT(rr3,UVALUE='xmin',VALUE='0.0',/EDITABLE,/ALL_EVENTS,$
                       xsize=6) 
    !xmax= 0.0
    txt= WIDGET_LABEL(rr3,value="     !Xmax:")
    xmx_id= WIDGET_TEXT(rr3,UVALUE='xmax',VALUE='0.0',/EDITABLE,/ALL_EVENTS,$
                       xsize=6)

    rr4= widget_base(rr,/ROW)
    y_styles= ['1','0']
    !y.style= 1
    ysyl_id= cw_bselector(rr4,UVALUE='ystyle',y_styles,label_left='          !Y.style:')
    !ymin= 0.0
    txt= WIDGET_LABEL(rr4,value="      !Ymin:")
    ymn_id= WIDGET_TEXT(rr4,UVALUE='ymin',VALUE='0.0',/EDITABLE,/ALL_EVENTS,$
                       xsize=6) 
    !ymax= 0.0
    txt= WIDGET_LABEL(rr4,value="     !Ymax:")
    ymx_id= WIDGET_TEXT(rr4,UVALUE='ymax',VALUE='0.0',/EDITABLE,/ALL_EVENTS,$
                       xsize=6)

    cc1= widget_base(rr,/ROW)
    cc2= widget_base(rr,/ROW,/frame)
    p_values=['plot','plot_io','oplot']
    pv=p_values(0)
    plt_id= cw_bselector(cc2,UVALUE='pval',p_values,label_left='')
    txt= WIDGET_LABEL(cc2,VALUE=", profile")
    set_id= WIDGET_TEXT(cc2,UVALUE='get_prof',VALUE=prof_num,xsize=3,/EDITABLE,/ALL_EVENTS,FONT=font)

    ps_values=['0','1','2','3','4','5','6','7','10','-1','-2','-3','-4','-5','-6','-7']
    psv= ps_values(0)
    y_id= cw_bselector(cc2,UVALUE='psym',ps_values,label_left=', psym=')
    s_values=['0','1','2','3','4','5']
    lsv= s_values(0)
    s_id= cw_bselector(cc2,UVALUE='linestyle',s_values,label_left=', linestyle=')
    c_values=['1','2','3','4','5','6','7']
    cv= c_values(0)
    c_id= cw_bselector(cc2,UVALUE='color',c_values,label_left=', color=')

    txt= widget_label(rr, VALUE=' ')
    pmsg='Select plot parameters from above and PRESS HERE to plot'
    mkp_id= WIDGET_BUTTON(rr, VALUE=pmsg,UVALUE='splot',/frame)

    msg='                                               '
    
     dg= widget_base(row1,/ROW)
     txt= widget_label(dg,value='                                           ')
     diag= widget_text(dg,VALUE='Enter a filename and press "Read This File" to get started.',xsize=50,FONT=font)


    widget_control,pbase,/realize
    widget_control,d_id,get_value= windex
    wset,windex

    struct={pbase:pbase}
    widget_control,pbase, SET_UVALUE=struct
    xmanager,'plot_txt_profiles',pbase,EVENT_HANDLER='plot_txt_profiles_event',$
             group_leader=group
;             /MODAL


end
