/*--------------------------------------------------------------------------- File name : is_rename.c Author : Y. Jung Created on : January 2001 Description : rename ISAAC products according defined rules *--------------------------------------------------------------------------*/ /* $Id: is_rename.c,v 1.17 2001/11/21 15:58:37 yjung Exp $ $Author: yjung $ $Date: 2001/11/21 15:58:37 $ $Revision: 1.17 $ */ /*--------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include #include #include "eclipse.h" #include "is_rename_engine.h" /*--------------------------------------------------------------------------- Define ---------------------------------------------------------------------------*/ #define OPT_ARCHIVE 1000 #define OPT_ORIGFILE 1001 #define OPT_REFERENCE 1002 /*--------------------------------------------------------------------------- Function prototypes ---------------------------------------------------------------------------*/ /* This function just gives the usage for the program */ static void usage(char *pname) ; static char prog_desc[] = "Isaac: Renaming routine" ; /*--------------------------------------------------------------------------- Function codes ---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { char * new_name ; int c ; char line[81] ; int origfile, archive ; char ref_name[FILENAMESZ] ; /* Variable definition zone */ origfile = archive = 0 ; ref_name[0] = (char)0 ; if (argc<2) usage(argv[0]) ; while (1) { int option_index = 0 ; static struct option long_options[] = { {"license", 0, 0, OPT_LICENSE}, {"help", 0, 0, OPT_HELP}, {"version", 0, 0, OPT_VERSION}, {"archive", 0, 0, OPT_ARCHIVE}, {"origfile", 0, 0, OPT_ORIGFILE}, {"ref_name", 1, 0, OPT_REFERENCE}, {0, 0, 0, 0} } ; c = getopt_long(argc, argv, "Lhoar:", long_options, &option_index) ; if (c==-1) break ; switch(c) { /* Standard option: display license undocumented option */ case OPT_LICENSE: case 'L': eclipse_display_license() ; return 0 ; /* Standard option : help */ case OPT_HELP: case 'h': usage(argv[0]) ; break ; /* Standard option: version */ case OPT_VERSION: print_eclipse_version() ; return 0 ; /* Local options */ case OPT_ARCHIVE: case 'a': archive = 1 ; break ; case OPT_ORIGFILE: case 'o': origfile = 1 ; break ; case OPT_REFERENCE: case 'r': strcpy(ref_name, optarg) ; break ; default: usage(argv[0]) ; break ; } } if (ref_name[0] != (char)0) { if ((archive==1) || (origfile==1)) { e_error("ARCHIVE or ORIGFILE opt cannot be used with REF") ; return -1 ; } } if ((archive==1) && (origfile==1)) { e_error("ARCHIVE and ORIGFILE options cannot be used together") ; return -1 ; } if ((argc-optind) < 1) { e_error("missing arguments") ; return -1 ; } /* * The following installs the atexit() and signal catching routines * to handle deletion of temporary files in case of sudden process * interruption. */ eclipse_init() ; /* Retrieve arguments: * argc - optind is the number of remaining arguments * argv[optind] is the first argument which is no option * nor option argument. */ /* Process each input file names */ while (argc > optind) { if ((new_name = isaac_compute_product_name(argv[optind], archive, origfile, ref_name)) == NULL) { optind++ ; } else { /* Rename the file */ e_comment(0, "%35s RENAMED IN %s", argv[optind], new_name) ; if (rename(argv[optind], new_name)) { e_comment(1, "cannot rename %s in %s", argv[optind], new_name) ; } if (is_fits_file(new_name)) { /* Update PIPEFILE keyword in the renamed file */ keytuple2str(line, "PIPEFILE", get_basename(new_name), "pipeline filename") ; qfits_replace_card(new_name, "PIPEFILE", line) ; } free(new_name) ; optind++ ; } } /* Free and return*/ if (debug_active()) xmemory_status() ; return 0 ; } /* * This function only gives the usage for the program */ static void usage(char *pname) { hello_world(pname, prog_desc) ; printf("\n") ; printf("use: %s [options] [parameters]\n", pname) ; printf("\n\n") ; printf("[parameters] is a series of files to rename\n\n") ; printf("The following optiuons are available\n") ; printf("\t-a or --arcfile to rename the file in the ARCFILE keyword\n") ; printf("\t-o or --origfile to rename the file in the ORIGFILE keyword\n") ; printf("\t-r or --ref_name to to rename a file by using an other one\n") ; printf("\nNOTE:\n\n") ; printf("\tWithout any option, the new file name is defined according\n") ; printf("\ta naming convention that differs for each different kind of\n") ; printf("\tfiles.\n") ; printf("\tThe file type is determined by its PRO.CATG keyword, and for\n") ; printf("\teach of these products, there is one way to build the new name\n") ; printf("\twith informations found in the header (date, filter, ...)\n") ; printf("\tFor the details of the naming convention, see \n\n") ; printf("\thttp://www.eso.org/observing/dfo/quality/index_isaac.html\n\n") ; exit(0) ; } /*------------------------ end of source ----------------------------------*/