view aim-mat/tools/@parameter/getas.m @ 0:74dedb26614d

Initial checkin of AIM-MAT version 1.5 (6.4.2011).
author tomwalters
date Fri, 20 May 2011 12:32:31 +0100
parents
children 20ada0af3d7d
line wrap: on
line source
% method of class @parameter
%
% (c) 2003-2008, University of Cambridge
% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
function val=getas(param,text,selectedunit,panel)
% returns the current value of the parameter if its an float or an int

cont=param.entries;
nrent=length(cont);

if nargin<4 % search in all subsections
    panel='all';
end

nr=getentrynumberbytext(param,text,panel);

if nr>0
    type=cont{nr}.type;

    if nargin==2
        selectedunit=cont{nr}.orgunit;
    end

    handleb=gethandle(param,text,panel,1);
    if  ~isequal(handleb,0) && ishandle(handleb) % yes, there is a screen representation
        strvalue=get(handleb,'string');            % value is a string, lets see what we make of it
        if ~strcmp(strvalue,'auto')
            orgvalue=str2num(strvalue); % its a float, it must have a value
            
            unitty=cont{nr}.unittype;
            if isa(unitty,'unit_none')
                rawvalue=orgvalue;
                selectedunit='';
            else
                cunit=getcurrentunit(param,text);
                rawvalue=fromunits(unitty,orgvalue,cunit); % translate to rawdata
                testvalue=tounits(unitty,rawvalue,cont{nr}.orgunit); %the unit in which the min and max values are defined
                val=fromunits(unitty,orgvalue,selectedunit); % translate to asked unit
            end
            val=tounits(unitty,rawvalue,selectedunit);
            return
        else
            val='auto';
            return
        end
    else % no representation on screen
        unittype=param.entries{nr}.unittype;
        rawval=cont{nr}.rawvalue;
        stringval=cont{nr}.stringvalue;
        if isequal(rawval,'auto')
            val=rawval;
            return
        end
        if isa(unittype,'unit_none')
            val=str2num(stringval);
        else
            val=tounits(unittype,rawval,selectedunit);
        end
    end
else
    error('getas:: error, the entry does not exist');
end