Last active
September 1, 2021 11:12
-
-
Save bogenpirat/04a187c1c25898647a823043cad85c03 to your computer and use it in GitHub Desktop.
function for reading node and beam data from radioss files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inFile = 'lattice_test_0000.rad.txt'; | |
fid = fopen(inFile); | |
clear('nodesTable', 'beamsTable'); | |
inNode = false; | |
inBeam = false; | |
line = ''; | |
while ischar(line) | |
line = fgetl(fid); | |
if length(line) == 1 || line(1) == '#' % skipping comments, empty lines | |
continue; | |
elseif line(1) == '/' % handle node/beam starts | |
inNode = startsWith(line, '/NODE'); | |
inBeam = startsWith(line, '/BEAM/'); | |
continue; | |
end | |
if inNode || inBeam % node/beam active? extract numbers | |
disp(line); | |
if inNode | |
val = [str2double(strtrim(line(1:10)))]; | |
for i = 11:20:length(line) | |
substr = line(i : i + 20 - 1); | |
val = [val, str2double(strtrim(substr))]; | |
end | |
if exist('nodesTable', 'var') == 0 | |
nodesTable = val; | |
else | |
nodesTable = [nodesTable; val]; | |
end | |
elseif inBeam | |
val = []; | |
for i = 1:10:length(line) | |
substr = line(i : i + 10 - 1); | |
val = [val, str2double(strtrim(substr))]; | |
end | |
if exist('beamsTable', 'var') == 0 | |
beamsTable = val; | |
else | |
beamsTable = [beamsTable; val]; | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment