;$Id: tasxp.pro,v 1.14 2003/10/30 21:09:20 jmspark Exp $
;
; TASXP
;
;

;
; Modification History
;
; 2002.08.29 by Sungil Park
; "Reading in one point data file crashes TASXP" bug fixed.
;
; 2002.08.28 by Sungil Park
; "Canceling at the first dialog crashes DAVE" bug fixed.
;
pro tasxp_event,ev

   message, 'Starts...', /continue

;

;
; Modified 3-11-99 by Carl Adams at NIST Center for Neutron Research
; IDL version 5.1 uses "pickfile_dialog" rather than "pickfile"
; and only accepts one value for filter (which I have made *.bt*)
;
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON colfile,filen
COMMON axwidgets,tasxpbase,xcol,ycol
COMMON fitp,ngau,nlor,a,vary,pnames,gw,ufunct,nufun
COMMON COMMON_fname, name, first_time ;This is used FOR the printing of the plot

type=tag_names(ev,/structure)

IF (type eq 'WIDGET_BUTTON') THEN BEGIN
  widget_control,ev.id,get_value=value,get_uvalue=uvalue
  CASE value of
    'Done': begin
      widget_control,/destroy,ev.top
      end
    'Help':xdisplayfile,filepath('tasxp.hlp') $ ;  subdir='tasxp') $
        , title='TASXP Help'
    'Remove': rpopup
    'X,Y range':xyrange
    'Fit': Xtasfit
    'New File':BEGIN
       pcomm=''
       save=d.prp
       first_time=1    ;Indicate new file
       filen = dave_dialog_pickfile(filter=['*.ng*', '*.bt*'] $
         ,/READ,title='Select a TASCOM file')

      print, 'The selected file is ', filen
      IF (filen ne '') THEN BEGIN
         d=tasrd(filen)

         ; If new data structure is DIFFERENT from the old one.
         IF ((n_elements(d.prp) ne n_elements(save)) or $
            ((n_elements(d.prp) eq n_elements(save)) $
            and (total(d.prp eq save) ne n_elements(save)))) THEN begin

            print, '---------------------- ev.top is ', ev.top
            widget_control, ev.top, get_uvalue = daveStatePtr
            widget_control,ev.top,/destroy

            if (tasid(xax,d) eq -1) then begin
               xax='H'
               IF (tasid(xax,d) eq -1) THEN xax=d.prp(0)
               endif else $
                  if (tasid(yax,d) eq -1) then begin
                     yax='I'
                     IF (tasid(yax,d) eq -1) THEN $
                        IF (n_elements(d.prp) GT 1) THEN yax=d.prp(1) ELSE yax=d.prp(0)
                  endif

               makewind, daveStatePtr = daveStatePtr

           endif

         xmin=0
         xmax=0
         ymin=0
         ymax=0

       ENDIF

       taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr

       fit='false'
       Xtasfit_event,/newfile ;Tell the Xtasfit_event handler new file

       print, '==================== tasxpbase is ', tasxpbase
       xmanager,'tasxp',tasxpbase, cleanup = 'tasxp_cleanup'


       END
    'Subtract':BEGIN
       pcomm=''

       filen=dave_dialog_pickfile( $
         filter= ( !version.release ge 5.4 ? ['*.ng*', '*.bt*'] : '*.ng*' ) $
         ,/READ,title='Select a TASCOM file')
;       filen=dialog_pickfile(filter='*.dat*',title='Select a TASCOM file')
       widget_control,/hour
       IF (filen ne '') THEN d=tassb(d,tasrd(filen),xax)
       xmin=0
       xmax=0
       ymin=0
       ymax=0
       taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr
       fit='false'
       END
    'Transform':deftra
    'Add Field':newf
    'Append':BEGIN
       pcomm=''
       filen=dave_dialog_pickfile($
         filter= ( !version.release ge 5.4 ? ['*.ng*', '*.bt*'] : '*.ng*' ) $
        ,/READ,title='Select a TAS data file')
