source: tags/release-1.0.7/src/Detection/spectrumDetect.cc @ 1441

Last change on this file since 1441 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: 1.2 KB
Line 
1/**
2 *  spectrumDetect.cc
3 *
4 * A detection algorithm that searches in a single 1-D spectrum.
5 *
6 * INPUTS:
7 *    image     -- an Image object, containing a 1-D image that has had
8 *                 its StatsContainer object defined.
9 *   The detection array in image will be filled, according to
10 *   the location of the objects in the image.
11 *
12 */
13
14#include <Cubes/cubes.hh>
15#include <Detection/detection.hh>
16
17enum STATUS { NONOBJECT, OBJECT };
18
19void Image::spectrumDetect()
20{
21  STATUS status;
22  Detection *obj = new Detection;
23  Pixel *pix = new Pixel;
24  bool isObject;
25
26  status = NONOBJECT;
27  for(int pos=0;pos<(this->axisDim[0]+1);pos++){
28
29    isObject=false;
30    if(pos<this->axisDim[0]){
31      pix->setXYF(pos, 0, this->array[pos] );
32      isObject = this->isDetection(pos,0);
33    }
34
35    if(isObject){
36      if(status != OBJECT) status = OBJECT;
37      obj->addPixel(*pix);
38    }
39    else{
40      if(status == OBJECT){ // if we were on an object and have left
41        if(obj->getSize() >= this->minSize){ // if it's big enough
42          obj->calcParams(); // work out midpoints, fluxes etc
43          this->addObject(*obj);  // add to list.
44        }
45        obj->clearDetection();
46      }
47      status = NONOBJECT;
48    }
49
50  }
51
52  // clean up and remove declared memory
53  delete obj;
54  delete pix;
55}
Note: See TracBrowser for help on using the repository browser.