Viewing contents of file '../idllib/sdss/allpro/combine_atlas.pro'
pro combine_atlas,xs, ys, cnum, color,imtot, imu=imu,img=img,imr=imr,imi=imi,imz=imz

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;+
;
; NAME: 
;    COMBINE_ATLAS
;
; PURPOSE: 
;    Subroutine of get_atlas.  Combines images
;
; CALLING SEQUENCE:
;   combine_atlas,xs, ys, cnum, color,imtot, 
;         imu=imu,img=img,imr=imr,imi=imi,imz=imz
;
; INPUTS:  
;          xs: xsize array
;          ys: ysize array
;          cnum: color numbers
;          color: ['u','g'.....
;          imtot: output array with all subimages in it.
;          imu, img, ....
;
; OUTPUTS: 
;          imtot
;
; REVISION HISTORY:
;    Erin Scott Sheldon  3/14/99  Just a modularization.
;-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;; Very rarely, the atlas images are of different size 
;;; We must allow for that possibility.

 xsize = fix( total(xs) )
 ysize = max(ys)
 imtot=intarr(xsize,ysize)

 nn = n_elements(cnum)
 xstart = 0
 xend = xs[cnum[0]]
 for kk=0, nn-1 do begin
   n=cnum[kk]

   if (kk ne 0) then begin
      xstart = xstart + xs[ cnum[kk-1] ]
      xend = xend + xs[n]
   endif
   yend = ys[n]
   col = color[n]

   CASE col OF
      'u': imtmp=imu
      'g': imtmp=img
      'r': imtmp=imr
      'i': imtmp=imi
      'z': imtmp=imz
   ENDCASE
   imtot[xstart:xend-1, 0:yend-1] = imtmp
 endfor
 imtmp=0

return
end