;       filen=dialog_pickfile(filter='*.dat*',title='Select a TASCOM file')
       IF (filen ne '') THEN d=append(d,tasrd(filen),xax)

       taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr = davePtr
       fit='false'
       END
    'Merge':BEGIN
       pcomm=''
       filen=dave_dialog_pickfile( $
         filter= ( !version.release ge 5.4 ? ['*.ng*', '*.bt*'] : '*.ng*' ) $
      ,/READ,title='Select a TAS data file')
;       filen=dialog_pickfile(filter='*.dat*',title='Select a TASCOM file')
       widget_control,/hour
       IF (filen ne '') THEN d=merge(d,tasrd(filen),xax)
       xmin=0
       xmax=0
       ymin=0
       ymax=0

       taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr = davePtr
       fit='false'
       END
    'Hardcopy':ppopup
    'Write File':BEGIN
       filen=dave_dialog_pickfile(filter='*.dat*',$
          title='TASCOM (*.dat), COLUMN (*.col), or FIT3AX (*.f3a) Filename')
       IF (strlowCASE(strmid(filen,strlen(filen)-3,3)) eq 'col') THEN $
         chooseind ELSE IF (strlowCASE(strmid(filen,strlen(filen)-3,3))$
          eq 'f3a') THEN f3awr,d,filen ELSE IF (filen ne '') THEN taswr,d,filen


       taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr = davePtr
       IF (fit eq 'true') THEN fitov,d,xax,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax
       if (pcomm ne '') then run=execute(pcomm)
       END

   'Write DAVE': begin

     filename = dave_DIALOG_PICKFILE(dialog_parent = ev.top,$
                               title = 'Enter filename',$
                               /write,filter = '*.dave')

     if filename eq '' then return

     widget_control, ev.top, get_uvalue = pState
     state = *(*pState).inPtr
     davePtr = ptr_new(state,/no_copy)
     save, davePtr, FILENAME = filename

     ; ptr_free,davePtr
   end


    ENDCASE
  ENDIF ELSE BEGIN
    widget_control,ev.id,get_value=value,get_uvalue=uvalue
    need_estimate=0
    if (uvalue eq 'PCommand') then goto,sk
    IF (uvalue eq 'x') THEN IF (xax NE d.prp(value)) THEN BEGIN
      xax=d.prp(value)
      need_estimate=1
      ENDIF
    IF (uvalue eq 'y') THEN IF (yax NE d.prp(value)) THEN BEGIN
      yax=d.prp(value)
      need_estimate=1
      ENDIF
    xmin=0
    xmax=0
    ymin=0
    ymax=0
sk:   taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr
    IF (need_estimate) THEN BEGIN
      fit='false'
      if (ufunct eq '') then estpars
      Xtasfit_event, /newfile
      ENDIF ELSE IF (fit EQ 'true') THEN $
        fitov,d,xax,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax
    if (uvalue eq 'PCommand') then pcomm=value(0)
    if (pcomm ne '') then run=execute(pcomm)
    ENDELSE
END

;-----------------------------------------------------------------------------
;User wants to create a new field for the TASCOM data structure
;-----------------------------------------------------------------------------
pro newf_event,ev
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON axwidgets,tasxpbase,xcol,ycol
widget_control,ev.id,get_value=value
widget_control, ev.top, get_uvalue = daveStatePtr
widget_control,ev.top,/destroy
IF (where(value eq d.prp) eq -1) THEN BEGIN
  ty=at(value(0))
  widget_control,tasxpbase,/destroy
  ymin=0
  ymax=0
  yax=value(0)
  makewind, daveStatePtr = daveStatePtr

  taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr = davePtr
  IF (fit EQ 'true') THEN fitov,d,xax,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax
  xmanager,'tasxp',tasxpbase, cleanup = 'tasxp_cleanup'
  ENDIF
END

