source: tags/release-1.1.12/src/Utils/utils.hh @ 1455

Last change on this file since 1455 was 756, checked in by MatthewWhiting, 14 years ago

A new way to calculate MADFM, so that if we have the median we don't need to re-calculate it

File size: 4.8 KB
Line 
1// -----------------------------------------------------------------------
2// utils.hh: Prototypes for utility functions.
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#ifndef UTILS_H
29#define UTILS_H
30
31#include <wcslib/wcs.h>
32#include <string>
33
34struct wcsprm; // just foreshadow this.
35
36// define the speed of light for WCS-related accessor functions
37const float C_kms = 299792.458;
38
39int linear_regression(int num, float *x, float *y, int ilow, int ihigh,
40                      float &slope, float &errSlope,
41                      float &intercept, float &errIntercept, float &r);
42template <class Type> void zscale(long imagesize, Type *image, Type &z1, Type &z2);
43template <class Type> void zscale(long imagesize, Type *image, Type &z1, Type &z2, Type nullVal);
44template <class T> void sort(T *arr, int begin, int end);
45template <class T1, class T2> void sort(T1 *arr, T2 *matchingArray,
46                                        int begin, int end);
47
48// STATISTICS-RELATED ROUTINES
49template <class T> T absval(T value);
50template <class T> void findMinMax(const T *array, const int size,
51                                   T &min, T &max);
52template <class T> float findMean(T *array, int size);
53template <class T> float findStddev(T *array, int size);
54template <class T> T findMedian(T *array, int size, bool changeArray=false);
55template <class T> T findMADFM(T *array, int size, bool changeArray=false);
56template <class T> T findMADFM(T *array, int size, T median, bool changeArray=false);
57template <class T> void findMedianStats(T *array, int size,
58                                        T &median, T &madfm);
59template <class T> void findMedianStats(T *array, int size, bool *isGood,
60                                        T &median, T &madfm);
61template <class T> void findNormalStats(T *array, int size,
62                                        float &mean, float &stddev);
63template <class T> void findNormalStats(T *array, int size, bool *isGood,
64                                        float &mean, float &stddev);
65template <class T> void findAllStats(T *array, int size,
66                                     float &mean, float &stddev,
67                                     T &median, T &madfm);
68template <class T> void findAllStats(T *array, int size, bool *mask,
69                                     float &mean, float &stddev,
70                                     T &median, T &madfm);
71
72
73// POSITION-RELATED ROUTINES
74std::string getIAUNameEQ(double ra, double dec, float equinox);
75std::string getIAUNameGAL(double ra, double dec);
76std::string decToDMS(double dec, std::string type);
77double dmsToDec(std::string dms);
78double angularSeparation(double &ra1, double &dec1, double &ra2, double &dec2);
79
80// WCS-RELATED ROUTINES
81int wcsToPixSingle(struct wcsprm *wcs, const double *world, double *pix);
82int pixToWCSSingle(struct wcsprm *wcs, const double *pix, double *world);
83int wcsToPixMulti(struct wcsprm *wcs, const double *world,
84                  double *pix, const int npts);
85int pixToWCSMulti(struct wcsprm *wcs, const double *pix,
86                  double *world, const int npts);
87double pixelToVelocity(struct wcsprm *wcs, double &x, double &y,
88                       double &z, std::string velUnits);
89double coordToVel(struct wcsprm *wcs, const double coord, std::string outputUnits);
90double velToCoord(struct wcsprm *wcs, const float velocity, std::string outputUnits);
91
92// FILTER SMOOTHING ROUTINES
93void waveletSmooth(int dim,float *array, int arraySize, float sigma);
94void hanningSmooth(float *array, int arraySize, int hanningSize);
95void tophatSmooth(float *array, int arraySize, int width);
96
97float *medianBaseline(float *inputArray, int dim, unsigned int boxWidth);
98
99// STRING AND INPUT PARAMETER MANIPULATION ROUTINES
100std::string makelower( std::string s );
101std::string stringize(bool b);
102bool boolify(std::string s);
103std::string readSval(std::stringstream& ss);
104std::string readFilename(std::stringstream& ss);
105bool readFlag(std::stringstream& ss);
106float readFval(std::stringstream& ss);
107int readIval(std::stringstream& ss);
108std::string removeLeadingBlanks(std::string s);
109std::string deblank(std::string s);
110
111#endif
Note: See TracBrowser for help on using the repository browser.