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_SERVER_URL "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);
170 char *catname,
int cdssearch,
char *cacheloc,
171 cpl_table **stds,
const char * cds_server,
int *status) {
172 const char *fctid =
"casu_getstds";
173 double xx1,xx2,yy1,yy2,r,d,xx,yy,*rad,*decd,dra,ddec;
174 float ramin,ramax,decmin,decmax,*ra,*dec,*x,*y,ramid,decmid;
178 char *req_string,catname2[64],*cdscatname,*cdscatid,*path2;
179 int isbin = (cdssearch > 6 ? 1 : 0);
181 if(cds_server == NULL){
183 cds_server = CDS_SERVER_URL;
189 if (*status != CASU_OK)
202 ddec = decmax - decmin;
203 ramid = 0.5*(ramax+ramin);
204 decmid = 0.5*(decmax+decmin);
206 cpl_msg_info(fctid,
"Searching catalogue %d, RA/Dec range [%f:%f, %f:%f]", cdssearch, ramin, ramax, decmin, decmax);
212 if (casu_getstds_cdslist(cdssearch,&cdscatname,&cdscatid,status) !=
215 (void)strcpy(catname2,cdscatname);
216 freespace(cdscatname);
218 (void)strcpy(catname2,catname);
222 *stds = check_cache(catname2,ramin,ramax,decmin,decmax,cacheloc);
231 if (cdssearch == 0) {
232 cpl_msg_info(fctid,
"Reading local catalogue");
234 path2 = cpl_strdup(path);
235 if (! strcmp(catname2,
"casu_2mass")) {
236 *stds = casu_2mass_extract(dirname(path2),ramin,ramax,decmin,
238 }
else if (! strcmp(catname2,
"casu_ppmxl")) {
239 *stds = casu_ppmxl_extract(dirname(path2),ramin,ramax,decmin,
241 }
else if (! strcmp(catname2,
"casu_apass")) {
242 *stds = casu_apass_extract(dirname(path2),ramin,ramax,decmin,
245 *stds = casu_local_extract(path2,ramin,ramax,decmin,decmax);
249 cpl_msg_error(fctid,
"Unable to extract data in %s",path);
256 cpl_msg_info(fctid,
"Requesting catalogue data from CDS");
258 req_string = form_request(ramid,decmid,dra,ddec,2000.0,
264 if (connect_site(cds_server,&sock) != CASU_OK) {
265 cpl_msg_warning(fctid,
"Couldn't connect to CDS");
271 if (send_request(sock,req_string,isbin) != CASU_OK) {
272 cpl_msg_warning(fctid,
"Couldn't send request to site CDS");
279 if (get_response(sock,stds) != CASU_OK) {
280 cpl_msg_warning(fctid,
"Error receiving info from site CDS");
290 if (cpl_table_has_column(*stds,
"RAJ2000")) {
291 cpl_table_name_column(*stds,
"RAJ2000",
"RA");
293 cpl_table_duplicate_column(*stds,
"RA", *stds,
"_RAJ2000");
295 if (cpl_table_has_column(*stds,
"DEJ2000")) {
296 cpl_table_name_column(*stds,
"DEJ2000",
"Dec");
298 cpl_table_duplicate_column(*stds,
"Dec", *stds,
"_DEJ2000");
302 if (cdssearch == 8) {
303 cpl_table_duplicate_column(*stds,
"DEC", *stds,
"Dec");
304 calculate_magerr(*stds,
"ERR_Umag",
"FU",
"e_FU");
305 calculate_magerr(*stds,
"ERR_Bmag",
"FB",
"e_FB");
306 calculate_magerr(*stds,
"ERR_Vmag",
"FV",
"e_FV");
307 calculate_magerr(*stds,
"ERR_Rmag",
"FR",
"e_FR");
308 calculate_magerr(*stds,
"ERR_Imag",
"FI",
"e_FI");
309 cpl_table_new_column(*stds,
"OBJECT", CPL_TYPE_STRING);
316 addto_cache(*stds,catname2,ramin,ramax,decmin,decmax,cacheloc);
321 n = (int)cpl_table_get_nrow(*stds);
322 cpl_msg_info(fctid,
"Found %d stars in catalogue", n);
329 cpl_table_new_column(*stds,
"xpredict",CPL_TYPE_FLOAT);
330 cpl_table_new_column(*stds,
"ypredict",CPL_TYPE_FLOAT);
334 if (cdssearch == 8) {
335 for (i = 0; i < n; i++) {
336 long long src = cpl_table_get_long_long(*stds,
"Source", i, NULL);
337 char* tmpstr = cpl_sprintf(
"%lld", src);
338 cpl_table_set_string(*stds,
"OBJECT", i, tmpstr);
345 wcs = cpl_wcs_new_from_propertylist((
const cpl_propertylist *)plist);
346 if (cpl_table_get_column_type(*stds,
"RA") == CPL_TYPE_FLOAT) {
347 ra = cpl_table_get_data_float(*stds,
"RA");
348 dec = cpl_table_get_data_float(*stds,
"Dec");
349 x = cpl_malloc(n*
sizeof(*x));
350 y = cpl_malloc(n*
sizeof(*y));
351 for (i = 0; i < n; i++) {
359 rad = cpl_table_get_data_double(*stds,
"RA");
360 decd = cpl_table_get_data_double(*stds,
"Dec");
361 x = cpl_malloc(n*
sizeof(*x));
362 y = cpl_malloc(n*
sizeof(*y));
363 for (i = 0; i < n; i++) {
375 cpl_table_wrap_float(*stds,x,
"xpredict");
376 cpl_table_set_column_unit(*stds,
"xpredict",
"pixels");
377 cpl_table_wrap_float(*stds,y,
"ypredict");
378 cpl_table_set_column_unit(*stds,
"ypredict",
"pixels");
382 p = cpl_propertylist_new();
383 cpl_propertylist_append_bool(p,
"ypredict",0);
384 cpl_table_sort(*stds,p);
385 cpl_propertylist_delete(p);
432static const int maxcds = 8;
433static const char *cdscatnames[9] =
434 {
"",
"2mass",
"usnob",
"ppmxl",
"landolt",
"wise",
"apass",
"gaiadr3",
"gaiasyntphot"};
435static const char *cdscats[9] =
436 {
"",
"II/246",
"I/284",
"I/317",
"II/183A",
"II/311",
"II/336",
"I/355",
"I/360/syntphot"};
438extern int casu_getstds_cdslist(
int cdschoice,
char **cdscatname,
439 char **cdscatid,
int *status) {
440 const char *fctid =
"casu_getstds_cdslist";
442 if (*status != CASU_OK)
449 if (cdschoice < 0 || cdschoice > maxcds) {
450 cpl_msg_error(fctid,
"CDS catalogue choice must be >= 0 && <= %d",
454 *cdscatname = cpl_strdup(cdscatnames[cdschoice]);
455 *cdscatid = cpl_strdup(cdscats[cdschoice]);
489 for (
int i=1; i<=maxcds; i++) {
490 if (!strcmp(cdscatname, cdscatnames[i])) {
528static cpl_table *casu_2mass_extract(
char *path,
float ramin1,
float ramax1,
529 float decmin,
float decmax) {
531 int i,nrows,start,finish,first_index,last_index,irow,init,j;
532 int first_index_ra,last_index_ra,wrap,iwrap;
533 float dectest,ratest,ramin,ramax;
534 char fullname[SZBUF];
536 const char *deccol =
"Dec";
541 o = cpl_table_new(0);
546 a = cpl_array_wrap_string((
char **)&deccol,1);
550 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
555 for (iwrap = 0; iwrap < wrap; iwrap++) {
558 ramin = ramin1 + 360.0;
571 first_index_ra = (int)ramin;
572 last_index_ra = min((
int)ramax,359);
577 for (i = first_index_ra; i <= last_index_ra; i++) {
582 (void)snprintf(fullname,SZBUF,
"%s/npsc%03d.fits",path,i);
587 p = cpl_propertylist_load(fullname,1);
593 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
594 cpl_propertylist_delete(p);
601 first_index = nrows/2;
602 while (finish - start >= 2) {
603 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
605 dectest = cpl_table_get_double(t,
"Dec",0,NULL);
607 if (dectest < decmin) {
609 first_index = (first_index + finish)/2;
611 finish = first_index;
612 first_index = (first_index + start)/2;
621 last_index = start + (finish - start)/2;
622 while (finish - start >= 2) {
623 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
625 dectest = cpl_table_get_double(t,
"Dec",0,NULL);
627 if (dectest < decmax) {
629 last_index = (last_index + finish)/2;
632 last_index = (last_index + start)/2;
635 if (last_index < first_index)
636 last_index = first_index;
640 nrows = last_index - first_index + 1;
641 if ((t = cpl_table_load_window(fullname,1,1,NULL,
642 (cpl_size)first_index,
643 (cpl_size)nrows)) == NULL) {
648 cpl_table_unselect_all(t);
654 for (j = 0; j < nrows; j++) {
655 ratest = cpl_table_get_double(t,
"RA",(cpl_size)j,NULL);
656 if (cpl_error_get_code() != CPL_ERROR_NONE) {
662 if (ratest >= ramin && ratest <= ramax)
663 cpl_table_select_row(t,(cpl_size)j);
669 s = cpl_table_extract_selected(t);
671 cpl_table_copy_structure(o,t);
674 irow = (int)cpl_table_get_nrow(o) + 1;
675 cpl_table_insert(o,s,(cpl_size)irow);
720static cpl_table *casu_ppmxl_extract(
char *path,
float ramin1,
float ramax1,
721 float decmin,
float decmax) {
723 int i,nrows,start,finish,first_index,last_index,irow,init,j;
724 int first_index_ra,last_index_ra,wrap,iwrap;
725 float dectest,ratest,ramin,ramax;
726 char fullname[SZBUF];
728 const char *deccol =
"Dec";
733 o = cpl_table_new(0);
738 a = cpl_array_wrap_string((
char **)&deccol,1);
742 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
747 for (iwrap = 0; iwrap < wrap; iwrap++) {
750 ramin = ramin1 + 360.0;
763 first_index_ra = (int)ramin;
764 last_index_ra = min((
int)ramax,359);
769 for (i = first_index_ra; i <= last_index_ra; i++) {
774 (void)snprintf(fullname,SZBUF,
"%s/nppmxl%03d.fits",path,i);
779 p = cpl_propertylist_load(fullname,1);
785 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
786 cpl_propertylist_delete(p);
793 first_index = nrows/2;
794 while (finish - start >= 2) {
795 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
797 dectest = (float)cpl_table_get_double(t,
"Dec",0,NULL);
799 if (dectest < decmin) {
801 first_index = (first_index + finish)/2;
803 finish = first_index;
804 first_index = (first_index + start)/2;
813 last_index = start + (finish - start)/2;
814 while (finish - start >= 2) {
815 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
817 dectest = (float)cpl_table_get_double(t,
"Dec",0,NULL);
819 if (dectest < decmax) {
821 last_index = (last_index + finish)/2;
824 last_index = (last_index + start)/2;
827 if (last_index < first_index)
828 last_index = first_index;
832 nrows = last_index - first_index + 1;
833 if ((t = cpl_table_load_window(fullname,1,1,NULL,
834 (cpl_size)first_index,
835 (cpl_size)nrows)) == NULL) {
840 cpl_table_unselect_all(t);
846 for (j = 0; j < nrows; j++) {
847 ratest = (float)cpl_table_get_double(t,
"RA",(cpl_size)j,NULL);
848 if (cpl_error_get_code() != CPL_ERROR_NONE) {
854 if (ratest >= ramin && ratest <= ramax)
855 cpl_table_select_row(t,(cpl_size)j);
861 s = cpl_table_extract_selected(t);
863 cpl_table_copy_structure(o,t);
866 irow = (int)cpl_table_get_nrow(o) + 1;
867 cpl_table_insert(o,s,(cpl_size)irow);
912static cpl_table *casu_apass_extract(
char *path,
float ramin1,
float ramax1,
913 float decmin,
float decmax) {
915 int i,nrows,start,finish,first_index,last_index,irow,init,j;
916 int first_index_ra,last_index_ra,wrap,iwrap;
917 float dectest,ratest,ramin,ramax;
918 char fullname[SZBUF];
920 const char *racol =
"RA";
925 o = cpl_table_new(0);
930 a = cpl_array_wrap_string((
char **)&racol,1);
934 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
939 for (iwrap = 0; iwrap < wrap; iwrap++) {
942 ramin = ramin1 + 360.0;
955 first_index_ra = (int)ramin;
956 last_index_ra = min((
int)ramax,359);
961 for (i = first_index_ra; i <= last_index_ra; i++) {
966 (void)snprintf(fullname,SZBUF,
"%s/casuapass_%03d.fits",path,i);
971 p = cpl_propertylist_load(fullname,1);
977 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
978 cpl_propertylist_delete(p);
985 first_index = nrows/2;
986 while (finish - start >= 2) {
987 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
989 ratest = (float)cpl_table_get_double(t,
"RA",0,NULL);
991 if (ratest < ramin) {
993 first_index = (first_index + finish)/2;
995 finish = first_index;
996 first_index = (first_index + start)/2;
1003 start = first_index;
1005 last_index = start + (finish - start)/2;
1006 while (finish - start >= 2) {
1007 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
1009 ratest = (float)cpl_table_get_double(t,
"RA",0,NULL);
1010 cpl_table_delete(t);
1011 if (ratest < ramax) {
1013 last_index = (last_index + finish)/2;
1015 finish = last_index;
1016 last_index = (last_index + start)/2;
1019 if (last_index < first_index)
1020 last_index = first_index;
1024 nrows = last_index - first_index + 1;
1025 if ((t = cpl_table_load_window(fullname,1,1,NULL,
1026 (cpl_size)first_index,
1027 (cpl_size)nrows)) == NULL) {
1029 cpl_array_unwrap(a);
1032 cpl_table_unselect_all(t);
1038 for (j = 0; j < nrows; j++) {
1039 dectest = (float)cpl_table_get_double(t,
"Dec",(cpl_size)j,NULL);
1040 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1041 cpl_table_delete(t);
1042 cpl_array_unwrap(a);
1046 if (dectest >= decmin && dectest <= decmax)
1047 cpl_table_select_row(t,(cpl_size)j);
1053 s = cpl_table_extract_selected(t);
1055 cpl_table_copy_structure(o,t);
1058 irow = (int)cpl_table_get_nrow(o) + 1;
1059 cpl_table_insert(o,s,(cpl_size)irow);
1063 cpl_table_delete(t);
1064 cpl_table_delete(s);
1070 cpl_array_unwrap(a);
1105static cpl_table *casu_local_extract(
char *path,
float ramin1,
float ramax1,
1106 float decmin,
float decmax) {
1107 cpl_table *whole,*out,*out2;
1108 int wrap,iwrap,nrows;
1110 cpl_propertylist *p;
1115 whole = cpl_table_load((
const char *)path,1,0);
1119 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
1125 for (iwrap = 0; iwrap < wrap; iwrap++) {
1128 ramin = ramin1 + 360.0;
1138 cpl_table_unselect_all(whole);
1142 cpl_table_or_selected_double(whole,
"RA",CPL_NOT_LESS_THAN,
1144 cpl_table_and_selected_double(whole,
"RA",CPL_NOT_GREATER_THAN,
1146 cpl_table_and_selected_double(whole,
"Dec",CPL_NOT_LESS_THAN,
1148 cpl_table_and_selected_double(whole,
"Dec",CPL_NOT_GREATER_THAN,
1154 out = cpl_table_extract_selected(whole);
1156 out2 = cpl_table_extract_selected(whole);
1157 nrows = cpl_table_get_nrow(out);
1158 cpl_table_insert(out,out2,nrows+1);
1159 cpl_table_delete(out2);
1165 p = cpl_propertylist_new();
1166 cpl_propertylist_append_bool(p,
"Dec",0);
1167 cpl_table_sort(out,p);
1168 cpl_propertylist_delete(p);
1204static cpl_table *check_cache(
char *catname,
float ra1_im,
float ra2_im,
1205 float dec1_im,
float dec2_im,
char *cacheloc) {
1208 char fname[BUFSIZ],catname2[SZBUF];
1209 char * cat_cache = NULL;
1210 float best,ra1_cat,ra2_cat,dec1_cat,dec2_cat,d1,d2,fra,fdec,ftot;
1215 (void)snprintf(fname,BUFSIZ,
"%s/%s",cacheloc,CACHEIND);
1216 fd = fopen(fname,
"r");
1222 wrap1 = (ra1_im < 0.0 ? 1 : 0);
1228 while (fscanf(fd,
"%8191s %1023s %g %g %g %g",
1229 fname,catname2,&ra1_cat,&ra2_cat,
1230 &dec1_cat,&dec2_cat) != EOF) {
1231 wrap2 = (ra1_cat < 0.0 ? 1 : 0);
1234 if (strcmp(catname,catname2))
1239 if (!(((ra1_im >= ra1_cat && ra1_im <= ra2_cat) ||
1240 (ra2_im >= ra1_cat && ra2_im <= ra2_cat)) &&
1241 ((dec1_im >= dec1_cat && dec1_im <= dec2_cat) ||
1242 (dec2_im >= dec1_cat && dec2_im <= dec2_cat))))
1247 d1 = max(0.0,ra1_cat-ra1_im);
1248 d2 = max(0.0,ra2_im-ra2_cat);
1249 fra = 1.0 - (d1 + d2)/(ra2_im - ra1_im);
1250 d1 = max(0.0,dec1_cat-dec1_im);
1251 d2 = max(0.0,dec2_im-dec2_cat);
1252 fdec = 1.0 - (d1 + d2)/(dec2_im - dec1_im);
1258 cpl_free(cat_cache);
1259 cat_cache = cpl_sprintf(
"%s/%s/%s",cacheloc,CACHEDIR,fname);
1273 out_cat = cpl_table_load(cat_cache,1,1);
1274 cpl_free(cat_cache);
1276 cpl_msg_info(cpl_func,
"Using cached catalogue data");
1311static void addto_cache(cpl_table *stds,
char *catname,
float ramin,
1312 float ramax,
float decmin,
float decmax,
1315 char newname[SZBUF];
1321 (void)snprintf(newname,SZBUF,
"%s/%s",cacheloc,CACHEDIR);
1322 if (access(newname,0) != 0)
1323 mkdir(newname,0755);
1327 (void)snprintf(newname,SZBUF,
"%s/%s",cacheloc,CACHEIND);
1328 fd = fopen(newname,
"a");
1336 snprintf(newname,SZBUF,
"%s/%s/cch_%08d",cacheloc,CACHEDIR,i);
1337 if (access(newname,F_OK) != 0)
1344 snprintf(newname,SZBUF,
"%s/%s/cch_%08d",cacheloc,CACHEDIR,i);
1345 cpl_table_save(stds,NULL,NULL,newname,CPL_IO_DEFAULT);
1346 snprintf(newname,SZBUF,
"cch_%08d",i);
1347 if (cpl_error_get_code() == CPL_ERROR_NONE)
1348 fprintf(fd,
"%s %s %g %g %g %g\n",newname,catname,ramin-0.0005,
1349 ramax+0.0005,decmin-0.0005,decmax+0.0005);
1378static int get_response(
int sock, cpl_table **outtab) {
1379 int nnewline,i,nv,irem = 0,fd;
1381 char buf[BUFMAX],outfile[32];
1382 const char *fctid =
"get_response";
1388 nv = recv(sock,buf,
sizeof(buf),0);
1390 cpl_msg_warning(fctid,
"Unable to find double newline");
1393 for (i = 0; i < nv; i++) {
1394 if (buf[i] ==
'\n') {
1399 if (nnewline && buf[i] !=
'\r')
1403 if (nnewline == 2) {
1411 for (i = irem; i < nv; i++)
1412 buf[i-irem] = buf[i];
1417 (void)snprintf(outfile,32,
"stdsXXXXXX");
1418 fd = mkstemp(outfile);
1423 ssize_t written = write(fd,buf,nv);
1425 cpl_msg_info(cpl_func,
"Not all bytes could be written - "
1428 nv = recv(sock,buf,
sizeof(buf),0);
1432 cpl_msg_warning(fctid,
"Read from socket failed");
1443 *outtab = cpl_table_load(outfile,1,0);
1444 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1445 cpl_msg_warning(fctid,
"No standards were found");
1451 nrows = (int)cpl_table_get_nrow(*outtab);
1453 cpl_msg_warning(fctid,
"No standards table had no rows");
1494static int send_request(
int sock,
char *req_string,
int isbin) {
1496 const char *fctid =
"send_request";
1501 sprintf(buf,
"GET /viz-bin/asu-binfits?%s HTTP/1.0\r\n\r\n",req_string);
1503 sprintf(buf,
"GET /viz-bin/asu-fits?%s HTTP/1.0\r\n\r\n",req_string);
1505 if (send(sock,buf,strlen(buf),0) < 0) {
1506 cpl_msg_warning(fctid,
"Attempt to send message failed, error: %d\n",
1538static int connect_site(
const char *site,
int *sock) {
1540 struct sockaddr_in ssin;
1541 const char *fctid =
"connect_site";
1545 hp = gethostbyname(site);
1547 cpl_msg_warning(fctid,
"Unable to get host information for %s\n",site);
1550 ssin.sin_family = hp->h_addrtype;
1551 memcpy(&ssin.sin_addr,hp->h_addr_list[0],hp->h_length);
1552 ssin.sin_port = htons(PORT);
1556 *sock = socket(hp->h_addrtype,SOCK_STREAM,0);
1558 cpl_msg_warning(fctid,
"Unable to create socket descriptor for %s\n",
1560 return (CASU_FATAL);
1565 if (connect(*sock,(
struct sockaddr*)&ssin,
sizeof(ssin)) < 0) {
1566 cpl_msg_warning(fctid,
"Unable to connect to site: %s\n",site);
1605static char *form_request(
float ra,
float dec,
float dra,
float ddec,
1606 float equinox,
const char *catid) {
1607 const char *fctid =
"form_request";
1608 static char buf[2*BUFSIZ];
1609 char buf2[BUFSIZ],equi[1];
1611 cpl_msg_debug(fctid,
"catid is: %s", catid);
1617 (void)snprintf(buf2,BUFSIZ,
"-c=%8.3f %8.3f",ra,dec);
1618 (void)strncpy(buf,url_encode(buf2),BUFSIZ);
1622 (void)snprintf(buf2,BUFSIZ,
"-c.bd=%g/%g",dra,ddec);
1623 (void)strncat(buf,
"&",BUFSIZ);
1624 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1628 (void)snprintf(buf2,BUFSIZ,
"-source=%s",catid);
1629 (void)strncat(buf,
"&",BUFSIZ);
1630 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1634 equi[0] = (equinox == 1950.0 ?
'B' :
'J');
1635 (void)snprintf(buf2,BUFSIZ,
"-c.eq=%c%g",equi[0],equinox);
1636 (void)strncat(buf,
"&",BUFSIZ);
1637 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1642 (void)snprintf(buf2,BUFSIZ,
"-out.max=unlimited");
1643 (void)strncat(buf,
"&",BUFSIZ);
1644 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1645 (void)snprintf(buf2,BUFSIZ,
"-sort=_RA*-c.eq");
1646 (void)strncat(buf,
"&",BUFSIZ);
1647 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1648 (void)snprintf(buf2,BUFSIZ,
"-out.add=_RA*-c.eq");
1649 (void)strncat(buf,
"&",BUFSIZ);
1650 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1651 (void)snprintf(buf2,BUFSIZ,
"-out.add=_DEC*-c.eq");
1652 (void)strncat(buf,
"&",BUFSIZ);
1653 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1656 if (strcmp(catid, cdscats[7]) == 0) {
1657 cpl_msg_debug(fctid,
"Adding extra fields");
1658 (void)snprintf(buf2,BUFSIZ,
"-out.add=VarFlag");
1659 (void)strncat(buf,
"&",BUFSIZ);
1660 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1661 (void)snprintf(buf2,BUFSIZ,
"-out.add=NSS");
1662 (void)strncat(buf,
"&",BUFSIZ);
1663 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1664 (void)snprintf(buf2,BUFSIZ,
"-out.add=Gmag");
1665 (void)strncat(buf,
"&",BUFSIZ);
1666 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1667 (void)snprintf(buf2,BUFSIZ,
"-out.add=RUWE");
1668 (void)strncat(buf,
"&",BUFSIZ);
1669 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1670 }
else if (strcmp(catid, cdscats[8]) == 0) {
1671 cpl_msg_debug(fctid,
"Adding -out.all");
1672 (void)snprintf(buf2,BUFSIZ,
"-out.all");
1673 (void)strncat(buf,
"&",BUFSIZ);
1674 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1677 cpl_msg_debug(fctid,
"Query is: %s", buf);
1704static char *url_encode(
char *instring) {
1705 static char buf[BUFSIZ];
1711 len = strlen(instring);
1713 buf[k] = instring[k];
1714 }
while (k < len && instring[k++] !=
'=');
1720 for (i = k; i < len; i++) {
1721 assert(j < (
int)
sizeof(buf));
1722 if (instring[i] ==
' ')
1724 else if (isalnum((
unsigned char)instring[i]))
1725 buf[j++] = instring[i];
1727 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, const char *cds_server, 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)