; $Id: davedat2d__clone.pro,v 1.4 2005/02/08 17:17:34 azuah Exp $
;###############################################################################
;
; CLASS NAME:
;   DaveDat2D
;
; PURPOSE:
;   This class encapsulates a DAVE formated dataset containing 2D
;   data.
;
; CATEGORY:
;   Data Browser
;
; SUPERCLASSES:
;   DaveDat
;
; PUBLIC METHODS:
;   Clone
;   Get
;   Print
;   Rebin
;   ResetData
;   Restore
;   Set
;   Transpose
;   XSpec
;
; AUTHOR:
;   Richard Tumanjong Azuah
;   NIST Center for Neutron Research
;   100 Bureau Drive, Gaithersburg, MD 20899
;   United States
;   azuah@nist.gov; (301) 9755604
;   Oct, 2002
;
; 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.
;
;###############################################################################



;===============================================================================
; DaveDat2D::clone
;
; PURPOSE:
;   This method is used to create an identical copy of the current
;   object.
;
; PARAMETERS:
;
; KEYWORDS:
;
; RETURN VALUE: 
;   a DaveDat2D object if successful 
;   a NULL object otherwise.
;
function DaveDat2D::clone

newObj = obj_new('davedat2d')   ; create a new (empty) DaveDat2D object

; if newObj was not created, exit now
if (not obj_valid(newObj)) then return, obj_new() ; return a NULL object.

; copy all current object's variables into the new object's
if (self->get(davePtr=davePtr, $
              descriPtr=descriPtr, $
              filename=filename, $
              scalefactor=scalefactor, $
              instrument=instrument, $
              treatment=treatment, $
              xval=xval, $
              xlabel=xlabel, $
              xtype=xtype, $
              xunits=xunits, $
              xDir=xDir, $
              yval=yval, $
              ylabel=ylabel, $
              ytype=ytype, $
              yunits=yunits, $
              yDir=yDir, $
              zval=zval, $
              zerr=zerr, $
              zlabel=zlabel, $
              zunits=zunits)) then begin ; get was successful, so copy vars to newObj
    if (newObj->set(davePtr=davePtr, $
                    descriPtr=descriPtr, $
                    filename=filename, $
                    scalefactor=scalefactor, $
                    instrument=instrument, $
                    treatment=treatment, $
                    xval=xval, $
                    xlabel=xlabel, $
                    xtype=xtype, $
                    xunits=xunits, $
                    xDir=xDir, $
                    yval=yval, $
                    ylabel=ylabel, $
                    ytype=ytype, $
                    yunits=yunits, $
                    yDir=yDir, $
                    zval=zval, $
                    zerr=zerr, $
                    zlabel=zlabel, $
                    zunits=zunits)) then begin ; set successful, so return newObj
        if (ptr_valid(davePtr)) then heap_free, davePtr
        if (ptr_valid(descriPtr)) then ptr_free, descriPtr
        return, newObj
    endif else begin            ; set unsuccessful, so destroy newObj and return a NULL
        obj_destroy, newObj
        if (ptr_valid(davePtr)) then heap_free,davePtr
        if (ptr_valid(descriPtr)) then ptr_free, descriPtr
        return, obj_new()
    endelse
endif else begin                ; get unsuccessful, so destroy newObj and return a NULL
    obj_destroy, newObj
    if (ptr_valid(davePtr)) then heap_free,davePtr
    if (ptr_valid(descriPtr)) then ptr_free, descriPtr
    return, obj_new()
endelse

end
