Read aquatec data into MATLAB INPUT filename Optional string specifying the name of the file to read. OUTPUT tide_data A MATLAB matrix with three columns: tide_data(:,1) - MATLAB datetime tide_data(:,2) - temperature tide_data(:,2) - pressure NOTES This function will fail if there are non-equidistant time steps in the input file. DEVELOPMENT v 1.0 2012 BE. Initial development (as Aquatec2dfs0.m) v 1.1 02/2013 Modfied to return MATLAB structure DP. Documentation. TODO Include DFS0 functionality
0001 function tide_data = mrg_aquatec_to_mat(filename) 0002 % Read aquatec data into MATLAB 0003 % 0004 % INPUT 0005 % filename Optional string specifying the name of the file to read. 0006 % 0007 % OUTPUT 0008 % tide_data A MATLAB matrix with three columns: 0009 % tide_data(:,1) - MATLAB datetime 0010 % tide_data(:,2) - temperature 0011 % tide_data(:,2) - pressure 0012 % 0013 % NOTES 0014 % This function will fail if there are non-equidistant time steps in the 0015 % input file. 0016 % 0017 % DEVELOPMENT 0018 % v 1.0 2012 0019 % BE. Initial development (as Aquatec2dfs0.m) 0020 % v 1.1 02/2013 0021 % Modfied to return MATLAB structure 0022 % DP. Documentation. 0023 % 0024 % TODO 0025 % Include DFS0 functionality 0026 0027 %% Get file to read 0028 old_path = cd(); 0029 if ~exist('filename', 'var') 0030 [filename,path] = uigetfile('*.csv','Open *.csv AQUATEC file'); 0031 cd(path); 0032 if isempty(filename) 0033 return 0034 end 0035 end 0036 %% Imports data from the specified file 0037 DELIMITER = ','; 0038 HEADERLINES = 18; 0039 % Import the file 0040 newData1 = importdata(filename, DELIMITER, HEADERLINES); 0041 warning('mrg:DefaultValue', [mfilename ' is assuming you have 18 header rows.']); 0042 %% read date and time if possible 0043 try 0044 tide_data = datenum(newData1.textdata(HEADERLINES+1:end,2),'HH:MM:SS dd/mm/yyyy'); 0045 catch 0046 error('Error reading date/time from file'); 0047 end 0048 % Check time step for equidistant spacing 0049 timestep = round((tide_data(2,1) - tide_data(1,1))*24*60); 0050 t_steps = diff(tide_data(:,1))*24*60; 0051 if any(abs(t_steps - timestep)>=1/60) 0052 error('Timestep is not equidistant in file!'); 0053 end 0054 %% read data 0055 tide_data(:,2:3) = newData1.data(:,[2 4]); 0056 cd(old_path); 0057 end