1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
#!/bin/sh
##
unalias -a
export LC_COLLATE=C
# fix path for python
export PATH=/usr/bin:/usr/local/bin:$PATH
#########################################################################
## Collect the calculated mass data and write to the JSON file.
##
## Weitian LI <liweitianux@gmail.com>
## August 31, 2012
##
## ChangeLogs:
## check JSON syntax, modify output to agree with the syntax
## Ref: http://json.parser.online.fr/
## v1.1, 2012/09/05, Weitian LI
## add `T_avg(0.2-0.5 R500)' and `T_err'
## v2.0, 2012/10/14, Weitian LI
## add parameters
## v2.1, 2012/11/07, Weitian LI
## account for `fitting_dbeta'
## v2.2, 2012/12/18, Weitian LI
## add `beta' and `cooling time' parameters
## v3.0, 2013/02/09, Weitian LI
## modified for `new sample info format'
## v3.1, 2013/05/18, Weitian LI
## add key `Feature'
## v3.2, 2013/05/29, Weitian LI
## add key `XCNTRD_RA, XCNTRD_DEC'
## v3.3, 2013/10/14, Weitian LI
## add key `Unified Name'
## v3.4, 2015/06/03, Aaron LI
## * Copy needed pfiles to current working directory, and
## set environment variable $PFILES to use these first.
## * Replaced 'grep' with '\grep', 'ls' with '\ls'
##
VERSION="v3.4"
UPDATED="2015/06/03"
## error code {{{
ERR_USG=1
ERR_DIR=11
ERR_CFG=12
ERR_RES=13
ERR_COSC=14
ERR_BETA=101
ERR_BETA2=102
ERR_JSON=201
ERR_MLOG=202
ERR_BLOG=203
ERR_CLOG=204
## error code }}}
## usage, help {{{
case "$1" in
-[hH]*|--[hH]*)
printf "usage:\n"
printf " `basename $0` json=<info_json> cfg=<main_cfg> res=<final_result> basedir=<repro_dir> massdir=<mass_dir>\n"
printf "\nversion:\n"
printf "${VERSION}, ${UPDATED}\n"
exit ${ERR_USG}
;;
esac
## usage, help }}}
## default parameters {{{
# default basedir
DFT_BASEDIR=".."
# default mass dir
DFT_MASSDIR="mass"
# default pattern for json info file
DFT_JSON_PAT="*_INFO.json"
# main config file
DFT_CFG_PAT="global.cfg"
# default result file
DFT_RES_FINAL_PAT="final_result.txt"
# default sbprofile region file
DFT_SBPROFILE_REG="sbprofile.reg"
# default radial spectra region file
DFT_RSPEC_REG="rspec.reg"
# default CMD to determine the `spc/profile' dir
DFT_SPC_DIR_CMD='dirname `readlink ${T_DATA_FILE}`'
# default CMD to determine the `img' dir
DFT_IMG_DIR_CMD='dirname `readlink ${RADIUS_SBP_FILE}`'
# default config file pattern for `expcorr'
DFT_EXPCORR_CONF_PAT="*_expcorr.conf"
## default parameters }}}
## functions {{{
# process commandline arguments
# cmdline arg format: `KEY=VALUE'
getopt_keyval() {
until [ -z "$1" ]
do
key=${1%%=*} # extract key
val=${1#*=} # extract value
keyval="${key}=\"${val}\""
echo "## getopt: eval '${keyval}'"
eval ${keyval}
shift # shift, process next one
done
}
## functions }}}
## parameters {{{
# process cmdline args using `getopt_keyval'
getopt_keyval "$@"
# init directory
INIT_DIR=`pwd -P`
# check given parameters
# check given dir
if [ -d "${basedir}" ] && \ls ${basedir}/*repro_evt2.fits > /dev/null 2>&1; then
BASEDIR=${basedir}
elif [ -d "${DFT_BASEDIR}" ] && \ls ${DFT_BASEDIR}/*repro_evt2.fits > /dev/null 2>&1; then
BASEDIR=${DFT_BASEDIR}
else
read -p "> basedir (contains info json): " BASEDIR
if [ ! -d "${BASEDIR}" ]; then
printf "ERROR: given \`${BASEDIR}' NOT a directory\n"
exit ${ERR_DIR}
elif ! \ls ${BASEDIR}/*repro_evt2.fits > /dev/null 2>&1; then
printf "ERROR: given \`${BASEDIR}' NOT contains needed evt files\n"
exit ${ERR_DIR}
fi
fi
# remove the trailing '/'
BASEDIR=`( cd ${INIT_DIR}/${BASEDIR} && pwd -P )`
printf "## use basedir: \`${BASEDIR}'\n"
# mass dir
if [ ! -z "${massdir}" ] && [ -d "${BASEDIR}/${massdir}" ]; then
MASS_DIR=`( cd ${BASEDIR}/${massdir} && pwd -P )`
elif [ -d "${BASEDIR}/${DFT_MASSDIR}" ]; then
MASS_DIR=`( cd ${BASEDIR}/${DFT_MASSDIR} && pwd -P )`
else
read -p "> mass dir (relative to basedir): " MASS_DIR
if [ ! -d "${BASEDIR}/${MASS_DIR}" ]; then
printf "ERROR: given \`${BASEDIR}/${MASS_DIR}' NOT a directory\n"
exit ${ERR_DIR}
fi
fi
# remove the trailing '/'
MASS_DIR=`echo ${MASS_DIR} | sed 's/\/*$//'`
printf "## use massdir: \`${MASS_DIR}'\n"
# check json file
if [ ! -z "${json}" ] && [ -r "${BASEDIR}/${json}" ]; then
JSON_FILE="${json}"
elif [ "`\ls ${BASEDIR}/${DFT_JSON_PAT} | wc -l`" -eq 1 ]; then
JSON_FILE=`( cd ${BASEDIR} && \ls ${DFT_JSON_PAT} )`
else
read -p "> info json file: " JSON_FILE
if ! [ -r "${BASEDIR}/${JSON_FILE}" ]; then
printf "ERROR: cannot access given \`${BASEDIR}/${INFO_JSON}' file\n"
exit ${ERR_JSON}
fi
fi
printf "## use info json file: \`${JSON_FILE}'\n"
# check main config file
if [ ! -z "${cfg}" ] && [ -r "${cfg}" ]; then
CFG_FILE="${cfg}"
elif [ -r "${DFT_CFG_PAT}" ]; then
CFG_FILE="${DFT_CFG_PAT}"
else
read -p "> main config file: " CFG_FILE
if [ ! -r "${CFG_FILE}" ]; then
printf "ERROR: cannot access given \`${CFG_JSON}' file\n"
exit ${ERR_CFG}
fi
fi
printf "## use main config file: \`${CFG_FILE}'\n"
SBP_CFG=`\grep '^sbp_cfg' ${CFG_FILE} | awk '{ print $2 }'`
printf "## sbp config file: \`${SBP_CFG}'\n"
# check final result file
if [ ! -z "${res}" ] && [ -r "${res}" ]; then
RES_FINAL="${res}"
elif [ -r "${DFT_RES_FINAL_PAT}" ]; then
RES_FINAL="${DFT_RES_FINAL_PAT}"
else
read -p "> final result file: " RES_FINAL
if [ ! -r "${RES_FINAL}" ]; then
printf "ERROR: cannot access given \`${RES_FINAL}' file\n"
exit ${ERR_RES}
fi
fi
printf "## use final result file: \`${RES_FINAL}'\n"
## parameters }}}
## directory & file {{{
BASE_PATH=`dirname $0`
printf "## BASE_PATH: ${BASE_PATH}\n"
COSMO_CALC="${BASE_PATH}/cosmo_calc"
if [ ! -x "${COSMO_CALC}" ]; then
printf "*** ERROR: \`${COSMO_CALC}' not executable\n"
exit ${ERR_COSC}
fi
EVT_DIR="${BASEDIR}/evt"
IMG_DIR="${BASEDIR}/img"
SPEC_DIR="${BASEDIR}/spc/profile"
## dir & file }}}
## prepare parameter files (pfiles) {{{
CIAO_TOOLS="dmkeypar"
# Copy necessary pfiles for localized usage
for tool in ${CIAO_TOOLS}; do
pfile=`paccess ${tool}`
[ -n "${pfile}" ] && punlearn ${tool} && cp -Lvf ${pfile} .
done
# Modify environment variable 'PFILES' to use local pfiles first
export PFILES="./:${PFILES}"
## pfiles }}}
cd ${BASEDIR}
printf "## enter directory: `pwd -P`\n"
## in dir `repro' {{{
punlearn dmkeypar
EVT_RAW=`\ls *repro_evt2.fits`
OBS_ID=`dmkeypar ${EVT_RAW} OBS_ID echo=yes`
DATE_OBS=`dmkeypar ${EVT_RAW} DATE-OBS echo=yes`
EXPOSURE_RAW=`dmkeypar ${EVT_RAW} EXPOSURE echo=yes | awk '{ print $1/1000 }'`
## ACIS_TYPE
DETNAM=`dmkeypar ${EVT_RAW} DETNAM echo=yes`
if echo ${DETNAM} | \grep -q 'ACIS-0123'; then
ACIS_TYPE="ACIS-I"
elif echo ${DETNAM} | \grep -q 'ACIS-[0-6]*7'; then
ACIS_TYPE="ACIS-S"
else
printf "*** ERROR: unknown detector type: ${DETNAM}\n"
ACIS_TYPE="UNKNOWN"
fi
## dir `repro' }}}
## in dir `repro/evt' {{{
cd ${EVT_DIR}
EVT_CLEAN=`\ls evt2_c*_clean.fits`
EXPOSURE_CLEAN=`dmkeypar ${EVT_CLEAN} EXPOSURE echo=yes | awk '{ print $1/1000 }'`
## dir `repro/evt' }}}
## in dir `repro/mass' {{{
cd ${MASS_DIR}
# misc {{{
N_H=`\grep '^nh' ${CFG_FILE} | awk '{ print $2 }'`
Z=`\grep '^z' ${SBP_CFG} | awk '{ print $2 }'`
T_DATA_FILE=`\grep '^t_data_file' ${CFG_FILE} | awk '{ print $2 }'`
NFW_RMIN_KPC=`\grep '^nfw_rmin_kpc' ${CFG_FILE} | awk '{ print $2 }'`
E_Z=`${COSMO_CALC} ${Z} | \grep -i 'Hubble_parameter' | awk '{ print $3 }'`
KPC_PER_PIXEL=`${COSMO_CALC} ${Z} | \grep 'kpc/pixel' | awk '{ print $3 }'`
RADIUS_SBP_FILE=`\grep '^radius_sbp_file' ${CFG_FILE} | awk '{ print $2 }'`
RMAX_SBP_PIX=`tail -n 1 ${RADIUS_SBP_FILE} | awk '{ print $1+$2 }'`
RMAX_SBP_KPC=`echo "${RMAX_SBP_PIX} ${KPC_PER_PIXEL}" | awk '{ printf("%.2f", $1*$2) }'`
SPC_DIR=`eval ${DFT_SPC_DIR_CMD}`
if [ -f "${SPC_DIR}/${DFT_RSPEC_REG}" ]; then
RMAX_TPRO_PIX=`\grep -iE '(pie|annulus)' ${SPC_DIR}/${DFT_RSPEC_REG} | tail -n 1 | awk -F',' '{ print $4 }'`
RMAX_TPRO_KPC=`echo "${RMAX_TPRO_PIX} ${KPC_PER_PIXEL}" | awk '{ printf("%.2f", $1*$2) }'`
fi
IMG_DIR=`eval ${DFT_IMG_DIR_CMD}`
EXPCORR_CONF=`\ls ${IMG_DIR}/${DFT_EXPCORR_CONF_PAT} 2> /dev/null`
echo "EXPCORR_CONF: ${EXPCORR_CONF}"
if [ -f "${EXPCORR_CONF}" ]; then
T_REF=`\grep '^temp' ${EXPCORR_CONF} | awk '{ print $2 }'`
Z_REF=`\grep '^abund' ${EXPCORR_CONF} | awk '{ print $2 }'`
fi
[ -z "${NFW_RMIN_KPC}" ] && NFW_RMIN_KPC="null"
[ -z "${RMAX_SBP_PIX}" ] && RMAX_SBP_PIX="null"
[ -z "${RMAX_SBP_KPC}" ] && RMAX_SBP_KPC="null"
[ -z "${T_REF}" ] && T_REF="null"
[ -z "${Z_REF}" ] && Z_REF="null"
# misc }}}
## determine single/double beta {{{
if \grep -q '^beta2' ${SBP_CFG}; then
MODEL_SBP="double-beta"
n01=`\grep '^n01' ${RES_FINAL} | awk '{ print $2 }'`
beta1=`\grep '^beta1' ${RES_FINAL} | awk '{ print $2 }'`
rc1=`\grep -E '^rc1\s' ${RES_FINAL} | awk '{ print $2 }'`
rc1_kpc=`\grep '^rc1_kpc' ${RES_FINAL} | awk '{ print $2 }'`
n02=`\grep '^n02' ${RES_FINAL} | awk '{ print $2 }'`
beta2=`\grep '^beta2' ${RES_FINAL} | awk '{ print $2 }'`
rc2=`\grep -E '^rc2\s' ${RES_FINAL} | awk '{ print $2 }'`
rc2_kpc=`\grep '^rc2_kpc' ${RES_FINAL} | awk '{ print $2 }'`
BKG=`\grep '^bkg' ${RES_FINAL} | awk '{ print $2 }'`
# beta1 -> smaller rc; beta2 -> bigger rc
if [ `echo "${rc1} < ${rc2}" | bc -l` -eq 1 ]; then
N01=${n01}
BETA1=${beta1}
RC1=${rc1}
RC1_KPC=${rc1_kpc}
N02=${n02}
BETA2=${beta2}
RC2=${rc2}
RC2_KPC=${rc2_kpc}
else
# beta1 <-> beta2 (swap)
N01=${n02}
BETA1=${beta2}
RC1=${rc2}
RC1_KPC=${rc2_kpc}
N02=${n01}
BETA2=${beta1}
RC2=${rc1}
RC2_KPC=${rc1_kpc}
fi
else
MODEL_SBP="single-beta"
N01="null"
BETA1="null"
RC1="null"
RC1_KPC="null"
N02=`\grep '^n0' ${RES_FINAL} | awk '{ print $2 }'`
BETA2=`\grep '^beta' ${RES_FINAL} | awk '{ print $2 }'`
RC2=`\grep -E '^rc\s' ${RES_FINAL} | awk '{ print $2 }'`
RC2_KPC=`\grep '^rc_kpc' ${RES_FINAL} | awk '{ print $2 }'`
BKG=`\grep '^bkg' ${RES_FINAL} | awk '{ print $2 }'`
fi
## single/double beta }}}
## get `mass/virial_radius/luminosity' {{{
# 200 data {{{
R200_VAL=`\grep '^r200' ${RES_FINAL} | awk '{ print $2 }'`
R200_ERR_L=`\grep '^r200' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
R200_ERR_U=`\grep '^r200' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
M200_VAL=`\grep '^m200' ${RES_FINAL} | awk '{ print $2 }'`
M200_ERR_L=`\grep '^m200' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
M200_ERR_U=`\grep '^m200' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
L200_VAL=`\grep '^L200' ${RES_FINAL} | awk '{ print $2 }'`
L200_ERR=`\grep '^L200' ${RES_FINAL} | awk '{ print $4 }'`
MGAS200_VAL=`\grep '^gas_m200' ${RES_FINAL} | awk '{ print $2 }'`
MGAS200_ERR_L=`\grep '^gas_m200' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
MGAS200_ERR_U=`\grep '^gas_m200' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
FGAS200_VAL=`\grep '^gas_fraction200' ${RES_FINAL} | awk '{ print $2 }'`
FGAS200_ERR_L=`\grep '^gas_fraction200' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
FGAS200_ERR_U=`\grep '^gas_fraction200' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
[ -z "${R200_VAL}" ] && R200_VAL="null"
[ -z "${R200_ERR_L}" ] && R200_ERR_L="null"
[ -z "${R200_ERR_U}" ] && R200_ERR_U="null"
[ -z "${M200_VAL}" ] && M200_VAL="null"
[ -z "${M200_ERR_L}" ] && M200_ERR_L="null"
[ -z "${M200_ERR_U}" ] && M200_ERR_U="null"
[ -z "${L200_VAL}" ] && L200_VAL="null"
[ -z "${L200_ERR}" ] && L200_ERR="null"
[ -z "${MGAS200_VAL}" ] && MGAS200_VAL="null"
[ -z "${MGAS200_ERR_L}" ] && MGAS200_ERR_L="null"
[ -z "${MGAS200_ERR_U}" ] && MGAS200_ERR_U="null"
[ -z "${FGAS200_VAL}" ] && FGAS200_VAL="null"
[ -z "${FGAS200_ERR_L}" ] && FGAS200_ERR_L="null"
[ -z "${FGAS200_ERR_U}" ] && FGAS200_ERR_U="null"
# 200 }}}
# 500 data {{{
R500_VAL=`\grep '^r500' ${RES_FINAL} | awk '{ print $2 }'`
R500_ERR_L=`\grep '^r500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
R500_ERR_U=`\grep '^r500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
M500_VAL=`\grep '^m500' ${RES_FINAL} | awk '{ print $2 }'`
M500_ERR_L=`\grep '^m500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
M500_ERR_U=`\grep '^m500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
L500_VAL=`\grep '^L500' ${RES_FINAL} | awk '{ print $2 }'`
L500_ERR=`\grep '^L500' ${RES_FINAL} | awk '{ print $4 }'`
MGAS500_VAL=`\grep '^gas_m500' ${RES_FINAL} | awk '{ print $2 }'`
MGAS500_ERR_L=`\grep '^gas_m500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
MGAS500_ERR_U=`\grep '^gas_m500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
FGAS500_VAL=`\grep '^gas_fraction500' ${RES_FINAL} | awk '{ print $2 }'`
FGAS500_ERR_L=`\grep '^gas_fraction500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
FGAS500_ERR_U=`\grep '^gas_fraction500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
[ -z "${R500_VAL}" ] && R500_VAL="null"
[ -z "${R500_ERR_L}" ] && R500_ERR_L="null"
[ -z "${R500_ERR_U}" ] && R500_ERR_U="null"
[ -z "${M500_VAL}" ] && M500_VAL="null"
[ -z "${M500_ERR_L}" ] && M500_ERR_L="null"
[ -z "${M500_ERR_U}" ] && M500_ERR_U="null"
[ -z "${L500_VAL}" ] && L500_VAL="null"
[ -z "${L500_ERR}" ] && L500_ERR="null"
[ -z "${MGAS500_VAL}" ] && MGAS500_VAL="null"
[ -z "${MGAS500_ERR_L}" ] && MGAS500_ERR_L="null"
[ -z "${MGAS500_ERR_U}" ] && MGAS500_ERR_U="null"
[ -z "${FGAS500_VAL}" ] && FGAS500_VAL="null"
[ -z "${FGAS500_ERR_L}" ] && FGAS500_ERR_L="null"
[ -z "${FGAS500_ERR_U}" ] && FGAS500_ERR_U="null"
# 500 }}}
# 1500 data {{{
R1500_VAL=`\grep '^r1500' ${RES_FINAL} | awk '{ print $2 }'`
R1500_ERR_L=`\grep '^r1500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
R1500_ERR_U=`\grep '^r1500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
M1500_VAL=`\grep '^m1500' ${RES_FINAL} | awk '{ print $2 }'`
M1500_ERR_L=`\grep '^m1500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
M1500_ERR_U=`\grep '^m1500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
L1500_VAL=`\grep '^L1500' ${RES_FINAL} | awk '{ print $2 }'`
L1500_ERR=`\grep '^L1500' ${RES_FINAL} | awk '{ print $4 }'`
MGAS1500_VAL=`\grep '^gas_m1500' ${RES_FINAL} | awk '{ print $2 }'`
MGAS1500_ERR_L=`\grep '^gas_m1500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
MGAS1500_ERR_U=`\grep '^gas_m1500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
FGAS1500_VAL=`\grep '^gas_fraction1500' ${RES_FINAL} | awk '{ print $2 }'`
FGAS1500_ERR_L=`\grep '^gas_fraction1500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
FGAS1500_ERR_U=`\grep '^gas_fraction1500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
[ -z "${R1500_VAL}" ] && R1500_VAL="null"
[ -z "${R1500_ERR_L}" ] && R1500_ERR_L="null"
[ -z "${R1500_ERR_U}" ] && R1500_ERR_U="null"
[ -z "${M1500_VAL}" ] && M1500_VAL="null"
[ -z "${M1500_ERR_L}" ] && M1500_ERR_L="null"
[ -z "${M1500_ERR_U}" ] && M1500_ERR_U="null"
[ -z "${L1500_VAL}" ] && L1500_VAL="null"
[ -z "${L1500_ERR}" ] && L1500_ERR="null"
[ -z "${MGAS1500_VAL}" ] && MGAS1500_VAL="null"
[ -z "${MGAS1500_ERR_L}" ] && MGAS1500_ERR_L="null"
[ -z "${MGAS1500_ERR_U}" ] && MGAS1500_ERR_U="null"
[ -z "${FGAS1500_VAL}" ] && FGAS1500_VAL="null"
[ -z "${FGAS1500_ERR_L}" ] && FGAS1500_ERR_L="null"
[ -z "${FGAS1500_ERR_U}" ] && FGAS1500_ERR_U="null"
# 1500 }}}
# 2500 data {{{
R2500_VAL=`\grep '^r2500' ${RES_FINAL} | awk '{ print $2 }'`
R2500_ERR_L=`\grep '^r2500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
R2500_ERR_U=`\grep '^r2500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
M2500_VAL=`\grep '^m2500' ${RES_FINAL} | awk '{ print $2 }'`
M2500_ERR_L=`\grep '^m2500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
M2500_ERR_U=`\grep '^m2500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
L2500_VAL=`\grep '^L2500' ${RES_FINAL} | awk '{ print $2 }'`
L2500_ERR=`\grep '^L2500' ${RES_FINAL} | awk '{ print $4 }'`
MGAS2500_VAL=`\grep '^gas_m2500' ${RES_FINAL} | awk '{ print $2 }'`
MGAS2500_ERR_L=`\grep '^gas_m2500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
MGAS2500_ERR_U=`\grep '^gas_m2500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
FGAS2500_VAL=`\grep '^gas_fraction2500' ${RES_FINAL} | awk '{ print $2 }'`
FGAS2500_ERR_L=`\grep '^gas_fraction2500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $1 }'`
FGAS2500_ERR_U=`\grep '^gas_fraction2500' ${RES_FINAL} | awk '{ print $3 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
[ -z "${R2500_VAL}" ] && R2500_VAL="null"
[ -z "${R2500_ERR_L}" ] && R2500_ERR_L="null"
[ -z "${R2500_ERR_U}" ] && R2500_ERR_U="null"
[ -z "${M2500_VAL}" ] && M2500_VAL="null"
[ -z "${M2500_ERR_L}" ] && M2500_ERR_L="null"
[ -z "${M2500_ERR_U}" ] && M2500_ERR_U="null"
[ -z "${L2500_VAL}" ] && L2500_VAL="null"
[ -z "${L2500_ERR}" ] && L2500_ERR="null"
[ -z "${MGAS2500_VAL}" ] && MGAS2500_VAL="null"
[ -z "${MGAS2500_ERR_L}" ] && MGAS2500_ERR_L="null"
[ -z "${MGAS2500_ERR_U}" ] && MGAS2500_ERR_U="null"
[ -z "${FGAS2500_VAL}" ] && FGAS2500_VAL="null"
[ -z "${FGAS2500_ERR_L}" ] && FGAS2500_ERR_L="null"
[ -z "${FGAS2500_ERR_U}" ] && FGAS2500_ERR_U="null"
# 2500 }}}
FGRR=`\grep '^gas_fraction.*r2500.*r500=' ${RES_FINAL} | sed 's/^.*r500=//' | awk '{ print $1 }'`
FGRR_ERR_L=`\grep '^gas_fraction.*r2500.*r500=' ${RES_FINAL} | sed 's/^.*r500=//' | awk '{ print $2 }' | awk -F'/' '{ print $1 }'`
FGRR_ERR_U=`\grep '^gas_fraction.*r2500.*r500=' ${RES_FINAL} | sed 's/^.*r500=//' | awk '{ print $2 }' | awk -F'/' '{ print $2 }' | tr -d '+'`
[ -z "${FGRR}" ] && FGRR="null"
[ -z "${FGRR_ERR_L}" ] && FGRR_ERR_L="null"
[ -z "${FGRR_ERR_U}" ] && FGRR_ERR_U="null"
## mrl }}}
## rcool & cooling time {{{
RCOOL=`\grep '^cooling' ${RES_FINAL} | awk '{ print $4 }'`
COOLING_TIME=`\grep '^cooling' ${RES_FINAL} | awk -F'=' '{ print $2 }' | tr -d ' Gyr'`
[ -z "${RCOOL}" ] && RCOOL="null"
[ -z "${COOLING_TIME}" ] && COOLING_TIME="null"
## cooling time }}}
## repro/mass }}}
cd ${BASEDIR}
## orig json file {{{
printf "## collect data from original info file ...\n"
OBJ_NAME=`\grep '"Source\ Name' ${JSON_FILE} | sed 's/.*"Source.*":\ //' | sed 's/^"//' | sed 's/"\ *,$//'`
OBJ_UNAME=`\grep '"Unified\ Name' ${JSON_FILE} | sed 's/.*"Unified.*":\ //' | sed 's/^"//' | sed 's/"\ *,$//'`
OBJ_RA=`\grep '"R\.\ A\.' ${JSON_FILE} | sed 's/.*"R\.\ A\.":\ //' | sed 's/^"//' | sed 's/"\ *,$//'`
OBJ_DEC=`\grep '"Dec\.' ${JSON_FILE} | sed 's/.*"Dec\.":\ //' | sed 's/^"//' | sed 's/"\ *,$//'`
OBJ_XCRA=`\grep '"XCNTRD_RA' ${JSON_FILE} | sed 's/.*"XCNTRD_RA":\ //' | sed 's/^"//' | sed 's/"\ *,$//'`
OBJ_XCDEC=`\grep '"XCNTRD_DEC' ${JSON_FILE} | sed 's/.*"XCNTRD_DEC":\ //' | sed 's/^"//' | sed 's/"\ *,$//'`
REDSHIFT=`\grep '"redshift' ${JSON_FILE} | sed 's/.*"redshift.*":\ //' | sed 's/\ *,$//'`
COOLCORE=`\grep -i '"cool.*core' ${JSON_FILE} | sed 's/.*"[cC]ool.*":\ //' | sed 's/\ *,$//'`
[ -z "${COOLCORE}" ] && COOLCORE="null"
OBJ_FEATURE=`\grep '"Feature' ${JSON_FILE} | sed 's/.*"Feature":\ //' | sed 's/^"//' | sed 's/"\ *,*$//'`
OBJ_NOTE=`\grep '"NOTE' ${JSON_FILE} | sed 's/.*"NOTE":\ //' | sed 's/^"//' | sed 's/"\ *,*$//'`
# T & Z {{{
T_1R500=`\grep '"T(0\.1.*R500' ${JSON_FILE} | sed 's/.*"T.*":\ //' | sed 's/\ *,$//'`
T_1ERR=`\grep '"T_err(.*0\.1.*R500' ${JSON_FILE} | sed 's/.*"T.*":\ //' | sed 's/\ *,$//'`
T_1ERR_L=`\grep '"T_err_l.*0\.1.*R500' ${JSON_FILE} | sed 's/.*"T.*":\ //' | sed 's/\ *,$//'`
T_1ERR_U=`\grep '"T_err_u.*0\.1.*R500' ${JSON_FILE} | sed 's/.*"T.*":\ //' | sed 's/\ *,$//'`
Z_1R500=`\grep '"Z(0\.1.*R500' ${JSON_FILE} | sed 's/.*"Z.*":\ //' | sed 's/\ *,$//'`
Z_1ERR=`\grep '"Z_err(.*0\.1.*R500' ${JSON_FILE} | sed 's/.*"Z.*":\ //' | sed 's/\ *,$//'`
Z_1ERR_L=`\grep '"Z_err_l.*0\.1.*R500' ${JSON_FILE} | sed 's/.*"Z.*":\ //' | sed 's/\ *,$//'`
Z_1ERR_U=`\grep '"Z_err_u.*0\.1.*R500' ${JSON_FILE} | sed 's/.*"Z.*":\ //' | sed 's/\ *,$//'`
T_2R500=`\grep '"T(0\.2.*R500' ${JSON_FILE} | sed 's/.*"T.*":\ //' | sed 's/\ *,$//'`
T_2ERR=`\grep '"T_err(.*0\.2.*R500' ${JSON_FILE} | sed 's/.*"T.*":\ //' | sed 's/\ *,$//'`
T_2ERR_L=`\grep '"T_err_l.*0\.2.*R500' ${JSON_FILE} | sed 's/.*"T.*":\ //' | sed 's/\ *,$//'`
T_2ERR_U=`\grep '"T_err_u.*0\.2.*R500' ${JSON_FILE} | sed 's/.*"T.*":\ //' | sed 's/\ *,$//'`
Z_2R500=`\grep '"Z(0\.2.*R500' ${JSON_FILE} | sed 's/.*"Z.*":\ //' | sed 's/\ *,$//'`
Z_2ERR=`\grep '"Z_err(.*0\.2.*R500' ${JSON_FILE} | sed 's/.*"Z.*":\ //' | sed 's/\ *,$//'`
Z_2ERR_L=`\grep '"Z_err_l.*0\.2.*R500' ${JSON_FILE} | sed 's/.*"Z.*":\ //' | sed 's/\ *,$//'`
Z_2ERR_U=`\grep '"Z_err_u.*0\.2.*R500' ${JSON_FILE} | sed 's/.*"Z.*":\ //' | sed 's/\ *,$//'`
[ -z "${T_1R500}" ] && T_1R500="null"
[ -z "${T_1ERR}" ] && T_1ERR="null"
[ -z "${T_1ERR_L}" ] && T_1ERR_L="null"
[ -z "${T_1ERR_U}" ] && T_1ERR_U="null"
[ -z "${Z_1R500}" ] && Z_1R500="null"
[ -z "${Z_1ERR}" ] && Z_1ERR="null"
[ -z "${Z_1ERR_L}" ] && Z_1ERR_L="null"
[ -z "${Z_1ERR_U}" ] && Z_1ERR_U="null"
[ -z "${T_2R500}" ] && T_2R500="null"
[ -z "${T_2ERR}" ] && T_2ERR="null"
[ -z "${T_2ERR_L}" ] && T_2ERR_L="null"
[ -z "${T_2ERR_U}" ] && T_2ERR_U="null"
[ -z "${Z_2R500}" ] && Z_2R500="null"
[ -z "${Z_2ERR}" ] && Z_2ERR="null"
[ -z "${Z_2ERR_L}" ] && Z_2ERR_L="null"
[ -z "${Z_2ERR_U}" ] && Z_2ERR_U="null"
# T & Z }}}
## json data }}}
## output data to JSON file {{{
printf "## save collected data into file \`${JSON_FILE}' ...\n"
mv -fv ${JSON_FILE} ${JSON_FILE}_bak
cat > ${JSON_FILE} << _EOF_
{
"Obs. ID": ${OBS_ID},
"Source Name": "${OBJ_NAME}",
"Unified Name": "${OBJ_UNAME}",
"Obs. Date": "${DATE_OBS}",
"Detector": "${ACIS_TYPE}",
"Exposure (ks)": ${EXPOSURE_RAW},
"Clean Exposure (ks)": ${EXPOSURE_CLEAN},
"R. A.": "${OBJ_RA}",
"Dec.": "${OBJ_DEC}",
"XCNTRD_RA": "${OBJ_XCRA}",
"XCNTRD_DEC": "${OBJ_XCDEC}",
"nH (10^22 cm^-2)": ${N_H},
"redshift": ${REDSHIFT},
"E(z)": ${E_Z},
"T_ref (keV)": ${T_REF},
"Z_ref (solar)": ${Z_REF},
"Rmax_SBP (pixel)": ${RMAX_SBP_PIX},
"Rmax_Tpro (pixel)": ${RMAX_TPRO_PIX},
"Rmax_SBP (kpc)": ${RMAX_SBP_KPC},
"Rmax_Tpro (kpc)": ${RMAX_TPRO_KPC},
"NFW_Rmin (kpc)": ${NFW_RMIN_KPC},
"Model_SBP": "${MODEL_SBP}",
"n01": ${N01},
"beta1": ${BETA1},
"rc1": ${RC1},
"rc1_kpc": ${RC1_KPC},
"n02": ${N02},
"beta2": ${BETA2},
"rc2": ${RC2},
"rc2_kpc": ${RC2_KPC},
"bkg": ${BKG},
"R200 (kpc)": ${R200_VAL},
"R200_err_lower (1sigma)": ${R200_ERR_L},
"R200_err_upper (1sigma)": ${R200_ERR_U},
"M200 (M_sun)": ${M200_VAL},
"M200_err_lower (1sigma)": ${M200_ERR_L},
"M200_err_upper (1sigma)": ${M200_ERR_U},
"L200 (erg/s)": ${L200_VAL},
"L200_err (1sigma)": ${L200_ERR},
"M_gas200 (M_sun)": ${MGAS200_VAL},
"M_gas200_err_lower (1sigma)": ${MGAS200_ERR_L},
"M_gas200_err_upper (1sigma)": ${MGAS200_ERR_U},
"F_gas200": ${FGAS200_VAL},
"F_gas200_err_lower (1sigma)": ${FGAS200_ERR_L},
"F_gas200_err_upper (1sigma)": ${FGAS200_ERR_U},
"R500 (kpc)": ${R500_VAL},
"R500_err_lower (1sigma)": ${R500_ERR_L},
"R500_err_upper (1sigma)": ${R500_ERR_U},
"M500 (M_sun)": ${M500_VAL},
"M500_err_lower (1sigma)": ${M500_ERR_L},
"M500_err_upper (1sigma)": ${M500_ERR_U},
"L500 (erg/s)": ${L500_VAL},
"L500_err (1sigma)": ${L500_ERR},
"M_gas500 (M_sun)": ${MGAS500_VAL},
"M_gas500_err_lower (1sigma)": ${MGAS500_ERR_L},
"M_gas500_err_upper (1sigma)": ${MGAS500_ERR_U},
"F_gas500": ${FGAS500_VAL},
"F_gas500_err_lower (1sigma)": ${FGAS500_ERR_L},
"F_gas500_err_upper (1sigma)": ${FGAS500_ERR_U},
"R1500": ${R1500_VAL},
"R1500_err_lower": ${R1500_ERR_L},
"R1500_err_upper": ${R1500_ERR_U},
"M1500": ${M1500_VAL},
"M1500_err_lower": ${M1500_ERR_L},
"M1500_err_upper": ${M1500_ERR_U},
"L1500": ${L1500_VAL},
"L1500_err": ${L1500_ERR},
"M_gas1500": ${MGAS1500_VAL},
"M_gas1500_err_lower": ${MGAS1500_ERR_L},
"M_gas1500_err_upper": ${MGAS1500_ERR_U},
"F_gas1500": ${FGAS1500_VAL},
"F_gas1500_err_lower": ${FGAS1500_ERR_L},
"F_gas1500_err_upper": ${FGAS1500_ERR_U},
"R2500": ${R2500_VAL},
"R2500_err_lower": ${R2500_ERR_L},
"R2500_err_upper": ${R2500_ERR_U},
"M2500": ${M2500_VAL},
"M2500_err_lower": ${M2500_ERR_L},
"M2500_err_upper": ${M2500_ERR_U},
"L2500": ${L2500_VAL},
"L2500_err": ${L2500_ERR},
"M_gas2500": ${MGAS2500_VAL},
"M_gas2500_err_lower": ${MGAS2500_ERR_L},
"M_gas2500_err_upper": ${MGAS2500_ERR_U},
"F_gas2500": ${FGAS2500_VAL},
"F_gas2500_err_lower": ${FGAS2500_ERR_L},
"F_gas2500_err_upper": ${FGAS2500_ERR_U},
"T(0.1-0.5 R500)": ${T_1R500},
"T_err(0.1-0.5 R500)": ${T_1ERR},
"T_err_l(0.1-0.5 R500)": ${T_1ERR_L},
"T_err_u(0.1-0.5 R500)": ${T_1ERR_U},
"Z(0.1-0.5 R500)": ${Z_1R500},
"Z_err(0.1-0.5 R500)": ${Z_1ERR},
"Z_err_l(0.1-0.5 R500)": ${Z_1ERR_L},
"Z_err_u(0.1-0.5 R500)": ${Z_1ERR_U},
"T(0.2-0.5 R500)": ${T_2R500},
"T_err(0.2-0.5 R500)": ${T_2ERR},
"T_err_l(0.2-0.5 R500)": ${T_2ERR_L},
"T_err_u(0.2-0.5 R500)": ${T_2ERR_U},
"Z(0.2-0.5 R500)": ${Z_2R500},
"Z_err(0.2-0.5 R500)": ${Z_2ERR},
"Z_err_l(0.2-0.5 R500)": ${Z_2ERR_L},
"Z_err_u(0.2-0.5 R500)": ${Z_2ERR_U},
"F_gas(R2500-R500)": ${FGRR},
"F_gas_err_l(R2500-R500)": ${FGRR_ERR_L},
"F_gas_err_u(R2500-R500)": ${FGRR_ERR_U},
"R_cool (kpc)": ${RCOOL},
"Cooling_time (Gyr)": ${COOLING_TIME},
"Cool_core": ${COOLCORE},
"Feature": "${OBJ_FEATURE}",
"NOTE": "${OBJ_NOTE}"
},
_EOF_
## output JSON }}}
exit 0
|