function [data,datevec] = loadTMB(fname);
% LOADTMB Load data saved in TurboMAP binary format.
%
% [data,datevec] = loadTMB(fname)
% Reads the TurboMAP data matrix from the binary file fname.
% If the optional output parameter dd is specified, the 
% date stamp is extracted from the file and return in dd.
%
% Example call: A = loadTMB('c:\data\test.tmb');

% Fabian Wolk 
% Alec Electronics Co., Ltd. 2000
% #Revision 0.0: 2001/08/09#

COLSFORMAT    = 'uint16';
TIMEFORMAT    = 'uchar';
DATAFORMAT    = 'float32';

fid = fopen(fname,'rb','ieee-le');
if fid < 0
    %errordlg('Unable to open file for reading');
    data = [];
    datevec = [];
   return
else

ncols = fread(fid,1,COLSFORMAT);
dd = fread(fid,6,TIMEFORMAT);
dd(1) = dd(1)+2000;
[data,count] = fread(fid,inf,DATAFORMAT);

data = reshape(data,ncols,count/ncols)';
fclose(fid);

if nargout==2
   datevec = dd';
end
end
% end of function
