dustem_set_data.pro 6.19 KB
FUNCTION dustem_set_data,help=help,sed=sed,ext=ext,fpol=fpol,rchi2_weight=rchi2_weight,f_HI=f_HI

;+
; NAME:
;    dustem_set_data
; PURPOSE:
;    Initializes the dustem data structure (!dustem_data)
; CATEGORY:
;    Dustem
; CALLING SEQUENCE:
;    dustem_set_data,spec[,help=]
; INPUTS:
;    spec: array of structures containing a SED
; OPTIONAL INPUT PARAMETERS:
;    None
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help      = If set print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    initializes !dustem_data
;    wavelengths are forced to be the central filter wavelength for
;    photometric data
; RESTRICTIONS:
;    The dustem idl wrapper must be installed
; PROCEDURE:
;    None
; EXAMPLES
;    dustem_init
;    dir=getenv('DUSTEM_SOFT_DIR')+'/src/dustem3.8_web/SEDs/'
;    file=dir+'Gal_composite_spectrum.xcat'
;    spec=read_xcat(file,/silent)
;    dustem_set_data,spec
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard
;    see evolution details on the dustem cvs maintained at CESR
;    Contact J.-Ph. Bernard (Jean-Philippe.Bernard@cesr.fr) in case of problems.
; 
;    V. Guillet (2012) : dustem_set_data is turned into a function which can be used 
;                        indifferently for sed, ext, polext
;    I. Choubani (2022): Adjusting the function to meet the format criteria set by the current release. 
;    The function uses two main input structures: SED and EXT. Polarization data is included within each. 
;-


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

;Cleaninig data structure
!dustem_data.sed = ptr_new()
!dustem_data.ext = ptr_new()


;SETTING THE DATA STRUCTURES FOR THE FITTING PROCESS - SED

IF keyword_set(sed) THEN BEGIN    
    
    
    ;maybe to activate fpol here you need to set it to one? CHECK THIS OUT.           
    if keyword_set(fpol) then xx=dustem_check_data(sed=sed,ist=ist,pst=pst,fpol=fpol,fpst=fpst,qst=qst,ust=ust) else xx=dustem_check_data(sed=sed,ist=ist,pst=pst,fpst=fpst,qst=qst,ust=ust)          
    ;stop
    ;=== fill !dustem_data
    IF isa(ist) THEN !dustem_data.sed = ptr_new(ist) ;ELSE !dustem_data.sed = ptr_new()   
    ; If f_HI is specified, multiply the data by f_HI
    If keyword_set(f_HI) and ptr_valid(!dustem_data.sed) then begin
        if f_HI gt 0 then (*!dustem_data.sed).values *= f_HI else f_HI = 1.
    endif else f_HI = 1.
    defsysv,'!dustem_f_HI',f_HI
    if !run_pol then begin
        If isa(pst) then BEGIN        
            ;=== fill !dustem_data
            !dustem_data.polsed = ptr_new(pst)
            ; If f_HI is specified, multiply the data by f_HI
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.polsed).values *= f_HI
        ENDIF
        If isa(fpst) then BEGIN        
            ;=== fill !dustem_data
            !dustem_data.polfrac = ptr_new(fpst)
            ; If f_HI is specified, multiply the data by f_HI
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.polfrac).values *= f_HI
        ENDIF
        IF isa(qst) THEN BEGIN        
            ;=== fill !dustem_data
            !dustem_data.qsed = ptr_new(qst)
            ; If f_HI is specified, multiply the data by f_HI
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.qsed).values *= f_HI
        ENDIF    
        if isa(ust) then BEGIN
            ;=== fill !dustem_data
            !dustem_data.used = ptr_new(ust)
            ; If f_HI is specified, multiply the data by f_HI
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.used).values *= f_HI
        ENDIF
    endif
ENDIF

;SETTING THE DATA STRUCTURES FOR THE FITTING PROCESS - EXT

IF keyword_set(ext) THEN BEGIN
    xx=dustem_check_data(ext=ext,exst=exst,pexst=pexst,qexst=qexst,uexst=uexst)
    ;=== fill !dustem_data
    IF isa(exst) THEN !dustem_data.ext = ptr_new(exst) ;ELSE !dustem_data.ext = ptr_new() 
    
    ; If f_HI is specified, multiply the data by f_HI
    if keyword_set(f_HI) and ptr_valid(!dustem_data.ext) then begin
        if f_HI gt 0 then (*!dustem_data.ext).values *= f_HI else f_HI = 1.
    endif else f_HI = 1.
    defsysv,'!dustem_f_HI',f_HI        
    
    if !run_pol then begin
        if isa(pexst) then BEGIN        
            !dustem_data.polext = ptr_new(pexst)
            ; If f_HI is specified, multiply the data by f_HI
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.polext).values *= f_HI
        ENDIF
        IF isa(qexst) THEN BEGIN        
            ;=== fill !dustem_data
            !dustem_data.qext = ptr_new(qexst)
            ; If f_HI is specified, multiply the data by f_HI
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.qext).values *= f_HI
        ENDIF
        if isa(uexst) then BEGIN 
            ;=== fill !dustem_data
            !dustem_data.uext = ptr_new(uexst)
            ; If f_HI is specified, multiply the data by f_HI
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.uext).values *= f_HI
        ENDIF
    endif
ENDIF

!fit_rchi2_weight.sed=1.
!fit_rchi2_weight.ext=1.

If !run_pol THEN BEGIN
    ;SED
    IF isa(pst) THEN !fit_rchi2_weight.polsed=1.
    IF isa(fpst) THEN !fit_rchi2_weight.polfrac=1.
    IF isa(qst) THEN !fit_rchi2_weight.qsed=1.
    IF isa(ust) THEN !fit_rchi2_weight.used=1.
    
    ;EXT
    IF isa(pexst) THEN !fit_rchi2_weight.polext=1.
    IF isa(qexst) THEN !fit_rchi2_weight.qext=1.
    IF isa(uexst) THEN !fit_rchi2_weight.uext=1.
ENDIF


IF keyword_set(rchi2_weight) THEN BEGIN
	!fit_rchi2_weight.sed     = rchi2_weight.sed
	!fit_rchi2_weight.ext     = rchi2_weight.ext
	
	IF !run_pol THEN BEGIN
    	IF isa(pst) THEN !fit_rchi2_weight.polsed  = rchi2_weight.polsed
    	IF isa(fpst) THEN !fit_rchi2_weight.polfrac = rchi2_weight.polfrac
    	IF isa(qst) THEN !fit_rchi2_weight.qsed  = rchi2_weight.qsed
    	IF isa(ust) THEN !fit_rchi2_weight.used  = rchi2_weight.used
    	
    	IF isa(pexst) THEN !fit_rchi2_weight.polext  = rchi2_weight.polext
    	IF isa(qexst) THEN !fit_rchi2_weight.qext  = rchi2_weight.qext
    	IF isa(uexst) THEN !fit_rchi2_weight.uext  = rchi2_weight.uext
    ENDIF
    
ENDIF

return,ptr_new(obs_st)


the_end:

END