source: tags/Mars-V0.8.7pre/showplot.cc@ 11681

Last change on this file since 11681 was 6253, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.3 KB
Line 
1#include <TROOT.h>
2#include <TClass.h>
3#include <TGClient.h>
4#include <TApplication.h>
5
6#include "MLog.h"
7#include "MLogManip.h"
8
9#include "MArgs.h"
10
11#include "MStatusDisplay.h"
12
13using namespace std;
14
15static void StartUpMessage()
16{
17 // 1 2 3 4 5
18 // 12345678901234567890123456789012345678901234567890
19 gLog << endl;
20 gLog << "showplot --- Mars V" << MARSVER << " compiled on <" << __DATE__ << "> using ROOT v" << ROOTVER << endl;
21 gLog << endl;
22}
23
24static void Usage()
25{
26 // 1 2 3 4 5 6 7 8
27 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
28 gLog << all << endl;
29 gLog << "Sorry the usage is:" << endl;
30 gLog << " showplot [options] filename" << endl << endl;
31 gLog << " Arguments:" << endl;
32 gLog << " filename Input file containing an MStatusArray" << endl << endl;
33 gLog << " Root Options:" << endl;
34 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
35 gLog << " Options: "<< endl;
36 gLog.Usage();
37 gLog << " -q Quit when job is finished" << endl;
38 gLog << endl;
39 gLog << " Output Options: "<< endl;
40 gLog << " --save-as-ps[=filename] Save plots as postscript" << endl;
41 gLog << " --save-as-gif[=filename] Save plots as gif files" << endl;
42 gLog << " --save-as-C[=filename] Save plots as root scripts" << endl;
43 gLog << " --tab=num Save only tab number num" << endl;
44 gLog << endl;
45 gLog << " --version, -V Show startup message with version number" << endl;
46 gLog << " -?, -h, --help This help" << endl;
47 gLog << endl;
48 gLog << "Description:" << endl;
49 gLog << " Use showplot to display a MStatusArray in an MStatusDisplay." << endl;
50 gLog << " MStatusArrays are typically written by programs showing data" << endl;
51 gLog << " check plots, like callisto." << endl;
52 gLog << endl;
53}
54
55int main(int argc, char **argv)
56{
57 StartUpMessage();
58
59 //
60 // Evaluate arguments
61 //
62 MArgs arg(argc, argv, kTRUE);
63
64 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
65 return 0;
66
67 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
68 {
69 Usage();
70 return -1;
71 }
72
73 gLog.Setup(arg);
74
75 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
76 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
77
78 const Int_t kTab = arg.GetIntAndRemove("--tab=", -1);
79
80 const Bool_t kSaveAsPs = arg.HasOnlyAndRemove("--save-as-ps") || arg.Has("--save-as-ps=");
81 const Bool_t kSaveAsGif = arg.HasOnlyAndRemove("--save-as-gif") || arg.Has("--save-as-gif=");
82 const Bool_t kSaveAsC = arg.HasOnlyAndRemove("--save-as-C") || arg.Has("--save-as-C=");
83
84 TString kNamePs = arg.GetStringAndRemove("--save-as-ps=");
85 TString kNameGif = arg.GetStringAndRemove("--save-as-gif=");
86 TString kNameC = arg.GetStringAndRemove("--save-as-C=");
87
88
89 //
90 // check for the right usage of the program
91 //
92 if (arg.GetNumArguments()!=1)
93 {
94 Usage();
95 return -1;
96 }
97
98 TApplication app("Showplot", &argc, argv);
99 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
100 {
101 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
102 return 1;
103 }
104
105 //
106 // Process filenames
107 //
108 const TString kInput = arg.GetArgumentStr(0);
109
110 if (kNamePs.IsNull() && kSaveAsPs)
111 kNamePs = kInput;
112 if (kNameGif.IsNull() && kSaveAsGif)
113 kNameGif = kInput;
114 if (kNameC.IsNull() && kSaveAsC)
115 kNameC = kInput;
116
117 //
118 // Update frequency by default = 1Hz
119 //
120 MStatusDisplay *d = new MStatusDisplay;
121
122 // From now on each 'Exit' means: Terminate the application
123 d->SetTitle(kInput);
124 d->Open(kInput);
125
126 if (kSaveAsPs)
127 d->SaveAsPS(kTab, kNamePs);
128 if (kSaveAsGif)
129 d->SaveAsGIF(kTab, kNameGif);
130 if (kSaveAsC)
131 d->SaveAsC(kTab, kNameC);
132
133 if (kBatch || kQuit)
134 {
135 delete d;
136 return 0;
137 }
138
139 // From now on each 'Close' means: Terminate the application
140 d->SetBit(MStatusDisplay::kExitLoopOnClose);
141
142 // Wait until the user decides to exit the application
143 app.Run(kFALSE);
144 return 0;
145}
Note: See TracBrowser for help on using the repository browser.