1 //*******************************************************************
2 //
3 // License:  LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author:  Garrett Potts
8 //
9 //*******************************************************************
10 //  $Id: ossim-info.cpp 18619 2011-01-03 10:33:51Z dburken $
11 
12 #include <ossim/base/ossimArgumentParser.h>
13 #include <ossim/base/ossimException.h>
14 #include <ossim/base/ossimNotify.h>
15 #include <ossim/base/ossimRefPtr.h>
16 #include <ossim/base/ossimTimer.h>
17 #include <ossim/init/ossimInit.h>
18 #include <ossim/util/ossimImageUtil.h>
19 
20 using namespace std;
21 
main(int argc,char * argv[])22 int main(int argc, char *argv[])
23 {
24    // Return 0 on success, something else on error.
25    enum
26    {
27       OK    = 0,
28       ERROR = 1
29    };
30 
31    int result = OK;
32 
33    // Start the timer.
34    ossimTimer::instance()->setStartTick();
35 
36    //---
37    // Get the arg count so we can tell if an arg was consumed by
38    // ossimInit::instance()->initialize
39    //---
40    int originalArgCount = argc;
41 
42    ossimArgumentParser ap(&argc, argv);
43 
44    // Initialize ossim stuff, factories, plugin, etc.
45    ossimInit::instance()->initialize(ap);
46 
47    //---
48    // Avoid going on if a global option was consumed by ossimInit::initialize
49    // like -V or --version option and the arg count is down to 1.
50    //---
51    if ( ( ap.argc() > 1 ) || ( ap.argc() == originalArgCount ) )
52    {
53       // Make the info object.
54       ossimRefPtr<ossimImageUtil> oiu = new ossimImageUtil();
55 
56       try
57       {
58          //---
59          // Initialize will take the options passed in and set things to output
60          // information for.
61          //
62          // ossimInfo::initialize can throw an exception.
63          //---
64          bool continue_after_init = oiu->initialize(ap);
65 
66          if ( continue_after_init )
67          {
68             // Execute the operation(s).
69             result = oiu->execute();
70 
71             ossimNotify(ossimNotifyLevel_NOTICE)
72                << "elapsed time in seconds: "
73                << std::setiosflags(ios::fixed)
74                << std::setprecision(3)
75                << ossimTimer::instance()->time_s() << endl;
76          }
77       }
78       catch (const ossimException& e)
79       {
80          ossimNotify(ossimNotifyLevel_WARN) << e.what() << std::endl;
81          result = ERROR;
82       }
83 
84    }  // End: if ( ( ap.argc() > 1 ) ...
85 
86    return result;
87 
88 } // End of main...
89