/* $Id: fsmosaic.c,v 1.4 2002/01/11 08:44:55 fors Exp $ * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * COPYRIGHT (c) 2001 European Southern Observatory * LICENSE: GNU General Public License version 2 or later * * PROJECT: VLT Data Flow System * AUTHOR: Ralf Palsa -- ESO/DMD/DPG * SUBSYSTEM: Instrument pipelines * * PURPOSE: * DESCRIPTION: * * $Name: fsmosaic-1_0 $ * $Revision: 1.4 $ * ---------------------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #ifdef HAVE_STRDUP #include #endif #include #include #include #include "create_mosaic.h" #include "file_utils.h" /* * String of possible options. The leading colon is needed to make * getopt() return a ':' instead of a '?' if a required argument is * not present. */ static const char *options = ":hsvpV"; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"silent", no_argument, 0, 's'}, {"verbose", no_argument, 0, 'v'}, {"permissive", no_argument, 0, 'p'}, {"version", no_argument, 0, 'V'}, {0, 0, 0, 0} }; /* * Default name if output file was not given on the command line. */ static const char *default_output_file = "fsmosaic.fits"; /* * Verbosity flag */ extern int verbose; inline static void show_usage(const char *name) { fprintf(stderr, "Usage: %s [-hV] [-v] [-p] input [output]\n", name); fprintf(stderr, "Create a mosaic from a FORS2 master and slave frame.\n"); fprintf(stderr, "\nOptions:\n"); fprintf(stderr, " -h, --help Print this message\n"); fprintf(stderr, " -v, --verbose Verbose mode\n"); fprintf(stderr, " -p, --permissive Permissive mode\n"); fprintf(stderr, " -V, --version Show version\n"); fprintf(stderr, "\nDepending on the frame passed as input the " "corresponding master and slave\n"); fprintf(stderr, "frame is searched in the current " "working directory. If an output file name\n"); fprintf(stderr, "is given the mosaic is written to this file, " "otherwise is saved as\n"); fprintf(stderr, "'%s.fits'.\n\n", name); fprintf(stderr, "If an already merged image is passed as input " "file %s reports an error\n", name); fprintf(stderr, "and exits with status %1d. However, when using the " "option '-p' and the passed\n", EXIT_IS_MOSAIC); fprintf(stderr, "mosaic was created by %s, %s creates " "a copy of the input file and\n", name, name); fprintf(stderr, "exits with status 0.\n\n"); return; } inline static void show_version(const char *name, const char *version) { fprintf(stderr, "%s %s\n", name, version); fprintf(stderr, "The program is part of the FORS2 Instrument pipeline.\n\n"); fprintf(stderr, "Copyright (C) 2001 European Southern Observatory\n"); fprintf(stderr, "This program is free software; you can redistribute it " "and/or\n"); fprintf(stderr, "modify it under the terms of the GNU General Public " "License as\n"); fprintf(stderr, "published by the Free Software Foundation; either " "version 2 of\n"); fprintf(stderr, "the License, or (at your option) any later version.\n\n"); fprintf(stderr, "This program is distributed in the hope that it will be " "useful,\n"); fprintf(stderr, "but WITHOUT ANY WARRANTY; without even the implied " "warranty of\n"); fprintf(stderr, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); fprintf(stderr, "See the GNU General Public License for more details.\n"); return; } int main(int argc, char **argv) { const char *task = "fsmosaic"; int silent = 0, permissive = 0; int option_index = 0; int c; int return_code; char *input_file, *output_file; /* * Parse command line */ verbose = 0; while ((c = getopt_long(argc, argv, options, long_options, &option_index)) != -1) { switch (c) { case 'h': show_usage(task); return 0; break; case 'p': permissive = 1; break; case 'v': verbose = 1; break; case 's': silent = 1; break; case 'V': show_version(task, VERSION); return 0; break; case ':': return 1; break; default: show_usage(task); return 1; break; } } if (argc <= optind) { fprintf(stderr, "%s: Missing input file!\n", task); show_usage(task); return 1; } else if (argc - optind > 2) { fprintf(stderr, "%s: Too many arguments!\n", task); show_usage(task); return 1; } /* * Let silent override verbose */ verbose = silent == 1 ? 0 : verbose; /* * Save file name arguments */ input_file = strdup(argv[optind]); if (argc - optind == 2) output_file = strdup(argv[optind + 1]); else output_file = (char *)default_output_file; /* * Check the input file */ if (access(input_file, F_OK)) { fprintf(stderr, "%s: %s: No such file or directory!\n", task, input_file); return EXIT_IS_NO_FILE; } if (access(input_file, R_OK)) { fprintf(stderr, "%s: %s: Permission denied!\n", task, input_file); return EXIT_NO_PERMISSION; } if (!is_fits_file((char *)input_file)) { fprintf(stderr, "%s: %s: File is not a valid FITS file!\n", task, input_file); return EXIT_IS_NO_FITS_FILE; } /* * Check if the input file is already a mosaic created by ourselves. * If the permissive option was used, handle it gracefully. */ if (is_mosaic(input_file)) { if (!permissive) { fprintf(stderr, "%s: Input file is already a merged frame!\n", task); if (output_file != (char *)default_output_file) free(output_file); free(input_file); return EXIT_IS_MOSAIC; } else { if (!strcmp(input_file, output_file)) { fprintf(stderr, "%s: Input and output file are the same file!\n", task); if (output_file != (char *)default_output_file) free(output_file); free(input_file); return EXIT_SAME_FILE; } else copy(input_file, output_file); } } else { /* * Create the mosaic */ if ((return_code = create_mosaic(input_file, output_file)) != EXIT_SUCCESS) { fprintf(stderr, "%s: Frame combination failed!\n", task); if (output_file != (char *)default_output_file) free(output_file); free(input_file); return return_code; } } if (output_file != (char *)default_output_file) free(output_file); free(input_file); return 0; }