apinit.c

00001 /* $Id: apinit.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 
00029 #include <stdlib.h>
00030 #include <cpl.h>
00031 #include "imcore.h"
00032 
00033 #define freespace(_p) if (_p != NULL) {cpl_free(_p); _p = NULL;}
00034 
00036 /*---------------------------------------------------------------------------*/
00062 /*---------------------------------------------------------------------------*/
00063 
00064 void apinit(ap_t *ap) {
00065     int maxpa;
00066 
00067     int i;
00068 
00069     maxpa = ap->lsiz / 2;               /* max possible parents */
00070     ap->lastline = cpl_calloc(ap->lsiz + 1, sizeof(short int));
00071     ap->maxip = 0;
00072     ap->maxpa = maxpa;
00073     ap->pstack = cpl_malloc(maxpa*sizeof(*ap->pstack));
00074     ap->parent = cpl_malloc(maxpa*sizeof(*(ap->parent)));
00075     for(i = 0; i < maxpa; i++) {
00076         ap->pstack[i] = i;
00077         ap->parent[i].pnop = -1;        /* mark all parents inactive */
00078         ap->parent[i].pnbp = -1;        /* mark all parents inactive */
00079     }
00080     ap->ipstack = 1;
00081     ap->maxbl = MAXBL;
00082     ap->bstack = cpl_malloc(ap->maxbl*sizeof(*ap->bstack));
00083     ap->blink = cpl_malloc(ap->maxbl*sizeof(*ap->blink));
00084     ap->plessey = cpl_malloc(ap->maxbl*sizeof(*ap->plessey));
00085     for (i = 0; i < MAXBL; i++)
00086         ap->bstack[i] = i;
00087     ap->ibstack = 2;    /* block 1 will get overwritten; don't use it */
00088     ap->nimages = 0;
00089 
00090     /* set up exponential areal-profile levels: */
00091 
00092     ap->areal[0] = 1;
00093     for (i = 1; i < 8; i++)
00094         ap->areal[i] = ap->areal[i-1]*2;
00095 
00096     /* allocate some space for a processing array */
00097 
00098     ap->npl = ap->lsiz;
00099     ap->npl_pix = 0;
00100     ap->plarray = cpl_malloc(ap->npl*sizeof(plstruct));
00101 
00102     /* set these to null values as you may not need the background structure */
00103 
00104     ap->backmap.nby = -1;
00105     ap->backmap.bvals = NULL;
00106 
00107     /* Initialise some info about the input images */
00108 
00109     ap->indata = NULL;
00110     ap->confdata = NULL;
00111 }
00112 
00113 /*---------------------------------------------------------------------------*/
00139 /*---------------------------------------------------------------------------*/
00140 
00141 void apreinit(ap_t *ap) {
00142     int i;
00143 
00144     for (i = 0; i < ap->lsiz+1; i++)
00145         ap->lastline[i] = 0;
00146     ap->maxip = 0;
00147     for(i = 0; i < ap->maxpa; i++) {
00148         ap->pstack[i] = i;
00149         ap->parent[i].pnop = -1;        /* mark all parents inactive */
00150         ap->parent[i].pnbp = -1;        /* mark all parents inactive */
00151     }
00152     ap->ipstack = 1;
00153     ap->ibstack = 2;    /* block 1 will get overwritten; don't use it */
00154     ap->nimages = 0;
00155     ap->npl_pix = 0;
00156 
00157 }
00158 
00159 /*---------------------------------------------------------------------------*/
00183 /*---------------------------------------------------------------------------*/
00184 
00185 void apclose(ap_t *ap) {
00186     int i;
00187     freespace(ap->lastline);
00188     freespace(ap->pstack);
00189     freespace(ap->parent);
00190     freespace(ap->bstack);
00191     freespace(ap->blink);
00192     freespace(ap->plessey);
00193     freespace(ap->plarray);
00194     for (i = 0; i < ap->backmap.nby; i++)
00195         freespace(ap->backmap.bvals[i]);
00196     freespace(ap->backmap.bvals);
00197 }
00198 
00199 /*
00200 
00201 $Log: apinit.c,v $
00202 Revision 1.4  2010/09/09 12:09:57  jim
00203 Added docs
00204 
00205 Revision 1.3  2007/03/01 12:38:26  jim
00206 Small modifications after a bit of code checking
00207 
00208 Revision 1.2  2005/09/20 15:07:46  jim
00209 Fixed a few bugs and added a few things
00210 
00211 Revision 1.1  2005/09/13 13:25:27  jim
00212 Initial entry after modifications to make cpl compliant
00213 
00214 
00215 */

Generated on 15 Mar 2012 for VIRCAM Pipeline by  doxygen 1.6.1