source: trunk/src/Detection/columns.cc @ 521

Last change on this file since 521 was 491, checked in by MatthewWhiting, 16 years ago

Some changes prompted by askapsoft development.

File size: 24.5 KB
Line 
1// -----------------------------------------------------------------------
2// columns.cc: Define a set of columns for Duchamp output.
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
31#include <math.h>
32#include <duchamp/duchamp.hh>
33#include <duchamp/fitsHeader.hh>
34#include <vector>
35#include <string>
36#include <duchamp/Detection/detection.hh>
37#include <duchamp/Detection/columns.hh>
38
39namespace duchamp
40{
41
42  namespace Column
43  {
44
45
46    Col::Col()
47    {
48      /** Set the default values for the parameters. */
49      this->width=1;
50      this->precision=0;
51      this->name=" ";
52      this->units=" ";
53      this->type=UNKNOWN;
54    }
55
56    Col::~Col(){}
57
58    Col::Col(const Col& c)
59    {
60      operator=(c);
61    }
62
63    Col& Col::operator=(const Col& c)
64    {
65      if(this==&c) return *this;
66      this->width = c.width;
67      this->precision = c.precision;
68      this->name = c.name;
69      this->units = c.units;
70      this->type = c.type;
71      return *this;
72    }
73
74    Col::Col(int num, int prec)
75    {
76      /**
77       * A specialised constructor that defines one of the default
78       *  columns, as defined in the Column namespace
79       * \param num The number of the column to be constructed.
80       *            Corresponds to the order of the columns in the const
81       *            arrays in the Column namespace.
82       * \param prec The precision to use, if not the default. A value
83       * <0 or no value given results in the default being used.
84       */
85      if((num>=0)&&(num<numColumns)){
86        this->width     = defaultWidth[num];
87        if(prec<0) this->precision = defaultPrec[num];
88        else this->precision = prec;
89        this->name      = defaultName[num];
90        this->units     = defaultUnits[num];
91        this->type = COLNAME(num);
92      }
93      else{
94        std::stringstream errmsg;
95        errmsg << "Incorrect value for Col(num) --> num="<<num
96               << ", should be between 0 and " << numColumns-1 << ".\n";
97        duchampError("Column constructor", errmsg.str());
98        this->width = 1;
99        this->precision = 0;
100        this->name = " ";
101        this->units = " ";
102        this->type=UNKNOWN;
103      }
104    }
105
106    //------------------------------------------------------------
107    void Col::printTitle(std::ostream &stream)
108    {
109      stream << std::setw(this->width)
110             << std::setfill(' ')
111             << this->name;
112    }
113
114    void Col::printUnits(std::ostream &stream)
115    {
116      stream << std::setw(this->width)
117             << std::setfill(' ')
118             << this->units;
119    }
120 
121    void Col::printDash (std::ostream &stream)
122    {
123      stream << std::setw(this->width)
124             << std::setfill('-')
125             << ""
126             << std::setfill(' ');
127    }
128
129    void Col::printBlank(std::ostream &stream)
130    {
131      stream << std::setw(this->width)
132             << std::setfill(' ')
133             << "";
134    }
135 
136    template <class T> void Col::printEntry(std::ostream &stream, T value)
137    {
138      /**
139       *  \param stream Where the printing is done.
140       *  \param value  The value to be printed.
141       */
142      stream << std::setprecision(this->precision)
143             << std::setw(this->width)
144             << std::setfill(' ')
145             << value;
146    }
147    template void Col::printEntry<int>(std::ostream &stream, int value);
148    template void Col::printEntry<long>(std::ostream &stream, long value);
149    template void Col::printEntry<unsigned>(std::ostream &stream, unsigned value);
150    template void Col::printEntry<float>(std::ostream &stream, float value);
151    template void Col::printEntry<double>(std::ostream &stream, double value);
152    template void Col::printEntry<std::string>(std::ostream &stream, std::string value);
153
154 
155    bool Col::doCol(std::string tableType, bool flagFint)
156    {
157      /**
158       *  Uses the info in the isFile etc arrays to determine whether
159       *  a given column, referenced by the enumeration COLNAME, is
160       *  used for a given table type.
161       * \param tableType The type of table: one of file, screen, log, votable.
162       * \param flagFint Whether to use FINT (true) or FTOT
163       * (false). This defaults to true, so need not be given. It only
164       * applies to the screen and votable cases -- both are written for the
165       * results file case.
166       * \return True if column is used for given table type. False
167       * otherwise. False if tableType not one of four listed.
168       */
169     
170      if(tableType == "file") return isFile[this->type];
171      else if(tableType == "screen"){
172        if(flagFint && this->type==FTOT) return false;
173        if(!flagFint && this->type==FINT) return false;
174        return isScreen[this->type];
175      }
176      else if(tableType == "log") return isLog[this->type];
177      else if(tableType == "votable"){
178        if(flagFint && this->type==FTOT) return false;
179        if(!flagFint && this->type==FINT) return false;
180        return isVOTable[this->type];
181      }
182      else return false;
183    }
184
185 
186
187    std::vector<Col> getFullColSet(std::vector<Detection> &objectList,
188                                   FitsHeader &head)
189    {
190      /**
191       *  A function that returns a std::vector of Col objects containing
192       *  information on the columns necessary for output to the results
193       *  file:
194       *    Obj#,NAME,X,Y,Z,RA,DEC,VEL,w_RA,w_DEC,w_VEL,F_tot,F_int,F_peak,
195       *                X1,X2,Y1,Y2,Z1,Z2,Npix,Flag,
196       *                XAV,YAV,ZAV,XCENT,YCENT,ZCENT,XPEAK,YPEAK,ZPEAK
197       *
198       *   Each object in the provided objectList is checked to see if it
199       *   requires any column to be widened, or for that column to have
200       *   its precision increased.
201       *
202       *   Both Ftot and Fint are provided -- it is up to the calling
203       *   function to determine which to use.
204       *
205       * \param objectList A std::vector list of Detection objects that the
206       * columns need to fit.
207       * \param head The FitsHeader object defining the World Coordinate
208       * System.
209       * \return A std::vector list of Col definitions.
210       */
211
212      std::vector<Col> newset;
213
214      // desired precisions for fluxes, velocities and SNR value
215      int precVel,precFlux,precSNR;
216      if(objectList.size()>0){
217        precVel=objectList[0].getVelPrec();
218        precFlux=objectList[0].getFpeakPrec(); // same as FintPrec at this point.
219        precSNR=objectList[0].getSNRPrec();
220      }
221      else {
222        precVel = prVEL;
223        precFlux = prFLUX;
224        precSNR = prSNR;
225      }
226
227      // set up the default columns
228      newset.push_back( Col(NUM) );
229      newset.push_back( Col(NAME) );
230      newset.push_back( Col(X) );
231      newset.push_back( Col(Y) );
232      newset.push_back( Col(Z) );
233      newset.push_back( Col(RA) );
234      newset.push_back( Col(DEC) );
235      newset.push_back( Col(RAJD) );
236      newset.push_back( Col(DECJD) );
237      newset.push_back( Col(VEL, precVel) );
238      newset.push_back( Col(WRA) );
239      newset.push_back( Col(WDEC) );
240      newset.push_back( Col(W50, precVel) );
241      newset.push_back( Col(W20, precVel) );
242      newset.push_back( Col(WVEL, precVel) );
243      newset.push_back( Col(FINT, precFlux) );
244      newset.push_back( Col(FTOT, precFlux) );
245      newset.push_back( Col(FPEAK, precFlux) );
246      newset.push_back( Col(SNRPEAK, precSNR) );
247      newset.push_back( Col(X1) );
248      newset.push_back( Col(X2) );
249      newset.push_back( Col(Y1) );
250      newset.push_back( Col(Y2) );
251      newset.push_back( Col(Z1) );
252      newset.push_back( Col(Z2) );
253      newset.push_back( Col(NPIX) );
254      newset.push_back( Col(FLAG) );
255      newset.push_back( Col(XAV) );
256      newset.push_back( Col(YAV) );
257      newset.push_back( Col(ZAV) );
258      newset.push_back( Col(XCENT) );
259      newset.push_back( Col(YCENT) );
260      newset.push_back( Col(ZCENT) );
261      newset.push_back( Col(XPEAK) );
262      newset.push_back( Col(YPEAK) );
263      newset.push_back( Col(ZPEAK) );
264
265
266      // Now test each object against each new column
267      for( int obj = 0; obj < objectList.size(); obj++){
268        std::string tempstr;
269        int tempwidth;
270        float val,minval;
271
272        // Obj#
273        tempwidth = int( log10(objectList[obj].getID()) + 1) + 1;
274        for(int i=newset[NUM].getWidth();i<tempwidth;i++) newset[NUM].widen();
275
276        // Name
277        tempwidth = objectList[obj].getName().size() + 1;
278        for(int i=newset[NAME].getWidth();i<tempwidth;i++) newset[NAME].widen();
279
280        // X position
281        val = objectList[obj].getXcentre() + objectList[obj].getXOffset();
282        if((val<1.)&&(val>0.)){
283          minval = pow(10, -1. * (newset[X].getPrecision()+1));
284          if(val < minval) newset[X].upPrec();
285        }
286        tempwidth = int( log10(val) + 1) + newset[X].getPrecision() + 2;
287        for(int i=newset[X].getWidth();i<tempwidth;i++) newset[X].widen();
288        // Y position
289        val = objectList[obj].getYcentre() + objectList[obj].getYOffset();
290        if((val<1.)&&(val>0.)){
291          minval = pow(10, -1. * (newset[Y].getPrecision()+1));
292          if(val < minval) newset[Y].upPrec();
293        }
294        tempwidth = int( log10(val) + 1) + newset[Y].getPrecision() + 2;
295        for(int i=newset[Y].getWidth();i<tempwidth;i++) newset[Y].widen();
296        // Z position
297        val = objectList[obj].getZcentre() + objectList[obj].getZOffset();
298        if((val<1.)&&(val>0.)){
299          minval = pow(10, -1. * (newset[Z].getPrecision()+1));
300          if((val>0.)&&(val < minval)) newset[Z].upPrec();
301        }
302        tempwidth = int( log10(val) + 1) + newset[Z].getPrecision() + 2;
303        for(int i=newset[Z].getWidth();i<tempwidth;i++) newset[Z].widen();
304
305        if(head.isWCS()){ 
306          // RA -- assign correct title. Check width but should be ok by definition
307          tempstr = head.WCS().lngtyp;
308          newset[RA].setName(tempstr);
309          tempwidth = objectList[obj].getRAs().size() + 1;
310          for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen();
311     
312          // Dec -- assign correct title. Check width, should be ok by definition
313          tempstr = head.WCS().lattyp;
314          newset[DEC].setName(tempstr);
315          tempwidth = objectList[obj].getDecs().size() + 1;
316          for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen();
317
318          // RA decimal degrees -- assign correct title. Check width but should be OK
319          tempstr = head.WCS().lngtyp;
320          newset[RAJD].setName(tempstr);
321          val = objectList[obj].getRA();
322          tempwidth = int( log10(fabs(val)) + 1) + newset[RAJD].getPrecision() + 2;
323          for(int i=newset[RAJD].getWidth();i<tempwidth;i++) newset[RAJD].widen();
324     
325          // Dec decimal degrees -- assign correct title. Check width but should be OK
326          tempstr = head.WCS().lattyp;
327          newset[DECJD].setName(tempstr);
328          val = objectList[obj].getDec();
329          tempwidth = int( log10(fabs(val)) + 1) + newset[DECJD].getPrecision() + 2;
330          for(int i=newset[DECJD].getWidth();i<tempwidth;i++) newset[DECJD].widen();
331
332          // Vel -- check width, title and units.
333          //if(head.isSpecOK()){
334          if(head.canUseThirdAxis()){
335            if(head.WCS().spec < 0)  // if it's not a spectral axis
336              newset[VEL].setName( head.WCS().ctype[2] );
337//          else if(head.WCS().restfrq == 0) // using frequency, not velocity
338            else if(head.getSpectralDescription()==duchamp::duchampSpectralDescription[FREQUENCY]) // using frequency, not velocity
339              newset[VEL].setName("FREQ");
340            if(head.getSpectralUnits().size()>0)
341              newset[VEL].setUnits("[" + head.getSpectralUnits() + "]");
342            tempwidth = newset[VEL].getUnits().size() + 1;
343            for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen();
344       
345            val = objectList[obj].getVel();
346            if((fabs(val) < 1.)&&(val>0.)){
347              minval = pow(10, -1. * (newset[VEL].getPrecision()+1));
348              if(val < minval) newset[VEL].upPrec();
349            }
350            tempwidth = int(log10(fabs(val)) + 1) + newset[VEL].getPrecision() + 2;
351            if(val<0) tempwidth++;
352            for(int i=newset[VEL].getWidth();i<tempwidth;i++) newset[VEL].widen();
353          }
354
355          // w_RA -- check width & title. leave units for the moment.
356          tempwidth = newset[RA].getUnits().size() + 1;
357          for(int i=newset[RA].getWidth();i<tempwidth;i++) newset[RA].widen();
358          val = objectList[obj].getRAWidth();
359          if((fabs(val) < 1.)&&(val>0.)){
360            minval = pow(10, -1. * (newset[WRA].getPrecision()+1));
361            if(val < minval) newset[WRA].upPrec();
362          }
363          tempwidth = int( log10(fabs(val)) + 1) + newset[WRA].getPrecision() + 2;
364          if(val<0) tempwidth++;
365          for(int i=newset[WRA].getWidth();i<tempwidth;i++) newset[WRA].widen();
366
367          // w_DEC -- check width & title. leave units for the moment.
368          tempwidth = newset[DEC].getUnits().size() + 1;
369          for(int i=newset[DEC].getWidth();i<tempwidth;i++) newset[DEC].widen();
370          val = objectList[obj].getDecWidth();
371          if((fabs(val) < 1.)&&(val>0.)){
372            minval = pow(10, -1. * (newset[WDEC].getPrecision()+1));
373            if(val < minval) newset[WDEC].upPrec();
374          }
375          tempwidth = int( log10(fabs(val)) + 1) + newset[WDEC].getPrecision() + 2;
376          if(val<0) tempwidth++;
377          for(int i=newset[WDEC].getWidth();i<tempwidth;i++) newset[WDEC].widen();
378
379          // w_50 -- check width, title and units.
380          if(head.canUseThirdAxis()){
381            if(head.getSpectralUnits().size()>0)
382              newset[W50].setUnits("[" + head.getSpectralUnits() + "]");
383            tempwidth = newset[W50].getUnits().size() + 1;
384            for(int i=newset[W50].getWidth();i<tempwidth;i++) newset[W50].widen();
385            val = objectList[obj].getW50();
386            if((fabs(val) < 1.)&&(val>0.)){
387              minval = pow(10, -1. * (newset[W50].getPrecision()+1));
388              if(val < minval) newset[W50].upPrec();
389            }
390            tempwidth = int( log10(fabs(val)) + 1) + newset[W50].getPrecision() + 2;
391            if(val<0) tempwidth++;
392            for(int i=newset[W50].getWidth();i<tempwidth;i++) newset[W50].widen();
393          }
394
395          // w_20 -- check width, title and units.
396          if(head.canUseThirdAxis()){
397            if(head.getSpectralUnits().size()>0)
398              newset[W20].setUnits("[" + head.getSpectralUnits() + "]");
399            tempwidth = newset[W20].getUnits().size() + 1;
400            for(int i=newset[W20].getWidth();i<tempwidth;i++)newset[W20].widen();
401            val = objectList[obj].getW20();
402            if((fabs(val) < 1.)&&(val>0.)){
403              minval = pow(10, -1. * (newset[W20].getPrecision()+1));
404              if(val < minval) newset[W20].upPrec();
405            }
406            tempwidth = int( log10(fabs(val)) + 1) + newset[W20].getPrecision() + 2;
407            if(val<0) tempwidth++;
408            for(int i=newset[W20].getWidth();i<tempwidth;i++) newset[W20].widen();
409          }
410
411          // w_Vel -- check width, title and units.
412          if(head.canUseThirdAxis()){
413            if(head.WCS().spec < 0) // if it's not a spectral axis
414              newset[WVEL].setName( std::string("w_") + head.WCS().ctype[2] );
415//          else if(head.WCS().restfrq == 0) // using frequency, not velocity
416            else if(head.getSpectralDescription()==duchamp::duchampSpectralDescription[FREQUENCY]) // using frequency, not velocity
417              newset[WVEL].setName("w_FREQ");
418            if(head.getSpectralUnits().size()>0)
419              newset[WVEL].setUnits("[" + head.getSpectralUnits() + "]");
420            tempwidth = newset[WVEL].getUnits().size() + 1;
421            for(int i=newset[WVEL].getWidth();i<tempwidth;i++)newset[WVEL].widen();
422            tempwidth = newset[WVEL].getName().size() + 1;
423            for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen();
424            val = objectList[obj].getVelWidth();
425            if((fabs(val) < 1.)&&(val>0.)){
426              minval = pow(10, -1. * (newset[WVEL].getPrecision()+1));
427              if(val < minval) newset[WVEL].upPrec();
428            }
429            tempwidth = int( log10(fabs(val)) + 1) + newset[WVEL].getPrecision() + 2;
430            if(val<0) tempwidth++;
431            for(int i=newset[WVEL].getWidth();i<tempwidth;i++) newset[WVEL].widen();
432          }
433
434          // F_int -- check width & units
435          if(head.getIntFluxUnits().size()>0)
436            newset[FINT].setUnits("[" + head.getIntFluxUnits() + "]");
437          tempwidth = newset[FINT].getUnits().size() + 1;
438          for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen();
439          val = objectList[obj].getIntegFlux();
440          if((fabs(val) < 1.)// &&(val>0.)
441             ){
442            int minprec = int(fabs(log10(fabs(val))))+2;
443            for(int i=newset[FINT].getPrecision();i<minprec;i++) newset[FINT].upPrec();
444          }
445          tempwidth = int( log10(fabs(val)) + 1) + newset[FINT].getPrecision() + 2;
446          if(val<0) tempwidth++;
447          for(int i=newset[FINT].getWidth();i<tempwidth;i++) newset[FINT].widen();
448     
449        }
450
451        // F_tot
452        newset[FTOT].setUnits("[" + head.getFluxUnits() + "]");
453        tempwidth = newset[FTOT].getUnits().size() + 1;
454        for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen();
455        val = objectList[obj].getTotalFlux();
456        //     std::cerr << val << "\n";
457        if((fabs(val) < 1.)// &&(val>0.)
458           ){
459          int minprec = int(fabs(log10(fabs(val))))+2;
460          for(int i=newset[FTOT].getPrecision();i<minprec;i++) newset[FTOT].upPrec();
461        }
462        tempwidth = int( log10(fabs(val)) + 1) + newset[FTOT].getPrecision() + 2;
463        if(val<0) tempwidth++;
464        for(int i=newset[FTOT].getWidth();i<tempwidth;i++) newset[FTOT].widen();
465
466        // F_peak
467        newset[FPEAK].setUnits("[" + head.getFluxUnits() + "]");
468        tempwidth = newset[FPEAK].getUnits().size() + 1;
469        for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen();
470        val = objectList[obj].getPeakFlux();
471        if((fabs(val) < 1.)// &&(val>0.)
472           ){
473          int minprec = int(fabs(log10(fabs(val))))+2;
474          for(int i=newset[FPEAK].getPrecision();i<minprec;i++) newset[FPEAK].upPrec();
475        }
476        tempwidth = int( log10(fabs(val)) + 1) + newset[FPEAK].getPrecision() + 2;
477        if(val<0) tempwidth++;
478        for(int i=newset[FPEAK].getWidth();i<tempwidth;i++) newset[FPEAK].widen();
479
480        // S/N_peak
481        val = objectList[obj].getPeakSNR();
482        if((fabs(val) < 1.)&&(val>0.)){
483          minval = pow(10, -1. * (newset[SNRPEAK].getPrecision()+1));
484          if(val < minval) newset[SNRPEAK].upPrec();
485        }
486        tempwidth = int( log10(fabs(val)) + 1) + newset[SNRPEAK].getPrecision() +2;
487        if(val<0) tempwidth++;
488        for(int i=newset[SNRPEAK].getWidth();i<tempwidth;i++) newset[SNRPEAK].widen();
489
490        // X1 position
491        val = objectList[obj].getXmin() + objectList[obj].getXOffset();
492        tempwidth = int( log10(val) + 1) + newset[X1].getPrecision() + 1;
493        for(int i=newset[X1].getWidth();i<tempwidth;i++) newset[X1].widen();
494        // X2 position
495        val = objectList[obj].getXmax() + objectList[obj].getXOffset();
496        tempwidth = int( log10(val) + 1) + newset[X2].getPrecision() + 1;
497        for(int i=newset[X2].getWidth();i<tempwidth;i++) newset[X2].widen();
498        // Y1 position
499        val = objectList[obj].getYmin() + objectList[obj].getYOffset();
500        tempwidth = int( log10(val) + 1) + newset[Y1].getPrecision() + 1;
501        for(int i=newset[Y1].getWidth();i<tempwidth;i++) newset[Y1].widen();
502        // Y2 position
503        val = objectList[obj].getYmax() + objectList[obj].getYOffset();
504        tempwidth = int( log10(val) + 1) + newset[Y2].getPrecision() + 1;
505        for(int i=newset[Y2].getWidth();i<tempwidth;i++) newset[Y2].widen();
506        // Z1 position
507        val = objectList[obj].getZmin() + objectList[obj].getZOffset();
508        tempwidth = int( log10(val) + 1) + newset[Z1].getPrecision() + 1;
509        for(int i=newset[Z1].getWidth();i<tempwidth;i++) newset[Z1].widen();
510        // Z2 position
511        val = objectList[obj].getZmax() + objectList[obj].getZOffset();
512        tempwidth = int( log10(val) + 1) + newset[Z2].getPrecision() + 1;
513        for(int i=newset[Z2].getWidth();i<tempwidth;i++) newset[Z2].widen();
514
515        // Npix
516        tempwidth = int( log10(objectList[obj].getSize()) + 1) +
517          newset[NPIX].getPrecision() + 1;
518        for(int i=newset[NPIX].getWidth();i<tempwidth;i++) newset[NPIX].widen();
519   
520        // average X position
521        val = objectList[obj].getXAverage() + objectList[obj].getXOffset();
522        if((val<1.)&&(val>0.)){
523          minval = pow(10, -1. * (newset[XAV].getPrecision()+1));
524          if(val < minval) newset[XAV].upPrec();
525        }
526        tempwidth = int( log10(val) + 1) + newset[XAV].getPrecision() + 2;
527        for(int i=newset[XAV].getWidth();i<tempwidth;i++) newset[XAV].widen();
528        // average Y position
529        val = objectList[obj].getYAverage() + objectList[obj].getYOffset();
530        if((val<1.)&&(val>0.)){
531          minval = pow(10, -1. * (newset[YAV].getPrecision()+1));
532          if(val < minval) newset[YAV].upPrec();
533        }
534        tempwidth = int( log10(val) + 1) + newset[YAV].getPrecision() + 2;
535        for(int i=newset[YAV].getWidth();i<tempwidth;i++) newset[YAV].widen();
536        // average Z position
537        val = objectList[obj].getZAverage() + objectList[obj].getZOffset();
538        if((val<1.)&&(val>0.)){
539          minval = pow(10, -1. * (newset[ZAV].getPrecision()+1));
540          if((val>0.)&&(val < minval)) newset[ZAV].upPrec();
541        }
542        tempwidth = int( log10(val) + 1) + newset[ZAV].getPrecision() + 2;
543        for(int i=newset[ZAV].getWidth();i<tempwidth;i++) newset[ZAV].widen();
544   
545        // X position of centroid
546        val = objectList[obj].getXCentroid() + objectList[obj].getXOffset();
547        if((val<1.)&&(val>0.)){
548          minval = pow(10, -1. * (newset[XCENT].getPrecision()+1));
549          if(val < minval) newset[XCENT].upPrec();
550        }
551        tempwidth = int( log10(val) + 1) + newset[XCENT].getPrecision() + 2;
552        for(int i=newset[XCENT].getWidth();i<tempwidth;i++) newset[XCENT].widen();
553        // Y position of centroid
554        val = objectList[obj].getYCentroid() + objectList[obj].getYOffset();
555        if((val<1.)&&(val>0.)){
556          minval = pow(10, -1. * (newset[YCENT].getPrecision()+1));
557          if(val < minval) newset[YCENT].upPrec();
558        }
559        tempwidth = int( log10(val) + 1) + newset[YCENT].getPrecision() + 2;
560        for(int i=newset[YCENT].getWidth();i<tempwidth;i++) newset[YCENT].widen();
561        // Z position of centroid
562        val = objectList[obj].getZCentroid() + objectList[obj].getZOffset();
563        if((val<1.)&&(val>0.)){
564          minval = pow(10, -1. * (newset[ZCENT].getPrecision()+1));
565          if((val>0.)&&(val < minval)) newset[ZCENT].upPrec();
566        }
567        tempwidth = int( log10(val) + 1) + newset[ZCENT].getPrecision() + 2;
568        for(int i=newset[ZCENT].getWidth();i<tempwidth;i++) newset[ZCENT].widen();
569   
570        // X position of peak flux
571        val = objectList[obj].getXPeak() + objectList[obj].getXOffset();
572        if((val<1.)&&(val>0.)){
573          minval = pow(10, -1. * (newset[XPEAK].getPrecision()+1));
574          if(val < minval) newset[XPEAK].upPrec();
575        }
576        tempwidth = int( log10(val) + 1) + newset[XPEAK].getPrecision() + 2;
577        for(int i=newset[XPEAK].getWidth();i<tempwidth;i++) newset[XPEAK].widen();
578        // Y position of peak flux
579        val = objectList[obj].getYPeak() + objectList[obj].getYOffset();
580        if((val<1.)&&(val>0.)){
581          minval = pow(10, -1. * (newset[YPEAK].getPrecision()+1));
582          if(val < minval) newset[YPEAK].upPrec();
583        }
584        tempwidth = int( log10(val) + 1) + newset[YPEAK].getPrecision() + 2;
585        for(int i=newset[YPEAK].getWidth();i<tempwidth;i++) newset[YPEAK].widen();
586        // Z position of peak flux
587        val = objectList[obj].getZPeak() + objectList[obj].getZOffset();
588        if((val<1.)&&(val>0.)){
589          minval = pow(10, -1. * (newset[ZPEAK].getPrecision()+1));
590          if((val>0.)&&(val < minval)) newset[ZPEAK].upPrec();
591        }
592        tempwidth = int( log10(val) + 1) + newset[ZPEAK].getPrecision() + 2;
593        for(int i=newset[ZPEAK].getWidth();i<tempwidth;i++) newset[ZPEAK].widen();
594      }
595
596      return newset;
597
598    }
599
600    std::vector<Col> getLogColSet(std::vector<Detection> &objectList,
601                                  FitsHeader &head)
602    {
603      /**
604       *  A function that returns a std::vector of Col objects containing
605       *    information on the columns necessary for logfile output:
606       *    Obj#,X,Y,Z,F_tot,F_peak,X1,X2,Y1,Y2,Z1,Z2,Npix
607       *
608       *   Each object in the provided objectList is checked to see if
609       *    it requires any column to be widened, or for that column to
610       *    have its precision increased.
611       *
612       * \param objectList A std::vector list of Detection objects that the columns need to fit.
613       * \param head The FitsHeader object defining the World Coordinate System.
614       * \return A std::vector list of Col definitions.
615       */
616
617      std::vector<Col> newset,tempset;
618 
619      // set up the default columns:
620      //  get from FullColSet, and select only the ones we want.
621      tempset = getFullColSet(objectList,head);
622
623      newset.push_back( tempset[NUM] );
624      newset.push_back( tempset[X] );
625      newset.push_back( tempset[Y] );
626      newset.push_back( tempset[Z] );
627      newset.push_back( tempset[FTOT] );
628      newset.push_back( tempset[FPEAK] );
629      newset.push_back( tempset[SNRPEAK] );
630      newset.push_back( tempset[X1] );
631      newset.push_back( tempset[X2] );
632      newset.push_back( tempset[Y1] );
633      newset.push_back( tempset[Y2] );
634      newset.push_back( tempset[Z1] );
635      newset.push_back( tempset[Z2] );
636      newset.push_back( tempset[NPIX] );
637
638      return newset;
639
640    }
641
642  }
643
644}
Note: See TracBrowser for help on using the repository browser.