Commit d60963ba authored by Simon Waldman's avatar Simon Waldman

Times2Datetime.m : now this recognizes the two different formats

that FVCOM uses in the Times field of different nc files...
parent c554f309
......@@ -9,9 +9,45 @@ function [ outputDTs ] = Times2Matlab( Times )
% Simon Waldman / Marine Scotland Science 2018.
global ftbverbose;
if ftbverbose
[~, subname] = fileparts(mfilename('fullpath'));
fprintf('\nbegin : %s\n', subname)
end
assert(ischar(Times), 'Input should be a character array.');
outputDTs = datetime( Times', 'InputFormat', 'yyyy-MM-dd''T''HH:mm:ss.SSSSSS');
% FVCOM can use two different formats for the Times variable, depending on
% which file it's in. So we have to mess around with accounting for both.
% There's probably a better way to do this that doesn't rely on catching
% errors...
try
outputDTs = datetime( Times', 'InputFormat', 'yyyy-MM-dd''T''HH:mm:ss.SSSSSS');
if ftbverbose
disp('Successfully converted Times to datetime using ''yyyy-MM-dd''T''HH:mm:ss.SSSSSS'' format.');
end
return;
catch
if ftbverbose
disp('Unable to convert the text to datetime using the format ''yyyy-MM-dd''T''HH:mm:ss.SSSSSS''. Trying other format.');
end
end
try
outputDTs = datetime( Times', 'InputFormat', 'yyyy/MM/dd'' ''HH:mm:ss.SSSSSS');
if ftbverbose
disp('Successfully converted Times to datetime using ''yyyy/MM/dd'' ''HH:mm:ss.SSSSSS'' format.');
end;
return;
catch
if ftbverbose
disp('Unable to convert the text to datetime using the format ''yyyy/MM/dd'' ''HH:mm:ss.SSSSSS''.');
end
error('Failed to convert Times to datetime using either FVCOM format.');
end
error('We should never get to here. Something went wrong.');
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment