dustem_set_func_ind.pro 3.92 KB
PRO dustem_set_func_ind,pd,iv

;REM: iv not necessary when ionfrac/isrf not there
;This program used to be called dustem_sort_params

;+
; NAME:
;       dustem_set_func_ind
; CALLING SEQUENCE:
;       dustem_set_func_ind
; PURPOSE:
;	Sorts the parameter descriptions and values the way they must
;	be processed.
; INPUTS:
;       None
; OPTIONAL INPUT:
;       None
; OUTPUTS:
;       None
; PROCEDURE AND SUBROUTINE USED
;       Parameter description (!param_desc) and values (!init_value) are
;       ordered the way they should be processed. The ordered information
;       is put into system variables !PDO and !IDO respectively
;       If the isrf is being modified, then, PAH ionization fraction
;       is set to be updated as well.
; SIDE EFFECTS:
;       !PDO and !IDO variables are set.
;       Optionally !ionfrac is set.
;       The !func_ind variable is set.
; MODIFICATION HISTORY:
;       See cvs logs
;       Written by NF,JPB,DP Jan-2007
;-

nparam = n_elements(*(*!dustem_fit).param_descs)
;!func_ind=ptr_new(fltarr(nparam))

;SORT THE PARAMETERS
;ord = sort(*(*!dustem_fit).param_descs)
;!PDO = ptr_new((*(*!dustem_fit).param_descs)(ord))     ;param_desc ordered (PDO)
;!IDO = ptr_new((*(*!dustem_fit).param_init_values)(ord))     ;init_desc ordered (IDO)
;Do NOT order the parameters
;PDO = ptr_new((*(*!dustem_fit).param_descs))     ;param_desc ordered (PDO)
;IDO = ptr_new((*(*!dustem_fit).param_init_values))     ;init_desc ordered (IDO)
PDO = ptr_new(pd)     ;param_desc ordered (PDO)
IDO = ptr_new(iv)     ;init_desc ordered (IDO)

;==== DEAL WITH THE ISRF<->IONFRAC DEPENDENCY
fct = strarr(nparam)
FOR i=0L,nparam-1 DO BEGIN
   fct[i] = strmid((*PDO)(i),0,strlen((*PDO)(i))-2.)
ENDFOR
wisrf = where(fct eq 'dustem_create_isrf' or fct eq 'dustem_create_isrf2',cisrf) ;DUSTEM_CREATE_ISRF is being called as a param ?
IF cisrf NE 0 THEN BEGIN
   wionf = where(fct EQ 'dustem_create_ionfrac',cionf) ; DUSTEM_CREATE_IONFRAC is being called as a param ?
; ISRF(yes), IONFRAC(no) => then everything is set by the IONFRACPAH in GRAIN.DAT
; ISRF(yes), IONFRAC(yes) => make sure DUSTEM_CREATE_IONFRAC is called after DUSTEM_CREATE_ISRF
   IF cionf NE 0 THEN BEGIN
      IF (wisrf(cisrf-1)) NE (nparam-1) THEN BEGIN ;ISRF was not the last in the list
         (*PDO) = [(*PDO)(0:wionf(0)-1), (*PDO)(wisrf(0):wisrf(cisrf-1)), (*PDO)(wionf(0):wionf(cionf-1)), (*PDO)(wisrf(cisrf-1)+1:*)]
         (*IDO) = [(*IDO)(0:wionf(0)-1), (*IDO)(wisrf(0):wisrf(cisrf-1)), (*IDO)(wionf(0):wionf(cionf-1)), (*IDO)(wisrf(cisrf-1)+1:*)]
      ENDIF ELSE BEGIN          ;ISRF was the last in the list
         (*PDO) = [(*PDO)(0:wionf(0)-1), (*PDO)(wisrf(0):wisrf(cisrf-1)), (*PDO)(wionf(0):wionf(cionf-1))]
         (*IDO) = [(*IDO)(0:wionf(0)-1), (*IDO)(wisrf(0):wisrf(cisrf-1)), (*IDO)(wionf(0):wionf(cionf-1))]
      ENDELSE
   ENDIF
ENDIF

;=== added by JPB on June 1st 2021 to set !dustem_idl_continuum when needed
ind=where(fct EQ 'dustem_create_continuum',count)
IF count NE 0 THEN !dustem_idl_continuum=1
ind=where(fct EQ 'dustem_create_freefree',count)
IF count NE 0 THEN !dustem_idl_freefree=1
ind=where(fct EQ 'dustem_create_synchrotron',count)
IF count NE 0 THEN !dustem_idl_synchrotron=1
;stop

;=== SET !FUNC_IND VALUES
; !FUNC_IND = 0 for the DUSTEM_PARAMS
; !FUNC_IND = 1 for the first DUSTEM_CREATE function, !FUNC_IND = 2
; for the second DUSTEM_CREATE function ...
(*!dustem_fit).param_func=ptr_new(replicate(0.,nparam))
ind = 1.
fct_prev = ''
FOR i=0L,nparam-1 DO BEGIN
;stop
;This was the definition of a dustem function before fit by grey body
;made possible
;  IF (strmid((*PDO)(i),0,3) NE '(*!') THEN BEGIN
;This is the new definition of a function
  IF (strmid((*PDO)[i],0,7) EQ 'dustem_') THEN BEGIN
    fct = strmid((*PDO)[i],14,strlen((*PDO)[i])-16)
    IF (fct EQ fct_prev) THEN BEGIN
      (*(*!dustem_fit).param_func)[i]=(*(*!dustem_fit).param_func)[i-1]
    ENDIF ELSE BEGIN
      (*(*!dustem_fit).param_func)[i]=ind
      ind=ind+1
    ENDELSE
    fct_prev=fct
  ENDIF
ENDFOR

END