pro newf
;proceedure to add a new field (column) to the data array
pcomm=''
base=widget_base(/column,title='Add a new field',xsize=300)
fun=widget_base(base,/frame,/column)
lab=widget_label(fun,value="Enter new field name")
space=widget_text(fun,/editable,xsize=20,ysize=1,/scroll,/no_newline)
widget_control,base,/realize
xmanager,'newf',base
END



;-----------------------------------------------------------------------------
;User wants to define a transformation on the data
;-----------------------------------------------------------------------------
pro deftra_event,ev
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
widget_control,ev.id,get_value=value
widget_control,ev.top,/destroy
widget_control,/hour
xefn,d,value,xax,yax
xmin=0 & xmax=0 & ymin=0 & ymax=0

taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr
fit='false'
END

pro deftra
pcomm=''
base=widget_base(/column,title='Transform y-axis =f(x,y,columns)',xsize=400)
fun=widget_base(base,/frame,/column)
lab=widget_label(fun,value="Enter function f eg y-100*x+10*at('gtem') ")
space=widget_text(fun,/editable,xsize=20,ysize=1,/scroll,/no_newline)
widget_control,base,/realize
xmanager,'deftra',base
END

;-----------------------------------------------------------------------------
;User wants to define a new plotting range
;-----------------------------------------------------------------------------
pro xyrange_event,ev
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON rangewid,xmit,xmat,ymit,ymat
widget_control,ev.id,get_value=value,get_uvalue=uvalue
type=tag_names(ev,/structure)
IF (type eq 'WIDGET_BUTTON') THEN BEGIN
CASE value of
  'OK':BEGIN
    widget_control,xmit,get_value=xmin
    xmin=float(xmin(0))
    widget_control,xmat,get_value=xmax
    xmax=float(xmax(0))
    widget_control,ymit,get_value=ymin
    ymin=float(ymin(0))
    widget_control,ymat,get_value=ymax
    ymax=float(ymax(0))
    END
  'Defaults':BEGIN
    xmin=0
    xmax=0
    ymin=0
    ymax=0
    END
  ENDCASE
  widget_control,ev.top,/destroy
  taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr
  IF (fit eq 'true') THEN fitov,d,xax,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax
 ENDIF ELSE BEGIN
  exstr=uvalue+'='+value(0)
  run=execute(exstr)
  ENDELSE
END

pro xyrange
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON rangewid,xmit,xmat,ymit,ymat
base=widget_base(title='Enter axis limits',/column,xsize=250)
xmi=widget_base(base,/row,/frame)
xmil=widget_label(xmi,value='Xmin :')
xmit=widget_text(xmi,/editable,xsize=10,ysize=1,uvalue='xmin',value=strcompress(xmin))
xma=widget_base(base,/row,/frame)
xmal=widget_label(xma,value='Xmax :')
xmat=widget_text(xma,/editable,xsize=10,ysize=1,uvalue='xmax',value=strcompress(xmax))
ymi=widget_base(base,/row,/frame)
ymil=widget_label(ymi,value='Ymin :')
ymit=widget_text(ymi,/editable,xsize=10,ysize=1,uvalue='ymin',value=strcompress(ymin))
yma=widget_base(base,/row,/frame)
ymal=widget_label(yma,value='Ymax :')
ymat=widget_text(yma,/editable,xsize=10,ysize=1,uvalue='ymax',value=strcompress(ymax))
okb=widget_button(base,value='OK')
def=widget_button(base,value='Defaults')
widget_control,base,/realize
xmanager,'xyrange',base
END

;-----------------------------------------------------------------------------
;User has asked to have the TASCOM data printed in column format
;So now we ask for the choice of columns
;-----------------------------------------------------------------------------
pro chooseind_event,ev
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON colfile,filen
widget_control,ev.id,get_value=value
CASE value of
   'Write':BEGIN
       widget_control,ev.top,/destroy
       colwr,d,filen,dindex
       END
   ELSE:IF (ev.select eq 1) THEN BEGIN
       dindex=[dindex,tasid(value,d)]
       ENDIF ELSE dindex=dindex(where(dindex ne tasid(value,d)))
   ENDCASE
