Blame view

src/idl/dustem_init.pro 21 KB
279e3f60   Annie Hughes   dust model names ...
1
PRO dustem_init,model=model $
279e3f60   Annie Hughes   dust model names ...
2
3
4
5
6
7
8
                ,wraptest=wraptest $
                ,plot_it=plot_it $
                ,noerase=noerase $
                ,st_model=st_model $
                ,polarization=polarization $
                ,verbose=verbose $
                ,help=help $
f8434c57   Jean-Philippe Bernard   modified handelin...
9
                ,grain_keywords=grain_keywords
427f1205   Jean-Michel Glorian   version 4.2 merged
10
11
12
13

;+
; NAME:
;   dustem_init
427f1205   Jean-Michel Glorian   version 4.2 merged
14
15
; PURPOSE:
;   Defines system variables to run the DUSTEM code
279e3f60   Annie Hughes   dust model names ...
16
17
18
19
; CATEGORY:
;    DustEMWrap, Distributed, High-Level, Initialization
; CALLING SEQUENCE:
;   dustem_init,model=model,
427f1205   Jean-Michel Glorian   version 4.2 merged
20
; INPUTS:
279e3f60   Annie Hughes   dust model names ...
21
22
23
;    None
; OPTIONAL INPUT PARAMETERS:
;    None
427f1205   Jean-Michel Glorian   version 4.2 merged
24
; OUTPUTS:
279e3f60   Annie Hughes   dust model names ...
25
26
27
28
29
30
31
32
;    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
b9f9db5d   Annie Hughes   WD01 model update
33
;           'WD01_RV5P5B' model from Weingartner & Draine 2002 with Rv=5.5
279e3f60   Annie Hughes   dust model names ...
34
35
36
37
38
39
40
41
;           '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)
f8434c57   Jean-Philippe Bernard   modified handelin...
42
43
44
45
46
47
48
;   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   = set this variables for runs taking polarization into account
;   noerase        : set this keyword to not erase the temporary memory used by dustemwrap
;   grain_keywords : Fortran grain keywords. Must be an array of Ngrains strings. Use '?' to keep default values.
279e3f60   Annie Hughes   dust model names ...
49
50
51
52
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    1/ The following system variables are initialized to null values
427f1205   Jean-Michel Glorian   version 4.2 merged
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;	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 ...
69
70
; PROCEDURES AND SUBROUTINES USED:
;    *** COMMENT AH --> is this really NONE? ****
427f1205   Jean-Michel Glorian   version 4.2 merged
71
; EXAMPLES
279e3f60   Annie Hughes   dust model names ...
72
;    dustem_init,model="MC10",/wrap,/plot_it
427f1205   Jean-Michel Glorian   version 4.2 merged
73
; MODIFICATION HISTORY:
427f1205   Jean-Michel Glorian   version 4.2 merged
74
;    Written by JPB,NF,DP Jan-2007
279e3f60   Annie Hughes   dust model names ...
75
76
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
427f1205   Jean-Michel Glorian   version 4.2 merged
77
78
;-

279e3f60   Annie Hughes   dust model names ...
79

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

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

8a2cb251   Jean-Philippe Bernard   modifcations to c...
87
88
89
90
91
92
93
94
95
96
97
;define which code is running, idl, gdl or fawlty
defsysv,'!fl',exist=fawlty
defsysv,'!gdl',exist=gdl
IF fawlty THEN defsysv,'!dustemwrap_which_language','fawlty'
IF gdl THEN defsysv,'!dustemwrap_which_language','gdl'
IF not fawlty and not gdl THEN defsysv,'!dustemwrap_which_language','idl'

;use this to let dustemwrap to not use object-oriented graphics
;IF gdl THEN defsysv,'!dustem_noobj',1 ELSE defsysv,'!dustem_noobj',0
IF fawlty OR gdl THEN defsysv,'!dustem_noobj',1 ELSE defsysv,'!dustem_noobj',0
;defsysv,'!dustem_noobj',1
163e943a   Jean-Philippe Bernard   added back the mo...
98
99
100
101
102

