% MATLAB script to read in data files
% UFR3-35
% Jenssen, U., Schanderl, W. and Manhart, M.
% Technical University of Munich, 2019
% https://www.bgu.tum.de/en/hy/home/

clc
clearvars
close all

%% set name
% X stands for eXperiment, here PIV
% C stands for Computational data, here LES

filename_X = 'UFR3-35_X_data.txt'; % PIV data
filename_C = 'UFR3-35_C_data.txt'; % LES data
filename_C_cf = 'UFR3-35_C_cf.txt'; % LES data, cf at z1

delimiter = ',';
n_lines_header = 11; % first ten lines belong to header

%% read in  data
% description of the structure can be found on the wiki
PIVdata = dlmread(filename_X,delimiter,n_lines_header,0);
LESdata = dlmread(filename_C,delimiter,n_lines_header,0);
Cfdata = dlmread(filename_C_cf,delimiter,n_lines_header,0);

%% size of data fields
nX = 50; 
mX = 171; 

nC = 143;
mC = 131;

%% example how to reshape the data
xD_X = reshape(PIVdata(:,2),nX,mX); % x/D coordinates
zD_X = reshape(PIVdata(:,3),nX,mX); % z/D coordinates
u_X = reshape(PIVdata(:,4),nX,mX); % u/ub velocity
% and so on...

xD_C = reshape(LESdata(:,2),nC,mC); % x/D coordinates
zD_C = reshape(LESdata(:,3),nC,mC); % z/D coordinates
u_C = reshape(LESdata(:,4),nC,mC); % u/ub velocity
% and so on...

%% alternatively in a loop:
% n0 = 1;
% xD_X = zeros(nX,mX);
% for i = 1:mX
%     xD_X(:,i) = PIVdata(n0:i*nX,2); % x/D coordinates
%     % the remaining data sets go here...
%     n0 = i*nX+1;
% end