40 #include "irplib_cat.h"
41 #include "irplib_wcs.h"
43 #define FILENAME_SZBUF 1024
75 (
const cpl_frame * master_index,
81 int status = CPL_ERROR_NONE;
88 fname = cpl_strdup(cpl_frame_get_filename(master_index));
89 if (access((
const char *)fname,R_OK) != 0)
91 cpl_msg_error(__func__,
"Can't access index file %s",fname);
93 return CPL_ERROR_FILE_IO;
95 *catpath = cpl_strdup(dirname(fname));
99 if ((p = cpl_propertylist_load(cpl_frame_get_filename(master_index),0)) == NULL)
101 cpl_msg_error(__func__,
"Can't load index file header %s",fname);
104 return CPL_ERROR_FILE_IO;
109 if (cpl_propertylist_has(p,
"CATNAME"))
111 *catname = cpl_strdup(cpl_propertylist_get_string(p,
"CATNAME"));
112 status = CPL_ERROR_NONE;
114 const char * unk =
"unknown";
115 *catname = cpl_strdup(unk);
116 cpl_msg_warning(__func__,
"Property CATNAME not in index file header %s",
122 cpl_propertylist_delete(p);
154 (
const cpl_wcs * wcs,
177 return CPL_ERROR_DATA_NOT_FOUND;
181 a = cpl_wcs_get_image_dims(wcs);
183 return CPL_ERROR_ILLEGAL_INPUT;
184 naxes = cpl_array_get_data_int_const(a);
196 for (j = 1; j < naxes[1]; j += 10) {
198 double y = (double)j;
199 for (i = 1; i < naxes[0]; i += 10) {
201 double x = (double)i;
202 irplib_wcs_xytoradec(wcs,x,y,&ra,&dec);
203 if (ra >= 0.0 && ra <= 90.0) {
207 }
else if (ra >= 270.0 && ra <= 360.0) {
209 if(ra - 360.0 < min_4q)
228 if (first_quad && fourth_quad) {
237 dra = 0.5*ext_search*(*ra2 - *ra1);
240 ddec = 0.5*ext_search*(*dec2 - *dec1);
246 return CPL_ERROR_NONE;
284 int i,nrows,start,finish,first_index,last_index,irow,init,j;
286 float dectest,ratest,ramin_wrap,ramax_wrap;
287 char fullname[FILENAME_SZBUF];
289 const char *deccol[] = {
"Dec"};
294 out = cpl_table_new(0);
300 a = cpl_array_wrap_string((
char **)deccol,1);
304 wrap = (ramin < 0.0 && ramax > 0.0) ? 2 : 1;
309 for (iwrap = 0; iwrap < wrap; iwrap++) {
310 int first_index_ra,last_index_ra;
314 ramin_wrap = ramin + 360.0;
317 ramin_wrap = 0.000001;
327 first_index_ra = (int)ramin_wrap;
328 last_index_ra = (int)ramax_wrap;
329 if(last_index_ra > 359)
335 for (i = first_index_ra; i <= last_index_ra; i++)
341 (void)snprintf(fullname,FILENAME_SZBUF,
"%s/npsc%03d.fits",path,i);
346 p = cpl_propertylist_load(fullname,1);
349 cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
350 __FILE__, __LINE__,
"2mass file %s missing",fullname);
351 cpl_table_delete(out);
355 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
356 cpl_propertylist_delete(p);
363 first_index = nrows/2;
364 while (finish - start >= 2)
366 t = cpl_table_load_window(fullname, 1, 0, a, first_index, 1);
367 dectest = cpl_table_get_float(t,
"Dec", 0, NULL);
369 if (dectest < decmin)
372 first_index = (first_index + finish)/2;
376 finish = first_index;
377 first_index = (first_index + start)/2;
386 last_index = start + (finish - start)/2;
387 while (finish - start >= 2)
389 t = cpl_table_load_window(fullname, 1, 0, a, last_index, 1);
390 dectest = cpl_table_get_float(t,
"Dec", 0, NULL);
392 if (dectest < decmax)
395 last_index = (last_index + finish)/2;
400 last_index = (last_index + start)/2;
403 if (last_index < first_index)
404 last_index = first_index;
408 nrows = last_index - first_index + 1;
409 if ((t = cpl_table_load_window(fullname, 1, 0, NULL, first_index,
412 cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
413 __FILE__, __LINE__,
"Error in subset of 2mass file %s ",
415 cpl_table_delete(out);
419 cpl_table_unselect_all(t);
425 for (j = 0; j < nrows; j++)
427 ratest = cpl_table_get_float(t,
"RA", j, NULL);
428 if (cpl_error_get_code() != CPL_ERROR_NONE)
430 cpl_error_set_message_macro(__func__,CPL_ERROR_DATA_NOT_FOUND,
431 __FILE__, __LINE__,
"No RA column in 2mass file %s",
435 cpl_table_delete(out);
438 if (ratest >= ramin_wrap && ratest <= ramax_wrap)
439 cpl_table_select_row(t, j);
445 s = cpl_table_extract_selected(t);
448 cpl_table_copy_structure(out, t);
451 irow = cpl_table_get_nrow(out) + 1;
452 cpl_table_insert(out, s, irow);
cpl_error_code irplib_cat_get_image_limits(const cpl_wcs *wcs, float ext_search, double *ra1, double *ra2, double *dec1, double *dec2)
Get coverage in ra, dec of a frame.
cpl_table * irplib_2mass_extract(char *path, float ramin, float ramax, float decmin, float decmax)
Extract standards from the 2mass catalogue.
int irplib_2mass_get_catpars(const cpl_frame *master_index, char **catpath, char **catname)
Find the name of the standard catalogue being used and its location.