File size: 5,003 Bytes
5ab75a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
function validate_params(params)
% validate_params - Validates the required input parameters for 
% EvaluateLightPollution
% Syntax: validate_params(params);
%
% =========================================================================
%
% Copyright (c)�2024�United States Government as represented by the
% Administrator of the National Aeronautics and Space Administration.
% All Rights Reserved.
%
% =========================================================================
%
% Description:
%    Validates that all required parameters are present based on whether
%    using MMT data distribution or explicitly specified distribution.
%
% =========================================================================
%
% Input:
%    params - Structure containing parameters for EvaluateLightPollution
%
% =========================================================================
%
% Output:
%    Throws error if required parameters are missing or invalid
%
% =========================================================================
%
% Initial version: Nov�2024;� Latest update: Nov�2024
%
% ----------------- BEGIN CODE -----------------

    % First check required fields for both methods
    validateRequiredBaseFields(params);
    
    % Determine which distribution method is being used
    if isempty(params.New.Mzen50)
        % Using MMT data distribution
        validateMMTFields(params);
    else
        % Using explicitly specified distribution
        validateExplicitFields(params);
    end
end

function validateRequiredBaseFields(params)
    % Check base required fields common to both methods
    if ~isfield(params, 'New') || ~isstruct(params.New)
        error('params.New structure is required');
    end
    
    required_new_fields = {'Nc', 'Altitude_km', 'Inclination_deg'};
    for i = 1:length(required_new_fields)
        field = required_new_fields{i};
        if ~isfield(params.New, field) || isempty(params.New.(field))
            error(['params.New.' field ' is required']);
        end
    end
    
    % Validate arrays match in size
    num_shells = numel(params.New.Nc);
    if numel(params.New.Altitude_km) ~= num_shells
        error('params.New.Altitude_km must have same number of elements as params.New.Nc');
    end
    if numel(params.New.Inclination_deg) ~= num_shells
        error('params.New.Inclination_deg must have same number of elements as params.New.Nc');
    end
end

function validateMMTFields(params)
    % Validate fields required for MMT data distribution
    if ~isfield(params, 'Analog') || ~isstruct(params.Analog)
        error('params.Analog structure is required when using MMT data distribution');
    end
    
    required_analog_fields = {'Type', 'datapath', 'UTbegin', 'UTend'};
    for i = 1:length(required_analog_fields)
        field = required_analog_fields{i};
        if ~isfield(params.Analog, field) || isempty(params.Analog.(field))
            error(['params.Analog.' field ' is required when using MMT data distribution']);
        end
    end
    
    % Check ReflBoxHWL_m requirement based on Type
    if strcmpi(params.Analog.Type, 'DifferentSatelliteDesign')
        if ~isfield(params.Analog, 'ReflBoxHWL_m') || isempty(params.Analog.ReflBoxHWL_m)
            error('params.Analog.ReflBoxHWL_m is required when Analog.Type is ''DifferentSatelliteDesign''');
        end
    end
    
    % Validate Type is one of the allowed values
    if ~any(strcmpi(params.Analog.Type, {'SameSatelliteDesign', 'DifferentSatelliteDesign'}))
        error('params.Analog.Type must be either ''SameSatelliteDesign'' or ''DifferentSatelliteDesign''');
    end
end

function validateExplicitFields(params)
    % Validate fields required for explicitly specified distribution
    required_fields = {'Mzen50', 'Mzen05', 'Mzen95', 'MzenAltkm'};
    for i = 1:length(required_fields)
        field = required_fields{i};
        if ~isfield(params.New, field) || isempty(params.New.(field))
            error(['params.New.' field ' is required when using explicit distribution']);
        end
        
        % Ensure fields are numeric
        if ~isnumeric(params.New.(field))
            error(['params.New.' field ' must be numeric']);
        end
    end
end

% ----------------- END OF CODE ------------------
%
% Please record any changes to the software in the change history
% shown below:
%
% ----------------- CHANGE HISTORY ------------------
% Developer |���� Date��� | Description
% ---------------------------------------------------
% J. Halpin��� |� 2024-Nov �| Initial version.
% =========================================================================
%
% Copyright (c)�2024�United States Government as represented by the
% Administrator of the National Aeronautics and Space Administration.
% All Rights Reserved.
%
% =========================================================================