Blame view

src/idl/dustem_fil_chi2.pro 1.12 KB
52a3cc37   Annie Hughes   First commit of I...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
FUNCTION DUSTEM_FIL_CHI2, sf, ntype=ntype
; fills in the Chi-square fields of an input SMDAT structure 
; (see format in DUSTEM_GET_BAND_FLUX)
;
; SF    (I): input SMDAT structure 
; NTYPE (I): index of SED to be used 

  if ntype EQ 0 then begin
     tt = SIZE(sf.sed.y)
     ntype = tt(2)
  endif
  ntag = N_TAGS(sf)
  stag = TAG_NAMES(sf)
  itg = WHERE( STRPOS(stag,'I_') GE 0, ctg )
  if ctg EQ 0 then begin
     print,'(F) DUSTEM_FIL_CHI2: no instrument to fill in'
     return,0
  endif
  yy=0d & mm=0d & ee=0d & ift=0
  for k = 0, ctg-1 do begin 
     i1 = WHERE( sf.(itg(k)).isel EQ 1 AND sf.(itg(k)).err GT 0, c1)
     if c1 GT 0 then begin
        sf.(itg(k)).chi2 = $
           DUSTEM_CHI2(sf.(itg(k)).yd(i1), sf.(itg(k)).ym(i1,ntype-1), sf.(itg(k)).npar, err=sf.(itg(k)).err(i1))
     endif
     yy = [ yy, sf.(itg(k)).yd ]
     ee = [ ee, sf.(itg(k)).err]
     mm = [ mm, sf.(itg(k)).ym(*,ntype-1) ]
     ift = [ ift, sf.(itg(k)).isel ]
  endfor
  yy=yy(1:*) & ee=ee(1:*) & mm=mm(1:*) & ift=ift(1:*)
  it = WHERE( ift EQ 1 AND ee GT 0, ct)
  if ct GT 0 then sf.chi2 = DUSTEM_CHI2( yy(it), mm(it), sf.npar, err=ee(it))

  return, sf
END