38#include "casu_utils.h"
39#include "casu_wcsutils.h"
40#include "eris_nix_catalogue.h"
63 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
67 cpl_ensure_code(frameset, CPL_ERROR_NULL_INPUT);
68 cpl_ensure_code(tag, CPL_ERROR_NULL_INPUT);
72 const cpl_frame * target_frame = cpl_frameset_find_const(frameset, tag);
73 if (target_frame != NULL) {
74 const char * filename = cpl_frame_get_filename(target_frame);
79 cpl_table * whole = cpl_table_load(filename, 1, CPL_FALSE);
84 en_catalogue_name_conformance(whole);
88 cpl_propertylist * pheader = cpl_propertylist_load(filename, 0);
89 cpl_propertylist * header = cpl_propertylist_load(filename, 1);
90 cpl_table_save(whole, pheader, header, filename, CPL_IO_CREATE);
91 cpl_propertylist_delete(pheader);
92 cpl_propertylist_delete(header);
94 cpl_table_delete(whole);
97 cpl_msg_warning(cpl_func,
"SoF has no file tagged %s", tag);
100 return cpl_error_get_code();
117cpl_error_code en_catalogue_coverage(
const located_imagelist * jitters,
118 double * ramin,
double * ramax,
119 double * decmin,
double * decmax) {
121 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
123 cpl_ensure_code(jitters, CPL_ERROR_NULL_INPUT);
125 for (cpl_size j=0; j < jitters->size; j++) {
130 int status = CASU_OK;
131 casu_coverage(jitters->limages[j]->plist, 1, &ra1, &ra2, &dec1,
133 enu_check(status==CASU_OK, CPL_ERROR_INCOMPATIBLE_INPUT,
134 "error in casu_coverage: status=%d", status);
142 if (ra1 < *ramin) *ramin = ra1;
143 if (ra2 > *ramax) *ramax = ra2;
144 if (dec1 < *decmin) *decmin = dec1;
145 if (dec2 < *decmax) *decmax = dec2;
149 cpl_msg_info(cpl_func,
"...coverage %5.3f %5.3f %5.3f %5.3f", *ramin,
150 *ramax, *decmin, *decmax);
152 return cpl_error_get_code();
170cpl_table * en_catalogue_load_from_file(
const char * filename,
174 const double decmax) {
177 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
179 cpl_table * whole = NULL;
180 cpl_table * result = NULL;
184 cpl_ensure(filename, CPL_ERROR_NULL_INPUT, NULL);
189 whole = cpl_table_load(filename, 1, CPL_FALSE);
193 en_catalogue_name_conformance(whole);
195 cpl_size nrows = cpl_table_get_nrow(whole);
196 cpl_msg_info(cpl_func,
"read rows %d %s", (
int)nrows, cpl_error_get_message());
200 if (ramin < 0.0 && ramax > 0.0) {
204 double ramin1 = ramin + 360.0;
205 double ramax1 = 360.0;
207 cpl_table_unselect_all(whole);
208 cpl_table_or_selected_double(whole,
"RA", CPL_NOT_LESS_THAN, ramin1);
209 cpl_table_and_selected_double(whole,
"RA", CPL_NOT_GREATER_THAN,
211 cpl_table_and_selected_double(whole,
"DEC", CPL_NOT_LESS_THAN, decmin);
212 cpl_table_and_selected_double(whole,
"DEC", CPL_NOT_GREATER_THAN,
214 result = cpl_table_extract_selected(whole);
221 cpl_table_unselect_all(whole);
222 cpl_table_or_selected_double(whole,
"RA", CPL_NOT_LESS_THAN, ramin1);
223 cpl_table_and_selected_double(whole,
"RA", CPL_NOT_GREATER_THAN,
225 cpl_table_and_selected_double(whole,
"DEC", CPL_NOT_LESS_THAN, decmin);
226 cpl_table_and_selected_double(whole,
"DEC", CPL_NOT_GREATER_THAN,
228 cpl_table * out2 = cpl_table_extract_selected(whole);
232 nrows = cpl_table_get_nrow(result);
233 cpl_table_insert(result, out2, nrows+1);
234 cpl_table_delete(out2);
240 cpl_table_unselect_all(whole);
241 cpl_table_or_selected_double(whole,
"RA", CPL_NOT_LESS_THAN, ramin);
242 cpl_table_and_selected_double(whole,
"RA", CPL_NOT_GREATER_THAN,
244 cpl_table_and_selected_double(whole,
"DEC", CPL_NOT_LESS_THAN, decmin);
245 cpl_table_and_selected_double(whole,
"DEC", CPL_NOT_GREATER_THAN,
247 result = cpl_table_extract_selected(whole);
249 for (cpl_size ir=0; ir<nrows; ir++) {
251 double ra = cpl_table_get(whole,
"RA", ir, &null);
252 double dec = cpl_table_get(whole,
"DEC", ir, &null);
254 cpl_msg_info(cpl_func,
"%8.6f %8.6f %8.6f %8.6f %8.6f %8.6f", ra, ramin, ramax, dec, decmin, decmax);
260 cpl_propertylist * p = cpl_propertylist_new();
261 cpl_propertylist_append_bool(p,
"DEC", 0);
262 cpl_table_sort(result, p);
263 cpl_propertylist_delete(p);
267 cpl_table_delete(whole);
268 if (cpl_error_get_code() != CPL_ERROR_NONE) {
269 cpl_table_delete(result);
290cpl_table * en_catalogue_load_from_frameset(cpl_frameset * frameset,
297 const int required) {
300 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
302 cpl_table * result = NULL;
306 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
307 cpl_ensure(tag, CPL_ERROR_NULL_INPUT, NULL);
311 const cpl_frame * target_frame = cpl_frameset_find_const(frameset, tag);
312 if (target_frame != NULL) {
313 const char * filename = cpl_frame_get_filename(target_frame);
315 result = en_catalogue_load_from_file(filename, ramin, ramax, decmin,
317 cpl_frameset_insert(used, cpl_frame_duplicate(target_frame));
319 enu_check(!required, CPL_ERROR_DATA_NOT_FOUND,
320 "SoF has no file tagged %s", tag);
324 if (cpl_error_get_code() != CPL_ERROR_NONE) {
325 cpl_table_delete(result);
344cpl_error_code en_catalogue_name_conformance(cpl_table * catalogue) {
346 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
348 cpl_ensure_code(catalogue, CPL_ERROR_NULL_INPUT);
353 if (!cpl_table_has_column(catalogue,
"RA")) {
354 if (cpl_table_has_column(catalogue,
"ra")) {
355 cpl_table_name_column(catalogue,
"ra",
"RA");
358 if (!cpl_table_has_column(catalogue,
"DEC")) {
359 if (cpl_table_has_column(catalogue,
"dec")) {
360 cpl_table_name_column(catalogue,
"dec",
"DEC");
361 }
else if (cpl_table_has_column(catalogue,
"Dec")) {
362 cpl_table_duplicate_column(catalogue,
"DEC", catalogue,
"Dec");
366 return cpl_error_get_code();
cpl_error_code en_catalogue_conform_naming(cpl_frameset *frameset, const char *tag)
Rename essential columns to standard names.