un_mouchard={iteration:0L,chi2:0.d0,rchi2:0.d0,parameters_descriptions:ptr_new(),parameters_values:ptr_new()}
mouchard=ptr_new(replicate(un_mouchard,1))
defsysv,'!iteration_mouchard',mouchard

0e608856   Jean-Philippe Bernard   improved
103
104
105
defsysv,'!dustem_verbose',0             ;1=verbose
IF keyword_set(verbose) THEN !dustem_verbose=1

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

427f1205   Jean-Michel Glorian   version 4.2 merged
109
110
111
112
113
;=== 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 ...
114
;=== polarization system variables
66aff855   Jean-Philippe Bernard   modified to impro...
115
116
117
118
defsysv, '!run_circ', 0.  
defsysv, '!run_anis', 0.  
defsysv, '!run_rrf', 0.    
defsysv, '!run_univ', 0.    
389a2b1d   Jean-Philippe Bernard   improved
119
defsysv, '!run_lin', 0.
66aff855   Jean-Philippe Bernard   modified to impro...
120

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

83b3ddee   Jean-Philippe Bernard   modified with Ily...
123
124
;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...
125
126
dustem_init_plugins,pd_bidon

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

4750086c   Ilyes Choubani   nouvelle philosph...
129

af20847a   Ilyes Choubani   small fix
130
131
132
133
defsysv,'!indef', exists=exists_indef
IF NOT exists_indef THEN defsysv,'!indef',-32768.


279e3f60   Annie Hughes   dust model names ...
134
;=== read info about instrument
427f1205   Jean-Michel Glorian   version 4.2 merged
135
136
137
138
file=!dustem_wrap_soft_dir+'instrument_description.xcat'
st=read_xcat(file,/silent)
defsysv,'!dustem_instrument_description',st

f9089dc2   Ilyes Choubani   implementing the ...
139
defsysv, '!dustem_isrf_file', ptr_new() ;but there is only one system variable for this... Is this ok?
40597848   Ilyes Choubani   Plotting of numbe...
140

40597848   Ilyes Choubani   Plotting of numbe...
141
defsysv, '!dustem_iter', {prv:1,act:1}
40597848   Ilyes Choubani   Plotting of numbe...
142

427f1205   Jean-Michel Glorian   version 4.2 merged
143
;define !dustem_fit
5a2643a4   Ilyes Choubani   cleaning/improvin...
144
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
145
146
147
148
149
150
151
               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 ...
152
if keyword_set(polarization) then begin
0068116a   Ilyes Choubani   General update + ...
153
154
    
    dustem_data_st ={    $ ;Structure contaning the data to fit
68598bce   Ilyes Choubani   reducing number o...
155
156
                                sed:    ptr_new(),      $ ; 
                                ext:    ptr_new(),      $ ;
68598bce   Ilyes Choubani   reducing number o...
157
158
                                qsed: ptr_new(),        $ ; 
                                used: ptr_new(),        $ ; 
5f04fa07   Ilyes Choubani   general update
159
160
161
                                polsed: ptr_new(),      $ ; 
                                polfrac: ptr_new(),     $ ;   
                                psi_em: ptr_new(),      $ ; 
68598bce   Ilyes Choubani   reducing number o...
162
                                qext: ptr_new(),        $ ; 
5f04fa07   Ilyes Choubani   general update
163
                                uext: ptr_new(),        $ ;
67bd858a   Ilyes Choubani   Replication of th...
164
                                polext: ptr_new(),      $ ;
4da8e20e   Ilyes Choubani   other procs that ...
165
                                fpolext: ptr_new(),     $ ;  
5f04fa07   Ilyes Choubani   general update
166
167
                                psi_ext: ptr_new()      $ ; 
                                 
68598bce   Ilyes Choubani   reducing number o...
168
                         }
