1 function [varargout]=read_array_tiles_sp(root,dmtiles,mptiles,num1,num2);
2 % [i,j,a]=read_array_tiles_sp(root,dmtiles,mptiles,num1,num2);
3 % a=read_array_tiles_sp(root,dmtiles,mptiles,num1,num2);
5 % read array produced by matching calls write_array_m in module_fr_sfire_util.F
6 % cycle tiles over dmtiles and mptiles
7 % from files root[_num1[_num2]].nnnn.txt, nnnn=1:dmntiles
8 % if mptiles nonempry, add tile*10000 to num1
9 % if dmtiles=[] mptiles=[] same as read_array_sp(root,num1,num2)
10 % output in [i j a] format works even when some indices are <1
12 % Jan Mandel, October 2008
14 if ~exist('num1','var'),
17 if ~exist('num2','var'),
20 ff=file_name(root,num1,num2);
21 if ~exist('dmtiles','var')
24 if ~exist('mptiles','var')
27 if isempty(dmtiles) & isempty(mptiles)
28 [i,j,a]=read_array_sp([ff,'.txt']);
30 i=[];j=[];a=[];tile=[];
40 f=sprintf('%s_%5.5i.%4.4i.txt',root,num1+10000*mptile,dmtile);
42 f=sprintf('%s_%5.5i.txt',root,num1+10000*mptile);
44 [ii,jj,aa]=read_array_sp(f);
45 i=[i;ii]; j=[j;jj]; a=[a;aa];
46 tile=[tile;ones(length(ii),1)*[dmtile,mptile]];
49 % check for consistent duplicates
50 isize=max(i)-min(i)+1;
51 ij=i+isize*(j-1); % coded pairs (i,j)
52 [k,kix]=sort(ij); % k=ij(kix)
55 ikix(kix)=[1:n]'; % ij=k(ikix);
56 same=find(k(2:end)==k(1:end-1));
57 idiff=same(a(kix(same+1))~=a(kix(same)));
69 for m=1:length(idiff);
70 fprintf('tile %i %i: a(%i,%i)=%g tile %i %i: a(%i,%i)=%g diff %g\n',...
71 t1(m,:),i1(m),j1(m),a1(m),t2(m,:),i2(m),j2(m),a2(m),a1(m)-a2(m))
73 warning('inconsistent values at overlap, taking the first seen')
75 % take out the duplicates
83 varargout{1}=sparse(i,j,a);
89 error('bad number of output arguments')