terminate.c

00001 /* $Id: terminate.c,v 1.4 2010/09/09 12:09:57 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: jim $
00023  * $Date: 2010/09/09 12:09:57 $
00024  * $Revision: 1.4 $
00025  * $Name: vcam-1_3_0 $
00026  */
00027 
00028 #include <stdio.h>
00029 #include "imcore.h"
00030 #include "util.h"
00031 
00034 /*---------------------------------------------------------------------------*/
00062 /*---------------------------------------------------------------------------*/
00063 
00064 extern void restack(ap_t *ap, int ip) {
00065     int i,ib,nn,np;
00066     unsigned char *mflag;
00067 
00068     /* Reset the mflag */
00069 
00070     np = ap->parent[ip].pnop;
00071     ib = ap->parent[ip].first;
00072     mflag = ap->mflag;
00073     for (i = 0; i < np; i++) {
00074         nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
00075         mflag[nn] = MF_POSSIBLEOBJ;
00076         ib = ap->blink[ib];
00077     }
00078 
00079     /* Stash all blocks back in a burst: */
00080     
00081     ib = ap->parent[ip].first;
00082     for(i = ap->ibstack - ap->parent[ip].pnop; i < ap->ibstack-1;  i++) {
00083         ap->bstack[i] = ib;
00084         ib = ap->blink[ib];
00085     }
00086 
00087     /* and the last one: */
00088 
00089     ap->bstack[ap->ibstack-1] = ib;
00090     ap->ibstack -= ap->parent[ip].pnop;
00091 
00092     /* Put parent name back on stack: */
00093 
00094     ap->pstack[--ap->ipstack] = ip;
00095 
00096     /* Mark that parent inactive: */
00097 
00098     ap->parent[ip].pnop = -1;
00099     ap->parent[ip].pnbp = -1;
00100 }
00101 
00102 /*---------------------------------------------------------------------------*/
00128 /*---------------------------------------------------------------------------*/
00129 
00130 extern void terminate(ap_t *ap) {
00131     int ip,status;
00132 
00133     /* Search through all possible parents!  */
00134 
00135     for (ip = 1; ip <= ap->maxip; ip++) {
00136         if(ap->parent[ip].pnop != -1) {
00137             if(ap->parent[ip].pnop == ap->parent[ip].growing) {
00138 
00139                 /* That's a termination: */
00140 
00141                 if((ap->parent[ip].pnop >= ap->ipnop &&
00142                     ap->parent[ip].touch == 0) &&
00143                     (ap->parent[ip].pnbp < (ap->parent[ip].pnop)/2)) {
00144                     extract_data(ap,ip);
00145                     
00146                     /* Call the processing routine */
00147 
00148                     status = process_results(ap);
00149                     if (status != VIR_OK) {
00150                         restack(ap,ip);
00151                         continue;
00152                     }
00153                 }
00154                 restack(ap,ip);
00155             } else {
00156 
00157                 /* This parent still active: */
00158 
00159                 ap->parent[ip].growing = ap->parent[ip].pnop;
00160             }
00161         }
00162     }
00163 }
00164 
00165 /*---------------------------------------------------------------------------*/
00190 /*---------------------------------------------------------------------------*/
00191 
00192 extern void apfu(ap_t *ap) {
00193     int ip, big, ipbig;
00194 
00195     /* Search through all possible parents and just junk the biggest
00196        one to free space:  */
00197 
00198     big = 0;
00199     ipbig = 0;
00200     for (ip = 1; ip <= ap->maxip; ip++) {
00201         if(ap->parent[ip].pnop != -1) {
00202             if(ap->parent[ip].pnop > big) {
00203                 big = ap->parent[ip].pnop;
00204                 ipbig = ip;
00205             }
00206         }
00207     }
00208     if(big > 0) {
00209         restack(ap, ipbig);
00210 
00211         /* clearout lastline references to this parent: */
00212 
00213         for (ip = 0; ip <= ap->lsiz; ip++)
00214             if(ap->lastline[ip] == ipbig) ap->lastline[ip] = 0;
00215     }
00216 }
00217 
00218 /*---------------------------------------------------------------------------*/
00246 /*---------------------------------------------------------------------------*/
00247 
00248 extern void extract_data(ap_t *ap, int ip) {
00249     int ib,i,np,nn;
00250     unsigned char *mflag;
00251 
00252     /* Check the size of the workspace and see if it's big enough. If it
00253        isn't then increase the size until it is */
00254 
00255     np = ap->parent[ip].pnop;
00256     if (ap->npl < np) {
00257         ap->plarray = cpl_realloc(ap->plarray,np*sizeof(plstruct));
00258         ap->npl = np;
00259     }
00260 
00261     /* Pull the info out now */
00262 
00263     ib = ap->parent[ip].first;
00264     ap->npl_pix = np;
00265     mflag = ap->mflag;
00266     for (i = 0; i < np; i++) {
00267         ap->plarray[i].x = ap->plessey[ib].x + 1;
00268         ap->plarray[i].y = ap->plessey[ib].y + 1;
00269         ap->plarray[i].z = ap->plessey[ib].z;
00270         ap->plarray[i].zsm = ap->plessey[ib].zsm;
00271         nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x;
00272         mflag[nn] = MF_OBJPIX;
00273         ib = ap->blink[ib];
00274     }
00275 }
00276 
00279 /*
00280 
00281 $Log: terminate.c,v $
00282 Revision 1.4  2010/09/09 12:09:57  jim
00283 Added docs
00284 
00285 Revision 1.3  2009/01/23 12:24:33  jim
00286 Fixed bugs in pixel flagging
00287 
00288 Revision 1.2  2007/03/01 12:38:26  jim
00289 Small modifications after a bit of code checking
00290 
00291 Revision 1.1  2005/09/13 13:25:31  jim
00292 Initial entry after modifications to make cpl compliant
00293 
00294 
00295 */

Generated on 15 Mar 2012 for VIRCAM Pipeline by  doxygen 1.6.1