34 #ifndef _POSIX_C_SOURCE
35 #define _POSIX_C_SOURCE 200112L
39 #define _XOPEN_SOURCE 500
45 #include <sys/types.h>
46 #include <sys/socket.h>
48 #include <netinet/in.h>
62 #include "casu_mods.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 "cdsarc.u-strasbg.fr"
74 static cpl_table *casu_2mass_extract(
char *path,
float ramin,
float ramax,
75 float decmin,
float decmax);
76 static cpl_table *casu_ppmxl_extract(
char *path,
float ramin1,
float ramax1,
77 float decmin,
float decmax);
78 static cpl_table *casu_apass_extract(
char *path,
float ramin1,
float ramax1,
79 float decmin,
float decmax);
80 static cpl_table *casu_local_extract(
char *path,
float ramin1,
float ramax1,
81 float decmin,
float decmax);
82 static cpl_table *check_cache(
char *catname,
float ra1_im,
float ra2_im,
83 float dec1_im,
float dec2_im,
char *cacheloc);
84 static void addto_cache(cpl_table *stds,
char *catname,
float ramin,
85 float ramax,
float decmin,
float decmax,
87 static char *form_request(
float ra,
float dec,
float dra,
float ddec,
88 float equinox,
const char *catid);
89 static char *url_encode(
char *instring);
90 static int connect_site(
const char *site,
int *sock);
91 static int send_request(
int sock,
char *req_string,
int isbin);
92 static int get_response(
int soc, cpl_table **outtab);
159 extern int casu_getstds(cpl_propertylist *plist,
int cache,
char *path,
160 char *catname,
int cdssearch,
char *cacheloc,
161 cpl_table **stds,
int *status) {
162 const char *fctid =
"casu_getstds";
163 double xx1,xx2,yy1,yy2,r,d,xx,yy,*rad,*decd,dra,ddec;
164 float ramin,ramax,decmin,decmax,*ra,*dec,*x,*y,ramid,decmid;
168 char *req_string,catname2[64],*cdscatname,*cdscatid,*path2;
169 int isbin = (cdssearch > 6 ? 1 : 0);
174 if (*status != CASU_OK)
187 ddec = decmax - decmin;
188 ramid = 0.5*(ramax+ramin);
189 decmid = 0.5*(decmax+decmin);
191 cpl_msg_info(fctid,
"Searching catalogue %d, RA/Dec range [%f:%f, %f:%f]", cdssearch, ramin, ramax, decmin, decmax);
197 if (casu_getstds_cdslist(cdssearch,&cdscatname,&cdscatid,status) !=
200 (void)strcpy(catname2,cdscatname);
201 freespace(cdscatname);
203 (void)strcpy(catname2,catname);
207 *stds = check_cache(catname2,ramin,ramax,decmin,decmax,cacheloc);
216 if (cdssearch == 0) {
217 cpl_msg_info(fctid,
"Reading local catalogue");
219 path2 = cpl_strdup(path);
220 if (! strcmp(catname2,
"casu_2mass")) {
221 *stds = casu_2mass_extract(dirname(path2),ramin,ramax,decmin,
223 }
else if (! strcmp(catname2,
"casu_ppmxl")) {
224 *stds = casu_ppmxl_extract(dirname(path2),ramin,ramax,decmin,
226 }
else if (! strcmp(catname2,
"casu_apass")) {
227 *stds = casu_apass_extract(dirname(path2),ramin,ramax,decmin,
230 *stds = casu_local_extract(path2,ramin,ramax,decmin,decmax);
234 cpl_msg_error(fctid,
"Unable to extract data in %s",path);
241 cpl_msg_info(fctid,
"Requesting catalogue data from CDS");
243 req_string = form_request(ramid,decmid,dra,ddec,2000.0,
249 if (connect_site(CDS,&sock) != CASU_OK) {
250 cpl_msg_warning(fctid,
"Couldn't connect to CDS");
256 if (send_request(sock,req_string,isbin) != CASU_OK) {
257 cpl_msg_warning(fctid,
"Couldn't send request to site CDS");
264 if (get_response(sock,stds) != CASU_OK) {
265 cpl_msg_warning(fctid,
"Error receiving info from site CDS");
275 cpl_table_name_column(*stds,
"RAJ2000",
"RA");
276 cpl_table_name_column(*stds,
"DEJ2000",
"Dec");
282 addto_cache(*stds,catname2,ramin,ramax,decmin,decmax,cacheloc);
287 n = (int)cpl_table_get_nrow(*stds);
288 cpl_msg_info(fctid,
"Found %d stars in catalogue", n);
295 cpl_table_new_column(*stds,
"xpredict",CPL_TYPE_FLOAT);
296 cpl_table_new_column(*stds,
"ypredict",CPL_TYPE_FLOAT);
302 wcs = cpl_wcs_new_from_propertylist((
const cpl_propertylist *)plist);
303 if (cpl_table_get_column_type(*stds,
"RA") == CPL_TYPE_FLOAT) {
304 ra = cpl_table_get_data_float(*stds,
"RA");
305 dec = cpl_table_get_data_float(*stds,
"Dec");
306 x = cpl_malloc(n*
sizeof(*x));
307 y = cpl_malloc(n*
sizeof(*y));
308 for (i = 0; i < n; i++) {
316 rad = cpl_table_get_data_double(*stds,
"RA");
317 decd = cpl_table_get_data_double(*stds,
"Dec");
318 x = cpl_malloc(n*
sizeof(*x));
319 y = cpl_malloc(n*
sizeof(*y));
320 for (i = 0; i < n; i++) {
332 cpl_table_wrap_float(*stds,x,
"xpredict");
333 cpl_table_set_column_unit(*stds,
"xpredict",
"pixels");
334 cpl_table_wrap_float(*stds,y,
"ypredict");
335 cpl_table_set_column_unit(*stds,
"ypredict",
"pixels");
339 p = cpl_propertylist_new();
340 cpl_propertylist_append_bool(p,
"ypredict",0);
341 cpl_table_sort(*stds,p);
342 cpl_propertylist_delete(p);
389 static const int maxcds = 7;
390 static const char *cdscatnames[8] =
391 {
"",
"2mass",
"usnob",
"ppmxl",
"landolt",
"wise",
"apass",
"gaiaedr3"};
392 static const char *cdscats[8] =
393 {
"",
"II/246",
"I/284",
"I/317",
"II/183A",
"II/311",
"II/336",
"I/350"};
395 extern int casu_getstds_cdslist(
int cdschoice,
char **cdscatname,
396 char **cdscatid,
int *status) {
397 const char *fctid =
"casu_getstds_cdslist";
399 if (*status != CASU_OK)
406 if (cdschoice < 0 || cdschoice > maxcds) {
407 cpl_msg_error(fctid,
"CDS catalogue choice must be >= 0 && <= %d",
411 *cdscatname = cpl_strdup(cdscatnames[cdschoice]);
412 *cdscatid = cpl_strdup(cdscats[cdschoice]);
445 const char *fctid =
"casu_get_cdschoice";
447 for (
int i=1; i<=maxcds; i++) {
448 if (!strcmp(cdscatname, cdscatnames[i])) {
486 static cpl_table *casu_2mass_extract(
char *path,
float ramin1,
float ramax1,
487 float decmin,
float decmax) {
489 int i,nrows,start,finish,first_index,last_index,irow,init,j;
490 int first_index_ra,last_index_ra,wrap,iwrap;
491 float dectest,ratest,ramin,ramax;
492 char fullname[SZBUF];
494 const char *deccol =
"Dec";
499 o = cpl_table_new(0);
504 a = cpl_array_wrap_string((
char **)&deccol,1);
508 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
513 for (iwrap = 0; iwrap < wrap; iwrap++) {
516 ramin = ramin1 + 360.0;
529 first_index_ra = (int)ramin;
530 last_index_ra = min((
int)ramax,359);
535 for (i = first_index_ra; i <= last_index_ra; i++) {
540 (void)snprintf(fullname,SZBUF,
"%s/npsc%03d.fits",path,i);
545 p = cpl_propertylist_load(fullname,1);
551 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
552 cpl_propertylist_delete(p);
559 first_index = nrows/2;
560 while (finish - start >= 2) {
561 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
563 dectest = cpl_table_get_double(t,
"Dec",0,NULL);
565 if (dectest < decmin) {
567 first_index = (first_index + finish)/2;
569 finish = first_index;
570 first_index = (first_index + start)/2;
579 last_index = start + (finish - start)/2;
580 while (finish - start >= 2) {
581 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
583 dectest = cpl_table_get_double(t,
"Dec",0,NULL);
585 if (dectest < decmax) {
587 last_index = (last_index + finish)/2;
590 last_index = (last_index + start)/2;
593 if (last_index < first_index)
594 last_index = first_index;
598 nrows = last_index - first_index + 1;
599 if ((t = cpl_table_load_window(fullname,1,1,NULL,
600 (cpl_size)first_index,
601 (cpl_size)nrows)) == NULL) {
606 cpl_table_unselect_all(t);
612 for (j = 0; j < nrows; j++) {
613 ratest = cpl_table_get_double(t,
"RA",(cpl_size)j,NULL);
614 if (cpl_error_get_code() != CPL_ERROR_NONE) {
620 if (ratest >= ramin && ratest <= ramax)
621 cpl_table_select_row(t,(cpl_size)j);
627 s = cpl_table_extract_selected(t);
629 cpl_table_copy_structure(o,t);
632 irow = (int)cpl_table_get_nrow(o) + 1;
633 cpl_table_insert(o,s,(cpl_size)irow);
678 static cpl_table *casu_ppmxl_extract(
char *path,
float ramin1,
float ramax1,
679 float decmin,
float decmax) {
681 int i,nrows,start,finish,first_index,last_index,irow,init,j;
682 int first_index_ra,last_index_ra,wrap,iwrap;
683 float dectest,ratest,ramin,ramax;
684 char fullname[SZBUF];
686 const char *deccol =
"Dec";
691 o = cpl_table_new(0);
696 a = cpl_array_wrap_string((
char **)&deccol,1);
700 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
705 for (iwrap = 0; iwrap < wrap; iwrap++) {
708 ramin = ramin1 + 360.0;
721 first_index_ra = (int)ramin;
722 last_index_ra = min((
int)ramax,359);
727 for (i = first_index_ra; i <= last_index_ra; i++) {
732 (void)snprintf(fullname,SZBUF,
"%s/nppmxl%03d.fits",path,i);
737 p = cpl_propertylist_load(fullname,1);
743 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
744 cpl_propertylist_delete(p);
751 first_index = nrows/2;
752 while (finish - start >= 2) {
753 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
755 dectest = (float)cpl_table_get_double(t,
"Dec",0,NULL);
757 if (dectest < decmin) {
759 first_index = (first_index + finish)/2;
761 finish = first_index;
762 first_index = (first_index + start)/2;
771 last_index = start + (finish - start)/2;
772 while (finish - start >= 2) {
773 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
775 dectest = (float)cpl_table_get_double(t,
"Dec",0,NULL);
777 if (dectest < decmax) {
779 last_index = (last_index + finish)/2;
782 last_index = (last_index + start)/2;
785 if (last_index < first_index)
786 last_index = first_index;
790 nrows = last_index - first_index + 1;
791 if ((t = cpl_table_load_window(fullname,1,1,NULL,
792 (cpl_size)first_index,
793 (cpl_size)nrows)) == NULL) {
798 cpl_table_unselect_all(t);
804 for (j = 0; j < nrows; j++) {
805 ratest = (float)cpl_table_get_double(t,
"RA",(cpl_size)j,NULL);
806 if (cpl_error_get_code() != CPL_ERROR_NONE) {
812 if (ratest >= ramin && ratest <= ramax)
813 cpl_table_select_row(t,(cpl_size)j);
819 s = cpl_table_extract_selected(t);
821 cpl_table_copy_structure(o,t);
824 irow = (int)cpl_table_get_nrow(o) + 1;
825 cpl_table_insert(o,s,(cpl_size)irow);
870 static cpl_table *casu_apass_extract(
char *path,
float ramin1,
float ramax1,
871 float decmin,
float decmax) {
873 int i,nrows,start,finish,first_index,last_index,irow,init,j;
874 int first_index_ra,last_index_ra,wrap,iwrap;
875 float dectest,ratest,ramin,ramax;
876 char fullname[SZBUF];
878 const char *racol =
"RA";
883 o = cpl_table_new(0);
888 a = cpl_array_wrap_string((
char **)&racol,1);
892 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
897 for (iwrap = 0; iwrap < wrap; iwrap++) {
900 ramin = ramin1 + 360.0;
913 first_index_ra = (int)ramin;
914 last_index_ra = min((
int)ramax,359);
919 for (i = first_index_ra; i <= last_index_ra; i++) {
924 (void)snprintf(fullname,SZBUF,
"%s/casuapass_%03d.fits",path,i);
929 p = cpl_propertylist_load(fullname,1);
935 nrows = cpl_propertylist_get_int(p,
"NAXIS2");
936 cpl_propertylist_delete(p);
943 first_index = nrows/2;
944 while (finish - start >= 2) {
945 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)first_index,
947 ratest = (float)cpl_table_get_double(t,
"RA",0,NULL);
949 if (ratest < ramin) {
951 first_index = (first_index + finish)/2;
953 finish = first_index;
954 first_index = (first_index + start)/2;
963 last_index = start + (finish - start)/2;
964 while (finish - start >= 2) {
965 t = cpl_table_load_window(fullname,1,1,a,(cpl_size)last_index,
967 ratest = (float)cpl_table_get_double(t,
"RA",0,NULL);
969 if (ratest < ramax) {
971 last_index = (last_index + finish)/2;
974 last_index = (last_index + start)/2;
977 if (last_index < first_index)
978 last_index = first_index;
982 nrows = last_index - first_index + 1;
983 if ((t = cpl_table_load_window(fullname,1,1,NULL,
984 (cpl_size)first_index,
985 (cpl_size)nrows)) == NULL) {
990 cpl_table_unselect_all(t);
996 for (j = 0; j < nrows; j++) {
997 dectest = (float)cpl_table_get_double(t,
"Dec",(cpl_size)j,NULL);
998 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1000 cpl_array_unwrap(a);
1004 if (dectest >= decmin && dectest <= decmax)
1005 cpl_table_select_row(t,(cpl_size)j);
1011 s = cpl_table_extract_selected(t);
1013 cpl_table_copy_structure(o,t);
1016 irow = (int)cpl_table_get_nrow(o) + 1;
1017 cpl_table_insert(o,s,(cpl_size)irow);
1021 cpl_table_delete(t);
1022 cpl_table_delete(s);
1028 cpl_array_unwrap(a);
1063 static cpl_table *casu_local_extract(
char *path,
float ramin1,
float ramax1,
1064 float decmin,
float decmax) {
1065 cpl_table *whole,*out,*out2;
1066 int wrap,iwrap,nrows;
1068 cpl_propertylist *p;
1073 whole = cpl_table_load((
const char *)path,1,0);
1077 wrap = (ramin1 < 0.0 && ramax1 > 0.0) ? 2 : 1;
1083 for (iwrap = 0; iwrap < wrap; iwrap++) {
1086 ramin = ramin1 + 360.0;
1096 cpl_table_unselect_all(whole);
1100 cpl_table_or_selected_double(whole,
"RA",CPL_NOT_LESS_THAN,
1102 cpl_table_and_selected_double(whole,
"RA",CPL_NOT_GREATER_THAN,
1104 cpl_table_and_selected_double(whole,
"Dec",CPL_NOT_LESS_THAN,
1106 cpl_table_and_selected_double(whole,
"Dec",CPL_NOT_GREATER_THAN,
1112 out = cpl_table_extract_selected(whole);
1114 out2 = cpl_table_extract_selected(whole);
1115 nrows = cpl_table_get_nrow(out);
1116 cpl_table_insert(out,out2,nrows+1);
1117 cpl_table_delete(out2);
1123 p = cpl_propertylist_new();
1124 cpl_propertylist_append_bool(p,
"Dec",0);
1125 cpl_table_sort(out,p);
1126 cpl_propertylist_delete(p);
1162 static cpl_table *check_cache(
char *catname,
float ra1_im,
float ra2_im,
1163 float dec1_im,
float dec2_im,
char *cacheloc) {
1166 char fname[BUFSIZ],catname2[SZBUF];
1167 char * cat_cache = NULL;
1168 float best,ra1_cat,ra2_cat,dec1_cat,dec2_cat,d1,d2,fra,fdec,ftot;
1173 (void)snprintf(fname,BUFSIZ,
"%s/%s",cacheloc,CACHEIND);
1174 fd = fopen(fname,
"r");
1180 wrap1 = (ra1_im < 0.0 ? 1 : 0);
1186 while (fscanf(fd,
"%8191s %1023s %g %g %g %g",
1187 fname,catname2,&ra1_cat,&ra2_cat,
1188 &dec1_cat,&dec2_cat) != EOF) {
1189 wrap2 = (ra1_cat < 0.0 ? 1 : 0);
1192 if (strcmp(catname,catname2))
1197 if (!(((ra1_im >= ra1_cat && ra1_im <= ra2_cat) ||
1198 (ra2_im >= ra1_cat && ra2_im <= ra2_cat)) &&
1199 ((dec1_im >= dec1_cat && dec1_im <= dec2_cat) ||
1200 (dec2_im >= dec1_cat && dec2_im <= dec2_cat))))
1205 d1 = max(0.0,ra1_cat-ra1_im);
1206 d2 = max(0.0,ra2_im-ra2_cat);
1207 fra = 1.0 - (d1 + d2)/(ra2_im - ra1_im);
1208 d1 = max(0.0,dec1_cat-dec1_im);
1209 d2 = max(0.0,dec2_im-dec2_cat);
1210 fdec = 1.0 - (d1 + d2)/(dec2_im - dec1_im);
1216 cpl_free(cat_cache);
1217 cat_cache = cpl_sprintf(
"%s/%s/%s",cacheloc,CACHEDIR,fname);
1231 out_cat = cpl_table_load(cat_cache,1,1);
1232 cpl_free(cat_cache);
1234 cpl_msg_info(cpl_func,
"Using cached catalogue data");
1269 static void addto_cache(cpl_table *stds,
char *catname,
float ramin,
1270 float ramax,
float decmin,
float decmax,
1273 char newname[SZBUF];
1279 (void)snprintf(newname,SZBUF,
"%s/%s",cacheloc,CACHEDIR);
1280 if (access(newname,0) != 0)
1281 mkdir(newname,0755);
1285 (void)snprintf(newname,SZBUF,
"%s/%s",cacheloc,CACHEIND);
1286 fd = fopen(newname,
"a");
1294 snprintf(newname,SZBUF,
"%s/%s/cch_%08d",cacheloc,CACHEDIR,i);
1295 if (access(newname,F_OK) != 0)
1302 snprintf(newname,SZBUF,
"%s/%s/cch_%08d",cacheloc,CACHEDIR,i);
1303 cpl_table_save(stds,NULL,NULL,newname,CPL_IO_DEFAULT);
1304 snprintf(newname,SZBUF,
"cch_%08d",i);
1305 if (cpl_error_get_code() == CPL_ERROR_NONE)
1306 fprintf(fd,
"%s %s %g %g %g %g\n",newname,catname,ramin-0.0005,
1307 ramax+0.0005,decmin-0.0005,decmax+0.0005);
1336 static int get_response(
int sock, cpl_table **outtab) {
1337 int nnewline,i,nv,irem = 0,fd;
1339 char buf[BUFMAX],outfile[32];
1340 const char *fctid =
"get_response";
1346 nv = recv(sock,buf,
sizeof(buf),0);
1348 cpl_msg_warning(fctid,
"Unable to find double newline");
1351 for (i = 0; i < nv; i++) {
1352 if (buf[i] ==
'\n') {
1357 if (nnewline && buf[i] !=
'\r')
1361 if (nnewline == 2) {
1369 for (i = irem; i < nv; i++)
1370 buf[i-irem] = buf[i];
1375 (void)snprintf(outfile,32,
"stdsXXXXXX");
1376 fd = mkstemp(outfile);
1381 ssize_t written = write(fd,buf,nv);
1383 cpl_msg_info(cpl_func,
"Not all bytes could be written - "
1386 nv = recv(sock,buf,
sizeof(buf),0);
1390 cpl_msg_warning(fctid,
"Read from socket failed");
1401 *outtab = cpl_table_load(outfile,1,0);
1402 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1403 cpl_msg_warning(fctid,
"No standards were found");
1409 nrows = (int)cpl_table_get_nrow(*outtab);
1411 cpl_msg_warning(fctid,
"No standards table had no rows");
1452 static int send_request(
int sock,
char *req_string,
int isbin) {
1454 const char *fctid =
"send_request";
1459 sprintf(buf,
"GET /viz-bin/asu-binfits?%s HTTP/1.0\r\n\r\n",req_string);
1461 sprintf(buf,
"GET /viz-bin/asu-fits?%s HTTP/1.0\r\n\r\n",req_string);
1463 if (send(sock,buf,strlen(buf),0) < 0) {
1464 cpl_msg_warning(fctid,
"Attempt to send message failed, error: %d\n",
1496 static int connect_site(
const char *site,
int *sock) {
1498 struct sockaddr_in ssin;
1499 const char *fctid =
"connect_site";
1503 hp = gethostbyname(site);
1505 cpl_msg_warning(fctid,
"Unable to get host information for %s\n",site);
1508 ssin.sin_family = hp->h_addrtype;
1509 memcpy(&ssin.sin_addr,hp->h_addr_list[0],hp->h_length);
1510 ssin.sin_port = htons(PORT);
1514 *sock = socket(hp->h_addrtype,SOCK_STREAM,0);
1516 cpl_msg_warning(fctid,
"Unable to create socket descriptor for %s\n",
1518 return (CASU_FATAL);
1523 if (connect(*sock,(
struct sockaddr*)&ssin,
sizeof(ssin)) < 0) {
1524 cpl_msg_warning(fctid,
"Unable to connect to site: %s\n",site);
1563 static char *form_request(
float ra,
float dec,
float dra,
float ddec,
1564 float equinox,
const char *catid) {
1565 static char buf[2*BUFSIZ];
1566 char buf2[BUFSIZ],equi[1];
1572 (void)snprintf(buf2,BUFSIZ,
"-c=%8.3f %8.3f",ra,dec);
1573 (void)strncpy(buf,url_encode(buf2),BUFSIZ);
1577 (void)snprintf(buf2,BUFSIZ,
"-c.bd=%g/%g",dra,ddec);
1578 (void)strncat(buf,
"&",BUFSIZ);
1579 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1583 (void)snprintf(buf2,BUFSIZ,
"-source=%s",catid);
1584 (void)strncat(buf,
"&",BUFSIZ);
1585 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1589 equi[0] = (equinox == 1950.0 ?
'B' :
'J');
1590 (void)snprintf(buf2,BUFSIZ,
"-c.eq=%c%g",equi[0],equinox);
1591 (void)strncat(buf,
"&",BUFSIZ);
1592 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1597 (void)snprintf(buf2,BUFSIZ,
"-out.max=unlimited");
1598 (void)strncat(buf,
"&",BUFSIZ);
1599 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1600 (void)snprintf(buf2,BUFSIZ,
"-sort=_RA*-c.eq");
1601 (void)strncat(buf,
"&",BUFSIZ);
1602 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1603 (void)snprintf(buf2,BUFSIZ,
"-out.add=_RA*-c.eq");
1604 (void)strncat(buf,
"&",BUFSIZ);
1605 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1606 (void)snprintf(buf2,BUFSIZ,
"-out.add=_DEC*-c.eq");
1607 (void)strncat(buf,
"&",BUFSIZ);
1608 (void)strncat(buf,url_encode(buf2),BUFSIZ);
1635 static char *url_encode(
char *instring) {
1636 static char buf[BUFSIZ];
1643 buf[k] = instring[k];
1644 }
while (instring[k++] !=
'=');
1645 len = strlen(instring);
1651 for (i = k; i < len; i++) {
1652 assert(j < (
int)
sizeof(buf));
1653 if (instring[i] ==
' ')
1655 else if (isalnum((
unsigned char)instring[i]))
1656 buf[j++] = instring[i];
1658 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)