% MKSDatum is a low level MKS class used for 
% storing physical property values

% Version 2.0 - updated 2024-02-28
classdef MKSDatum < MKSBase
    
    % Properties
    properties
        valueAccuracy = double.empty
        value = double.empty
        valueUnits = ""

        tempAccuracy = double.empty
        tempValue = double.empty
        tempUnits = ""

        presAccuracy = double.empty
        presValue = double.empty
        presUnits = ""

        xAccuracies = []
        xValues = []
        xUnits = ""

        errorString = ""
        reference = ""
        comment = ""
    end

    % Methods
    methods

        % processJson - decoded json input
        function mksDtm = processJson(mksDtm, jsonStruct)

            % Catch errors
            try

                % Temperature properties
                mksDtm.tempAccuracy = mksDtm.getJsonDbl(jsonStruct, "TempAccuracy");
                mksDtm.tempValue = mksDtm.getJsonDbl(jsonStruct, "Temperature");
                mksDtm.tempUnits = mksDtm.getJsonStr(jsonStruct, "TempUnits");
    
                % Pressure properties
                mksDtm.presAccuracy = mksDtm.getJsonDbl(jsonStruct, "PresAccuracy");
                mksDtm.presValue = mksDtm.getJsonDbl(jsonStruct, "Pressure");
                mksDtm.presUnits = mksDtm.getJsonStr(jsonStruct, "PresUnits");
    
                % Value properties
                mksDtm.valueAccuracy = mksDtm.getJsonDbl(jsonStruct, "ValueAccuracy");
                mksDtm.value = mksDtm.getJsonDbl(jsonStruct, "Value");
                mksDtm.valueUnits = mksDtm.getJsonStr(jsonStruct, "ValueUnits");
                
                mksDtm.xAccuracies = mksDtm.getJsonDArray(jsonStruct, "XAccuracies");
                mksDtm.xValues = mksDtm.getJsonDArray(jsonStruct, "XValues");
                mksDtm.xUnits = mksDtm.getJsonStr(jsonStruct, "XUnits");
        
                mksDtm.reference = mksDtm.getJsonStr(jsonStruct, "Reference");
                mksDtm.comment = mksDtm.getJsonStr(jsonStruct, "Comment");

            % Assign error
            catch
                mksDtm.errorString = "Datum could not be parsed.";
            end
        end
    end
end