Blame view

src/idl/dustem_init.pro 17.9 KB
279e3f60   Annie Hughes   dust model names ...
1
2
3
4
5
6
7
8
9
10
PRO dustem_init,model=model $
;                ,dir=dir $
                ,wraptest=wraptest $
                ,plot_it=plot_it $
                ,noerase=noerase $
                ,st_model=st_model $
                ,polarization=polarization $
                ,verbose=verbose $
                ,help=help $
                ,kwords=kwords
427f1205   Jean-Michel Glorian   version 4.2 merged
11
12
13
14

;+
; NAME:
;   dustem_init
427f1205   Jean-Michel Glorian   version 4.2 merged
15
16
; PURPOSE:
;   Defines system variables to run the DUSTEM code
279e3f60   Annie Hughes   dust model names ...
17
18
19
20
; CATEGORY:
;    DustEMWrap, Distributed, High-Level, Initialization
; CALLING SEQUENCE:
;   dustem_init,model=model,
427f1205   Jean-Michel Glorian   version 4.2 merged
21
; INPUTS:
279e3f60   Annie Hughes   dust model names ...
22
23
24
;    None
; OPTIONAL INPUT PARAMETERS:
;    None
427f1205   Jean-Michel Glorian   version 4.2 merged
25
; OUTPUTS:
279e3f60   Annie Hughes   dust model names ...
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
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    ;   st_model *** COMMENT AH -- what is this? END COMMENT AH ***
; ACCEPTED KEY-WORDS:
;    model = specifies the interstellar dust mixture used by DustEM
;           'MC10' model from Compiegne et al 2010 (default)
;           'DBP90' model from Desert et al 1990
;           'DL01' model from Draine & Li 2001
;           'WD01_RV5p5B' model from Weingartner & Draine 2002 with Rv=5.5
;           'DL07' model from Draine & Li 2007
;           'J13' model from Jones et al 2013, as updated in
;                 Koehler et al 2014
;           'G17_ModelA' model A from Guillet et al (2018). Includes
;                 polarisation. See Tables 2 and 3 of that paper for details.
;           'G17_ModelB' model B from Guillet et al (2018)
;           'G17_ModelC' model C from Guillet et al (2018)
;           'G17_ModelD' model A from Guillet et al (2018)
;   dir      = directory where to read data (overrides the default)
;   wraptest = test running dustem f90 through the wrapper
;   plot_it  = plots result of wraptest (ignored if wraptest not set)
;   help     = if set, print this help
;   verbose     = if set, output code diagnostic info (default OFF)
;   polarization *** COMMENT AH -- what is this? END COMMENT AH ***
;   noerase *** COMMENT AH -- what is this? END COMMENT AH ***
;   kwords *** COMMENT AH -- what are they? END COMMENT AH ***
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    1/ The following system variables are initialized to null values
427f1205   Jean-Michel Glorian   version 4.2 merged
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
;	or empty pointers:
;       !dustem_fit
;       !dustem_data
;       !dustem_inputs
;       !dustem_params
;       !run_ionfrac
;       !dustem_idl_continuum
;       !dustem_filters
;       !dustem_verbose
;       !dustem_show_plot
;    2/ optionally runs the fortran code (if wraptest)
;       This step calls the Fortran code to run a standard model
;    3/ !dustem_filters is initialized calling dustem_filter_init.pro.
; RESTRICTIONS:
;    The dustem fortran code must be installed
;    The dustem idl wrapper must be installed
279e3f60   Annie Hughes   dust model names ...
71
72
; PROCEDURES AND SUBROUTINES USED:
;    *** COMMENT AH --> is this really NONE? ****
427f1205   Jean-Michel Glorian   version 4.2 merged
73
; EXAMPLES
279e3f60   Annie Hughes   dust model names ...
74
;    dustem_init,model="MC10",/wrap,/plot_it
427f1205   Jean-Michel Glorian   version 4.2 merged
75
; MODIFICATION HISTORY:
427f1205   Jean-Michel Glorian   version 4.2 merged
76
;    Written by JPB,NF,DP Jan-2007
279e3f60   Annie Hughes   dust model names ...
77
78
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
427f1205   Jean-Michel Glorian   version 4.2 merged
79
80
;-

