VIRCAM Pipeline  1.3.4
apinit.c
1 /* $Id: apinit.c,v 1.5 2013-10-15 16:17:53 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: 2013-10-15 16:17:53 $
24  * $Revision: 1.5 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 
29 #include <stdlib.h>
30 #include <cpl.h>
31 #include "imcore.h"
32 
33 #define freespace(_p) if (_p != NULL) {cpl_free(_p); _p = NULL;}
34 
36 /*---------------------------------------------------------------------------*/
62 /*---------------------------------------------------------------------------*/
63 
64 void apinit(ap_t *ap) {
65  int maxpa;
66 
67  int i;
68 
69  maxpa = ap->lsiz / 2; /* max possible parents */
70  ap->lastline = cpl_calloc(ap->lsiz + 1, sizeof(short int));
71  ap->maxip = 0;
72  ap->maxpa = maxpa;
73  ap->pstack = cpl_malloc(maxpa*sizeof(*ap->pstack));
74  ap->parent = cpl_malloc(maxpa*sizeof(*(ap->parent)));
75  for(i = 0; i < maxpa; i++) {
76  ap->pstack[i] = i;
77  ap->parent[i].pnop = -1; /* mark all parents inactive */
78  ap->parent[i].pnbp = -1; /* mark all parents inactive */
79  }
80  ap->ipstack = 1;
81  ap->maxbl = MAXBL;
82  ap->bstack = cpl_malloc(ap->maxbl*sizeof(*ap->bstack));
83  ap->blink = cpl_malloc(ap->maxbl*sizeof(*ap->blink));
84  ap->plessey = cpl_malloc(ap->maxbl*sizeof(*ap->plessey));
85  for (i = 0; i < MAXBL; i++)
86  ap->bstack[i] = i;
87  ap->ibstack = 2; /* block 1 will get overwritten; don't use it */
88  ap->nimages = 0;
89 
90  /* set up exponential areal-profile levels: */
91 
92  ap->areal[0] = 1;
93  for (i = 1; i < 8; i++)
94  ap->areal[i] = ap->areal[i-1]*2;
95 
96  /* allocate some space for a processing array */
97 
98  ap->npl = ap->lsiz;
99  ap->npl_pix = 0;
100  ap->plarray = cpl_malloc(ap->npl*sizeof(plstruct));
101 
102  /* set these to null values as you may not need the background structure */
103 
104  ap->backmap.nby = -1;
105  ap->backmap.bvals = NULL;
106 
107  /* Initialise some info about the input images */
108 
109  ap->indata = NULL;
110  ap->confdata = NULL;
111 }
112 
113 /*---------------------------------------------------------------------------*/
139 /*---------------------------------------------------------------------------*/
140 
141 void apreinit(ap_t *ap) {
142  int i;
143 
144  for (i = 0; i < ap->lsiz+1; i++)
145  ap->lastline[i] = 0;
146  ap->maxip = 0;
147  for(i = 0; i < ap->maxpa; i++) {
148  ap->pstack[i] = i;
149  ap->parent[i].pnop = -1; /* mark all parents inactive */
150  ap->parent[i].pnbp = -1; /* mark all parents inactive */
151  }
152  ap->ipstack = 1;
153  ap->ibstack = 2; /* block 1 will get overwritten; don't use it */
154  ap->nimages = 0;
155  ap->npl_pix = 0;
156 
157 }
158 
159 /*---------------------------------------------------------------------------*/
183 /*---------------------------------------------------------------------------*/
184 
185 void apclose(ap_t *ap) {
186  int i;
187  freespace(ap->lastline);
188  freespace(ap->pstack);
189  freespace(ap->parent);
190  freespace(ap->bstack);
191  freespace(ap->blink);
192  freespace(ap->plessey);
193  freespace(ap->plarray);
194  if (ap->backmap.bvals != NULL) {
195  for (i = 0; i < ap->backmap.nby; i++)
196  freespace(ap->backmap.bvals[i]);
197  freespace(ap->backmap.bvals);
198  }
199 }
200 
201 /*
202 
203 $Log: not supported by cvs2svn $
204 Revision 1.4 2010/09/09 12:09:57 jim
205 Added docs
206 
207 Revision 1.3 2007/03/01 12:38:26 jim
208 Small modifications after a bit of code checking
209 
210 Revision 1.2 2005/09/20 15:07:46 jim
211 Fixed a few bugs and added a few things
212 
213 Revision 1.1 2005/09/13 13:25:27 jim
214 Initial entry after modifications to make cpl compliant
215 
216 
217 */
void apreinit(ap_t *ap)
Re-initialise the ap structure.
Definition: apinit.c:141
void apclose(ap_t *ap)
Close ap structure.
Definition: apinit.c:185
void apinit(ap_t *ap)
Initialise the ap structure.
Definition: apinit.c:64