001 /* @(#)CopyFits.java $Revision: 1.1 $ $Date: 2002/05/03 11:51:29 $
002 *
003 * Copyright (C) 2002 European Southern Observatory
004 * License: GNU General Public License version 2 or later
005 */
006 package org.eso.fits;
007
008 import java.lang.*;
009 import java.util.*;
010 import java.io.*;
011
012 /** CopyFits class provides a static main method to test writing
013 * of FITS files by copying an existing FITS file.
014 *
015 * @version $Revision: 1.1 $ $Date: 2002/05/03 11:51:29 $
016 * @author P.Grosbol, DMD/ESO, <pgrosbol@eso.org>
017 */
018 public class CopyFits{
019 /** Static method for testing the FITS class library.
020 *
021 * @param argv array of arguments i.e. options of FITS files
022 */
023 public static void main(String[] argv) {
024 System.out.println("Start CopyFits");
025 if (argv.length != 2) {
026 System.err.println("Error: must have two argument> input output");
027 System.exit(1);
028 }
029
030 FitsFile file = null;
031 try {
032 file = new FitsFile(argv[0]);
033 } catch (FitsException e) {
034 System.err.println("Error: is not a FITS file >" + argv[0] + "<");
035 System.exit(-1);
036 } catch (IOException e) {
037 System.err.println("Error: cannot open file >" + argv[0] + "<");
038 System.exit(-1);
039 }
040
041 int noHDU = file.getNoHDUnits();
042 System.out.println("FITS file has " + noHDU + " HDUnits");
043
044 try {
045 file.writeFile(argv[1]);
046 } catch (FitsException e) {
047 System.err.println("Error: FITS problem in writing >"
048 + argv[1] + "<");
049 System.exit(-1);
050 } catch (IOException e) {
051 System.err.println("Error: cannot write file >" + argv[1] + "<");
052 System.exit(-1);
053 }
054
055 System.out.println("Finish CopyFits");
056 System.exit(0);
057 }
058 }