; Written by  Craig Brown
;************************************************************************************************
;###############################################################################
;
; 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.
;
;###############################################################################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_remove_char,str,char
char_pos = strpos(str,char)
while char_pos[0] ne -1 do begin
   str_len = strlen(str)
   if char_pos eq 0 then begin
      str = strmid(str,1,str_len-1)
   endif
   if char_pos eq (str_len-1) then begin
      str = strmid(str,0,str_len-1)
   endif
   if char_pos ne 0 and char_pos ne str_len-1 then begin
      str1 = strmid(str,0,char_pos)
      str2 = strmid(str,char_pos+1,str_len-char_pos)
      str = str1+str2
   endif
   char_pos = strpos(str,char)
endwhile
return,str
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data_remove_quotes,line
; Removes all (single) quotation marks
new_line = ddcs_remove_char(line,"'")
return,new_line
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ddcs_data::cleanup

ptr_free,self.qty_ptr
ptr_free,self.err_ptr
ptr_free,self.variables_read_ptr
ptr_free,self.variables_unknown_ptr
ptr_free,self.time_props_ptr
ptr_free,self.energy_props_ptr
ptr_free,self.angle_props_ptr
ptr_free,self.Q_props_ptr
ptr_free,self.normalization_sum
ptr_free,self.fbnormalization_sum
ptr_free,self.treatment_ptr
ptr_free,self.bitflips_ptr
ptr_free,self.x_ptr
ptr_free,self.y_ptr


end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::sanity_check,value=value
; N.B. timsum is sum over detectors as function of time channel (size 1024)
;      detsum is sum over time as function of detector number (size 931)
;
; From an email to Nick, expressed in Octave language,
;
; grandsum(0)=sum(sum(histodata))
; grandsum(1)=sum(detsum(0:912))
; grandsum(2)=sum(sum(histohigh))
; grandsum(3)=sum(detsum(913:929))
; grandsum(4)=grandsum(0)+grandsum(2)
; grandsum(5)=sum(detsum)
; grandsum(6)=sum(timsum)
; grandsum(7)=sum(sum(totals))
ratiocriterion=self.ratiocriterion
maxbitflips=self.maxbitflips
bitflips=*self.bitflips_ptr
printlines=''

case value of
;
; Detailed sanity checks.
       1: begin
         print,"OTHER Sanity Checks should be placed here"
       end
;
;   Mandatory sanity checks only.
       0: begin
         print,"Easy Sanity Checks"
            ; Sanity check # 1; look for bitflips.
         grandsum=self.grandsum
         fail1=(grandsum[4] ne grandsum[5])
         fail2=(grandsum[4] ne grandsum[6])
         fail3=(grandsum[4] ne grandsum[7])
         if (not (fail1 or fail2 or fail3)) then begin
         Print,"PASSED GRANDSUM CHECKS"
        endif else begin
         self.insane[0]=1
         Print,"FAILED GRANDSUM CHECKS"
         lines=["Failed SANITY CHECK 0:",$
         "  grandsum[4] = "+strcompress(grandsum[4])]
         for i=1,3 do begin
         diff=grandsum[4]-grandsum[i+4]
         if (diff gt 0) then power=strcompress(alog(diff)/alog(2),/remove_all)
         if (diff lt 0) then power=strcompress("-"+alog(-diff)/alog(2),/remove_all)
         if (diff ne 0) then begin
          newline1="  grandsum["+strcompress(i+4,/remove_all)+$
              "] = "+strcompress(grandsum[i+4])
          newline2="  grandsum[4]-grandsum["+strcompress(i+4,/remove_all)+$
              "] = 2^"+strcompress(power)+" = "+strcompress(diff)+", i.e. "+$
              strcompress(dcs_dec2bin(diff))
          lines=[lines,newline1,newline2]
         endif
       endfor
        endelse

        ;   Sum He3 data and high end data over detectors and time channels
       tdh1=[long(total(*self.qty_ptr,1,/double)),$
                 long(total(self.histohigh,1,/double))]-self.detsum
       tdh2=long(total(*self.qty_ptr,2,/double))+$
                 long(total(self.histohigh,2,/double))-$
                 self.timsum
       ;
       bad_t=where(tdh2 ne 0,tcount); disagreement in time sums over detector
       bad_d=where(tdh1 ne 0,dcount); disagreement in detector sums over time

        if (dcount eq 1 and tcount eq 1) then begin
         badt=bad_t[0]
         badd=bad_d[0]
         newline="  "+strcompress("Single bitflip occurred at [time,detector] = ["+$
          string(badt)+","+string(badd)+"].")
         lines=[lines,newline]
         bitflips[0,0]=badt
         bitflips[1,0]=badd
         bitflips[2,0]=tdh1[badd]
       endif else begin
         tdcount=0
         for it=0,tcount-1 do begin
          for id=0,dcount-1 do begin
              if (tdh2[bad_t[it]] eq tdh1[bad_d[id]]) then tdcount=tdcount+1
          endfor
         endfor
         if (tdcount le maxbitflips) then begin
          ibitflip=-1
          for it=0,tcount-1 do begin
              for id=0,dcount-1 do begin
                 if (tdh2[bad_t[it]] eq tdh1[bad_d[id]]) then begin
                   value=tdh1[bad_d[id]]
                   newline=strcompress("  Bitflip occurred at [time,detector] = ["+$
                    string(bad_t[it])+","+string(bad_d[id])+"]: value = "+string(value)+".")
                   lines=[lines,newline]
                   ibitflip=ibitflip+1
                   bitflips[0,ibitflip]=bad_t[it]
                   bitflips[1,ibitflip]=bad_d[id]
                   bitflips[2,ibitflip]=tdh1[bad_d[id]]
                 endif
              endfor
          endfor
         endif else begin
          lines=[lines,"  Time channels (0-1023) with disagreement in sums over detector number:",$
              "  "+strjoin(strcompress(bad_t[0:(20<(n_elements(bad_t)-1))])," :"),$
              "  Detector numbers (0-912) with disagreement in sums over time:",$
              "  "+strjoin(strcompress(bad_d[0:(20<(n_elements(bad_d)-1))])," :")]
         endelse
       endelse

    ch_ms=self.ch_ms
    ch_srdenom=self.ch_srdenom
    speriod=(60000000.0/ch_ms)*ch_srdenom
;
; Define the number of good time channels for the He3 detectors,
; ngtchan0, putting it in davePtr.
    twid=self.tchanlook[0,*]*0.05
    times=[0,reform(total(twid,/cumulative))]
    tstart=times[0:self.ntchan-1]
    tstop=times[1:self.ntchan]
    chan=where(tstart le speriod-0.05 and tstop gt speriod-0.05) + 1
    ngtchan0=chan[0]
    self.ngtchan0=ngtchan0
    print,ngtchan0
;
; Define the number of good time channels for the high end inputs,
; ngtchan1, putting it in davePtr.
    twid=self.tchanlook[1,*]*0.05
    times=[0,reform(total(twid,/cumulative))]
    tstart=times[0:self.ntchan-1]
    tstop=times[1:self.ntchan]
    chan=where(tstart le speriod-0.05 and tstop gt speriod-0.05) + 1
    ngtchan1=chan[0]
    self.ngtchan1=ngtchan1

; time mismatches
       failed0=abs(speriod-tstart[ngtchan0]) gt 0.05
       failed1=abs(speriod-tstart[ngtchan1]) gt 0.05
       if (failed0 or failed1) then $
         lines=["File "+fileread,"  failed SANITY CHECK 2:"]
       if (failed0) then begin
         self.insane[1]=1
         lines=[lines,$
          "  The time between pulses at the sample,"+strcompress(speriod)+" us,",$
          "   does not correspond to a whole number of LOW END time channels.",$
          "  Time channel"+strcompress(chan[0]-1)+$
          " starts at"+strcompress(tstart[chan[0]-1])+" us"+$
          " and ends at"+strcompress(tstop[chan[0]-1])+" us.",$
          "  The data reduction may be compromised."]
       endif
       if (failed1) then begin
         self.insane[1]=1
         lines=[lines,$
          "  The time between pulses at the sample,"+strcompress(speriod)+" us,",$
          "   does not correspond to a whole number of HIGH END time channels.",$
          "  Time channel"+strcompress(chan[0]-1)+$
          " starts at"+strcompress(tstart[chan[0]-1])+" us"+$
          " and ends at"+strcompress(tstop[chan[0]-1])+" us.",$
          "  The data reduction may be compromised."]

       endif
       if (failed0 or failed1) then printlines=[printlines,lines]



; Sanity check # 3. Look for counts in channels between firstbadtchan and lastbadtchan.
; First define firstbadtchan and lastbadtchan.
       firstbadtchan=self.ngtchan0
       lastbadtchan=self.ntchan-1
       if (firstbadtchan le lastbadtchan) then begin
         badtimes=where(self.timsum[firstbadtchan:lastbadtchan] gt 0, count)
         if (count gt 0) then begin
          self.insane[2]=1
          lines=["File failed SANITY CHECK 3:"]
          newline1="  Non-empty time channels (that should be empty)"+$
              strjoin(strcompress(firstbadtchan+badtimes))
          newline2="  Contents of these time channels:"+$
              strjoin(strcompress(self.timsum[firstbadtchan+badtimes]))
          lines=[lines,newline1,newline2]
          printlines=[printlines,lines]
         endif
       endif

