function saveSRL(file, name, desc, nspk, pos, mtrx)
%function saveSRL(file, name, desc, nspk, pos, mtrx)
% file  : filename including path and .SRL
% name  : name of layout (e.g. 'surroundx')
% desc  : description (e.g. 'my favorite decode')
% nspk  : how many speakers actually used (<= 8)
% pos   : speaker coordinates (always 8x3 even if nspk < 8)
% mtrx  : decoding matrix (always 8x4 even if nspk < 8)
% ---
% version 1.0a, 06-Aug-2001
% Copyright (c) CATT 2001

fh = fopen(file,'w');
if fh == -1, disp(['failed to create ' file]); return, end

% file info

int = 703798; 
n_file_id = fwrite(fh,int,'integer*4'); 
int = 0;      
n_version = fwrite(fh,int,'integer*4');

%rig layout data

n_nspkr = fwrite(fh,nspk,'integer*2');

n_layout = fwrite(fh,0,'integer*2');

n_method = fwrite(fh,0,'integer*2');

maxname = [ name char(zeros(21-length(name),1)')];
n_name = fwrite(fh,maxname,'uchar');

maxname = [ desc char(zeros(33-length(desc),1)')];
n_desc = fwrite(fh,maxname,'uchar');

n_pos = fwrite(fh,pos','single'); %spkr coordinates

n_scale = fwrite(fh,1.,'single'); %scale to meter

n_mtrx = fwrite(fh,mtrx','single'); %matrix

fclose(fh);

return
