Viewing contents of file '../idllib/uit/pro/clust_flux.pro'
pro clust_flux, wave, time, expon, flux, log_Z, init_m, NoInterp = nointerp, $
	Mass_range = Mass_range, Z_evol=Z_evol, OldKurucz = oldkurucz, $
	OldMaeder = oldmaeder, Silent = Silent, Mdot = mdot
;+
; NAME:
;	CLUST_FLUX
; PURPOSE:
;	Returns the flux of a model star cluster at a specified wavelength
;	as a function of time.
;
; CALLING SEQUENCE:
;	CLUST_FLUX, wave, time, expon, flux,[ log_z, init_m, Mass_range = , 
;			NoInterp = , Z_evol = , OldKurucz =, Oldmaeder = ,
;			Mdot = mdot, /SILENT ]
;
; INPUTS:
;	WAVE - Wavelength(s) (A) at which to determine flux, scalar or vector
;		Set WAVE = -1 to determine the Lyman continuum flux.    WAVE
;		may be modified upon output, if the /NoInterp keyword is set
;	TIME - Time(s) (in Myr) following starburst at which to evaluate flux, 
;		scalar or vector
;	EXPON - power law exponent, usually negative, scalar or vector
;		The number of values in expon equals the number of different
;		power-law components in the IMF
;		A Saltpeter IMF has a scalar value of expon = -1.35
;
; KEYWORD INPUT:
;	MASS_RANGE - vector containing upper and lower limits of the IMF and
;               masses where the IMF exponent changes.   The number of values
;		in mass_range should be one more than in expon.   The values
;		in mass_range should be monotonically increasing.    For 
;		a scalar value of EXPON the default value of MASS_RANGE is
;		[0.1, 110].
;
; OPTIONAL INPUT:
;	LOG_Z  - Log of the metal abundance relative to solar.  Suggested values
;		are 0.3, 0, -0.4, -0.7, or -1.5.  CLUST_FLUX will prompt for 
;		LOG_Z if not supplied.
;	INIT_M - This parameter determines the discrete masses at which to 
;		evaluate the cluster flux.   If INIT_M is not supplied,
;		or set to 0, then the discrete initial masses of the Schaller 
;		et al (1992) models are used (with a factor of 10 finer grid for
;		the post-main-sequence).   The user can alter this default mass 
;		grid in two ways:
;
;		(1)  If INIT_M is a vector it is assumed to explicitly contain 
;		each mass at which the cluster flux is to be evaluated
;
;		(2)  If INIT_M is a scalar positive integer, it specifies how
;		how many times finer the mass grid should be than the 
;		default; i.e setting INIT_M=2 will double the number of
;		mass_grid points.
;
; OPTIONAL KEYWORD INPUT:
;	Z_Evol - scalar giving metal abundance to compute Schaller (1992) 
;		evolution models with.   Must be 0.04, 0.02, 0.004, 0.008, or 
;		0.001.  If not supplied, then metallicity closest to log_Z is 
;		selected. 
;	NoInterp - If this keyword set, then the input wavelengths are rounded
;		off to the nearest Kurucz model wavelengths.    This avoids
;		interpolation in wavelength and saves considerable time.
;	OldKurucz - If this keyword is set and non-zero, then the old (1979)
;		Kurucz models are used.   Cannot be used with /NoInterp
;	OldMaeder - If set and non-zero, then the old (1989) Maeder tracks are
;		are used.
;	Silent - If set and non-zero, informational messages are suppressed
;
; OUTPUT:
;	FLUX  - Flux vector dimensioned NWAVE by NTIME where NWAVE is the number
;		of elements in WAVE and NTIME is then number of elements in 
;		TIME.  Units are ergs s(-1) A(-1) per solar mass formed.   
;		If WAVE = -1, then FLUX is given in 10(45) Lyman continuum 
;		photons per second.
; EXAMPLES:
;	Find the 1600 A flux every Myr during the first 10 Myr, for a star
;	cluster with an IMF exponent gamma = -2, and upper and lower mass
;	limits of 0.1 and 110 Msun
;
;          IDL> CLUST_FLUX, 1600, indgen(11), -2, f, mass_range = [0.1,110]
;
; REVISION HISTORY:
;	Written         W. Landsman         September, 1989
;	Updated for new Maeder models       August, 1992
;	Added /NoInterp keyword             September, 1992
;	Support multicomponent IMF          April, 1993
;-
 On_error,2

 if N_params() LT 4 then begin
  print, $
    'Syntax - CLUST_FLUX, wave, time, expon, flux,[ log_z, init_m, Mass_range=
   print,'               /Silent, /NoInterp, Z_evol = , /OldKurucz, /OldMaeder]'
   print,'   '
   print,'   wave - Input wavelength to evaluate cluster flux, scalar or vector
   print,'   time - Times at which to evaluate cluster flux, scalar or vector
   print,'   expon - Exponent of the IMF, negative scalar or vector
   print,'   flux - Output flux vector, dimensioned (N_wave by N_time)
   print,'   Mass_range = ,vector giving mass range of IMF
  return
 endif

 zparcheck, 'CLUST_FLUX', wave, 1, [2,3,4,5], [0,1], 'Wavelength'
 zparcheck, 'CLUST_FLUX', expon, 3, [1,2,3,4,5], [0,1], 'Power-law exponent'
                                                                
 if min(expon) GE 0 then $
    message,'ERROR - Exponent of the IMF must be negative'

 if ( N_elements(expon) EQ 0 ) then expon = -1.35         ;Default IMF exponent
 if not keyword_set( Mdot ) then mdot = 1
 if not keyword_set( mass_range ) then $
       if N_elements(expon) EQ 1 then mass_range = [0.1,110] $
		else message,'ERROR - MASS_RANGE keyword not supplied

 Ncomp = N_elements(expon)
 if N_elements( mass_range) ne Ncomp+1 then message, $
  'ERROR - MASS_RANGE vector must contain ' + strtrim(Ncomp+1,2) + ' elements'

 rd_logz = N_elements(log_z) NE 1

 RD_Z:  if rd_logz then read, $
     'Enter log metal abundance (usually 0.3, 0, -0.4 -0.7, or -1.5): ', log_z

 if not keyword_set(Z_evol) then begin
    if keyword_set( OldMaeder) then zevol = [0.002,0.005,0.02,0.04] $ 
                               else zevol = [0.04, 0.02, 0.008, 0.004, 0.001]
    tabinv, alog10( zevol/0.02), log_Z, i
    Z_evol = zevol( nint(i) )
 endif

 nmass = N_elements(init_m)
 mgrid = 1
 if nmass EQ 1 then begin
      init_m = init_m(0)
      if init_m EQ 0. then nmass = 0 else $
      if init_m GE 1 then begin
             mgrid = init_m
             nmass = 0
      endif
 endif

 if ( mgrid GT 20 ) then message,'ERROR - ' + $
            'Too many mass grid points -- INIT_M = ' + strtrim(mgrid,2)

 nwave = N_elements( wave )
 ntime = N_elements( time )
 flux = fltarr( nwave, ntime)

 for i = 0,ntime-1 do begin
     if nmass EQ 0 then init_m = $
        mass_grid( time(i), mgrid, Mdot = mdot, z=Z_evol, Oldmaeder = oldmaeder)

        clustmod, wave, f, time(i), expon, log_z, init_m, Mdot = mdot, $
                  Mass_range = mass_range, Z=Z_evol, NoInterp = nointerp, $
                  OldKurucz = oldkurucz, OldMaeder = oldmaeder,Silent = silent
        for j = 0,nwave-1 do flux(j,i) = tsum(init_m,f(j,*))

 endfor

 return
 end