File: testrot.c

package info (click to toggle)
wcstools 3.9.7-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,684 kB
  • sloc: ansic: 113,336; sh: 553; makefile: 245; lisp: 86; sed: 1
file content (248 lines) | stat: -rw-r--r-- 5,797 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/* File testrot.c
 * June 19, 2002
 * By Jessica Mink Harvard-Smithsonian Center for Astrophysics)
 * Send bug reports to jmink@cfa.harvard.edu
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include "libwcs/fitsfile.h"
#include "libwcs/wcs.h"

static void usage();
static void PrintHead();

static int verbose = 0;		/* verbose/debugging flag */
static int tabout = 0;		/* tab table output flag */
static int nchar = 16;		/* maximum number of characters for filename */
static int hms = 0;		/* 1 for output in hh:mm:ss dd:mm:ss */
static int nf = 0;
static int version = 0;		/* If 1, print only program name and version */

static char *RevMsg = "TESTROT WCSTools 3.9.7, 26 April 2022, Jessica Mink (jmink@cfa.harvard.edu)";

main (ac, av)
int ac;
char **av;
{
    char *str;
    int readlist = 0;
    char *lastchar;
    char filename[128];
    FILE *flist;
    char *listfile;

    /* Check for help or version command first */
    str = *(av+1);
    if (!strcmp (str, "help") || !strcmp (str, "-help"))
	usage();
    if (!strcmp (str, "version") || !strcmp (str, "-version")) {
	version = 1;
	usage();
	}

    /* crack arguments */
    for (av++; --ac > 0 && (*(str = *av)=='-' || *str == '@'); av++) {
	char c;
	if (*str == '@')
	    str = str - 1;
	while (c = *++str)
	switch (c) {

	case 'h':	/* hh:mm:ss output for crval, cdelt in arcsec/pix */
	    hms++;
	    break;

	case 'n':	/* hh:mm:ss output */
	    tabout++;
	    break;

	case 't':	/* tab table output */
	    tabout++;
	    break;

	case 'v':	/* more verbosity */
	    verbose++;
	    break;

    	case 'z':	/* Use AIPS classic WCS */
    	    setdefwcs (WCS_ALT);
    	    break;

	case '@':	/* List of files to be read */
	    readlist++;
	    listfile = ++str;
	    str = str + strlen (str) - 1;
	    av++;
	    ac--;

	default:
	    usage();
	    break;
	}
    }

    /* Find number of images to search and leave listfile open for reading */
    if (readlist) {
	if ((flist = fopen (listfile, "r")) == NULL) {
	    fprintf (stderr,"TESTROT: List file %s cannot be read\n",
		     listfile);
	    usage ();
	    }
	while (fgets (filename, 128, flist) != NULL) {
	    lastchar = filename + strlen (filename) - 1;
	    if (*lastchar < 32) *lastchar = 0;
	    PrintHead (filename);
	    if (verbose)
		printf ("\n");
	    }
	fclose (flist);
	}

    /* If no arguments left, print usage */
    if (ac == 0)
	usage ();

    if (verbose)
	fprintf (stderr,"%s\n",RevMsg);

    nf = 0;
    while (ac-- > 0) {
	char *fn = *av++;
	nf++;
	PrintHead (fn);
	}

    return (0);
}

static void
usage ()
{
    fprintf (stderr,"%s\n",RevMsg);
    if (version)
	exit (-1);
    fprintf (stderr,"Print WCS part of FITS or IRAF image header\n");
    fprintf (stderr,"usage: testrot [-htv] file.fit ...\n");
    fprintf (stderr,"  -h: print CRVALs as hh:mm:ss dd:mm:ss\n");
    fprintf (stderr,"  -t: print tab table output\n");
    fprintf (stderr,"  -v: verbose\n");
    fprintf (stderr,"  -z: Use AIPS classic WCS subroutines\n");
    exit (1);
}


static void
PrintHead (filename)