279e3f60   Annie Hughes   dust model names ...
81

427f1205   Jean-Michel Glorian   version 4.2 merged
82
83
84
85
86
IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_init'
  goto,the_end
ENDIF

d012e324   Ilyes Choubani   FIX to the use of...
87
dustem_define_la_common 
5a7a4415   Jean-Philippe Bernard   adapted to new fi...
88

0e608856   Jean-Philippe Bernard   improved
89
90
91
defsysv,'!dustem_verbose',0             ;1=verbose
IF keyword_set(verbose) THEN !dustem_verbose=1

b5ccb706   Jean-Philippe Bernard   improved to fit p...
92
defsysv,'!run_pol',0             ;0=no polar
279e3f60   Annie Hughes   dust model names ...
93
IF keyword_set(polarization) THEN !run_pol=1
b5ccb706   Jean-Philippe Bernard   improved to fit p...
94

427f1205   Jean-Michel Glorian   version 4.2 merged
95
96
97
98
99
;=== color correction system variables
defsysv,'!dustem_previous_cc',ptr_new()   ;store previous color correction values
defsysv,'!dustem_do_cc',1   ;indicates to dustem if color corrections are needed. Will be changed when fitting
defsysv,'!dustem_never_do_cc',0   ;set to 1 to never do color corrections (not recommanded, but faster).

279e3f60   Annie Hughes   dust model names ...
100
;=== polarization system variables
66aff855   Jean-Philippe Bernard   modified to impro...
101
102
103
104
defsysv, '!run_circ', 0.  
defsysv, '!run_anis', 0.  
defsysv, '!run_rrf', 0.    
defsysv, '!run_univ', 0.    
389a2b1d   Jean-Philippe Bernard   improved
105
defsysv, '!run_lin', 0.
66aff855   Jean-Philippe Bernard   modified to impro...
106

62a2393e   Jean-Philippe Bernard   added redshift
107
108
defsysv, '!dustem_redshift', 0.    ;in case the SED needs to be shifted for a non zero redshift

83b3ddee   Jean-Philippe Bernard   modified with Ily...
109
110
;This is just to make sure that plugin system variables are created even if no plugins are used
pd_bidon=['NONE']
83b3ddee   Jean-Philippe Bernard   modified with Ily...
111
112
dustem_init_plugins,pd_bidon

279e3f60   Annie Hughes   dust model names ...
113
defsysv,'!dustem_nocatch',0   ;set to catch errors in SED fitting.
83b3ddee   Jean-Philippe Bernard   modified with Ily...
114

4750086c   Ilyes Choubani   nouvelle philosph...
115

279e3f60   Annie Hughes   dust model names ...
116
;=== read info about instrument
427f1205   Jean-Michel Glorian   version 4.2 merged
117
118
119
120
121
122
123
file=!dustem_wrap_soft_dir+'instrument_description.xcat'
st=read_xcat(file,/silent)
defsysv,'!dustem_instrument_description',st

defsysv,'!indef', exists=exists_indef
IF NOT exists_indef THEN defsysv,'!indef',-32768.

40597848   Ilyes Choubani   Plotting of numbe...
124
125
126
127
128
129


;NOT REALLY SURE ABOUT THIS - getting the iteration number
defsysv, '!dustem_iter', {prv:1,act:1}
; defsysv, '!dustem_fit_perror', 0.

427f1205   Jean-Michel Glorian   version 4.2 merged
130
;define !dustem_fit
5a2643a4   Ilyes Choubani   cleaning/improvin...
131
dustem_fit_st={data:ptr_new(), $ ;,wavelength:ptr_new(), ;because wavelength arrays in the different datasets (data) can be different
427f1205   Jean-Michel Glorian   version 4.2 merged
132
133
134
135
136
137
138
               param_descs:ptr_new(),param_init_values:ptr_new(),param_func:ptr_new(), $
               fixed_param_descs:ptr_new(),fixed_param_init_values:ptr_new(), $
               chi2:0.D0,rchi2:0.D0, $
               current_param_values:ptr_new(), current_param_errors:ptr_new() $
               }
