source: trunk/src/Utils/utils.hh @ 208

Last change on this file since 208 was 205, checked in by Matthew Whiting, 18 years ago

Changes here mostly aimed at reducing/removing memory leaks. These were one of:

  • Forgetting to delete something allocated with "new". The Cube destructor has improved with the use of bool variables to keep track of when recon & baseline ahave been allocated.
  • Incorrectly using the wcs->flag parameter (eg. wcsIO had it set to -1 *after* calling wcsini)
  • Not closing a fits file once finished with (dataIO)
  • Allocating the wcsprm structs with calloc before calling wcsini, so that wcsvfree can work (it calls "free", so the memory needs to be allocated with calloc or malloc).

The only other change was the following:

  • A new way of doing the Cube::setCubeStats -- rather than calling the functions in getStats.cc, we explicitly do the calculations. This means we can sort the tempArray that has the BLANKS etc removed. This saves a great deal of memory usage on large FITS files (such as Enno's 2Gb one)
  • The old setCubeStats function is still there but called setCubeStatsOld.
File size: 4.5 KB
Line 
1#ifndef UTILS_H
2#define UTILS_H
3
4#include <param.hh>
5#include <wcs.h>
6#include <string>
7
8// define the speed of light for WCS-related accessor functions
9const float C_kms = 299792.458;
10
11// MENU ROUTINES FOR DIGANOSTIC/TEST PROGRAMS
12std::string menu();
13std::string specMenu();
14std::string orionMenu();
15std::string imageMenu();
16std::string twoblMenu();
17
18int linear_regression(int num, float *x, float *y, int ilow, int ihigh,
19                      float &slope, float &errSlope,
20                      float &intercept, float &errIntercept, float &r);
21void zscale(long imagesize, float *image, float &z1, float &z2);
22void zscale(long imagesize, float *image, float &z1, float &z2, float nullVal);
23template <class T> void swap(T &a, T &b){T t=a;a=b;b=t;};
24template <class T> void sort(T *arr, int begin, int end);
25template <class T1, class T2> void sort(T1 *arr, T2 *matchingArray,
26                                        int begin, int end);
27
28// STATISTICS-RELATED ROUTINES
29template <class T> T absval(T value);
30template <class T> void findMinMax(const T *array, const int size,
31                                   T &min, T &max);
32template <class T> float findMean(T *array, int size);
33template <class T> float findStddev(T *array, int size);
34template <class T> T findMedian(T *array, int size);
35template <class T> T findMADFM(T *array, int size);
36template <class T> void findMedianStats(T *array, int size,
37                                        T &median, T &madfm);
38template <class T> void findMedianStats(T *array, int size, bool *isGood,
39                                        T &median, T &madfm);
40template <class T> void findNormalStats(T *array, int size,
41                                        float &mean, float &stddev);
42template <class T> void findNormalStats(T *array, int size, bool *isGood,
43                     float &mean, float &stddev);
44
45void findTrimmedHistStats(float *array, const int size,
46                          float &tmean, float &tsigma);
47void getRandomSpectrum(int length, float *x, float *y);
48void getRandomSpectrum(int length, float *x, double *y);
49void getRandomSpectrum(int length, float mean, float sigma,
50                       float *x, double *y);
51void getRandomSpectrum(int length, float mean, float sigma,
52                       float *x, float *y);
53float getNormalRV();
54float getNormalRVtrunc();
55float getNormalRV(float mean, float sigma);
56void getSigmaFactors(int &numScales, float *factors);
57void getSigmaFactors2D(int &numScales, float *factors);
58void getSigmaFactors3D(int &numScales, float *factors);
59void getSigmaFactors1DNew(int &numScales);
60void getSigmaFactors2DNew(int &numScales);
61void getSigmaFactors3DNew(int &numScales);
62
63
64// PLOTTING ROUTINES
65extern "C" int  cpgtest();
66extern "C" int  cpgIsPS();
67extern "C" void cpgwedglog(const char* side, float disp, float width,
68                           float fg, float bg, const char *label);
69extern "C" void cpghistlog(int npts, float *data, float datamin,
70                           float datamax, int nbin, int pgflag);
71extern "C" void cpgcumul(int npts, float *data, float datamin,
72                         float datamax, int pgflag);
73void plotLine(const float slope, const float intercept);
74void lineOfEquality();
75void lineOfBestFit(int size, float *x, float *y);
76void lineOfBestFitPB(const int size, const float *x, const float *y);
77void plotVertLine(const float xval, const int colour, const int style);
78void plotVertLine(const float xval);
79void plotVertLine(const float xval, const int colour);
80void plotHorizLine(const float yval, const int colour, const int style);
81void plotHorizLine(const float yval);
82void plotHorizLine(const float yval, const int colour);
83void drawContours(const int size, const float *x, const float *y);
84void drawBlankEdges(float *dataArray, int xdim, int ydim, Param &par);
85
86// POSITION-RELATED ROUTINES
87string getIAUNameEQ(double ra, double dec, float equinox);
88string getIAUNameGAL(double ra, double dec);
89string decToDMS(double dec, string type);
90double dmsToDec(string dms);
91double angularSeparation(double &ra1, double &dec1, double &ra2, double &dec2);
92
93// WCS-RELATED ROUTINES
94int wcsToPixSingle(struct wcsprm *wcs, const double *world, double *pix);
95int pixToWCSSingle(struct wcsprm *wcs, const double *pix, double *world);
96int wcsToPixMulti(struct wcsprm *wcs, const double *world,
97                  double *pix, const int npts);
98int pixToWCSMulti(struct wcsprm *wcs, const double *pix,
99                  double *world, const int npts);
100double pixelToVelocity(struct wcsprm *wcs, double &x, double &y,
101                       double &z, string velUnits);
102double coordToVel(struct wcsprm *wcs, const double coord, string outputUnits);
103double velToCoord(struct wcsprm *wcs, const float velocity, string outputUnits);
104
105// FILTER SMOOTHING ROUTINES
106void waveletSmooth(int dim,float *array, int arraySize, float sigma);
107void hanningSmooth(float *array, int arraySize, int hanningSize);
108void tophatSmooth(float *array, int arraySize, int width);
109
110#endif
Note: See TracBrowser for help on using the repository browser.