0068116a   Ilyes Choubani   General update + ...
169
170

	defsysv, '!dustem_data', ptr_new(dustem_data_st) 
68598bce   Ilyes Choubani   reducing number o...
171
    
0068116a   Ilyes Choubani   General update + ...
172
173
174
    defsysv,'!dustem_show', ptr_new(dustem_data_st)   
    
    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...
175
         
427f1205   Jean-Michel Glorian   version 4.2 merged
176
endif else begin
0068116a   Ilyes Choubani   General update + ...
177
178

    dustem_data_st = {    $ 
427f1205   Jean-Michel Glorian   version 4.2 merged
179
180
181
                                sed:    ptr_new(),      $
                                ext:    ptr_new()       $
                         }
68598bce   Ilyes Choubani   reducing number o...
182
	
0068116a   Ilyes Choubani   General update + ...
183
184
185
186
187
188
189
	defsysv, '!dustem_data', ptr_new(dustem_data_st)
	
	
	defsysv, '!dustem_show', ptr_new(dustem_data_st)
    
    rchi2_weight = {sed: 0.,ext: 0.}

427f1205   Jean-Michel Glorian   version 4.2 merged
190
191
endelse

c8368c6e   Ilyes Choubani   updating plotting...
192
if !run_pol then begin
0068116a   Ilyes Choubani   General update + ...
193
    tagnames=tag_names(*!dustem_data)
04db9491   Ilyes Choubani   fixing small erro...
194
    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...
195
    ind_data=where(~testpol,ctestpol)
0068116a   Ilyes Choubani   General update + ...
196
    if ctestpol ne 0 then tagnames =(tag_names(*!dustem_data))[ind_data] 
c8368c6e   Ilyes Choubani   updating plotting...
197

0068116a   Ilyes Choubani   General update + ...
198
endif else tagnames=tag_names(*!dustem_data)
68598bce   Ilyes Choubani   reducing number o...
199

427f1205   Jean-Michel Glorian   version 4.2 merged
200
201
202
203
204
205
206
207
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...
208
209
210
;#########system variables necessary for cgwindow plotting##########     
defsysv, '!dustemcgwin_id', {    $ ;IDs of windows to plot                  
                            sed:    la_undef(),      $                          
5f04fa07   Ilyes Choubani   general update
211
212
213
                            ext:    la_undef(),      $
                            prms:   la_undef(),      $
                            plgns:  la_undef()       $
68598bce   Ilyes Choubani   reducing number o...
214
                     }                                                      
18e4331f   Ilyes Choubani   general update (f...
215

5f04fa07   Ilyes Choubani   general update
216
217
218
219
220
221
222
223
224
225
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...
226
                            polext:  {pl:0, nrm:0},      $ ;
4da8e20e   Ilyes Choubani   other procs that ...
227
                            fpolext: {pl:0, nrm:0},      $ ;  
5f04fa07   Ilyes Choubani   general update
228
229
230
231
232
                            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...
233
                            plgns :  {pl:0},             $ ;
07372e26   Ilyes Choubani   Corrected huge pl...
234
                            runs :   {pl:0, txtwdth:0.}  $ ;
40597848   Ilyes Choubani   Plotting of numbe...
235
                            
5f04fa07   Ilyes Choubani   general update
236
                     }
5f04fa07   Ilyes Choubani   general update
237

9c7cd75f   Jean-Philippe Bernard   added system vari...
238
239
240
241

version={version:'V2.0',version_number:2.0}
defsysv, '!dustem_version',version       ;This is the current dustemwrap version

4da8e20e   Ilyes Choubani   other procs that ...
242
243
244

;NB: #This is definitely not a robust way to handle the _extra tags but it's a primariy workaround for the plotting tags of the data sets. 

