This repository has been archived by the owner on May 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathh5ProcCloud.m
91 lines (69 loc) · 2.98 KB
/
h5ProcCloud.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
% Script to process and write metadata from HDF5 data file
%
% This script is now obsolete, and all functionality here is replaced by a
% Python-script 'writeXDMF.py'.
fileName = '../h5Data/h5Data0.h5';
[upperPath, folder] = fileparts(pwd);
XDMFname = strcat(folder, 'Clouds.xdmf');
%% Load and process cloud metadata
% Load mesh metadata
Info = h5info(fileName, '/CLOUDS/kinematicCloud');
% Find number of time steps present
nTimes = size(Info.Groups, 1);
% Extraxt some useful information from file
nPoints = zeros(nTimes, 1);
timeVals = zeros(nTimes, 1);
for i=1:nTimes
timeNames{i} = Info.Groups(i,1).Name;
timeVals(i) = sscanf(timeNames{i}, '/CLOUDS/kinematicCloud/%f');
nPoints(i) = Info.Groups(i,1).Datasets(1,1).Dataspace.Size(1,2);
end
%% Write XDMF file
% Sort time values
[T, idx] = sort(timeVals);
% Open File
fh = fopen(XDMFname, 'w');
% Print header
fprintf(fh, '<Xdmf>\n');
fprintf(fh, ' <Domain>\n');
fprintf(fh, ' <Grid Name="cloudData" GridType="Collection" CollectionType="Temporal">\n\n');
% Time loop
for t=1:nTimes
i = idx(t);
fprintf(fh, ' <Grid Name="time%f" Type="Uniform">\n',timeVals(i));
fprintf(fh, ' <Time Type="Single" Value="%f" />\n', timeVals(i));
% Geometry definition
fprintf(fh, ' <Geometry GeometryType="XYZ">\n');
fprintf(fh, ' <DataStructure Dimensions="%i 3" NumberType="Float" Presicion="4" Format="HDF" >\n', nPoints(i));
fprintf(fh, ' %s:%s/position\n', fileName, timeNames{i});
fprintf(fh, ' </DataStructure>\n');
fprintf(fh, ' </Geometry>\n');
fprintf(fh, ' <Topology Type="Polyvertex" NodesPerElement="1" NumberOfElements="%i">\n', nPoints(i));
fprintf(fh, ' </Topology>\n');
% Velocity
fprintf(fh, ' <Attribute Name="U" Center="Node" AttributeType="Vector">\n');
fprintf(fh, ' <DataStructure Format="HDF" DataType="Float" Precision="4" Dimensions="%i 3">\n', nPoints(i));
fprintf(fh, ' %s:%s/U\n', fileName, timeNames{i});
fprintf(fh, ' </DataStructure>\n');
fprintf(fh, ' </Attribute>\n');
% Slip velocity
fprintf(fh, ' <Attribute Name="Us" Center="Node" AttributeType="Vector">\n');
fprintf(fh, ' <DataStructure Format="HDF" DataType="Float" Precision="4" Dimensions="%i 3">\n', nPoints(i));
fprintf(fh, ' %s:%s/Us\n', fileName, timeNames{i});
fprintf(fh, ' </DataStructure>\n');
fprintf(fh, ' </Attribute>\n');
% Age
fprintf(fh, ' <Attribute Name="age" Center="Node" AttributeType="Scalar">\n');
fprintf(fh, ' <DataStructure Format="HDF" DataType="Float" Precision="4" Dimensions="%i">\n', nPoints(i));
fprintf(fh, ' %s:%s/age\n', fileName, timeNames{i});
fprintf(fh, ' </DataStructure>\n');
fprintf(fh, ' </Attribute>\n');
fprintf(fh, ' </Grid>\n\n\n');
end
% Print footer
fprintf(fh, ' </Grid>\n');
fprintf(fh, ' </Domain>\n');
fprintf(fh, '</Xdmf>\n');
% Close file
fclose(fh);
exit