source: trunk/test/graph.cc @ 1325

Last change on this file since 1325 was 1325, checked in by Peter Johansson, 10 years ago

use reverse iterator instead of reversing the range

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1// $Id: graph.cc 1325 2011-01-23 07:22:57Z peter $
2
3/*
4  Copyright (C) 2010 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Suite.h"
23
24#include "lib/Graph.h"
25#include "lib/Vector.h"
26
27#include <cstdlib>
28#include <ostream>
29
30#include <plplot/plplotP.h>
31#include <plplot/qsastime.h>
32
33using namespace theplu::svndigest;
34
35void test_graph(const std::string format, test::Suite& suite);
36void test_graph__(const std::string format, test::Suite& suite);
37
38int main(int argc, char* argv[])
39{
40  test::Suite suite(argc, argv);
41
42#ifndef HAVE_PLPLOT
43  suite.out() << "no plplot: skip test\n";
44  exit(EXIT_SKIP);
45#endif
46
47  test_graph("svg", suite);
48  // Need to create an instance of Graph (plstream) since there is a
49  // bug in plplot with dynamic loading of runtime libraries. The
50  // issue is reported in the plplot issue tracking system
51  // https://sf.net/tracker/?func=detail&aid=3009045&group_id=2915&atid=102915
52  // and as http://dev.thep.lu.se/svndigest/ticket/472. Simply remove
53  // this comment and the next line of code when plplot developers
54  // fixes their bug.
55  //
56  // Omitting the dummy instance will cause segmentation fault.
57  Graph dummy_never_used("/dev/null", "png");
58  test_graph("png", suite);
59  test_graph("pdf", suite);
60
61  Graph graph("plot.png", "png");
62
63  double vpwxmi = 40 * 365.25 * 24 * 60 * 60; 
64  double vpwxma = 44 * 365.25 * 24 * 60 * 60; 
65  double xtick1 = 0;
66  int nxsub1 = 0;
67  bool ldx = true;
68  pldtik( vpwxmi, vpwxma, &xtick1, &nxsub1, ldx );
69  std::cout << "xticks: " << xtick1 << std::endl;
70  std::cout << "xticks days: " << xtick1/60/60/24 << std::endl;
71
72  double factor=0;
73  double tstart=0;
74  double sec   = 0.;
75  int min   = 0;
76  int hour  = 0;
77  int day   = 0;
78  int month = 0;
79  int year;
80
81  std::cout << "vpwxmi: " << vpwxmi << "\n";
82
83  plbtime( &year, &month, &day, &hour, &min, &sec, vpwxmi);
84  std::cout << year << "-" << month << "-" << day << " " << hour << "\n";
85
86  sec   = 0.;
87  min   = 0;
88  hour  = 0;
89  day   = 0;
90  month = 0;
91  plctime(year, month, day, hour, min, sec, &tstart);
92
93  std::cout << "tstart: " << tstart << "\n";
94
95  std::cout << "vpwxmi-tstart: " << (vpwxmi-tstart)/3600 << "\n";
96
97  pldtfac( vpwxmi, vpwxma, &factor, &tstart );
98  std::cout << "tstart: " << tstart << "\n";
99  std::cout << "factor: " << factor/60/60/24 << "\n";
100
101  plbtime( &year, &month, &day, &hour, &min, &sec, tstart);
102  std::cout << year << "-" << month << "-" << day << " " << hour
103            << " " << min << " " << sec << "\n";
104
105  plbtime( &year, &month, &day, &hour, &min, &sec, tstart+3600);
106  std::cout << year << "-" << month << "-" << day << " " << hour
107            << " " << min << " " << sec << "\n";
108
109  plbtime( &year, &month, &day, &hour, &min, &sec, tstart+3600*24);
110  std::cout << year << "-" << month << "-" << day << " " << hour
111            << " " << min << " " << sec << "\n";
112
113 
114
115  return suite.exit_status();
116}
117
118
119void test_graph(const std::string format, test::Suite& suite)
120{
121  suite.out() << "testing " << format << std::endl;
122  for (size_t i=0; i<20; ++i)
123    test_graph__(format, suite);
124}
125
126
127void test_graph__(const std::string format, test::Suite& suite)
128{
129  std::string filename("plot.");
130  filename+=format;
131  Graph graph(filename, format);
132  graph.ymax(10);
133  graph.current_color(255, 0, 0);
134  SumVector data;
135  graph.rev_max(100);
136  data.set(99,1);
137  graph.plot(data, "label", 1);
138}
Note: See TracBrowser for help on using the repository browser.