ALIGNSGDIVEPARAMS Align Seaglider dive parameters with column data. Syntax: DATA = ALIGNSGDIVEPARAMS(DATA, META, PARAMS) Description: DATA = ALIGNSGDIVEPARAMS(DATA, META, PARAMS) aligns the values of Seaglider dive parameters in the fields of struct DATA selected by character array or string cell array PARAMS with the data column fields. It assigns each parameter value to the first record of the corresponding dive in the final data column, and initializes all other entries as invalid (NaN). Notes: Some parameters like the target waypoint or the currents estimates are provided by Seagliders only once per dive in the log file (.log), and they are not timestamped. This function aligns them with the data collected during the dive as if they were timestamped as the first dive record. For some parameters (e.g. SENSOR_SECS) this might not be the nearest record. Examples: data = alignSGDiveParams(data, meta, params) See also: LOADSEAGLIDERDATA Authors: Joan Pau Beltran <joanpau.beltran@socib.cat>
0001 function data = alignSGDiveParams(data, meta, params) 0002 %ALIGNSGDIVEPARAMS Align Seaglider dive parameters with column data. 0003 % 0004 % Syntax: 0005 % DATA = ALIGNSGDIVEPARAMS(DATA, META, PARAMS) 0006 % 0007 % Description: 0008 % DATA = ALIGNSGDIVEPARAMS(DATA, META, PARAMS) aligns the values of 0009 % Seaglider dive parameters in the fields of struct DATA selected by 0010 % character array or string cell array PARAMS with the data column fields. 0011 % It assigns each parameter value to the first record of the corresponding 0012 % dive in the final data column, and initializes all other entries as 0013 % invalid (NaN). 0014 % 0015 % Notes: 0016 % Some parameters like the target waypoint or the currents estimates are 0017 % provided by Seagliders only once per dive in the log file (.log), and they 0018 % are not timestamped. This function aligns them with the data collected 0019 % during the dive as if they were timestamped as the first dive record. For 0020 % some parameters (e.g. SENSOR_SECS) this might not be the nearest record. 0021 % 0022 % Examples: 0023 % data = alignSGDiveParams(data, meta, params) 0024 % 0025 % See also: 0026 % LOADSEAGLIDERDATA 0027 % 0028 % Authors: 0029 % Joan Pau Beltran <joanpau.beltran@socib.cat> 0030 0031 % Copyright (C) 2014-2016 0032 % ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears 0033 % <http://www.socib.es> 0034 % 0035 % This program is free software: you can redistribute it and/or modify 0036 % it under the terms of the GNU General Public License as published by 0037 % the Free Software Foundation, either version 3 of the License, or 0038 % (at your option) any later version. 0039 % 0040 % This program is distributed in the hope that it will be useful, 0041 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0042 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0043 % GNU General Public License for more details. 0044 % 0045 % You should have received a copy of the GNU General Public License 0046 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0047 0048 error(nargchk(3, 3, nargin, 'struct')); 0049 0050 dive_select = ~cellfun(@isempty, {meta.engheaders.dive}'); 0051 dive_start = vertcat(meta.logheaders(dive_select).start); 0052 dive_start = [1900 + dive_start(:,3) dive_start(:, [1:2 4:6])]; 0053 dive_start_secs = etime(dive_start, dive_start(ones(size(dive_start,1),1),:)); 0054 record_secs = data.elaps_t; 0055 delta_secs = bsxfun(@minus, record_secs(:), dive_start_secs(:)'); 0056 delta_secs(delta_secs < 0) = nan; 0057 [first_records_offsets, first_records_indices] = min(delta_secs); 0058 dive_with_records = isfinite(first_records_offsets); 0059 first_records = false(size(record_secs)); 0060 first_records(first_records_indices(dive_with_records)) = true; 0061 other_records = ~first_records; 0062 param_name_list = cellstr(params); 0063 for param_name_idx = 1:numel(param_name_list) 0064 param_name = param_name_list{param_name_idx}; 0065 if isfield(data, param_name) 0066 data.(param_name)(first_records) = data.(param_name)(dive_with_records); 0067 if iscell(data.(param_name)) 0068 data.(param_name)(other_records) = {[]}; 0069 else 0070 data.(param_name)(other_records) = nan; 0071 end 0072 end 0073 end 0074 0075 end