defsysv, '!dustem_fit', ptr_new(dustem_fit_st)    ;Data to fit

279e3f60   Annie Hughes   dust model names ...
139
if keyword_set(polarization) then begin
b74c4452   Ilyes Choubani   Treating extincti...
140
	defsysv, '!dustem_data', {    $ ;Structure contaning the data to fit
68598bce   Ilyes Choubani   reducing number o...
141
142
                                sed:    ptr_new(),      $ ; 
                                ext:    ptr_new(),      $ ;
68598bce   Ilyes Choubani   reducing number o...
143
144
                                qsed: ptr_new(),        $ ; 
                                used: ptr_new(),        $ ; 
5f04fa07   Ilyes Choubani   general update
145
146
147
                                polsed: ptr_new(),      $ ; 
                                polfrac: ptr_new(),     $ ;   
                                psi_em: ptr_new(),      $ ; 
68598bce   Ilyes Choubani   reducing number o...
148
                                qext: ptr_new(),        $ ; 
5f04fa07   Ilyes Choubani   general update
149
                                uext: ptr_new(),        $ ;
67bd858a   Ilyes Choubani   Replication of th...
150
151
                                polext: ptr_new(),      $ ;
                                fpolext: ptr_new(),  $ ;  ADDED FOR COMPLETENESS
5f04fa07   Ilyes Choubani   general update
152
153
                                psi_ext: ptr_new()      $ ; 
                                 
68598bce   Ilyes Choubani   reducing number o...
154
155
                         }
    
5f04fa07   Ilyes Choubani   general update
156
157
         
         rchi2_weight = {sed: 0.,ext: 0.,qsed:0.,used:0.,polsed:0.,polfrac:0.,psi_em:0.,qext:0.,uext:0.,polext:0.,psi_ext:0.}
68598bce   Ilyes Choubani   reducing number o...
158
         
b74c4452   Ilyes Choubani   Treating extincti...
159
    defsysv,'!dustem_show', {    $ ;Structure containing all the data (to be fitted or not)
5f04fa07   Ilyes Choubani   general update
160
161
162
163
164
165
166
167
168
169
                                sed:    ptr_new(),      $ ; 
                                ext:    ptr_new(),      $ ;
                                qsed: ptr_new(),        $ ; 
                                used: ptr_new(),        $ ; 
                                polsed: ptr_new(),      $ ; 
                                polfrac: ptr_new(),     $ ;   
                                psi_em: ptr_new(),      $ ; 
                                qext: ptr_new(),        $ ; 
                                uext: ptr_new(),        $ ;
                                polext: ptr_new(),      $ ;  
67bd858a   Ilyes Choubani   Replication of th...
170
                                fpolext: ptr_new(),  $ ; ADDED FOR COMPLETENESS
5f04fa07   Ilyes Choubani   general update
171
172
                                psi_ext: ptr_new()      $ ; 
                                 
68598bce   Ilyes Choubani   reducing number o...
173
174
                         }     
         
427f1205   Jean-Michel Glorian   version 4.2 merged
175
endif else begin
c8368c6e   Ilyes Choubani   updating plotting...
176
	
b74c4452   Ilyes Choubani   Treating extincti...
177
	defsysv, '!dustem_data', {    $ 
427f1205   Jean-Michel Glorian   version 4.2 merged
178
179
180
181
                                sed:    ptr_new(),      $
                                ext:    ptr_new()       $
                         }
	rchi2_weight = {sed: 0.,ext: 0.}
68598bce   Ilyes Choubani   reducing number o...
182
	
b74c4452   Ilyes Choubani   Treating extincti...
183
	defsysv, '!dustem_show', {    $ 
68598bce   Ilyes Choubani   reducing number o...
184
185
186
                                sed:    ptr_new(),      $
                                ext:    ptr_new()       $
                         }
427f1205   Jean-Michel Glorian   version 4.2 merged
187
188
endelse

c8368c6e   Ilyes Choubani   updating plotting...
189
190
if !run_pol then begin
    tagnames=tag_names(!dustem_data)
