function processSVC_SIG(filepath)
% PROCESSSVC_SIG_ENHANCED 增强版SVC光谱处理器
%% 初始化模块
clc; close all; warning off;
fig = figure(‘Position’, [100, 100, 1000, 700], ‘Name’, ‘SVC光谱分析’);
try
%% 1. 安全数据读取模块
if ~exist(filepath, ‘file’)
error(‘FileNotFound: %s’, filepath);
end
% 多编码格式尝试读取 encodings = {'UTF-8', 'GBK', 'ISO-8859-1'}; for enc = encodings try fileContent = fileread(filepath, 'Encoding', enc{1}); break; catch continue; end end % 数据段提取(增强正则表达式) dataSection = regexp(fileContent, 'data=\s*([\d\.\s\-]+)', 'tokens'); if isempty(dataSection) error('NoDataSection: 文件中未找到有效数据段'); end % 安全数据转换 try data = sscanf(dataSection{1}{1}, '%f %f %f %f', [4, Inf])'; catch error('DataFormatError: 数据格式转换失败'); end %% 2. 数据验证模块 if size(data,1) < 10 || size(data,2) < 4 error('InsufficientData: 数据点不足或列数不够'); end wavelength = data(:,1); validRange = [min(wavelength), max(wavelength)]; %% 3. 特征分析模块(安全实现) featureBands = [550, 1450, 1940]; % 可配置特征波段 featureMarks = cell(1, length(featureBands)); for i = 1:length(featureBands) [~, idx] = min(abs(wavelength - featureBands(i))); if idx >= 1 && idx <= length(wavelength) featureMarks{i} = struct(... 'band', featureBands(i), ... 'wl', wavelength(idx), ... 'refl', data(idx,4), ... 'valid', true); else featureMarks{i} = struct('valid', false); end end %% 4. 可视化模块 % 子图1:辐射亮度 subplot(2,1,1); plot(wavelength, data(:,2), 'b-', 'LineWidth', 1.5); title('辐射亮度光谱'); xlabel('波长 (nm)'); ylabel('辐射亮度 (10^{-6} W·cm^{-2}·nm^{-1}·sr^{-1})'); grid on; xlim(validRange); % 子图2:反射率(带特征标注) subplot(2,1,2); plot(wavelength, data(:,4), 'k-', 'LineWidth', 1.5); hold on; % 安全标注特征 for mark = featureMarks if mark{1}.valid plot(mark{1}.wl, mark{1}.refl, 'ro', 'MarkerSize', 8); text(mark{1}.wl+20, mark{1}.refl, ... sprintf('%dnm\n%.1f%%', mark{1}.band, mark{1}.refl), ... 'FontSize', 8); end end title('反射率光谱'); xlabel('波长 (nm)'); ylabel('反射率 (%)'); grid on; xlim(validRange); %% 5. 输出模块 [outDir, fname] = fileparts(filepath); outputPath = fullfile(outDir, [fname '_analysis.png']); try saveas(fig, outputPath); fprintf('分析结果已保存至: \n%s\n', outputPath); catch warning('文件保存失败,请检查写入权限'); end
catch ME
%% 6. 增强错误处理
fprintf(2, ‘===== 处理失败 =====\n’);
fprintf(2, ‘错误类型: %s\n’, ME.identifier);
fprintf(2, ‘错误信息: %s\n’, ME.message);
% 显示调用栈(最多5层) stackDepth = min(length(ME.stack), 5); for k = 1:stackDepth fprintf(2, ' > %s (第%d行)\n', ... ME.stack(k).name, ME.stack(k).line); end % 尝试保存错误截图 if exist('fig', 'var') errPath = fullfile(pwd, 'SVC_processing_error.png'); saveas(fig, errPath); fprintf(2, '错误状态已保存至: %s\n', errPath); end
end
end 上述代码为使用SVC HR-1024i观测的无遮挡、直射遮挡标准板反射的太阳辐射辐射亮度数据(10-10 W cm-2 nm-1 sr-1),分别绘出无遮挡标准板、直射遮挡标准板反射的辐射亮度光谱曲线图的代码,进行下一步:使用上步结果,求算该时刻到达地面的太阳直射辐射被标准板反射的辐射亮度(10-10 W cm-2 nm-1 sr-1)光谱,绘出光谱曲线图。