Blame view

src/idl/dustem_get_band_flux.pro 23.3 KB
aed288de   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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
FUNCTION DUSTEM_GET_BAND_FLUX, dpath, inst, xs=xs, ys=ys, smi=smi, unit=unit, VERBOSE=verbose

  if n_params() EQ 0 then begin 
     print,'-------------------------------------------------------------------------------------------------------------------------'
     print,'FUNCTION GET_BAND_FLUX, dpath, inst, xs=xs, ys=ys, smi=smi, unit=unit, VERBOSE=verbose'
     print,'-------------------------------------------------------------------------------------------------------------------------'
     print,' returns new structure SMDAT with color corrected (cc) flux (MJy/sr) in instrument filter.'
     print,' or fills band flux in input structure SMI containing M_EMIS field'
     print,' Band flux integration always done in lambda, Deviations less than 1% for transmissions given vs. frequency.'
     print,''
     print,' SMDAT = { M_EMIS:  UNIT: for SED (erg/s/cm2/sr)' 
     print,'                    X:  xgrid for SED (microns) '
     print,'                    Y:  input SED '
     print,'                    YP: input polarized SED  '
     print,'           COM:  string for doc'
     print,'           NPAR: nr of parameters for overall CHI2'
     print,'           CHI2: chi-square on all data'
     print,'           INST: NAME: names of bands, '
     print,'                 X:    band center in microns, '                  
     print,'                 YD:   data points (erg/s/cm2/sr)'
     print,'                 ERR:  error on YD same unit'
     print,'                 YM:   SED of model in bands (erg/s/cm2/sr), '
     print,'                 FLX:  flux of model in bands (MJy/sr), '
     print,'                 CC:   color correction in bands, '
     print,'                 RR:   band sampling ratio flux/filt, '                   
     print,'                 ISEL: mask for band selection, 0:discard band, 1=take band, '
     print,'                 UNIT: info on units for X,YD,YM,FLX'
     print,'                 CHI2: chi-square on current bands masked with ISEL, '
     print,'                 TRANS: X: grid for band transmission, '
     print,'                        Y: band transmission } '
     print,''
     print,' DPATH  (I): path for FILTERS directory'
     print,' INST   (I): array of labels for band set, so far CAM, DIRBE, HFI, IRAC, IRAS, LFI, MIPS, PACS, SPIRE, WMAP'
     print,' XS     (I): SMDAT creation, input wave array in microns '
     print,' YS     (I): SMDAT creation, input SED in erg/s/cm2/sr, array(nwave,ntype) allows for several SEDs (grain type)'
     print,' SMI    (I): input SMDAT structure, must at least contain M_EMIS field. If set GET_BAND_FLUX will return filled SMI'
     print,''
     print,' Dependencies: '
     print,'  DUSTEM_BAND_CC, DUSTEM_ADD_MOD, HFI_READ_BANDPASS, GET_HFIBOLO_LIST, HFI_COLOR_CORRECTION '
     print,''
     print,' Examples: '
     print,' SMDAT creation: sm = GET_BAND_FLUX(dpath, [''iras'',''hfi''], xs=xs, ys=ys)'
     print,' SMDAT filling:  sm = GET_BAND_FLUX(dpath, [''spire''],smi=smi)               -> uses xs and ys from SMI (M_EMIS.X and Y)'
     print,' SMDAT filling:  sm = GET_BAND_FLUX(dpath, [''spire''],xs=xs,ys=ys,smi=smi)   -> force xs and ys in SMI'
     print,''
     print,' created by L Verstraete, IAS, Oct-dec 2010, Bandpass data from FILTERS'
     print,''
     print,'-------------------------------------------------------------------------------------------------------------------------'
     return,0
  endif

; init & check
  clight = 2.9979246D10  ; cm/s
  inst = STRUPCASE(STRTRIM(inst,2))
  n_inst = n_elements(inst)
  i_list = [ 'CAM', 'DIRBE', 'HFI', 'IRAC', 'IRAS', 'LFI', 'MIPS', 'PACS', 'SPIRE', 'WMAP' ]
  cx = 0
  for ik = 0, n_inst-1 do begin
     iix = WHERE( i_list EQ inst(ik), cxx )
     cx = cx + cxx
  endfor
  if cx EQ 0 then begin
     print,'(F) DUSTEM_GET_BAND_FLUX: no valid instrument name'
     return,-1
  endif
