Skip to content
Snippets Groups Projects
Commit 9b2e81ab authored by leprob001's avatar leprob001
Browse files

Added export function of startEndToa and its test.

parent 0b071390
No related branches found
No related tags found
No related merge requests found
function [success] = save()
%SAVE Test function for saving a start end toa file.
% Uses a test rfb data file from the data folder. Uses only dummy fields
% for saving, because the actual algorithm for creating the data is not yet
% implemented.
[currentDirectory, ~, ~] = fileparts(mfilename('fullpath'));
dataFileName = fullfile(currentDirectory, '..', 'data', '0272.rfb');
% Select trajectory number
track = 2;
rfb = artoa.load.rfb(dataFileName);
% load test mat file exported from old version of artoa3
load(fullfile(currentDirectory, '..', 'data', 'float_0272_globals.mat'));
% get global variables that have been imported from the mat file
global TOA_DATE TOA TOA_SEL SOSOREF afoffbeg afoffend
% convert global variables to toaData format
toa = struct();
toa.status = zeros(length(TOA), 1);
toa.status(TOA_SEL > 0) = 1; % marks that the toa has been selected
toa.toa = TOA;
toa.toaDate = TOA_DATE;
toa.soundSource = cell(length(TOA), 1);
toa.soundSource(:) = {''};
for i = 1:length(toa.soundSource)
if TOA_SEL(i) == 0
continue;
end
toa.soundSource{i} = strtrim(SOSOREF(TOA_SEL(i), :));
end
%% Setup trajectory
trajectory = struct();
trajectory.trackingMethod = TRAJ(track).tmethod;
trajectory.interval = TRAJ(track).interval;
trajectory.gapSize = TRAJ(track).gapsize;
trajectory.interpolationMethod = TRAJ(track).imethod;
trajectory.soundSpeedMethod = TRAJ(track).ssmethod;
trajectory.dopplerCorrection = TRAJ(track).doppler;
trajectory.velocityMethod = TRAJ(track).vmethod;
trajectory.status = TRAJ(track).status;
trajectory.toaData = toa;
trajectory.latitude = TRAJ(track).lat;
trajectory.longitude = TRAJ(track).lon;
trajectory.date = TRAJ(track).date;
trajectory.pressure = TRAJ(track).pres;
trajectory.temperature = TRAJ(track).temp;
trajectory.iflag = TRAJ(track).iflag;
trajectory.clockError = TRAJ(track).clockerror;
trajectory.misfits = TRAJ(track).misfits;
trajectory.residualsPlotted = TRAJ(track).plotresiduals;
trajectory.velocityTotal = TRAJ(track).vtot;
trajectory.velocityLatitude = TRAJ(track).vlat;
trajectory.velocityLongitude = TRAJ(track).vlon;
trajectory.velocityVertical = TRAJ(track).vvert;
trajectory.velocityVerticalDate = TRAJ(track).vvert_date;
trajectory.additionalFloatOffsetBegin = afoffbeg;
trajectory.additionalFloatOffsetEnd = afoffend;
%% Setup sound sources
soundsources = artoa.load.soundsources(fullfile(currentDirectory, '..', 'data', 'HAFOS.soso'));
%% Save data
saveToFilename = fullfile(currentDirectory, '..', 'data', 'startEndToaOutput.trj4');
success = artoa.save.startEndToa(saveToFilename, trajectory, soundsources);
end
function [ success ] = startEndToa(pFilename, pTrajectory, pSoundSources)
%STARTENDTOA Saves the given data in start end toa format.
% Saves start and ending position of the given float.
%
% Parameters:
% pFilename (string) The destination filename.
% pSoundSources (struct) The sound sources loaded using
% artoa.load.soundsource function.
% pTrajectory (struct) The trajectory data according to the memory
% data format specification, see projects wiki.
%% Initialize return variables
success = false;
%% Initialize variables required for processing and defaults
noSoundSource = 'No SoSo';
dataString = '';
%% Parameter check
parameterError = false;
if (~isstring(pFilename) && ~ischar(pFilename))
warning([mfilename ': Given filename is neither a string nor a char!']);
parameterError = true;
end
if (~isstruct(pSoundSources))
warning([mfilename ': Given sound source data is not a struct!']);
parameterError = true;
end
if (~isstruct(pTrajectory))
warning([mfilename ': Given trajectory data is not a struct!']);
parameterError = true;
end
if (parameterError)
return;
else
clear parameterError;
end
%% Collect data
indexStart = find( ...
pTrajectory.toaData.toaDate == min(pTrajectory.toaData.toaDate) ...
);
indexEnd = find( ...
pTrajectory.toaData.toaDate == max(pTrajectory.toaData.toaDate) ...
);
% Collect toa
startToa = pTrajectory.toaData.toa(indexStart);
endToa = pTrajectory.toaData.toa(indexEnd);
% Collect toa date
startToaDate = pTrajectory.toaData.toaDate(indexStart);
endToaDate = pTrajectory.toaData.toaDate(indexEnd);
% Collect sound source names
startSources = pTrajectory.toaData.soundSource(indexStart);
endSources = pTrajectory.toaData.soundSource(indexEnd);
% Replace non selected soundsources by default string
startNotSelectedIndices = contains(startSources, '');
startSources(startNotSelectedIndices) = {noSoundSource};
endNotSelectedIndices = contains(endSources, '');
endSources(endNotSelectedIndices) = {noSoundSource};
for i = 1:length(startToa)
dataString = [ dataString ...
num2str(startToaDate(i)) ' ' ...
num2str(startToa(i)) ' ' ...
startSources{i} ' ' ...
num2str(endToaDate(i)) ' ' ...
num2str(endToa(i)) ' ' ...
endSources{i} newline ...
];
end
%% Save to file
saveToFile(pFilename, '', dataString);
%% Update return variable
success = true;
%% Nested functions
function saveToFile(pFilename, pHeader, pData)
fid = fopen(pFilename, 'w');
fprintf(fid, pHeader);
fprintf(fid, pData);
fclose(fid);
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment