Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [Points, vVolumeFaceMx, vSurfFaceMx] = ansysMeshReader(fileName)
- fid = fopen(fileName, 'r');
- %% Write all lines as strings
- cac = textscan( fid, '%[^\n]' );
- fclose(fid);
- A = char( cac{1} );
- %% Locate Point Mx
- i=1;
- % Initalize Termination Conditions: do while termination condition == 0
- end_of_points = 0; end_of_volume_faces = 0; end_of_surface_faces1 = 0;
- while (i<=size(A,1)-1)
- if strcmp(A(i, 1:4), '(10 ')==1 && strcmp(A(i+1, 1:4), '(10 ')~=1 % Find line before points defined, usually line 5
- start_of_points=i+2; % i+2 modified for ANSYS mesh files
- while end_of_points == 0
- if strcmp(A(i, 1:2),'))')==1
- end_of_points=i-1;
- end
- i=i+1;
- end
- end
- % Count on (for now) volume faces coming first
- if strcmp(A(i, 1:4), '(13 ')==1 && strcmp(A(i+2, 1:4), '(13 ')~=1 && end_of_volume_faces == 0
- start_of_volume_faces=i+1;
- while end_of_volume_faces == 0
- if strcmp(A(i, 1), ')') && strcmp(A(i+1, 1), ')') ==1
- end_of_volume_faces=i-1;
- end
- i=i+1;
- end
- end
- if strcmp(A(i, 1:4), '(13 ')==1 && end_of_volume_faces ~=0
- start_of_surface_faces1=i+1;
- while end_of_surface_faces1 == 0
- if strcmp(A(i, 1), ')') && strcmp(A(i+1, 1), ')') ==1
- end_of_surface_faces1=i-1;
- i=size(A,1);
- end
- i=i+1;
- end
- end
- i=i+1;
- end
- % Write points to MX
- Points = zeros(end_of_points,3); % Initialize
- for i=start_of_points : end_of_points
- Points(i-start_of_points+1, :)=sscanf(A(i,:), '%f');
- end
- % Write volume faces to a matrix
- for i=start_of_volume_faces : end_of_volume_faces
- % vFaceMx(i-start_of_faces+1, :)=sscanf(A(i,:), '%f'); %if mesh does not have hexidec notation
- vVolumeFaceMx(i-start_of_volume_faces+1, :)=sscanf(A(i,:), '%x'); %if mesh uses hexidec notation
- end
- % Write Surface Faces to a Matrix
- for i=start_of_surface_faces1 : end_of_surface_faces1
- % vFaceMx(i-start_of_faces+1, :)=sscanf(A(i,:), '%f'); %if mesh does not have hexidec notation
- vSurfFaceMx(i-start_of_surface_faces1+1, :)=sscanf(A(i,:), '%x'); %if mesh uses hexidec notation
- end
- vVolumeFaceMx = vVolumeFaceMx(:,1:4);
- vSurfFaceMx = vSurfFaceMx(:,1:3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement