Blame view

src/idl/dustem_read_fits_table.pro 13.7 KB
52a3c8dc   Jean-Philippe Bernard   mise a jour
1
PRO dustem_read_fits_table,filename=filename,dustem_st=dustem_st,help=help,Q_spec=Q_spec,U_spec=U_spec
a1839067   Jean-Philippe Bernard   First commit
2
3
4
5

;+
; NAME:
;    dustem_read_fits_table
66c3a3ea   Annie Hughes   cosmetic changes ...
6
;
a1839067   Jean-Philippe Bernard   First commit
7
; PURPOSE:
201cf7e2   Annie Hughes   minor changes to ...
8
;    Reads a Dustem fits table into current DustEMWrap system variables
66c3a3ea   Annie Hughes   cosmetic changes ...
9
;
a1839067   Jean-Philippe Bernard   First commit
10
; CATEGORY:
90c53809   Annie Hughes   updated doc heade...
11
;    DustEMWrap, High-Level, Distributed, User convenience
66c3a3ea   Annie Hughes   cosmetic changes ...
12
;
a1839067   Jean-Philippe Bernard   First commit
13
14
; CALLING SEQUENCE:
;    dustem_read_fits_table[,filename=][,/help]
66c3a3ea   Annie Hughes   cosmetic changes ...
15
;
a1839067   Jean-Philippe Bernard   First commit
16
; INPUTS:
66c3a3ea   Annie Hughes   cosmetic changes ...
17
;
a1839067   Jean-Philippe Bernard   First commit
18
; OPTIONAL INPUT PARAMETERS:
201cf7e2   Annie Hughes   minor changes to ...
19
;    filename      = File name to be read (default='./dustemwrap_results.fits')
66c3a3ea   Annie Hughes   cosmetic changes ...
20
;
a1839067   Jean-Philippe Bernard   First commit
21
22
; OUTPUTS:
;    None
66c3a3ea   Annie Hughes   cosmetic changes ...
23
;
a1839067   Jean-Philippe Bernard   First commit
24
; OPTIONAL OUTPUT PARAMETERS:
762cbe48   Jean-Philippe Bernard   modifed to cope f...
25
;    dustem_st = emission and extinction dustem output structure (total and for each grain type)
66c3a3ea   Annie Hughes   cosmetic changes ...
26
;
a1839067   Jean-Philippe Bernard   First commit
27
28
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
66c3a3ea   Annie Hughes   cosmetic changes ...
29
;
a1839067   Jean-Philippe Bernard   First commit
30
31
; COMMON BLOCKS:
;    None
66c3a3ea   Annie Hughes   cosmetic changes ...
32
;
a1839067   Jean-Philippe Bernard   First commit
33
; SIDE EFFECTS:
201cf7e2   Annie Hughes   minor changes to ...
34
;    DustEMWrap system variables are set
66c3a3ea   Annie Hughes   cosmetic changes ...
35
;
a1839067   Jean-Philippe Bernard   First commit
36
; RESTRICTIONS:
201cf7e2   Annie Hughes   minor changes to ...
37
;    The DustEMWrap IDL code must be installed
66c3a3ea   Annie Hughes   cosmetic changes ...
38
;
a1839067   Jean-Philippe Bernard   First commit
39
40
; PROCEDURE:
;    None
66c3a3ea   Annie Hughes   cosmetic changes ...
41
;
a1839067   Jean-Philippe Bernard   First commit
42
43
44
; EXAMPLES
;    
; MODIFICATION HISTORY:
1cf2bf59   Annie Hughes   updated dustem_da...
45
46
47
;    Written by J.-Ph. Bernard July 2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
a1839067   Jean-Philippe Bernard   First commit
48
49
;-

a1839067   Jean-Philippe Bernard   First commit
50
51
52
53
54
55
56
57
58
59

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_read_fits_table'
  goto,the_end
ENDIF

;write final file
IF keyword_set(filename) THEN BEGIN
	file=filename
ENDIF ELSE BEGIN
1cf2bf59   Annie Hughes   updated dustem_da...
60
	file='./dustemwrap_results.fits'
a1839067   Jean-Philippe Bernard   First commit
61
62
63
ENDELSE
message,'Reading '+file,/info

