VIRCAM Pipeline  1.3.4
terminate.c
1 /* $Id: terminate.c,v 1.4 2010-09-09 12:09:57 jim Exp $
2  *
3  * This file is part of the VIRCAM Pipeline
4  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2010-09-09 12:09:57 $
24  * $Revision: 1.4 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #include <stdio.h>
29 #include "imcore.h"
30 #include "util.h"
31 
34 /*---------------------------------------------------------------------------*/
62 /*---------------------------------------------------------------------------*/
63 
64 extern void restack(ap_t *ap, int ip) {
65  int i,ib,nn,np;
66  unsigned char *mflag;
67 
68  /* Reset the mflag */
69 
70  np = ap->parent[ip].pnop;
71  ib = ap->parent[ip].first;
72  mflag = ap->mflag;
73  for (i = 0; i < np; i++) {
74  nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
75  mflag[nn] = MF_POSSIBLEOBJ;
76  ib = ap->blink[ib];
77  }
78 
79  /* Stash all blocks back in a burst: */
80 
81  ib = ap->parent[ip].first;
82  for(i = ap->ibstack - ap->parent[ip].pnop; i < ap->ibstack-1; i++) {
83  ap->bstack[i] = ib;
84  ib = ap->blink[ib];
85  }
86 
87  /* and the last one: */
88 
89  ap->bstack[ap->ibstack-1] = ib;
90  ap->ibstack -= ap->parent[ip].pnop;
91 
92  /* Put parent name back on stack: */
93 
94  ap->pstack[--ap->ipstack] = ip;
95 
96  /* Mark that parent inactive: */
97 
98  ap->parent[ip].pnop = -1;
99  ap->parent[ip].pnbp = -1;
100 }
101 
102 /*---------------------------------------------------------------------------*/
128 /*---------------------------------------------------------------------------*/
129 
130 extern void terminate(ap_t *ap) {
131  int ip,status;
132 
133  /* Search through all possible parents! */
134 
135  for (ip = 1; ip <= ap->maxip; ip++) {
136  if(ap->parent[ip].pnop != -1) {
137  if(ap->parent[ip].pnop == ap->parent[ip].growing) {
138 
139  /* That's a termination: */
140 
141  if((ap->parent[ip].pnop >= ap->ipnop &&
142  ap->parent[ip].touch == 0) &&
143  (ap->parent[ip].pnbp < (ap->parent[ip].pnop)/2)) {
144  extract_data(ap,ip);
145 
146  /* Call the processing routine */
147 
148  status = process_results(ap);
149  if (status != VIR_OK) {
150  restack(ap,ip);
151  continue;
152  }
153  }
154  restack(ap,ip);
155  } else {
156 
157  /* This parent still active: */
158 
159  ap->parent[ip].growing = ap->parent[ip].pnop;
160  }
161  }
162  }
163 }
164 
165 /*---------------------------------------------------------------------------*/
190 /*---------------------------------------------------------------------------*/
191 
192 extern void apfu(ap_t *ap) {
193  int ip, big, ipbig;
194 
195  /* Search through all possible parents and just junk the biggest
196  one to free space: */
197 
198  big = 0;
199  ipbig = 0;
200  for (ip = 1; ip <= ap->maxip; ip++) {
201  if(ap->parent[ip].pnop != -1) {
202  if(ap->parent[ip].pnop > big) {
203  big = ap->parent[ip].pnop;
204  ipbig = ip;
205  }
206  }
207  }
208  if(big > 0) {
209  restack(ap, ipbig);
210 
211  /* clearout lastline references to this parent: */
212 
213  for (ip = 0; ip <= ap->lsiz; ip++)
214  if(ap->lastline[ip] == ipbig) ap->lastline[ip] = 0;
215  }
216 }
217 
218 /*---------------------------------------------------------------------------*/
246 /*---------------------------------------------------------------------------*/
247 
248 extern void extract_data(ap_t *ap, int ip) {
249  int ib,i,np,nn;
250  unsigned char *mflag;
251 
252  /* Check the size of the workspace and see if it's big enough. If it
253  isn't then increase the size until it is */
254 
255  np = ap->parent[ip].pnop;
256  if (ap->npl < np) {
257  ap->plarray = cpl_realloc(ap->plarray,np*sizeof(plstruct));
258  ap->npl = np;
259  }
260 
261  /* Pull the info out now */
262 
263  ib = ap->parent[ip].first;
264  ap->npl_pix = np;
265  mflag = ap->mflag;
266  for (i = 0; i < np; i++) {
267  ap->plarray[i].x = ap->plessey[ib].x + 1;
268  ap->plarray[i].y = ap->plessey[ib].y + 1;
269  ap->plarray[i].z = ap->plessey[ib].z;
270  ap->plarray[i].zsm = ap->plessey[ib].zsm;
271  nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
272  mflag[nn] = MF_OBJPIX;
273  ib = ap->blink[ib];
274  }
275 }
276 
279 /*
280 
281 $Log: not supported by cvs2svn $
282 Revision 1.3 2009/01/23 12:24:33 jim
283 Fixed bugs in pixel flagging
284 
285 Revision 1.2 2007/03/01 12:38:26 jim
286 Small modifications after a bit of code checking
287 
288 Revision 1.1 2005/09/13 13:25:31 jim
289 Initial entry after modifications to make cpl compliant
290 
291 
292 */
void terminate(ap_t *ap)
Check for objects that have terminated.
Definition: terminate.c:130
void restack(ap_t *ap, int ip)
Free information for an object from the ap structure.
Definition: terminate.c:64
void apfu(ap_t *ap)
Get rid of the largest contributor in an ap structure.
Definition: terminate.c:192
void extract_data(ap_t *ap, int ip)
Put data into the Plessey array for an object.
Definition: terminate.c:248
int process_results(ap_t *ap)
Process results.
Definition: create_table.c:177