; $Id: dm_save_parameter.pro,v 1.23 2007/11/13 16:19:31 ymqiu Exp $
;#######################################################################
;
; NAME:
;  dm_save_parameter
;
; PURPOSE:
;  save parameters in a file
;
; CATEGORY:
;  dcs_mslice
;
; AUTHOR:
;  Yiming Qiu
;  NIST Center for Neutron Research
;  100 Bureau Drive, Gaithersburg, MD 20899-6102
;  United States
;  yiming.qiu@nist.gov
;  October, 2007
;
; 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 or if the code in this file is
;  included in another product.
;
;#######################################################################

pro dcs_mslice::dm_save_parameter,parmfile
    openw,unit,parmfile,/get_lun,error=openerr
    if openerr ne 0 then begin
       ok = dialog_message("Can't write in "+parmfile+'.',/error,dialog_parent=self.tlb)
       return
    endif
    if ptr_valid(self.absp_info) then begin
       tmp = dm_to_string((*(self.absp_info))[0],/int) +'&'+dm_to_string((*(self.absp_info))[1],/int)
       for i=2,n_elements(*(self.absp_info))-1 do tmp=tmp+'&'+dm_to_string((*(self.absp_info))[i])
       printf,unit,'sshield:'+tmp
    endif
    printf,unit,'in_geom:'+dm_to_string(self.instrgeom)
    printf,unit,'f__type:'+dm_to_string(self.ftype)
    printf,unit,'dcor_eq:'+dm_to_string(self.dcor_eqran[0])+'&'+dm_to_string(self.dcor_eqran[1])+'&'$
                          +dm_to_string(self.dcor_eqran[2])+'&'+dm_to_string(self.dcor_eqran[3])
    printf,unit,'dcor_yn:'+dm_to_string(self.dcor_yn,/int)
    printf,unit,'hklr_yn:'+dm_to_string(self.hklran_yn,/int)
    printf,unit,'edep_yn:'+dm_to_string(self.edep_yn,/int)
    printf,unit,'eadj_yn:'+dm_to_string(self.eadjust,/int)
    printf,unit,'eint_yn:'+dm_to_string(self.eint_yn,/int)
    printf,unit,'selfshd:'+dm_to_string(self.ssfac)
    printf,unit,'datadir:'+self.fileSel->getproperty(/path)
    printf,unit,'viewwin:'+dm_to_string(self.view[0],/int)+'&'+dm_to_string(self.view[1],/int)+'&'+dm_to_string(self.view[2],/int)
    printf,unit,'samptyp:'+dm_to_string(self.samp_typ,/int)
    printf,unit,'intnlab:'+self.intn_lab
    printf,unit,'intntyp:'+dm_to_string(self.intn_typ,/int)
    printf,unit,'binmeth:'+dm_to_string(self.bin_avgsum,/int)
    printf,unit,'ebinsiz:'+dm_to_string(self.e_bin[0],/int)+'&'+dm_to_string(self.e_bin[1],/int)+'&'$
                          +dm_to_string(self.e_bin[2],/int)+'&'+dm_to_string(self.e_bin[3],/int)+'&'$
                          +dm_to_string(self.e_bin[4],/int)
    printf,unit,'e_range:'+dm_to_string(self.e_range[0])+'&'+dm_to_string(self.e_range[1])
    printf,unit,'mon_fit:'+dm_to_string(self.mon_sumfit,/int)
    printf,unit,'dcs_mon:'+dm_to_string(self.dcs_mon,/int)
    printf,unit,'ortharb:'+dm_to_string(self.view_ortharbi)
    printf,unit,'latt__a:'+dm_to_string(float(self.latt_parm[0]))
    printf,unit,'latt__b:'+dm_to_string(float(self.latt_parm[1]))
    printf,unit,'latt__c:'+dm_to_string(float(self.latt_parm[2]))
    printf,unit,'latt_aa:'+dm_to_string(float(self.latt_parm[3]))
    printf,unit,'latt_bb:'+dm_to_string(float(self.latt_parm[4]))
    printf,unit,'latt_cc:'+dm_to_string(float(self.latt_parm[5]))
    printf,unit,'orie_ux:'+dm_to_string(self.orie_u[0],/int)
    printf,unit,'orie_uy:'+dm_to_string(self.orie_u[1],/int)
    printf,unit,'orie_uz:'+dm_to_string(self.orie_u[2],/int)
    printf,unit,'orie_vx:'+dm_to_string(self.orie_v[0],/int)
    printf,unit,'orie_vy:'+dm_to_string(self.orie_v[1],/int)
    printf,unit,'orie_vz:'+dm_to_string(self.orie_v[2],/int)
    printf,unit,'oriepsi:'+dm_to_string(self.orie_psi)
    printf,unit,'view1tp:'+dm_to_string(self.view_u1typ,/int)
    printf,unit,'view2tp:'+dm_to_string(self.view_u2typ,/int)
    printf,unit,'viewu1h:'+dm_to_string(self.view_u1[0],/int)
    printf,unit,'viewu1k:'+dm_to_string(self.view_u1[1],/int)
    printf,unit,'viewu1l:'+dm_to_string(self.view_u1[2],/int)
    printf,unit,'viewu1e:'+dm_to_string(self.view_u1[3],/int)
    printf,unit,'view1lb:'+self.view_u1lab[0]+'&'+self.view_u1lab[1]
    printf,unit,'viewu2h:'+dm_to_string(self.view_u2[0],/int)
    printf,unit,'viewu2k:'+dm_to_string(self.view_u2[1],/int)
    printf,unit,'viewu2l:'+dm_to_string(self.view_u2[2],/int)
    printf,unit,'viewu2e:'+dm_to_string(self.view_u2[3],/int)
    printf,unit,'view2lb:'+self.view_u2lab[0]+'&'+self.view_u2lab[1]
    printf,unit,'viewu3h:'+dm_to_string(self.view_u3[0],/int)
    printf,unit,'viewu3k:'+dm_to_string(self.view_u3[1],/int)
    printf,unit,'viewu3l:'+dm_to_string(self.view_u3[2],/int)
    printf,unit,'viewu3e:'+dm_to_string(self.view_u3[3],/int)
    printf,unit,'view3lb:'+self.view_u3lab
    printf,unit,'dispper:'+dm_to_string(self.disp_perp,/int)
    printf,unit,'disptfr:'+dm_to_string(self.disp_tran[0])
    printf,unit,'disptto:'+dm_to_string(self.disp_tran[1])
    printf,unit,'disphkl:'+dm_to_string(self.disp_hkl,/int)
    printf,unit,'hklr_fr:'+dm_to_string(self.disp_hklran[0])
    printf,unit,'hklr_to:'+dm_to_string(self.disp_hklran[1])
    printf,unit,'dispfld:'+dm_to_string(self.disp_fold,/int)
    printf,unit,'disphfr:'+dm_to_string(self.disp_hran[0])
    printf,unit,'disphto:'+dm_to_string(self.disp_hran[1])
    printf,unit,'disphst:'+dm_to_string(self.disp_hstep)
    printf,unit,'dispvfr:'+dm_to_string(self.disp_vran[0])
    printf,unit,'dispvto:'+dm_to_string(self.disp_vran[1])
    printf,unit,'dispvst:'+dm_to_string(self.disp_vstep)
    printf,unit,'dispifr:'+dm_to_string(self.disp_iran[0])
    printf,unit,'dispito:'+dm_to_string(self.disp_iran[1])
    printf,unit,'dispsmo:'+dm_to_string(self.disp_smooth,/int)
    tmp = dm_to_string(self.disp_sm_kernel)
    tmp = tmp[0]+'&'+tmp[1]+'&'+tmp[2]+'&'+tmp[3]+'&'+tmp[4]+'&'+tmp[5]+'&'+tmp[6]+'&'+tmp[7]+'&'+tmp[8]
    printf,unit,'dispker:'+tmp
    printf,unit,'dispsha:'+dm_to_string(self.disp_shading,/int)
    printf,unit,'dispcol:'+dm_to_string(self.disp_color,/int)
    printf,unit,'cut___x:'+dm_to_string(self.cut_x[0],/int)+'&'+dm_to_string(self.cut_x[1],/int)+'&'$
                          +dm_to_string(self.cut_x[2],/int)+'&'+dm_to_string(self.cut_x[3],/int)
    printf,unit,'cut__fr:'+dm_to_string(self.cut_ran[0])
    printf,unit,'cut__to:'+dm_to_string(self.cut_ran[1])
    printf,unit,'cut__st:'+dm_to_string(self.cut_step)
    printf,unit,'cutt1fr:'+dm_to_string(self.cut_t1ran[0])
    printf,unit,'cutt1to:'+dm_to_string(self.cut_t1ran[1])
    printf,unit,'cutt2fr:'+dm_to_string(self.cut_t2ran[0])
    printf,unit,'cutt2to:'+dm_to_string(self.cut_t2ran[1])
    printf,unit,'cut___y:'+dm_to_string(self.cut_y[0],/int)+'&'+dm_to_string(self.cut_y[1],/int)+'&'$
                          +dm_to_string(self.cut_y[2],/int)+'&'+dm_to_string(self.cut_y[3],/int)
    printf,unit,'cut_yfr:'+dm_to_string(self.cut_yran[0])
    printf,unit,'cut_yto:'+dm_to_string(self.cut_yran[1])
    printf,unit,'cut_sym:'+dm_to_string(self.cut_symbol,/int)
    printf,unit,'cut_col:'+dm_to_string(self.cut_color,/int)
    printf,unit,'cutline:'+dm_to_string(self.cut_line,/int)
    printf,unit,'traj__x:'+dm_to_string(self.traj_x[0],/int)+'&'+dm_to_string(self.traj_x[1],/int)+'&'$
                          +dm_to_string(self.traj_x[2],/int)+'&'+dm_to_string(self.traj_x[3],/int)
    printf,unit,'traj_xf:'+dm_to_string(self.traj_xran[0])
    printf,unit,'traj_xt:'+dm_to_string(self.traj_xran[1])
    printf,unit,'traj__y:'+dm_to_string(self.traj_y[0],/int)+'&'+dm_to_string(self.traj_y[1],/int)+'&'$
                          +dm_to_string(self.traj_y[2],/int)+'&'+dm_to_string(self.traj_y[3],/int)
    printf,unit,'traj_yf:'+dm_to_string(self.traj_yran[0])
    printf,unit,'traj_yt:'+dm_to_string(self.traj_yran[1])
    printf,unit,'traj__z:'+dm_to_string(self.traj_z[0],/int)+'&'+dm_to_string(self.traj_z[1],/int)+'&'$
                          +dm_to_string(self.traj_z[2],/int)+'&'+dm_to_string(self.traj_z[3],/int)
    printf,unit,'traj_zf:'+dm_to_string(self.traj_zran[0])
    printf,unit,'traj_zt:'+dm_to_string(self.traj_zran[1])
    for i=0,self.n_history-1 do begin
        file_hist = (*(self.file_hist[i]))[0]
        for j=1,n_elements(*(self.file_hist[i]))-1 do file_hist=file_hist+string('A4'xb)+(*(self.file_hist[i]))[j]
        printf,unit,'history:'+file_hist
    endfor
    free_lun,unit
end