; THIS HAS PROBLEMS...COMPARE DIMENSIONS IN DAVE
;
; Sanity check # 4. Check that ratio of "fast chopper" counts to "slow chopper"
;     counts is essentially equal to frame overlap denominator.

;
;       denominator=self.ch_input[4]
;       and_counts=0
;       ch_counts=lonarr(7)
;       startchoice=strmid(self.startchoice,0,3)
;       for k=0,16 do begin
;         string123=strmid(self.highsource[k],0,3)
;         if (string123 eq startchoice) then summed_counts=self.nframes else $
;          summed_counts=self.detsum[913+k]
;         if (string123 eq "AND") then and_counts=summed_counts
;         if (string123 eq "CH1") then ch_counts[0]=summed_counts
;         if (string123 eq "CH2") then ch_counts[1]=summed_counts
;         if (string123 eq "CH3") then ch_counts[2]=summed_counts
;         if (string123 eq "CH4") then ch_counts[3]=summed_counts
;         if (string123 eq "CH5") then ch_counts[4]=summed_counts
;         if (string123 eq "CH6") then ch_counts[5]=summed_counts
;         if (string123 eq "CH7") then ch_counts[6]=summed_counts
;       endfor
;;
;       quantity=abs(denominator*and_counts/ch_counts[6]-1.0)
;       if (quantity gt ratiocriterion) then begin
;         self.insane[3]=1
;         lines=["File "+self.filename,"  failed SANITY CHECK 4:"]
;         newline1="  Frame overlap denominator = "+strcompress(denominator)
;         newline2="  Chopper 7 counts = "+strcompress(ch_counts[6])
;         newline3="  Coincidence counts = "+strcompress(and_counts)
;         lines=[lines,newline1,newline2,newline3]
;         printlines=[printlines,lines]
;       endif
;;

; Sanity check # 5. Look for invalid boards.
       if (self.badbrd ne 0) then begin
         self.insane[4]=1
         lines=["File "+fileread,"  failed SANITY CHECK 5:"]
         lines=[lines,"  INVALID BOARD"+strcompress(self.badbrd),$
          "","File "+fileread]
         printlines=[printlines,lines]
       endif

; Sanity check # 6. Look for invalid detectors.
       if (self.baddet ne 0) then begin
         self.insane[5]=1
         lines=["File "+fileread,"  failed SANITY CHECK 6:"]
         lines=[lines,"  INVALID DETECTOR"+strcompress(self.baddet),$
          "","File "+fileread]
         printlines=[printlines,lines]
       endif

; Sanity check # 7. Look for repeats and resets.

       badboards_p0=where(self.repeats[0,*] gt 0, count_p0)
       badboards_r0=where(self.resets[0,*] gt 0, count_r0)
       badboards_p1=where(self.repeats[1,*] gt 0, count_p1)
       badboards_r1=where(self.resets[1,*] gt 0, count_r1)
;
       if (count_p0+count_r0+count_p1+count_r1 gt 0) then begin
         self.insane[6]=1
         lines=["File  failed SANITY CHECK 7:"]
         line=3
         if (count_p0 gt 0) then begin
          lines=[lines,"  Nonzero repeats for crate 0 boards "+$
              strjoin(strcompress(long(badboards_p0)))]
          numbers=long(self.repeats[0,badboards_p0])
          if (count_p0 gt 1) then numbers=transpose(numbers)
          lines=[lines,"  Numbers of repeats are "+strjoin(strcompress(numbers))]
         endif
         if (count_r0 gt 0) then begin
          lines=[lines,"  Nonzero resets for crate 0 boards "+$
              strjoin(strcompress(long(badboards_r0)))]
          numbers=long(self.resets[0,badboards_r0])
          if (count_r0 gt 1) then numbers=transpose(numbers)
          lines=[lines,"  Numbers of resets are "+strjoin(strcompress(numbers))]
         endif
         if (count_p1 gt 0) then begin
          lines=[lines,"  Nonzero repeats for crate 1 boards "+$
              strjoin(strcompress(long(badboards_p1)))]
          numbers=long(self.repeats[1,badboards_p1])
          if (count_p1 gt 1) then numbers=transpose(numbers)
          lines=[lines,"  Numbers of repeats are "+strjoin(strcompress(numbers))]
         endif
         if (count_r1 gt 0) then begin
          lines=[lines,"  Nonzero resets for crate 1 boards "+strjoin(strcompress(long(badboards_r1)))]
          numbers=long(self.resets[1,badboards_r1])
          if (count_r1 gt 1) then numbers=transpose(numbers)
          lines=[lines,"  Numbers of resets are "+strjoin(strcompress(numbers))]
         endif
         printlines=[printlines,lines]
       endif

n_insane=total(self.insane)
if ((n_insane) eq 0) then return,1


;
; set the new values:
    if n_elements(lines) ne 0 then begin
       *self.treatment_ptr=[*self.treatment_ptr,lines]
       *self.bitflips_ptr=bitflips
    endif else begin
       *self.bitflips_ptr=bitflips
    endelse
    end
;
       else: return,1
endcase


return,1
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::update_display_name,str
ppos = strpos(self.display_name,'.')
if ppos eq -1 then return,0
extension = strmid(self.display_name,ppos)
beginning = strmid(self.display_name,0,ppos)
self.display_name = beginning+str+extension
return,1
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::get_property,   filename = filename,             $
                                    extension = extension,           $
                                    signal_type = signal_type,       $
                                    ntchan = ntchan,                 $
                                    nhedet = nhedet,                 $
                                    display_name = display_name,     $
                                    user = user,                     $
                                    command = command,               $
                                    comments = comments,             $
                                    start_date=start_date,           $
                                    stop_date=stop_date,             $
                                    duration=duration,               $
                                    cduration_csum=cduration_csum,     $
                                    sample_desc=sample_desc,         $
                                    ch_wl = ch_wl          ,         $
                                    ch_ms = ch_ms,                   $
                                    ch_res = ch_res,                 $
                                    ch_srmode=ch_srmode,             $
                                    ch_srdenom=ch_srdenom,           $
                                    tsdmin=tsdmin,                   $
                                    ch_phase=ch_phase,               $
                                    ch_delay=ch_delay,               $
                                    temp_sample = temp_sample,       $
                                    temp_control = temp_control,     $
                                    temp_setpoint = temp_setpoint,   $
                                    repeats=repeats,                 $
                                    resets=resets,                   $
                                    badbrd=badbrd,                   $
                                    baddet=baddet,                   $
                                    bitflips=bitflips,               $
                                    ch_input=ch_input,               $
                                    ch_slots=ch_slots,               $
                                    coll_amp=coll_amp,               $
                                    coll_mean=coll_mean,             $
                                    tchanlook=tchanlook,             $
                                    startchoice=startchoice,         $
                                    highsource=highsource,           $
                                    fc_dis=fc_dis,                   $
                                    det_dis=det_dis,                 $
                                    ch_dis=ch_dis,                   $
                                    ch_bid=ch_bid,                   $
                                    ngtchan1=ngtchan1,               $
                                    n0ngtchan = n0ngtchan,           $ ; i.e.  ngtchan0
                                    detsum=detsum,                   $
                                    histohigh=histohigh,             $
                                    maxbitflips=maxbitflips,         $
                                    nframes=nframes,                 $
                                    qty=qty,                         $
                                    err=err,                         $
                                    ncycles=ncycles,                 $
                                    grandsum=grandsum,               $
                                    totals=totals,                   $
                                    timsum=timsum,                   $
                                    he3_csum=he3_csum,               $
                                    high_csum=high_csum,             $
                                    time_props=time_props,           $
                                    Q_props=Q_props,                 $
                                    angle_props=angle_props,         $
                                    energy_props=energy_props,      $
                                    normalization_sum=normalization_sum,$
                                    fbnormalization_sum=fbnormalization_sum,$
                                    treatment = treatment, $
                                    xvals=xvals,                         $
                                    yvals=yvals,                         $
                                    xlabel=xlabel,                       $
                                    ylabel=ylabel,                       $
                                    xtype=xtype,                         $
                                    ytype=ytype,                         $
                                    yunits=yunits,                       $
                                    xunits=xunits,                       $
                                    histlabel=histlabel,                 $
                                    plot_sums=plot_sums



if arg_present(signal_type) then signal_type = self.signal_type
if arg_present(extension) then extension = self.extension
if arg_present(filename) and self.filename ne '' then begin
   filename = self.filename
endif
if arg_present(energy_props) then begin
     if n_elements(*self.energy_props_ptr) ne 0 then $
      energy_props=*self.energy_props_ptr
endif
if arg_present(normalization_sum) then begin
     if n_elements(*self.normalization_sum) ne 0 then $
      normalization_sum=*self.normalization_sum
endif
if arg_present(fbnormalization_sum) then begin
     if n_elements(*self.fbnormalization_sum) ne 0 then $
      fbnormalization_sum=*self.fbnormalization_sum
endif

