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

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

A large commit, based on improving memory usage, allocation, etc:

  • src/param.hh :
    • Added a delete command for the offsets array in Param. Keep track of size via new sizeOffsets variable.
    • Changed "wcsprm" to "struct wcsprm", for clarity.
    • Put wcsvfree in the FitsHeader? destructor so that memory is deallocated correctly.
  • src/param.cc :
    • Improved the FitsHeader? constructor functions, so that memory for the wcsprm structures is allocated appropriately.
    • Other wcsprm-related tweaks.
    • Included code for sizeOffsets -- the size of the offsets array in Param, so that we can properly deallocate its memory in the destructor function.
  • src/FitsIO/subsection.cc : Changed "wcsprm" to "struct wcsprm", for clarity, and added a sizeOffsets to track the memory allocation for offsets.
  • src/FitsIO/dataIO.cc : renamed the local variable array to pixarray so that there is no confusion. Added delete[] commands for local arrays.
  • src/FitsIO/wcsIO.cc : Improved the struct wcsprm memory allocation. Now using a local wcs variable so that we don't get confusion with the FitsHeader? one.
  • src/Utils/wcsFunctions.cc : changed "wcsprm" to "struct wcsprm", for clarity.
  • src/Cubes/CubicSearch.cc : removed two allocation calls (to new) that were not needed, as well as unused commented-out code.
  • src/Cubes/plotting.cc :
    • Corrected the way the detection map is worked out and the scale bar range calculated.
    • Changed "wcsprm" to "struct wcsprm", for clarity.
  • src/duchamp.hh : better implementation of the rewind() and remove() functions for ProgressBar?
  • src/Utils/getStats.cc : minor diffs
  • src/Utils/utils.hh : changed prototypes
  • src/Cubes/cubes.cc : Changed the way the setCubeStats() function works, so that stats aren't needlessly calculated if the threshold has already been specified.
  • src/Cubes/cubes.hh : minor presentation changes
  • src/Cubes/drawMomentCutout.cc : Tried to improve the scale-bar drawing function, to cope with very high angular resolution data. Not quite working properly yet.
  • src/Cubes/outputSpectra.cc : Corrected the flux labels so that the appropriate units are used, and not just Jy or Jy/beam.
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> void findMinMax(const T *array, const int size,
30                                   T &min, T &max);
31template <class T> float findMean(T *array, int size);
32template <class T> float findStddev(T *array, int size);
33template <class T> T findMedian(T *array, int size);
34template <class T> T findMADFM(T *array, int size);
35template <class T> void findMedianStats(T *array, int size,
36                                        T &median, T &madfm);
37template <class T> void findMedianStats(T *array, int size, bool *isGood,
38                                        T &median, T &madfm);
39template <class T> void findNormalStats(T *array, int size,
40                                        float &mean, float &stddev);
41template <class T> void findNormalStats(T *array, int size, bool *isGood,
42                     float &mean, float &stddev);
43
44void findTrimmedHistStats(float *array, const int size,
45                          float &tmean, float &tsigma);
46void getRandomSpectrum(int length, float *x, float *y);
47void getRandomSpectrum(int length, float *x, double *y);
48void getRandomSpectrum(int length, float mean, float sigma,
49                       float *x, double *y);
50void getRandomSpectrum(int length, float mean, float sigma,
51                       float *x, float *y);
52float getNormalRV();
53float getNormalRVtrunc();
54float getNormalRV(float mean, float sigma);
55void getSigmaFactors(int &numScales, float *factors);
56void getSigmaFactors2D(int &numScales, float *factors);
57void getSigmaFactors3D(int &numScales, float *factors);
58void getSigmaFactors1DNew(int &numScales);
59void getSigmaFactors2DNew(int &numScales);
60void getSigmaFactors3DNew(int &numScales);
61
62
63// PLOTTING ROUTINES
64extern "C" int  cpgtest();
65extern "C" int  cpgIsPS();
66extern "C" void cpgwedglog(const char* side, float disp, float width,
67                           float fg, float bg, const char *label);
68extern "C" void cpghistlog(int npts, float *data, float datamin,
69                           float datamax, int nbin, int pgflag);
70extern "C" void cpgcumul(int npts, float *data, float datamin,
71                         float datamax, int pgflag);
72void plotLine(const float slope, const float intercept);
73void lineOfEquality();
74void lineOfBestFit(int size, float *x, float *y);
75void lineOfBestFitPB(const int size, const float *x, const float *y);
76void plotVertLine(const float xval, const int colour, const int style);
77void plotVertLine(const float xval);
78void plotVertLine(const float xval, const int colour);
79void plotHorizLine(const float yval, const int colour, const int style);
80void plotHorizLine(const float yval);
81void plotHorizLine(const float yval, const int colour);
82void drawContours(const int size, const float *x, const float *y);
83void drawBlankEdges(float *dataArray, int xdim, int ydim, Param &par);
84
85// POSITION-RELATED ROUTINES
86string getIAUNameEQ(double ra, double dec, float equinox);
87string getIAUNameGAL(double ra, double dec);
88string decToDMS(double dec, string type);
89double dmsToDec(string dms);
90double angularSeparation(double &ra1, double &dec1, double &ra2, double &dec2);
91
92// WCS-RELATED ROUTINES
93int wcsToPixSingle(struct wcsprm *wcs, const double *world, double *pix);
94int pixToWCSSingle(struct wcsprm *wcs, const double *pix, double *world);
95int wcsToPixMulti(struct wcsprm *wcs, const double *world,
96                  double *pix, const int npts);
97int pixToWCSMulti(struct wcsprm *wcs, const double *pix,
98                  double *world, const int npts);
99double pixelToVelocity(struct wcsprm *wcs, double &x, double &y,
100                       double &z, string velUnits);
101double coordToVel(struct wcsprm *wcs, const double coord, string outputUnits);
102double velToCoord(struct wcsprm *wcs, const float velocity, string outputUnits);
103
104// FILTER SMOOTHING ROUTINES
105void waveletSmooth(int dim,float *array, int arraySize, float sigma);
106void hanningSmooth(float *array, int arraySize, int hanningSize);
107void tophatSmooth(float *array, int arraySize, int width);
108
109#endif
Note: See TracBrowser for help on using the repository browser.