File: twcs.c

package info (click to toggle)
funtools 1.4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,004 kB
  • sloc: ansic: 89,502; sh: 10,714; lex: 4,613; asm: 3,281; ada: 1,681; makefile: 1,468; pascal: 1,089; cpp: 1,001; cs: 879; perl: 161; python: 119; yacc: 64; sed: 38; csh: 10; tcl: 9
file content (61 lines) | stat: -rw-r--r-- 1,477 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 *
 * twcs.c -- example using WCS Library
 *
 */

#include <funtools.h>

int main(int argc, char **argv)
{
  int i;
  Fun fun;
  struct WorldCoor *wcs;  /* WCS info */
  double x,y,ra,dec,xr,yr;

  if(argc == 1){
    fprintf(stderr, "usage: twcs iname\n");
    exit(1);
  }

  /* open Funtools file */
  /* Funopen makes initial WCS library call: wcs = wcsinit(header_string) */
  if( !(fun = FunOpen(argv[1], "r ", NULL)) ){
    fprintf(stderr, "ERROR can't open file: %s\n", argv[1]);
    exit(1);
  }

  /* get wcs structure */
  FunInfoGet(fun,FUN_WCS,&wcs,0);
  if( !wcs || !iswcs(wcs) ){
    fprintf(stderr,"No WCS data");
    return(1);
  }

  /* read input, convert pixels to wcs and back */
  while(1){
    fprintf(stdout,"\nInput x y: ");
    if(scanf("%lf %lf", &x, &y) != EOF){
      if(x <= -999)
	break;
      /* convert image pixels to sky coords */
      pix2wcs(wcs, x, y, &ra, &dec);
      fprintf(stdout,"Convert from pixels to ra,dec using pix2wcs()\n");
      fprintf(stdout, "x=%.10g y=%.10g -> ra=%.10g dec=%.10g\n",
	      x, y, ra, dec);
      /* convert sky coords to image pixels */
      fprintf(stdout,"Convert from ra,dec -> pixels using wcs2pix()\n");
      wcs2pix(wcs, ra, dec, &xr, &yr, &i);
      fprintf(stdout, "ra=%.10g dec=%.10g -> x=%.10g y=%.10g offscale=%d\n",
	      ra, dec, xr, yr, i);
    }
    else
      break;
  }

  /* clean up */
  /* FunClose makes final WCS library call: wcsfree(wcs) */
  FunClose(fun);
  return(0);
}