; find whether this is a creation
  ntg = N_TAGS(smi) 
  if N_TAGS(smi) EQ 0 then begin
     new_str = 1
  endif else begin
     tgs = TAG_NAMES(smi)
     ix = WHERE( tgs EQ 'M_EMIS', cx)
     if cx EQ 0 then new_str = 1 else new_str = 0
  endelse
; get start structure
  if new_str EQ 1 then begin        ; SMDAT creation
     tt = SIZE(ys) 
     if tt(0) GT 1 then ntype = tt(tt(0)) else ntype = 1
     if (n_elements(xs)+n_elements(ys)) EQ 0 OR (n_elements(xs) NE tt(1))  then begin
        print,'(F) DUSTEM_GET_BAND_FLUX: creating SMDAT must define xs(n1), ys(n1,n2)'
        return,0
     endif
     ix = SORT(xs)
     xw = xs(ix) & yw = ys(ix,0:ntype-1)
     smdat = { COM : '', NPAR : 0, CHI2 : 0d }
     smdat = DUSTEM_ADD_MOD(smdat,'emis',[n_elements(xw),ntype])
  endif else if new_str EQ 0 then begin  ; SMDAT filling 
     smdat = smi
     xw = smdat.m_emis.x
     yw = smdat.m_emis.y 
     if n_elements(xs) EQ n_elements(xw) then good = 1 
     if n_elements(ys) EQ n_elements(yw) then good = good + 1 
     if good EQ 2 then begin 
        ix = SORT(xs)
        tt = SIZE(ys)
        if tt(0) GT 1 then ntype = tt(tt(0)) else ntype = 1
        xw = xs(ix) & yw = ys(ix,0:ntype-1)
        if keyword_set(verbose) then print,'(W) DUSTEM_GET_BAND_FLUX: forcing xs, ys in SMI'
     endif 
     if n_elements(unit) EQ 0 then unit = smi.m_emis.unit
  endif
  if n_elements(unit) EQ 0 then unit = 'x(microns) SED(erg/s/cm2/sr)' 
  smdat.m_emis.unit = unit
  smdat.m_emis.x = xw
  smdat.m_emis.y = yw
  tag = TAG_NAMES(smdat)


