;------------------------------------------------------------------------------
;+
; NAME:
;   maskfitstoply
;
; PURPOSE:
;   Input a fits polygon file (leave off .fits) with weights assigned in python, output the .ply with appropriate weights.
;
; CALLING SEQUENCE:
; maskfitstoply,maskfnamebase,geomplyfname 
; where maskfnamebase.fits exists, and maskfnamebase.ply will be created.
; 
;
; OPTIONAL INPUTS:
;
; OUTPUTS:
; maskfnamebase.ply
; EXAMPLES:
;
; REQUIREMENTS:
; stuff.
;
; REVISION HISTORY:
;
; 11-Feb-2013 Written by Beth Reid (LBNL) /home/bareid/boss/mksamplecatslatestdr10/v5/fitstoply.pro
;  8-May-2014 Copied over to mksample and slightly modified the inputs
;
;------------------------------------------------------------------------------
pro maskfitstoply,fitsmaskbase,geomplyfname
  print,' '
  print,'fitstoply'
  print,'Input fitsmask: ',fitsmaskbase+'.fits'
  print,'Output poly: ',fitsmaskbase+'.ply'
  print,'Geom poly: ',geomplyfname

  polyhdr=0
  read_mangle_polygons,geomplyfname,dummy,hdr=polyhdr
  ;; do this just to get polyhdr.

  ; Get the pixelisation scheme
  pixscheme = (strsplit(polyhdr[0],/extract))[1]
  ; Will die here unless uses simple pix scheme.
  pixres = nint((strsplit(pixscheme,'s',/extract))[0])
  print,'Using ',pixres,'s pixels from boss_geometry'

  read_fits_polygons,fitsmaskbase+'.fits',bosspoly

  outfname = fitsmaskbase+'.ply'

  write_mangle_polygons, outfname , bosspoly,$
    hdr=polyhdr,/pixels

end



