source: tags/release-1.0.2/src/Utils/cpgcumul.c @ 1323

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

Some bugfixes, and improved image/spectrum extraction routines:
Corrected bug that meant blank pixels weren't being seen by the
drawMomentMap function. Improved the blankpixel testing in that
function, and changed getImage so that the blank pixel info is
always stored (if it is in the fits header).
Added new functions to Image class that can read a spectrum or
channel map given a cube and a channel/pixel number.
Other minor corrections as well:
src/Utils/cpgcumul.c -- changed way _swap is declared (pointers
rather than references, which don't work in C)
src/Cubes/cubes.cc -- new extraction functions
src/Cubes/cubes.hh -- prototypes thereof
src/Cubes/drawMomentCutout.cc -- improved blank pixel handling
src/Cubes/getImage.cc -- made sure blank pixel info is always
read in.
src/param.cc -- tidied up code slightly.
src/Detection/thresholding_functions.cc -- corrected setupFDR
to remove potential for accessing outside allocated memory.

File size: 1.6 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <cpgplot.h>
4#include <math.h>
5
6void _swap(float *a, float *b)
7{
8  float t;
9  t=*a; *a=*b; *b=t;
10}
11
12void _sort(float *array, int begin, int end)
13{
14  float pivot = array[begin];
15  int i = begin + 1, j = end, k = end;
16  float t;
17
18  while (i < j) {
19    if (array[i] < pivot) i++;
20    else if (array[i] > pivot) {
21      j--; k--;
22      t = array[i];
23      array[i] = array[j];
24      array[j] = array[k];
25      array[k] = t; }
26    else {
27      j--;
28      _swap(&array[i], &array[j]);
29    }  }
30  i--;
31  _swap(&array[begin], &array[i]);       
32  if (i - begin > 1)
33    _sort(array, begin, i);
34  if (end - k   > 1)
35    _sort(array, k, end);                     
36}
37
38
39void cpgcumul(int npts, float *data, float datamin, float datamax, int pgflag)
40{
41  /**
42   *  cpgcumul(npts, data, datamin, datamax, pgflag)
43   *    A new pgplot routine that draws a cumulative distribution.
44   *   The use of pgflag is similar to cpghist & cpghist_log:
45   *    0 --> draw a new graph using cpgenv, going from 0 to 1 on the y-axis.
46   *    2 --> draw the plot on the current graph, without re-drawing any axes.
47   */
48
49  int i;
50  float *sorted;
51  float MINCOUNT=0.;
52
53  sorted = (float *)calloc(npts,sizeof(float));
54  for(i=0;i<npts;i++) sorted[i] = data[i];
55  _sort(sorted,0,npts);
56
57  cpgbbuf();
58
59  // DEFINE ENVIRONMENT IF NECESSARY
60  if(pgflag == 0) cpgenv(datamin,datamax,MINCOUNT,1.0001,0,0);
61  if(pgflag == 2) cpgswin(datamin,datamax,MINCOUNT,1.);
62
63  // DRAW LINE
64  cpgmove(datamin,MINCOUNT);
65  for(i=0;i<npts;i++) cpgdraw(sorted[i],(float)(i+1)/(float)(npts));
66  cpgdraw(datamax,1.);
67
68  cpgebuf();
69 
70  free(sorted);
71
72}
73
74
Note: See TracBrowser for help on using the repository browser.