Skip to content

Commit 5ddd782

Browse files
authored
Add files via upload
1 parent 847510f commit 5ddd782

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Example2.mlx

54.9 KB
Binary file not shown.

write2bts.m

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
function write2bts(filename,u,v,w,t,y,z,zHub,uHub,ntower)
2+
% This function is a first attempt to write output from windSimFast into
3+
% bts file. The function write2bts is based on the function readTSgrid.m by
4+
% Bonnie Jonkman, National Renewable Energy Laboratory
5+
% Author: E. Cheynet - UiB - Last modified 28/11/2022
6+
7+
nffc = 3; % number of velocity components
8+
nt = size(u,1);
9+
ny = numel(y);
10+
nz = numel(z);
11+
dt = median(diff(t));
12+
fid = fopen(filename,'wb');
13+
14+
dz = abs(median(diff(z)));
15+
dy = abs(median(diff(y)));
16+
17+
if fid > 0
18+
19+
% Headers
20+
fwrite( fid, 7, 'int16'); % TurbSim format identifier (should = 7, just 'cause I like that number), INT(2)
21+
fwrite( fid, nz, 'int32'); % the number of grid points vertically, INT(4)
22+
fwrite( fid, ny, 'int32'); % the number of grid points laterally, INT(4)
23+
fwrite( fid, ntower, 'int32'); % the number of tower points, INT(4)
24+
fwrite( fid, nt, 'int32'); % the number of time steps, INT(4)
25+
fwrite( fid, dz, 'float32'); % grid spacing in vertical direction, REAL(4), in m
26+
fwrite( fid, dy, 'float32'); % grid spacing in lateral direction, REAL(4), in m
27+
fwrite( fid, dt, 'float32'); % grid spacing in delta time, REAL(4), in m/s
28+
fwrite( fid, uHub, 'float32'); % the mean wind speed at hub height, REAL(4), in m/s
29+
fwrite( fid, zHub, 'float32'); % height of the hub, REAL(4), in m
30+
fwrite( fid, min(z), 'float32'); % height of the bottom of the grid, REAL(4), in m
31+
32+
33+
coeff = 1000;
34+
35+
fwrite(fid, coeff, 'float32'); % the U-component slope for scaling, REAL(4)
36+
fwrite(fid, 0, 'float32'); % the U-component offset for scaling, REAL(4)
37+
fwrite(fid, coeff, 'float32'); % the V-component slope for scaling, REAL(4)
38+
fwrite(fid, 0, 'float32'); % the V-component offset for scaling, REAL(4)
39+
fwrite(fid, coeff, 'float32'); % the W-component slope for scaling, REAL(4)
40+
fwrite(fid, 0, 'float32'); % the W-component offset for scaling, REAL(4)
41+
42+
% Read the description string: "Generated by TurbSim (vx.xx, dd-mmm-yyyy) on dd-mmm-yyyy at hh:mm:ss."
43+
asciiSTR = double('This full-field file was generated by windSimFast');
44+
fwrite(fid, numel(asciiSTR), 'int32'); % the number of characters in the description string, max 200, INT(4)
45+
fwrite(fid, asciiSTR, 'int8' ); % the ASCII integer representation of the character string
46+
disp( ['Reading from the file ' filename ' with heading: ' ] );
47+
disp( [' "' asciiSTR '".' ] ) ;
48+
49+
WF(:,:,:,1)=u;
50+
WF(:,:,:,2)=v;
51+
WF(:,:,:,3)=w;
52+
53+
val = zeros(1,nffc);
54+
for it = 1:nt
55+
for iz = 1:nz
56+
for iy = 1:ny
57+
for ii = 1:nffc
58+
val(ii) = WF(it,iz,iy,ii)*coeff;
59+
end
60+
fwrite(fid, val, 'int16');
61+
end
62+
end
63+
end
64+
65+
66+
67+
fclose(fid);
68+
69+
end
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+

0 commit comments

Comments
 (0)