if arg_present(display_name) then display_name = self.display_name
if arg_present(user) then user = self.user
if arg_present(command) then command = self.command
if arg_present(comments) then comments = self.comments
if arg_present(start_date) then start_date = self.start_date
if arg_present(stop_date) then stop_date = self.stop_date
if arg_present(duration) then duration = self.duration
if arg_present(cduration_csum) then cduration_csum = self.duration_csum
if arg_present(sample_desc) then sample_desc = self.sample_desc
if arg_present(ch_wl) then ch_wl = self.ch_wl
if arg_present(ch_ms) then ch_ms = self.ch_ms
if arg_present(ch_res) then ch_res = self.ch_res
if arg_present(ch_srmode) then ch_srmode = self.ch_srmode
if arg_present(ch_srdenom) then ch_srdenom = self.ch_srdenom
if arg_present(tsdmin) then tsdmin = self.tsdmin
if arg_present(ch_phase) then ch_phase = self.ch_phase
if arg_present(ch_delay) then ch_delay = self.ch_delay

if arg_present(temp_sample) then temp_sample = self.temp_sample
if arg_present(temp_control) then temp_control = self.temp_control
if arg_present(temp_setpoint) then temp_setpoint = self.temp_setpoint

if arg_present(repeats) then repeats = self.repeats
if arg_present(resets) then resets = self.resets
if arg_present(badbrd) then badbrd = self.badbrd
if arg_present(baddet) then baddet = self.baddet
if arg_present(bitflips) then bitflips = *self.bitflips_ptr
if arg_present(ch_input) then ch_input = self.ch_input
if arg_present(ch_slots) then ch_slots = self.ch_slots
if arg_present(coll_mean) then coll_mean = self.coll_mean
if arg_present(coll_amp) then coll_amp = self.coll_amp
if arg_present(tchanlook) then tchanlook = self.tchanlook
if arg_present(startchoice)then  startchoice = self.startchoice
if arg_present(highsource) then highsource = self.highsource
if arg_present(fc_dis) then fc_dis = self.fc_dis
if arg_present(ch_dis) then ch_dis = self.ch_dis
if arg_present(ch_bid) then ch_bid = self.ch_bid
if arg_present(det_dis) then det_dis = self.det_dis
if arg_present(ntchan) then ntchan = self.ntchan
if arg_present(nhedet) then nhedet = self.nhedet
if arg_present(n0ngtchan) then n0ngtchan = self.ngtchan0
if arg_present(ngtchan1) then  ngtchan1 = self.ngtchan1
if arg_present(nframes) then nframes = self.nframes
if arg_present(histohigh) then histohigh = self.histohigh
if arg_present(maxbitflips) then maxbitflips = self.maxbitflips
if arg_present(qty) then qty = *self.qty_ptr
if arg_present(err) then err = *self.err_ptr
if arg_present(ncycles) then ncycles = self.ncycles
if arg_present(grandsum) then grandsum = self.grandsum
if arg_present(totals) then totals = self.totals
if arg_present(timsum) then timsum = self.timsum
if arg_present(detsum) then detsum = self.detsum
if arg_present(he3_csum) then he3_csum = self.he3_csum
if arg_present(high_csum) then high_csum = self.high_csum
if arg_present(time_props) then time_props = *self.time_props_ptr
if arg_present(Q_props) then Q_props = *self.Q_props_ptr
if arg_present(angle_props) then angle_props = *self.angle_props_ptr
if arg_present(xvals) then       begin
       if n_elements(*self.x_ptr) ne 0 then xvals=*self.x_ptr
endif
if arg_present(yvals) then begin
        if n_elements(*self.y_ptr) ne 0 then yvals=*self.y_ptr
endif
if arg_present(xlabel) then xlabel=self.xlabel
if arg_present(ylabel) then ylabel=self.ylabel
if arg_present(xtype) then  xtype=self.xtype
if arg_present(ytype) then  ytype=self.ytype
if arg_present(yunits) then yunits=self.yunits
if arg_present(xunits) then xunits=self.xunits
if arg_present(histlabel) then histlabel=self.histlabel


if arg_present(treatment) and self.filename ne '' then begin
   treatment = *self.treatment_ptr
endif

if arg_present(plot_sums) then begin
   plot_sums=total(*self.qty_ptr,1)
endif


return,1
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::set_property,   filename = filename,                $
                                    signal_type = signal_type,          $
                                    display_name = display_name,        $
                                    ntchan = ntchan,                    $
                                    nhedet = nhedet,                    $
                                    qty = qty,                          $
                                    err = err,                          $
                                    badbrd=badbrd,                      $
                                    baddet=baddet,                      $
                                    duration=duration,                  $
                                    nframes=nframes,                    $
                                    ncycles=ncycles,                    $
                                    detsum=detsum,                      $
                                    grandsum=grandsum,                  $
                                    histohigh=histohigh,                $
                                    repeats=repeats,                    $
                                    resets=resets,                      $
                                    timsum=timsum,                      $
                                    totals=totals,                      $
                                    datamax=datamax,                    $
                                    highmax=highmax,                    $
                                    temp_setpoint=temp_setpoint,        $
                                    command=command,                    $
                                    comments=comments,                  $
                                    sample_desc=sample_desc,            $
                                    start_date=start_date,              $
                                    stop_date=stop_date,                $
                                    user=user,                          $
                                    cduration_csum=cduration_csum,        $
                                    he3_csum=he3_csum,                  $
                                    high_csum=high_csum,                $
                                    temp_control=temp_control,          $
                                    temp_sample=temp_sample,            $
                                    normalization_sum=normalization_sum,$
                                    fbnormalization_sum=fbnormalization_sum,$
                                    xval=xval,                                $
                                    yval=yval,                                $
                                    xlabel=xlabel,                      $
                                    ylabel=ylabel,                      $
                                    xtype=xtype,                        $
                                    ytype=ytype,                        $
                                    yunits=yunits,                      $
                                    xunits=xunits,                      $
                                    Q_props=Q_props,                    $
                                    angle_props=angle_props,            $
                                    histlabel=histlabel,                $
                                    treatment=treatment



if n_elements(treatment) ne 0 then *self.treatment_ptr=treatment
if n_elements(qty) ne 0 then *self.qty_ptr=qty
if n_elements(err) ne 0 then *self.err_ptr=err
if n_elements(badbrd) ne 0 then self.badbrd=badbrd
if n_elements(baddet) ne 0 then self.baddet=baddet
if n_elements(duration) ne 0 then self.duration=duration
if n_elements(nframes) ne 0 then self.nframes=nframes
if n_elements(ncycles) ne 0 then self.ncycles=ncycles
if n_elements(detsum) ne 0 then self.detsum=detsum
if n_elements(grandsum) ne 0 then self.grandsum=grandsum
if n_elements(histohigh) ne 0 then self.histohigh=histohigh
if n_elements(repeats) ne 0 then self.repeats=repeats
if n_elements(resets) ne 0 then self.resets=resets
if n_elements(timsum) ne 0 then self.timsum=timsum
if n_elements(totals) ne 0 then self.totals=totals
if n_elements(datamax) ne 0 then self.datamax=datamax
if n_elements(highmax) ne 0 then self.highmax=highmax
if n_elements(temp_setpoint) ne 0 then self.temp_setpoint=temp_setpoint
if n_elements(command) ne 0 then self.command=command
if n_elements(comments) ne 0 then self.comments=comments
if n_elements(sample_desc) ne 0 then self.sample_desc=sample_desc
if n_elements(start_date) ne 0 then self.start_date=start_date
if n_elements(stop_date) ne 0 then self.stop_date=stop_date
if n_elements(user) ne 0 then self.user=user
if n_elements(cduration_csum) ne 0 then self.duration_csum=cduration_csum
if n_elements(he3_csum) ne 0 then self.he3_csum=he3_csum
if n_elements(high_csum) ne 0 then self.high_csum=high_csum
if n_elements(temp_control) ne 0 then self.temp_control=temp_control
if n_elements(temp_sample) ne 0 then self.temp_sample=temp_sample
if n_elements(normalization_sum) ne 0 then *self.normalization_sum=normalization_sum
if n_elements(fbnormalization_sum) ne 0 then *self.fbnormalization_sum=fbnormalization_sum
if n_elements(signal_type) ne 0 then self.signal_type = signal_type
if n_elements(display_name) ne 0 then self.display_name = display_name
if n_elements(filename) ne 0 then self.filename = filename
if n_elements(ntchan) ne 0 then self.ntchan = ntchan
if n_elements(nhedet) ne 0 then self.nhedet = nhedet
;ambiguous
if n_elements(xval) ne 0 then *self.x_ptr=xval
; ambiguous
if n_elements(yval) ne 0 then *self.y_ptr=yval

if n_elements(xlabel) ne 0 then self.xlabel=xlabel
if n_elements(ylabel) ne 0 then self.ylabel=ylabel
if n_elements(xtype) ne 0 then self.xtype=xtype
if n_elements(ytype) ne 0 then self.ytype=ytype
if n_elements(yunits) ne 0 then self.yunits=yunits
if n_elements(xunits) ne 0 then self.xunits=xunits

if n_elements(histlabel) ne 0 then self.histlabel=histlabel
if n_elements(Q_props) ne 0 then *self.Q_props_ptr = Q_props
if n_elements(angle_props) ne 0 then *self.angle_props_ptr = angle_props
if n_elements(histlabel)  ne 0 then self.histlabel=histlabel

