From 69831225acd6b3b770bb4bc8b14dfc284e382567 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 16 Oct 2019 13:52:31 +0800 Subject: astro/sfr_chandra.pl: Support region list with each line a region file --- astro/spectrum/sfr_chandra.pl | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/astro/spectrum/sfr_chandra.pl b/astro/spectrum/sfr_chandra.pl index f7d86c7..010c7cd 100755 --- a/astro/spectrum/sfr_chandra.pl +++ b/astro/spectrum/sfr_chandra.pl @@ -16,10 +16,18 @@ use strict; use warnings; use File::Basename; +use File::Copy; -my $version = "2015/03/04"; +my $version = "2019/10/16"; # # ChangeLogs: +# +# 2019/10/16: Weitian LI +# * support region list file with each line representing a region file +# instead of the region itself (Sanders's contour binning +# segmentation program output such a region format: +# http://www-xray.ast.cam.ac.uk/papers/contbin/ ) +# # 2015/03/04: Weitian LI # Completely rewrite of this script: # * add use strict, warnings, many fixes to the syntax @@ -58,6 +66,9 @@ sub usage { Usage: $prog +Options: + region_list: each line can be a region string or a region file + Version: $version ); print $text; @@ -614,11 +625,18 @@ foreach my $line (@region_lines) { # Save the current region to a temporary region file unlink($fit_reg_fn); - open(my $FIT_REG, ">", $fit_reg_fn) - or die "ERROR: Could not open file '$fit_reg_fn', $!"; - my @cur_regs = split(/\s+/, $line); - foreach my $reg (@cur_regs) { - print $FIT_REG "$reg\n" + if (-f $line) { + # Each line is a region file + copy($line, $fit_reg_fn) + or die "ERROR: Could not copy region file '$line', $!"; + } else { + # Each line is a region string + open(my $FIT_REG, ">", $fit_reg_fn) + or die "ERROR: Could not open file '$fit_reg_fn', $!"; + my @cur_regs = split(/\s+/, $line); + foreach my $reg (@cur_regs) { + print $FIT_REG "$reg\n" + } } close($FIT_REG); -- cgit v1.2.2