34#ifndef _POSIX_C_SOURCE
35#define _POSIX_C_SOURCE 200112L
39#define _XOPEN_SOURCE 500
46#include <sys/socket.h>
48#include <netinet/in.h>
63#include "catalogue/casu_utils.h"
64#include "catalogue/casu_wcsutils.h"
66#define CACHEDIR ".catcache"
67#define CACHEIND ".catcache/index"
70#define CDS "vizier.cds.unistra.fr"
74static cpl_table *casu_2mass_extract(
char *path,
float ramin,
float ramax,
75 float decmin,
float decmax);
76static cpl_table *casu_ppmxl_extract(
char *path,
float ramin1,
float ramax1,
77 float decmin,
float decmax);
78static cpl_table *casu_apass_extract(
char *path,
float ramin1,
float ramax1,
79 float decmin,
float decmax);
80static cpl_table *casu_local_extract(
char *path,
float ramin1,
float ramax1,
81 float decmin,
float decmax);
82static cpl_table *check_cache(
char *catname,
float ra1_im,
float ra2_im,
83 float dec1_im,
float dec2_im,
char *cacheloc);
84static void addto_cache(cpl_table *stds,
char *catname,
float ramin,
85 float ramax,
float decmin,
float decmax,
87static char *form_request(
float ra,
float dec,
float dra,
float ddec,
88 float equinox,
const char *catid);
89static char *url_encode(
char *instring);
90static int connect_site(
const char *site,
int *sock);
91static int send_request(
int sock,
char *req_string,
int isbin);
92static int get_response(
int soc, cpl_table **outtab);
96static void calculate_magerr(cpl_table* stds,
const char* magerr,
const char* flux,
const char* fluxerr)
98 const double k = 1.086;
99 cpl_table_duplicate_column(stds, magerr, stds, fluxerr);
100 cpl_table_divide_columns(stds, magerr, flux);
101 cpl_table_multiply_scalar(stds, magerr, k);
168 char *catname,
int cdssearch,
char *cacheloc,
169 cpl_table **stds,
int *status) {
170 const char *fctid =
"casu_getstds";
171 double xx1,xx2,yy1,yy2,r,d,xx,yy,*rad,*decd,dra,ddec;
172 float ramin,ramax,decmin,decmax,*ra,*dec,*x,*y,ramid,decmid;
176 char *req_string,catname2[64],*cdscatname,*cdscatid,*path2;
177 int isbin = (cdssearch > 6 ? 1 : 0);
182 if (*status != CASU_OK)
195 ddec = decmax - decmin;
196 ramid = 0.5*(ramax+ramin);
197 decmid = 0.5*(decmax+decmin);
199 cpl_msg_info(fctid,
"Searching catalogue %d, RA/Dec range [%f:%f, %f:%f]", cdssearch, ramin, ramax, decmin, decmax);
205 if (casu_getstds_cdslist(cdssearch,&cdscatname,&cdscatid,status) !=
208 (void)strcpy(catname2,cdscatname);
209 freespace(cdscatname);
211 (void)strcpy(catname2,catname);
215 *stds = check_cache(catname2,ramin,ramax,decmin,decmax,cacheloc);
224 if (cdssearch == 0) {
225 cpl_msg_info(fctid,
"Reading local catalogue");
227 path2 = cpl_strdup(path);
228 if (! strcmp(catname2,
"casu_2mass")) {
229 *stds = casu_2mass_extract(dirname(path2),ramin,ramax,decmin,
231 }
else if (! strcmp(catname2,
"casu_ppmxl")) {
232 *stds = casu_ppmxl_extract(dirname(path2),ramin,ramax,decmin,
234 }
else if (! strcmp(catname2,
"casu_apass")) {
235 *stds = casu_apass_extract(dirname(path2),ramin,ramax,decmin,
238 *stds = casu_local_extract(path2,ramin,ramax,decmin,decmax);
242 cpl_msg_error(fctid,
"Unable to extract data in %s",path);
249 cpl_msg_info(fctid,
"Requesting catalogue data from CDS");
251 req_string = form_request(ramid,decmid,dra,ddec,2000.0,
257 if (connect_site(CDS,&sock) != CASU_OK) {
258 cpl_msg_warning(fctid,
"Couldn't connect to CDS");
264 if (send_request(sock,req_string,isbin) != CASU_OK) {
265 cpl_msg_warning(fctid,
"Couldn't send request to site CDS");
272 if (get_response(sock,stds) != CASU_OK) {
273 cpl_msg_warning(fctid,
"Error receiving info from site CDS");
283 if (cpl_table_has_column(*stds,
"RAJ2000")) {
284 cpl_table_name_column(*stds,
"RAJ2000",
"RA");
286 cpl_table_duplicate_column(*stds,
"RA", *stds,
"_RAJ2000");
288 if (cpl_table_has_column(*stds,
"DEJ2000")) {
289 cpl_table_name_column(*stds,
"DEJ2000",
"Dec");
291 cpl_table_duplicate_column(*stds,
"Dec", *stds,
"_DEJ2000");
295 if (cdssearch == 8) {
296 cpl_table_duplicate_column(*stds,
"DEC", *stds,
"Dec");
297 calculate_magerr(*stds,
"ERR_Umag",
"FU",
"e_FU");
298 calculate_magerr(*stds,
"ERR_Bmag",
"FB",
"e_FB");
299 calculate_magerr(*stds,
"ERR_Vmag",
"FV",
"e_FV");
300 calculate_magerr(*stds,
"ERR_Rmag",
"FR",
"e_FR");
301 calculate_magerr(*stds,
"ERR_Imag",
"FI",
"e_FI");
302 cpl_table_new_column(*stds,
"OBJECT", CPL_TYPE_STRING);
309 addto_cache(*stds,catname2,ramin,ramax,decmin,decmax,cacheloc);
314 n = (int)cpl_table_get_nrow(*stds);
315 cpl_msg_info(fctid,
"Found %d stars in catalogue", n);
322 cpl_table_new_column(*stds,
"xpredict",CPL_TYPE_FLOAT);
323 cpl_table_new_column(*stds,
"ypredict",CPL_TYPE_FLOAT);
327 if (cdssearch == 8) {
328 for (i = 0; i < n; i++) {
329 long long src = cpl_table_get_long_long(*stds,
"Source", i, NULL);
330 char* tmpstr = cpl_sprintf(
"%lld", src);
331 cpl_table_set_string(*stds,
"OBJECT", i, tmpstr);
338 wcs = cpl_wcs_new_from_propertylist((
const cpl_propertylist *)plist);
339 if (cpl_table_get_column_type(*stds,
"RA") == CPL_TYPE_FLOAT) {
340 ra = cpl_table_get_data_float(*stds,
"RA");
341 dec = cpl_table_get_data_float(*stds,
"Dec");
342 x = cpl_malloc(n*
sizeof(*x));
343 y = cpl_malloc(n*
sizeof(*y));
344 for (i = 0; i < n; i++) {
352 rad = cpl_table_get_data_double(*stds,
"RA");
353 decd = cpl_table_get_data_double(*stds,
"Dec");
354 x = cpl_malloc(n*
sizeof(*x));
355 y = cpl_malloc(n*
sizeof(*y));
356 for (i = 0; i < n; i++) {
368 cpl_table_wrap_float(*stds,x,
"xpredict");
369 cpl_table_set_column_unit(*stds,
"xpredict",
"pixels");
370 cpl_table_wrap_float(*stds,y,
"ypredict");
371 cpl_table_set_column_unit(*stds,
"ypredict",
"pixels");
375 p = cpl_propertylist_new();
376 cpl_propertylist_append_bool(p,
"ypredict",0);
377 cpl_table_sort(*stds,p);
378 cpl_propertylist_delete(p);
425static const int maxcds = 8;
426static const char *cdscatnames[9] =
427 {
"",
"2mass",
"usnob",
"ppmxl",
"landolt",
"wise",
"apass",
"gaiadr3",
"gaiasyntphot"};
428static const char *cdscats[9] =
429 {
"",
"II/246",
"I/284",
"I/317",
"II/183A",
"II/311",
"II/336",
"I/355",
"I/360/syntphot"};
431extern int casu_getstds_cdslist(
int cdschoice,
char **cdscatname,
432 char **cdscatid,
int *status) {
433 const char *fctid =
"casu_getstds_cdslist";
435 if (*status != CASU_OK)
442 if (cdschoice < 0 || cdschoice > maxcds) {
443 cpl_msg_error(fctid,
"CDS catalogue choice must be >= 0 && <= %d",
447 *cdscatname = cpl_strdup(cdscatnames[cdschoice]);
448 *cdscatid = cpl_strdup(cdscats[cdschoice]);
482 for (
int i=1; i<=maxcds; i++) {
483 if (!strcmp(cdscatname, cdscatnames[i])) {
521static cpl_table *casu_2mass_extract(
char *path,
float ramin1,
float ramax1,
522 float decmin,
float decmax) {
524 int i,nrows,start,finish,first_index,last_index,irow,init,j;
525 int first_index_ra,last_index_ra,wrap,iwrap;
526 float dectest,ratest,ramin,ramax;
527 char fullname[SZBUF];
529 const char *deccol =
"Dec";
534 o = cpl_table_new(0);
539 a = cpl_array_wrap_string((
char **)&deccol,1);
543 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
548 for (iwrap = 0; iwrap < wrap; iwrap++) {
551 ramin = ramin1 + 360.0;
564 first_index_ra = (int)ramin;
565 last_index_ra = min((
int)ramax,359);
570 for (i = first_index_ra; i <= last_index_ra; i++) {
575 (void)snprintf(fullname,SZBUF,
"%s/npsc%03d.fits",path,i);
580 p = cpl_propertylist_load(fullname,1);
586 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
587 cpl_propertylist_delete(p);
594 first_index = nrows/2;
595 while (finish - start >= 2) {
596 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
598 dectest = cpl_table_get_double(t,
"Dec",0,NULL);
600 if (dectest < decmin) {
602 first_index = (first_index + finish)/2;
604 finish = first_index;
605 first_index = (first_index + start)/2;
614 last_index = start + (finish - start)/2;
615 while (finish - start >= 2) {
616 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
618 dectest = cpl_table_get_double(t,
"Dec",0,NULL);
620 if (dectest < decmax) {
622 last_index = (last_index + finish)/2;
625 last_index = (last_index + start)/2;
628 if (last_index < first_index)
629 last_index = first_index;
633 nrows = last_index - first_index + 1;
634 if ((t = cpl_table_load_window(fullname,1,1,NULL,
635 (cpl_size)first_index,
636 (cpl_size)nrows)) == NULL) {
641 cpl_table_unselect_all(t);
647 for (j = 0; j < nrows; j++) {
648 ratest = cpl_table_get_double(t,
"RA",(cpl_size)j,NULL);
649 if (cpl_error_get_code() != CPL_ERROR_NONE) {
655 if (ratest >= ramin && ratest <= ramax)
656 cpl_table_select_row(t,(cpl_size)j);
662 s = cpl_table_extract_selected(t);
664 cpl_table_copy_structure(o,t);
667 irow = (int)cpl_table_get_nrow(o) + 1;
668 cpl_table_insert(o,s,(cpl_size)irow);
713static cpl_table *casu_ppmxl_extract(
char *path,
float ramin1,
float ramax1,
714 float decmin,
float decmax) {
716 int i,nrows,start,finish,first_index,last_index,irow,init,j;
717 int first_index_ra,last_index_ra,wrap,iwrap;
718 float dectest,ratest,ramin,ramax;
719 char fullname[SZBUF];
721 const char *deccol =
"Dec";
726 o = cpl_table_new(0);
731 a = cpl_array_wrap_string((
char **)&deccol,1);
735 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
740 for (iwrap = 0; iwrap < wrap; iwrap++) {
743 ramin = ramin1 + 360.0;
756 first_index_ra = (int)ramin;
757 last_index_ra = min((
int)ramax,359);
762 for (i = first_index_ra; i <= last_index_ra; i++) {
767 (void)snprintf(fullname,SZBUF,
"%s/nppmxl%03d.fits",path,i);
772 p = cpl_propertylist_load(fullname,1);
778 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
779 cpl_propertylist_delete(p);
786 first_index = nrows/2;
787 while (finish - start >= 2) {
788 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
790 dectest = (float)cpl_table_get_double(t,
"Dec",0,NULL);
792 if (dectest < decmin) {
794 first_index = (first_index + finish)/2;
796 finish = first_index;
797 first_index = (first_index + start)/2;
806 last_index = start + (finish - start)/2;
807 while (finish - start >= 2) {
808 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
810 dectest = (float)cpl_table_get_double(t,
"Dec",0,NULL);
812 if (dectest < decmax) {
814 last_index = (last_index + finish)/2;
817 last_index = (last_index + start)/2;
820 if (last_index < first_index)
821 last_index = first_index;
825 nrows = last_index - first_index + 1;
826 if ((t = cpl_table_load_window(fullname,1,1,NULL,
827 (cpl_size)first_index,
828 (cpl_size)nrows)) == NULL) {
833 cpl_table_unselect_all(t);
839 for (j = 0; j < nrows; j++) {
840 ratest = (float)cpl_table_get_double(t,
"RA",(cpl_size)j,NULL);
841 if (cpl_error_get_code() != CPL_ERROR_NONE) {
847 if (ratest >= ramin && ratest <= ramax)
848 cpl_table_select_row(t,(cpl_size)j);
854 s = cpl_table_extract_selected(t);
856 cpl_table_copy_structure(o,t);
859 irow = (int)cpl_table_get_nrow(o) + 1;
860 cpl_table_insert(o,s,(cpl_size)irow);
905static cpl_table *casu_apass_extract(
char *path,
float ramin1,
float ramax1,
906 float decmin,
float decmax) {
908 int i,nrows,start,finish,first_index,last_index,irow,init,j;
909 int first_index_ra,last_index_ra,wrap,iwrap;
910 float dectest,ratest,ramin,ramax;
911 char fullname[SZBUF];
913 const char *racol =
"RA";
918 o = cpl_table_new(0);
923 a = cpl_array_wrap_string((
char **)&racol,1);
927 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
932 for (iwrap = 0; iwrap < wrap; iwrap++) {
935 ramin = ramin1 + 360.0;
948 first_index_ra = (int)ramin;
949 last_index_ra = min((
int)ramax,359);
954 for (i = first_index_ra; i <= last_index_ra; i++) {
959 (void)snprintf(fullname,SZBUF,
"%s/casuapass_%03d.fits",path,i);
964 p = cpl_propertylist_load(fullname,1);
970 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
971 cpl_propertylist_delete(p);
978 first_index = nrows/2;
979 while (finish - start >= 2) {
980 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
982 ratest = (float)cpl_table_get_double(t,
"RA",0,NULL);
984 if (ratest < ramin) {
986 first_index = (first_index + finish)/2;
988 finish = first_index;
989 first_index = (first_index + start)/2;
998 last_index = start + (finish - start)/2;
999 while (finish - start >= 2) {
1000 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
1002 ratest = (float)cpl_table_get_double(t,
"RA",0,NULL);
1003 cpl_table_delete(t);
1004 if (ratest < ramax) {
1006 last_index = (last_index + finish)/2;
1008 finish = last_index;
1009 last_index = (last_index + start)/2;
1012 if (last_index < first_index)
1013 last_index = first_index;
1017 nrows = last_index - first_index + 1;
1018 if ((t = cpl_table_load_window(fullname,1,1,NULL,
1019 (cpl_size)first_index,
1020 (cpl_size)nrows)) == NULL) {
1022 cpl_array_unwrap(a);
1025 cpl_table_unselect_all(t);
1031 for (j = 0; j < nrows; j++) {
1032 dectest = (float)cpl_table_get_double(t,
"Dec",(cpl_size)j,NULL);
1033 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1034 cpl_table_delete(t);
1035 cpl_array_unwrap(a);
1039 if (dectest >= decmin && dectest <= decmax)
1040 cpl_table_select_row(t,(cpl_size)j);
1046 s = cpl_table_extract_selected(t);
1048 cpl_table_copy_structure(o,t);
1051 irow = (int)cpl_table_get_nrow(o) + 1;
1052 cpl_table_insert(o,s,(cpl_size)irow);
1056 cpl_table_delete(t);
1057 cpl_table_delete(s);
1063 cpl_array_unwrap(a);
1098static cpl_table *casu_local_extract(
char *path,
float ramin1,
float ramax1,
1099 float decmin,
float decmax) {
1100 cpl_table *whole,*out,*out2;
1101 int wrap,iwrap,nrows;
1103 cpl_propertylist *p;
1108 whole = cpl_table_load((
const char *)path,1,0);
1112 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
1118 for (iwrap = 0; iwrap < wrap; iwrap++) {
1121 ramin = ramin1 + 360.0;
1131 cpl_table_unselect_all(whole);
1135 cpl_table_or_selected_double(whole,
"RA",CPL_NOT_LESS_THAN,
1137 cpl_table_and_selected_double(whole,
"RA",CPL_NOT_GREATER_THAN,
1139 cpl_table_and_selected_double(whole,
"Dec",CPL_NOT_LESS_THAN,
1141 cpl_table_and_selected_double(whole,
"Dec",CPL_NOT_GREATER_THAN,
1147 out = cpl_table_extract_selected(whole);
1149 out2 = cpl_table_extract_selected(whole);
1150 nrows = cpl_table_get_nrow(out);
1151 cpl_table_insert(out,out2,nrows+1);
1152 cpl_table_delete(out2);
1158 p = cpl_propertylist_new();
1159 cpl_propertylist_append_bool(p,
"Dec",0);
1160 cpl_table_sort(out,p);
1161 cpl_propertylist_delete(p);
1197static cpl_table *check_cache(
char *catname,
float ra1_im,
float ra2_im,
1198 float dec1_im,
float dec2_im,
char *cacheloc) {
1201 char fname[BUFSIZ],catname2[SZBUF];
1202 char * cat_cache = NULL;
1203 float best,ra1_cat,ra2_cat,dec1_cat,dec2_cat,d1,d2,fra,fdec,ftot;
1208 (void)snprintf(fname,BUFSIZ,
"%s/%s",cacheloc,CACHEIND);
1209 fd = fopen(fname,
"r");
1215 wrap1 = (ra1_im < 0.0 ? 1 : 0);
1221 while (fscanf(fd,
"%8191s %1023s %g %g %g %g",
1222 fname,catname2,&ra1_cat,&ra2_cat,
1223 &dec1_cat,&dec2_cat) != EOF) {
1224 wrap2 = (ra1_cat < 0.0 ? 1 : 0);
1227 if (strcmp(catname,catname2))
1232 if (!(((ra1_im >= ra1_cat && ra1_im <= ra2_cat) ||
1233 (ra2_im >= ra1_cat && ra2_im <= ra2_cat)) &&
1234 ((dec1_im >= dec1_cat && dec1_im <= dec2_cat) ||
1235 (dec2_im >= dec1_cat && dec2_im <= dec2_cat))))
1240 d1 = max(0.0,ra1_cat-ra1_im);
1241 d2 = max(0.0,ra2_im-ra2_cat);
1242 fra = 1.0 - (d1 + d2)/(ra2_im - ra1_im);
1243 d1 = max(0.0,dec1_cat-dec1_im);
1244 d2 = max(0.0,dec2_im-dec2_cat);
1245 fdec = 1.0 - (d1 + d2)/(dec2_im - dec1_im);
1251 cpl_free(cat_cache);
1252 cat_cache = cpl_sprintf(
"%s/%s/%s",cacheloc,CACHEDIR,fname);
1266 out_cat = cpl_table_load(cat_cache,1,1);
1267 cpl_free(cat_cache);
1269 cpl_msg_info(cpl_func,
"Using cached catalogue data");
1304static void addto_cache(cpl_table *stds,
char *catname,
float ramin,
1305 float ramax,
float decmin,
float decmax,
1308 char newname[SZBUF];
1314 (void)snprintf(newname,SZBUF,
"%s/%s",cacheloc,CACHEDIR);
1315 if (access(newname,0) != 0)
1316 mkdir(newname,0755);
1320 (void)snprintf(newname,SZBUF,
"%s/%s",cacheloc,CACHEIND);
1321 fd = fopen(newname,
"a");
1329 snprintf(newname,SZBUF,
"%s/%s/cch_%08d",cacheloc,CACHEDIR,i);
1330 if (access(newname,F_OK) != 0)
1337 snprintf(newname,SZBUF,
"%s/%s/cch_%08d",cacheloc,CACHEDIR,i);
1338 cpl_table_save(stds,NULL,NULL,newname,CPL_IO_DEFAULT);
1339 snprintf(newname,SZBUF,
"cch_%08d",i);
1340 if (cpl_error_get_code() == CPL_ERROR_NONE)
1341 fprintf(fd,
"%s %s %g %g %g %g\n",newname,catname,ramin-0.0005,
1342 ramax+0.0005,decmin-0.0005,decmax+0.0005);
1371static int get_response(
int sock, cpl_table **outtab) {
1372 int nnewline,i,nv,irem = 0,fd;
1374 char buf[BUFMAX],outfile[32];
1375 const char *fctid =
"get_response";
1381 nv = recv(sock,buf,
sizeof(buf),0);
1383 cpl_msg_warning(fctid,
"Unable to find double newline");
1386 for (i = 0; i < nv; i++) {
1387 if (buf[i] ==
'\n') {
1392 if (nnewline && buf[i] !=
'\r')
1396 if (nnewline == 2) {
1404 for (i = irem; i < nv; i++)
1405 buf[i-irem] = buf[i];
1410 (void)snprintf(outfile,32,
"stdsXXXXXX");
1411 fd = mkstemp(outfile);
1416 ssize_t written = write(fd,buf,nv);
1418 cpl_msg_info(cpl_func,
"Not all bytes could be written - "
1421 nv = recv(sock,buf,
sizeof(buf),0);
1425 cpl_msg_warning(fctid,
"Read from socket failed");
1436 *outtab = cpl_table_load(outfile,1,0);
1437 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1438 cpl_msg_warning(fctid,
"No standards were found");
1444 nrows = (int)cpl_table_get_nrow(*outtab);
1446 cpl_msg_warning(fctid,
"No standards table had no rows");
1487static int send_request(
int sock,
char *req_string,
int isbin) {
1489 const char *fctid =
"send_request";
1494 sprintf(buf,
"GET /viz-bin/asu-binfits?%s HTTP/1.0\r\n\r\n",req_string);
1496 sprintf(buf,
"GET /viz-bin/asu-fits?%s HTTP/1.0\r\n\r\n",req_string);
1498 if (send(sock,buf,strlen(buf),0) < 0) {
1499 cpl_msg_warning(fctid,
"Attempt to send message failed, error: %d\n",
1531static int connect_site(
const char *site,
int *sock) {
1533 struct sockaddr_in ssin;
1534 const char *fctid =
"connect_site";
1538 hp = gethostbyname(site);
1540 cpl_msg_warning(fctid,
"Unable to get host information for %s\n",site);
1543 ssin.sin_family = hp->h_addrtype;
1544 memcpy(&ssin.sin_addr,hp->h_addr_list[0],hp->h_length);
1545 ssin.sin_port = htons(PORT);
1549 *sock = socket(hp->h_addrtype,SOCK_STREAM,0);
1551 cpl_msg_warning(fctid,
"Unable to create socket descriptor for %s\n",
1553 return (CASU_FATAL);
1558 if (connect(*sock,(
struct sockaddr*)&ssin,
sizeof(ssin)) < 0) {
1559 cpl_msg_warning(fctid,
"Unable to connect to site: %s\n",site);
1598static char *form_request(
float ra,
float dec,
float dra,
float ddec,
1599 float equinox,
const char *catid) {
1600 const char *fctid =
"form_request";
1601 static char buf[2*BUFSIZ];
1602 char buf2[BUFSIZ],equi[1];
1604 cpl_msg_debug(fctid,
"catid is: %s", catid);
1610 (void)snprintf(buf2,BUFSIZ,
"-c=%8.3f %8.3f",ra,dec);
1611 (void)strncpy(buf,url_encode(buf2),BUFSIZ);
1615 (void)snprintf(buf2,BUFSIZ,
"-c.bd=%g/%g",dra,ddec);
1616 (void)strncat(buf,
"&",BUFSIZ);
1617 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1621 (void)snprintf(buf2,BUFSIZ,
"-source=%s",catid);
1622 (void)strncat(buf,
"&",BUFSIZ);
1623 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1627 equi[0] = (equinox == 1950.0 ?
'B' :
'J');
1628 (void)snprintf(buf2,BUFSIZ,
"-c.eq=%c%g",equi[0],equinox);
1629 (void)strncat(buf,
"&",BUFSIZ);
1630 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1635 (void)snprintf(buf2,BUFSIZ,
"-out.max=unlimited");
1636 (void)strncat(buf,
"&",BUFSIZ);
1637 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1638 (void)snprintf(buf2,BUFSIZ,
"-sort=_RA*-c.eq");
1639 (void)strncat(buf,
"&",BUFSIZ);
1640 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1641 (void)snprintf(buf2,BUFSIZ,
"-out.add=_RA*-c.eq");
1642 (void)strncat(buf,
"&",BUFSIZ);
1643 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1644 (void)snprintf(buf2,BUFSIZ,
"-out.add=_DEC*-c.eq");
1645 (void)strncat(buf,
"&",BUFSIZ);
1646 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1649 if (strcmp(catid, cdscats[7]) == 0) {
1650 cpl_msg_debug(fctid,
"Adding extra fields");
1651 (void)snprintf(buf2,BUFSIZ,
"-out.add=VarFlag");
1652 (void)strncat(buf,
"&",BUFSIZ);
1653 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1654 (void)snprintf(buf2,BUFSIZ,
"-out.add=NSS");
1655 (void)strncat(buf,
"&",BUFSIZ);
1656 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1657 (void)snprintf(buf2,BUFSIZ,
"-out.add=Gmag");
1658 (void)strncat(buf,
"&",BUFSIZ);
1659 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1660 (void)snprintf(buf2,BUFSIZ,
"-out.add=RUWE");
1661 (void)strncat(buf,
"&",BUFSIZ);
1662 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1663 }
else if (strcmp(catid, cdscats[8]) == 0) {
1664 cpl_msg_debug(fctid,
"Adding -out.all");
1665 (void)snprintf(buf2,BUFSIZ,
"-out.all");
1666 (void)strncat(buf,
"&",BUFSIZ);
1667 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1670 cpl_msg_debug(fctid,
"Query is: %s", buf);
1697static char *url_encode(
char *instring) {
1698 static char buf[BUFSIZ];
1705 buf[k] = instring[k];
1706 }
while (instring[k++] !=
'=');
1707 len = strlen(instring);
1713 for (i = k; i < len; i++) {
1714 assert(j < (
int)
sizeof(buf));
1715 if (instring[i] ==
' ')
1717 else if (isalnum((
unsigned char)instring[i]))
1718 buf[j++] = instring[i];
1720 sprintf(buf+j,
"%%%2x",(
unsigned char)instring[i]);
int casu_get_cdschoice(const char *cdscatname)
int casu_getstds(cpl_propertylist *plist, int cache, char *path, char *catname, int cdssearch, char *cacheloc, cpl_table **stds, int *status)
Get a table of standard stars that appear on an image from a catalogue.
void casu_radectoxy(cpl_wcs *wcs, double ra, double dec, double *x, double *y)
int casu_coverage(cpl_propertylist *plist, int fudge, double *ra1, double *ra2, double *dec1, double *dec2, int *status)