function covm = cov_off_axis(combinecovfile) % function to read combinelayercov.out to spit out off-axis covariance % matrix terms for each region, for sin and cos if nargin < 1 combinecovfile = '/Users/zeilon/Dropbox/Work/JdF_SWanis/Don_inversions/regionalised_new_SW_results/combinelayercov.out'; end covm = struct('nlay',[],'zlay',[]); % open file fid = fopen(combinecovfile,'r'); % read layers a = textscan(fid,'%.0f',1); covm.nlay = a{1}; b = textscan(fid,'%f%f',covm.nlay); covm.zlay= [b{1} b{2}]; % read regions while 1 c = textscan(fid,'%s%s',1); cd = textscan(fid,'%f%f%f',handshake(covm.nlay)); s = textscan(fid,'%s%s',1); sd = textscan(fid,'%f%f%f',handshake(covm.nlay)); if feof(fid), break; end % skip if end of file % unnecessary one-liner... % c tells us region and cos, s tells us region and sin % then just make 3x3 covm matrix from d covm.(c{1}{1}) = struct(c{2}{1},full(sparse([cd{1};cd{2}],[cd{2},cd{1}],[cd{3};cd{3}],3,3)),... s{2}{1},full(sparse([sd{1};sd{2}],[sd{2},sd{1}],[sd{3};sd{3}],3,3)) ); end fclose(fid); end