From 3ca78329f6b3df293cfd8b16ea90586cae02c278 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 27 Oct 2016 10:12:36 +0800 Subject: Check the output file existence first --- bin/healpix2hpx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'bin/healpix2hpx') diff --git a/bin/healpix2hpx b/bin/healpix2hpx index 2a0e6a4..6f30795 100755 --- a/bin/healpix2hpx +++ b/bin/healpix2hpx @@ -62,11 +62,18 @@ def main(): 'See also {0}'.format(fg21sim.__url__) ] + if os.path.exists(args.outfile): + if args.clobber: + logger.warning("Remove existing output file: %s" % args.outfile) + os.remove(args.outfile) + else: + raise OSError("Output file already exists: %s" % args.outfile) + hpx_data, hpx_header = healpix2hpx(args.infile, append_history=history, append_comment=comments) hdu = fits.PrimaryHDU(data=hpx_data, header=hpx_header) - hdu.writeto(args.outfile, clobber=args.clobber, checksum=True) + hdu.writeto(args.outfile, checksum=True) logger.info("HPX FITS images write to: %s" % args.outfile) -- cgit v1.2.2