04db9491   Ilyes Choubani   fixing small erro...
191
    testpol = tagnames EQ 'POLSED' or tagnames EQ 'POLEXT' or tagnames EQ 'POLFRAC' or tagnames EQ 'FPOLEXT' or tagnames EQ 'PSI_EM' or tagnames EQ 'PSI_EXT'
c8368c6e   Ilyes Choubani   updating plotting...
192
193
194
195
    ind_data=where(~testpol,ctestpol)
    if ctestpol ne 0 then tagnames =(tag_names(!dustem_data))[ind_data] 

endif else tagnames=tag_names(!dustem_data)
68598bce   Ilyes Choubani   reducing number o...
196

427f1205   Jean-Michel Glorian   version 4.2 merged
197
198
199
200
201
202
203
204
instr="defsysv, '!fit_rchi2_weight', {"
FOR i = 0, n_elements(tagnames)-1 DO BEGIN
  instr+=tagnames(i)+': rchi2_weight.'+tagnames(i)
  IF i NE n_elements(tagnames)-1 THEN instr+=','
ENDFOR
instr+='}'
toto=execute(instr)

68598bce   Ilyes Choubani   reducing number o...
205
206
207
;#########system variables necessary for cgwindow plotting##########     
defsysv, '!dustemcgwin_id', {    $ ;IDs of windows to plot                  
                            sed:    la_undef(),      $                          
5f04fa07   Ilyes Choubani   general update
208
209
210
                            ext:    la_undef(),      $
                            prms:   la_undef(),      $
                            plgns:  la_undef()       $
68598bce   Ilyes Choubani   reducing number o...
211
                     }                                                      
