-
Notifications
You must be signed in to change notification settings - Fork 4
/
write2bts.m
84 lines (55 loc) · 2.84 KB
/
write2bts.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
function write2bts(filename,u,v,w,t,y,z,zHub,uHub,ntower)
% This function is a first attempt to write output from windSimFast into
% bts file. The function write2bts is based on the function readTSgrid.m by
% Bonnie Jonkman, National Renewable Energy Laboratory
% Author: E. Cheynet - UiB - Last modified 28/11/2022
nffc = 3; % number of velocity components
nt = size(u,1);
ny = numel(y);
nz = numel(z);
dt = median(diff(t));
fid = fopen(filename,'wb');
dz = abs(median(diff(z)));
dy = abs(median(diff(y)));
if fid > 0
% Headers
fwrite( fid, 8, 'int16'); % TurbSim format identifier (E.C.: should = 8 to work on fast.Farm), INT(2)
fwrite( fid, nz, 'int32'); % the number of grid points vertically, INT(4)
fwrite( fid, ny, 'int32'); % the number of grid points laterally, INT(4)
fwrite( fid, ntower, 'int32'); % the number of tower points, INT(4)
fwrite( fid, nt, 'int32'); % the number of time steps, INT(4)
fwrite( fid, dz, 'float32'); % grid spacing in vertical direction, REAL(4), in m
fwrite( fid, dy, 'float32'); % grid spacing in lateral direction, REAL(4), in m
fwrite( fid, dt, 'float32'); % grid spacing in delta time, REAL(4), in m/s
fwrite( fid, uHub, 'float32'); % the mean wind speed at hub height, REAL(4), in m/s
fwrite( fid, zHub, 'float32'); % height of the hub, REAL(4), in m
fwrite( fid, min(z), 'float32'); % height of the bottom of the grid, REAL(4), in m
coeff = 1000;
fwrite(fid, coeff, 'float32'); % the U-component slope for scaling, REAL(4)
fwrite(fid, 0, 'float32'); % the U-component offset for scaling, REAL(4)
fwrite(fid, coeff, 'float32'); % the V-component slope for scaling, REAL(4)
fwrite(fid, 0, 'float32'); % the V-component offset for scaling, REAL(4)
fwrite(fid, coeff, 'float32'); % the W-component slope for scaling, REAL(4)
fwrite(fid, 0, 'float32'); % the W-component offset for scaling, REAL(4)
% Read the description string: "Generated by TurbSim (vx.xx, dd-mmm-yyyy) on dd-mmm-yyyy at hh:mm:ss."
asciiSTR = double('This full-field file was generated by windSimFast');
fwrite(fid, numel(asciiSTR), 'int32'); % the number of characters in the description string, max 200, INT(4)
fwrite(fid, asciiSTR, 'int8' ); % the ASCII integer representation of the character string
disp( ['Reading from the file ' filename ' with heading: ' ] );
disp( [' "' asciiSTR '".' ] ) ;
WF(:,:,:,1)=u;
WF(:,:,:,2)=v;
WF(:,:,:,3)=w;
val = zeros(1,nffc);
for it = 1:nt
for iz = 1:nz
for iy = 1:ny
for ii = 1:nffc
val(ii) = WF(it,iz,iy,ii)*coeff;
end
fwrite(fid, val, 'int16');
end
end
end
fclose(fid);
end