;+ ;FUNCTION fitredden,x,spec,jhk=jhk,errjhk=errjhk,parmresult=result ; ;PURPOSE To redden an appropiate stellar model to agree with 2MASS infrared ; JHK magnitudes found in Vizier. The reddening is done using the Fitzpatrick ; 1999 model. ; ;DETAILS You need to enter the JHK mags and their errors, it returns the ; reddened spectra and you have the option of outputting the two parameters ; used to redden and scale it [E(B-V),Scale Factor]. Note x=wavelegnth ; in microns. ; This requires the iso* routines which also require the RSR.sav file ; Output is in Watts/cm2/micron ; ;WRITTEN BY: Conor Laver 07/06/2006 ;- FUNCTION unredwrap,jhk,a,_extra=ex ;setup the parameters ebv=a[0] scale=a[1] x=ex.x firstguess=ex.firstguess ;remember the wavelength must be angstroms for fm_unred fm_unred,x*1e4,firstguess,ebv,funred scaledguess=funred*scale h_isoflux=isoh(x,scaledguess,calc=newh,quiet=1) k_isoflux=isok(x,scaledguess,calc=newk,quiet=1) j_isoflux=isoj(x,scaledguess,calc=newj,quiet=1) newmags=[newj,newh,newk] return,newmags end ;;;;;;;;;;;;;; THIS IS THE MAIN FUNCTION;;;;;;;;;;;;;;;;;;;;;;; FUNCTION fitredden,x,spec,jhk=jhk,errjhk=errjhk,parmresult=result ;start by scaling the spectra to the h mag h_isoflux=isoh(x,spec,mag=jhk[1],scaled=firstguess,calc=calc,quiet=1) ;initial guess will be zero reddening and a scaling parameter of one a=[0.0,1.0] extra={x:x,firstguess:firstguess} result=mpfitfun('unredwrap',[0,1,2],jhk,errjhk,a,functargs=extra) ;make the final spectrum from the results of mpfit fm_unred,x*1e4,firstguess,result[0],redderspec finalspec=redderspec*result[1] h_isoflux=isoh(x,finalspec,calc=finalh,quiet=1) k_isoflux=isok(x,finalspec,calc=finalk,quiet=1) j_isoflux=isoj(x,finalspec,calc=finalj,quiet=1) firstmags=unredwrap([0,1,2],[0.0,1.0],_extra=extra) ;last sanity check to make sure answers are logical print,'The inputted desired JHK magnitudes of your spectra were: ',jhk print,'The scaled guess without reddening gives JHK of: ',firstmags print,'The best reddened spectra gives JHK magnitudes of :',finalj,finalh,finalk print,'The inputted errors on JHK were: ',errjhk print,'The best reddened spectra gives differences from the desried of: ',jhk-[finalj,finalh,finalk] return,finalspec end