;
; NAME:
;    makepup.pro
;
; PURPOSE:
;    this module creates a matrix representing the pupil of the telescope.
;    It makes an annular pupil of the right size with values of 1 inside
;    and 0 outside of the pupil.
;
; CALLING SEQUENCE:
;    pupil = makepup(dim,  $
;                    diam, $
;                    cobs  )
;
; INPUTS:
;    dim = x- and y-dimensions of the simulation matrix to generate
;          [integer or long, in sampling points]
;    diam  = actual linear dimension of the pupil in the simulation
;            [integer or long, in sampling points]
;    cobs  = relative diameter of the central obsturation
;            [float, <1, fraction of pupdiam]
;
; OUTPUT:
;    pupil = the matrix containing the pupil [bytes, dim x dim]
;
; Marcel Carbillet [marcel.carbillet@unice.fr],
; UMR 7293 Lagrange (UNS/CNRS/OCA), February 2013.
;
FUNCTION makepup, dim, diam, eps

; by default the pupil is centered on the center of the array
; (i.e. NOT on a pixel for a square array…)
xc = (dim-1L)/2.
yc = (dim-1L)/2.

x = rebin(findgen(dim), dim, dim)            - xc
y = transpose(rebin(findgen(dim), dim, dim)) - yc

dummy = sqrt(x^2.+y^2.)/(diam/2.)

; pupil array is 1 under the pupil and 0 elsewhere
pupil = (dummy lt 1.) and (dummy ge eps)

; return the pupil array and back to calling program
return, pupil
end