/*--------------------------------------------------------------------------- File name : average.c Author : Nicolas Devillard Created on : August 23, 1995 Description : average a list of frames or a cube to a single frame *--------------------------------------------------------------------------*/ /* $Id: average.c,v 1.14 2002/01/29 12:36:53 ndevilla Exp $ $Author: ndevilla $ $Date: 2002/01/29 12:36:53 $ $Revision: 1.14 $ */ /*--------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include #include #include #include "eclipse.h" /*--------------------------------------------------------------------------- Defines ---------------------------------------------------------------------------*/ #define OPT_CUT 1001 #define OPT_AVG 1002 #define OPT_FILT_LOW 2001 #define OPT_FILT_HIGH 2002 #define OPT_CYCLE_STEP 2003 #define OPT_RUN_HW 2004 /* This function just gives the usage for the program */ static void usage(char *pname) ; static char prog_desc[] = "average a list of frames or a cube to a single frame" ; /*--------------------------------------------------------------------------- main ---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { int c ; average_method amethod ; cut_method cmethod ; int lo_rej, hi_rej ; int cycle_step ; int run_hw ; char inputname[FILENAMESZ+1] ; char outputname[FILENAMESZ+1] ; int ret ; /* * Command line parsing by GNU's getopt() * See implementation in pipes/gnugetopt.c and pipes/gnugetopt1.c */ lo_rej = -1.0 ; hi_rej = -1.0 ; inputname[0] = (char)0 ; outputname[0] = (char)0 ; cmethod = cut_whole ; amethod = avg_linear ; cycle_step = -1 ; run_hw = -1 ; 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}, {"cut", 1, 0, OPT_CUT}, {"method", 1, 0, OPT_AVG}, {"filt-low", 1, 0, OPT_FILT_LOW}, {"filt-high", 1, 0, OPT_FILT_HIGH}, {"step", 1, 0, OPT_CYCLE_STEP}, {"halfwidth", 1, 0, OPT_RUN_HW}, {"in", 1, 0, OPT_INPUT}, {"out", 1, 0, OPT_OUTPUT}, {0, 0, 0, 0} } ; c = getopt_long(argc, argv, "Lhmsc:r:i:o:l", 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_INPUT: case 'i': strncpy(inputname, optarg, FILENAMESZ) ; break ; case OPT_OUTPUT: case 'o': strncpy(outputname, optarg, FILENAMESZ) ; break ; case OPT_CUT: if (!strcmp(optarg, "whole")) { cmethod = cut_whole ; } else if (!strcmp(optarg, "cycle")) { cmethod = cut_cycle ; } else if (!strcmp(optarg, "running")) { cmethod = cut_running ; } else { e_error("unsupported cut style: [%s]", optarg) ; return -1 ; } break ; case OPT_AVG: if(!strcmp(optarg, "linear")) { amethod = avg_linear ; } else if (!strcmp(optarg, "median")) { amethod = avg_median ; } else if (!strcmp(optarg, "sum")) { amethod = avg_sum ; } else if (!strcmp(optarg, "filtered")) { amethod = avg_filtered ; } else { e_error("unsupported average method: [%s]", optarg) ; } break ; case OPT_FILT_LOW: lo_rej = atoi(optarg) ; break ; case OPT_FILT_HIGH: hi_rej = atoi(optarg) ; break ; case OPT_CYCLE_STEP: cycle_step = (int)atoi(optarg) ; break ; case OPT_RUN_HW: run_hw = (int)atoi(optarg) ; break ; /* Support for old options */ case 'm': e_warning("old-fashioned option: use --method median instead"); amethod = avg_median ; break ; case 's': e_warning("old-fashioned option: use --method sum instead") ; amethod = avg_sum ; break ; case 'c': e_warning("old-fashioned option: use --cut cycle instead") ; cmethod = cut_cycle ; cycle_step = (int)atoi(optarg) ; break ; case 'r': e_warning("old-fashioned option: use --cut running instead") ; cmethod = cut_running ; run_hw = (int)atoi(optarg) ; break ; default: usage(argv[0]) ; break ; } } /* Initialize eclipse environment */ eclipse_init(); /* Real processing starts here */ ret = average_engine( inputname, outputname, cmethod, amethod, cycle_step, run_hw, lo_rej, hi_rej) ; if (debug_active()) xmemory_status() ; return ret ; } static void usage(char *pname) { hello_world(pname, prog_desc) ; printf( "\n" "use: %s [options] [parameters]\n" "parameters are:\n" "\t--in or -i to give input cube name\n" "\t--out or -o to give output cube name (optional)\n" "\n", pname); printf( "options are:\n" "\t--cut whole (default) to average a cube to an image\n" "\t--cut cycle --step to use cycle average\n" "\t--cut running --halfwidth to use running average\n" "\n"); printf( "\t--method linear (default) normal average\n" "\t--method sum to do a sum only\n" "\t--method median to do a median average\n" "\t--method filtered to do a filtered average, with parameters:\n" "\t\t--filt-low where is a number of low pixels\n" "\t\t--filt-high where is a number of high pixels\n" "\n\n"); exit(0) ; }