return,1
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::read_file
if not file_test(self.filename) then return,0
catch,the_error
if the_error ne 0 then begin
   catch,/cancel
   void = dialog_message(!error_state.msg)
   if n_elements(lun) ne 0 then free_lun,lun,/force
   return,0
endif
; What is the file extension?
ppos = strpos(self.filename,'.')
self.extension = strmid(self.filename,ppos+1)

forbidden_char = ['#','-','(',')','.'] ; these characters cannot be structure
; tag names.
n_forbidden = n_elements(forbidden_char)
; Get the display name out
ret= self->ddcs_get_filename(self.filename)

;From John Copley read proceedure:---------------------------------------------------------------------------------
; Determine whether or not file is compressed.
ending=strmid(self.filename,2,3,/reverse_offset)
compressed=(ending eq ".gz")
; Read header to determine byte ordering ("endianness") of input file.
openr,lun,self.filename,compress=compressed,/get_lun
header=bytarr(11)
readu,lun,header
free_lun,lun,/force
;
; When opening the file take into account the endianness of the computer that is **reading** the file.
; Goran Gasparovic pointed out that my original coding (commented out) was incorrect.
case string(header[9]) of
;   "B": openr,unit,filepath,/swap_endian,compress=compressed,/get_lun
;   "L": openr,unit,filepath,compress=compressed,/get_lun
    "B": openr,unit,self.filename,/swap_if_little_endian,compress=compressed,/get_lun
    "L": openr,unit,self.filename,/swap_if_big_endian,compress=compressed,/get_lun
;cb else: begin
;cb     error="Cannot determine byte ordering of file named "+self.filename
;cb     return
;cb end
endcase
;
readu,unit,header
;
; Define the types of some variables
nlgth=0l & dldocgf=bytarr(5) & dt=0b & padding=0b & scalar=0.0d
n1=0l & n2=0l & nstrgs=0l & nchars=0l
;
variables_read=strarr(100)
unknowns=strarr(100)
error=""
ivar=-1
ivaru=-1

while (not eof(unit)) do begin
    readu,unit,nlgth; read name_length
    name=bytarr(nlgth) & readu,unit,name & name=string(name); read name
;CB we dont need this
;   if ((omithisto eq 2 and name eq "histohigh") or $
;     (omithisto eq 1 and name eq "histodata")) then begin
;     dcs_read_binaryOctavefile_done_reading,unit,ivar,ivaru,$
;      variables_read,unknowns,davePtr=davePtr,fname=fname
;     return
;   endif
;   if (omithisto eq 3 and name eq "histohigh") then begin
;     free_lun,unit
;     return
;   endif
;CB
    ;
    readu,unit,dldocgf; read 5 bytes of doc_length, doc, and global flag
    readu,unit,dt; read data type
    case dt of
       1: begin; read scalar
         readu,unit,padding
         readu,unit,scalar
          case name of
              "badbrd":        self.badbrd=float(scalar)
              "baddet":        self.baddet=float(scalar)
              "ch_ms":         self.ch_ms=float(scalar)
              "ch_res":        self.ch_res=fix(scalar)
              "ch_srdenom":    self.ch_srdenom=fix(scalar)
              "ch_srmode":     self.ch_srmode=fix(scalar)
              "ch_wl":         self.ch_wl=float(scalar)
              "coll_amp":      self.coll_amp=float(scalar)
              "coll_mean":     self.coll_mean=float(scalar)
              "coll_osc":      self.coll_osc=fix(scalar)
              "datamax":       self.datamax=float(scalar)
              "det_dis":       self.det_dis=float(scalar)
              "duration":      self.duration=float(scalar)
              "highmax":       self.highmax=float(scalar)
              "ncycles":       self.ncycles=long(scalar)
              "nframes":       self.nframes=long(scalar)
              "shutter_stat":  self.shutter_stat=fix(scalar); added 10/31/03
              "temp_setpoint": self.temp_setpoint=float(scalar)
              "tsdmin":        self.tsdmin=float(scalar)
              else: begin & ivaru=ivaru+1 & unknowns[ivaru]=name & end
          endcase
          ivar=ivar+1
          variables_read[ivar]=name
       end
       2: begin; read matrix
         readu,unit,n1,n2
         nhi=n1>n2
         nlo=n1<n2
         if (nlo eq 1) then data=dblarr(nhi) else data=dblarr(n1,n2)
         readu,unit,padding
         readu,unit,data
          case name of
              "ch_bid" :   self.ch_bid=float(data)
              "ch_delay":  self.ch_delay=float(data)
              "ch_dis":    self.ch_dis=float(data)
              "ch_input":  self.ch_input=float(data)
              "ch_phase":  self.ch_phase=float(data)
              "ch_slots":  self.ch_slots=float(data)
              "detsum":    self.detsum=ulong(data)
              "duration_csum": begin
                          self.duration_csum=-1.1
                          self.duration_csum=float(data)
              end
              "fc_dis":    self.fc_dis=float(data)
              "grandsum":  self.grandsum=ulong(data)
              "he3_csum": begin
                          self.he3_csum=-1.1
                          self.he3_csum=float(data)
              end
              "high_csum": begin
                          self.high_csum=-1.1
                          self.high_csum=float(data)
              end
              "histodata": begin
                        *self.qty_ptr=float(data) ; CHANGED 4/15/02
                        *self.err_ptr=sqrt(float(data)) ; CHANGED 4/15/02
              end
              "histohigh": self.histohigh=ulong(data) ; CHANGED 4/15/02
              "motor_pos": self.motor_pos=float(data)
              "repeats":   self.repeats=ulong(data)
              "resets":    self.resets=ulong(data)
              "runinfo":   self.runinfo=ulong(data); added 10/31/03
              "tchanlook": self.tchanlook=ulong(data)
              "temp_control": begin
                          self.temp_control=-1.1
                          self.temp_control=float(data)
              end
              "temp_sample": begin
                          self.temp_sample=-1.1
                          self.temp_sample=float(data)
              end
              "timsum":    self.timsum=ulong(data)
              "totals":    self.totals=ulong(data)
              else: begin & ivaru=ivaru+1 & unknowns[ivaru]=name & end
          endcase
          ivar=ivar+1
          variables_read[ivar]=name
       end
       5: begin; read string
         readu,unit,nchars; read number of characters in string element
         if (nchars gt 0) then begin
          str=bytarr(nchars) & readu,unit,str; read string element
          str=string(str)
          case name of
              "command":     self.command=str
              "comments":    self.comments=str
              "sample_desc": self.sample_desc=str
              "start_date":  self.start_date=str
              "startchoice": self.startchoice=str
              "stop_date":   self.stop_date=str
              "user":        self.user=str; added 10/31/03
              else: begin & ivaru=ivaru+1 & unknowns[ivaru]=name & end
          endcase
          ivar=ivar+1
          variables_read[ivar]=name
         endif
       end
       7: begin; read string array
         readu,unit,nstrgs; read number of strings in array
         strarray=strarr(nstrgs)
         for j=1,nstrgs do begin
          readu,unit,nchars; read number of characters in string element
          str=bytarr(nchars) & readu,unit,str; read string element
          strarray[j-1]=strjoin(string(str)); store, joined, in strarray
         endfor
         case name of
          "highsource":     self.highsource=strarray
          else: begin & ivaru=ivaru+1 & unknowns[ivaru]=name & end
         endcase
         ivar=ivar+1
         variables_read[ivar]=name
       end
       else: error="N.B. An unsupported variable type has been encountered: "+strcompress(dt)
    endcase
endwhile

;end Johns read proceedure.-----------------------------------------------------------------------------------------

;might as well keep these for now:
*self.variables_read_ptr = variables_read
*self.variables_unknown_ptr = unknowns


ntchan = self.ntchan
nhedet = self.nhedet
;unused as of yet CB
;x = indgen(ntchan)+1
;y = indgen(nhedet)+1

;more Johns testing the file stuff__________________________________________________________________________________
;This is not actually all that meaningful since I made pointers above and just filled them with available data.
;the  -1.1 values probably wont exist as arrays. Ever.


; With respect to the variables ncycles, duration_csum, he3_csum and high_csum, there are
;   three possible situations:
; 1.    If the raw data file was created before 10/31/03, ncycles is unknown. The variable ngood
;      is determined from temp_control except that in case B (when temperatures were not read)
;      it is set equal to 1. Then ncycles is set equal to ngood.
;      The csum variables are then set to average values determined from ngood.
;   2.    If the raw data file was created after 10/31/03 and before 5/4/04 it does not contain
;      ncycles nor the csum variables but it does contain runinfo so ncycles is set to runinfo[0].
;    The number of good cycles, ngood, is determined from temp_control except that in case B
;      it is unknown so it is set equal to ncycles.
;      The csum variables are set to average values determined from ngood.
;   3.    If the raw data file was created after 5/4/04 it contains ncycles, duration_csum,
;      he3_csum and high_csum.
;
caseB=(self.temp_control)[0] eq 300.0 and $
    (self.temp_sample)[0] eq 300.0 and $
    self.temp_setpoint eq 300.0
