Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ECheynet committed Nov 28, 2022
1 parent 847510f commit 5ddd782
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Binary file modified Example2.mlx
Binary file not shown.
84 changes: 84 additions & 0 deletions write2bts.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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, 7, 'int16'); % TurbSim format identifier (should = 7, just 'cause I like that number), 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















0 comments on commit 5ddd782

Please sign in to comment.