source: trunk/src/Cubes/plots.cc @ 985

Last change on this file since 985 was 985, checked in by MatthewWhiting, 12 years ago

Ticket #148: Enabling output of the spectrum highlighting the detections that have been made, as well as the final objects. This is to replace the moment map output that is not possible in 1D mode. Some functions
have been moved around (from outputSpectra to spectraUtils) and a new class added to plots.hh

File size: 25.4 KB
Line 
1// -----------------------------------------------------------------------
2// plots.cc: Functions defining SpectralPlot and ImagePlot classes.
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 <iostream>
29#include <sstream>
30#include <string>
31#include <math.h>
32#include <cpgplot.h>
33#include <duchamp/param.hh>
34#include <duchamp/duchamp.hh>
35#include <duchamp/Utils/mycpgplot.hh>
36#include <duchamp/Cubes/plots.hh>
37
38using std::stringstream;
39using namespace mycpgplot;
40
41namespace duchamp
42{
43
44  namespace Plot
45  {
46
47    //----------------------------------------------------------
48    // SpectralPlot functions
49    //----------------------------------------------------------
50
51    SpectralPlot::SpectralPlot(){
52      this->paperWidth=a4width/inchToCm - 2*psHoffset;
53      this->aspectRatio = M_SQRT2;
54      this->spectraCount=0;
55      this->numOnPage = 5;
56    }
57
58    SpectralPlot::~SpectralPlot(){}
59
60    SpectralPlot::SpectralPlot(const SpectralPlot& p)
61    {
62      operator=(p);
63    }
64
65    SpectralPlot& SpectralPlot::operator=(const SpectralPlot& p)
66    {
67      if(this==&p) return *this;
68      this->numOnPage = p.numOnPage;
69      this->spectraCount = p.spectraCount; 
70      for(int i=0;i<4;i++) this->mainCoords[i] = p.mainCoords[i];
71      for(int i=0;i<4;i++) this->zoomCoords[i] = p.zoomCoords[i];
72      for(int i=0;i<4;i++) this->mapCoords[i] = p.mapCoords[i];
73      this->paperWidth = p.paperWidth;   
74      this->paperHeight = p.paperHeight;   
75      this->aspectRatio = p.aspectRatio;
76      this->identifier = p.identifier;   
77      return *this;
78    }
79
80    //----------------------------------------------------------
81    int SpectralPlot::setUpPlot(std::string pgDestination)
82    {
83      ///  @details
84      /// Opens the designated pgplot device.  Scales the paper so that
85      /// it fits on an A4 sheet (using known values of the default
86      /// pgplot offsets). 
87      ///
88      /// \param pgDestination The std::string indicating the PGPLOT device to
89      /// be written to.
90      ///
91      /// \return The value returned by mycpgopen. If <= 0, then an error
92      /// has occurred.
93
94      this->paperHeight = this->paperWidth*this->aspectRatio;
95      if(this->paperHeight+2*Plot::psVoffset > Plot::a4height){
96        this->paperHeight = Plot::a4height - 2*Plot::psVoffset;
97        this->paperWidth = this->paperHeight / this->aspectRatio;
98      }
99      this->identifier = mycpgopen(pgDestination);
100      if(this->identifier>0) cpgpap(this->paperWidth, this->aspectRatio);
101      // make paper size to fit on A4.
102      return this->identifier;
103    }
104    //----------------------------------------------------------
105    void SpectralPlot::close()
106    {
107      cpgclos();
108    }
109    //----------------------------------------------------------
110    void SpectralPlot::calcCoords()
111    {
112      /// @details
113      /// Calculates the boundaries for the various boxes, in inches measured
114      ///  from the lower left corner.
115      /// Based on the fact that there are numOnPage spectra shown on each
116      ///  page, going down the page in increasing number (given by
117      ///  SpectralPlot::spectraCount).
118
119      int posOnPage = (this->numOnPage -
120                       (this->spectraCount%this->numOnPage))
121        %this->numOnPage;
122      this->mainCoords[0] = Plot::spMainX1/inchToCm;
123      this->mainCoords[1] = Plot::spMainX2/inchToCm;
124      this->zoomCoords[0] = Plot::spZoomX1/inchToCm;
125      this->zoomCoords[1] = Plot::spZoomX2/inchToCm;
126      this->mainCoords[2] = this->zoomCoords[2] = this->mapCoords[2] =
127        posOnPage*paperHeight/float(this->numOnPage) + Plot::spMainY1/inchToCm;
128      this->mainCoords[3] = this->zoomCoords[3] = this->mapCoords[3] =
129        posOnPage*paperHeight/float(this->numOnPage) + Plot::spMainY2/inchToCm;
130      this->mapCoords[0]  = Plot::spMapX1/inchToCm;
131      this->mapCoords[1]  = this->mapCoords[0] + (this->mapCoords[3]-this->mapCoords[2]);
132    }
133    //----------------------------------------------------------
134    void SpectralPlot::gotoHeader(std::string xlabel)
135    {
136      /// @details
137      /// Calls calcCoords, to calculate correct coordinates for this spectrum.
138      /// Defines the region for the header information, making it centred
139      ///  on the page.
140      /// Also writes the velocity (x axis) label, given by the string argument.
141      /// \param xlabel Label to go on the velocity/spectral axis.
142
143      if(spectraCount%numOnPage==0) cpgpage();
144      spectraCount++;
145      this->calcCoords();
146      cpgvsiz(0., this->paperWidth, this->mainCoords[2], this->mainCoords[3]); 
147      cpgsch(Plot::spLabelSize);
148      cpgmtxt("b",Plot::spXlabelOffset,0.5,0.5,xlabel.c_str());
149    }
150    //----------------------------------------------------------
151    void SpectralPlot::gotoMainSpectrum(float x1, float x2, float y1, float y2, std::string ylabel)
152    {
153      /// @details
154      ///  Defines the region for the main spectrum.
155      ///  Draws the box, with tick marks, and
156      ///   writes the flux (y axis) label, given by the string argument.
157      /// \param x1 Minimum X-coordinate of box.
158      /// \param x2 Maximum X-coordinate of box.
159      /// \param y1 Minimum Y-coordinate of box.
160      /// \param y2 Maximum Y-coordinate of box.
161      /// \param ylabel Label for the flux (Y) axis.
162
163      cpgvsiz(this->mainCoords[0],this->mainCoords[1],
164              this->mainCoords[2],this->mainCoords[3]);
165      cpgsch(Plot::spIndexSize);
166      cpgswin(x1,x2,y1,y2);
167      cpgbox("1bcnst",0.,0,"bcnst1v",0.,0);
168      cpgsch(Plot::spLabelSize);
169      cpgmtxt("l",Plot::spYlabelOffset,0.5,0.5,ylabel.c_str());
170    }
171    //----------------------------------------------------------
172    void SpectralPlot::gotoZoomSpectrum(float x1, float x2, float y1, float y2)
173    {
174      /// @details
175      ///   Defines the region for the zoomed-in part of the spectrum.
176      ///   Draws the box, with special tick marks on the bottom axis.
177      /// \param x1 Minimum X-coordinate of box.
178      /// \param x2 Maximum X-coordinate of box.
179      /// \param y1 Minimum Y-coordinate of box.
180      /// \param y2 Maximum Y-coordinate of box.
181
182      cpgvsiz(this->zoomCoords[0],this->zoomCoords[1],
183              this->zoomCoords[2],this->zoomCoords[3]);
184      cpgsch(Plot::spIndexSize);
185      cpgswin(x1,x2,y1,y2);
186      cpgbox("bc",0.,0,"bcstn1v",0.,0);
187      float lengthL,lengthR,disp,tickpt,step;
188      stringstream label;
189      for(int i=1;i<10;i++){
190        tickpt = x1+(x2-x1)*float(i)/10.;  // spectral coord of the tick
191        switch(i)
192          {
193          case 2:
194          case 8:
195            lengthL = lengthR = 0.5;
196            disp = 0.3 + float(i-2)/6.; // i==2 --> disp=0.3, i==8 --> disp=1.3
197            label.str("");
198            label << tickpt;
199            // do a labelled tick mark
200            cpgtick(x1,y1,x2,y1,float(i)/10.,lengthL,lengthR,
201                    disp, 0., label.str().c_str());
202            break;
203          default:
204            label.str("");
205            lengthL = 0.25;
206            lengthR = 0.;
207            disp = 0.;  // not used in this case, but set it anyway.
208            break;
209          }
210        // first the bottom axis, just the ticks
211        if(fabs(tickpt)<(x2-x1)/1.e4) step = 2.*(x2-x1);
212        else step = tickpt;
213        cpgaxis("",
214                tickpt-0.001*(x2-x1), y1,
215                tickpt+0.001*(x2-x1), y1,
216                tickpt-0.001*(x2-x1), tickpt+0.001*(x2-x1),
217                step, -1, lengthL,lengthR, 0.5, disp, 0.);
218        //and now the top -- no labels, just tick marks
219        cpgtick(x1,y2,x2,y2,float(i)/10.,lengthL,lengthR,0.,0.,"");
220      }
221    }
222    //----------------------------------------------------------
223    void SpectralPlot::gotoMap()
224    {
225      cpgvsiz(this->mapCoords[0],this->mapCoords[1],
226              this->mapCoords[2],this->mapCoords[3]);
227      cpgsch(Plot::spIndexSize);
228    }
229    //----------------------------------------------------------
230    void SpectralPlot::drawVelRange(float v1, float v2)
231    {
232      /// @details
233      /// Draws two vertical lines at the limits of velocity
234      ///  given by the arguments.
235      /// \param v1 Minimum velocity.
236      /// \param v2 Maximum velocity.
237
238      int ci,ls;
239      float dud,min,max;
240      cpgqwin(&dud,&dud,&min,&max);
241      cpgqci(&ci);
242      cpgqls(&ls);
243      cpgsci(DUCHAMP_OBJECT_OUTLINE_COLOUR);
244      cpgsls(DASHED);
245      cpgmove(v1,min);  cpgdraw(v1,max);
246      cpgmove(v2,min);  cpgdraw(v2,max);
247      cpgsci(ci);
248      cpgsls(ls);
249    }
250    //----------------------------------------------------------
251    void SpectralPlot::drawMWRange(float v1, float v2)
252    {
253      ///  @details
254      /// Draws a box showing the extent of channels masked by the
255      ///  Milky Way parameters
256      /// \param v1 Minimum velocity of the Milky Way range.
257      /// \param v2 Maximum velocity of the Milky Way range.
258
259      int ci,fs;
260      float dud,min,max,height;
261      cpgqwin(&dud,&dud,&min,&max);
262      height = max-min;
263      max += 0.01*height;
264      min -= 0.01*height;
265      cpgqci(&ci);
266      cpgqfs(&fs);
267      setDarkGreen();
268      cpgsci(DUCHAMP_MILKY_WAY_COLOUR);
269      cpgsfs(HATCHED);
270      cpgrect(v1,v2,min,max);
271      cpgsfs(OUTLINE);
272      cpgrect(v1,v2,min,max);
273      cpgsci(ci);
274      cpgsfs(fs);
275    }
276    //----------------------------------------------------------
277    // SpectralPlot functions...
278    //----------------------------------------------------------
279    void  SpectralPlot::firstHeaderLine(std::string line)
280    {
281      cpgsch(Plot::spTitleSize);
282      cpgmtxt("t",Plot::spTitleOffset1*Plot::spLabelSize/Plot::spTitleSize,
283              0.5,0.5,line.c_str());
284    }
285    void  SpectralPlot::secondHeaderLine(std::string line)
286    {
287      cpgsch(Plot::spLabelSize);
288      cpgmtxt("t",Plot::spTitleOffset2,0.5,0.5,line.c_str());
289    }
290    void  SpectralPlot::thirdHeaderLine(std::string line)
291    {
292      cpgsch(Plot::spLabelSize);
293      cpgmtxt("t",Plot::spTitleOffset3,0.5,0.5,line.c_str());
294    }
295    void  SpectralPlot::fourthHeaderLine(std::string line)
296    {
297      cpgsch(Plot::spLabelSize);
298      cpgmtxt("t",Plot::spTitleOffset4,0.5,0.5,line.c_str());
299    }
300    void  SpectralPlot::goToPlot(){cpgslct(this->identifier);}
301
302    //----------------------------------------------------------
303    // SimpleSpectralPlot functions
304    //----------------------------------------------------------
305
306    SimpleSpectralPlot::SimpleSpectralPlot(){
307      this->paperWidth=a4width/inchToCm - 2*psHoffset;
308      this->aspectRatio = M_SQRT2/5.;
309    }
310
311    SimpleSpectralPlot::~SimpleSpectralPlot(){}
312
313    SimpleSpectralPlot::SimpleSpectralPlot(const SimpleSpectralPlot& p)
314    {
315      operator=(p);
316    }
317
318    SimpleSpectralPlot& SimpleSpectralPlot::operator=(const SimpleSpectralPlot& p)
319    {
320      if(this==&p) return *this;
321      for(int i=0;i<4;i++) this->mainCoords[i] = p.mainCoords[i];
322      this->paperWidth = p.paperWidth;   
323      this->paperHeight = p.paperHeight;   
324      this->aspectRatio = p.aspectRatio;
325      this->identifier = p.identifier;   
326      return *this;
327    }
328
329    //----------------------------------------------------------
330    int SimpleSpectralPlot::setUpPlot(std::string pgDestination)
331    {
332      ///  @details
333      /// Opens the designated pgplot device.  Scales the paper so that
334      /// it fits on an A4 sheet (using known values of the default
335      /// pgplot offsets). 
336      ///
337      /// \param pgDestination The std::string indicating the PGPLOT device to
338      /// be written to.
339      ///
340      /// \return The value returned by mycpgopen. If <= 0, then an error
341      /// has occurred.
342
343      if(pgDestination == "/xs") this->paperWidth=12.;
344
345      this->paperHeight = this->paperWidth*this->aspectRatio;
346      this->identifier = mycpgopen(pgDestination);
347      if(this->identifier>0) cpgpap(this->paperWidth, this->aspectRatio);
348      // make paper size to fit on A4.
349      float scaling = this->paperWidth*inchToCm / a4width;
350      this->mainCoords[0] = Plot::spMainX1/inchToCm * scaling;
351      this->mainCoords[1] = (Plot::spMapX1+Plot::spMainY2-Plot::spMainY1)/inchToCm * scaling;
352      this->mainCoords[2] = Plot::spMainY1/inchToCm * scaling;
353      this->mainCoords[3] = Plot::spMainY2/inchToCm * scaling;
354      return this->identifier;
355    }
356    //----------------------------------------------------------
357    void SimpleSpectralPlot::close()
358    {
359      cpgclos();
360    }
361    void SimpleSpectralPlot::label(std::string xlabel,std::string ylabel, std::string title)
362    {
363      /// @details
364      /// Calls calcCoords, to calculate correct coordinates for this spectrum.
365      /// Defines the region for the header information, making it centred
366      ///  on the page.
367      /// Also writes the velocity (x axis) label, given by the string argument.
368      /// \param xlabel Label to go on the velocity/spectral axis.
369
370      cpgvsiz(this->mainCoords[0],this->mainCoords[1],this->mainCoords[2],this->mainCoords[3]);
371      cpgsch(2.);
372      cpgmtxt("B",3.,0.5,0.5,xlabel.c_str());
373      cpgmtxt("L",4.,0.5,0.5,ylabel.c_str());
374      cpgmtxt("T",2.,0.5,0.5,title.c_str());
375    }
376    //----------------------------------------------------------
377    void SimpleSpectralPlot::gotoMainSpectrum(float x1, float x2, float y1, float y2)
378    {
379      /// @details
380      ///  Defines the region for the main spectrum.
381      ///  Draws the box, with tick marks, and
382      ///   writes the flux (y axis) label, given by the string argument.
383      /// \param x1 Minimum X-coordinate of box.
384      /// \param x2 Maximum X-coordinate of box.
385      /// \param y1 Minimum Y-coordinate of box.
386      /// \param y2 Maximum Y-coordinate of box.
387      /// \param ylabel Label for the flux (Y) axis.
388
389      cpgvsiz(this->mainCoords[0],this->mainCoords[1],this->mainCoords[2],this->mainCoords[3]);
390      cpgsch(2.);
391      cpgswin(x1,x2,y1,y2);
392      cpgbox("1bcnst",0.,0,"bcnst1v",0.,0);
393    }
394    //----------------------------------------------------------
395    void SimpleSpectralPlot::drawVelRange(float v1, float v2)
396    {
397      /// @details
398      /// Draws two vertical lines at the limits of velocity
399      ///  given by the arguments.
400      /// \param v1 Minimum velocity.
401      /// \param v2 Maximum velocity.
402
403      int ci,ls;
404      float dud,min,max;
405      cpgqwin(&dud,&dud,&min,&max);
406      cpgqci(&ci);
407      cpgqls(&ls);
408      cpgsci(DUCHAMP_OBJECT_OUTLINE_COLOUR);
409      cpgsls(DASHED);
410      cpgmove(v1,min);  cpgdraw(v1,max);
411      cpgmove(v2,min);  cpgdraw(v2,max);
412      cpgsci(ci);
413      cpgsls(ls);
414    }
415    //----------------------------------------------------------
416    void SimpleSpectralPlot::drawMWRange(float v1, float v2)
417    {
418      ///  @details
419      /// Draws a box showing the extent of channels masked by the
420      ///  Milky Way parameters
421      /// \param v1 Minimum velocity of the Milky Way range.
422      /// \param v2 Maximum velocity of the Milky Way range.
423
424      int ci,fs;
425      float dud,min,max,height;
426      cpgqwin(&dud,&dud,&min,&max);
427      height = max-min;
428      max += 0.01*height;
429      min -= 0.01*height;
430      cpgqci(&ci);
431      cpgqfs(&fs);
432      setDarkGreen();
433      cpgsci(DUCHAMP_MILKY_WAY_COLOUR);
434      cpgsfs(HATCHED);
435      cpgrect(v1,v2,min,max);
436      cpgsfs(OUTLINE);
437      cpgrect(v1,v2,min,max);
438      cpgsci(ci);
439      cpgsfs(fs);
440    }
441
442
443    //----------------------------------------------------------
444    //----------------------------------------------------------
445    // ImagePlot functions
446    //----------------------------------------------------------
447
448    ImagePlot::ImagePlot(){
449      this->paperWidth = 7.5;
450      this->maxPaperHeight = 10.;
451      this->marginWidth = 0.8;
452      this->wedgeWidth = 0.7;
453    }
454
455    ImagePlot::~ImagePlot(){}
456
457    ImagePlot::ImagePlot(const ImagePlot& p)
458    {
459      operator=(p);
460    }
461
462    ImagePlot& ImagePlot::operator=(const ImagePlot& p)
463    {
464      if(this==&p) return *this;
465      this->paperWidth = p.paperWidth;   
466      this->maxPaperHeight = p.maxPaperHeight;   
467      this->marginWidth = p.marginWidth;   
468      this->wedgeWidth = p.wedgeWidth;
469      this->imageRatio = p.imageRatio;
470      this->aspectRatio = p.aspectRatio;
471      this->xdim = p.xdim;
472      this->ydim = p.ydim;
473      this->identifier = p.identifier;   
474      return *this;
475    }
476
477    //----------------------------------------------------------
478
479    int ImagePlot::setUpPlot(std::string pgDestination, float x, float y)
480    {
481      /// @details
482      ///  Opens a pgplot device and scales it to the correct shape.
483      ///  In doing so, the dimensions for the image are set, and the required
484      ///   aspect ratios of the image and of the plot are calculated.
485      ///  If the resulting image is going to be tall enough to exceed the
486      ///   maximum height (given the default width), then scale everything
487      ///   down by enough to make the height equal to maxPaperHeight.
488      /// \param pgDestination  The string indicating the PGPLOT device to be
489      ///   written to.
490      /// \param x The length of the X-axis.
491      /// \param y The length of the Y-axis.
492      /// \return The value returned by mycpgopen: if <= 0, then an error
493      ///  has occurred.
494
495      this->xdim = x;
496      this->ydim = y;
497      this->imageRatio= this->ydim / this->xdim;
498      this->aspectRatio =  (this->imageRatio*this->imageWidth() + 2*this->marginWidth)
499        / this->paperWidth;
500      float correction;
501      if((this->imageRatio*this->imageWidth() + 2*this->marginWidth) >
502         this->maxPaperHeight){
503        correction = this->maxPaperHeight /
504          (this->imageRatio*this->imageWidth()+2*this->marginWidth);
505        this->paperWidth *= correction;
506        this->marginWidth *= correction;
507        this->wedgeWidth *= correction;
508      }
509      this->identifier = mycpgopen(pgDestination);
510      if(this->identifier>0) cpgpap(this->paperWidth, this->aspectRatio);
511      return this->identifier;
512    }
513    //----------------------------------------------------------
514    void ImagePlot::close()
515    {
516      cpgclos();
517    }
518    //----------------------------------------------------------
519    void ImagePlot::drawMapBox(float x1, float x2, float y1, float y2,
520                               std::string xlabel, std::string ylabel)
521    {
522      /// @details
523      ///  Defines the region that the box containing the map is to go in,
524      ///  and draws the box with limits given by the arguments.
525      ///  Also writes labels on both X- and Y-axes.
526      /// \param x1 Minimum X-axis value.
527      /// \param x2 Maximum X-axis value.
528      /// \param y1 Minimum Y-axis value.
529      /// \param y2 Maximum Y-axis value.
530      /// \param xlabel The label to be put on the X-axis.
531      /// \param ylabel The label to be put on the Y-axis.
532
533      cpgvsiz(this->marginWidth, this->marginWidth + this->imageWidth(),
534              this->marginWidth, this->marginWidth + (this->imageWidth()*this->imageRatio) );
535      cpgslw(2);
536      cpgswin(x1,x2,y1,y2);
537      cpgbox("bcst",0.,0,"bcst",0.,0);
538      cpgslw(1);
539      cpgbox("bcnst",0.,0,"bcnst",0.,0);
540      cpglab(xlabel.c_str(), ylabel.c_str(), "");
541    }
542    //----------------------------------------------------------
543   
544    void ImagePlot::makeTitle(std::string title)
545    {
546      /// @details
547      ///   Writes the title for the plot, making it centred for the entire
548      ///    plot and not just the map.
549      ///  \param title String with title for plot.
550
551      cpgvstd();
552      cpgmtxt("t", Plot::imTitleOffset, 0.5, 0.5, title.c_str());
553    }
554
555    void  ImagePlot::goToPlot(){cpgslct(this->identifier);}
556
557    float ImagePlot::imageWidth(){
558      return this->paperWidth - 2*this->marginWidth - this->wedgeWidth;
559    }
560
561    float ImagePlot::cmToCoord(float cm){
562      /** \param cm Distance to be converted.*/
563      return (cm/Plot::inchToCm) * this->ydim / (this->imageWidth()*this->imageRatio);
564    }
565
566
567    //----------------------------------------------------------
568    //----------------------------------------------------------
569    // CutoutPlot functions
570    //----------------------------------------------------------
571    //----------------------------------------------------------
572
573    CutoutPlot::CutoutPlot(){
574      this->paperWidth=a4width/inchToCm - 2*psHoffset;
575      this->sourceCount=0;
576      this->numOnPage = 7;
577    }
578
579    CutoutPlot::~CutoutPlot(){}
580
581    CutoutPlot::CutoutPlot(const CutoutPlot& p)
582    {
583      operator=(p);
584    }
585
586    CutoutPlot& CutoutPlot::operator=(const CutoutPlot& p)
587    {
588      if(this==&p) return *this;
589      this->numOnPage = p.numOnPage;
590      this->sourceCount = p.sourceCount; 
591      for(int i=0;i<4;i++) this->mainCoords[i] = p.mainCoords[i];
592      for(int i=0;i<4;i++) this->mapCoords[i] = p.mapCoords[i];
593      this->paperWidth = p.paperWidth;   
594      this->paperHeight = p.paperHeight;   
595      this->identifier = p.identifier;   
596      return *this;
597    }
598
599    //----------------------------------------------------------
600    int CutoutPlot::setUpPlot(std::string pgDestination)
601    {
602      ///  @details
603      /// Opens the designated pgplot device.  Scales the paper so that
604      /// it fits on an A4 sheet (using known values of the default
605      /// pgplot offsets). 
606      ///
607      /// \param pgDestination The std::string indicating the PGPLOT device to
608      /// be written to.
609      ///
610      /// \return The value returned by mycpgopen. If <= 0, then an error
611      /// has occurred.
612
613      this->paperHeight = this->paperWidth*M_SQRT2;
614      if(this->paperHeight+2*Plot::psVoffset > Plot::a4height){
615        this->paperHeight = Plot::a4height - 2*Plot::psVoffset;
616        this->paperWidth = this->paperHeight / M_SQRT2;
617      }
618      this->identifier = mycpgopen(pgDestination);
619      if(this->identifier>0) cpgpap(this->paperWidth, this->paperHeight/this->paperWidth);
620      // make paper size to fit on A4.
621      return this->identifier;
622    }
623    //----------------------------------------------------------
624    void CutoutPlot::calcCoords()
625    {
626      /// @details
627      /// Calculates the boundaries for the various boxes, in inches measured
628      ///  from the lower left corner.
629      /// Based on the fact that there are numOnPage spectra shown on each
630      ///  page, going down the page in increasing number (given by
631      ///  CutoutPlot::spectraCount).
632
633      int posOnPage = (this->numOnPage -
634                       (this->sourceCount%this->numOnPage))
635        %this->numOnPage;
636      this->mainCoords[0] = Plot::cuMainX1/inchToCm;
637      this->mainCoords[1] = Plot::cuMainX2/inchToCm;
638      this->mainCoords[2] = this->mapCoords[2] =
639        posOnPage*paperHeight/float(this->numOnPage) + Plot::cuMainY1/inchToCm;
640      this->mainCoords[3] = this->mapCoords[3] =
641        posOnPage*paperHeight/float(this->numOnPage) + Plot::cuMainY2/inchToCm;
642      this->mapCoords[0]  = Plot::cuMapX1/inchToCm;
643      this->mapCoords[1]  = this->mapCoords[0] + (this->mapCoords[3]-this->mapCoords[2]);
644    }
645    //----------------------------------------------------------
646    void CutoutPlot::gotoHeader()
647    {
648      ///  @details
649      /// Calls calcCoords, to calculate correct coordinates for this spectrum.
650      /// Defines the region for the header information, making it centred
651      ///  on the page.
652      /// Also writes the velocity (x axis) label, given by the string argument.
653      /// \param xlabel Label to go on the velocity/spectral axis.
654
655      if(sourceCount%numOnPage==0) cpgpage();
656      sourceCount++;
657      this->calcCoords();
658      //     cpgvsiz(0., this->paperWidth, this->mainCoords[2], this->mainCoords[3]); 
659      cpgvsiz(this->mainCoords[0], this->mainCoords[1],
660              this->mainCoords[2], this->mainCoords[3]); 
661      cpgsch(Plot::spLabelSize);
662      //   cpgmtxt("b",Plot::spXlabelOffset,0.5,0.5,xlabel.c_str());
663      cpgswin(0.,1.,0.,1.);
664      //    cpgbox("bc",0,0,"bc",0,0);
665    }
666    //----------------------------------------------------------
667
668    void CutoutPlot::gotoMap(){
669      cpgvsiz(this->mapCoords[0],this->mapCoords[1],
670              this->mapCoords[2],this->mapCoords[3]);
671      cpgsch(Plot::spIndexSize);
672    }
673    //----------------------------------------------------------
674    // CutoutPlot functions...
675    //----------------------------------------------------------
676    void  CutoutPlot::firstHeaderLine(std::string line)
677    {
678      cpgsch(Plot::spTitleSize);
679      //     cpgmtxt("t",Plot::spTitleOffset1*Plot::spLabelSize/Plot::spTitleSize,
680      //            0.5,0.5,line.c_str());
681      cpgptxt(0.5,0.8,0.,0.5,line.c_str());
682    }
683    void  CutoutPlot::secondHeaderLine(std::string line)
684    {
685      cpgsch(Plot::spLabelSize);
686      //    cpgmtxt("t",Plot::spTitleOffset2,0.5,0.5,line.c_str());
687      cpgptxt(0.5,0.6,0.,0.5,line.c_str());
688    }
689    void  CutoutPlot::thirdHeaderLine(std::string line)
690    {
691      cpgsch(Plot::spLabelSize);
692      //    cpgmtxt("t",Plot::spTitleOffset3,0.5,0.5,line.c_str());
693      cpgptxt(0.5,0.4,0.,0.5,line.c_str());
694    }
695    void  CutoutPlot::fourthHeaderLine(std::string line)
696    {
697      cpgsch(Plot::spLabelSize);
698      //    cpgmtxt("t",Plot::spTitleOffset4,0.5,0.5,line.c_str());
699      cpgptxt(0.5,0.2,0.,0.5,line.c_str());
700    }
701    void  CutoutPlot::goToPlot(){cpgslct(this->identifier);}
702
703  }
704
705}
Note: See TracBrowser for help on using the repository browser.