-
Notifications
You must be signed in to change notification settings - Fork 45
/
loadopenpivtxtdir.m
94 lines (77 loc) · 2.49 KB
/
loadopenpivtxtdir.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function [v] = loadopenpivtxtdir(dirname,type)
% default inputs
if ~nargin
dirname = '.';
type = 'txt';
end
% default type input
if nargin < 2 | isempty(type)
type = 'txt';
end
if exist(dirname,'file') == 2
fileList = {dirname};
else
% get the fileList
fileList = listTXTfiles(dirname,type);
end
[v] = loadtopivmatstructure(dirname,fileList)
% % make quiver of the files
% for i = 1:numel(onlyTxtFiles)
% data = load(onlyTxtFiles{i});
% quiver(data(:,1),data(:,2),data(:,3),data(:,4));
% end
% % if in a single file, the data is like this:
% plot(data(:,3).^2 + data(:,4).^2)
end
function [v] = loadtopivmatstructure(dirname,fileList)
v = repmat(struct('x','y','vx','vy','choice','unitx','unity','namex','namey',...
'unitvx','unitvy','namevx','namevy','pivmat_version','ysign','Attributes',...
'name','setname','history','source'),1,length(fileList));
tmp = load(fullfile(dirname,fileList{1}));
x = tmp(:,1);
y = tmp(:,2);
lx = length(unique(x));
ly = length(unique(y));
for i = 1:length(fileList)
% Import the file
tmp = load(fullfile(dirname,fileList{i}));
% convert into PIVMAT structure
v(i).x = unique(tmp(:,1)).'; % reshape(tmp.data(:,2),lx,ly);
v(i).y = unique(tmp(:,2)).'; % reshape(tmp.data(:,3),lx,ly);
v(i).vx = reshape(tmp(:,3),lx,ly);
v(i).vy = reshape(tmp(:,4),lx,ly);
v(i).history = {['load_dpiv(',fileList{i},')']};
v(i).unitx = 'mm';
v(i).unitx = 'mm';
v(i).unitvx = 'm/s';
v(i).unitvx = 'm/s';
v(i).namex = 'x';
v(i).namey = 'y';
v(i).namevx = 'u_x';
v(i).namevy = 'u_y';
v(i).setname = 'tmp';
v(i).ysign = 'Y axis downward';
v(i).pivmat_version = '1.90';
end
end
function [fileList] = listTXTfiles(dirname,type)
% reading the files from the directory of the TYPE only
% TYPE: 'txt' or 'final'
% 'noflt' or 'raw'
% 'flt' or 'filtered'
wd = cd;
cd(dirname);
fileList = dir('*.txt'); % list all files
fltFileList = dir('*_flt.txt'); % only filtered (before interpolation)
noFltFileList = dir('*_noflt.txt'); % only raw files (before filtering and interpolation)
% list only final files, after filtering and interpolation
switch type
case{'txt','final'}
fileList = setdiff(setdiff({fileList.name},{fltFileList.name}),{noFltFileList.name});
case{'noflt','raw'}
fileList = {noFltFileList.name};
case{'flt','filtered'}
fileList = {fltFileList.name};
end
cd(wd);
end