MATLAB讀取TECPLOT笛卡爾網格三維流場數據
阿新 • • 發佈:2017-11-16
find nsh mon ret filename demo ear ati 數據文件
tecplot按照網格點逐點輸出數據到文件,一個點的坐標及其相關數據寫成一行,更具數據文件頭可以知道,一行含七個數據,分別是x,y,z,u,v,w,rho。
1、matlab讀取tecplot文件,將數據存貯到三維數組中,並保存變量到mat文件以供調用
% read data from tecplot file % save the data as the three dimension arrays function [x,y,z,u,v,w,rho]=tecplot2mat(filename,num_head) %% tecplot data file read fid = fopen(strcat(filename,‘.dat‘)); data = textscan(fid,‘%f %f %f %f %f %f %f‘,‘headerlines‘,num_head); data = cell2mat(data); fclose(fid); %% reshape data % get discrete points xi = sort(unique(data(:,1))); yi = sort(unique(data(:,2))); zi = sort(unique(data(:,3))); % number of the discrete points num_x = length(xi); num_y = length(yi); num_z = length(zi); % initialize the three demonsions array x = zeros(num_x,num_y,num_z); y = zeros(num_x,num_y,num_z); z = zeros(num_x,num_y,num_z); u = zeros(num_x,num_y,num_z); v = zeros(num_x,num_y,num_z); w = zeros(num_x,num_y,num_z); rho = zeros(num_x,num_y,num_z); % assignment the array according to the data for n = 1:size(data,1) % % if we don‘t know the relationship between the number and the index,we % % must find the index according to the number % index_x = find(data(n,1) == xi); % index_y = find(data(n,2) == yi); % index_z = find(data(n,3) == zi); % if we know the relationship between the number and the index, we can % directly access the index index_x = data(n,1) + 1; index_y = data(n,2) + 1; index_z = data(n,3) + 1; % access the data x(index_x,index_y,index_z) = data(n,1); y(index_x,index_y,index_z) = data(n,2); z(index_x,index_y,index_z) = data(n,3); u(index_x,index_y,index_z) = data(n,4); v(index_x,index_y,index_z) = data(n,5); w(index_x,index_y,index_z) = data(n,6); rho(index_x,index_y,index_z) = data(n,7); end fprintf(‘reshape the data\n‘); %% data save to mat eval([‘save ‘,filename,‘ x y z u v w rho;‘]); fprintf(‘save the data\n‘); end
2、測試函數
clc;clear; close all; file_info = dir(‘*.dat‘); file_num = length(file_info); num_head = 3; for i = 1:file_num [~,~,~,~,~,~,~]=tecplot2mat(file_info(i).name,num_head); end
MATLAB讀取TECPLOT笛卡爾網格三維流場數據