Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

extract_snap.C

Go to the documentation of this file.
00001 
00011 
00012 #include "dyn.h"
00013 
00014 #ifdef TOOLBOX
00015 
00016 main(int argc, char ** argv)
00017 {
00018     char  *comment;
00019     bool  c_flag = FALSE;       // if TRUE, a comment given on command line
00020 
00021     real  t_extract;
00022     bool  t_flag = FALSE;       // if TRUE, a time was specified
00023 
00024     bool  v_flag = FALSE;       // if TRUE, print snap times as read
00025 
00026     int   n = 1;
00027     bool  n_flag = false;       // if TRUE, a number was specified
00028 
00029     check_help();
00030 
00031     extern char *poptarg;
00032     int c;
00033     char* param_string = "c:n:t:v";
00034 
00035     while ((c = pgetopt(argc, argv, param_string)) != -1)
00036         switch(c) {
00037             case 'c': c_flag = TRUE;
00038                       comment = poptarg;
00039                       break;
00040             case 't': t_flag = TRUE;
00041                       t_extract = atof(poptarg);
00042                       break;
00043             case 'n': n_flag = TRUE;
00044                       n = atoi(poptarg);
00045                       break;
00046             case 'v': v_flag = TRUE;
00047                       break;
00048             case '?': params_to_usage(cerr, argv[0], param_string);
00049                       get_help();
00050                       exit(1);
00051         }            
00052 
00053     if (n < 0) err_exit("n < 0 specified.");
00054     if (n > 1 && !t_flag) {
00055         warning("n > 1 but no time specified -- 0 assumed.");
00056         t_extract = 0;
00057         t_flag = true;
00058     }
00059 
00060     dyn *b = NULL, *bp = NULL;
00061     int i = 0;
00062 
00063     while (b = get_dyn(cin)) {
00064 
00065         real time = b->get_system_time();
00066         i++;
00067 
00068         if (v_flag) cerr << "Snap time #" << i << " = " << time << endl;
00069 
00070         if (t_flag && time >= t_extract) {
00071 
00072             if (n > 0) {
00073 
00074                 if (c_flag == TRUE)
00075                     b->log_comment(comment);
00076 
00077                 b->log_history(argc, argv);
00078                 put_dyn(cout, *b);
00079             }
00080 
00081             if (--n <= 0) exit(0);
00082         }
00083 
00084         if (bp != NULL)         // Hmmm... if (!bp) fails here on merlot!
00085             rmtree(bp);
00086 
00087         bp = b;
00088     }
00089 
00090     if (n > 0 && !t_flag) {
00091         bp->log_history(argc, argv);
00092         put_dyn(cout, *bp);
00093     }
00094 
00095 }
00096 
00097 #endif

Generated at Sun Feb 24 09:57:00 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001