; instrument loop
  for ixs = 0, n_inst-1 do begin
     if (INST(ixs) EQ 'CAM') then begin
        Nband_sw = 11
        Nband_lw = 10
        nband = nband_sw + nband_lw  ; nr of bands
        ntrans = 160                 ; max nr of points in transmission grid
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
        endif 
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        RESTORE, dpath+'ISO/cam_filter_transmission.save'
        smdat.(itx).x = [ sw_lambda_lc(0:nband_sw-1), lw_lambda_lc(0:nband_lw-1) ]
        smdat.(itx).name = [ strupcase(sw_name_arr(0:nband_sw-1)), strupcase(lw_name_arr(0:nband_lw-1)) ]
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
        FOR i=0,Nband_sw-1 DO BEGIN
           ind = where(sw_lambda_arr(*,i) NE 0.)
           xt = sw_lambda_arr(ind,i)
           yt = sw_trans_arr(ind,i)
           nu0 = 1d4*clight/sw_lambda_lc[i]
           for itp = 0, ntype-1 do begin
              smdat.(itx).ym(i,itp) = DUSTEM_BAND_CC( sw_lambda_lc[i], xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(i,itp) =  1.d17*tc*y0/nu0 ; in MJy/sr
              smdat.(itx).cc(i,itp) = tc
           endfor
           smdat.(itx).rr(i) = rb
           smdat.(itx).trans.x(i,0:nt-1) = xt
           smdat.(itx).trans.y(i,0:nt-1) = yt
        ENDFOR
        FOR i=0,Nband_lw-1 DO BEGIN
           ind=where(lw_lambda_arr(*,i) NE 0.)
           xt = lw_lambda_arr(ind,i)
           yt = lw_trans_arr(ind,i)/max(lw_trans_arr(ind,i))
           nu0 = 1d4*clight/lw_lambda_lc[i]
           for itp = 0, ntype-1 do begin
              smdat.(itx).ym(nband_sw+i,itp) = DUSTEM_BAND_CC( lw_lambda_lc[i], xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(nband_sw+i,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
              smdat.(itx).cc(nband_sw+i,itp) = tc
           endfor
           smdat.(itx).rr(nband_sw+i) = rb
           smdat.(itx).trans.x(nband_sw+i,0:nt-1) = xt
           smdat.(itx).trans.y(nband_sw+i,0:nt-1) = yt
        ENDFOR ; CAM 
     ENDIF else if (INST(ixs) EQ 'DIRBE') then begin 
        nband = 10              ; nr of bands
        ntrans = 160            ; max nr of points in transmission grid
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband, n2=ntype, n3=ntrans) )
           smdat = CREATE_STRUCT( smdat, st )
        endif
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        dir_band = dpath + 'DIRBE/'
        fname = dir_band + 'dirbe_response.asc'
        nwav = 800
        wav = dblarr(nwav)
        trans = dblarr(nwav,nband)
        OPENR, uu, fname, /get_lun
        tmp=''
        for i=0,11 do READF, uu, tmp
        for i=0,nwav-1 do begin 
           READF, uu, tmp
           tt = double( strsplit(tmp, ' ', /extract) ) ; first wave then 10 filters
           wav(i) = tt(0)
           trans(i,*) = tt(1:nband) 
        endfor
        CLOSE, uu
        free_lun, uu
        wbd = [1.25,2.2,3.5,4.9,12,25.,60.,100.,140.,240.]
        smdat.(itx).x = wbd
        smdat.(itx).name = 'DIRBE'+strtrim(indgen(10)+1,2)
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
        for k=0,nband-1 do begin 
           nu0 = 1d4*clight/wbd[k]
           xt=wav & yt=trans(*,k)
           for itp = 0, ntype-1 do begin
              smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( wbd[k], xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
              smdat.(itx).cc(k,itp) = tc
           endfor 
           smdat.(itx).rr(k) = rb
           smdat.(itx).trans.x(k,0:nt-1) = xt
           smdat.(itx).trans.y(k,0:nt-1) = yt
        endfor ; DIRBE
     ENDIF else if (INST(ixs) EQ 'HFI') then begin
        nband=6
        hfi_bp_version = 'v101'
        ntrans = 800
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
        endif
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        dir_band = dpath + 'HFI/OFFICIAL/'
        wbd = double([100.,143.,217.,353.,545.,857.]) ; band center in GHz
        bnm = STRTRIM(FIX(wbd),2)
        smdat.(itx).name = bnm
        smdat.(itx).x = 1d-5*clight/wbd
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)'
        bp = HFI_READ_BANDPASS(hfi_bp_version,path_rimo=dir_band,/rimo)
        NAME   = bp.name        ; name of the detector
        FREQ   = bp.freq/1d9    ; frequencies measured in GHz
        TRANS  = bp.trans       ; values of the transmission (normalized later)
        nu = 1d-5*clight/xw     ; microns to GHz
        ixw = SORT(nu) & nu = nu(ixw)
        FOR k=0,nband-1 do begin         
           BOLO_LIST = GET_HFIBOLO_LIST( channel = bnm(k) )
           N_BOLO_LIST = n_elements( bolo_list )  
           yt = 0d0
           For idet = 0 , n_bolo_list - 1 do begin ; ----- get transmission ------------
              Q_DET = where(bolo_list[ idet ] eq name)
              Q_DET = q_det(0)
              Q_TRANS = where( trans(*,q_det) gt 1d-6, nt )
              FREQ_D = freq( q_trans, q_det ) ; already in GHz
              TRANS_D = trans( q_trans, q_det )
              if idet EQ 0 then begin
                 freq_0 = freq_d
                 n0 = n_elements(freq_0)
                 yt = yt + trans_d
              endif else yt = yt + INTERPOL( trans_d, freq_d, freq_0)
           endfor
           smdat.(itx).trans.x(k,0:n0-1) = 1d-5*clight/freq_0
           smdat.(itx).trans.y(k,0:n0-1) = yt / MAX(yt)
           for itp=0,ntype-1 do begin
              inu = 1d17 * yw(ixw,itp)/nu/1d9 ; MJy/sr 
              y0 = INTERPOL(yw(ixw,itp),nu,wbd(k))
2ffa8f64   Annie Hughes   changed to dustem...
241
242
;              cc = HFI_COLOR_CORRECTION( bp,bnm(k),bolo_cc, nu,inu )
              cc = HFI_COLOR_CORRECTION_DUSTEM( bp.name,bp.freq/1e9,bp.trans,bnm(k),bolo_cc, nu,inu )
aed288de   Annie Hughes   first commit of I...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
              smdat.(itx).ym(k,itp)  = cc.cc * y0                  ; SED (erg/cm2/s/sr) @ band center
              smdat.(itx).flx(k,itp) = 1d17*cc.cc*y0/wbd(k)/1d9    ; in MJy/sr
              smdat.(itx).cc(k,itp)  = cc.cc
           endfor 
        ENDFOR       
     ENDIF ELSE if (INST(ixs) EQ 'IRAC') then begin
        nband = 4
        ntrans = 410
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
        endif
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        wbd = [ 3.550, 4.493, 5.731, 7.872 ] ; in microns 
        smdat.(itx).x = wbd
        bnm = ['IRAC1','IRAC2','IRAC3','IRAC4']
        smdat.(itx).name = bnm
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
        dir_band = dpath + 'Spitzer/'
        for k = 0, nband-1 do begin 
           fn = dir_band + STRLOWCASE(bnm(k)) + '.dat'
           READCOL, fn, xt, yt, /sil ; !!! response in electrons per photon !!!
           yt = yt*xt
           nu0 = 1d4*clight/wbd[k]
           for itp=0,ntype-1 do begin
              smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( wbd[k], xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
              smdat.(itx).cc(k,itp) = tc
           endfor 
           smdat.(itx).trans.x(k,0:nt-1) = xt
           smdat.(itx).trans.y(k,0:nt-1) = yt
           smdat.(itx).rr(k) = rb
        endfor ; IRAC
     ENDIF ELSE if (INST(ixs) EQ 'IRAS') then begin
        nband = 4
        ntrans = 140
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
           ttg = TAG_NAMES(smdat)
           itx = WHERE( ttg EQ 'I_'+inst(ixs))
           bnm = ['12','25','60','100']
           smdat.(itx).name = bnm
           wbd = DOUBLE(bnm)
           smdat.(itx).x = wbd
           smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
           dir_band = dpath + 'IRAS/IRAS'
           for k=0,nband-1 do begin 
              fn = dir_band + bnm(k)+'.txt'
              READCOL, fn, xt, yt,/SIL
              nu0 = 1d4*clight/wbd[k]
              for itp=0,ntype-1 do begin
                 smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( wbd[k], xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
                 smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
                 smdat.(itx).cc(k,itp) = tc
              endfor
              smdat.(itx).trans.x(k,0:nt-1) = xt
              smdat.(itx).trans.y(k,0:nt-1) = yt
              smdat.(itx).rr(k) = rb
           endfor
        endif else begin ; IRAS no read
           ttg = TAG_NAMES(smdat)
           itx = WHERE( ttg EQ 'I_'+inst(ixs))
           wbd = smdat.(itx).x
           for k=0,nband-1 do begin 
              nu0 = 1d4*clight/wbd[k]
              xt = smdat.(itx).trans.x(k,*)
              yt = smdat.(itx).trans.y(k,*)
              for itp=0,ntype-1 do begin
                 smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( wbd[k], xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
                 smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
                 smdat.(itx).cc(k,itp) = tc
                 smdat.(itx).rr(k) = rb
              endfor
           endfor    ; IRAS
        endelse
     ENDIF else if (INST(ixs) EQ 'LFI') then begin 
        wbd = [ 30.,44.,70. ]   ;band center in GHz
        nband = n_elements(wbd)
        ntrans = 210
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
        endif
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        smdat.(itx).x = 1d-5*clight/wbd 
        bnm = STRTRIM(FIX(wbd),2) + 'GHz'
        smdat.(itx).name = bnm
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
        dir_band = dpath + 'LFI/LFI'
        FOR k=0L,Nband-1 DO BEGIN
           lfi_files = FINDFILE(dir_band+'*'+bnm(k)+'*.dat',count=Nfiles)
           FOR i=0L,Nfiles-1 DO BEGIN
              IF i EQ 0 THEN BEGIN
                 READCOL,lfi_files(i),nu,R0D0,R0D1,R1D0,R1D1, /SIL
              ENDIF ELSE BEGIN
                 READCOL,lfi_files(i),nu2,R0D0_2,R0D1_2,R1D0_2,R1D1_2, /SIL
                 R0D0 = R0D0 + INTERPOL(R0D0_2,nu2,nu)
                 R1D0 = R1D0 + INTERPOL(R1D0_2,nu2,nu)
                 R0D1 = R0D1 + INTERPOL(R0D1_2,nu2,nu)
                 R1D1 = R1D1 + INTERPOL(R1D1_2,nu2,nu)
              ENDELSE
           ENDFOR
           trans=sqrt(R0D0^2+R1D1^2+R1D0^2+R0D1^2) ; no idea if this is how it should be done
           xt = 1d-5*clight/nu
           yt = trans
           w0 = 1d-5*clight/wbd[k]
           nu0 = 1d9*wbd[k]
           for itp=0,ntype-1 do begin
              smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( w0, xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
              smdat.(itx).cc(k,itp) = tc
           endfor
           smdat.(itx).trans.x(k,0:nt-1) = xt
           smdat.(itx).trans.y(k,0:nt-1) = yt
           smdat.(itx).rr(k) = rb
        ENDFOR ; LFI
     ENDIF else if (INST(ixs) EQ 'MIPS') then begin
        bnm = [ '24', '70', '160' ] ; band name
        wbd = [ 23.68, 71.42, 155.90 ] ; band center in microns
        nband = n_elements(wbd)
        ntrans = 400
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
        endif
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        smdat.(itx).x = wbd
        smdat.(itx).name = bnm
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
        dir_band = dpath + 'Spitzer/MIPSfiltsumm_'
        for k = 0, nband-1 do begin 
           fn = dir_band + bnm(k) + '.txt'
           READCOL, fn, xt, yt, /sil ; ; !!! response in electrons per photon energy !!!
           nu0 = 1d4*clight/wbd[k]
           for itp=0,ntype-1 do begin
              smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( wbd[k], xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
              smdat.(itx).cc(k,itp) = tc
           endfor
           smdat.(itx).trans.x(k,0:nt-1) = xt
           smdat.(itx).trans.y(k,0:nt-1) = yt
           smdat.(itx).rr(k) = rb
        endfor ; MIPS
     ENDIF else if (INST(ixs) EQ 'PACS') then begin 
;        wbd=[75.,110.,170.]     ;microns
        wbd=[70.,100.,160.]     ;microns
        nband = n_elements(wbd)
        ntrans = 2030
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
        endif
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        smdat.(itx).x = wbd
        bnm = STRTRIM(FIX(wbd),2)
        smdat.(itx).name = bnm
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
        dir_band = dpath + 'PACS/'
        file = dir_band+'PCalPhotometer_Absorption_FM_v2.fits'
        wave=mrdfits(file,1,h,/sil)
        Trans=mrdfits(file,2,h,/sil)
        file=dir_band+'PCalPhotometer_FilterTransmission_FM_v1.fits'
        st3=mrdfits(file,1,h,/sil) & lamb3=st3.wavelength & T3=st3.transmission
        st1=mrdfits(file,2,h,/sil) & lamb1=st1.wavelength & T1=st1.transmission
        st2=mrdfits(file,3,h,/sil) & lamb2=st2.wavelength & T2=st2.transmission
        mx = MAX([n_elements(lamb1),n_elements(lamb2),n_elements(lamb3)])
        yt  = dblarr(nband,mx)
        xt  = dblarr(nband,mx)
        TT1=interpol(Trans,wave,lamb1)
        TT2=interpol(Trans,wave,lamb2)
        TT3=interpol(Trans,wave,lamb3)
        yt(0,0:n_elements(lamb1)-1)=T1*TT1 & xt(0,0:n_elements(lamb1)-1) = lamb1
        yt(1,0:n_elements(lamb2)-1)=T2*TT2 & xt(1,0:n_elements(lamb2)-1) = lamb2 
        yt(2,0:n_elements(lamb3)-1)=T3*TT3 & xt(2,0:n_elements(lamb3)-1) = lamb3
        FOR k=0, nband-1 do begin 
           xtt = REFORM(xt(k,*),mx) & ytt = REFORM(yt(k,*),mx)
           nu0 = 1d4*clight/wbd[k]
           for itp=0,ntype-1 do begin
              smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( wbd[k], xw, yw(*,itp), xtt, ytt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
              smdat.(itx).cc(k,itp) = tc
           endfor
           smdat.(itx).trans.x(k,0:nt-1) = xtt
           smdat.(itx).trans.y(k,0:nt-1) = ytt
           smdat.(itx).rr(k) = rb
        endfor ; PACS
     ENDIF else if (INST(ixs) EQ 'SPIRE') then begin 
        wbd= [250., 350., 500.]
        nband = n_elements(wbd)
        ntrans = 510
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
        endif
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        smdat.(itx).x = wbd
        bnm = STRTRIM(FIX(wbd),2)
        smdat.(itx).name = bnm
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
        tt  = dblarr(nband+1,512)   
        dir_band = dpath + 'SPIRE/'
        OPENR,unit,dir_band+'SPIRE_transmissions.txt',/get_lun
        sstr=''
        for i=0,2 do READF,unit,sstr
        cnt = 0 & ss=''
        WHILE not eof(unit) DO BEGIN
           READF,unit,ss
           tt(*,cnt) = double(strsplit(ss,/extract))
           cnt = cnt + 1
        ENDWHILE
        CLOSE, unit
        free_lun, unit
        FOR k=0, nband-1 do begin
           xt = 1d4/tt(0,*)     ; convert to microns
           yt = tt[k+1,*]
           w0 = wbd[k]
           nu0 = 1d4*clight/w0
           for itp=0,ntype-1 do begin
              smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( w0, xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr
              smdat.(itx).cc(k,itp) = tc
           endfor
           smdat.(itx).trans.x(k,0:nt-1) = xt
           smdat.(itx).trans.y(k,0:nt-1) = yt
           smdat.(itx).rr(k) = rb
        endfor ; SPIRE
     ENDIF else if (INST(ixs) EQ 'WMAP') then begin 
        wbd = double([ 23., 33., 41., 61., 94. ])
        nband = n_elements(wbd)
        ntrans = 1000
        ix = WHERE(tag EQ 'I_'+inst(ixs), ctg)
        if new_str EQ 1 OR ctg EQ 0 then begin
           st = CREATE_STRUCT( 'I_'+inst(ixs), DUSTEM_STR_INST(nband,n2=ntype,n3=ntrans) ) 
           smdat = CREATE_STRUCT( smdat, st )
        endif
        ttg = TAG_NAMES(smdat)
        itx = WHERE( ttg EQ 'I_'+inst(ixs))
        smdat.(itx).x = 1d-5*clight/wbd
        bnm = STRTRIM(FIX(wbd),2)+'GHz'
        smdat.(itx).name = bnm
        smdat.(itx).unit = 'x(microns) YM(erg/s/cm2/sr) FLX(MJy/sr)' 
        dir_band = dpath + 'WMAP/'
        wmap_files = FINDFILE(dir_band+'*v3.xcat', count=nfiles)
        FOR k=0, nband-1 do begin 
           READCOL, wmap_files(k), nu, trans, skip=4, /sil
           xt = 1d-5*clight/nu  ; !!!! integrate in microns
           yt = trans
           w0 = 1d-5*clight/wbd[k]
           nu0 = 1d9*wbd[k]
           for itp=0,ntype-1 do begin
              smdat.(itx).ym(k,itp) = DUSTEM_BAND_CC( w0, xw, yw(*,itp), xt, yt, y0=y0, cc=tc, rr=rb, ni=nt )
              smdat.(itx).flx(k,itp) = 1.d17*tc*y0/nu0 ; in MJy/sr 
              smdat.(itx).cc(k,itp) = tc
           endfor 
           smdat.(itx).trans.x(k,0:nt-1) = xt
           smdat.(itx).trans.y(k,0:nt-1) = yt
           smdat.(itx).rr(k) = rb
        endfor ; WMAP
     ENDIF

  ENDFOR

  RETURN, SMDAT
END