PRO smei_frm_darkfit, tt, plotx=plotx @compile_opt.pro ; On error, return to caller InitVar, plotx, /key ; the time origin MUST match the origin in the Fortran routines ; smei_frm_darkratio and smei_frm_fudgeratio. t0 = TimeSet('2003/04/15') files = findallfiles('*.dat.out',path=filepath(root=who_am_i(/dir),subdir='hists','old'),count=count) FOR i=0,count-1 DO BEGIN IF flt_read(files[i],tmp) THEN BEGIN boost,n,GetFileSpec(GetFileSpec(files[i],part='name'),part='name') boost,d,tmp ENDIF ENDFOR t = TimeSet(n) f = 0.5+d[*,0] ; functional fit to f(dt) = 1-exp(-a[0]*(dt-a[1])) a = [0.002,-260.0] dt = TimeOp(/subtract,t,t0,TimeUnit(/day)) print, '========= DARK RATIO ===========' print, 'Initial values: ', [1.0/a[0],a[1]] ;smei_frm_darkfnc, 0.0,a,e e = curvefit(dt,f,w,a,function_name='smei_frm_darkfnc', $ status=status,itmax=100,iter=iter) print, 'Final best fit: ', [1.0/a[0],a[1]] print, 'status=',status,iter IF plotx THEN BEGIN plotcurve, t, f, /silent smei_frm_darkfnc, dt,a,e plotcurve, t, e, /silent, /oplot ENDIF IF IsTime(tt) THEN BEGIN dt = TimeOp(/subtract,tt,t0,TimeUnit(/day)) smei_frm_darkfnc, dt,a,e print, tt, e ENDIF print, '========= FUDGE RATIO ===========' a = flt_read(filepath(root=who_am_i(/dir),'smei_frm_fudgeratio.txt'),f) t = TimeSet(yr=round(reform(f[0,*])),mon=round(reform(f[1,*])),day=round(reform(f[2,*]))) f = reform(f[3,*]) ; functional fit to f(dt) = 1-exp(-a[0]*(dt-a[1])) a = [0.001,-2000.0] dt = TimeOp(/subtract,t,t0,TimeUnit(/day)) print, 'Initial values: ', [1.0/a[0],a[1]] ;smei_frm_darkfnc, 0.0,a,e e = curvefit(dt,f,w,a,function_name='smei_frm_darkfnc', $ status=status,itmax=100,iter=iter) print, 'Final best fit: ', [1.0/a[0],a[1]] print, 'status=',status,iter IF plotx THEN BEGIN plotcurve, t, f, /silent, /oplot smei_frm_darkfnc, dt,a,e plotcurve, t, e, /silent, /oplot ENDIF IF IsTime(tt) THEN BEGIN dt = TimeOp(/subtract,tt,t0,TimeUnit(/day)) smei_frm_darkfnc, dt,a,e print, tt, e ENDIF RETURN & END