175 return CPL_ERROR_DATA_NOT_FOUND;
179 a = cpl_wcs_get_image_dims(wcs);
181 return CPL_ERROR_ILLEGAL_INPUT;
182 naxes = cpl_array_get_data_int_const(a);
194 for (j = 1; j < naxes[1]; j += 10) {
196 double y = (double)j;
197 for (i = 1; i < naxes[0]; i += 10) {
199 double x = (double)i;
200 irplib_wcs_xytoradec(wcs, x, y, &ra, &dec);
201 if (ra >= 0.0 && ra <= 90.0) {
206 else if (ra >= 270.0 && ra <= 360.0) {
208 if (ra - 360.0 < min_4q)
227 if (first_quad && fourth_quad) {
235 dra = 0.5 * ext_search * (*ra2 - *ra1);
238 ddec = 0.5 * ext_search * (*dec2 - *dec1);
244 return CPL_ERROR_NONE;
282 int i, nrows, start, finish, first_index, last_index, irow, init, j;
284 float dectest, ratest, ramin_wrap, ramax_wrap;
285 char fullname[FILENAME_SZBUF];
287 const char *deccol[] = {
"Dec"};
292 out = cpl_table_new(0);
298 a = cpl_array_wrap_string((
char **)deccol, 1);
302 wrap = (ramin < 0.0 && ramax > 0.0) ? 2 : 1;
307 for (iwrap = 0; iwrap < wrap; iwrap++) {
308 int first_index_ra, last_index_ra;
312 ramin_wrap = ramin + 360.0;
316 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++) {
339 (void)snprintf(fullname, FILENAME_SZBUF,
"%s/npsc%03d.fits", path,
345 p = cpl_propertylist_load(fullname, 1);
347 cpl_error_set_message_macro(__func__, CPL_ERROR_DATA_NOT_FOUND,
349 "2mass file %s missing", fullname);
350 cpl_table_delete(out);
354 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
355 cpl_propertylist_delete(p);
362 first_index = nrows / 2;
363 while (finish - start >= 2) {
364 t = cpl_table_load_window(fullname, 1, 0, a, first_index, 1);
365 dectest = cpl_table_get_float(t,
"Dec", 0, NULL);
367 if (dectest < decmin) {
369 first_index = (first_index + finish) / 2;
372 finish = first_index;
373 first_index = (first_index + start) / 2;
382 last_index = start + (finish - start) / 2;
383 while (finish - start >= 2) {
384 t = cpl_table_load_window(fullname, 1, 0, a, last_index, 1);
385 dectest = cpl_table_get_float(t,
"Dec", 0, NULL);
387 if (dectest < decmax) {
389 last_index = (last_index + finish) / 2;
393 last_index = (last_index + start) / 2;
396 if (last_index < first_index)
397 last_index = first_index;
401 nrows = last_index - first_index + 1;
402 if ((t = cpl_table_load_window(fullname, 1, 0, NULL, first_index,
404 cpl_error_set_message_macro(__func__, CPL_ERROR_DATA_NOT_FOUND,
406 "Error in subset of 2mass file %s ",
408 cpl_table_delete(out);
412 cpl_table_unselect_all(t);
418 for (j = 0; j < nrows; j++) {
419 ratest = cpl_table_get_float(t,
"RA", j, NULL);
420 if (cpl_error_get_code() != CPL_ERROR_NONE) {
421 cpl_error_set_message_macro(__func__,
422 CPL_ERROR_DATA_NOT_FOUND,
424 "No RA column in 2mass file %s",
428 cpl_table_delete(out);
431 if (ratest >= ramin_wrap && ratest <= ramax_wrap)
432 cpl_table_select_row(t, j);
438 s = cpl_table_extract_selected(t);
440 cpl_table_copy_structure(out, t);
443 irow = cpl_table_get_nrow(out) + 1;
444 cpl_table_insert(out, s, irow);