/*---------------------------------------------------------------------------- File name : jitter.c Author : N. Devillard Created on : Sept 30, 1997 Description : Jitter mode data reduction for ISAAC/SOFI ---------------------------------------------------------------------------*/ /* $Id: jitter.c,v 1.10 2002/01/17 10:42:55 ndevilla Exp $ $Author: ndevilla $ $Date: 2002/01/17 10:42:55 $ $Revision: 1.10 $ */ static char cvsId[]= "@(#) $Id: jitter.c,v 1.10 2002/01/17 10:42:55 ndevilla Exp $"; /*---------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include #include #include #include "eclipse.h" #include "jitter_ini.h" #include "jitter_engine.h" /*---------------------------------------------------------------------------- Defines ---------------------------------------------------------------------------*/ #define OPT_FILE 1001 #define OPT_GENERATE 1002 #define OPT_TIMING 1003 #define OPT_OFFSET 1004 #define OPT_GUI 1005 #define OPT_IN 2000 #define OPT_OUT 2001 #define OPT_CALIB 2002 /* This function just gives the usage for the program */ static void usage(char *pname) ; static void help_offset_file_format(void) ; static char prog_desc[] = "isaac/sofi jitter imaging reduction" ; /*---------------------------------------------------------------------------- Main code ---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { char ini_name[FILENAMESZ] ; int c ; int gen_flag = 0 ; int gui_flag = 0 ; int timing_flag = 0 ; long total_inpix ; char name_i[FILENAMESZ]; char name_o[FILENAMESZ]; char name_c[FILENAMESZ]; strcpy(ini_name, "jitter.ini") ; strcpy(name_i, "framelist.ascii"); strcpy(name_o, "jittered_result"); strcpy(name_c, "calib.ascii"); /* * Command line parsing by GNU's getopt() * See implementation in pipes/gnugetopt.c and pipes/gnugetopt1.c */ while (1) { int option_index = 0 ; static struct option long_options[] = { {"license", 0, 0, OPT_LICENSE}, {"version", 0, 0, OPT_VERSION}, {"file", 1, 0, OPT_FILE}, {"help", 0, 0, OPT_HELP}, {"generate",0, 0, OPT_GENERATE}, {"time", 0, 0, OPT_TIMING}, {"offset", 0, 0, OPT_OFFSET}, {"gui", 0, 0, OPT_GUI}, {"in", 1, 0, OPT_IN}, {"out", 1, 0, OPT_OUT}, {"calib", 1, 0, OPT_CALIB}, {0, 0, 0, 0} } ; c = getopt_long(argc, argv, "LTc:f:ghi:o:tw", 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: give version number */ case OPT_VERSION: print_eclipse_version() ; printf("%s\n", cvsId); return 0 ; case OPT_HELP: case 'h': usage(argv[0]) ; break ; /* Local options */ /* name of the .ini file */ case OPT_FILE: case 'f': strcpy(ini_name, optarg) ; break ; /* generate a default .ini file */ case OPT_GENERATE: case 'g': gen_flag = 1 ; break ; /* use the GUI */ case OPT_GUI: case 'w': gui_flag = 1 ; break ; /* timing flag: use it to get an evaluation of CPU time */ case OPT_TIMING: case 't': timing_flag = 1 ; break ; /* Display help about the offset file format */ case OPT_OFFSET: help_offset_file_format() ; return 0 ; /* Input list name */ case OPT_IN: case 'i': strcpy(name_i, optarg); break ; /* Output base name */ case OPT_OUT: case 'o': strcpy(name_o, optarg); break ; /* Calibration file list name */ case OPT_CALIB: case 'c': strcpy(name_c, optarg); break ; default: usage(argv[0]) ; break ; } } /* Dis bonjour a la dame */ hello_world(argv[0], prog_desc) ; /* Initialize eclipse environment */ eclipse_init() ; if (gui_flag) { /* Launch GUI */ jitter_gui() ; } else if (gen_flag) { /* Generate a default ini file */ if (generate_ini_file(ini_name, name_i, name_o, name_c) == 0) { fprintf(stderr, "ini file [%s] has been generated\n", ini_name) ; } return 0 ; } else { /* Launch the jitter engine, timing is not mandatory */ if (timing_flag) eclipse_cpu_timing(START_CLOCK, -1) ; /* * MAIN CALL TO THE JITTER ENGINE */ total_inpix = jitter_engine(ini_name) ; if (timing_flag) { printf("\n"); printf("performance:\n"); printf("\t (s)\t (us)\t(kpix/s)\n") ; eclipse_cpu_timing(STOP_CLOCK, total_inpix) ; } else { if (total_inpix>0) e_comment(0, "%ld pixels processed in input", total_inpix); } } 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 [flags] [options]\n", pname) ; printf("flags are :\n\n") ; printf("\t-g or --generate : generate a .ini file\n") ; printf("\t-t or --time : estimate used CPU time\n") ; printf("\t--offset : get help about the offset file format\n") ; printf("\t-h or --help : get this help\n") ; printf("\noptions are :\n\n") ; printf("\t-f or --file \n") ; printf("\tto specify which .ini file to work on (default: jitter.ini)\n"); printf("\n") ; printf("\t-w or --gui\n") ; printf("\tto launch the GUI\n") ; printf("\n"); printf("following options are only valid with -g or --generate:\n"); printf("\t-i or --in provide input file name\n"); printf("\t-o or --out provide output file name\n"); printf("\t-c or --calib provide calibration file name\n"); printf("\n\n") ; exit(0) ; } static void help_offset_file_format(void) { printf( "\n" "*** jitter help: offset files ***\n" "An offset file contains input offsets for plane registration.\n" "These offsets are either absolute or relative.\n" "Absolute offsets are for example the position of the same\n" "object in all frames. They specify the position of the same\n" "object in each frame.\n" "\n"); printf( "Relative offsets are all referenced to the first frame.\n" "They must start at (0,0) and provide for each frame the\n" "difference in position relative to the first frame.\n" "\n"); printf( "To specify which type of offsets should be used, one line in\n" "the file should contain the word 'abs' or 'rel' alone\n" "(without quotes). If the words 'abs' or 'rel' cannot be\n" "found alone on a line anywhere in the file, relative\n" "offsets will be assumed\n" "\n"); printf( "Blank lines and lines starting with a hash (#) are comments.\n" "Data are given as 3 numerical values:\n" "plane number, x position or shift, y position or shift.\n" "\n"); printf( "Example:\n" "\n" "# This is an absolute offset file for two frames\n" "abs\n" "1 156 257\n" "2 143 288\n" "\n" "# This is the same information with relative offsets\n" "rel\n" "1 0 0\n" "2 -13 31\n" "\n"); return ; }