function [loadDuringScan,startTime,timeDuringScan] =...
    getScanHDFdata(scanFile)
%[loadDuringScan,startTime,timeDuringScan] = getScanHDFdata(scanFile)
%==========================================================================
% Open and read a HDF file, looking for the time, load, and displacement
% data written during the June 2017 and November 2017 series of experiments
%
% --- INPUT ---
% scanFile - string, full path to file, including full file name.
%
% --- OUTPUT ---
% loadDuringScan - vec, load read from sensor
% startTime - time/date the file was opened (very close to the first time
%               data point)
% timeDuringScan - vec, running clock during scan or read-points for load
%
% -------------------------------------------------------------------------
% History - Orion L. Kafka
% 12-12-2017 - written
%
%==========================================================================

% Grab the load data from the hdf (scan record) data
file_info = h5info(scanFile,'/user_specific/Load/setup/Load from 2-BM-A_multimeter_voltage');
loadDuringScan = h5read(scanFile,...
    '/user_specific/Load/setup/Load from 2-BM-A_multimeter_voltage',1,file_info.Dataspace.Size);

file_info = h5info(scanFile,'/defaults/NDArrayTimeStamp');
timeDuringScan = h5read(scanFile,'/defaults/NDArrayTimeStamp',1,file_info.Dataspace.Size);
% re-zero time during scan
timeDuringScan = timeDuringScan - timeDuringScan(1);

% Get the scan start time into a "datatime" object that we
% can work with
startInts = h5read(scanFile,'/process/acquisition/start_date');
startSpaces = find(startInts==32);
startYear = cellstr(char(startInts(startSpaces(2)+1:startSpaces(3)-1))');
startMonth = cellstr(char(startInts(1:startSpaces(1)))');
startMonth = month2number(startMonth{1});
startDay = cellstr(char(startInts(startSpaces(1)+1:startSpaces(2)-2))');
startHour = cellstr(char(startInts(startSpaces(end)+1:startSpaces(end)+2))');
startMin = cellstr(char(startInts(startSpaces(end)+4:startSpaces(end)+5))');
startSec = cellstr(char(startInts(startSpaces(end)+7:startSpaces(end)+8))');
startTime = [startYear{1},startMonth,startDay{1},startHour{1},startMin{1},startSec{1}];
startTime = datetime(startTime,'InputFormat','yyyyMMddHHmmss');
% Convert to posix time, to be consistent
startTime = posixtime(startTime);