END

pro chooseind
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
base=widget_base(title='Select',/column,xsize=150)
xmenu,d.prp,base,/nonexclusive,/frame,/column,buttons=imen_ids
button1=widget_button(base,value='Write')
widget_control,base,/realize
FOR i=0,n_elements(dindex)-1 DO widget_control,imen_ids(dindex(i)),/set_button
xmanager,'chooseind',base
END


;-----------------------------------------------------------------------------
;User wants to remove data. So let him.
;-----------------------------------------------------------------------------
pro rpopup_event,ev
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON rem,rxmin,rxmax,rymin,rymax
widget_control,ev.id,get_value=value
CASE value of
  'Cancel':BEGIN
    widget_control,ev.top,/destroy
    taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr
    fit='false'
    END
  'Remove':BEGIN
    widget_control,ev.top,/destroy
    d=remove(d,xax,rxmin,rxmax,yax,rymin,rymax)
    taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr
    fit='false'
    END
  ENDCASE
END

pro rpopup
COMMON rem,xmin,xmax,ymin,ymax
mess=widget_base(title='Message',xsize=300)
lab=widget_label(mess,value='Select region with mouse')
widget_control,mess,/realize
cursor,xmin,ymin,/data,/down
cursor,xmax,ymax,/data,/down
xline=[xmin,xmin,xmax,xmax,xmin]
yline=[ymin,ymax,ymax,ymin,ymin]
oplot,xline,yline,psym=0,linestyle=0
widget_control,mess,/destroy
base=widget_base(title='Remove data?',xsize=200,/column)
button1=widget_button(base,value='Remove')
button2=widget_button(base,value='Cancel')
widget_control,base,/realize
xmanager,'rpopup',base
END

;*******************************************************************************
;23456789 123456789 123456789 123465798 123456789 123456789 123465789 123456789
;       10        20        30        40        50        60        70        80
;*******************************************************************************
pro makewind, daveStatePtr=daveStatePtr
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON axwidgets,mbase,xcol,ycol

message, 'Starts...', /continue

mbase=widget_base(title='TASXP', /column)
base=widget_base(mbase, /row)
lcol=widget_base(base,/frame,/column,space=5)
rcol=widget_base(base,/frame,/column)
new=widget_button(lcol,value='New File')
mer=widget_button(lcol,value='Merge')
app=widget_button(lcol,value='Append')
sub=widget_button(lcol,value='Subtract')
tra=widget_button(lcol,value='Transform')
nec=widget_button(lcol,value='Add Field')
rem=widget_button(lcol,value='Remove')
ftt=widget_button(lcol,value='Fit')
axs=widget_button(lcol,value='X,Y range')
hcp=widget_button(lcol,value='Hardcopy')
wri=widget_button(lcol,value='Write File')
dav=widget_button(lcol,value='Write DAVE')
hlp=widget_button(lcol,value='Help')
don=widget_button(lcol,value='Done')
draw=widget_draw(rcol,xsize=600,ysize=500)
pltcom=widget_base(mbase,/row)
plttxt=cw_field(pltcom,/row,/string,title='IDL Command:',uvalue='PCommand',$
 value=pcomm,/return_events,xsize=80)
xarr='x'
yarr='y'
xcol=widget_base(base,/column,/scroll,x_scroll_size=125,xsize=90)
ycol=widget_base(base,/column,/scroll,x_scroll_size=125,xsize=90)
xaxis=cw_bgroup(xcol,d.prp,uvalue=xarr,/column,/exclusive,$
ids=xmen_ids,label_top='X axis')
yaxis=cw_bgroup(ycol,d.prp,uvalue=yarr,/column,/exclusive,$
ids=ymen_ids,label_top='Y axis')
widget_control,mbase,/realize
widget_control,xmen_ids(tasid(xax,d)),/set_button
widget_control,ymen_ids(tasid(yax,d)),/set_button
widget_control,get_value=drawind,draw
wset=drawind

; Desensitize the broken buttons.
widget_control, hlp, sensitive = 0

; Create DAVE structure and set it as the user value.
if n_elements( daveStatePtr ) eq 1 then begin
   davePtr = (*daveStatePtr).inPtr
endif
dave_makeDAVEptr, davePtr=davePtr
if ptr_valid( (*(*davePtr).dataStrPtr).commonStr.treatmentPtr ) then $
   heap_free, (*(*davePtr).dataStrPtr).commonStr.treatmentPtr
(*(*davePtr).dataStrPtr).commonStr.treatmentPtr = ptr_new('TASXP')

if n_elements( daveStatePtr ) ne 1 then begin
   daveStatePtr = ptr_new( $
     { notifyIDs:[0L, 0L] $
     , group_leader:0 $
     , inPtr:davePtr $
     , runFlag:0 $
     }, /no_copy )
endif
widget_control, mbase, set_uvalue = daveStatePtr, group_leader = (*daveStatePtr).group_leader

END

;*******************************************************************************
;23456789 123456789 123456789 123465798 123456789 123456789 123465789 123456789
;       10        20        30        40        50        60        70        80
;*******************************************************************************
pro tasxp_cleanup, tlb, daveStatePtr = daveStatePtr

   message, 'Starts...', /continue

   if n_elements( tlb ) eq 1 then begin

     widget_control, tlb, get_uvalue = uvalue, /no_copy
     daveStatePtr = uvalue

   endif else if n_elements( daveStatePtr ) eq 0 then return


   if (*daveStatePtr).runFlag eq 1 then begin
     tasxp_dismiss, (*daveStatePtr).notifyIDs, (*daveStatePtr).inPtr $
      , group_leader= (*daveStatePtr).group_leader
     return
   endif else begin

      message, 'Cleaning Up daveStatePtr.', /continue
      ; free_all_ptrs, daveStatePtr
      heap_free, daveStatePtr

   endelse

end

;*******************************************************************************
;23456789 123456789 123456789 123465798 123456789 123456789 123465789 123456789
;       10        20        30        40        50        60        70        80
;*******************************************************************************
pro tasxp, filen $
   , lorentz=wlorentz $
   , lines=lines $
   , vertresol=vertresol $
   , multi=multi $
   , daveStatePtr = daveStatePtr
;+
; NAME:         TASXP
; PURPOSE:
;               Window based program to process TASCOM files, mainly intENDed
;               FOR combining multiple scans into a single dataset for
;               further analysis, plotting 2D etc. not FOR heavy duty
;               analysis or plotting (yet)
; CATEGORY:
; CALLING SEQUENCE:
;               tasxp
; INPUTS:
; OPTIONAL INPUT PARAMETERS:
;   You may specify the filename eg. tasxp,'happy.dat'
; KEYWORD PARAMETERS:
;   /lorentz - if set, then fitting defaults to lorentzians
; OUPUTS:
; OPTIONAL OUTPUT PARAMETERS:
; COMMON BLOCKS:
;               data- contains the working data structure,d
;                     the x-axis and y-axis indices xax,yax
;                     and indicators whether a fit has
;                     been overlaid
; SIDE EFFECTS:
; RESTRICTIONS:
; PROCEDURE:
; MODIFICATION HISTORY:
;               Thom Mason, Riso National Laboratory, 1993
;       Guangyong Xu, The Johns Hopkins University, 1995, 1996
;      Sungil Park, University of Maryland/NIST, 2001, 2002, 2003
;-
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON fitp,ngau,nlor,a,vary,pnames,gw,ufunct,nufun
COMMON axwidgets,mbase,xcol,ycol
COMMON preferences, pref
COMMON com_minchoice, minchoice, minpath
COMMON COMMON_fname, name, first_time

message, 'Starts...', /continue

; If there is already a TasXP running, quit.
IF xregistered('tasxp') THEN begin
   tasxp_cleanup, daveStatePtr = daveStatePtr
   return
endif

;file name information FOR printout routine
first_time=1

;Process KEYWORD parameters
;
; Since TASXP is usually called without any parameters,
; the default is all ZERO for the pref structure.
; By default, 'symboln' is 1.
;
pref = {wantlorentz:0,lines:0,vert:0,multi_gauss:0}
IF keyword_set(wlorentz) THEN pref.wantlorentz=1 ELSE pref.wantlorentz=0
IF keyword_set(lines) THEN BEGIN
    pref.lines=1
    symboln = -1
END ELSE BEGIN
    pref.lines=0
    symboln=1
END
IF keyword_set(vertresol) THEN pref.vert=1
IF keyword_set(multi) THEN pref.multi_gauss = 1

; Select the file filter according to the IDL version number.
; Recall that IDL 5.4 or later can handle multiple file filters.
if !version.release ge 5.4 then begin
   file_filter = ['*.n*', '*.b*', '*.N*', '*.B*']
endif else begin
   file_filter = '*.b*'
endelse

; Check whether we have a valid DAVE pointer.
; If not, read in the designated data file.

; help, (*(*(*daveStatePtr).inPtr).dataStrPtr).commonStr, /struct
Good_Dave = 1
if ptr_valid( daveStatePtr ) then Good_Dave = Good_Dave * 1 else Good_Dave = 0
if Good_Dave then Good_Dave = Good_Dave * dave_valid( (*daveStatePtr).inPtr, /full )
if Good_Dave then begin

   commonStr = (*(*(*daveStatePtr).inPtr).dataStrPtr).commonStr
   histStr = *(*(*(*daveStatePtr).inPtr).dataStrPtr).commonStr.histPtr

   ; Assuming 1D data,
   x = histStr.x
   f = histStr.qty
   e = histStr.err

   fLabel = commonStr.histLabel
   if fLabel eq '' then fLabel = 'I'

   points = n_elements( f )
   text = 'DAVE DATA'

   heads = 1
   hdef = 'No Header'
   hnum = 0.0

   pars = 3
   prp = [ commonStr.xLabel, fLabel, 'SIGI' ]
   data = transpose( [ [ x ], [ f ], [ e ] ] )

   d = { points:points, text:text $
      , heads:heads, hdef:hdef, hnum:hnum $
      , pars:pars, prp:prp, data:data }

endif else begin

      ; Select a TAS data file or goto 'nofile'.
   IF (n_params() eq 0) THEN $

      filen = dave_dialog_pickfile( $
         filter=file_filter, /read, title='Select a TAS data file')

      if (filen eq '') then begin
         tasxp_cleanup, daveStatePtr = daveStatePtr
         return
      endif

      d = tasrd(filen, error = error)
      if error eq -1 then begin
         tasxp_cleanup, daveStatePtr = daveStatePtr
         return
      endif

endelse

xmin=0.0
xmax=0.0
ymin=0.0
ymax=0.0
fit='false'
pcomm=''

minpath = ' '               ;DOS can't do shared libraries
minchoice='SFit'            ;So use the dumb minimizer

; Select X-axis and Y-axis.
; Default is using 'H' and 'I'.
; If they don't exists, the 1st and the 2nd columns will be used.
xax='H'
IF (tasid(xax,d) eq -1) THEN xax=d.prp(0)
yax='I'
IF (tasid(yax,d) eq -1) THEN BEGIN
    IF (n_elements(d.prp) GT 1) THEN yax=d.prp(1) ELSE yax=d.prp(0)
END

; Estimate fit parameters.
estpars

dindex = indgen(n_elements(d.prp))

makewind, daveStatePtr = daveStatePtr
taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax

print, '==================== mbase is ', mbase
xmanager,'tasxp',mbase, cleanup = 'tasxp_cleanup'

nofile:
END
