The mat2tt.m script converts a matrix with raw data in ASCII format into a binary file with .DAT extension that can be read into the LISST-SOP for processing. It is useful for converting .LOG files created in LISST-SOP version 4.65 and lower into .DAT files for analysis. LISST-SOP version 5.0 and higher are all capable of reading .LOG files and process them.
————————-
% Mat2TT file for matlab use
% Usage:
%
% Result=Mat2TT([‘filename’],data);
% where Result = number of bytes saved
% filename= name and path to save data to
% data = Matlab variable to saved, across the rows
%
% Save a variable in TattleTale Binary format
% Created 2/22/2003 HCP
% Updated 4/16/2008 OAM to include batch processing as well as selecting a
% file using a gui
function result = mat2tt(FileNameDat,data)
if nargin == 2;%if a .DAT file name and existing data matrix is specified
[m,n] = size(data);
data_col = reshape(data’,1,m*n); %reshape data into column, taken across rows
data_byte(1:2:length(data_col)*2) = fix(data_col/256);
data_byte(2:2:length(data_col)*2) = data_col-fix(data_col/256).*256; % seperate high and low bytes
fid = fopen(FileNameDat,’wb’);%open for writing; wb
result = fwrite(fid,data_byte,’uint8′);%write
fclose all
else
[FileNameLog,PathName] = uigetfile(‘.log’,’Select the .log file(s) you want to process’,’MultiSelect’,’on’);%and then select the log file(s) for processing, get their names and directory
if iscell(FileNameLog) == 0;%special case if we only have one file
data = load(fullfile(char(PathName),char(FileNameLog)));%load the .LOG file into matrix called data
s = num2str(FileNameLog);%create a string with the .LOG file name
k = find(s==’.’);
s(k+1:k+3)=(‘DAT’);%change extension to .DAT
FileNameDat = fullfile(PathName,s);%create new path and filename for the .DAT file to be saved shortly
[m,n] = size(data);
data_col = reshape(data’,1,m*n); %reshape data into column, taken across rows
data_byte(1:2:length(data_col)*2) = fix(data_col/256);
data_byte(2:2:length(data_col)*2) = data_col-fix(data_col/256).*256; % seperate high and low bytes
fid = fopen(FileNameDat,’wb’);%open for writing
result = fwrite(fid,data_byte,’uint8′);%write
fclose all
else%if more than one .LOG file has been selected we will no loop through all entries in FileNameLog and process the files one by one
FileNameLog = sort(FileNameLog);%sort it
for x = 1:length(FileNameLog)
data = []; FileNameDat = []; data_byte=[]; data_col=[]; s=[];%reset matrices
data = load(fullfile(char(PathName),char(FileNameLog(x))));%load the .LOG file into matrix called data
s = num2str(char(FileNameLog(x)));%create a string with the .LOG file name
k = find(s==’.’);
s(k+1:k+3)=(‘DAT’);%change extension to .DAT
FileNameDat = fullfile(PathName,s);%create new path and filename for the .DAT file to be saved shortly
[m,n] = size(data);
data_col = reshape(data’,1,m*n); %reshape data into column, taken across rows
data_byte(1:2:length(data_col)*2) = fix(data_col/256);
data_byte(2:2:length(data_col)*2) = data_col-fix(data_col/256).*256; % seperate high and low bytes
fid = fopen(FileNameDat,’wb’);%open for writing
result(x).data = fwrite(fid,data_byte,’uint8′);%write
fclose all
end
end
end
—————————– |