f7c692c9   Ilyes Choubani   updating dustem_i...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
defsysv, '!dustem_plot_range', {    $

                            sed:     {xr:[1.,5.0e5], yr:[5e-8,1.00e6]},      $ ; 
                            qsed:    {xr:[1.,5.0e5], yr:[5e-8,1.00e6]},      $ ; 
                            used:    {xr:[1.,5.0e5], yr:[5e-8,1.00e6]},      $ ; 
                            polsed:  {xr:[1.,5.0e5], yr:[5e-8,1.00e6]},      $ ; 
                            polfrac: {xr:[1.,5.0e5], yr:[1.00E-04,50.00]},      $ ;   
                            psi_em:  {xr:[1.,5.0e5], yr:[-90.,90.]},   $ ;
                            ext:     {xr:[0.01,30], yr:[5.00E-8,10]},      $ ; 
                            qext:    {xr:[0.01,30], yr:[5.00E-8,10]},      $ ; 
                            uext:    {xr:[0.01,30], yr:[5.00E-8,10]},      $ ;
                            polext:  {xr:[0.01,30], yr:[5.00E-8,10]},      $ ;
                            fpolext: {xr:[0.01,30], yr:[1.00E-04,10.00]},      $ ; 
                            psi_ext: {xr:[0.01,30], yr:[-90.,90.]},   $ ;
                            title_m : 'DUSTEMWRAP '+'('+!dustem_version.version+') '+'Spectral Energy Distribution', $ ; default title if no title is specified
                            title_x : 'DUSTEMWRAP '+'('+!dustem_version.version+') '+'Dust Optical Depth' $
4da8e20e   Ilyes Choubani   other procs that ...
261
262
263
                     }


f7c692c9   Ilyes Choubani   updating dustem_i...
264

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

68598bce   Ilyes Choubani   reducing number o...
267
268
269
;###################################################################


b74c4452   Ilyes Choubani   Treating extincti...
270
271
272
;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...
273
defsysv, '!dustem_psi', 0.
b74c4452   Ilyes Choubani   Treating extincti...
274
defsysv, '!dustem_psi_ext', 0.
3ff9cac3   Ilyes Choubani   general update
275

4da8e20e   Ilyes Choubani   other procs that ...
276

4b745987   Ilyes Choubani   minor update
277
;useful pointers (current dustem output structure and current mpfit params values)
afde94a3   Ilyes Choubani   general update
278
defsysv,'!dustem_current',ptr_new()
4da8e20e   Ilyes Choubani   other procs that ...
279
280
281
282
283
284
285

; defsysv,'!dustem_current_params',ptr_new() ;Is replaced by (*!dustem_fit).CURRENT_PARAM_VALUES 
; defsysv, '!dustem_current_errors', ptr_new() ;Is replaced by (*!dustem_fit).current_param_errors=ptr_new(p_er_dim)



defsysv, '!dustem_end', 0 ;Easiest and fastest way I could find to signal the end of the fit. If there is a better way please remove this.                     
427f1205   Jean-Michel Glorian   version 4.2 merged
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
;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 ...
312
;The following is not used in the RELEASE version of the code, only in VERSTRAETE
427f1205   Jean-Michel Glorian   version 4.2 merged
313
314
315
316
317
318
;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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
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...
340
defsysv,'!dustem_verbose',0                                  ;1=verbose
427f1205   Jean-Michel Glorian   version 4.2 merged
341
342
defsysv,'!dustem_show_plot',1           ;0=show no plot

607060e5   Ilyes Choubani   test version
343

427f1205   Jean-Michel Glorian   version 4.2 merged
344
345
346
347
348
349
;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)
72089d7a   Jean-Philippe Bernard   improved to save ...
350
use_model='DEFAULT'
266ae799   Ilyes Choubani   General update
351

68598bce   Ilyes Choubani   reducing number o...
352
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
353
354


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

e69bf245   Jean-Philippe Bernard   improved
357
IF keyword_set(model) THEN BEGIN
e69bf245   Jean-Philippe Bernard   improved
358
  CASE model OF
279e3f60   Annie Hughes   dust model names ...
359
    'MC10':BEGIN