;
situation=0
if (file_basename(self.filename) lt '20031103_003') then situation=1                          ;<----mod 9/9/04 JRDC
if (file_basename(self.filename) ge '20031103_003' and self.filename lt '20040504_001') then situation=2  ;<----mod 9/9/04 JRDC
if (file_basename(self.filename) ge '20040504_001') then situation=3
;
; For case B (when temperatures are not read, i.e. when rectemp=0), temp_control and temp_sample
; are scalars but duration_csum, he3_csum and high_csum all contain ngood (or 18*ngood)
;   useful numbers.
;
; For cases A, C and D, temp_control, temp_sample, duration_csum, he3_csum and high_csum
; all contain ngood (or 18*ngood) useful numbers.
;
; The following explanation of cases A, C and D is from dcs_runsinfo.
;
;
; temp_sample and temp_control are initialized in dcs_definedavestructure as vectors of length nvals
; with value -1.0, then in read_binaryoctavefile they become vectors of length nvals, value -1.1
; They are then modified according to the content of the raw data file. In the comments that follow
;   #cycles is the number of accepted (good) cycles and the descriptions refer to the content of the
;   raw data file.
;
; Case A:   If rectemp=1 but the temperature cannot be read temp_sample and temp_control (in the raw data
;             file) are vectors of length #cycles, value -1.0 (thus temp_sample and temp_control in this
;             procedure, if there were 3 good cycles, would be [-1.0,-1.0,-1.0,-1.1,-1.1,-1.1,-1.1,-1.1,-1.1 ...])
; Case B:   If rectemp=0, temp_sample,temp_control and temp_setpoint (in the raw data file) are scalars,
;             value "300.0", i.e. temp_sample and temp_control in this procedure, would be [300.0,-1.1,-1.1,-1.1,
;             -1.1,-1.1,-1.1,-1.1,-1.1,-1.1,-1.1 ...])
; Case C:   Normally temp_sample and temp_control (in the raw data file) are vectors of length #cycles
;             with positive numbers.
; Case D:   If the temperature controller were set to <none> temp_sample and temp_control (in the raw data
;             file) would be vectors of length #cycles, value 0.0 (thus temp_sample and temp_control in this
;             procedure, if there were 3 good cycles, would be [0.0,0.0,0.0,-1.1,-1.1,-1.1,-1.1,-1.1,-1.1 ...])
;
;
; Test for creation before 10/31/03.
if (situation eq 1) then begin
    if (caseB) then begin
       ngood=1
    endif else begin
       res=where(self.temp_control ge 0.0,ngood)
       res=where(self.temp_control ge -1.05,ngood)   ; <---- this line added 9/3/04
    endelse
    ncycles=ngood
endif
;
; Test for creation after 10/31/03 and before 5/4/04.
if (situation eq 2) then begin
    ncycles=(self.runinfo)[0]
    if (caseB) then begin
       ngood=ncycles
    endif else begin
       res=where(self.temp_control ge 0.0,ngood)
       res=where(self.temp_control ge -1.05,ngood)   ; <---- this line added 9/3/04
    endelse
endif
;
; Test for creation before 5/4/04.
if (situation eq 1 or situation eq 2) then begin
    self.ncycles=ncycles
    ngood=float(ngood)
    self.duration_csum = -1.0
    self.he3_csum = -1.0
    self.high_csum = -1.0

    dcs=self.duration_csum
    dcs[0:ngood-1] = (self.duration)/ngood
    self.duration_csum=dcs

    hcs=self.he3_csum
    hcs[0:ngood-1] = total((self.detsum)[0:912])/ngood
    self.he3_csum = hcs

    hc=self.high_csum
    hc[*,0:ngood-1] = ((self.detsum)[913:930]/ngood)#(fltarr(ngood)+1)
    self.high_csum= hc
endif

; Initialize normalization_sum and fbnormalization_sum.
;UNUSED AS OF YET CB
;self.normalization_sum=fltarr(nhedet)
;self.fbnormalization_sum=fltarr(nhedet)
;
; Define time channel boundaries in units of time sample-detector.
twid=(self.tchanlook)[0,*]*0.05
tsdmin=self.tsdmin
*self.time_props_ptr=tsdmin+[0,reform(total(twid,/cumulative))]