char	*filename;	/* FITS or IRAF image file name */

{
    struct WorldCoor *wcs, *GetWCSFITS();
    static void TabRot();

    wcs = GetWCSFITS (filename, verbose);
    if (nowcs (wcs))
	return;

    TabRot (filename, wcs);

    free (wcs);
    return;
}


static void
TabRot (filename, wcs)

char	*filename;	/* FITS or IRAF image file name */

struct WorldCoor *wcs;

{
    int i, off;
    char fform[8];
    double xc, yc, cra, cdec, xe, ye, xn, yn, pa_north, pa_east;

    if (wcs->ctype[0][0] == (char) 0)
	return;
    if (tabout && nf == 1) {
	printf ("filename   ");
	for (i = 1; i < nchar - 5; i++) printf (" ");
	printf ("	flip	cd  ");
	printf ("	cd1_1	cd1_2	cd2_1	cd2_2");
	printf ("	cdelt1	cdelt2");
	printf ("	crota2  	north   	east     ");
	printf ("	imrot   	imflip\n");
	printf ("------------");
	for (i = 1; i < nchar - 8; i++) printf ("-");
	printf ("	------	------");
	printf ("	------	------	------	------");
	printf ("	------	------");
	printf ("	---------	---------	---------");
	printf ("	---------	-------\n");
	}

    sprintf (fform,"%%%d.%ds",nchar,nchar);
    if (tabout)
	printf (fform, filename);
    else
	printf (fform, filename);

    if (tabout)
	printf ("	%d	%d", wcs->coorflip, wcs->rotmat);
    else
	printf (" %d %d", wcs->coorflip, wcs->rotmat);

    if (tabout)
	printf ("	%7.4f	%7.4f	%7.4f	%7.4f",
		3600.0*wcs->cd[0], 3600.0*wcs->cd[1],
		3600.0*wcs->cd[2], 3600.0*wcs->cd[3]);
    else
	printf (" %7.4f %7.4f %7.4f %7.4f",
		3600.0*wcs->cd[0], 3600.0*wcs->cd[1],
		3600.0*wcs->cd[2], 3600.0*wcs->cd[3]);

    if (tabout)
	printf ("	%7.4f	%7.4f	%9.4f",
		3600.0*wcs->xinc, 3600.0*wcs->yinc, wcs->rot);
    else
	printf (" %7.4f %7.4f %9.4f",
		3600.0*wcs->xinc, 3600.0*wcs->yinc, wcs->rot);

    xc = wcs->crpix[0];
    yc = wcs->crpix[1];
    pix2wcs (wcs, xc, yc, &cra, &cdec);
    if (wcs->coorflip) {
	wcs2pix (wcs, cra+fabs(wcs->cdelt[1]), cdec, &xe, &ye, &off);
	wcs2pix (wcs, cra, cdec+fabs(wcs->cdelt[0]), &xn, &yn, &off);
	}
    else {
	wcs2pix (wcs, cra+fabs(wcs->cdelt[0]), cdec, &xe, &ye, &off);
	wcs2pix (wcs, cra, cdec+fabs(wcs->cdelt[1]), &xn, &yn, &off);
	}
    pa_north = raddeg (atan2 (yn-yc, xn-xc));
    pa_east = raddeg (atan2 (ye-yc, xe-xc));
    if (tabout)
	printf ("	%9.4f	%9.4f	%9.4f	%d\n",
		pa_north, pa_east, wcs->imrot, wcs->imflip);
    else
	printf (" %9.4f %9.4f %9.4f %d\n",
		pa_north, pa_east, wcs->imrot, wcs->imflip);

    return;
}
/* Sep  2 1998	New program
 * Nov 30 1998	Add version and help commands for consistency
 *
 * Oct 22 1999	Drop unused variables after lint
 *
 * Jan 28 2000	Call setdefwcs() with WCS_ALT instead of 1
 *
 * Jun 19 2002	Add verbose argument to GetWCSFITS()
 */