PRO bbfit,w,b,db,t,f,noplot=noplot,maxtemp=maxt,ymax=ymax ; ; Procedure to fit a blackbody curve to PLBS brightness measurements. ; Uses FITPLANCK.PRO to generate first guess at blackbody temperature ; and multiplier scaling blackbody output to PLBS output. Uses CurveFit ; calling PLANCK.PRO to do a nonlinear least-squares best fit to refine ; first guesses. Plots data and overplots best fit once found. ; INPUTS: ; w = wavelengths of measurements ; b = measured PLBS brightnesses at wavelengths w ; db = uncertainties in measured brightnesses ; OUTPUTS: ; t = temperature of best-fit blackbody curve ; f = scale factor applied to blackbody output to match PLBS output ; ; create arrays for test factors and RMS errors in test fits IF N_Elements(maxt) EQ 0 THEN maxt=3125 ntries=(maxt-2000)/25.+1 mf=FLTARR(ntries) & rmse=mf ; try blackbody fits at 2000 K, 2025 K, ... 3125 K to make first guesses factor=1 ; dummy initial guess start=2000. step=25. FOR i=0,ntries-1 DO BEGIN params=[start+step*i,factor] fitplanck,w,b,db,params,error,/noplot,/noprint mf(i)=params(1) & rmse(i)=error ENDFOR ; Help,mf,rmse ; Stop ; make best guesses at t and f bge=MIN(rmse,bgi) bgf=mf(bgi) bgt=start+step*bgi bg=DOUBLE([bgt,bgf]) sigbg=DBLARR(2) ; refine guesses bestfit=curvefit(w,b,1./db,bg,sigbg,FUNCTION_NAME='planck') ;bestfit=SVDFIT(w,b,2, PRINT,bg(0),sigbg(0), $ FORMAT='("Best-fit temperature = ",F5.0," K +/- ",F7.0," K")' PRINT,bg(1),sigbg(1), $ FORMAT='("Best-fit multiplier = ",E9.2," +/- ",E9.2)' t=bg(0) f=bg(1) IF NOT KEYWORD_SET(noplot) THEN plotfit,w,b,db,bg,rmse,ymax=ymax RETURN END