pro masstable,logt,logg,logmass
; This routine reads a bunch of Girardi isochrones and uses
; them to estimate the 2D function relating log(Teff) and log(g)
; to stellar mass. Method is to construct a uniform grid in
; logt and logg, then assign to each point a weighted sum over
; all isochrone points of the corresp mass.
; Weights are proportional to isochrone age (in effect, assumes
; constant star formation rate), and also to inverse square of
; weighted distance in log(T), log(g), with log(T) scaling
; distance smaller than that for log(g) by factor of 20. This
; covers roughly a factor of 7 because that is the ratio of the
; range of logg to logt, and an additional factor of 3 because we
; want teff similarity to outweigh logg similarity.
; make scales in logt, logg
rat=6. ; factor by which logg differences are scaled rel to logt
nt=20
ng=24
logt=3.4+(1./nt)*findgen(nt)
logg=-2.4+(8.0/ng)*findgen(ng)
logmass=fltarr(nt,ng)
rd_girardi,z,age,massi,massa,logl,logtr,loggr,mbol,vmag,flum
lm=alog10(massa)
for i=0,nt-1 do begin
tdif=abs((logtr-logt(i))) > .01
tdif2=tdif^2
for j=0,ng-1 do begin
gdif=abs(((loggr-logg(j))/rat)) > .05
gdif2=gdif^2
; wts=age/(tdif2+gdif2)
argw=sqrt(tdif2+gdif2)/.04
wts=age*exp(-(argw < 30.))
logmass(i,j)=total(lm*wts)/total(wts)
endfor
endfor
stop
end