1 | // ----------------------------------------------------------------------- |
---|
2 | // mycpgplot.cc: Various useful functions for use with PGPLOT. |
---|
3 | // ----------------------------------------------------------------------- |
---|
4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
5 | // |
---|
6 | // This program is free software; you can redistribute it and/or modify it |
---|
7 | // under the terms of the GNU General Public License as published by the |
---|
8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
9 | // option) any later version. |
---|
10 | // |
---|
11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
14 | // for more details. |
---|
15 | // |
---|
16 | // You should have received a copy of the GNU General Public License |
---|
17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
19 | // |
---|
20 | // Correspondence concerning Duchamp may be directed to: |
---|
21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
22 | // Postal address: Dr. Matthew Whiting |
---|
23 | // Australia Telescope National Facility, CSIRO |
---|
24 | // PO Box 76 |
---|
25 | // Epping NSW 1710 |
---|
26 | // AUSTRALIA |
---|
27 | // ----------------------------------------------------------------------- |
---|
28 | #include <string> |
---|
29 | #include <cpgplot.h> |
---|
30 | #include <duchamp/Utils/mycpgplot.hh> |
---|
31 | |
---|
32 | namespace mycpgplot |
---|
33 | { |
---|
34 | |
---|
35 | int cpgIsPS() |
---|
36 | { |
---|
37 | /** |
---|
38 | * A front-end to cpgqinf, that tests whether the device is using a |
---|
39 | * postscript (by which we mean "hardcopy") device |
---|
40 | */ |
---|
41 | char answer[50]; |
---|
42 | int answer_len = sizeof(answer); |
---|
43 | cpgqinf("TYPE", answer, &answer_len); |
---|
44 | return ((answer[answer_len-2]=='P')&&((answer[answer_len-1]=='S'))); |
---|
45 | } |
---|
46 | |
---|
47 | void setDarkGreen(){ |
---|
48 | cpgscr(DARKGREEN,0.,0.7,0.); |
---|
49 | } |
---|
50 | |
---|
51 | void setWCSGreen(){ |
---|
52 | cpgscr(WCSGREEN,0.3,0.5,0.3); |
---|
53 | } |
---|
54 | |
---|
55 | int mycpgopen(std::string device) |
---|
56 | { |
---|
57 | /** |
---|
58 | * This function opens the requested device using cpgopen. |
---|
59 | * |
---|
60 | * It also defines both the new colours DARKGREEN and WCSGREEN, |
---|
61 | * for later use so that they don't have to be defined manually. |
---|
62 | * |
---|
63 | * \param device The PGPLOT device to be opened. |
---|
64 | * \return The return value of cpgopen. |
---|
65 | */ |
---|
66 | int status = cpgopen(device.c_str()); |
---|
67 | if(status>0){ |
---|
68 | setDarkGreen(); |
---|
69 | setWCSGreen(); |
---|
70 | } |
---|
71 | return status; |
---|
72 | } |
---|
73 | |
---|
74 | void setWhite(){ |
---|
75 | /** |
---|
76 | * Uses cpgIsPS() to determine whether a device is a postscript |
---|
77 | * one. If so, we use the BACKGND colour (ie. 0), otherwise use |
---|
78 | * FOREGND (1). |
---|
79 | */ |
---|
80 | if(cpgIsPS()) cpgsci(BACKGND); |
---|
81 | else cpgsci(FOREGND); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | void setBlack(){ |
---|
86 | /** |
---|
87 | * Uses cpgIsPS() to determine whether a device is a postscript |
---|
88 | * one. If so, we use the FOREGND colour (ie. 1), otherwise use |
---|
89 | * BACKGND (0). |
---|
90 | */ |
---|
91 | if(cpgIsPS()) cpgsci(FOREGND); |
---|
92 | else cpgsci(BACKGND); |
---|
93 | } |
---|
94 | |
---|
95 | } |
---|