-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeStreamtubes.m
80 lines (65 loc) · 2.14 KB
/
writeStreamtubes.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
function writeStreamtubes(Nodes, Tubes, OutFName, Flow, ks, Mask, OutFNameMask)
%WRITESTREAMTUBES output streamtubes to text file
% writeStreamtubes(Nodes, Tubes, OutFName)
%
% Richard Measures, Gu Stecca, NIWA
%
% See also delft3d_streamtubes
%% Extract some basic parameters
NoOfXs = size(Nodes,1);
NoOfVerts = size(Tubes{1,1},2);
NoOfLayers = size(Tubes{1,1},1);
NoOfNodes = size(Nodes{1,1},1);
% %% Flexibility to account for either single or variable ks
% if all(ks(:) == ks(1,1)) == 1
% ks = repmat(ks(1,1),NoOfVerts+1,NoOfXs);
% end
%% Open file for write access
FID=fopen(OutFName,'w');
%% Write header info
fprintf(FID, 'Drift Model Output\r\n');
fprintf(FID, 'number of x-secs: %i\r\n', NoOfXs);
fprintf(FID, 'number of flow tubes: %i\r\n', NoOfVerts);
fprintf(FID, 'number of VertTubes: %i\r\n', NoOfLayers);
%% Write cross-section data
for XsNo = 1:NoOfXs
% Cross-section header
fprintf(FID, '%-7i %1.5f\r\n',XsNo,Flow);
fprintf(FID, '%-7.5f ',ks{XsNo,1}');
fprintf(FID, '\r\n');
% Nodes
for NodeNo = 1:NoOfNodes
fprintf(FID, '%-7i %-7.2f %-7.2f % -7.6f\r\n', NodeNo, Nodes{XsNo,1}(NodeNo,:));
end
% Tubes
for VertNo = 1:NoOfVerts
for LayerNo = 1:NoOfLayers
fprintf(FID, '%-7i ',Tubes{XsNo,1}{LayerNo,VertNo});
fprintf(FID, '\r\n');
end
end
end
%% Close file
fclose(FID);
if iscell(Mask)
FIDM=fopen(OutFNameMask,'w');
%% Write header info
fprintf(FIDM, 'Drift Model Output\r\n');
fprintf(FIDM, 'number of x-secs: %i\r\n', NoOfXs);
fprintf(FIDM, 'number of flow tubes: %i\r\n', NoOfVerts);
fprintf(FIDM, 'number of VertTubes: %i\r\n', NoOfLayers);
%% Write cross-section data
for XsNo = 1:NoOfXs
% Cross-section header
fprintf(FIDM, '%-7i %1.5f\r\n',XsNo,Flow);
% Masks
for VertNo = 1:NoOfVerts
for LayerNo = 1:NoOfLayers
fprintf(FIDM, '%-7i ',Mask{XsNo,1}{LayerNo,VertNo});
fprintf(FIDM, '\r\n');
end
end
end
fclose(FIDM);
end
end