; $Id: davedat2d__set.pro,v 1.5 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::set
; 
; PURPOSE:
;   Main set method for class.
;   Extends DaveDat::set method.
;
; PARAMETERS:
;
; KEYWORDS:
;   transpose [in] - assign value (expects 0|1) to the object's transpose
;                 variable to indicate the transpose state (0=>no,
;                 1=>yes) of the object.
;
;   yVal [in] - assign value (expects float array) to objects yVal
;               (y-axis values) variable.
;
;   yLabel [in] - assign value (expects scaler string) to object's
;                 yLabel (y-axis label) variable
;
;   yType [in] - assign value (expects scaler string) to object's
;                yType (y-axis type) variable.
;
;   yUnits [in] - assign value (expects scaler string) to object's
;                 yUnits (y-axis units) variable.
;
;   yDir [in] - assign int value (0:1) to the object's yDir (is y-axis
;               increasing or decreasing?) variable.
;
;   _EXTRA - allows keywords to be passed to the base class (see
;            DaveDat::set).
;
; RETURN VALUE: 
;   0 => failure
;   1 => success
;
function DaveDat2D::set, _EXTRA=etc, yVal=yval, yLabel=ylabel, yType=ytype, yUnits=yunits $
  ,yDir=yDir, transpose=transpose

; reset !error_state structure, ie clear all errors
message,/reset

retVal = 1

if (n_elements(transpose)) then self.transposeFlag=transpose

if (n_elements(yDir)) then self.yDir=yDir

;
if (n_elements(yval) gt 0) then begin
    yvalType = vartype(yval)
    if ( (yvalType eq 'FLOAT') or $
         (yvalType eq 'DOUBLE') or $
         (yvalType eq 'INT') or $
         (yvalType eq 'LONG') ) then begin
        if (ptr_valid(self.yvPtr)) then begin
            (*self.yvPtr) = yval ; assign contents to object 
        endif else begin
            self.yvPtr = ptr_new(yval)
        endelse 
    endif else begin
        !error_state.msg = 'DaveDat2D::set: yval keyword value is not a float'
        !error_state.code = -1
        retVal = 0
    endelse
endif

;
if (n_elements(ylabel) gt 0) then begin
    ;; make sure value is a _scaler string_
    if ( (vartype(ylabel) eq 'STRING') and $
         (size(ylabel,/n_dimensions) eq 0) ) then begin
        self.ylabel = ylabel 
    endif else begin
        !error_state.msg = 'DaveDat2D::set: ylabel keyword value is not a scaler string'
        !error_state.code = -1
        retVal = 0
    endelse
endif

;
if (n_elements(ytype) gt 0) then begin
    ;; make sure value is a _scaler string_
    if ( (vartype(ytype) eq 'STRING') and $
         (size(ytype,/n_dimensions) eq 0) ) then begin
        self.ytype = ytype
    endif else begin
        !error_state.msg = 'DaveDat2D::set: ytype keyword value is not a scaler string'
        !error_state.code = -1
        retVal = 0
    endelse
endif

;
if (n_elements(yunits) gt 0) then begin
    ;; make sure value is a _scaler string_
    if ( (vartype(yunits) eq 'STRING') and $
         (size(yunits,/n_dimensions) eq 0) ) then begin
        self.yunits = yunits 
    endif else begin
        !error_state.msg = 'DaveDat2D::set: yunits keyword value is not a scaler string'
        !error_state.code = -1
        retVal = 0
    endelse
endif

; Anything else is handled by the base class
if (n_elements(etc) gt 0) then begin
    retVal = self->DaveDat::set(_EXTRA=etc)
endif


return, retVal
end
;_______________________________________________________________________________
