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
|
/*************************************************************************
* Johns Hopkins University
* Center For Astrophysical Sciences
* FUSE
*************************************************************************
*
*
* Usage:
* extract_jitter [-h] [-v level] input_file
*
*
*
* Arguments:
* input_file : jitter file
*
*
*
*
*
*
* Options:
* -h: this help message
* -v: verbosity level (=1; 0 is silent)
*
*
*
*
* History: 11/04/2004 v1.0 bjg
* 06/03/2005 v1.1 wvd Fix bug that set expstart=expend.
* Delete unused variables.
*
***************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#include "calfuse.h"
static char CF_PRGM_ID[]= "extract_jitter";
static char CF_VER_NUM[]= "1.0";
int main(int argc,char *argv[]){
char input_filename[FLEN_CARD];
char output_filename_x[FLEN_CARD];
char output_filename_y[FLEN_CARD];
FILE * output_file_x;
FILE * output_file_y;
fitsfile * infits;
int intnull=0,anynull;
int status=0;
int hdutype=0;
long i, N;
int ncol;
double * hdu2_time;
double * hdu2_dx;
double * hdu2_dy;
int * hdu2_trkflg;
double mjd,dx,dy;
int trkflg;
double expstart, expend;
int optc;
char opts[] = "hfv:";
char usage[] =
"Usage:\n"
" extract_jitter [-h] [-v level] input_file\n\n"
"Arguments:\n"
" input_file : jitter file (FITS)\n\n";
char option[] =
"Options:\n"
" -h: this help message \n"
" -v: verbosity level (=1; 0 is silent) \n";
verbose_level = 1;
/* Check number of options and arguments */
while ((optc = getopt(argc, argv, opts)) != -1) {
switch(optc) {
case 'h':
printf("%s\n%s", usage, option);
return EXIT_SUCCESS;
case 'v':
verbose_level = atoi(optarg);
break;
}
}
/* Initialize error checking. */
cf_error_init(CF_PRGM_ID, CF_VER_NUM, stderr);
if (argc != optind+1)
cf_if_error("%s\nIncorrect number of program arguments", usage);
cf_timestamp(CF_PRGM_ID, CF_VER_NUM, "Started execution.");
strcpy(input_filename,argv[optind]);
strcpy(output_filename_x,input_filename);
strcpy(output_filename_y,input_filename);
strcat(output_filename_x,".jtx");
strcat(output_filename_y,".jty");
/* Create the output file */
output_file_x = fopen(output_filename_x,"w");
output_file_y = fopen(output_filename_y,"w");
FITS_open_file(&infits,input_filename,READONLY,&status);
FITS_read_key(infits,TDOUBLE,"EXPSTART",&expstart,NULL,&status);
FITS_read_key(infits,TDOUBLE,"EXPEND",&expend,NULL,&status);
FITS_movabs_hdu(infits,2,&hdutype,&status);
FITS_read_key(infits,TLONG,"NAXIS2",&N,NULL,&status);
hdu2_time=(double *)malloc(N*sizeof(double));
hdu2_dx=(double *)malloc(N*sizeof(double));
hdu2_dy=(double *)malloc(N*sizeof(double));
hdu2_trkflg=(int *)malloc(N*sizeof(int));
FITS_get_colnum(infits, TRUE, "TIME", &ncol, &status);
FITS_read_col(infits, TDOUBLE, ncol, 1, 1, N, &intnull,
hdu2_time, &anynull, &status);
FITS_get_colnum(infits, TRUE, "DX", &ncol, &status);
FITS_read_col(infits, TDOUBLE, ncol, 1, 1, N, &intnull,
hdu2_dx, &anynull, &status);
FITS_get_colnum(infits, TRUE, "DY", &ncol, &status);
FITS_read_col(infits, TDOUBLE, ncol, 1, 1, N, &intnull,
hdu2_dy, &anynull, &status);
FITS_get_colnum(infits, TRUE, "TRKFLG", &ncol, &status);
FITS_read_col(infits, TINT, ncol, 1, 1, N, &intnull,
hdu2_trkflg, &anynull, &status);
for (i=0;i<N-100;i++){
mjd=expstart+(hdu2_time[i])/(3600.0*24.0);
dx=hdu2_dx[i];
dy=hdu2_dy[i];
trkflg=hdu2_trkflg[i];
if ((mjd>=expstart) && (mjd<=expend) && (trkflg==5)){
fprintf(output_file_x,"%15lf %15lf\n",mjd,dx);
fprintf(output_file_y,"%15lf %15lf\n",mjd,dy);
}
}
free(hdu2_time);
free(hdu2_dx);
free(hdu2_dy);
free(hdu2_trkflg);
FITS_close_file(infits,&status);
fclose(output_file_x);
fclose(output_file_y);
cf_timestamp(CF_PRGM_ID, CF_VER_NUM, "Finished execution.");
return EXIT_SUCCESS;
}
|