diff --git a/src/idl/dustem_define_grid_v1.pro b/src/idl/dustem_define_grid_v1.pro new file mode 100644 index 0000000..cf31652 --- /dev/null +++ b/src/idl/dustem_define_grid_v1.pro @@ -0,0 +1,202 @@ +PRO dustem_define_grid_v1,table_name $ + ,filters=filters $ + ,help=help $ + ,table_params=table_params $ + ,table_pmins=table_pmins $ + ,table_pmaxs=table_pmaxs $ + ,table_pnvals=table_pnvals $ + ,table_plogs=table_plogs + +;+ +; NAME: +; dustem_define_grid_v1 +; PURPOSE: +; loads an SED Grid table into !dustem_grid. This is for initial versions of grid tables. Used to convert them to new convention. +; CATEGORY: +; Dustem +; CALLING SEQUENCE: +; dustem_define_grid,table_name,filters[,table_params=][,table_pmins=][,table_pmaxs=][,table_pnvals=][,table_plogs=] +; INPUTS: +; table_name : fits file name containing the grid +; filters : name of dustemwrap filters to be included in the GRID +; OPTIONAL INPUT PARAMETERS: +; NONE +; OUTPUTS: +; None +; OPTIONAL OUTPUT PARAMETERS: +; table_params= parameter names in the grid table +; table_pmins= parameter min values in the grid table +; table_pmaxs= parameter max values in the grid table +; table_pnvals= parameter number of values in the grid table +; table_plogs= 1=parameter values in log in the grid table, 0=linear +; ACCEPTED KEY-WORDS: +; help = If set, print this help +; COMMON BLOCKS: +; None +; SIDE EFFECTS: +; !dustem_grid is updated +; RESTRICTIONS: +; The DustEM fortran code must be installed +; The DustEMWrap IDL code must be installed +; PROCEDURE: +; None +; EXAMPLES +; dustem_make_sed_table,'DBP90',['(*!dustem_params).G0','(*!dustem_params).grains(0).mdust_o_mh'], $ +; [0.1,1.e-3],[100.,1.e-1],[10,3],filename='/tmp/IRAS_GO.fits',log=[1,0],/show_seds, $ +; filters=[dustem_instru2filters('IRAC'),dustem_instru2filters('SPIRE')] +; dustem_define_grid,/tmp/IRAS_GO.fits',['IRAC3','SPIRE2'] +; help,!dustem_grid +; MODIFICATION HISTORY: +; Written by J.-Ph. Bernard (2023) +; 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_define_grid_v1' + goto,the_end +ENDIF + +;=== read the grid table +message,'reading grid data from '+table_name,/continue +;stop +info=file_info(table_name) +IF info.exists THEN BEGIN + st=mrdfits(table_name,1,h) +ENDIF ELSE BEGIN + message,'grid data '+table_name+' not found',/continue + stop +ENDELSE + +;stop +;=== get filters and params names from grid table header +i=0L +table_filters=[''] +fname='bidon' +count=1 +WHILE count NE 0 DO BEGIN + fname=sxpar(h,'FNAME'+strtrim(i+1,2),count=count) + IF count NE 0 THEN table_filters=[table_filters,strtrim(fname,2)] + i=i+1 +ENDWHILE +table_filters=table_filters[1:*] +Ntfilters=n_elements(table_filters) + +table_params=[''] +table_pmins=[0.d0] +table_pmaxs=[0.d0] +table_pnvals=[0L] +table_plogs=[0] +count=1 +i=0L +WHILE count NE 0 DO BEGIN + pname=sxpar(h,'PNAME'+strtrim(i+1,2),count=count) + IF count NE 0 THEN BEGIN + table_params=[table_params,strtrim(pname,2)] + pmin=sxpar(h,'PMIN'+strtrim(i+1,2),count=count) + pmax=sxpar(h,'PMAX'+strtrim(i+1,2),count=count) + pnval=sxpar(h,'PNVAL'+strtrim(i+1,2),count=count) + plog=sxpar(h,'PLOG'+strtrim(i+1,2),count=count) + table_pmins=[table_pmins,pmin] + table_pmaxs=[table_pmaxs,pmax] + table_pnvals=[table_pnvals,pnval] + table_plogs=[table_plogs,plog] + ENDIF + i=i+1 +ENDWHILE +table_params=table_params[1:*] +table_pmins=table_pmins[1:*] +table_pmaxs=table_pmaxs[1:*] +table_pnvals=table_pnvals[1:*] +table_plogs=table_plogs[1:*] +Ntparams=n_elements(table_params) + +;=== select only requested filters +;stop +use_filters=table_filters ;default is to keep all filters +IF keyword_set(filters) THEN use_filters=filters + +Nfilters=n_elements(use_filters) +keep_tfilters=intarr(Ntfilters) +tags=tag_names(st) +FOR i=0L,Nfilters-1 DO BEGIN + ind=where(table_filters EQ use_filters[i],count) + IF count NE 0 THEN keep_tfilters[ind]=1 +ENDFOR + +;stop + +;totals=st.total +FOR i=0L,Ntfilters-1 DO BEGIN + IF keep_tfilters[i] EQ 0 THEN BEGIN + col_name=tags[i+Ntparams] + st=structure_remove_column(st,col_name) + ENDIF +ENDFOR + +;separate structure into parameters and seds +st_seds=st +tags=tag_names(st) +FOR i=0L,Ntparams-1 DO BEGIN + col_name=tags[i] + st_seds=structure_remove_column(st_seds,col_name) +ENDFOR +;stop +st_seds=structure_remove_column(st_seds,'TOTAL') +st_params=st +FOR i=0L,Nfilters-1 DO BEGIN + col_name=tags[i+Ntparams] + st_params=structure_remove_column(st_params,col_name) +ENDFOR +st_params=structure_remove_column(st_params,'TOTAL') +sed_totals=st.(Nfilters+Ntparams-1) + +;stop + +;==== recompute totals +Nsed=n_elements(st) +;==== recompute totals (needed if some columns have been removed) +FOR i=0L,Nsed-1 DO BEGIN + this_total=0.d0 + FOR j=0L,Nfilters-1 DO BEGIN + ;this_total=this_total+(st[i]).(j+Ntparams) + this_total=this_total+st_seds[i].(j) + ENDFOR + ;st[i].total=this_total + sed_totals[i]=this_total +ENDFOR + +;stop + +dustem_grid={Nsed:Nsed $ ; + ,Nfilters:Nfilters $ ; + ,Nparams:Ntparams $ ; + ,filters:use_filters $ ; + ,params:table_params $; + ,st_seds:st_seds $ ; + ,st_params:st_params $ ; + ,sed_totals:sed_totals $ ; +; ,seds:st $ ;meant to disapear + ,pmin_values:table_pmins $ ; + ,pmax_values:table_pmaxs $ ; + } + +defsysv,'!dustem_grid',ptr_new(dustem_grid) +message,'Defined !dustem_grid',/continue + +;help,!dustem_grid +;** Structure <9b80dc08>, 10 tags, length=3760784, data length=3760780, refs=2: +; NSED LONG 20000 +; NFILTERS LONG 42 +; NPARAMS LONG 3 +; FILTERS STRING Array[42] +; PARAMS STRING Array[3] +; ST_SEDS STRUCT -> Array[20000] +; ST_PARAMS STRUCT -> Array[20000] +; SED_TOTALS DOUBLE Array[20000] +; PMIN_VALUES DOUBLE Array[3] +; PMAX_VALUES DOUBLE Array[3] + +the_end: + +END \ No newline at end of file -- libgit2 0.21.2