18e4331f   Ilyes Choubani   general update (f...
212

5f04fa07   Ilyes Choubani   general update
213
214
215
216
217
218
219
220
221
222
defsysv, '!dustemcgwin_ncmds', {    $ ;Data to fit
                            sed:     {pl:0, nrm:0},      $ ; 
                            ext:     {pl:0, nrm:0},      $ ;
                            qsed:    {pl:0, nrm:0},      $ ; 
                            used:    {pl:0, nrm:0},      $ ; 
                            polsed:  {pl:0, nrm:0},      $ ; 
                            polfrac: {pl:0},             $ ;   
                            psi_em:  {pl:0},             $ ; 
                            qext:    {pl:0, nrm:0},      $ ; 
                            uext:    {pl:0, nrm:0},      $ ;
67bd858a   Ilyes Choubani   Replication of th...
223
224
                            polext:  {pl:0, nrm:0},      $ ;
                            fpolext:  {pl:0, nrm:0},      $ ; Added for completeness  
5f04fa07   Ilyes Choubani   general update
225
226
227
228
229
                            psi_ext: {pl:0},             $ ;
                            chi2 :   {pl:0, txtwdth:0.}, $ ; ;beacause chi2 needs to be updated (needing the command index)
                            rchi2 :  {pl:0, txtwdth:0.}, $ ;
                            pltit :  {pl:0, txtwdth:0.}, $ ; plot title
                            prms :   {pl:0},             $ ;
40597848   Ilyes Choubani   Plotting of numbe...
230
231
232
                            plgns :  {pl:0},             $ ;
                            runs :  {pl:0, txtwdth:0.}  $ ;
                            
5f04fa07   Ilyes Choubani   general update
233
                     }
5f04fa07   Ilyes Choubani   general update
234

279e3f60   Annie Hughes   dust model names ...
235
236
defsysv, '!dustem_mlog', 0      ;necessary for the plotting of negative values on the axis in dstmwrp_exp.pro

68598bce   Ilyes Choubani   reducing number o...
237
238
239
;###################################################################


b74c4452   Ilyes Choubani   Treating extincti...
240
241
242
;These two sysvars allow for the polarization angle (whether in emission or extinction) to
;be updated in procedures (non-plugins) that create polarization data such as 
;dustem_compute_stokes and dustem_compute_stokext
68598bce   Ilyes Choubani   reducing number o...
243
defsysv, '!dustem_psi', 0.
b74c4452   Ilyes Choubani   Treating extincti...
244
defsysv, '!dustem_psi_ext', 0.
3ff9cac3   Ilyes Choubani   general update
245

86e5c5c1   Ilyes Choubani   General update + ...
246

6d4eaab4   Ilyes Choubani   Replacing !dustem...
247
                     
427f1205   Jean-Michel Glorian   version 4.2 merged
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
;IDL> help,*!dustem_data,/str
;** Structure <2173b20>, 4 tags, length=448, data length=448, refs=1:
;   INSTRU_NAMES    STRING    Array[14]
;   FILT_NAMES      STRING    Array[14]
;   VALUES          FLOAT     Array[14]
;   SIGMA           FLOAT     Array[14]
defsysv,'!dustem_inputs',ptr_new()    ;dustem input files

;=== This is not a system variable anymore
;defsysv, '!dustem_ext', ptr_new()    ;Contains the values of extinction
;=== This is not a system variable anymore
;defsysv, '!dustem_specem', ptr_new() ;Contains the values of emission

defsysv, '!dustem_params', ptr_new() ;Contains the values of all Desert Model parameters (except extinction !)
;IDL> help,*!dustem_params,/str
;** Structure <2926e10>, 7 tags, length=13312, data length=13282, refs=1:
;   GRAINS          STRUCT    -> <Anonymous> Array[3]
;   GEMISSIV        STRUCT    -> <Anonymous> Array[300]
;   ISRF            STRUCT    -> <Anonymous> Array[64]
;   QABS            STRUCT    -> <Anonymous> Array[64]
;   CALOR           STRUCT    -> <Anonymous> Array[5]
;   SPECEM          STRUCT    -> <Anonymous> Array[1]
;   IONFRAC         STRUCT    -> <Anonymous> Array[10]

;defsysv, '!dustem_fit_sed',ptr_new()          ;Best fit SED

279e3f60   Annie Hughes   dust model names ...
274
;The following is not used in the RELEASE version of the code, only in VERSTRAETE
427f1205   Jean-Michel Glorian   version 4.2 merged
275
276
277
278
279
280
;IF getenv('DUSTEM_WHICH') EQ 'VERSTRAETE' THEN BEGIN
  defsysv, '!run_ionfrac', 0.     ; 0:no call to dustem_create_ionfrac UNLESS it is called as a param
                                  ; 1:call to dustem_create_ionfrac with the MIX_xxx.DAT files
                                  ; 2:call to dustem_create_ionfrac with the SIZE_xxx.DAT files
;ENDIF

427f1205   Jean-Michel Glorian   version 4.2 merged
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
defsysv,'!dustem_filters',ptr_new()     ;filter information (filled by dustem_filter_init.pro)
;; IDL> help,*!dustem_filters,/str
;; ** Structure <1b95608>, 17 tags, length=8232, data length=8118, refs=1:
;;    IRAC            STRUCT    -> <Anonymous> Array[1]
;;    MIPS            STRUCT    -> <Anonymous> Array[1]
;;    MSX             STRUCT    -> <Anonymous> Array[1]
;;    IRAS            STRUCT    -> <Anonymous> Array[1]
;;    DIRBE           STRUCT    -> <Anonymous> Array[1]
;;    SPM             STRUCT    -> <Anonymous> Array[1]
;;    ISOCAM          STRUCT    -> <Anonymous> Array[1]
;;    ISOPHOTP        STRUCT    -> <Anonymous> Array[1]
;;    ISOPHOTC        STRUCT    -> <Anonymous> Array[1]
;;    EFIRAS          STRUCT    -> <Anonymous> Array[1]
;;    ARCHEOPS        STRUCT    -> <Anonymous> Array[1]
;;    HFI             STRUCT    -> <Anonymous> Array[1]
;;    LFI             STRUCT    -> <Anonymous> Array[1]
;;    WMAP            STRUCT    -> <Anonymous> Array[1]
;;    SPIRE           STRUCT    -> <Anonymous> Array[1]
;;    PACS            STRUCT    -> <Anonymous> Array[1]
;;    AKARI           STRUCT    -> <Anonymous> Array[1]

4750086c   Ilyes Choubani   nouvelle philosph...
302
defsysv,'!dustem_verbose',0                                  ;1=verbose
427f1205   Jean-Michel Glorian   version 4.2 merged
303
304
defsysv,'!dustem_show_plot',1           ;0=show no plot

607060e5   Ilyes Choubani   test version
305

427f1205   Jean-Michel Glorian   version 4.2 merged
306
307
308
309
310
311
;apparently not needed anymore. Was removed.
;defsysv,'!ki',0.  ;apparently needed by mpfit, but what is it ?

;== This is for the default mode
dustem_inputs={GRAIN:'GRAIN.DAT',ISRF:'ISRF.DAT',ALIGN:'ALIGN.DAT'}
!dustem_inputs=ptr_new(dustem_inputs)
266ae799   Ilyes Choubani   General update
312
313


68598bce   Ilyes Choubani   reducing number o...
314
defsysv, '!dustem_HCD', ptr_new(1.00E20) ;I do not see the reason behind using a pointer in this case.
266ae799   Ilyes Choubani   General update
315
316


427f1205   Jean-Michel Glorian   version 4.2 merged
317
;===This is the Desert option
759a527d   Ilyes Choubani   general update
318

e69bf245   Jean-Philippe Bernard   improved
319
IF keyword_set(model) THEN BEGIN
4750086c   Ilyes Choubani   nouvelle philosph...
320
321
322

defsysv, '!dustem_model', model

759a527d   Ilyes Choubani   general update
323

e69bf245   Jean-Philippe Bernard   improved
324
  CASE model OF
279e3f60   Annie Hughes   dust model names ...
325
    'MC10':BEGIN
427f1205   Jean-Michel Glorian   version 4.2 merged
326
327
328
329
330
331
332
333
      (*!dustem_inputs).grain='GRAIN_MC10.DAT'
    END
    'DBP90':BEGIN
      (*!dustem_inputs).grain='GRAIN_DBP90.DAT'
    END
    'DL01':BEGIN
      (*!dustem_inputs).grain='GRAIN_DL01.DAT'
    END
279e3f60   Annie Hughes   dust model names ...
334
335
336
    'WD01_RV5p5B':BEGIN
      (*!dustem_inputs).grain='GRAIN_WD01_Rv5.5B.DAT'
    END
427f1205   Jean-Michel Glorian   version 4.2 merged
337
338
    'DL07':BEGIN
      (*!dustem_inputs).grain='GRAIN_DL07.DAT'
b5ccb706   Jean-Philippe Bernard   improved to fit p...
339
    END
279e3f60   Annie Hughes   dust model names ...
340
    'J13':BEGIN
427f1205   Jean-Michel Glorian   version 4.2 merged
341
      (*!dustem_inputs).grain='GRAIN_J13.DAT'
b5ccb706   Jean-Philippe Bernard   improved to fit p...
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
    END
    'G17_MODELA':BEGIN
      (*!dustem_inputs).grain='GRAIN_G17_MODELA.DAT'
      (*!dustem_inputs).align='ALIGN_G17_MODELA.DAT'
    END
    'G17_MODELB':BEGIN
      (*!dustem_inputs).grain='GRAIN_G17_MODELB.DAT'
      (*!dustem_inputs).align='ALIGN_G17_MODELB.DAT'
    END
    'G17_MODELC':BEGIN
      (*!dustem_inputs).grain='GRAIN_G17_MODELC.DAT'
      (*!dustem_inputs).align='ALIGN_G17_MODELC.DAT'
    END
    'G17_MODELD':BEGIN
      (*!dustem_inputs).grain='GRAIN_G17_MODELD.DAT'
      (*!dustem_inputs).align='ALIGN_G17_MODELD.DAT'
    END
2399e73e   Jean-Philippe Bernard   imprved towards r...
359
360
    'THEMIS':BEGIN
      (*!dustem_inputs).grain='GRAIN_THEMIS.DAT'
d012e324   Ilyes Choubani   FIX to the use of...
361
      (*!dustem_inputs).align='ALIGN_THEMIS.DAT'
2399e73e   Jean-Philippe Bernard   imprved towards r...
362
    END
8bab7d4b   Ilyes Choubani   small corrections...
363
    'NY_MODELA':BEGIN ;TB removed?
b0cabd3c   Ilyes Choubani   general update
364
365
      (*!dustem_inputs).grain='GRAIN_NY_MODELA.DAT'
      (*!dustem_inputs).align='ALIGN_G17_MODELA.DAT' 
266ae799   Ilyes Choubani   General update
366
    END
279e3f60   Annie Hughes   dust model names ...
367
    ;This is a user-defined model ;This will probably need to be modified.    
8bab7d4b   Ilyes Choubani   small corrections...
368
    'USER_MODEL':BEGIN ;TB removed? 
266ae799   Ilyes Choubani   General update
369
370
      (*!dustem_inputs).grain='GRAIN_USER.DAT' 
    END
427f1205   Jean-Michel Glorian   version 4.2 merged
371
    ELSE:BEGIN
26361fb3   Jean-Philippe Bernard   improved
372
      message,'model '+model+' unknown',/continue
279e3f60   Annie Hughes   dust model names ...
373
      message,'Known models are MC10,DBP90,DL01,DL07,J13,G17_MODELA,G17_MODELB,G17_MODELC,G17_MODELD',/continue
26361fb3   Jean-Philippe Bernard   improved
374
      stop
427f1205   Jean-Michel Glorian   version 4.2 merged
375
376
377
378
    END
  ENDCASE
ENDIF

427f1205   Jean-Michel Glorian   version 4.2 merged
379
380
381
382
383
384
;Initialize !dustem_params structure
IF not keyword_set(dir) THEN BEGIN
;  CASE getenv('DUSTEM_WHICH') OF
  CASE !dustem_which OF
    'DESERT':dir_in=!dustem_wrap_soft_dir+'/Data/DESERT_POST_ISO_MORE/'
    'COMPIEGNE': dir_in=!dustem_wrap_soft_dir+'/Data/MC_DAT/'
427f1205   Jean-Michel Glorian   version 4.2 merged
385
    'VERSTRAETE': dir_in=!dustem_wrap_soft_dir+'/Data/LV_DAT/'
279e3f60   Annie Hughes   dust model names ...
386
    'RELEASE': dir_in=!dustem_soft_dir
4fd64cbb   Ilyes Choubani   dustem_fit_sed_po...
387
    ELSE: dir_in=!dustem_wrap_soft_dir+'/Data/les_DAT/';!dustem_wrap_soft_dir+'/Data/les_DAT/'
427f1205   Jean-Michel Glorian   version 4.2 merged
388
389
390
391
392
393
394
  ENDCASE
ENDIF ELSE BEGIN
  dir_in=dir
ENDELSE
;stop
;dir_in=getenv('DUSTEM_SOFT_DIR')+'/src/'+dir
;dir_in=!dustem_soft_dir+'/src/'+dir
427f1205   Jean-Michel Glorian   version 4.2 merged
395

1a82f397   Ilyes Choubani   Keep dustemwrap a...
396
if keyword_set(kwords) then defsysv, '!dustem_kwords', ptr_new(kwords) else defsysv, '!dustem_kwords', ptr_new()
06fe3845   Ilyes Choubani   general update
397
398
399

st_model=dustem_read_all(dir_in,/silent)
!dustem_params=ptr_new(st_model)
25a9c7a2   Ilyes Choubani   removing stops
400

427f1205   Jean-Michel Glorian   version 4.2 merged
401
402
;=== create dynamical storage if needed
IF not file_test(!dustem_dat,/dir) THEN BEGIN
2cb867e5   Jean-Philippe Bernard   cant remember what
403
  spawn,'mkdir '+!dustem_dat
427f1205   Jean-Michel Glorian   version 4.2 merged
404
405
406
407
408
409
410
411
ENDIF
IF not file_test(!dustem_res,/dir) THEN BEGIN
  spawn,'mkdir '+!dustem_dat
ENDIF

;=== remove dynamical storage directories
;=== This is needed for iterative use of DUSTEM from IDL
if not keyword_set(noerase) then begin
427f1205   Jean-Michel Glorian   version 4.2 merged
412
413
414
415
416
417
418
419
420
421
CASE !dustem_which OF
  'VERSTRAETE':BEGIN
    IF file_test(!dustem_dat,/dir) THEN BEGIN
      spawn,'rm -rf '+!dustem_dat+'/les_DAT'
      spawn,'rm -rf '+!dustem_dat+'/les_QABS'
      spawn,'rm -rf '+!dustem_dat+'/les_CAPA'
    ENDIF
    IF file_test(!dustem_res,/dir) THEN BEGIN
      spawn,'rm -rf '+!dustem_res+'/les_RES'
    ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
422
  END
279e3f60   Annie Hughes   dust model names ...
423
  'RELEASE':BEGIN 
427f1205   Jean-Michel Glorian   version 4.2 merged
424
425
426
427
428
    IF file_test(!dustem_dat,/dir) THEN BEGIN
      spawn,'rm -rf '+!dustem_dat+'/data'
      spawn,'rm -rf '+!dustem_dat+'/hcap'
      spawn,'rm -rf '+!dustem_dat+'/oprop'
      spawn,'rm -rf '+!dustem_dat+'/out'
607060e5   Ilyes Choubani   test version
429
      ;spawn,'rm -rf '+!dustem_dat+'/plots' TO BE TESTED. NOT SURE ABOUT WHAT I AM DOING HERE. ASK JP ABOUT THIS
427f1205   Jean-Michel Glorian   version 4.2 merged
430
    ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
431
432
433
434
435
436
437
  END
  ELSE: BEGIN
  END
ENDCASE

;=== create storage directories
;=== This is needed for iterative use of DUSTEM from IDL
427f1205   Jean-Michel Glorian   version 4.2 merged
438
439
440
441
442
443
444
445
446
447
CASE !dustem_which OF
  'VERSTRAETE':BEGIN
    IF file_test(!dustem_dat,/dir) THEN BEGIN
      spawn,'mkdir '+!dustem_dat+'/les_DAT'
      spawn,'mkdir '+!dustem_dat+'/les_QABS'
      spawn,'mkdir '+!dustem_dat+'/les_CAPA'
    ENDIF
    IF file_test(!dustem_res,/dir) THEN BEGIN
      spawn,'mkdir '+!dustem_res+'/les_RES'
    ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
448
  END
279e3f60   Annie Hughes   dust model names ...
449
  'RELEASE':BEGIN  ; IN CHANGED THIS AS WELL
427f1205   Jean-Michel Glorian   version 4.2 merged
450
451
452
453
454
    IF file_test(!dustem_dat,/dir) THEN BEGIN
      spawn,'mkdir '+!dustem_dat+'/data'
      spawn,'mkdir '+!dustem_dat+'/hcap'
      spawn,'mkdir '+!dustem_dat+'/oprop'
      spawn,'mkdir '+!dustem_dat+'/out'
4750086c   Ilyes Choubani   nouvelle philosph...
455
      ;spawn,'mkdir '+!dustem_dat+'/plots' TO BE TESTED
427f1205   Jean-Michel Glorian   version 4.2 merged
456
    ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
457
458
459
460
461
462
463
464
465
466
  END
  ELSE: BEGIN
  END
ENDCASE
endif ; /noerase

;=== If needed, test runing the model through the wrapper
IF keyword_set(wraptest) THEN BEGIN
  dir_out=!dustem_dat
  dustem_write_all,st_model,dir_out
427f1205   Jean-Michel Glorian   version 4.2 merged
467
468
469
470
471
472
473
  st=dustem_run()
  IF keyword_set(plot_it) THEN BEGIN
    loadct,13
    dustem_plot_nuinu_em,st,yr=[1e-14,1.e-6],/ysty,xr=[1,5e3],/xsty
  ENDIF
ENDIF

427f1205   Jean-Michel Glorian   version 4.2 merged
474
;Initialize filters
279e3f60   Annie Hughes   dust model names ...
475
dustem_filter_init
68598bce   Ilyes Choubani   reducing number o...
476

427f1205   Jean-Michel Glorian   version 4.2 merged
477
478
479
the_end:

END