762cbe48   Jean-Philippe Bernard   modifed to cope f...
64
toto=mrdfits(file,0,main_header)
a1839067   Jean-Philippe Bernard   First commit
65

762cbe48   Jean-Philippe Bernard   modifed to cope f...
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
;get extention numbers from main header
current_ext=1
ext_names=['']
exts=[-1]
finished=0
WHILE not finished DO BEGIN
	ext_name=sxpar(main_header,'EXT'+strtrim(current_ext,2),count=count)
	IF count NE 0 THEN BEGIN
		ext_names=[ext_names,ext_name]
		exts=[exts,current_ext]
		current_ext=current_ext+1
	ENDIF ELSE BEGIN
		finished=1
	ENDELSE
ENDWHILE
ext_names=ext_names[1:*]
exts=exts[1:*]
Nextensions=n_elements(exts)

message,'================================================',/info
message,'Reading '+file,/info
message,'File extensions detected are: ',/info
FOR i=0L,Nextensions-1 DO BEGIN
	message,'extension '+strtrim(exts[i],2)+' : '+strtrim(ext_names[i],2),/info
ENDFOR
message,'================================================',/info

17f02a5a   Jean-Philippe Bernard   updated
93
94
;extensions_strs=['INPUT_EMISSION_SED','DUSTEM_PREDICTED_SED','DUSTEM_SHOWN_SED', $
;				 'INPUT_EXTINCTION_SED','DUSTEM_PREDICTED_EXTINCTION_SED','DUSTEM_SHOWN_EXTINCTION_SED', $
762cbe48   Jean-Philippe Bernard   modifed to cope f...
95
96
;				 'DUSTEM_PREDICTED_EMISSION_SPECTRA','DUSTEM_PREDICTED_EXTINCTION_SPECTRA', $
;				 'DUSTEM_PREDICTED_EMISSION_SPECTRA_POL','DUSTEM_PREDICTED_EXTINCTION_SPECTRA_POL']
8f83f26b   Jean-Philippe Bernard   added saving plug...
97
98
99
100
ind_plugin=where(strmid(ext_names,0,strlen('PLUGIN_')) EQ 'PLUGIN_',Nplugin)
IF Nplugin NE 0 THEN BEGIN
	ext_names_plugins=strarr(Nplugin)
	;names_plugins=strarr(Nplugin)
52f17b34   Annie Hughes   fixes for reading...
101
        FOR i=0L,Nplugin-1 DO BEGIN
8f83f26b   Jean-Philippe Bernard   added saving plug...
102
103
104
105
		ext_names_plugins[i]=ext_names[ind_plugin[i]]
		;names_plugins[i]=strmid(ext_names[ind_plugin[i]],strlen('PLUGIN_'),100)
	ENDFOR
ENDIF
762cbe48   Jean-Philippe Bernard   modifed to cope f...
106
107
108
109

ind=where(ext_names EQ 'INPUT_EMISSION_SED',count)
IF count NE 0 THEN BEGIN
	unit_input_emission_sed=exts[ind[0]]
0dda35a7   Jean-Philippe Bernard   modified to inclu...
110
	;print,unit_input_emission_sed
762cbe48   Jean-Philippe Bernard   modifed to cope f...
111
112
113
114
115
116
ENDIF ELSE BEGIN
    unit_input_emission_sed=-1
