Code covered by the BSD License  

Highlights from
slatec

from slatec by Ben Barrowes
The slatec library converted into matlab functions.

[tcos,i1,m1,i2,m2,i3]=s1merg(tcos,i1,m1,i2,m2,i3);
function [tcos,i1,m1,i2,m2,i3]=s1merg(tcos,i1,m1,i2,m2,i3);
%***BEGIN PROLOGUE  S1MERG
%***SUBSIDIARY
%***PURPOSE  Merge two strings of ascending real numbers.
%***LIBRARY   SLATEC
%***TYPE      SINGLE PRECISION (S1MERG-S, D1MERG-D, C1MERG-C, I1MERG-I)
%***AUTHOR  (UNKNOWN)
%***DESCRIPTION
%
%   This subroutine merges two ascending strings of numbers in the
%   array TCOS.  The first string is of length M1 and starts at
%   TCOS(I1+1).  The second string is of length M2 and starts at
%   TCOS(I2+1).  The merged string goes into TCOS(I3+1).
%
%***SEE ALSO  GENBUN
%***ROUTINES CALLED  SCOPY
%***REVISION HISTORY  (YYMMDD)
%   801001  DATE WRITTEN
%   891214  Prologue converted to Version 4.0 format.  (BAB)
%   900402  Added TYPE section.  (WRB)
%   901120  Modified to use IF-THEN-ELSE.  Previous spaghetti code did
%           not compile correctly with optimization on the IBM RS6000.
%           (RWC)
%   920130  Code name changed from MERGE to S1MERG.  (WRB)
%***end PROLOGUE  S1MERG
persistent j1 j2 j3 ; 

tcos_shape=size(tcos);tcos=reshape(tcos,1,[]);
%
if isempty(j1), j1=0; end;
if isempty(j2), j2=0; end;
if isempty(j3), j3=0; end;
%
%***FIRST EXECUTABLE STATEMENT  S1MERG
if( m1~=0 || m2~=0 )
%
if( m1==0 && m2~=0 )
[m2,dumvar2,dumvar3,dumvar4]=scopy(m2,tcos(sub2ind(size(tcos),max(i2+1,1)):end),1,tcos(sub2ind(size(tcos),max(i3+1,1)):end),1);   dumvar2i=find((tcos(sub2ind(size(tcos),max(i2+1,1)):end))~=(dumvar2));dumvar4i=find((tcos(sub2ind(size(tcos),max(i3+1,1)):end))~=(dumvar4));   tcos(i2+1-1+dumvar2i)=dumvar2(dumvar2i); tcos(i3+1-1+dumvar4i)=dumvar4(dumvar4i); 
%
elseif( m1~=0 && m2==0 ) ;
[m1,dumvar2,dumvar3,dumvar4]=scopy(m1,tcos(sub2ind(size(tcos),max(i1+1,1)):end),1,tcos(sub2ind(size(tcos),max(i3+1,1)):end),1);   dumvar2i=find((tcos(sub2ind(size(tcos),max(i1+1,1)):end))~=(dumvar2));dumvar4i=find((tcos(sub2ind(size(tcos),max(i3+1,1)):end))~=(dumvar4));   tcos(i1+1-1+dumvar2i)=dumvar2(dumvar2i); tcos(i3+1-1+dumvar4i)=dumvar4(dumvar4i); 
else;
%
j1 = 1;
j2 = 1;
j3 = 1;
%
while( true );
if( tcos(i1+j1)<=tcos(i2+j2) )
tcos(i3+j3) = tcos(i1+j1);
j1 = fix(j1 + 1);
if( j1>m1 )
[dumvar1,dumvar2,dumvar3,dumvar4]=scopy(m2-j2+1,tcos(sub2ind(size(tcos),max(i2+j2,1)):end),1,tcos(sub2ind(size(tcos),max(i3+j3+1,1)):end),1);   dumvar2i=find((tcos(sub2ind(size(tcos),max(i2+j2,1)):end))~=(dumvar2));dumvar4i=find((tcos(sub2ind(size(tcos),max(i3+j3+1,1)):end))~=(dumvar4));   tcos(i2+j2-1+dumvar2i)=dumvar2(dumvar2i); tcos(i3+j3+1-1+dumvar4i)=dumvar4(dumvar4i); 
tcos_shape=zeros(tcos_shape);tcos_shape(:)=tcos(1:numel(tcos_shape));tcos=tcos_shape;
return;
end;
else;
tcos(i3+j3) = tcos(i2+j2);
j2 = fix(j2 + 1);
if( j2>m2 )
break;
end;
end;
j3 = fix(j3 + 1);
end;
[dumvar1,dumvar2,dumvar3,dumvar4]=scopy(m1-j1+1,tcos(sub2ind(size(tcos),max(i1+j1,1)):end),1,tcos(sub2ind(size(tcos),max(i3+j3+1,1)):end),1);   dumvar2i=find((tcos(sub2ind(size(tcos),max(i1+j1,1)):end))~=(dumvar2));dumvar4i=find((tcos(sub2ind(size(tcos),max(i3+j3+1,1)):end))~=(dumvar4));   tcos(i1+j1-1+dumvar2i)=dumvar2(dumvar2i); tcos(i3+j3+1-1+dumvar4i)=dumvar4(dumvar4i); 
tcos_shape=zeros(tcos_shape);tcos_shape(:)=tcos(1:numel(tcos_shape));tcos=tcos_shape;
return;
end;
end;
tcos_shape=zeros(tcos_shape);tcos_shape(:)=tcos(1:numel(tcos_shape));tcos=tcos_shape;
end %subroutine s1merg
%DECK SASUM

Contact us at files@mathworks.com