aboutsummaryrefslogtreecommitdiffstats
path: root/bin/calc_coolfunc.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/calc_coolfunc.sh')
-rwxr-xr-xbin/calc_coolfunc.sh113
1 files changed, 113 insertions, 0 deletions
diff --git a/bin/calc_coolfunc.sh b/bin/calc_coolfunc.sh
new file mode 100755
index 0000000..d1d0b35
--- /dev/null
+++ b/bin/calc_coolfunc.sh
@@ -0,0 +1,113 @@
+#!/bin/sh
+##
+## Calculate the 'cooling function' profile with respect to the
+## given 'temperature profile' and the average abundance, redshift,
+## and column density nH, using the XSPEC model 'wabs*apec'.
+##
+## NOTE:
+## The output cooling function values should be the 'flux' values
+## with unit 'photon/s/cm^2' (different to 'calc_coolfunc_bands.sh').
+## These results will be used by 'fit_{beta,dbeta}_sbp' to derive the
+## (3D) gas density profile from (2D) surface brightness profile,
+## whose values have unit 'photon/cm^2/pixel/s'.
+##
+## Weitian LI
+## Created: 2012-08-17
+##
+## Change logs:
+## 2017-02-17, Weitian LI
+## * Rename from 'coolfunc_calc.sh' to 'calc_coolfunc.sh'
+## * Clean up that do not calculate and output <coolfunc_bolo>
+## 2017-02-16, Weitian LI
+## * Do not calculate and output 'flux_cnt_ratio.txt'
+##
+
+## cmdline arguments {{{
+if [ $# -ne 5 ]; then
+ printf "usage:\n"
+ printf " `basename $0` <tprofile> <avg_abund> <nH> <redshift> <coolfunc_outfile>\n"
+ exit 1
+fi
+TPROFILE=$1
+ABUNDANCE=$2
+N_H=$3
+REDSHIFT=$4
+COOLFUNC_DAT=$5
+NORM=`cosmo_calc ${REDSHIFT} | grep 'norm.*cooling_function' | awk -F':' '{ print $2 }'`
+
+if [ ! -r "${TPROFILE}" ]; then
+ printf "ERROR: given tprofile '${TPROFILE}' NOT accessiable\n"
+ exit 2
+fi
+[ -e "${COOLFUNC_DAT}" ] && rm -f ${COOLFUNC_DAT}
+## arguments }}}
+
+XSPEC_CF_XCM="_calc_coolfunc.xcm"
+[ -e "${XSPEC_CF_XCM}" ] && rm -f ${XSPEC_CF_XCM}
+
+## generate xspec script {{{
+cat > ${XSPEC_CF_XCM} << _EOF_
+## XSPEC Tcl script
+## Calculate the cooling function profile w.r.t the temperature profile.
+##
+## Generated by: `basename $0`
+## Date: `date`
+
+set xs_return_results 1
+set xs_echo_script 0
+# set tcl_precision 12
+## set basic data {{{
+set nh ${N_H}
+set redshift ${REDSHIFT}
+set abundance ${ABUNDANCE}
+set norm ${NORM}
+## basic }}}
+
+## xspec related {{{
+# debug settings {{{
+chatter 0
+# debug }}}
+query yes
+abund grsa
+dummyrsp 0.01 100.0 4096 linear
+# load model 'wabs*apec' to calc cooling function
+model wabs*apec & \${nh} & 1.0 & \${abundance} & \${redshift} & \${norm} & /*
+## xspec }}}
+
+## set input and output filename & open files
+set tpro_fn "${TPROFILE}"
+set cf_fn "${COOLFUNC_DAT}"
+if { [ file exists \${cf_fn} ] } {
+ exec rm -fv \${cf_fn}
+}
+
+## open files
+set tpro_fd [ open \${tpro_fn} r ]
+set cf_fd [ open \${cf_fn} w ]
+
+## read data from tprofile line by line
+while { [ gets \${tpro_fd} tpro_line ] != -1 } {
+ scan \${tpro_line} "%f %f" radius temperature
+ #puts "radius: \${radius}, temperature: \${temperature}"
+ # set temperature value
+ newpar 2 \${temperature}
+ # calc flux & tclout
+ flux 0.7 7.0
+ tclout flux 1
+ scan \${xspec_tclout} "%f %f %f %f" _ _ _ cf_photon
+ #puts "cf: \${cf_photon}"
+ puts \${cf_fd} "\${radius} \${cf_photon}"
+}
+
+## close opened files
+close \${tpro_fd}
+close \${cf_fd}
+
+## exit
+tclexit
+_EOF_
+## xcm generation }}}
+
+## invoke xspec to calc
+printf "invoking XSPEC to calculate cooling function profile ...\n"
+xspec - ${XSPEC_CF_XCM} > /dev/null