File: vmphotometrictable.c

package info (click to toggle)
cpl-plugin-vimos 2.9.15%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 18,560 kB
  • ctags: 6,341
  • sloc: ansic: 148,777; sh: 11,457; cpp: 724; makefile: 606; python: 287; perl: 10
file content (214 lines) | stat: -rw-r--r-- 5,126 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* $Id: vmphotometrictable.c,v 1.2 2013-03-25 11:43:04 cgarcia Exp $
 *
 * This file is part of the VIMOS Pipeline
 * Copyright (C) 2002-2004 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <string.h>

#include <fitsio.h>

#include <pilmessages.h>
#include <cpl_msg.h>
#include <piltranslator.h>

#include "vmtable.h"
#include "vmmath.h"
#include "vmphotometrictable.h"


/**
 * @name vmphotometrictable Photometric Table
 *
 * @doc
 *   The module provides the functions to treat photometric tables.
 */

/**@{*/

/*
 *  Allocate a new Photometric Table. This is a VimosTable with name 
 *  VM_IPC (which should have value "IPC").
 */

VimosTable *newPhotometricTable()
{
  VimosTable *newTab;

  /* allocate new VimosTable */
  newTab = newTable();

  if (newTab == NULL) {
    return NULL;
  }

  /* copy "IPC" into name of table */
  strcpy(newTab->name, VM_IPC);
  newTab->descs = newStringDescriptor("ESO PRO TABLE", VM_IPC, "");

  /* return address of new Photometric Table */
  return(newTab);

}

/** 
 * @memo 
 *  Read photometric Table from fitsfile (the file has to be open)
 *
 * @return EXIT_SUCCESS or EXIT_FAILURE. 
 *
 * @param photTable        photometric Table
 * @param fptr             pointer to fitsfile 
 *
 * @doc 
 *   Read photometric Table from fitsfile (the file has to be already open)
 *
 * @author P. Sartoretti
 */


VimosBool readFitsPhotometricTable(VimosTable *photTable, fitsfile *fptr)
{
  int status = 0;
  char     modName[] = "readFitsPhotometricTable";


  /* validate input */
  if (photTable == NULL) {
    cpl_msg_error(modName,"NULL input table");
    return (VM_FALSE);
  }

  if (fptr == NULL) {
    cpl_msg_error(modName,"NULL pointer to fitsfile");
    return (VM_FALSE);
  }

  if (strcmp(photTable->name, VM_IPC) ) {
    cpl_msg_error(modName,"Invalid input table");
    return (VM_FALSE);
  }

/* open Table */
  if (fits_movnam_hdu(fptr, BINARY_TBL, VM_IPC, 0, &status)) {
    cpl_msg_error(modName,"The function fits_movnam_hdu has returned an  "
                "error (code %d)", status);
    return(VM_FALSE);
  }

  photTable->fptr = fptr;


 /* read Table */

  if (!readFitsTable(photTable, photTable->fptr)) {
    cpl_msg_info(modName, "Error in reading the FITS file");
    return VM_FALSE;
  }
  if (!checkPhotometricTable(photTable)) {
    cpl_msg_info(modName, "Photometric Table is not complete");
    return VM_FALSE;
  }

  return VM_TRUE;
}
/** 
 * @memo 
 *  Check the photometric Table 
 *
 * @return EXIT_SUCCESS or EXIT_FAILURE. 
 *
 * @param photTable        photometric Table 
 *
 * @doc 
 *   Check if all necessary descriptors and columns of the photometric Table 
 *   are present
 *
 * @author P. Sartoretti
 */

VimosBool checkPhotometricTable(VimosTable *photTable)
{
  char     modName[] = "checkPhotometricTable";


  if (photTable == NULL) {
    cpl_msg_error(modName,"NULL input table");
    return (VM_FALSE);
  }

  if ( strcmp(photTable->name, VM_IPC) ) {
    cpl_msg_error(modName,"Invalid input table");
    return (VM_FALSE);
  }
  /* check if all the necessary descriptors are there */

  if (!findDescInTab(photTable, pilTrnGetKeyword("MagZero"))) {
    cpl_msg_error(modName, "Descriptor MagZero not found");
    return VM_FALSE;
  }
   if (!findDescInTab(photTable, pilTrnGetKeyword("Extinction"))) {
    cpl_msg_error(modName, "Descriptor Extinction not found");
    return VM_FALSE;
  }
 return VM_TRUE;
}


/** 
 * @memo 
 *  Write photometric Table to fitsfile 
 *
 * @return EXIT_SUCCESS or EXIT_FAILURE.
 * 
 * @param filename        name of the fitsfile 
 * @param photTable       photometric Table
 *
 *
 * @doc 
 *   Write photometric Table to fitsfile 
 *
 * @author P. Sartoretti
 */
VimosBool writeFitsPhotometricTable(char *filename, VimosTable *photTable)
{
 char modName[]  = "writeFitsPhotometricTable";

 /* validate input */
  if (photTable == NULL) {
    cpl_msg_error(modName,"NULL input table");
    return(VM_FALSE);
  }
  if ( strcmp(photTable->name, VM_IPC) ) {
    cpl_msg_error(modName,"Invalid input table");
    return(VM_FALSE);
  }
  if (!checkPhotometricTable(photTable)) {
    cpl_msg_info(modName, "Photometric Table is not complete");
    return VM_FALSE;
  }
   if (!createFitsTable(filename, photTable, VM_IPC)) {
    cpl_msg_error(modName, "Error in writing fits table");
    return VM_FALSE;
  }
  return VM_TRUE;
}
/**@}*/