/****Copyright (c) 1997-2009 All rights reserved
 ****A. V. Gerbessiotis and C. J. Siniolakis
 ****Permission to use, copy, modify, and distribute this software,
 ****and to incorporate it, in whole or in part, into 
 ****other software,is hereby granted without fee, provided that
 ****  (1) the above copyright notice and this permission 
 ****      notice appear in all copies of the source code, and 
 ****      the above copyright notice appear in clearly visible 
 ****      form on all supporting documentation and distribution 
 ****      media, and
 ****     (2) any redistribution of the software, in original
 ****         or modified form, be without fee and subject to
 ****         these same conditions.
 ****   No guarantee, whatsoever, is offered that the code works as
 ****   advertised or is absent of any, even damaging,
 ****   side-effects. Use this code at your own personal risk.
 ****/
#include "smrg.h"

void    imerge1(data *src1,data *src2,int m1,int m2)
{
 register data *temp,*SRC,*DES;
 register int i,j,l,M;
 register data a,b;

 if ((m1<= 0)&& (m2<= 0)) return;
 temp = (data  *) malloc((m1+m2)*sizeof(data));
#ifdef SANITY_CHECK
  check_if_null((void *)temp,"imerge1","temp");
#endif
  i=j=l=0;
  while ((i<m1) && (j<m2)){
    a=src1[i]; b=src2[j];
    if (a<b) {
     temp[l]=a;i++;l++;
    }
    else {
     temp[l]=b;j++;l++;
    }
  }
  if (i <m1) IMEMCPY(&temp[l],&src1[i],(m1-i)*sizeof(data));
  if (j <m2) IMEMCPY(&temp[l],&src2[j],(m2-j)*sizeof(data));
  IMEMCPY(src1,temp,m1*sizeof(data));
  IMEMCPY(src2,&temp[m1],m2*sizeof(data));
  free((void *)temp);
}
