XIAN-FEM-2026June/三维matlab代码/matlab 3D一阶基 + bele/load_dat_vertices.m

29 lines
763 B
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function [V, nbr] = load_dat_vertices(datFile)
%LOAD_DAT_VERTICES Read NbrVertex and Vertex block from OpticsFEM .dat mesh.
%
% [V, nbr] = load_dat_vertices('belemesh.dat')
% V is N×3, row i matches vertex i in the dat file (same order as getMesh).
fid = fopen(datFile, 'r');
if fid < 0
error('无法打开网格文件: %s', datFile);
end
cleanup = onCleanup(@() fclose(fid));
tag = fscanf(fid, '%s', 1);
if ~strcmp(tag, 'NbrVertex')
error('期望 NbrVertex实际为 %s', tag);
end
nbr = fscanf(fid, '%d', 1);
tag = fscanf(fid, '%s', 1);
if ~strcmp(tag, 'Vertex')
error('期望 Vertex实际为 %s', tag);
end
V = reshape(fscanf(fid, '%f', nbr * 3), 3, []).';
if size(V, 1) ~= nbr
error('顶点数与 NbrVertex 不一致');
end
end