;
; Define time channel boundaries in units of energy transfer.
conversion=!dcs_hsq2mn/(!dcs_hom/!dcs_dsd)^2
wl0=self.ch_wl
if (wl0 eq 0.0) then begin
    *self.energy_props_ptr=-conversion/*self.time_props_ptr^2
endif else begin
    *self.energy_props_ptr=!dcs_hsq2mn/wl0^2-conversion/*self.time_props_ptr^2
endelse

;
; Define detector angles (as a vector).

dcs_getangles,angles,nhedet=nhedet
*self.angle_props_ptr=angles
;
; Define elastic Q values (as a vector).
*self.Q_props_ptr=4.0*!dpi*sin(0.5*angles*!dtor)/self.ch_wl


; set the treatment:
    newline=strcompress(self.display_name+" loaded on "+$
                    string(self.now)+".")
    *self.treatment_ptr=[newline]

free_lun,lun,/force
;close,/file,/force
return,1
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::ddcs_get_filename,filename
pos = strpos(filename,path_sep(),/reverse_search)
self.display_name = strmid(filename,pos+1)
return,1
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::clone
compile_opt strictarr
ret = self->get_private(signal_type=signal_type, $
         display_name=display_name,            $
         extension=extension ,                 $
         ;CONSTANTS
         ntchan=ntchan,                        $
         nhedet=nhedet,                        $
         ratiocriterion=ratiocriterion,        $
         ;SCALARS
         badbrd=badbrd,                        $
         baddet=baddet,                        $
         ch_ms=ch_ms,                          $
         ch_res=ch_res,                        $
         ch_srdenom=ch_srdenom,                $
         ch_srmode=ch_srmode,                  $
         ch_wl=ch_wl,                          $
         coll_amp=coll_amp,                    $
         coll_mean=coll_mean,                  $
         coll_osc=coll_osc,                    $
         datamax=datamax,                      $
         det_dis=det_dis,                      $
         duration=duration,                    $
         highmax=highmax,                      $
         ncycles=ncycles,                      $
         nframes=nframes,                      $
         shutter_stat=shutter_stat,            $
         temp_setpoint=temp_setpoint,          $
         tsdmin=tsdmin,                        $
         maxbitflips=maxbitflips,              $
         ;DATA ARRAYS
         ch_bid=ch_bid,                        $
         ch_delay=ch_delay,                    $
         ch_dis=ch_dis,                        $
         ch_input=ch_input,                    $
         ch_phase=ch_phase,                    $
         ch_slots=ch_slots,                    $
         detsum=detsum,                        $
         cduration_csum=cduration_csum,        $
         fc_dis=fc_dis,                        $
         grandsum=grandsum,                    $
         he3_csum=he3_csum,                    $
         high_csum=high_csum,                  $
         histohigh=histohigh,                  $
         motor_pos=motor_pos,                  $
         repeats=repeats,                      $
         resets=resets,                        $
         runinfo=runinfo,                      $
         tchanlook=tchanlook,                  $
         temp_control=temp_control,            $
         temp_sample=temp_sample,              $
         timsum=timsum,                        $
         totals=totals,                        $
         insane=insane,                        $
         ;STRING
         command=command,                      $
         comments=comments,                    $
         sample_desc=sample_desc,              $
         start_date=start_date,                $
         startchoice=startchoice,              $
         stop_date=stop_date,                  $
         user=user,                            $
         highsource=highsource,                $
         ;DERIVED
         ;derived
         qty_ptr= qty_ptr,                     $
         err_ptr=err_ptr ,                     $
         variables_read_ptr=variables_read_ptr,$
         variables_unknown_ptr=variables_unknown_ptr,$
         time_props_ptr=time_props_ptr,        $
         energy_props_ptr=energy_props_ptr,    $
         angle_props_ptr=angle_props_ptr,      $
         Q_props_ptr=Q_props_ptr,              $
         normalization_sum=normalization_sum,  $
         fbnormalization_sum=fbnormalization_sum,$
         ngtchan0=ngtchan0,                    $
         ngtchan1=ngtchan1,                    $
         now=now,                              $
         filename=filename,                    $
         treatment_ptr=treatment_ptr,          $
         bitflips_ptr= bitflips_ptr,           $
         xvals=xvals,                         $
         yvals=yvals,                         $
         xlabel=xlabel,                       $
         ylabel=ylabel,                       $
         xtype=xtype,                         $
         ytype=ytype,                         $
         yunits=yunits,                       $
         xunits=xunits,                       $
         histlabel=histlabel                  $
 )

oclone = obj_new('ddcs_data',nhedet=nhedet, ntchan =ntchan)

ret = oclone->set_private(signal_type=signal_type,  $
         display_name=display_name,            $
         extension=extension ,                 $
         ;CONSTANTS
         ntchan=ntchan,                        $
         nhedet=nhedet,                        $
         ratiocriterion=ratiocriterion,        $
         ;SCALARS
         badbrd=badbrd,                        $
         baddet=baddet,                        $
         ch_ms=ch_ms,                          $
         ch_res=ch_res,                        $
         ch_srdenom=ch_srdenom,                $
         ch_srmode=ch_srmode,                  $
         ch_wl=ch_wl,                          $
         coll_amp=coll_amp,                    $
         coll_mean=coll_mean,                  $
         coll_osc=coll_osc,                    $
         datamax=datamax,                      $
         det_dis=det_dis,                      $
         duration=duration,                    $
         highmax=highmax,                      $
         ncycles=ncycles,                      $
         nframes=nframes,                      $
         shutter_stat=shutter_stat,            $
         temp_setpoint=temp_setpoint,          $
         tsdmin=tsdmin,                        $
         maxbitflips=maxbitflips,              $
         ;DATA ARRAYS
         ch_bid=ch_bid,                        $
         ch_delay=ch_delay,                    $
         ch_dis=ch_dis,                        $
         ch_input=ch_input,                    $
         ch_phase=ch_phase,                    $
         ch_slots=ch_slots,                    $
         detsum=detsum,                        $
         cduration_csum=cduration_csum,        $
         fc_dis=fc_dis,                        $
         grandsum=grandsum,                    $
         he3_csum=he3_csum,                    $
         high_csum=high_csum,                  $
         histohigh=histohigh,                  $
         motor_pos=motor_pos,                  $
         repeats=repeats,                      $
         resets=resets,                        $
         runinfo=runinfo,                      $
         tchanlook=tchanlook,                  $
         temp_control=temp_control,            $
         temp_sample=temp_sample,              $
         timsum=timsum,                        $
         totals=totals,                        $
         insane=insane,                        $
         ;STRING
         command=command,                      $
         comments=comments,                    $
         sample_desc=sample_desc,              $
         start_date=start_date,                $
         startchoice=startchoice,              $
         stop_date=stop_date,                  $
         user=user,                            $
         highsource=highsource,                $
         ;DERIVED
         ;derived
         qty_ptr= qty_ptr,                     $
         err_ptr=err_ptr ,                     $
         variables_read_ptr=variables_read_ptr,$
         variables_unknown_ptr=variables_unknown_ptr,$
         time_props_ptr=time_props_ptr,        $
         energy_props_ptr=energy_props_ptr,    $
         angle_props_ptr=angle_props_ptr,      $
         Q_props_ptr=Q_props_ptr,              $
         normalization_sum=normalization_sum,  $
         fbnormalization_sum=fbnormalization_sum,$
         ngtchan0=ngtchan0,                    $
         ngtchan1=ngtchan1,                    $
         now=now,                              $
         filename=filename,                    $
         treatment_ptr=treatment_ptr,          $
         bitflips_ptr= bitflips_ptr,            $
         xvals=xvals,                         $
         yvals=yvals,                         $
         xlabel=xlabel,                       $
         ylabel=ylabel,                       $
         xtype=xtype,                         $
         ytype=ytype,                         $
         yunits=yunits,                       $
         xunits=xunits,                       $
         histlabel=histlabel                  $
         )

return,oclone
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::get_private,              $
         signal_type=signal_type,             $
         display_name=display_name,           $
         extension=extension ,                $
         ;CONSTANTS
         ntchan=ntchan,                       $
         nhedet=nhedet,                       $
         ratiocriterion=ratiocriterion,       $
         ;SCALARS
         badbrd=badbrd,                       $
         baddet=baddet,                       $
         ch_ms=ch_ms,                         $
         ch_res=ch_res,                       $
         ch_srdenom=ch_srdenom,               $
         ch_srmode=ch_srmode,                 $
         ch_wl=ch_wl,                         $
         coll_amp=coll_amp,                   $
         coll_mean=coll_mean,                 $
         coll_osc=coll_osc,                   $
         datamax=datamax,                     $
         det_dis=det_dis,                     $
         duration=duration,                   $
         highmax=highmax,                     $
         ncycles=ncycles,                     $
         nframes=nframes,                     $
         shutter_stat=shutter_stat,           $
         temp_setpoint=temp_setpoint,         $
         tsdmin=tsdmin,                       $
         maxbitflips=maxbitflips,             $
         ;DATA ARRAYS
         ch_bid=ch_bid,                       $
         ch_delay=ch_delay,                   $
         ch_dis=ch_dis,                       $
         ch_input=ch_input,                   $
         ch_phase=ch_phase,                   $
         ch_slots=ch_slots,                   $
         detsum=detsum,                       $
         cduration_csum=cduration_csum,         $
         fc_dis=fc_dis,                       $
         grandsum=grandsum,                   $
         he3_csum=he3_csum,                   $
         high_csum=high_csum,                 $
         histohigh=histohigh,                 $
         motor_pos=motor_pos,                 $
         repeats=repeats,                     $
         resets=resets,                       $
         runinfo=runinfo,                     $
         tchanlook=tchanlook,                 $
         temp_control=temp_control,           $
         temp_sample=temp_sample,             $
         timsum=timsum,                       $
         totals=totals,                       $
         insane=insane,                       $
         ;STRING
         command=command,                     $
         comments=comments,                   $
         sample_desc=sample_desc,             $
         start_date=start_date,               $
         startchoice=startchoice,             $
         stop_date=stop_date,                 $
         user=user,                           $
         highsource=highsource,               $
         ;DERIVED
         ;derived
         qty_ptr= qty_ptr,                    $
         err_ptr=err_ptr ,                    $
         variables_read_ptr=variables_read_ptr,$
         variables_unknown_ptr=variables_unknown_ptr,$
         time_props_ptr=time_props_ptr,       $
         energy_props_ptr=energy_props_ptr,   $
         angle_props_ptr=angle_props_ptr,     $
         Q_props_ptr=Q_props_ptr,             $
         normalization_sum=normalization_sum, $
         fbnormalization_sum=fbnormalization_sum,$
         ngtchan0=ngtchan0,                   $
         ngtchan1=ngtchan1,                   $
         now=now,                             $
         filename=filename,                   $
         treatment_ptr=treatment_ptr,         $
         bitflips_ptr= bitflips_ptr,          $
         xvals=xvals,                         $
         yvals=yvals,                         $
         xlabel=xlabel,                       $
         ylabel=ylabel,                       $
         xtype=xtype,                         $
         ytype=ytype,                         $
         yunits=yunits,                       $
         xunits=xunits,                       $
         histlabel=histlabel


         signal_type=self.signal_type
         display_name=self.display_name
         extension=self.extension
         ;CONSTANTS
         ntchan=self.ntchan
         nhedet=self.nhedet
         ratiocriterion=self.ratiocriterion
         ;SCALARS
         badbrd=self.badbrd
         baddet=self.baddet
         ch_ms=self.ch_ms
         ch_res=self.ch_res
         ch_srdenom=self.ch_srdenom
         ch_srmode=self.ch_srmode
         ch_wl=self.ch_wl
         coll_amp=self.coll_amp
         coll_mean=self.coll_mean
         coll_osc=self.coll_osc
         datamax=self.datamax
         det_dis=self.det_dis
         duration=self.duration
         highmax=self.highmax
         ncycles=self.ncycles
         nframes=self.nframes
         shutter_stat=self.shutter_stat
         temp_setpoint=self.temp_setpoint
         tsdmin=self.tsdmin
         maxbitflips=self.maxbitflips
         ;DATA ARRAYS
         ch_bid=self.ch_bid
         ch_delay=self.ch_delay
         ch_dis=self.ch_dis
         ch_input=self.ch_input
         ch_phase=self.ch_phase
         ch_slots=self.ch_slots
         detsum=self.detsum
         cduration_csum=self.duration_csum
         fc_dis=self.fc_dis
         grandsum=self.grandsum
         he3_csum=self.he3_csum
         high_csum=self.high_csum
         histohigh=self.histohigh
         motor_pos=self.motor_pos
         repeats=self.repeats
         resets=self.resets
         runinfo=self.runinfo
         tchanlook=self.tchanlook
         temp_control=self.temp_control
         temp_sample=self.temp_sample
         timsum=self.timsum
         totals=self.totals
         insane=self.insane
         ;STRING
         command=self.command
         comments=self.comments
         sample_desc=self.sample_desc
         start_date=self.start_date
         startchoice=self.startchoice
         stop_date=self.stop_date
         user=self.user
         highsource=self.highsource
         ;DERIVED
         ;derived
         if n_elements(*self.qty_ptr) ne 0 then $
            qty_ptr= *self.qty_ptr
         if n_elements(*self.err_ptr) ne 0 then $
         err_ptr=*self.err_ptr
         if n_elements(*self.variables_read_ptr) ne 0 then $
         variables_read_ptr=*self.variables_read_ptr
         if n_elements(*self.variables_unknown_ptr) ne 0 then $
         variables_unknown_ptr=*self.variables_unknown_ptr
         if n_elements(*self.time_props_ptr) ne 0 then $
         time_props_ptr=*self.time_props_ptr
         if n_elements(*self.energy_props_ptr) ne 0 then $
         energy_props_ptr=*self.energy_props_ptr
         if n_elements(*self.angle_props_ptr) ne 0 then $
         angle_props_ptr=*self.angle_props_ptr
         if n_elements(*self.Q_props_ptr) ne 0 then $
         Q_props_ptr=*self.Q_props_ptr
         if n_elements(*self.normalization_sum) ne 0 then $
         normalization_sum=*self.normalization_sum
         if n_elements(*self.fbnormalization_sum) ne 0 then $
         fbnormalization_sum=*self.fbnormalization_sum
         ngtchan0=self.ngtchan0
         ngtchan1=self.ngtchan1
         now=self.now
         filename=self.filename
         if n_elements(*self.treatment_ptr) ne 0 then $
         treatment_ptr=*self.treatment_ptr
         if n_elements(*self.bitflips_ptr) ne 0 then $
         bitflips_ptr= *self.bitflips_ptr

         if n_elements(*self.x_ptr) ne 0 then xvals=*self.x_ptr
         if n_elements(*self.y_ptr) ne 0 then yvals=*self.y_ptr
         xlabel=self.xlabel
         ylabel=self.ylabel
         xtype=self.xtype
         ytype=self.ytype
         yunits=self.yunits
         xunits=self.xunits
         histlabel=self.histlabel

return,0
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::set_private,              $
         signal_type=signal_type,             $
         display_name=display_name,           $
         extension=extension ,                $
         ;CONSTANTS
         ntchan=ntchan,                       $
         nhedet=nhedet,                       $
         ratiocriterion=ratiocriterion,       $
         ;SCALARS
         badbrd=badbrd,                       $
         baddet=baddet,                       $
         ch_ms=ch_ms,                         $
         ch_res=ch_res,                       $
         ch_srdenom=ch_srdenom,               $
         ch_srmode=ch_srmode,                 $
         ch_wl=ch_wl,                         $
         coll_amp=coll_amp,                   $
         coll_mean=coll_mean,                 $
         coll_osc=coll_osc,                   $
         datamax=datamax,                     $
         det_dis=det_dis,                     $
         duration=duration,                   $
         highmax=highmax,                     $
         ncycles=ncycles,                     $
         nframes=nframes,                     $
         shutter_stat=shutter_stat,           $
         temp_setpoint=temp_setpoint,         $
         tsdmin=tsdmin,                       $
         maxbitflips=maxbitflips,             $
         ;DATA ARRAYS
         ch_bid=ch_bid,                       $
         ch_delay=ch_delay,                   $
         ch_dis=ch_dis,                       $
         ch_input=ch_input,                   $
         ch_phase=ch_phase,                   $
         ch_slots=ch_slots,                   $
         detsum=detsum,                       $
         cduration_csum=cduration_csum,       $
         fc_dis=fc_dis,                       $
         grandsum=grandsum,                   $
         he3_csum=he3_csum,                   $
         high_csum=high_csum,                 $
         histohigh=histohigh,                 $
         motor_pos=motor_pos,                 $
         repeats=repeats,                     $
         resets=resets,                       $
         runinfo=runinfo,                     $
         tchanlook=tchanlook,                 $
         temp_control=temp_control,           $
         temp_sample=temp_sample,             $
         timsum=timsum,                       $
         totals=totals,                       $
         insane=insane,                       $
         ;STRING
         command=command,                     $
         comments=comments,                   $
         sample_desc=sample_desc,             $
         start_date=start_date,               $
         startchoice=startchoice,             $
         stop_date=stop_date,                 $
         user=user,                           $
         highsource=highsource,               $
         ;DERIVED
         ;derived
         qty_ptr= qty_ptr,                    $
         err_ptr=err_ptr ,                    $
         variables_read_ptr=variables_read_ptr,$
         variables_unknown_ptr=variables_unknown_ptr,$
         time_props_ptr=time_props_ptr,       $
         energy_props_ptr=energy_props_ptr,   $
         angle_props_ptr=angle_props_ptr,     $
         Q_props_ptr=Q_props_ptr,             $
         normalization_sum=normalization_sum, $
         fbnormalization_sum=fbnormalization_sum,$
         ngtchan0=ngtchan0,                   $
         ngtchan1=ngtchan1,                   $
         now=now,                             $
         filename=filename,                   $
         treatment_ptr=treatment_ptr,         $
         bitflips_ptr= bitflips_ptr,          $
         xvals=xvals,                         $
         yvals=yvals,                         $
         xlabel=xlabel,                       $
         ylabel=ylabel,                       $
         xtype=xtype,                         $
         ytype=ytype,                         $
         yunits=yunits,                       $
         xunits=xunits,                       $
         histlabel=histlabel


         self.signal_type=signal_type
         self.display_name=display_name
         self.extension=extension
         ;CONSTANTS
         self.ntchan=ntchan
         self.nhedet=nhedet
         self.ratiocriterion=ratiocriterion
         ;SCALARS
         self.badbrd=badbrd
         self.baddet=baddet
         self.ch_ms=ch_ms
         self.ch_res=ch_res
         self.ch_srdenom=ch_srdenom
         self.ch_srmode=ch_srmode
         self.ch_wl=ch_wl
         self.coll_amp=coll_amp
         self.coll_mean=coll_mean
         self.coll_osc=coll_osc
         self.datamax=datamax
         self.det_dis=det_dis
         self.duration=duration
         self.highmax=highmax
         self.ncycles=ncycles
         self.nframes=nframes
         self.shutter_stat=shutter_stat
         self.temp_setpoint=temp_setpoint
         self.tsdmin=tsdmin
         self.maxbitflips=maxbitflips
         ;DATA ARRAYS
         self.ch_bid=ch_bid
         self.ch_delay=ch_delay
         self.ch_dis=ch_dis
         self.ch_input=ch_input
         self.ch_phase=ch_phase
         self.ch_slots=ch_slots
         self.detsum=detsum
         self.duration_csum=cduration_csum
         self.fc_dis=fc_dis
         self.grandsum=grandsum
         self.he3_csum=he3_csum
         self.high_csum=high_csum
         self.histohigh=histohigh
         self.motor_pos=motor_pos
         self.repeats=repeats
         self.resets=resets
         self.runinfo=runinfo
         self.tchanlook=tchanlook
         self.temp_control=temp_control
         self.temp_sample=temp_sample
         self.timsum=timsum
         self.totals=totals
         self.insane=insane
         ;STRING
         self.command=command
         self.comments=comments
         self.sample_desc=sample_desc
         self.start_date=start_date
         self.startchoice=startchoice
         self.stop_date=stop_date
         self.user=user
         self.highsource=highsource
         ;DERIVED
         ;derived
if n_elements(qty_ptr) ne 0 then $
         *self.qty_ptr= qty_ptr
if n_elements(err_ptr) ne 0 then $
        *self.err_ptr=err_ptr
if n_elements(variables_read_ptr) ne 0 then $
        *self.variables_read_ptr=variables_read_ptr
if n_elements(variables_unknown_ptr) ne 0 then $
        *self.variables_unknown_ptr=variables_unknown_ptr
if n_elements(time_props_ptr) ne 0 then $
        *self.time_props_ptr=time_props_ptr
if n_elements(energy_props_ptr) ne 0 then $
        *self.energy_props_ptr=energy_props_ptr
if n_elements(angle_props_ptr) ne 0 then $
        *self.angle_props_ptr=angle_props_ptr
if n_elements(Q_props_ptr) ne 0 then $
        *self.Q_props_ptr=Q_props_ptr
if n_elements(normalization_sum) ne 0 then $
        *self.normalization_sum=normalization_sum
if n_elements(fbnormalization_sum) ne 0 then $
        *self.fbnormalization_sum=fbnormalization_sum
         self.ngtchan0=ngtchan0
         self.ngtchan1=ngtchan1
         self.now=now
         self.filename=filename
if n_elements(treatment_ptr) ne 0 then *self.treatment_ptr=treatment_ptr
if n_elements(bitflips_ptr) ne 0 then  *self.bitflips_ptr= bitflips_ptr
         if n_elements(xvals) ne 0 then *self.x_ptr=xvals
         if n_elements(yvals) ne 0 then *self.y_ptr=yvals
         self.xlabel=xlabel
         self.ylabel=ylabel
         self.xtype=xtype
         self.ytype=ytype
         self.yunits=yunits
         self.xunits=xunits
         self.histlabel=histlabel
return,1
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function ddcs_data::init,  filename = filename,       $
                           signal_type = signal_type, $
                           nhedet = nhedet,             $
                           ntchan =ntchan,            $
                           read = read
if n_elements(filename) eq 0 then filename = ''
if n_elements(signal_type) eq 0 then signal_type = 'SIGNAL'
if n_elements(nhedet) eq 0 then nhedet = 913
if n_elements(ntchan) eq 0 then ntchan = 1024

nchop=7
nhigh=18
nvals=500; This is the dimension of the arrays that are added to at the end of each run cycle.
;CONSTANTS
self.nhedet = nhedet
self.ntchan = ntchan
self.ratiocriterion = 0.0001
self.signal_type = signal_type
self.filename = filename
self.display_name = ''
self.extension=''
self.treatment_ptr=ptr_new('')
;SCALARS
self.badbrd = -1.0d
self.baddet = -1.0d
self.ch_ms = -1.0d
self.ch_res = -1
self.ch_srdenom = -1
self.ch_srmode = -1
self.ch_wl = -1.0d
self.coll_amp = -1.0d
self.coll_mean = -1.0d
self.coll_osc = -1
self.datamax = -1.0d
self.det_dis = +1.d4
self.duration = -1.0d
self.highmax = -1.0d
self.ncycles = -1
self.nframes = 1l
self.shutter_stat = -1
self.temp_setpoint = -1.0d
self.tsdmin = -1.0d
self.maxbitflips=10
;DATA ARRAYS
self.ch_bid = fltarr(nchop)+1.e4
self.ch_delay = fltarr(nchop)-1.0d
self.ch_dis = fltarr(nchop)+1.e4
self.ch_input = fltarr(6)-1.0d
self.ch_phase = fltarr(nchop)-1.0d
self.ch_slots = fltarr(nchop,3)-1.0d
self.detsum = ulonarr(nhedet+nhigh)-1
self.duration_csum = fltarr(nvals)-1.0
self.fc_dis = fltarr(3)+1.e4
self.grandsum = ulonarr(8)-1
self.he3_csum = fltarr(nvals)-1.0
self.high_csum = fltarr(nhigh,nvals)-1.0
self.histohigh = ulonarr(ntchan,nhigh)-1
self.motor_pos = fltarr(8)+1.e4
self.repeats = ulonarr(2,32)-1
self.resets = ulonarr(2,32)-1
self.runinfo = lonarr(4)-1
self.tchanlook = ulonarr(2,ntchan)-1
self.temp_control = fltarr(nvals)-1.0
self.temp_sample = fltarr(nvals)-1.0
self.timsum = ulonarr(ntchan)-1
self.totals = ulonarr(2,32)-1
self.insane=intarr(7); currently only doing basic check on array 0
;STRINGS
self.command = 'xxx'
self.comments = 'xxx'
self.sample_desc = strarr(10)+"xxx"
self.start_date = "xxx"
self.startchoice = "xxx"
self.stop_date = "xxx"
self.user = "xxx"
self.highsource = strarr(nhigh-1)+"xxx"
;derived
self.qty_ptr = ptr_new(/allocate_heap) ;                OTHER OPTION FROM JOHN IS FLOAT. CHECK
self.err_ptr = ptr_new(/allocate_heap) ;          ""             ""
self.variables_read_ptr =ptr_new(/allocate_heap)
self.variables_unknown_ptr = ptr_new(/allocate_heap)
self.time_props_ptr = ptr_new(/allocate_heap)
self.energy_props_ptr = ptr_new(/allocate_heap)
self.angle_props_ptr = ptr_new(/allocate_heap)
self.Q_props_ptr = ptr_new(/allocate_heap)
self.normalization_sum = ptr_new(fltarr(nhedet))
self.fbnormalization_sum = ptr_new(fltarr(nhedet))
self.ngtchan0 = 0
self.ngtchan1 = 0
self.now = systime()
self.bitflips_ptr=ptr_new(lonarr(3,self.maxbitflips)+1000)
self.x_ptr=ptr_new(findgen(ntchan)+1)
self.y_ptr=ptr_new(findgen(nhedet)+1)
self.xlabel=''
self.ylabel=''
self.xtype=''
self.ytype=''
self.yunits=''
self.xunits=''
self.histlabel=''

if self.filename ne '' then begin

   ret = self->read_file()
   if ret ne 1 then begin
      self->cleanup
      return,0
   endif
endif

return,1
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ddcs_data__define
class =  {ddcs_data,                 $
         signal_type:'',             $
         display_name:'',            $
         extension:'',               $
         ;CONSTANTS
         ntchan:0,                   $
         nhedet:0,                   $
         ratiocriterion:0.0001,      $
         ;SCALARS
         badbrd:0.0,                 $
         baddet:0.0,                 $
         ch_ms:0.0,                  $
         ch_res:0,                   $
         ch_srdenom:0,               $
         ch_srmode:0,                $
         ch_wl:0.0,                  $
         coll_amp:0.0,               $
         coll_mean:0.0,              $
         coll_osc:0,                 $
         datamax:0.0,                $
         det_dis:0.0,                $
         duration:0.0,               $
         highmax:0.0,                $
         ncycles:0L,                 $
         nframes:0L,                 $
         shutter_stat:0,             $
         temp_setpoint:0.0,          $
         tsdmin:0.0,                 $
         maxbitflips:0,              $
         ;DATA ARRAYS
         ch_bid:fltarr(7),       $
         ch_delay:fltarr(7),     $
         ch_dis:fltarr(7),       $
         ch_input:fltarr(6),     $
         ch_phase:fltarr(7),     $
         ch_slots:fltarr(7,3),     $
         detsum:ulonarr(931),       $
         duration_csum:fltarr(500),$
         fc_dis:fltarr(3),       $
         grandsum:ulonarr(8),     $
         he3_csum:fltarr(500),     $
         high_csum:fltarr(18,500),    $
         histohigh:ulonarr(1024,18),    $
         motor_pos:fltarr(8),    $
         repeats:ulonarr(2,32),      $
         resets:ulonarr(2,32),       $
         runinfo:lonarr(4),      $
         tchanlook:ulonarr(2,1024),    $
         temp_control:fltarr(500), $
         temp_sample:fltarr(500),  $
         timsum:ulonarr(1024),       $
         totals:ulonarr(2,32),       $
         insane:intarr(7),$
         ;STRING
         command:'',                 $
         comments:'',                $
         sample_desc:strarr(10),             $
         start_date:'',              $
         startchoice:'',             $
         stop_date:'',               $
         user:'',                    $
         highsource:strarr(17),       $
         ;DERIVED
         ;derived
         qty_ptr:ptr_new() ,         $
         err_ptr:ptr_new() ,         $
         variables_read_ptr:ptr_new(),$
         variables_unknown_ptr:ptr_new(),$
         time_props_ptr:ptr_new(),   $
         energy_props_ptr:ptr_new(), $
         angle_props_ptr:ptr_new(),  $
         Q_props_ptr:ptr_new(),      $
         normalization_sum:ptr_new(),$
         fbnormalization_sum:ptr_new(),$
         ngtchan0:0,                 $
         ngtchan1:0,                 $
         now:'',                     $
         filename:'',                $
         x_ptr:ptr_new(),            $
         y_ptr:ptr_new(),            $
         treatment_ptr:ptr_new(),               $
         bitflips_ptr:ptr_new(),     $
         xlabel:'',                  $
         ylabel:'',                  $
         xtype:'',                   $
         ytype:'',                   $
         yunits:'',                  $
         xunits:'',                  $
         histlabel:''               }

end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro ddcs_data_test, loc=loc
; Simple test program
if loc eq '' then  loc='laptop'

;call the variables the have been defined for other DAVE AND DCS routines:

defsysv, '!dave_planck', 6.62606876d-34, 1 ; J s
defsysv, '!dave_nmass', 1.67492716d-27, 1 ; kg
defsysv, '!dave_e', 1.602176462d-19, 1 ; C
defsysv, '!dave_boltzmann', 1.3806503d-23, 1 ; J K-1
defsysv,'!dcs_hom',(!dave_planck/!dave_nmass)*1.e7
defsysv,'!dcs_hbar',(!dave_planck/(2*!dpi))*1.e7
defsysv,'!dcs_mevcon',!dave_e*1.e4
defsysv,'!dcs_hsq2mn',(!dave_planck*1.e7)^2/(2.0*!dave_nmass)/!dcs_mevcon*1.e13
defsysv,'!dcs_boltzmann',!dave_boltzmann*1.e7
defsysv,'!dcs_dsd',4010.0
defsysv,'!ext_pgen',120.0



; need this for the detangles program of johns:
case loc of
'home': begin
        defsysv,'!DAVE_AUXILIARY_DIR','J:\RSI\dave\programs\auxiliary\'
        filename = 'J:\RSI\IDL61\work\data\20041218_001.dcs.gz'
    end
'laptop': begin
      defsysv,'!DAVE_AUXILIARY_DIR','C:\RSI\dave\programs\auxiliary\'
       filename = 'C:\RSI\work\20050321_014v.dcs.gz'
    end
'work': begin
       defsysv,'!DAVE_AUXILIARY_DIR','C:\RSI-6.0\dave\programs\auxiliary\'
      ;filename='C:\Documents and Settings\craig\My Documents\ncnr\dcs\development\standalone\20010719_09.dcs.gz'  ; early case, Tvary
        ;filename='C:\Documents and Settings\craig\My Documents\ncnr\dcs\development\standalone\20010823_01.dcs.gz'  ; early case, Tunread
        ;filename='C:\Documents and Settings\craig\My Documents\ncnr\dcs\development\standalone\20040214_004.dcs.gz'  ; middle case, Tvary
        ;filename='C:\Documents and Settings\craig\My Documents\ncnr\dcs\development\standalone\20040122_002.dcs.gz'  ; middle case, Tunread
        ;filename='C:\Documents and Settings\craig\My Documents\ncnr\dcs\users\trouw\20041206_001.dcs.gz' ;normal Tvary,
        ;filename='C:\Documents and Settings\craig\My Documents\ncnr\dcs\development\standalone\ ;normal Tunread
    end
endcase

o = obj_new('ddcs_data',filename = filename,nhedet=913, ntchan =1024,signal_type='VANADIUM')
ret = o->get_private(signal_type = signal_type,filename = filename,display_name=display_name,$
                     nhedet=nhedet, ntchan=ntchan)
print,'signal type: ',signal_type
print,'File Name: ',filename
print,'Display Name: ',display_name
print,'ntchan: ',ntchan
print,'nhedet: ',nhedet
print,'Valid o: ',obj_valid(o)
ret = o->sanity_check(value=0)
obj_destroy,[o]
end