ENDELSE
ind=where(ext_names EQ 'DUSTEM_PREDICTED_SED',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_sed=exts[ind[0]]
0dda35a7   Jean-Philippe Bernard   modified to inclu...
117
	;print,unit_dustem_predicted_sed
762cbe48   Jean-Philippe Bernard   modifed to cope f...
118
119
120
ENDIF ELSE BEGIN
    unit_dustem_predicted_sed=-1
ENDELSE
17f02a5a   Jean-Philippe Bernard   updated
121
122
123
124
125
126
127
ind=where(ext_names EQ 'DUSTEM_SHOWN_SED',count)
IF count NE 0 THEN BEGIN
	unit_dustem_shown_sed=exts[ind[0]]
	;print,unit_dustem_predicted_sed
ENDIF ELSE BEGIN
    unit_dustem_shown_sed=-1
ENDELSE
762cbe48   Jean-Philippe Bernard   modifed to cope f...
128
129
130
131

ind=where(ext_names EQ 'INPUT_EXTINCTION_SED',count)
IF count NE 0 THEN BEGIN
	unit_input_extinction_sed=exts[ind[0]]
0dda35a7   Jean-Philippe Bernard   modified to inclu...
132
	;print,unit_input_extinction_sed
762cbe48   Jean-Philippe Bernard   modifed to cope f...
133
134
135
136
137
138
ENDIF ELSE BEGIN
    unit_input_extinction_sed=-1
ENDELSE
ind=where(ext_names EQ 'DUSTEM_PREDICTED_EXTINCTION_SED',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_extinction_sed=exts[ind[0]]
0dda35a7   Jean-Philippe Bernard   modified to inclu...
139
	;print,unit_dustem_predicted_extinction_sed
762cbe48   Jean-Philippe Bernard   modifed to cope f...
140
141
142
ENDIF ELSE BEGIN
	unit_dustem_predicted_extinction_sed=-1   ;That would be abnormal
ENDELSE
17f02a5a   Jean-Philippe Bernard   updated
143
144
145
146
147
148
149
ind=where(ext_names EQ 'DUSTEM_SHOWN_EXTINCTION_SED',count)
IF count NE 0 THEN BEGIN
	unit_dustem_shown_extinction_sed=exts[ind[0]]
	;print,unit_dustem_predicted_extinction_sed
ENDIF ELSE BEGIN
	unit_dustem_shown_extinction_sed=-1   ;That would be abnormal
ENDELSE
762cbe48   Jean-Philippe Bernard   modifed to cope f...
150
151
152
153

ind=where(ext_names EQ 'DUSTEM_PREDICTED_EMISSION_SPECTRA',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_emission_spectra=exts[ind[0]]
0dda35a7   Jean-Philippe Bernard   modified to inclu...
154
	;print,unit_dustem_predicted_emission_spectra
762cbe48   Jean-Philippe Bernard   modifed to cope f...
155
156
157
158
159
160
ENDIF ELSE BEGIN
	unit_dustem_predicted_emission_spectra=-1   ;That would be abnormal
ENDELSE
ind=where(ext_names EQ 'DUSTEM_PREDICTED_EXTINCTION_SPECTRA',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_extinction_spectra=exts[ind[0]]
0dda35a7   Jean-Philippe Bernard   modified to inclu...
161
	;print,unit_dustem_predicted_extinction_spectra
762cbe48   Jean-Philippe Bernard   modifed to cope f...
162
163
164
165
166
167
168
ENDIF ELSE BEGIN
	unit_dustem_predicted_extinction_spectra=-1   ;That would be abnormal
ENDELSE

ind=where(ext_names EQ 'DUSTEM_PREDICTED_EMISSION_SPECTRA_POL',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_emission_spectra_pol=exts[ind[0]]
0dda35a7   Jean-Philippe Bernard   modified to inclu...
169
	;print,unit_dustem_predicted_emission_spectra_pol
762cbe48   Jean-Philippe Bernard   modifed to cope f...
170
171
172
173
174
175
ENDIF ELSE BEGIN
	unit_dustem_predicted_emission_spectra_pol=-1
ENDELSE
ind=where(ext_names EQ 'DUSTEM_PREDICTED_EXTINCTION_SPECTRA_POL',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_extinction_spectra_pol=exts[ind[0]]
0dda35a7   Jean-Philippe Bernard   modified to inclu...
176
	;print,unit_dustem_predicted_extinction_spectra_pol
762cbe48   Jean-Philippe Bernard   modifed to cope f...
177
178
179
ENDIF ELSE BEGIN
	unit_dustem_predicted_extinction_spectra_pol=-1
ENDELSE
8f83f26b   Jean-Philippe Bernard   added saving plug...
180
181
182
183
184
185
186
187
188
189
190
191
;=== find out logical units for plugins
IF Nplugin NE 0 THEN BEGIN
	unit_plugins=lonarr(Nplugin)
	FOR i=0L,Nplugin-1 DO BEGIN
		ind=where(ext_names EQ ext_names_plugins[i],count)
		IF count NE 0 THEN BEGIN
			unit_plugins[i]=exts[ind[0]]
		ENDIF ELSE BEGIN
			unit_plugins[i]=-1
		ENDELSE
	ENDFOR
ENDIF
762cbe48   Jean-Philippe Bernard   modifed to cope f...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

;stop

; unit_input_sed=sxpar(main_header,'INPUT_EMISSION_SED')
; unit_predicted_sed=sxpar(main_header,'DUSTEM_PREDICTED_SED')
; unit_predicted_spectra=sxpar(main_header,'DUSTEM_PREDICTED_EMISSION')
; unit_predicted_extinctions=sxpar(main_header,'DUSTEM_PREDICTED_EXTINCTION')
; unit_predicted_spectra_pol=sxpar(main_header,'DUSTEM_PREDICTED_EMISSION_POL')
; unit_predicted_extinctions_pol=sxpar(main_header,'DUSTEM_PREDICTED_EXTINCTION_POL')

;==== read the observed SED (if any)
IF unit_input_emission_sed NE -1 THEN BEGIN
	str_input_SED=mrdfits(file,unit_input_emission_sed,header_input_sed)
ENDIF ELSE BEGIN
ENDELSE
;==== read the predicted SED (if any)
IF unit_dustem_predicted_sed NE -1 THEN BEGIN
	str_predicted_SED=mrdfits(file,unit_dustem_predicted_sed,header_predicted_SED)
ENDIF ELSE BEGIN
ENDELSE
17f02a5a   Jean-Philippe Bernard   updated
212
213
214
215
216
217
;==== read the shown SED (if any)
;stop
IF unit_dustem_shown_sed NE -1 THEN BEGIN
	str_shown_SED=mrdfits(file,unit_dustem_shown_sed,header_shown_SED)
ENDIF ELSE BEGIN
ENDELSE
762cbe48   Jean-Philippe Bernard   modifed to cope f...
218
219
220
221
222
223
224
225
IF unit_input_extinction_sed NE -1 THEN BEGIN
	str_input_EXT=mrdfits(file,unit_input_extinction_sed,header_input_ext)
ENDIF ELSE BEGIN
ENDELSE
IF unit_dustem_predicted_extinction_sed NE -1 THEN BEGIN
	str_predicted_EXT=mrdfits(file,unit_input_extinction_sed,header_input_ext)
ENDIF ELSE BEGIN
ENDELSE
17f02a5a   Jean-Philippe Bernard   updated
226
IF unit_dustem_shown_extinction_sed NE -1 THEN BEGIN
3196a378   Ilyes Choubani   Complementing fit...
227
	str_shown_EXT=mrdfits(file,unit_dustem_shown_extinction_sed,header_shown_ext)
17f02a5a   Jean-Philippe Bernard   updated
228
229
ENDIF ELSE BEGIN
ENDELSE
8f83f26b   Jean-Philippe Bernard   added saving plug...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
;=== read plugin informations and plugins headers
IF Nplugin NE 0 THEN BEGIN
	str_plugin=ptrarr(Nplugin)
	headers_plugin=ptrarr(Nplugin)
	FOR i=0L,Nplugin-1 DO BEGIN
		IF unit_plugins[i] NE -1 THEN BEGIN
			a=mrdfits(file,unit_plugins[i],header)
			str_plugin[i]=ptr_new(a)
			headers_plugin[i]=ptr_new(header)
		ENDIF
	ENDFOR
ENDIF

;stop
a1839067   Jean-Philippe Bernard   First commit
244

762cbe48   Jean-Philippe Bernard   modifed to cope f...
245
246
247
used_model=strtrim(sxpar(main_header,'MODEL'),2)
used_pol=long(strtrim(sxpar(main_header,'POL'),2))
used_version=strtrim(sxpar(main_header,'WRAP_V'),2)
7bb82b3b   Ilyes Choubani   remove lingering ...
248

72089d7a   Jean-Philippe Bernard   improved to save ...
249
IF used_model NE 'DEFAULT' THEN BEGIN
7bb82b3b   Ilyes Choubani   remove lingering ...
250
 	dustem_init,model=used_model,pol=used_pol
72089d7a   Jean-Philippe Bernard   improved to save ...
251
ENDIF ELSE BEGIN
7bb82b3b   Ilyes Choubani   remove lingering ...
252
   	dustem_init,model=0
72089d7a   Jean-Philippe Bernard   improved to save ...
253
ENDELSE
7bb82b3b   Ilyes Choubani   remove lingering ...
254

52f17b34   Annie Hughes   fixes for reading...
255
256
257
258
259
260
261
262
263
264
IF unit_input_emission_sed NE -1 THEN defsysv,'!dustem_hcd',ptr_new(float(sxpar(header_input_sed,'NH_SED')))
IF unit_input_extinction_sed NE -1 THEN defsysv,'!dustem_hcd',ptr_new(float(sxpar(header_input_ext,'NH_EXT')))
IF unit_input_emission_sed NE -1 AND unit_input_extinction_sed NE -1 THEN BEGIN
   defsysv,'!dustem_hcd',ptr_new(float(sxpar(header_input_sed,'NH_SED')))
   if float(sxpar(header_input_sed,'NH_SED')) ne float(sxpar(header_input_ext,'NH_EXT')) then begin
      message,'Assumed column density for emission in input FITS is [H/cm2]: '+string(sxpar(header_input_sed,'NH_SED')),/info
      message,'Assumed column density for extinction in input FITS is [H/cm2]: '+string(sxpar(header_input_sed,'NH_EXT')),/info
      message,'Restoring using NH_SED value for !DUSTEM_HCD',/info
   end
ENDIF
b7dca888   Jean-Philippe Bernard   improved to recov...
265

52f17b34   Annie Hughes   fixes for reading...
266
   
72089d7a   Jean-Philippe Bernard   improved to save ...
267
!dustem_model=used_model
762cbe48   Jean-Philippe Bernard   modifed to cope f...
268
269
270
271
272
IF !dustem_version.version NE used_version THEN BEGIN
	message,'Caution: fits file was not created with the same Dustemwrap version as your current version',/continue
	message,'Fits dustemwrap version is    :'+used_version,/continue
	message,'current dustemwrap version is :'+!dustem_version.version,/continue
	stop
a1839067   Jean-Philippe Bernard   First commit
273
274
ENDIF

762cbe48   Jean-Philippe Bernard   modifed to cope f...
275
276
best_fit_chi2=sxpar(main_header,'CHI2')
best_fit_rchi2=sxpar(main_header,'RCHI2')
a1839067   Jean-Philippe Bernard   First commit
277

762cbe48   Jean-Philippe Bernard   modifed to cope f...
278
279
;==== get parameter values
Nparams=sxpar(main_header,'NPARAMS')
a1839067   Jean-Philippe Bernard   First commit
280
281
282
283
parameters_desc=strarr(Nparams)
best_parameters=dblarr(Nparams)
best_parameters_init_values=dblarr(Nparams)
best_parameters_uncertainties=dblarr(Nparams)
72089d7a   Jean-Philippe Bernard   improved to save ...
284
parameters_func_values=dblarr(Nparams)
a1839067   Jean-Philippe Bernard   First commit
285
FOR i=0L,Nparams-1 DO BEGIN
762cbe48   Jean-Philippe Bernard   modifed to cope f...
286
287
288
289
	parameters_desc[i]=sxpar(main_header,'PARN'+strtrim(i+1,2))
	best_parameters[i]=sxpar(main_header,'PARV'+strtrim(i+1,2))
	best_parameters_uncertainties[i]=sxpar(main_header,'PARU'+strtrim(i+1,2))
	best_parameters_init_values[i]=sxpar(main_header,'PARI'+strtrim(i+1,2))
7bb82b3b   Ilyes Choubani   remove lingering ...
290
	parameters_func_values[i]=sxpar(main_header,'PARF'+strtrim(i+1,2))
a1839067   Jean-Philippe Bernard   First commit
291
292
ENDFOR

72089d7a   Jean-Philippe Bernard   improved to save ...
293
294
295
296
297
298
299
(*!dustem_fit).PARAM_DESCS=ptr_new(parameters_desc)
(*!dustem_fit).PARAM_INIT_VALUES=ptr_new(best_parameters_init_values)
(*!dustem_fit).CURRENT_PARAM_VALUES=ptr_new(best_parameters)
(*!dustem_fit).CURRENT_PARAM_ERRORS=ptr_new(best_parameters_uncertainties)
(*!dustem_fit).CHI2=best_fit_chi2
(*!dustem_fit).RCHI2=best_fit_rchi2
(*!dustem_fit).PARAM_FUNC=ptr_new(parameters_func_values)
f53f5e45   Jean-Philippe Bernard   not sure what
300
301
302
303
304
305
306
307
308
309
310
311
312
;==== get fixed parameter values, if any
Nfixedparams=sxpar(main_header,'NFPARAMS')
IF Nfixedparams NE 0 THEN BEGIN
	fixed_parameters_desc=strarr(Nfixedparams)
	fixed_parameters_values=dblarr(Nfixedparams)
	FOR i=0L,Nfixedparams-1 DO BEGIN
		fixed_parameters_desc[i]=sxpar(main_header,'FPARN'+strtrim(i+1,2))
		fixed_parameters_values[i]=sxpar(main_header,'FPARV'+strtrim(i+1,2))
	ENDFOR
	(*!dustem_fit).fixed_param_descs=ptr_new(fixed_parameters_desc)
	(*!dustem_fit).fixed_param_init_values=ptr_new(fixed_parameters_values)
ENDIF
;stop
a1839067   Jean-Philippe Bernard   First commit
313

8f83f26b   Jean-Philippe Bernard   added saving plug...
314
315
;=== set !dustem_plugin according to fits file content
IF Nplugin NE 0 THEN BEGIN
52f17b34   Annie Hughes   fixes for reading...
316
  dustem_init_plugins,parameters_desc,fpd=fixed_parameters_desc
8f83f26b   Jean-Philippe Bernard   added saving plug...
317
  FOR i=0L,Nplugin-1 DO BEGIN
58781030   Jean-Philippe Bernard   fixed a bug with ...
318
319
  	;stop
  	;(*!dustem_plugin).(i).spec=ptr_new(str_plugin[i])
ab7bdcb3   Annie Hughes   Updated write and...
320
  	(*!dustem_plugin)[i].spec=str_plugin[i]
8f83f26b   Jean-Philippe Bernard   added saving plug...
321
322
323
324
325
326
327
328
329
330
331
  	header=*headers_plugin[i]
  	pluggin_name=strtrim(sxpar(header,'PLUGIN'),2)
  	pluggin_scope=strtrim(sxpar(header,'SCOPE'),2)
    paramtags=['']
    ii=1 & cc=1
  	WHILE cc NE 0 DO BEGIN
  		ss=strtrim(sxpar(header,'TAGN'+strtrim(ii,2),count=cc),2)
  		IF cc NE 0 THEN paramtags=[paramtags,ss]
  		ii=ii+1
  	ENDWHILE
  	paramtags=paramtags[1:*]
ab7bdcb3   Annie Hughes   Updated write and...
332
333
334
  	;(*!dustem_plugin).(i).scope=ptr_new(pluggin_scope)
  	(*!dustem_plugin)[i].scope=pluggin_scope
  	(*!dustem_plugin)[i].PARAMTAG=ptr_new(paramtags)
8f83f26b   Jean-Philippe Bernard   added saving plug...
335
336
  ENDFOR
ENDIF
8f83f26b   Jean-Philippe Bernard   added saving plug...
337

762cbe48   Jean-Philippe Bernard   modifed to cope f...
338
;==== This is to create (*!dustem_data).sed in case it does not exist already
7bb82b3b   Ilyes Choubani   remove lingering ...
339
; it doesn't exist at all times because dustem_init has been run
762cbe48   Jean-Philippe Bernard   modifed to cope f...
340
IF unit_input_emission_sed NE -1 THEN BEGIN
b7dca888   Jean-Philippe Bernard   improved to recov...
341
342
343
	;Nsed=n_elements(str_input_SED)
	;sed=dustem_initialize_internal_sed(Nsed)
	dustem_fillup_systvar_from_fits,*!dustem_data,str_input_SED,used_pol
17f02a5a   Jean-Philippe Bernard   updated
344
ENDIF
762cbe48   Jean-Philippe Bernard   modifed to cope f...
345

17f02a5a   Jean-Philippe Bernard   updated
346
;help,str_shown_SED
762cbe48   Jean-Philippe Bernard   modifed to cope f...
347

17f02a5a   Jean-Philippe Bernard   updated
348
349
;==== This is to create (*!dustem_show).sed in case it does not exist already
IF unit_dustem_shown_sed NE -1 THEN BEGIN
b7dca888   Jean-Philippe Bernard   improved to recov...
350
351
352
	;Nsed=n_elements(str_shown_SED)
	;sed=dustem_initialize_internal_sed(Nsed)
	dustem_fillup_systvar_from_fits,*!dustem_show,str_shown_SED,used_pol
762cbe48   Jean-Philippe Bernard   modifed to cope f...
353
354
355
ENDIF

IF unit_input_extinction_sed NE -1 THEN BEGIN
b7dca888   Jean-Philippe Bernard   improved to recov...
356
357
358
359
360
361
362
	;Next=n_elements(str_input_EXT)
	;ext=dustem_initialize_internal_sed(Next)
	dustem_fillup_systvar_from_fits,*!dustem_data,str_input_EXT,used_pol
ENDIF

IF unit_dustem_shown_extinction_sed NE -1 THEN BEGIN
	dustem_fillup_systvar_from_fits,*!dustem_show,str_shown_EXT,used_pol
762cbe48   Jean-Philippe Bernard   modifed to cope f...
363
364
ENDIF

a1839067   Jean-Philippe Bernard   First commit
365
366
;=== Below is only to get the same output form as dustem_compute_sed
;Note: If the same model is used, the outputs should be the same as what is in the fits file ....
762cbe48   Jean-Philippe Bernard   modifed to cope f...
367
368
IF unit_input_emission_sed NE -1 THEN BEGIN
	recomputed_dustem_predicted_emission_sed=dustem_compute_sed(*(*!dustem_fit).current_param_values,st=dustem_st)
52a3c8dc   Jean-Philippe Bernard   mise a jour
369
	;This is to compute the spectrum of Q,U which is not stored in dustem_st (only polsed is)
52f17b34   Annie Hughes   fixes for reading...
370
	if used_pol then toto = dustem_compute_stokes(*(*!dustem_fit).current_param_values,st=dustem_st,Q_spec=Q_spec,U_spec=U_spec,PSI_spec=PSI_spec,dustem_psi_em=dustem_psi_em)
762cbe48   Jean-Philippe Bernard   modifed to cope f...
371
372
373
ENDIF ELSE BEGIN
	recomputed_dustem_predicted_ext_sed=dustem_compute_ext(*(*!dustem_fit).current_param_values,st=dustem_st)
ENDELSE
52a3c8dc   Jean-Philippe Bernard   mise a jour
374
375
376
377
378
379
;IF !run_pol AND !run_lin AND tag_exist(*!dustem_show,'qsed') THEN BEGIN
;     dustem_polsed = dustem_compute_polsed(p_dim,st=st,P_spec=P_spec,SP_spec=SP_spec,dustem_polfrac=dustem_polfrac)
;     toto = dustem_compute_stokes(p_dim,st=st,Q_spec=Q_spec,U_spec=U_spec,PSI_spec=PSI_spec,dustem_psi_em=dustem_psi_em) 
;     dustem_qsed = toto[0]
;     dustem_used = toto[1]   
;ENDIF         
762cbe48   Jean-Philippe Bernard   modifed to cope f...
380

762cbe48   Jean-Philippe Bernard   modifed to cope f...
381
382
383
dustem_predicted_em=mrdfits(file,unit_dustem_predicted_emission_spectra,header_predicted_emission)
dustem_predicted_ext= mrdfits(file,unit_dustem_predicted_extinction_spectra,header_predicted_extinction)

7bb82b3b   Ilyes Choubani   remove lingering ...
384
dustem_st.sed=dustem_predicted_em   
762cbe48   Jean-Philippe Bernard   modifed to cope f...
385
dustem_st.ext=dustem_predicted_ext
90c53809   Annie Hughes   updated doc heade...
386

762cbe48   Jean-Philippe Bernard   modifed to cope f...
387
IF used_pol THEN BEGIN
52f17b34   Annie Hughes   fixes for reading...
388
389
390
391
392
   toto=mrdfits(file,unit_dustem_predicted_emission_spectra_pol,header_predicted_spectra_pol)
                                ;help,dustem_st.polsed,toto,/str
   dustem_st.polsed=toto
   toto=mrdfits(file,unit_dustem_predicted_extinction_spectra_pol,header_predicted_extinctions_pol)
   dustem_st.polext=toto
762cbe48   Jean-Philippe Bernard   modifed to cope f...
393
ENDIF
a1839067   Jean-Philippe Bernard   First commit
394

a1839067   Jean-Philippe Bernard   First commit
395
396
397
the_end:

END