VIRCAM Pipeline  1.3.3
create_table.c
1 /* $Id: create_table.c,v 1.6 2013-10-15 16:18:59 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:18:59 $
24  * $Revision: 1.6 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #include <stdio.h>
29 #include <string.h>
30 #include "imcore.h"
31 
32 static float *work = NULL;
33 
34 static void tidy(void);
35 
38 /*---------------------------------------------------------------------------*/
63 /*---------------------------------------------------------------------------*/
64 
65 extern void tabinit(ap_t *ap) {
66 
67  switch (cattype) {
68  case CAT_INTWFC:
69  tabinit_1();
70  break;
71  case CAT_WFCAM:
72  tabinit_2();
73  break;
74  case CAT_BASIC:
75  tabinit_3();
76  break;
77  case CAT_OBJMASK:
78  tabinit_4(ap);
79  break;
80  case CAT_VIRCAM:
81  tabinit_6(ap);
82  break;
83  default:
84  cpl_msg_error("tabinit","Option %" CPL_SIZE_FORMAT " does not exist",
85  (cpl_size)cattype);
86  tab = NULL;
87  break;
88  }
89 }
90 
91 /*---------------------------------------------------------------------------*/
118 /*---------------------------------------------------------------------------*/
119 
120 extern int do_seeing(ap_t *ap) {
121  int status;
122 
123  switch (cattype) {
124  case CAT_INTWFC:
125  status = do_seeing_1(ap);
126  break;
127  case CAT_WFCAM:
128  status = do_seeing_2(ap);
129  break;
130  case CAT_BASIC:
131  status = do_seeing_3(ap);
132  break;
133  case CAT_OBJMASK:
134  status = do_seeing_4(ap);
135  break;
136  case CAT_VIRCAM:
137  status = do_seeing_6(ap);
138  break;
139  default:
140  status = VIR_FATAL;
141  cpl_msg_error("do_seeing","Option %" CPL_SIZE_FORMAT " does not exist",
142  (cpl_size)cattype);
143  break;
144  }
145  return(status);
146 }
147 
148 /*---------------------------------------------------------------------------*/
175 /*---------------------------------------------------------------------------*/
176 
177 extern int process_results(ap_t *ap) {
178  int status;
179 
180  switch (cattype) {
181  case CAT_INTWFC:
182  status = process_results_1(ap);
183  break;
184  case CAT_WFCAM:
185  status = process_results_2(ap);
186  break;
187  case CAT_BASIC:
188  status = process_results_3(ap);
189  break;
190  case CAT_OBJMASK:
191  status = process_results_4(ap);
192  break;
193  case CAT_VIRCAM:
194  status = process_results_6(ap);
195  break;
196  default:
197  status = VIR_FATAL;
198  cpl_msg_error("process_result","Option %" CPL_SIZE_FORMAT " does not exist",
199  (cpl_size)cattype);
200  break;
201  }
202  return(status);
203 }
204 
205 /*---------------------------------------------------------------------------*/
232 /*---------------------------------------------------------------------------*/
233 
234 extern int tabclose(ap_t *ap) {
235  int status;
236 
237  switch (cattype) {
238  case CAT_OBJMASK:
239  status = tabclose_4(ap);
240  break;
241  default:
242  status = VIR_OK;
243  break;
244  }
245  return(status);
246 }
247 
248 /*---------------------------------------------------------------------------*/
279 /*---------------------------------------------------------------------------*/
280 
281 extern void tabinit_gen(int ncols, const char *ttype[], const char *tunit[],
282  cpl_type tform[]) {
283  int i;
284  const char *fctid = "tabinit_gen";
285 
286  /* First, create the table with a default number of rows. */
287 
288  if ((tab = cpl_table_new(0)) == NULL) {
289  cpl_msg_error(fctid,"Unable to open cpl table!");
290  return;
291  }
292 
293  /* Now define all of the columns */
294 
295  for (i = 0; i < ncols; i++) {
296  cpl_table_new_column(tab,ttype[i],tform[i]);
297  cpl_table_set_column_unit(tab,ttype[i],tunit[i]);
298  }
299 
300 }
301 
302 /*---------------------------------------------------------------------------*/
332 /*---------------------------------------------------------------------------*/
333 
334 extern int do_seeing_gen(ap_t *ap, const char *col_ellipt,
335  const char *col_pkht, char *col_areals[NAREAL]) {
336  int i;
337  float fwhm,*areal[NAREAL],*ellipt,*pkht;
338 
339  /* Get some space and read the relevant columns */
340 
341  if (nobjects >= 3) {
342  ellipt = cpl_table_get_data_float(tab,col_ellipt);
343  pkht = cpl_table_get_data_float(tab,col_pkht);
344  work = cpl_malloc(nobjects*sizeof(*work));
345  for (i = 0; i < NAREAL; i++)
346  areal[i] = cpl_table_get_data_float(tab,col_areals[i]);
347 
348  /* Do the seeing calculation */
349 
350  seeing(ap,nobjects,ellipt,pkht,areal,work,&fwhm);
351  } else
352  fwhm = 0.0;
353  ap->fwhm = fwhm;
354 
355  /* Get out of here */
356 
357  tidy();
358  return(VIR_OK);
359 }
360 
361 static void tidy (void) {
362 
363  /* Free up workspace */
364 
365  freespace(work);
366 }
367 
370 /*
371 
372 $Log: not supported by cvs2svn $
373 Revision 1.5 2012/01/15 17:40:09 jim
374 Minor modifications to take into accout the changes in cpl API for v6
375 
376 Revision 1.4 2010/09/09 12:09:57 jim
377 Added docs
378 
379 Revision 1.3 2007/03/01 12:38:26 jim
380 Small modifications after a bit of code checking
381 
382 Revision 1.2 2006/11/10 09:25:39 jim
383 Modifed tabinit to only start with a single row
384 
385 Revision 1.1 2005/09/13 13:25:27 jim
386 Initial entry after modifications to make cpl compliant
387 
388 
389 */