427f1205   Jean-Michel Glorian   version 4.2 merged
360
361
362
363
364
365
366
367
      (*!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
b9f9db5d   Annie Hughes   WD01 model update
368
    'WD01_RV5P5B':BEGIN
279e3f60   Annie Hughes   dust model names ...
369
370
      (*!dustem_inputs).grain='GRAIN_WD01_Rv5.5B.DAT'
    END
427f1205   Jean-Michel Glorian   version 4.2 merged
371
372
    'DL07':BEGIN
      (*!dustem_inputs).grain='GRAIN_DL07.DAT'
b5ccb706   Jean-Philippe Bernard   improved to fit p...
373
    END
279e3f60   Annie Hughes   dust model names ...
374
    'J13':BEGIN
427f1205   Jean-Michel Glorian   version 4.2 merged
375
      (*!dustem_inputs).grain='GRAIN_J13.DAT'
b5ccb706   Jean-Philippe Bernard   improved to fit p...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
    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...
393
394
    'THEMIS':BEGIN
      (*!dustem_inputs).grain='GRAIN_THEMIS.DAT'
d012e324   Ilyes Choubani   FIX to the use of...
395
      (*!dustem_inputs).align='ALIGN_THEMIS.DAT'
2399e73e   Jean-Philippe Bernard   imprved towards r...
396
    END
8bab7d4b   Ilyes Choubani   small corrections...
397
    'NY_MODELA':BEGIN ;TB removed?
b0cabd3c   Ilyes Choubani   general update
398
399
      (*!dustem_inputs).grain='GRAIN_NY_MODELA.DAT'
      (*!dustem_inputs).align='ALIGN_G17_MODELA.DAT' 
266ae799   Ilyes Choubani   General update
400
    END
279e3f60   Annie Hughes   dust model names ...
401
    ;This is a user-defined model ;This will probably need to be modified.    
8bab7d4b   Ilyes Choubani   small corrections...
402
    'USER_MODEL':BEGIN ;TB removed? 
266ae799   Ilyes Choubani   General update
403
404
      (*!dustem_inputs).grain='GRAIN_USER.DAT' 
    END
427f1205   Jean-Michel Glorian   version 4.2 merged
405
    ELSE:BEGIN
26361fb3   Jean-Philippe Bernard   improved
406
      message,'model '+model+' unknown',/continue
b9f9db5d   Annie Hughes   WD01 model update
407
      message,'Known models are MC10,DBP90,DL01,WD01_RV5P5B,DL07,J13,G17_MODELA,G17_MODELB,G17_MODELC,G17_MODELD',/continue
26361fb3   Jean-Philippe Bernard   improved
408
      stop
427f1205   Jean-Michel Glorian   version 4.2 merged
409
410
    END
  ENDCASE
72089d7a   Jean-Philippe Bernard   improved to save ...
411
  use_model=model
427f1205   Jean-Michel Glorian   version 4.2 merged
412
413
ENDIF

72089d7a   Jean-Philippe Bernard   improved to save ...
414
415
defsysv, '!dustem_model', use_model

427f1205   Jean-Michel Glorian   version 4.2 merged
416
417
418
419
420
421
;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
422
    'VERSTRAETE': dir_in=!dustem_wrap_soft_dir+'/Data/LV_DAT/'
279e3f60   Annie Hughes   dust model names ...
423
    'RELEASE': dir_in=!dustem_soft_dir
4fd64cbb   Ilyes Choubani   dustem_fit_sed_po...
424
    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
425
426
427
428
429
430
431
  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
432

f8434c57   Jean-Philippe Bernard   modified handelin...
433
;stop
06fe3845   Ilyes Choubani   general update
434

f8434c57   Jean-Philippe Bernard   modified handelin...
435
436
437
438
439
440
441
442
443
;reading fortran files to set up !dustem_params
defsysv, '!dustem_kwords', ptr_new()
st_model=dustem_read_all(dir_in,/silent)
!dustem_params=ptr_new(st_model)
Ngrains=(*!dustem_params).Ngrains
needed_keywords=strarr(Ngrains)
;replace dustem keywords requested by the user
IF keyword_set(grain_keywords) THEN BEGIN
  IF n_elements(grain_keywords) NE Ngrains THEN BEGIN
0bf9eb5f   Annie Hughes   minor comments
444
445
    message,'Grain_keywords provided do not match the number of grains ('+strtrim(Ngrains,2)+') in the model',/continue
    message,'Please provide '+strtrim(Ngrains,2)+' keywords, using ? for those left to their default value',/continue
f8434c57   Jean-Philippe Bernard   modified handelin...
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
    stop
  ENDIF ELSE BEGIN
    FOR i=0L,Ngrains-1 DO BEGIN
      IF grain_keywords[i] NE '?' THEN BEGIN
        needed_keywords[i]=grain_keywords[i]
      ENDIF ELSE BEGIN
        needed_keywords[i]=(*!dustem_params).grains(i).TYPE_KEYWORDS
      ENDELSE
    ENDFOR
  ENDELSE
ENDIF ELSE BEGIN
  FOR i=0L,Ngrains-1 DO BEGIN
    needed_keywords[i]=(*!dustem_params).grains(i).TYPE_KEYWORDS
  ENDFOR
ENDELSE
;reading fortran inputs again, but now with replaced keywords
defsysv,'!dustem_kwords', ptr_new(needed_keywords)
06fe3845   Ilyes Choubani   general update
463
464
st_model=dustem_read_all(dir_in,/silent)
!dustem_params=ptr_new(st_model)
f8434c57   Jean-Philippe Bernard   modified handelin...
465
;stop
25a9c7a2   Ilyes Choubani   removing stops
466

427f1205   Jean-Michel Glorian   version 4.2 merged
467
468
;=== create dynamical storage if needed
IF not file_test(!dustem_dat,/dir) THEN BEGIN
3f13e841   Jean-Philippe Bernard   replaced mkdir by...
469
  ;spawn,'mkdir '+!dustem_dat
58593d56   Annie Hughes   force_mkdir wrong...
470
  force_mkdir,!dustem_dat
427f1205   Jean-Michel Glorian   version 4.2 merged
471
472
ENDIF
IF not file_test(!dustem_res,/dir) THEN BEGIN
3f13e841   Jean-Philippe Bernard   replaced mkdir by...
473
  ;spawn,'mkdir '+!dustem_dat
58593d56   Annie Hughes   force_mkdir wrong...
474
  force_mkdir,!dustem_dat
427f1205   Jean-Michel Glorian   version 4.2 merged
475
476
477
478
479
ENDIF

;=== remove dynamical storage directories
;=== This is needed for iterative use of DUSTEM from IDL
if not keyword_set(noerase) then begin
f8434c57   Jean-Philippe Bernard   modified handelin...
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
519
520
521
522
523
524
525
526
527
528
  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
    END
    'RELEASE':BEGIN 
      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'
        ;spawn,'rm -rf '+!dustem_dat+'/plots' TO BE TESTED. NOT SURE ABOUT WHAT I AM DOING HERE. ASK JP ABOUT THIS
      ENDIF
    END
    ELSE: BEGIN
    END
  ENDCASE

  ;=== create storage directories
  ;=== This is needed for iterative use of DUSTEM from IDL
  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
    END
    'RELEASE':BEGIN  ; IN CHANGED THIS AS WELL
      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'
        ;spawn,'mkdir '+!dustem_dat+'/plots' TO BE TESTED
      ENDIF
    END
    ELSE: BEGIN
    END
  ENDCASE
427f1205   Jean-Michel Glorian   version 4.2 merged
529
530
531
532
533
534
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
535
536
537
538
539
540
541
  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
542
;Initialize filters
279e3f60   Annie Hughes   dust model names ...
543
dustem_filter_init
68598bce   Ilyes Choubani   reducing number o...
544

427f1205   Jean-Michel Glorian   version 4.2 merged
545
546
547
the_end:

END