Blame view

src/idl/dustem_init_params.pro 5.35 KB
a4c9699a   Annie Hughes   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
PRO dustem_init_params,model,pd,iv, $
                       fpd=fpd,fiv=fiv $
                       ,ulimed=ulimed,llimed=llimed,ulims=ulims,llims=llims $
                       ,tied=tied,fixed=fixed $
                       ,polarization=polarization
;+
; NAME:
;    dustem_init_params
;
; PURPOSE:
; This routine initialises the free and fixed parameters of both the
; dust models and plugins. It does some basic sanity checking.
;  
; CATEGORY:
;    DustEMWrap, Distributed, Mid-Level, Initialization
;
; CALLING SEQUENCE:
041ca6b6   Annie Hughes   updated help
18
;    dustem_init_params, model, pd, iv, [,fpd=fpd,fiv=fiv,ulimed=ulimed,llimed=llimed,ulims=ulims,lolims=llims,tied=tied,fixed=fixed]
a4c9699a   Annie Hughes   first commit
19
20
21
22
23
24
25
;  
; INPUTS:
;    model -- the dust model
;    pd -- the parameter description vector
;    iv -- the initial values of the free parameters 
;
; OPTIONAL INPUT PARAMETERS:
041ca6b6   Annie Hughes   updated help
26
27
28
29
30
31
32
33
34
;    fpd -- the fixed parameter description vector
;    fiv -- the initial values of the fixed parameters 
;    ulimed -- flag 1/0 if upper limits ON/OFF
;    llimed -- flag 1/0 if lower limits ON/OFF
;    ulims -- upper limit values
;    llims -- lower limit values
;
;
;
a4c9699a   Annie Hughes   first commit
35
36
37
38
39
40
41
42
;
; OUTPUTS:
;    None
;
; OPTIONAL OUTPUT PARAMETERS:
;    None
;
; ACCEPTED KEY-WORDS:
041ca6b6   Annie Hughes   updated help
43
;    polarization = assume dustem is running in polarization mode
a4c9699a   Annie Hughes   first commit
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
;    help      = if set, print this help
;
; COMMON BLOCKS:
;    None
;
; SIDE EFFECTS:
;    None
;
; RESTRICTIONS:
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
;
; PROCEDURES AND SUBROUTINES USED:
;   dustem_init_parinfo
;   dustem_init_plugins
;   dustem_init_fixed_params
;  
; EXAMPLES
;
; MODIFICATION HISTORY:
;    Written by AH October-2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_init_params'
  goto,the_end
END

Npar=n_elements(pd)
Niv=n_elements(iv)

if Npar ne Niv then begin
   message, 'Number of parameters does not equal number of initial values provided',/info
   stop
end

if keyword_set(ulimed) then begin
   Nulimed=n_elements(ulimed)
   if Npar ne Nulimed then begin
      message, 'Number of parameters does not equal number of upper limit flags',/info
      stop
   end
end

if keyword_set(ulims) then begin
   Nulims=n_elements(ulims)
   if Npar ne Nulims then begin
      message, 'Number of upper limits must equal number of parameters (use ulimed to specify ON/OFF for each parameter)',/info
      stop
   end
end

if keyword_set(llimed) then begin
   Nllimed=n_elements(llimed)
   if Npar ne Nllimed then begin
      message, 'Number of parameters does not equal number of lower limit flags',/info
      stop
   end
end

if keyword_set(llims) then begin
   Nllims=n_elements(llims)
   if Npar ne Nllims then begin
      message, 'Number of lower limits must equal number of parameters (use llimed to specify ON/OFF for each parameter)',/info
      stop
   end
end


if keyword_set(fpd) then begin
   Nfpar=n_elements(fpd)
   Nfiv=n_elements(fiv)
   if Nfpar ne Nfiv then begin
      message, 'Number of fixed parameters does not equal number of fixed initial values',/info
      stop
   end
;== CHECK IF USER HAS MADE SOMETHING FIXED AND FREE
   match,pd,fpd,a,b,count=ct
   if ct ne 0 then begin
      message, 'Parameter that is both free and fixed?',/info
      print,'Matching free parameters: '+pd[a]
      print,'Matching fixed parameters: '+fpd[b]
      stop
   end
end

; basic sanity checking of models

041ca6b6   Annie Hughes   updated help
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
;;known_mdls=['MC10','DBP90','DL01','WD01_RV5P5B','DL07','J13','G17_MODELA','G17_MODELB','G17_MODELC','G17_MODELD'] 
;;pol_mdls=['G17_MODELA','G17_MODELB','G17_MODELC','G17_MODELD'] 
;;test_model = where(known_mdls eq model,ct)
;; if ct eq 0 then begin
;;    message,'ISM dust model '+use_model+' unknown',/continue
;;    message,'Known models are MC10,DBP90,DL01,WD01_RV5P5B,DL07,J13,G17_MODELA,G17_MODELB,G17_MODELC,G17_MODELD',/continue
;;    stop
;; end
;; if keyword_set(polarization) then begin
;;    test_model = where(pol_mdls eq model,ct)
;;    if ct eq 0 then begin
;;       message,'The only models with polarisation are G17_MODELA,G17_MODELB,G17_MODELC,G17_MODELD',/continue
;;       stop
;;    end
;; end else begin
;;    test_model = where(pol_mdls eq model,ct)
;;    if ct eq 1 then begin
;;       message,'You have requested a dust model with polarisation '+model+' but DustEMWrap is not initialized in polarisation mode',/info
;;       message,'You should set dustem_init,model=use_model,polarization=1',/info
;;       message,'and set polarization=1 in the call to this routine (dustem_init_params)',/info
;;       stop
;;    end
;; end

eef37ef9   Annie Hughes   do not remember, ...
158
exists=dustem_test_model_exists(model,/silent)
041ca6b6   Annie Hughes   updated help
159
160
161
if exists ne 1 then $
   message,'Unknown dust model '+model

eef37ef9   Annie Hughes   do not remember, ...
162
polexists=dustem_test_model_exists(model,/pol,/silent)
041ca6b6   Annie Hughes   updated help
163
164
if keyword_set(polarization) and polexists eq 0 then $
   message,'You have requested polarization mode, but the '+model+' model does not predict polarization'
a4c9699a   Annie Hughes   first commit
165
166

; basic sanity checking of plugins
041ca6b6   Annie Hughes   updated help
167
; to be written
a4c9699a   Annie Hughes   first commit
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

;== INITIALIZE DUST MODEL PARAMETERS and PLUGIN FREE PARAMETERS
dustem_init_parinfo,pd,iv,up_limited=ulimed,lo_limited=llimed,up_limits=ulims,lo_limits=llims,fixed=fixed,tied=tied

;== INITIALIZE ANY PLUGINS
dustem_init_plugins,pd,fpd=fpd 

;== INITIALIZE ANY FIXED PARAMETERS FOR DUST MODOEL AND PLUGINS
if keyword_set(fpd) then dustem_init_fixed_params,fpd,fiv

message,'Finished initializing free and fixed parameters of dust model and plugins',/info


the_end:

END