Format sattools C code with GNU indent...
parent
db0415128c
commit
556aa1cca3
263
src/addwcs.c
263
src/addwcs.c
|
@ -13,7 +13,8 @@
|
||||||
#define D2R M_PI/180.0
|
#define D2R M_PI/180.0
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
|
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int naxis, naxis1, naxis2, nframes;
|
int naxis, naxis1, naxis2, nframes;
|
||||||
float *zavg, *zstd, *zmax, *znum;
|
float *zavg, *zstd, *zmax, *znum;
|
||||||
double ra0, de0;
|
double ra0, de0;
|
||||||
|
@ -22,19 +23,22 @@ struct image {
|
||||||
double mjd;
|
double mjd;
|
||||||
float *dt;
|
float *dt;
|
||||||
};
|
};
|
||||||
struct transformation {
|
struct transformation
|
||||||
|
{
|
||||||
double mjd;
|
double mjd;
|
||||||
double ra0, de0;
|
double ra0, de0;
|
||||||
float a[3], b[3];
|
float a[3], b[3];
|
||||||
float x0, y0;
|
float x0, y0;
|
||||||
float xrms, yrms, rms;
|
float xrms, yrms, rms;
|
||||||
};
|
};
|
||||||
struct star {
|
struct star
|
||||||
|
{
|
||||||
double ra, de;
|
double ra, de;
|
||||||
float pmra, pmde;
|
float pmra, pmde;
|
||||||
float mag;
|
float mag;
|
||||||
};
|
};
|
||||||
struct catalog {
|
struct catalog
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
float x[NMAX], y[NMAX], imag[NMAX], fm[NMAX], fb[NMAX], bg[NMAX];
|
float x[NMAX], y[NMAX], imag[NMAX], fm[NMAX], fb[NMAX], bg[NMAX];
|
||||||
double ra[NMAX], de[NMAX], vmag[NMAX];
|
double ra[NMAX], de[NMAX], vmag[NMAX];
|
||||||
|
@ -43,20 +47,28 @@ struct catalog {
|
||||||
int usage[NMAX];
|
int usage[NMAX];
|
||||||
};
|
};
|
||||||
struct image read_fits (char *filename);
|
struct image read_fits (char *filename);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de);
|
double *y);
|
||||||
|
void reverse (double ra0, double de0, double x, double y, double *ra,
|
||||||
|
double *de);
|
||||||
double gmst (double mjd);
|
double gmst (double mjd);
|
||||||
double modulo (double x, double y);
|
double modulo (double x, double y);
|
||||||
int fgetline (FILE * file, char *s, int lim);
|
int fgetline (FILE * file, char *s, int lim);
|
||||||
struct catalog match_catalogs(char *pixcat,char *astcat,struct transformation t,struct image img,float rmax,float mmin);
|
struct catalog match_catalogs (char *pixcat, char *astcat,
|
||||||
void plot_astrometric_catalog(struct transformation t,struct image img,float mmin);
|
struct transformation t, struct image img,
|
||||||
|
float rmax, float mmin);
|
||||||
|
void plot_astrometric_catalog (struct transformation t, struct image img,
|
||||||
|
float mmin);
|
||||||
void plot_pixel_catalog (char *filename);
|
void plot_pixel_catalog (char *filename);
|
||||||
void lfit2d (float *x, float *y, float *z, int n, float *a);
|
void lfit2d (float *x, float *y, float *z, int n, float *a);
|
||||||
void add_fits_keywords (struct transformation t, char *filename);
|
void add_fits_keywords (struct transformation t, char *filename);
|
||||||
void modify_fits_keywords (struct transformation t, char *filename);
|
void modify_fits_keywords (struct transformation t, char *filename);
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de);
|
void precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de);
|
||||||
|
|
||||||
void plot_image(struct image img,struct transformation t,struct catalog c,char *filename,float mmin)
|
void
|
||||||
|
plot_image (struct image img, struct transformation t, struct catalog c,
|
||||||
|
char *filename, float mmin)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float tr[] = { -0.5, 1.0, 0.0, -0.5, 0.0, 1.0 };
|
float tr[] = { -0.5, 1.0, 0.0, -0.5, 0.0, 1.0 };
|
||||||
|
@ -79,7 +91,8 @@ void plot_image(struct image img,struct transformation t,struct catalog c,char *
|
||||||
cpgwnad (0.0, img.naxis1, 0.0, img.naxis2);
|
cpgwnad (0.0, img.naxis1, 0.0, img.naxis2);
|
||||||
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
||||||
|
|
||||||
cpgimag(img.zavg,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,zmin,zmax,tr);
|
cpgimag (img.zavg, img.naxis1, img.naxis2, 1, img.naxis1, 1, img.naxis2,
|
||||||
|
zmin, zmax, tr);
|
||||||
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
||||||
|
|
||||||
cpgsci (3);
|
cpgsci (3);
|
||||||
|
@ -96,24 +109,32 @@ void plot_image(struct image img,struct transformation t,struct catalog c,char *
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(float mmin,float rmin)
|
void
|
||||||
|
usage (float mmin, float rmin)
|
||||||
{
|
{
|
||||||
printf ("addwcs: Add/fit World Coordinate System to a FITS file\n\n");
|
printf ("addwcs: Add/fit World Coordinate System to a FITS file\n\n");
|
||||||
|
|
||||||
printf ("-f <file>: FITS file to add/fit WCS to [required]\n");
|
printf ("-f <file>: FITS file to add/fit WCS to [required]\n");
|
||||||
printf ("-r <file>: FITS file with reference WCS [required]\n");
|
printf ("-r <file>: FITS file with reference WCS [required]\n");
|
||||||
printf("-m <float>: Magnitude cut-off in Tycho-2 catalog [optional; default %.1f]\n",mmin);
|
printf
|
||||||
printf("-R <float>: Radius cut-off for matching [optional; default %.1f pix]\n",rmin);
|
("-m <float>: Magnitude cut-off in Tycho-2 catalog [optional; default %.1f]\n",
|
||||||
|
mmin);
|
||||||
|
printf
|
||||||
|
("-R <float>: Radius cut-off for matching [optional; default %.1f pix]\n",
|
||||||
|
rmin);
|
||||||
printf ("-p Plot image and selected stars [optional]\n");
|
printf ("-p Plot image and selected stars [optional]\n");
|
||||||
printf("-a Add WCS keywords to input file (instead of modify) [optional]\n");
|
printf
|
||||||
printf("-t Track on a fixed RA/Dec (correct for field rotation)\n");
|
("-a Add WCS keywords to input file (instead of modify) [optional]\n");
|
||||||
|
printf
|
||||||
|
("-t Track on a fixed RA/Dec (correct for field rotation)\n");
|
||||||
printf ("-h Print this help\n");
|
printf ("-h Print this help\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get reference transformation
|
// Get reference transformation
|
||||||
struct transformation reference(char *filename)
|
struct transformation
|
||||||
|
reference (char *filename)
|
||||||
{
|
{
|
||||||
struct transformation t;
|
struct transformation t;
|
||||||
|
|
||||||
|
@ -132,7 +153,8 @@ struct transformation reference(char *filename)
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotate(float theta,float *x,float *y)
|
void
|
||||||
|
rotate (float theta, float *x, float *y)
|
||||||
{
|
{
|
||||||
float ct, st;
|
float ct, st;
|
||||||
float x0, y0;
|
float x0, y0;
|
||||||
|
@ -148,7 +170,8 @@ void rotate(float theta,float *x,float *y)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
struct transformation t;
|
struct transformation t;
|
||||||
|
@ -169,9 +192,12 @@ int main(int argc,char *argv[])
|
||||||
sprintf (starfile, "%s/data/tycho2.dat", env);
|
sprintf (starfile, "%s/data/tycho2.dat", env);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
if (argc>1) {
|
if (argc > 1)
|
||||||
while ((arg=getopt(argc,argv,"f:r:m:R:hpnta"))!=-1) {
|
{
|
||||||
switch (arg) {
|
while ((arg = getopt (argc, argv, "f:r:m:R:hpnta")) != -1)
|
||||||
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
fitsfile = optarg;
|
fitsfile = optarg;
|
||||||
|
@ -210,25 +236,30 @@ int main(int argc,char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
usage (mmin, rmin);
|
usage (mmin, rmin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if minimum input is provided
|
// Check if minimum input is provided
|
||||||
if (fitsfile==NULL || reffile==NULL) {
|
if (fitsfile == NULL || reffile == NULL)
|
||||||
|
{
|
||||||
usage (mmin, rmin);
|
usage (mmin, rmin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check this is indeed a FITS file
|
// Check this is indeed a FITS file
|
||||||
if (is_fits_file(fitsfile)!=1) {
|
if (is_fits_file (fitsfile) != 1)
|
||||||
|
{
|
||||||
printf ("%s is not a FITS file\n", fitsfile);
|
printf ("%s is not a FITS file\n", fitsfile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check this is indeed a FITS file
|
// Check this is indeed a FITS file
|
||||||
if (is_fits_file(reffile)!=1) {
|
if (is_fits_file (reffile) != 1)
|
||||||
|
{
|
||||||
printf ("%s is not a FITS file\n", reffile);
|
printf ("%s is not a FITS file\n", reffile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +273,8 @@ int main(int argc,char *argv[])
|
||||||
t = reference (reffile);
|
t = reference (reffile);
|
||||||
|
|
||||||
// Correct astrometry for fixed or tracked setup
|
// Correct astrometry for fixed or tracked setup
|
||||||
if (track==0) {
|
if (track == 0)
|
||||||
|
{
|
||||||
precess (mjd0, t.ra0, t.de0, t.mjd, &ra1, &de1);
|
precess (mjd0, t.ra0, t.de0, t.mjd, &ra1, &de1);
|
||||||
ra1 = modulo (ra1 + gmst (img.mjd) - gmst (t.mjd), 360.0);
|
ra1 = modulo (ra1 + gmst (img.mjd) - gmst (t.mjd), 360.0);
|
||||||
precess (img.mjd, ra1, de1, mjd0, &t.ra0, &t.de0);
|
precess (img.mjd, ra1, de1, mjd0, &t.ra0, &t.de0);
|
||||||
|
@ -257,16 +289,21 @@ int main(int argc,char *argv[])
|
||||||
plot_image (img, t, c, catfile, mmin);
|
plot_image (img, t, c, catfile, mmin);
|
||||||
|
|
||||||
// Do fit
|
// Do fit
|
||||||
if (c.n>10) {
|
if (c.n > 10)
|
||||||
for (l=0;l<10;l++) {
|
{
|
||||||
for (j=0;j<5;j++) {
|
for (l = 0; l < 10; l++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 5; j++)
|
||||||
|
{
|
||||||
// Transform
|
// Transform
|
||||||
for (i = 0; i < c.n; i++)
|
for (i = 0; i < c.n; i++)
|
||||||
forward (t.ra0, t.de0, c.ra[i], c.de[i], &c.rx[i], &c.ry[i]);
|
forward (t.ra0, t.de0, c.ra[i], c.de[i], &c.rx[i], &c.ry[i]);
|
||||||
|
|
||||||
// Select
|
// Select
|
||||||
for (i=0,k=0;i<c.n;i++) {
|
for (i = 0, k = 0; i < c.n; i++)
|
||||||
if (c.usage[i]==1) {
|
{
|
||||||
|
if (c.usage[i] == 1)
|
||||||
|
{
|
||||||
x[k] = c.x[i];
|
x[k] = c.x[i];
|
||||||
y[k] = c.y[i];
|
y[k] = c.y[i];
|
||||||
rx[k] = (float) c.rx[i];
|
rx[k] = (float) c.rx[i];
|
||||||
|
@ -285,12 +322,17 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute and plot residuals
|
// Compute and plot residuals
|
||||||
for (i=0,t.xrms=0.0,t.yrms=0.0,m=0;i<c.n;i++) {
|
for (i = 0, t.xrms = 0.0, t.yrms = 0.0, m = 0; i < c.n; i++)
|
||||||
if (c.usage[i]==1) {
|
{
|
||||||
c.xres[i]=c.rx[i]-(t.a[0]+t.a[1]*c.x[i]+t.a[2]*c.y[i]);
|
if (c.usage[i] == 1)
|
||||||
c.yres[i]=c.ry[i]-(t.b[0]+t.b[1]*c.x[i]+t.b[2]*c.y[i]);
|
{
|
||||||
|
c.xres[i] =
|
||||||
|
c.rx[i] - (t.a[0] + t.a[1] * c.x[i] + t.a[2] * c.y[i]);
|
||||||
|
c.yres[i] =
|
||||||
|
c.ry[i] - (t.b[0] + t.b[1] * c.x[i] + t.b[2] * c.y[i]);
|
||||||
|
|
||||||
c.res[i]=sqrt(c.xres[i]*c.xres[i]+c.yres[i]*c.yres[i]);
|
c.res[i] =
|
||||||
|
sqrt (c.xres[i] * c.xres[i] + c.yres[i] * c.yres[i]);
|
||||||
t.xrms += c.xres[i] * c.xres[i];
|
t.xrms += c.xres[i] * c.xres[i];
|
||||||
t.yrms += c.yres[i] * c.yres[i];
|
t.yrms += c.yres[i] * c.yres[i];
|
||||||
t.rms += c.xres[i] * c.xres[i] + c.yres[i] * c.yres[i];
|
t.rms += c.xres[i] * c.xres[i] + c.yres[i] * c.yres[i];
|
||||||
|
@ -302,12 +344,15 @@ int main(int argc,char *argv[])
|
||||||
t.rms = sqrt (t.rms / (float) m);
|
t.rms = sqrt (t.rms / (float) m);
|
||||||
|
|
||||||
// Deselect outliers
|
// Deselect outliers
|
||||||
for (i=0;i<c.n;i++) {
|
for (i = 0; i < c.n; i++)
|
||||||
|
{
|
||||||
if (c.res[i] > 2 * t.rms)
|
if (c.res[i] > 2 * t.rms)
|
||||||
c.usage[i] = 0;
|
c.usage[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
t.xrms = 0.0;
|
t.xrms = 0.0;
|
||||||
t.yrms = 0.0;
|
t.yrms = 0.0;
|
||||||
t.rms = 0.0;
|
t.rms = 0.0;
|
||||||
|
@ -317,7 +362,10 @@ int main(int argc,char *argv[])
|
||||||
outfile = fopen (calfile, "w");
|
outfile = fopen (calfile, "w");
|
||||||
for (i = 0; i < c.n; i++)
|
for (i = 0; i < c.n; i++)
|
||||||
if (c.usage[i] == 1)
|
if (c.usage[i] == 1)
|
||||||
fprintf(outfile,"%10.4f %10.4f %10.6f %10.6f %8.3f %8.3f %8.3f %8.3f %8.3f\n",c.x[i],c.y[i],c.ra[i],c.de[i],c.vmag[i],c.imag[i],c.fb[i],c.fm[i],c.bg[i]);
|
fprintf (outfile,
|
||||||
|
"%10.4f %10.4f %10.6f %10.6f %8.3f %8.3f %8.3f %8.3f %8.3f\n",
|
||||||
|
c.x[i], c.y[i], c.ra[i], c.de[i], c.vmag[i], c.imag[i],
|
||||||
|
c.fb[i], c.fm[i], c.bg[i]);
|
||||||
fclose (outfile);
|
fclose (outfile);
|
||||||
|
|
||||||
printf ("%s %8.4lf %8.4lf ", fitsfile, t.ra0, t.de0);
|
printf ("%s %8.4lf %8.4lf ", fitsfile, t.ra0, t.de0);
|
||||||
|
@ -333,7 +381,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename)
|
struct image
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -354,13 +403,15 @@ struct image read_fits(char *filename)
|
||||||
ql.ptype = PTYPE_FLOAT;
|
ql.ptype = PTYPE_FLOAT;
|
||||||
ql.filename = filename;
|
ql.filename = filename;
|
||||||
|
|
||||||
if (img.naxis==3) {
|
if (img.naxis == 3)
|
||||||
|
{
|
||||||
// Number of frames
|
// Number of frames
|
||||||
img.nframes = atoi (qfits_query_hdr (filename, "NFRAMES"));
|
img.nframes = atoi (qfits_query_hdr (filename, "NFRAMES"));
|
||||||
|
|
||||||
// Timestamps
|
// Timestamps
|
||||||
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
||||||
for (i=0;i<img.nframes;i++) {
|
for (i = 0; i < img.nframes; i++)
|
||||||
|
{
|
||||||
sprintf (key, "DT%04d", i);
|
sprintf (key, "DT%04d", i);
|
||||||
strcpy (val, qfits_query_hdr (filename, key));
|
strcpy (val, qfits_query_hdr (filename, key));
|
||||||
sscanf (val + 1, "%f", &img.dt[i]);
|
sscanf (val + 1, "%f", &img.dt[i]);
|
||||||
|
@ -375,7 +426,8 @@ struct image read_fits(char *filename)
|
||||||
|
|
||||||
|
|
||||||
// Loop over planes
|
// Loop over planes
|
||||||
for (k=0;k<4;k++) {
|
for (k = 0; k < 4; k++)
|
||||||
|
{
|
||||||
ql.pnum = k;;
|
ql.pnum = k;;
|
||||||
|
|
||||||
// Initialize load
|
// Initialize load
|
||||||
|
@ -387,17 +439,25 @@ struct image read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
if (k==0) img.zavg[l]=ql.fbuf[l];
|
for (j = 0; j < img.naxis2; j++)
|
||||||
if (k==1) img.zstd[l]=ql.fbuf[l];
|
{
|
||||||
if (k==2) img.zmax[l]=ql.fbuf[l];
|
if (k == 0)
|
||||||
if (k==3) img.znum[l]=ql.fbuf[l];
|
img.zavg[l] = ql.fbuf[l];
|
||||||
|
if (k == 1)
|
||||||
|
img.zstd[l] = ql.fbuf[l];
|
||||||
|
if (k == 2)
|
||||||
|
img.zmax[l] = ql.fbuf[l];
|
||||||
|
if (k == 3)
|
||||||
|
img.znum[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Allocate image memory
|
// Allocate image memory
|
||||||
img.zavg = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
img.zavg = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
||||||
|
|
||||||
|
@ -412,8 +472,10 @@ struct image read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
img.zavg[l] = ql.fbuf[l];
|
img.zavg[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
|
@ -425,28 +487,34 @@ struct image read_fits(char *filename)
|
||||||
|
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -459,7 +527,9 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match catalogs
|
// Match catalogs
|
||||||
struct catalog match_catalogs(char *pixcat,char *astcat,struct transformation t,struct image img,float rmax,float mmin)
|
struct catalog
|
||||||
|
match_catalogs (char *pixcat, char *astcat, struct transformation t,
|
||||||
|
struct image img, float rmax, float mmin)
|
||||||
{
|
{
|
||||||
int i = 0, imin, j, k, np;
|
int i = 0, imin, j, k, np;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -473,14 +543,17 @@ struct catalog match_catalogs(char *pixcat,char *astcat,struct transformation t,
|
||||||
|
|
||||||
// Read pixel catalog
|
// Read pixel catalog
|
||||||
file = fopen (pixcat, "r");
|
file = fopen (pixcat, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("pixel catalog not found\n");
|
printf ("pixel catalog not found\n");
|
||||||
exit (-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
sscanf(line,"%f %f %f %f %f %f",&xp[i],&yp[i],&mp[i],&fb[i],&fm[i],&bg[i]);
|
sscanf (line, "%f %f %f %f %f %f", &xp[i], &yp[i], &mp[i], &fb[i],
|
||||||
|
&fm[i], &bg[i]);
|
||||||
usage[i] = 1;
|
usage[i] = 1;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -492,16 +565,21 @@ struct catalog match_catalogs(char *pixcat,char *astcat,struct transformation t,
|
||||||
|
|
||||||
// Read astrometric catalog
|
// Read astrometric catalog
|
||||||
file = fopen (astcat, "rb");
|
file = fopen (astcat, "rb");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("astrometric catalog not found\n");
|
printf ("astrometric catalog not found\n");
|
||||||
exit (-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
j = 0;
|
j = 0;
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fread (&s, sizeof (struct star), 1, file);
|
fread (&s, sizeof (struct star), 1, file);
|
||||||
if (s.mag > mmin)
|
if (s.mag > mmin)
|
||||||
continue;
|
continue;
|
||||||
r=acos(sin(t.de0*D2R)*sin(s.de*D2R)+cos(t.de0*D2R)*cos(s.de*D2R)*cos((t.ra0-s.ra)*D2R))*R2D;
|
r =
|
||||||
|
acos (sin (t.de0 * D2R) * sin (s.de * D2R) +
|
||||||
|
cos (t.de0 * D2R) * cos (s.de * D2R) * cos ((t.ra0 - s.ra) *
|
||||||
|
D2R)) * R2D;
|
||||||
if (r > 90.0)
|
if (r > 90.0)
|
||||||
continue;
|
continue;
|
||||||
forward (t.ra0, t.de0, s.ra, s.de, &rx, &ry);
|
forward (t.ra0, t.de0, s.ra, s.de, &rx, &ry);
|
||||||
|
@ -512,18 +590,22 @@ struct catalog match_catalogs(char *pixcat,char *astcat,struct transformation t,
|
||||||
y = (t.a[1] * dy - t.b[1] * dx) / d + t.y0;
|
y = (t.a[1] * dy - t.b[1] * dx) / d + t.y0;
|
||||||
|
|
||||||
// On image
|
// On image
|
||||||
if (x>0.0 && x<img.naxis1 && y>0.0 && y<img.naxis2) {
|
if (x > 0.0 && x < img.naxis1 && y > 0.0 && y < img.naxis2)
|
||||||
|
{
|
||||||
// Loop over pixel catalog
|
// Loop over pixel catalog
|
||||||
for (i=0;i<np;i++) {
|
for (i = 0; i < np; i++)
|
||||||
|
{
|
||||||
r = sqrt (pow (xp[i] - x, 2) + pow (yp[i] - y, 2));
|
r = sqrt (pow (xp[i] - x, 2) + pow (yp[i] - y, 2));
|
||||||
if (i==0 || r<rmin) {
|
if (i == 0 || r < rmin)
|
||||||
|
{
|
||||||
rmin = r;
|
rmin = r;
|
||||||
imin = i;
|
imin = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select
|
// Select
|
||||||
if (rmin<rmax && usage[imin]==1) {
|
if (rmin < rmax && usage[imin] == 1)
|
||||||
|
{
|
||||||
c.x[j] = xp[imin] - t.x0;
|
c.x[j] = xp[imin] - t.x0;
|
||||||
c.y[j] = yp[imin] - t.y0;
|
c.y[j] = yp[imin] - t.y0;
|
||||||
c.imag[j] = mp[imin];
|
c.imag[j] = mp[imin];
|
||||||
|
@ -546,7 +628,9 @@ struct catalog match_catalogs(char *pixcat,char *astcat,struct transformation t,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plot astrometric catalog
|
// Plot astrometric catalog
|
||||||
void plot_astrometric_catalog(struct transformation t,struct image img,float mmin)
|
void
|
||||||
|
plot_astrometric_catalog (struct transformation t, struct image img,
|
||||||
|
float mmin)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -563,11 +647,15 @@ void plot_astrometric_catalog(struct transformation t,struct image img,float mmi
|
||||||
d = t.a[1] * t.b[2] - t.a[2] * t.b[1];
|
d = t.a[1] * t.b[2] - t.a[2] * t.b[1];
|
||||||
|
|
||||||
file = fopen (starfile, "rb");
|
file = fopen (starfile, "rb");
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fread (&s, sizeof (struct star), 1, file);
|
fread (&s, sizeof (struct star), 1, file);
|
||||||
if (s.mag > mmin)
|
if (s.mag > mmin)
|
||||||
continue;
|
continue;
|
||||||
r=acos(sin(t.de0*D2R)*sin(s.de*D2R)+cos(t.de0*D2R)*cos(s.de*D2R)*cos((t.ra0-s.ra)*D2R))*R2D;
|
r =
|
||||||
|
acos (sin (t.de0 * D2R) * sin (s.de * D2R) +
|
||||||
|
cos (t.de0 * D2R) * cos (s.de * D2R) * cos ((t.ra0 - s.ra) *
|
||||||
|
D2R)) * R2D;
|
||||||
if (r > 90.0)
|
if (r > 90.0)
|
||||||
continue;
|
continue;
|
||||||
forward (t.ra0, t.de0, s.ra, s.de, &rx, &ry);
|
forward (t.ra0, t.de0, s.ra, s.de, &rx, &ry);
|
||||||
|
@ -582,7 +670,8 @@ void plot_astrometric_catalog(struct transformation t,struct image img,float mmi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plot pixel catalog
|
// Plot pixel catalog
|
||||||
void plot_pixel_catalog(char *filename)
|
void
|
||||||
|
plot_pixel_catalog (char *filename)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -591,7 +680,8 @@ void plot_pixel_catalog(char *filename)
|
||||||
|
|
||||||
// Read catalog
|
// Read catalog
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
sscanf (line, "%f %f %f", &x, &y, &mag);
|
sscanf (line, "%f %f %f", &x, &y, &mag);
|
||||||
|
@ -606,7 +696,8 @@ void plot_pixel_catalog(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linear 2D fit
|
// Linear 2D fit
|
||||||
void lfit2d(float *x,float *y,float *z,int n,float *a)
|
void
|
||||||
|
lfit2d (float *x, float *y, float *z, int n, float *a)
|
||||||
{
|
{
|
||||||
int i, j, m;
|
int i, j, m;
|
||||||
double chisq;
|
double chisq;
|
||||||
|
@ -621,7 +712,8 @@ void lfit2d(float *x,float *y,float *z,int n,float *a)
|
||||||
cov = gsl_matrix_alloc (3, 3);
|
cov = gsl_matrix_alloc (3, 3);
|
||||||
|
|
||||||
// Fill matrices
|
// Fill matrices
|
||||||
for(i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
gsl_matrix_set (X, i, 0, 1.0);
|
gsl_matrix_set (X, i, 0, 1.0);
|
||||||
gsl_matrix_set (X, i, 1, x[i]);
|
gsl_matrix_set (X, i, 1, x[i]);
|
||||||
gsl_matrix_set (X, i, 2, y[i]);
|
gsl_matrix_set (X, i, 2, y[i]);
|
||||||
|
@ -649,7 +741,8 @@ void lfit2d(float *x,float *y,float *z,int n,float *a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add FITS keywords
|
// Add FITS keywords
|
||||||
void add_fits_keywords(struct transformation t,char *filename)
|
void
|
||||||
|
add_fits_keywords (struct transformation t, char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
int naxis1, naxis2, naxis3;
|
int naxis1, naxis2, naxis3;
|
||||||
|
@ -675,7 +768,8 @@ void add_fits_keywords(struct transformation t,char *filename)
|
||||||
ql.xtnum = 0;
|
ql.xtnum = 0;
|
||||||
ql.ptype = PTYPE_FLOAT;
|
ql.ptype = PTYPE_FLOAT;
|
||||||
ql.filename = filename;
|
ql.filename = filename;
|
||||||
for (k=0,l=0;k<naxis3;k++) {
|
for (k = 0, l = 0; k < naxis3; k++)
|
||||||
|
{
|
||||||
ql.pnum = k;
|
ql.pnum = k;
|
||||||
// Initialize load
|
// Initialize load
|
||||||
if (qfitsloader_init (&ql) != 0)
|
if (qfitsloader_init (&ql) != 0)
|
||||||
|
@ -685,8 +779,10 @@ void add_fits_keywords(struct transformation t,char *filename)
|
||||||
if (qfits_loadpix (&ql) != 0)
|
if (qfits_loadpix (&ql) != 0)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
for (i=0,m=0;i<naxis1;i++) {
|
for (i = 0, m = 0; i < naxis1; i++)
|
||||||
for (j=0;j<naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < naxis2; j++)
|
||||||
|
{
|
||||||
fbuf[l] = ql.fbuf[m];
|
fbuf[l] = ql.fbuf[m];
|
||||||
l++;
|
l++;
|
||||||
m++;
|
m++;
|
||||||
|
@ -738,7 +834,8 @@ void add_fits_keywords(struct transformation t,char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify FITS keywords
|
// Modify FITS keywords
|
||||||
void modify_fits_keywords(struct transformation t,char *filename)
|
void
|
||||||
|
modify_fits_keywords (struct transformation t, char *filename)
|
||||||
{
|
{
|
||||||
char card[FITS_LINESZ + 1];
|
char card[FITS_LINESZ + 1];
|
||||||
char key[FITS_LINESZ + 1];
|
char key[FITS_LINESZ + 1];
|
||||||
|
@ -790,7 +887,9 @@ void modify_fits_keywords(struct transformation t,char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precess a celestial position
|
// Precess a celestial position
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
void
|
||||||
|
precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
double zeta, z, theta;
|
double zeta, z, theta;
|
||||||
|
|
148
src/allnight.c
148
src/allnight.c
|
@ -11,7 +11,8 @@
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
#define XKMPAU 149597879.691 // AU in km
|
#define XKMPAU 149597879.691 // AU in km
|
||||||
|
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
int site_id;
|
int site_id;
|
||||||
double mjd;
|
double mjd;
|
||||||
float saltmin, alt;
|
float saltmin, alt;
|
||||||
|
@ -31,7 +32,8 @@ void get_site(int site_id);
|
||||||
double date2mjd (int year, int month, double day);
|
double date2mjd (int year, int month, double day);
|
||||||
void usage (void);
|
void usage (void);
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0;
|
int arg = 0;
|
||||||
char *env;
|
char *env;
|
||||||
|
@ -47,15 +49,21 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Get default site
|
// Get default site
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (m.datadir, env);
|
strcpy (m.datadir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_DATADIR environment variable not found.\n");
|
printf ("ST_DATADIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
env = getenv ("ST_COSPAR");
|
env = getenv ("ST_COSPAR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
get_site (atoi (env));
|
get_site (atoi (env));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_COSPAR environment variable not found.\n");
|
printf ("ST_COSPAR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +72,10 @@ int main(int argc,char *argv[])
|
||||||
m.mjd = nfd2mjd (m.nfd);
|
m.mjd = nfd2mjd (m.nfd);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"t:s:S:h"))!=-1) {
|
while ((arg = getopt (argc, argv, "t:s:S:h")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (m.nfd, optarg);
|
strcpy (m.nfd, optarg);
|
||||||
|
@ -98,7 +108,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Usage
|
// Usage
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf ("allnight t:s:S:\n\n");
|
printf ("allnight t:s:S:\n\n");
|
||||||
printf ("t date/time (yyyy-mm-ddThh:mm:ss.sss) [default: now]\n");
|
printf ("t date/time (yyyy-mm-ddThh:mm:ss.sss) [default: now]\n");
|
||||||
|
@ -109,29 +120,40 @@ void usage(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert equatorial into horizontal coordinates
|
// Convert equatorial into horizontal coordinates
|
||||||
void equatorial2horizontal(double mjd,double ra,double de,double *azi,double *alt)
|
void
|
||||||
|
equatorial2horizontal (double mjd, double ra, double de, double *azi,
|
||||||
|
double *alt)
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
|
|
||||||
h = gmst (mjd) + m.lng - ra;
|
h = gmst (mjd) + m.lng - ra;
|
||||||
|
|
||||||
*azi=modulo(atan2(sin(h*D2R),cos(h*D2R)*sin(m.lat*D2R)-tan(de*D2R)*cos(m.lat*D2R))*R2D,360.0);
|
*azi =
|
||||||
*alt=asin(sin(m.lat*D2R)*sin(de*D2R)+cos(m.lat*D2R)*cos(de*D2R)*cos(h*D2R))*R2D;
|
modulo (atan2
|
||||||
|
(sin (h * D2R),
|
||||||
|
cos (h * D2R) * sin (m.lat * D2R) -
|
||||||
|
tan (de * D2R) * cos (m.lat * D2R)) * R2D, 360.0);
|
||||||
|
*alt =
|
||||||
|
asin (sin (m.lat * D2R) * sin (de * D2R) +
|
||||||
|
cos (m.lat * D2R) * cos (de * D2R) * cos (h * D2R)) * R2D;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Solar position
|
// Solar position
|
||||||
void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
void
|
||||||
|
sunpos_xyz (double mjd, xyz_t * pos, double *ra, double *de)
|
||||||
{
|
{
|
||||||
double jd, t, l0, m, e, c, r;
|
double jd, t, l0, m, e, c, r;
|
||||||
double n, s, ecl;
|
double n, s, ecl;
|
||||||
|
@ -148,7 +170,10 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
||||||
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
||||||
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
||||||
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
||||||
ecl=(23.43929111+(-46.8150*t-0.00059*t*t+0.001813*t*t*t)/3600.0+0.00256*cos(n))*D2R;
|
ecl =
|
||||||
|
(23.43929111 +
|
||||||
|
(-46.8150 * t - 0.00059 * t * t + 0.001813 * t * t * t) / 3600.0 +
|
||||||
|
0.00256 * cos (n)) * D2R;
|
||||||
|
|
||||||
*ra = atan2 (cos (ecl) * sin (s), cos (s)) * R2D;
|
*ra = atan2 (cos (ecl) * sin (s), cos (s)) * R2D;
|
||||||
*de = asin (sin (ecl) * sin (s)) * R2D;
|
*de = asin (sin (ecl) * sin (s)) * R2D;
|
||||||
|
@ -160,7 +185,8 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void allnight(void)
|
void
|
||||||
|
allnight (void)
|
||||||
{
|
{
|
||||||
int flag;
|
int flag;
|
||||||
xyz_t sunpos;
|
xyz_t sunpos;
|
||||||
|
@ -173,12 +199,15 @@ void allnight(void)
|
||||||
equatorial2horizontal (m.mjd, ra, de, &azi, &alt);
|
equatorial2horizontal (m.mjd, ra, de, &azi, &alt);
|
||||||
|
|
||||||
// Sun below limit, find rise, then set
|
// Sun below limit, find rise, then set
|
||||||
if (alt<m.saltmin) {
|
if (alt < m.saltmin)
|
||||||
for (flag=0,mjd=m.mjd;mjd<m.mjd+0.5;mjd+=1.0/86400) {
|
{
|
||||||
|
for (flag = 0, mjd = m.mjd; mjd < m.mjd + 0.5; mjd += 1.0 / 86400)
|
||||||
|
{
|
||||||
sunpos_xyz (mjd, &sunpos, &ra, &de);
|
sunpos_xyz (mjd, &sunpos, &ra, &de);
|
||||||
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
||||||
|
|
||||||
if (flag!=0) {
|
if (flag != 0)
|
||||||
|
{
|
||||||
if (alt > m.saltmin && alt0 <= m.saltmin)
|
if (alt > m.saltmin && alt0 <= m.saltmin)
|
||||||
mjdrise = mjd;
|
mjdrise = mjd;
|
||||||
}
|
}
|
||||||
|
@ -188,11 +217,13 @@ void allnight(void)
|
||||||
|
|
||||||
alt0 = alt;
|
alt0 = alt;
|
||||||
}
|
}
|
||||||
for (flag=0,mjd=m.mjd-0.5;mjd<m.mjd;mjd+=1.0/86400) {
|
for (flag = 0, mjd = m.mjd - 0.5; mjd < m.mjd; mjd += 1.0 / 86400)
|
||||||
|
{
|
||||||
sunpos_xyz (mjd, &sunpos, &ra, &de);
|
sunpos_xyz (mjd, &sunpos, &ra, &de);
|
||||||
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
||||||
|
|
||||||
if (flag!=0) {
|
if (flag != 0)
|
||||||
|
{
|
||||||
if (alt < m.saltmin && alt0 >= m.saltmin)
|
if (alt < m.saltmin && alt0 >= m.saltmin)
|
||||||
mjdset = mjd;
|
mjdset = mjd;
|
||||||
}
|
}
|
||||||
|
@ -203,12 +234,16 @@ void allnight(void)
|
||||||
alt0 = alt;
|
alt0 = alt;
|
||||||
}
|
}
|
||||||
// Sun above limit, find set, and rise
|
// Sun above limit, find set, and rise
|
||||||
} else {
|
}
|
||||||
for (flag=0,mjd=m.mjd;mjd<m.mjd+1.0;mjd+=1.0/86400) {
|
else
|
||||||
|
{
|
||||||
|
for (flag = 0, mjd = m.mjd; mjd < m.mjd + 1.0; mjd += 1.0 / 86400)
|
||||||
|
{
|
||||||
sunpos_xyz (mjd, &sunpos, &ra, &de);
|
sunpos_xyz (mjd, &sunpos, &ra, &de);
|
||||||
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
||||||
|
|
||||||
if (flag!=0) {
|
if (flag != 0)
|
||||||
|
{
|
||||||
if (alt > m.saltmin && alt0 <= m.saltmin)
|
if (alt > m.saltmin && alt0 <= m.saltmin)
|
||||||
mjdrise = mjd;
|
mjdrise = mjd;
|
||||||
if (alt < m.saltmin && alt0 >= m.saltmin)
|
if (alt < m.saltmin && alt0 >= m.saltmin)
|
||||||
|
@ -231,7 +266,8 @@ void allnight(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date)
|
void
|
||||||
|
mjd2date (double mjd, char *date)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -246,7 +282,8 @@ void mjd2date(double mjd,char *date)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -276,25 +313,30 @@ void mjd2date(double mjd,char *date)
|
||||||
hour = x;
|
hour = x;
|
||||||
sec = floor (1000.0 * sec) / 1000.0;
|
sec = floor (1000.0 * sec) / 1000.0;
|
||||||
|
|
||||||
sprintf(date,"%04d-%02d-%02dT%02d:%02d:%02.0f",year,month,day,hour,min,sec);
|
sprintf (date, "%04d-%02d-%02dT%02d:%02d:%02.0f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -303,18 +345,22 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -323,12 +369,14 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -336,17 +384,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -358,11 +412,13 @@ void get_site(int site_id)
|
||||||
|
|
||||||
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -371,14 +427,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
|
|
@ -11,14 +11,16 @@ double s2dec(char *);
|
||||||
void reverse (double, double, double, double, double *, double *);
|
void reverse (double, double, double, double, double *, double *);
|
||||||
void forward (double, double, double, double, double *, double *);
|
void forward (double, double, double, double, double *, double *);
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double ra1, de1, ra2, de2;
|
double ra1, de1, ra2, de2;
|
||||||
double rx, ry;
|
double rx, ry;
|
||||||
char sra[15], sde[15];
|
char sra[15], sde[15];
|
||||||
|
|
||||||
if (argc==1) {
|
if (argc == 1)
|
||||||
|
{
|
||||||
printf ("Usage: %s <ra1> <de1> <ra2> <de2>\n", argv[0]);
|
printf ("Usage: %s <ra1> <de1> <ra2> <de2>\n", argv[0]);
|
||||||
printf (" Computes angular offset\n");
|
printf (" Computes angular offset\n");
|
||||||
printf ("Usage: %s -d <ra1> <de1> <dra> <dde>\n", argv[0]);
|
printf ("Usage: %s -d <ra1> <de1> <dra> <dde>\n", argv[0]);
|
||||||
|
@ -30,7 +32,8 @@ int main(int argc,char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(argv[1],"-d")==0) {
|
if (strcmp (argv[1], "-d") == 0)
|
||||||
|
{
|
||||||
if (strchr (argv[2], ':') != NULL)
|
if (strchr (argv[2], ':') != NULL)
|
||||||
ra1 = 15. * s2dec (argv[2]);
|
ra1 = 15. * s2dec (argv[2]);
|
||||||
else
|
else
|
||||||
|
@ -49,7 +52,9 @@ int main(int argc,char *argv[])
|
||||||
dec2s (de2, sde, 0, 6);
|
dec2s (de2, sde, 0, 6);
|
||||||
|
|
||||||
printf ("%s %s\n", sra, sde);
|
printf ("%s %s\n", sra, sde);
|
||||||
} else if (strcmp(argv[1],"-x")==0) {
|
}
|
||||||
|
else if (strcmp (argv[1], "-x") == 0)
|
||||||
|
{
|
||||||
if (strchr (argv[2], ':') != NULL)
|
if (strchr (argv[2], ':') != NULL)
|
||||||
ra1 = 15. * s2dec (argv[2]);
|
ra1 = 15. * s2dec (argv[2]);
|
||||||
else
|
else
|
||||||
|
@ -70,7 +75,9 @@ int main(int argc,char *argv[])
|
||||||
forward (ra1, de1, ra2, de2, &rx, &ry);
|
forward (ra1, de1, ra2, de2, &rx, &ry);
|
||||||
|
|
||||||
printf ("%8.3f\n", rx);
|
printf ("%8.3f\n", rx);
|
||||||
} else if (strcmp(argv[1],"-y")==0) {
|
}
|
||||||
|
else if (strcmp (argv[1], "-y") == 0)
|
||||||
|
{
|
||||||
if (strchr (argv[2], ':') != NULL)
|
if (strchr (argv[2], ':') != NULL)
|
||||||
ra1 = 15. * s2dec (argv[2]);
|
ra1 = 15. * s2dec (argv[2]);
|
||||||
else
|
else
|
||||||
|
@ -91,7 +98,9 @@ int main(int argc,char *argv[])
|
||||||
forward (ra1, de1, ra2, de2, &rx, &ry);
|
forward (ra1, de1, ra2, de2, &rx, &ry);
|
||||||
|
|
||||||
printf ("%8.3f\n", ry);
|
printf ("%8.3f\n", ry);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (strchr (argv[1], ':') != NULL)
|
if (strchr (argv[1], ':') != NULL)
|
||||||
ra1 = 15. * s2dec (argv[1]);
|
ra1 = 15. * s2dec (argv[1]);
|
||||||
else
|
else
|
||||||
|
@ -118,7 +127,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Decimal into Sexagesimal
|
// Convert Decimal into Sexagesimal
|
||||||
void dec2s(double x,char *s,int f,int len)
|
void
|
||||||
|
dec2s (double x, char *s, int f, int len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double sec, deg, min;
|
double sec, deg, min;
|
||||||
|
@ -135,17 +145,28 @@ void dec2s(double x,char *s,int f,int len)
|
||||||
// deg=fmod(x,60.);
|
// deg=fmod(x,60.);
|
||||||
deg = x;
|
deg = x;
|
||||||
|
|
||||||
if (len==7) sprintf(s,"%c%02i%c%02i%c%07.4f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
if (len == 7)
|
||||||
if (len==6) sprintf(s,"%c%02i%c%02i%c%06.3f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
sprintf (s, "%c%02i%c%02i%c%07.4f%c", sign, (int) deg, form[f][0],
|
||||||
if (len==5) sprintf(s,"%c%02i%c%02i%c%05.2f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
if (len==4) sprintf(s,"%c%02i%c%02i%c%04.1f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
if (len == 6)
|
||||||
if (len==2) sprintf(s,"%c%02i%c%02i%c%02i%c",sign,(int) deg,form[f][0],(int) min,form[f][1],(int) floor(sec),form[f][2]);
|
sprintf (s, "%c%02i%c%02i%c%06.3f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 5)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%05.2f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 4)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%04.1f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 2)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%02i%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], (int) floor (sec), form[f][2]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Sexagesimal into Decimal
|
// Convert Sexagesimal into Decimal
|
||||||
double s2dec(char *s)
|
double
|
||||||
|
s2dec (char *s)
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
float deg, min, sec;
|
float deg, min, sec;
|
||||||
|
@ -158,7 +179,8 @@ double s2dec(char *s)
|
||||||
sec = fabs (atof (strtok (NULL, " :")));
|
sec = fabs (atof (strtok (NULL, " :")));
|
||||||
|
|
||||||
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
||||||
if (s[0]=='-') x= -x;
|
if (s[0] == '-')
|
||||||
|
x = -x;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
220
src/calibrate.c
220
src/calibrate.c
|
@ -13,12 +13,14 @@
|
||||||
#define D2R M_PI/180.0
|
#define D2R M_PI/180.0
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
|
|
||||||
struct star {
|
struct star
|
||||||
|
{
|
||||||
double ra, de;
|
double ra, de;
|
||||||
float pmra, pmde;
|
float pmra, pmde;
|
||||||
float mag;
|
float mag;
|
||||||
};
|
};
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int naxis1, naxis2, naxis3;
|
int naxis1, naxis2, naxis3;
|
||||||
float *z;
|
float *z;
|
||||||
float zmin, zmax;
|
float zmin, zmax;
|
||||||
|
@ -27,7 +29,8 @@ struct image {
|
||||||
float a[3], b[3];
|
float a[3], b[3];
|
||||||
double mjd;
|
double mjd;
|
||||||
} img;
|
} img;
|
||||||
struct catalog {
|
struct catalog
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
float x[NMAX], y[NMAX], mag[NMAX];
|
float x[NMAX], y[NMAX], mag[NMAX];
|
||||||
double ra[NMAX], de[NMAX], rx[NMAX], ry[NMAX];
|
double ra[NMAX], de[NMAX], rx[NMAX], ry[NMAX];
|
||||||
|
@ -36,8 +39,10 @@ struct catalog {
|
||||||
struct image read_fits (char *filename, int pnum);
|
struct image read_fits (char *filename, int pnum);
|
||||||
struct catalog read_pixel_catalog (char *filename, float, float, float);
|
struct catalog read_pixel_catalog (char *filename, float, float, float);
|
||||||
int fgetline (FILE * file, char *s, int lim);
|
int fgetline (FILE * file, char *s, int lim);
|
||||||
struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float sy,float angle);
|
struct catalog read_astrometric_catalog (char *filename, float mmin, float sx,
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
float sy, float angle);
|
||||||
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
|
double *y);
|
||||||
int select_nearest (struct catalog c, float x, float y);
|
int select_nearest (struct catalog c, float x, float y);
|
||||||
void lfit2d (float *x, float *y, float *z, int n, float *a);
|
void lfit2d (float *x, float *y, float *z, int n, float *a);
|
||||||
void fit_transformation (struct catalog cat, struct catalog ast, int nselect);
|
void fit_transformation (struct catalog cat, struct catalog ast, int nselect);
|
||||||
|
@ -45,7 +50,8 @@ struct catalog reread_astrometric_catalog(char *filename,float mmin);
|
||||||
int match_catalogs (struct catalog *cat, struct catalog *ast, float rmax);
|
int match_catalogs (struct catalog *cat, struct catalog *ast, float rmax);
|
||||||
double s2dec (char *s);
|
double s2dec (char *s);
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
|
|
||||||
printf ("-f <file> FITS file to calibrate\n");
|
printf ("-f <file> FITS file to calibrate\n");
|
||||||
|
@ -59,7 +65,8 @@ void usage(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
float xmin, xmax, ymin, ymax, zmin, zmax;
|
float xmin, xmax, ymin, ymax, zmin, zmax;
|
||||||
|
@ -74,7 +81,8 @@ int main(int argc,char *argv[])
|
||||||
struct catalog cat, ast;
|
struct catalog cat, ast;
|
||||||
float sx = -10.0, sy = 10.0, q = 0.0;
|
float sx = -10.0, sy = 10.0, q = 0.0;
|
||||||
char *env, starfile[128];
|
char *env, starfile[128];
|
||||||
float r,srmin=1.0,srmax=10.0,smmin=2.0,smmax=8.0,mag=9.0,rmax=10.0,rmask=-1;
|
float r, srmin = 1.0, srmax = 10.0, smmin = 2.0, smmax = 8.0, mag =
|
||||||
|
9.0, rmax = 10.0, rmask = -1;
|
||||||
int arg = 0;
|
int arg = 0;
|
||||||
char *fitsfile = NULL;
|
char *fitsfile = NULL;
|
||||||
char sra[16], sde[16];
|
char sra[16], sde[16];
|
||||||
|
@ -86,9 +94,12 @@ int main(int argc,char *argv[])
|
||||||
sprintf (starfile, "%s/data/tycho2.dat", env);
|
sprintf (starfile, "%s/data/tycho2.dat", env);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
if (argc>1) {
|
if (argc > 1)
|
||||||
while ((arg=getopt(argc,argv,"f:R:D:s:q:m:r:M:"))!=-1) {
|
{
|
||||||
switch(arg) {
|
while ((arg = getopt (argc, argv, "f:R:D:s:q:m:r:M:")) != -1)
|
||||||
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
fitsfile = optarg;
|
fitsfile = optarg;
|
||||||
|
@ -111,9 +122,12 @@ int main(int argc,char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
if (strchr(optarg,',')!=NULL) {
|
if (strchr (optarg, ',') != NULL)
|
||||||
|
{
|
||||||
sscanf (optarg, "%f,%f", &sx, &sy);
|
sscanf (optarg, "%f,%f", &sx, &sy);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sx = -atof (optarg);
|
sx = -atof (optarg);
|
||||||
sy = -sx;
|
sy = -sx;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +159,9 @@ int main(int argc,char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
usage ();
|
usage ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -183,8 +199,10 @@ int main(int argc,char *argv[])
|
||||||
zmax = img.zmax;
|
zmax = img.zmax;
|
||||||
|
|
||||||
// Forever loop
|
// Forever loop
|
||||||
for (;;) {
|
for (;;)
|
||||||
if (redraw==1) {
|
{
|
||||||
|
if (redraw == 1)
|
||||||
|
{
|
||||||
cpgeras ();
|
cpgeras ();
|
||||||
|
|
||||||
cpgsvp (0.1, 0.95, 0.1, 0.95);
|
cpgsvp (0.1, 0.95, 0.1, 0.95);
|
||||||
|
@ -193,13 +211,16 @@ int main(int argc,char *argv[])
|
||||||
cpgsfs (2);
|
cpgsfs (2);
|
||||||
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
||||||
|
|
||||||
cpgimag(img.z,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,zmin,zmax,tr);
|
cpgimag (img.z, img.naxis1, img.naxis2, 1, img.naxis1, 1,
|
||||||
|
img.naxis2, zmin, zmax, tr);
|
||||||
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
||||||
|
|
||||||
// Plot catalog
|
// Plot catalog
|
||||||
if (plotcat==1) {
|
if (plotcat == 1)
|
||||||
|
{
|
||||||
cpgsci (3);
|
cpgsci (3);
|
||||||
for (i=0;i<cat.n;i++) {
|
for (i = 0; i < cat.n; i++)
|
||||||
|
{
|
||||||
if (cat.select[i] != 0)
|
if (cat.select[i] != 0)
|
||||||
cpgpt1 (cat.x[i], cat.y[i], 6);
|
cpgpt1 (cat.x[i], cat.y[i], 6);
|
||||||
else
|
else
|
||||||
|
@ -209,8 +230,11 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
cpgsci (4);
|
cpgsci (4);
|
||||||
for (i=0;i<ast.n;i++) {
|
for (i = 0; i < ast.n; i++)
|
||||||
r=srmax-(srmax-srmin)*(ast.mag[i]-smmin)/(smmax-smmin);
|
{
|
||||||
|
r =
|
||||||
|
srmax - (srmax - srmin) * (ast.mag[i] - smmin) / (smmax -
|
||||||
|
smmin);
|
||||||
|
|
||||||
// Upscale for image size
|
// Upscale for image size
|
||||||
r *= img.naxis1 / 752.0;
|
r *= img.naxis1 / 752.0;
|
||||||
|
@ -230,8 +254,10 @@ int main(int argc,char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Help
|
// Help
|
||||||
if (c=='h') {
|
if (c == 'h')
|
||||||
printf("Calibrates astrometry. Initially requires manual matching of at least three stars. Use 'a' to select star on the image, then 'b' to select star from the catalog (blue circles). If at least three stars are matched, use 'f' and 'm' to converge the calibration.\n\n");
|
{
|
||||||
|
printf
|
||||||
|
("Calibrates astrometry. Initially requires manual matching of at least three stars. Use 'a' to select star on the image, then 'b' to select star from the catalog (blue circles). If at least three stars are matched, use 'f' and 'm' to converge the calibration.\n\n");
|
||||||
printf ("q Quit\n");
|
printf ("q Quit\n");
|
||||||
printf ("a Select star on image\n");
|
printf ("a Select star on image\n");
|
||||||
printf ("b Select star from catalog\n");
|
printf ("b Select star from catalog\n");
|
||||||
|
@ -246,7 +272,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select pixel catalog
|
// Select pixel catalog
|
||||||
if (c=='a' && click==0) {
|
if (c == 'a' && click == 0)
|
||||||
|
{
|
||||||
i = select_nearest (cat, x, y);
|
i = select_nearest (cat, x, y);
|
||||||
cat.select[i] = nselect + 1;
|
cat.select[i] = nselect + 1;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
|
@ -254,7 +281,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select catalog
|
// Select catalog
|
||||||
if (c=='b' && click==1) {
|
if (c == 'b' && click == 1)
|
||||||
|
{
|
||||||
i = select_nearest (ast, x, y);
|
i = select_nearest (ast, x, y);
|
||||||
ast.select[i] = nselect + 1;
|
ast.select[i] = nselect + 1;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
|
@ -263,7 +291,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Center
|
// Center
|
||||||
if (c=='c') {
|
if (c == 'c')
|
||||||
|
{
|
||||||
xmin = x - 0.5 * width;
|
xmin = x - 0.5 * width;
|
||||||
xmax = x + 0.5 * width;
|
xmax = x + 0.5 * width;
|
||||||
ymin = y - 0.5 * width;
|
ymin = y - 0.5 * width;
|
||||||
|
@ -273,14 +302,16 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fit
|
// Fit
|
||||||
if (c=='f' && nselect>=3) {
|
if (c == 'f' && nselect >= 3)
|
||||||
|
{
|
||||||
fit_transformation (cat, ast, nselect);
|
fit_transformation (cat, ast, nselect);
|
||||||
ast = reread_astrometric_catalog (starfile, mag + 1);
|
ast = reread_astrometric_catalog (starfile, mag + 1);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zoom
|
// Zoom
|
||||||
if (c=='z' || c=='+' || c=='=') {
|
if (c == 'z' || c == '+' || c == '=')
|
||||||
|
{
|
||||||
width /= 1.25;
|
width /= 1.25;
|
||||||
xmin = x - 0.5 * width;
|
xmin = x - 0.5 * width;
|
||||||
xmax = x + 0.5 * width;
|
xmax = x + 0.5 * width;
|
||||||
|
@ -291,13 +322,15 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match catalogs
|
// Match catalogs
|
||||||
if (c=='m') {
|
if (c == 'm')
|
||||||
|
{
|
||||||
nselect = match_catalogs (&cat, &ast, rmax);
|
nselect = match_catalogs (&cat, &ast, rmax);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unzoom
|
// Unzoom
|
||||||
if (c=='x' || c=='-') {
|
if (c == 'x' || c == '-')
|
||||||
|
{
|
||||||
width *= 1.25;
|
width *= 1.25;
|
||||||
xmin = x - 0.5 * width;
|
xmin = x - 0.5 * width;
|
||||||
xmax = x + 0.5 * width;
|
xmax = x + 0.5 * width;
|
||||||
|
@ -308,13 +341,15 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plot catalog
|
// Plot catalog
|
||||||
if (c=='p') {
|
if (c == 'p')
|
||||||
|
{
|
||||||
plotcat = (plotcat == 1) ? 0 : 1;
|
plotcat = (plotcat == 1) ? 0 : 1;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
if (c=='r') {
|
if (c == 'r')
|
||||||
|
{
|
||||||
width = (img.naxis1 > img.naxis2) ? img.naxis1 : img.naxis2;
|
width = (img.naxis1 > img.naxis2) ? img.naxis1 : img.naxis2;
|
||||||
xmin = 0.5 * (img.naxis1 - width);
|
xmin = 0.5 * (img.naxis1 - width);
|
||||||
xmax = 0.5 * (img.naxis1 + width);
|
xmax = 0.5 * (img.naxis1 + width);
|
||||||
|
@ -325,12 +360,15 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump
|
// Dump
|
||||||
if (c=='d') {
|
if (c == 'd')
|
||||||
|
{
|
||||||
file = fopen ("dump.dat", "w");
|
file = fopen ("dump.dat", "w");
|
||||||
for (i=0;i<nselect;i++) {
|
for (i = 0; i < nselect; i++)
|
||||||
|
{
|
||||||
for (j = 0; j < cat.n; j++)
|
for (j = 0; j < cat.n; j++)
|
||||||
if (cat.select[j] == i + 1)
|
if (cat.select[j] == i + 1)
|
||||||
fprintf(file,"%lf %lf ",cat.x[j]-img.x0,cat.y[j]-img.y0);
|
fprintf (file, "%lf %lf ", cat.x[j] - img.x0,
|
||||||
|
cat.y[j] - img.y0);
|
||||||
for (j = 0; j < ast.n; j++)
|
for (j = 0; j < ast.n; j++)
|
||||||
if (ast.select[j] == i + 1)
|
if (ast.select[j] == i + 1)
|
||||||
fprintf (file, "%lf %lf\n", ast.ra[j], ast.de[j]);
|
fprintf (file, "%lf %lf\n", ast.ra[j], ast.de[j]);
|
||||||
|
@ -346,7 +384,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename,int pnum)
|
struct image
|
||||||
|
read_fits (char *filename, int pnum)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -381,8 +420,10 @@ struct image read_fits(char *filename,int pnum)
|
||||||
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0,m=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0, m = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
img.z[l] = ql.fbuf[l];
|
img.z[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
|
@ -402,7 +443,8 @@ struct image read_fits(char *filename,int pnum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read pixel catalog
|
// Read pixel catalog
|
||||||
struct catalog read_pixel_catalog(char *filename,float x0,float y0,float rmin)
|
struct catalog
|
||||||
|
read_pixel_catalog (char *filename, float x0, float y0, float rmin)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -412,11 +454,13 @@ struct catalog read_pixel_catalog(char *filename,float x0,float y0,float rmin)
|
||||||
|
|
||||||
// Read catalog
|
// Read catalog
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "%s not found!\n", filename);
|
fprintf (stderr, "%s not found!\n", filename);
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
if (i >= NMAX)
|
if (i >= NMAX)
|
||||||
break;
|
break;
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
|
@ -437,7 +481,8 @@ struct catalog read_pixel_catalog(char *filename,float x0,float y0,float rmin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -449,7 +494,9 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float sy,float angle)
|
struct catalog
|
||||||
|
read_astrometric_catalog (char *filename, float mmin, float sx, float sy,
|
||||||
|
float angle)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -461,18 +508,25 @@ struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float
|
||||||
double mjd0 = 51544.5;
|
double mjd0 = 51544.5;
|
||||||
|
|
||||||
file = fopen (filename, "rb");
|
file = fopen (filename, "rb");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "%s not found!\n", filename);
|
fprintf (stderr, "%s not found!\n", filename);
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fread (&s, sizeof (struct star), 1, file);
|
fread (&s, sizeof (struct star), 1, file);
|
||||||
if (s.mag > mmin)
|
if (s.mag > mmin)
|
||||||
continue;
|
continue;
|
||||||
forward (img.ra0, img.de0, s.ra, s.de, &rx, &ry);
|
forward (img.ra0, img.de0, s.ra, s.de, &rx, &ry);
|
||||||
x=img.x0+1.0/sx*(cos(angle*D2R)*rx+sin(angle*D2R)*ry);
|
x =
|
||||||
y=img.y0+1.0/sy*(-sin(angle*D2R)*rx+cos(angle*D2R)*ry);
|
img.x0 + 1.0 / sx * (cos (angle * D2R) * rx + sin (angle * D2R) * ry);
|
||||||
if (x>0.0 && x<(float) img.naxis1 && y>0.0 && y<(float) img.naxis2) {
|
y =
|
||||||
|
img.y0 + 1.0 / sy * (-sin (angle * D2R) * rx +
|
||||||
|
cos (angle * D2R) * ry);
|
||||||
|
if (x > 0.0 && x < (float) img.naxis1 && y > 0.0
|
||||||
|
&& y < (float) img.naxis2)
|
||||||
|
{
|
||||||
c.x[i] = x;
|
c.x[i] = x;
|
||||||
c.y[i] = y;
|
c.y[i] = y;
|
||||||
c.rx[i] = rx;
|
c.rx[i] = rx;
|
||||||
|
@ -495,14 +549,17 @@ struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float
|
||||||
|
|
||||||
|
|
||||||
// Select nearest object
|
// Select nearest object
|
||||||
int select_nearest(struct catalog c,float x,float y)
|
int
|
||||||
|
select_nearest (struct catalog c, float x, float y)
|
||||||
{
|
{
|
||||||
int i, imin;
|
int i, imin;
|
||||||
float r, rmin;
|
float r, rmin;
|
||||||
|
|
||||||
for (i=0;i<c.n;i++) {
|
for (i = 0; i < c.n; i++)
|
||||||
|
{
|
||||||
r = sqrt (pow (x - c.x[i], 2) + pow (y - c.y[i], 2));
|
r = sqrt (pow (x - c.x[i], 2) + pow (y - c.y[i], 2));
|
||||||
if (i==0 || r<rmin) {
|
if (i == 0 || r < rmin)
|
||||||
|
{
|
||||||
imin = i;
|
imin = i;
|
||||||
rmin = r;
|
rmin = r;
|
||||||
}
|
}
|
||||||
|
@ -512,7 +569,8 @@ int select_nearest(struct catalog c,float x,float y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fit transformation
|
// Fit transformation
|
||||||
void fit_transformation(struct catalog cat,struct catalog ast,int nselect)
|
void
|
||||||
|
fit_transformation (struct catalog cat, struct catalog ast, int nselect)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
float *x, *y, *rx, *ry;
|
float *x, *y, *rx, *ry;
|
||||||
|
@ -522,15 +580,20 @@ void fit_transformation(struct catalog cat,struct catalog ast,int nselect)
|
||||||
rx = (float *) malloc (sizeof (float) * nselect);
|
rx = (float *) malloc (sizeof (float) * nselect);
|
||||||
ry = (float *) malloc (sizeof (float) * nselect);
|
ry = (float *) malloc (sizeof (float) * nselect);
|
||||||
|
|
||||||
for (i=0;i<nselect;i++) {
|
for (i = 0; i < nselect; i++)
|
||||||
for (j=0;j<cat.n;j++) {
|
{
|
||||||
if (cat.select[j]==i+1) {
|
for (j = 0; j < cat.n; j++)
|
||||||
|
{
|
||||||
|
if (cat.select[j] == i + 1)
|
||||||
|
{
|
||||||
x[i] = cat.x[j] - img.x0;
|
x[i] = cat.x[j] - img.x0;
|
||||||
y[i] = cat.y[j] - img.y0;
|
y[i] = cat.y[j] - img.y0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (j=0;j<ast.n;j++) {
|
for (j = 0; j < ast.n; j++)
|
||||||
if (ast.select[j]==i+1) {
|
{
|
||||||
|
if (ast.select[j] == i + 1)
|
||||||
|
{
|
||||||
rx[i] = ast.rx[j];
|
rx[i] = ast.rx[j];
|
||||||
ry[i] = ast.ry[j];
|
ry[i] = ast.ry[j];
|
||||||
}
|
}
|
||||||
|
@ -544,7 +607,8 @@ void fit_transformation(struct catalog cat,struct catalog ast,int nselect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linear 2D fit
|
// Linear 2D fit
|
||||||
void lfit2d(float *x,float *y,float *z,int n,float *a)
|
void
|
||||||
|
lfit2d (float *x, float *y, float *z, int n, float *a)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double chisq;
|
double chisq;
|
||||||
|
@ -559,7 +623,8 @@ void lfit2d(float *x,float *y,float *z,int n,float *a)
|
||||||
cov = gsl_matrix_alloc (3, 3);
|
cov = gsl_matrix_alloc (3, 3);
|
||||||
|
|
||||||
// Fill matrices
|
// Fill matrices
|
||||||
for(i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
gsl_matrix_set (X, i, 0, 1.0);
|
gsl_matrix_set (X, i, 0, 1.0);
|
||||||
gsl_matrix_set (X, i, 1, x[i]);
|
gsl_matrix_set (X, i, 1, x[i]);
|
||||||
gsl_matrix_set (X, i, 2, y[i]);
|
gsl_matrix_set (X, i, 2, y[i]);
|
||||||
|
@ -587,7 +652,8 @@ void lfit2d(float *x,float *y,float *z,int n,float *a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read astrometric catalog
|
// Read astrometric catalog
|
||||||
struct catalog reread_astrometric_catalog(char *filename,float mmin)
|
struct catalog
|
||||||
|
reread_astrometric_catalog (char *filename, float mmin)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -599,7 +665,8 @@ struct catalog reread_astrometric_catalog(char *filename,float mmin)
|
||||||
double mjd0 = 51544.5;
|
double mjd0 = 51544.5;
|
||||||
|
|
||||||
file = fopen (filename, "rb");
|
file = fopen (filename, "rb");
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fread (&s, sizeof (struct star), 1, file);
|
fread (&s, sizeof (struct star), 1, file);
|
||||||
if (s.mag > mmin)
|
if (s.mag > mmin)
|
||||||
continue;
|
continue;
|
||||||
|
@ -609,7 +676,8 @@ struct catalog reread_astrometric_catalog(char *filename,float mmin)
|
||||||
d = img.a[1] * img.b[2] - img.a[2] * img.b[1];
|
d = img.a[1] * img.b[2] - img.a[2] * img.b[1];
|
||||||
x = (img.b[2] * dx - img.a[2] * dy) / d + img.x0;
|
x = (img.b[2] * dx - img.a[2] * dy) / d + img.x0;
|
||||||
y = (img.a[1] * dy - img.b[1] * dx) / d + img.y0;
|
y = (img.a[1] * dy - img.b[1] * dx) / d + img.y0;
|
||||||
if (x>0.0 && x<img.naxis1 && y>0.0 && y<img.naxis2) {
|
if (x > 0.0 && x < img.naxis1 && y > 0.0 && y < img.naxis2)
|
||||||
|
{
|
||||||
c.x[i] = x;
|
c.x[i] = x;
|
||||||
c.y[i] = y;
|
c.y[i] = y;
|
||||||
c.rx[i] = rx;
|
c.rx[i] = rx;
|
||||||
|
@ -627,7 +695,8 @@ struct catalog reread_astrometric_catalog(char *filename,float mmin)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int match_catalogs(struct catalog *cat,struct catalog *ast,float rmax)
|
int
|
||||||
|
match_catalogs (struct catalog *cat, struct catalog *ast, float rmax)
|
||||||
{
|
{
|
||||||
int i, j, jmin, n, flag = 0;
|
int i, j, jmin, n, flag = 0;
|
||||||
float r, rmin;
|
float r, rmin;
|
||||||
|
@ -640,19 +709,26 @@ int match_catalogs(struct catalog *cat,struct catalog *ast,float rmax)
|
||||||
ast->select[i] = 0;
|
ast->select[i] = 0;
|
||||||
|
|
||||||
file = fopen ("out.dat", "w");
|
file = fopen ("out.dat", "w");
|
||||||
for (i=0,n=0;i<cat->n;i++) {
|
for (i = 0, n = 0; i < cat->n; i++)
|
||||||
for (j=0,flag=0;j<ast->n;j++) {
|
{
|
||||||
|
for (j = 0, flag = 0; j < ast->n; j++)
|
||||||
|
{
|
||||||
if (ast->select[j] != 0)
|
if (ast->select[j] != 0)
|
||||||
continue;
|
continue;
|
||||||
r=sqrt(pow(cat->x[i]-ast->x[j],2)+pow(cat->y[i]-ast->y[j],2));
|
r =
|
||||||
if (flag==0 || r<rmin) {
|
sqrt (pow (cat->x[i] - ast->x[j], 2) +
|
||||||
|
pow (cat->y[i] - ast->y[j], 2));
|
||||||
|
if (flag == 0 || r < rmin)
|
||||||
|
{
|
||||||
rmin = r;
|
rmin = r;
|
||||||
jmin = j;
|
jmin = j;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rmin<rmax) {
|
if (rmin < rmax)
|
||||||
fprintf(file,"%10.4f %10.4f %10.6f %10.6f\n",cat->x[i]-img.x0,cat->y[i]-img.y0,ast->ra[jmin],ast->de[jmin]);
|
{
|
||||||
|
fprintf (file, "%10.4f %10.4f %10.6f %10.6f\n", cat->x[i] - img.x0,
|
||||||
|
cat->y[i] - img.y0, ast->ra[jmin], ast->de[jmin]);
|
||||||
cat->select[i] = n + 1;
|
cat->select[i] = n + 1;
|
||||||
ast->select[jmin] = n + 1;
|
ast->select[jmin] = n + 1;
|
||||||
n++;
|
n++;
|
||||||
|
@ -665,7 +741,8 @@ int match_catalogs(struct catalog *cat,struct catalog *ast,float rmax)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Sexagesimal into Decimal
|
// Convert Sexagesimal into Decimal
|
||||||
double s2dec(char *s)
|
double
|
||||||
|
s2dec (char *s)
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
float deg, min, sec;
|
float deg, min, sec;
|
||||||
|
@ -678,7 +755,8 @@ double s2dec(char *s)
|
||||||
sec = fabs (atof (strtok (NULL, " :")));
|
sec = fabs (atof (strtok (NULL, " :")));
|
||||||
|
|
||||||
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
||||||
if (s[0]=='-') x= -x;
|
if (s[0] == '-')
|
||||||
|
x = -x;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
326
src/confirm.c
326
src/confirm.c
|
@ -13,7 +13,8 @@
|
||||||
#define D2R M_PI/180.0
|
#define D2R M_PI/180.0
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
|
|
||||||
struct fourframe {
|
struct fourframe
|
||||||
|
{
|
||||||
char filename[64];
|
char filename[64];
|
||||||
int naxis1, naxis2, naxis3, nframes;
|
int naxis1, naxis2, naxis3, nframes;
|
||||||
float *zavg, *zstd, *zmax, *znum, *ztrk, *zsig;
|
float *zavg, *zstd, *zmax, *znum, *ztrk, *zsig;
|
||||||
|
@ -26,7 +27,8 @@ struct fourframe {
|
||||||
char nfd[32];
|
char nfd[32];
|
||||||
int cospar;
|
int cospar;
|
||||||
};
|
};
|
||||||
struct observation {
|
struct observation
|
||||||
|
{
|
||||||
int satno, cospar;
|
int satno, cospar;
|
||||||
char desig[16], conditions, behavior, catalog[32], comment[LIM];
|
char desig[16], conditions, behavior, catalog[32], comment[LIM];
|
||||||
double mjd, ra, de;
|
double mjd, ra, de;
|
||||||
|
@ -43,11 +45,14 @@ struct point
|
||||||
int flag;
|
int flag;
|
||||||
};
|
};
|
||||||
struct fourframe read_fits (char *filename);
|
struct fourframe read_fits (char *filename);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de);
|
double *y);
|
||||||
|
void reverse (double ra0, double de0, double x, double y, double *ra,
|
||||||
|
double *de);
|
||||||
|
|
||||||
// Linear least squares fit
|
// Linear least squares fit
|
||||||
float linear_fit(float x[],float y[],float w[],int n,float a[],float sa[])
|
float
|
||||||
|
linear_fit (float x[], float y[], float w[], int n, float a[], float sa[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float sum, sumx, sumy, sumxx, sumxy;
|
float sum, sumx, sumy, sumxx, sumxy;
|
||||||
|
@ -55,7 +60,8 @@ float linear_fit(float x[],float y[],float w[],int n,float a[],float sa[])
|
||||||
|
|
||||||
// Compute sums
|
// Compute sums
|
||||||
sum = sumx = sumy = sumxx = sumxy = 0.;
|
sum = sumx = sumy = sumxx = sumxy = 0.;
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
sum += w[i];
|
sum += w[i];
|
||||||
sumx += x[i] * w[i];
|
sumx += x[i] * w[i];
|
||||||
sumy += y[i] * w[i];
|
sumy += y[i] * w[i];
|
||||||
|
@ -86,12 +92,14 @@ float linear_fit(float x[],float y[],float w[],int n,float a[],float sa[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -99,23 +107,30 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min;
|
int year, month, day, hour, min;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
float sec;
|
float sec;
|
||||||
|
|
||||||
sscanf(date,"'%04d-%02d-%02dT%02d:%02d:%f'",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "'%04d-%02d-%02dT%02d:%02d:%f'", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
|
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -124,7 +139,8 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date)
|
void
|
||||||
|
mjd2date (double mjd, char *date)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -139,7 +155,8 @@ void mjd2date(double mjd,char *date)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -168,13 +185,15 @@ void mjd2date(double mjd,char *date)
|
||||||
x = (x - min) / 60.;
|
x = (x - min) / 60.;
|
||||||
hour = x;
|
hour = x;
|
||||||
fsec = 1000.0 * (sec - floor (sec));
|
fsec = 1000.0 * (sec - floor (sec));
|
||||||
sprintf(date,"%04d%02d%02d%02d%02d%02.0f%03.0f",(int) year,(int) month,(int) day,(int) hour,(int) min,floor(sec),fsec);
|
sprintf (date, "%04d%02d%02d%02d%02d%02.0f%03.0f", (int) year, (int) month,
|
||||||
|
(int) day, (int) hour, (int) min, floor (sec), fsec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
int day;
|
int day;
|
||||||
|
@ -190,7 +209,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -198,7 +218,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Decimal into Sexagesimal
|
// Convert Decimal into Sexagesimal
|
||||||
void dec2s(double x,char *s,int type)
|
void
|
||||||
|
dec2s (double x, char *s, int type)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double sec, deg, min, fmin;
|
double sec, deg, min, fmin;
|
||||||
|
@ -225,7 +246,9 @@ void dec2s(double x,char *s,int type)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce point
|
// Reduce point
|
||||||
void reduce_point(struct observation *obs,struct fourframe img,float tmid,float x,float y)
|
void
|
||||||
|
reduce_point (struct observation *obs, struct fourframe img, float tmid,
|
||||||
|
float x, float y)
|
||||||
{
|
{
|
||||||
int iframe, k;
|
int iframe, k;
|
||||||
double ra, de, rx, ry;
|
double ra, de, rx, ry;
|
||||||
|
@ -260,7 +283,9 @@ void reduce_point(struct observation *obs,struct fourframe img,float tmid,float
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int flag)
|
void
|
||||||
|
fit (struct observation *obs, struct fourframe ff, struct point *p, int np,
|
||||||
|
int flag)
|
||||||
{
|
{
|
||||||
int i, j, k, l, n, m;
|
int i, j, k, l, n, m;
|
||||||
float *t, *dt, *x, *y, *w;
|
float *t, *dt, *x, *y, *w;
|
||||||
|
@ -281,8 +306,10 @@ void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int
|
||||||
w = (float *) malloc (sizeof (float) * n);
|
w = (float *) malloc (sizeof (float) * n);
|
||||||
|
|
||||||
// Fill
|
// Fill
|
||||||
for (i=0,l=0;i<np;i++) {
|
for (i = 0, l = 0; i < np; i++)
|
||||||
if (p[i].flag==flag) {
|
{
|
||||||
|
if (p[i].flag == flag)
|
||||||
|
{
|
||||||
x[l] = p[i].x;
|
x[l] = p[i].x;
|
||||||
y[l] = p[i].y;
|
y[l] = p[i].y;
|
||||||
w[l] = 1.0;
|
w[l] = 1.0;
|
||||||
|
@ -292,13 +319,19 @@ void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find limits in time
|
// Find limits in time
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
if (i==0) {
|
{
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
tmin = t[i];
|
tmin = t[i];
|
||||||
tmax = t[i];
|
tmax = t[i];
|
||||||
} else {
|
}
|
||||||
if (t[i]<tmin) tmin=t[i];
|
else
|
||||||
if (t[i]>tmax) tmax=t[i];
|
{
|
||||||
|
if (t[i] < tmin)
|
||||||
|
tmin = t[i];
|
||||||
|
if (t[i] > tmax)
|
||||||
|
tmax = t[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmid = 0.5 * (tmin + tmax);
|
tmid = 0.5 * (tmin + tmax);
|
||||||
|
@ -314,7 +347,8 @@ void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int
|
||||||
chi2y = linear_fit (dt, y, w, n, ay, say);
|
chi2y = linear_fit (dt, y, w, n, ay, say);
|
||||||
|
|
||||||
// Compute rms
|
// Compute rms
|
||||||
for (i=0,rmsx=0.0,rmsy=0.0;i<n;i++) {
|
for (i = 0, rmsx = 0.0, rmsy = 0.0; i < n; i++)
|
||||||
|
{
|
||||||
rmsx += pow (x[i] - (ax[0] + ax[1] * dt[i]), 2);
|
rmsx += pow (x[i] - (ax[0] + ax[1] * dt[i]), 2);
|
||||||
rmsy += pow (y[i] - (ay[0] + ay[1] * dt[i]), 2);
|
rmsy += pow (y[i] - (ay[0] + ay[1] * dt[i]), 2);
|
||||||
}
|
}
|
||||||
|
@ -347,7 +381,8 @@ void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void format_iod_line(struct observation *obs)
|
void
|
||||||
|
format_iod_line (struct observation *obs)
|
||||||
{
|
{
|
||||||
int mt, xt, mp, xp;
|
int mt, xt, mp, xp;
|
||||||
char string[10];
|
char string[10];
|
||||||
|
@ -358,32 +393,29 @@ void format_iod_line(struct observation *obs)
|
||||||
xt = atoi (string + 4) + 8;
|
xt = atoi (string + 4) + 8;
|
||||||
|
|
||||||
// Position format
|
// Position format
|
||||||
if (obs->type==2) {
|
if (obs->type == 2)
|
||||||
|
{
|
||||||
sprintf (string, "%7.1e", obs->perr);
|
sprintf (string, "%7.1e", obs->perr);
|
||||||
mp = string[0] - '0';
|
mp = string[0] - '0';
|
||||||
xp = atoi (string + 4) + 8;
|
xp = atoi (string + 4) + 8;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("Position format not implemented!\n");
|
printf ("Position format not implemented!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(obs->iod_line,"%05d %c%c %-6s %04d %c %-17s %d%d %d%d %-14s %d%d %c",
|
sprintf (obs->iod_line,
|
||||||
obs->satno,
|
"%05d %c%c %-6s %04d %c %-17s %d%d %d%d %-14s %d%d %c", obs->satno,
|
||||||
obs->desig[0],obs->desig[1],
|
obs->desig[0], obs->desig[1], obs->desig + 2, obs->cospar,
|
||||||
obs->desig+2,
|
obs->conditions, obs->nfd, mt, xt, obs->type, obs->epoch, obs->pos,
|
||||||
obs->cospar,
|
mp, xp, obs->behavior);
|
||||||
obs->conditions,
|
|
||||||
obs->nfd,
|
|
||||||
mt,xt,
|
|
||||||
obs->type,obs->epoch,
|
|
||||||
obs->pos,
|
|
||||||
mp,xp,
|
|
||||||
obs->behavior);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -397,7 +429,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void find_designation(int satno0,char *desig0)
|
void
|
||||||
|
find_designation (int satno0, char *desig0)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
int satno;
|
int satno;
|
||||||
|
@ -409,13 +442,16 @@ void find_designation(int satno0,char *desig0)
|
||||||
sprintf (filename, "%s/data/desig.txt", env);
|
sprintf (filename, "%s/data/desig.txt", env);
|
||||||
|
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Designation file not found!\n");
|
fprintf (stderr, "Designation file not found!\n");
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fscanf (file, "%d %s", &satno, desig);
|
fscanf (file, "%d %s", &satno, desig);
|
||||||
if (satno==satno0) {
|
if (satno == satno0)
|
||||||
|
{
|
||||||
strcpy (desig0, desig);
|
strcpy (desig0, desig);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -425,7 +461,9 @@ void find_designation(int satno0,char *desig0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void identify_observation(struct observation *obs,char *fileroot,float drmin,float amin)
|
void
|
||||||
|
identify_observation (struct observation *obs, char *fileroot, float drmin,
|
||||||
|
float amin)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
float x0, y0, x1, y1, x, y, texp;
|
float x0, y0, x1, y1, x, y, texp;
|
||||||
|
@ -437,12 +475,15 @@ void identify_observation(struct observation *obs,char *fileroot,float drmin,flo
|
||||||
// Open ID file
|
// Open ID file
|
||||||
sprintf (filename, "%s.id", fileroot);
|
sprintf (filename, "%s.id", fileroot);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "ID file %s not found\n", filename);
|
fprintf (stderr, "ID file %s not found\n", filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
sscanf(line,"%s %f %f %f %f %f %d %s",nfd,&x0,&y0,&x1,&y1,&texp,&satno,catalog);
|
{
|
||||||
|
sscanf (line, "%s %f %f %f %f %f %d %s", nfd, &x0, &y0, &x1, &y1, &texp,
|
||||||
|
&satno, catalog);
|
||||||
|
|
||||||
// Predicted pixel rates
|
// Predicted pixel rates
|
||||||
dxdt = (x1 - x0) / texp;
|
dxdt = (x1 - x0) / texp;
|
||||||
|
@ -462,7 +503,8 @@ void identify_observation(struct observation *obs,char *fileroot,float drmin,flo
|
||||||
angle = 0.0;
|
angle = 0.0;
|
||||||
|
|
||||||
// Identify
|
// Identify
|
||||||
if (dr<drmin && angle<amin) {
|
if (dr < drmin && angle < amin)
|
||||||
|
{
|
||||||
obs->satno = satno;
|
obs->satno = satno;
|
||||||
if (strstr (catalog, "classfd.tle") != NULL)
|
if (strstr (catalog, "classfd.tle") != NULL)
|
||||||
strcpy (obs->catalog, "classfd");
|
strcpy (obs->catalog, "classfd");
|
||||||
|
@ -477,7 +519,8 @@ void identify_observation(struct observation *obs,char *fileroot,float drmin,flo
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_observation(struct observation obs)
|
void
|
||||||
|
write_observation (struct observation obs)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char filename[LIM];
|
char filename[LIM];
|
||||||
|
@ -491,7 +534,8 @@ void write_observation(struct observation obs)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void overlay_predictions(char *fitsfile,struct fourframe ff)
|
void
|
||||||
|
overlay_predictions (char *fitsfile, struct fourframe ff)
|
||||||
{
|
{
|
||||||
float x0, y0, x1, y1, texp;
|
float x0, y0, x1, y1, texp;
|
||||||
int satno, isch;
|
int satno, isch;
|
||||||
|
@ -505,12 +549,15 @@ void overlay_predictions(char *fitsfile,struct fourframe ff)
|
||||||
|
|
||||||
// Open ID file
|
// Open ID file
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "ID file %s not found\n", filename);
|
fprintf (stderr, "ID file %s not found\n", filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
sscanf(line,"%s %f %f %f %f %f %d %s",nfd,&x0,&y0,&x1,&y1,&texp,&satno,catalog);
|
{
|
||||||
|
sscanf (line, "%s %f %f %f %f %f %d %s", nfd, &x0, &y0, &x1, &y1, &texp,
|
||||||
|
&satno, catalog);
|
||||||
|
|
||||||
if (strstr (catalog, "classfd") != NULL)
|
if (strstr (catalog, "classfd") != NULL)
|
||||||
cpgsci (4);
|
cpgsci (4);
|
||||||
|
@ -528,10 +575,12 @@ void overlay_predictions(char *fitsfile,struct fourframe ff)
|
||||||
// plot text
|
// plot text
|
||||||
cpgsch (0.65);
|
cpgsch (0.65);
|
||||||
sprintf (text, " %05d", satno);
|
sprintf (text, " %05d", satno);
|
||||||
for (t=0.0;t<1.0;t+=0.1) {
|
for (t = 0.0; t < 1.0; t += 0.1)
|
||||||
|
{
|
||||||
x = x0 + (x1 - x0) * t;
|
x = x0 + (x1 - x0) * t;
|
||||||
y = y0 + (y1 - y0) * t;
|
y = y0 + (y1 - y0) * t;
|
||||||
if (x>0.0 && y>0.0 && x<ff.naxis1 && y<ff.naxis2) {
|
if (x > 0.0 && y > 0.0 && x < ff.naxis1 && y < ff.naxis2)
|
||||||
|
{
|
||||||
cpgtext (x, y, text);
|
cpgtext (x, y, text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -546,7 +595,9 @@ void overlay_predictions(char *fitsfile,struct fourframe ff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void accumulate(float *z,int nx,int ny,int nz,int *mask,int bx,int by,int bz,int nsel,int *zsel)
|
void
|
||||||
|
accumulate (float *z, int nx, int ny, int nz, int *mask, int bx, int by,
|
||||||
|
int bz, int nsel, int *zsel)
|
||||||
{
|
{
|
||||||
int ix, iy, iz;
|
int ix, iy, iz;
|
||||||
int jx, jy, jz, k;
|
int jx, jy, jz, k;
|
||||||
|
@ -564,8 +615,10 @@ void accumulate(float *z,int nx,int ny,int nz,int *mask,int bx,int by,int bz,int
|
||||||
c[ix] = 0;
|
c[ix] = 0;
|
||||||
|
|
||||||
// Accumulate
|
// Accumulate
|
||||||
for (ix=0;ix<nx;ix++) {
|
for (ix = 0; ix < nx; ix++)
|
||||||
for (iy=0;iy<ny;iy++) {
|
{
|
||||||
|
for (iy = 0; iy < ny; iy++)
|
||||||
|
{
|
||||||
iz = (int) z[ix + nx * iy];
|
iz = (int) z[ix + nx * iy];
|
||||||
jx = ix / bx;
|
jx = ix / bx;
|
||||||
jy = iy / by;
|
jy = iy / by;
|
||||||
|
@ -577,8 +630,10 @@ void accumulate(float *z,int nx,int ny,int nz,int *mask,int bx,int by,int bz,int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply mask
|
// Apply mask
|
||||||
for (ix=0;ix<nx;ix++) {
|
for (ix = 0; ix < nx; ix++)
|
||||||
for (iy=0;iy<ny;iy++) {
|
{
|
||||||
|
for (iy = 0; iy < ny; iy++)
|
||||||
|
{
|
||||||
iz = (int) z[ix + nx * iy];
|
iz = (int) z[ix + nx * iy];
|
||||||
jx = ix / bx;
|
jx = ix / bx;
|
||||||
jy = iy / by;
|
jy = iy / by;
|
||||||
|
@ -594,7 +649,8 @@ void accumulate(float *z,int nx,int ny,int nz,int *mask,int bx,int by,int bz,int
|
||||||
}
|
}
|
||||||
|
|
||||||
// RANSAC line finding
|
// RANSAC line finding
|
||||||
void ransac(struct point *p,int np,float drmin)
|
void
|
||||||
|
ransac (struct point *p, int np, float drmin)
|
||||||
{
|
{
|
||||||
int i = 0, j, k, l, m, n, mmax;
|
int i = 0, j, k, l, m, n, mmax;
|
||||||
const gsl_rng_type *T;
|
const gsl_rng_type *T;
|
||||||
|
@ -610,16 +666,20 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
r = gsl_rng_alloc (T);
|
r = gsl_rng_alloc (T);
|
||||||
|
|
||||||
// Loop over number of lines
|
// Loop over number of lines
|
||||||
for (i=1;i<=4;i++) {
|
for (i = 1; i <= 4; i++)
|
||||||
|
{
|
||||||
// Number of iterations
|
// Number of iterations
|
||||||
for (l=0,mmax=0;l<10000;l++) {
|
for (l = 0, mmax = 0; l < 10000; l++)
|
||||||
|
{
|
||||||
// Get random end points
|
// Get random end points
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
i0 = (int) (np * gsl_rng_uniform (r));
|
i0 = (int) (np * gsl_rng_uniform (r));
|
||||||
if (p[i0].flag == 0)
|
if (p[i0].flag == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
i1 = (int) (np * gsl_rng_uniform (r));
|
i1 = (int) (np * gsl_rng_uniform (r));
|
||||||
if (p[i1].flag == 0)
|
if (p[i1].flag == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -632,7 +692,8 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
by = p[i0].y - ay * p[i0].t;
|
by = p[i0].y - ay * p[i0].t;
|
||||||
|
|
||||||
// Find matches
|
// Find matches
|
||||||
for (k=0,m=0;k<np;k++) {
|
for (k = 0, m = 0; k < np; k++)
|
||||||
|
{
|
||||||
dx = bx + ax * p[k].t - p[k].x;
|
dx = bx + ax * p[k].t - p[k].x;
|
||||||
dy = by + ay * p[k].t - p[k].y;
|
dy = by + ay * p[k].t - p[k].y;
|
||||||
dr = sqrt (dx * dx + dy * dy);
|
dr = sqrt (dx * dx + dy * dy);
|
||||||
|
@ -641,7 +702,8 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store
|
// Store
|
||||||
if (m>mmax) {
|
if (m > mmax)
|
||||||
|
{
|
||||||
mmax = m;
|
mmax = m;
|
||||||
i0max = i0;
|
i0max = i0;
|
||||||
i1max = i1;
|
i1max = i1;
|
||||||
|
@ -655,7 +717,8 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
by = p[i0max].y - ay * p[i0max].t;
|
by = p[i0max].y - ay * p[i0max].t;
|
||||||
|
|
||||||
// Find matches
|
// Find matches
|
||||||
for (k=0;k<np;k++) {
|
for (k = 0; k < np; k++)
|
||||||
|
{
|
||||||
dx = bx + ax * p[k].t - p[k].x;
|
dx = bx + ax * p[k].t - p[k].x;
|
||||||
dy = by + ay * p[k].t - p[k].y;
|
dy = by + ay * p[k].t - p[k].y;
|
||||||
dr = sqrt (dx * dx + dy * dy);
|
dr = sqrt (dx * dx + dy * dy);
|
||||||
|
@ -674,7 +737,8 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, k, l, m, n, flag = 0, np, nline;
|
int i, j, k, l, m, n, flag = 0, np, nline;
|
||||||
struct fourframe ff;
|
struct fourframe ff;
|
||||||
|
@ -702,9 +766,12 @@ int main(int argc,char *argv[])
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
if (argc>1) {
|
if (argc > 1)
|
||||||
while ((arg=getopt(argc,argv,"f:s:R:r:a:pn:"))!=-1) {
|
{
|
||||||
switch(arg) {
|
while ((arg = getopt (argc, argv, "f:s:R:r:a:pn:")) != -1)
|
||||||
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
fitsfile = optarg;
|
fitsfile = optarg;
|
||||||
|
@ -735,7 +802,9 @@ int main(int argc,char *argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,9 +820,12 @@ int main(int argc,char *argv[])
|
||||||
ff = read_fits (fitsfile);
|
ff = read_fits (fitsfile);
|
||||||
|
|
||||||
// Fill mask
|
// Fill mask
|
||||||
if (ff.naxis1==720 && ff.naxis2==576) {
|
if (ff.naxis1 == 720 && ff.naxis2 == 576)
|
||||||
for (i=0;i<ff.naxis1;i++) {
|
{
|
||||||
for (j=0;j<ff.naxis2;j++) {
|
for (i = 0; i < ff.naxis1; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < ff.naxis2; j++)
|
||||||
|
{
|
||||||
k = i + ff.naxis1 * j;
|
k = i + ff.naxis1 * j;
|
||||||
if (i < 10 || i > ff.naxis1 - 10 || j > ff.naxis2 - 10)
|
if (i < 10 || i > ff.naxis1 - 10 || j > ff.naxis2 - 10)
|
||||||
ff.mask[k] = 0;
|
ff.mask[k] = 0;
|
||||||
|
@ -767,12 +839,17 @@ int main(int argc,char *argv[])
|
||||||
zsel[i] = 0;
|
zsel[i] = 0;
|
||||||
|
|
||||||
// Accumulate
|
// Accumulate
|
||||||
if (ff.nframes==250) {
|
if (ff.nframes == 250)
|
||||||
|
{
|
||||||
// accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,2,2,10,2,zsel);
|
// accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,2,2,10,2,zsel);
|
||||||
accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,4,4,10,8,zsel);
|
accumulate (ff.znum, ff.naxis1, ff.naxis2, ff.nframes, ff.mask, 4, 4,
|
||||||
} else if (ff.nframes==256) {
|
10, 8, zsel);
|
||||||
|
}
|
||||||
|
else if (ff.nframes == 256)
|
||||||
|
{
|
||||||
// accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,2,2,8,2,zsel);
|
// accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,2,2,8,2,zsel);
|
||||||
accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,4,4,16,6,zsel);
|
accumulate (ff.znum, ff.naxis1, ff.naxis2, ff.nframes, ff.mask, 4, 4,
|
||||||
|
16, 6, zsel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply mask
|
// Apply mask
|
||||||
|
@ -787,9 +864,15 @@ int main(int argc,char *argv[])
|
||||||
cpgsch (0.8);
|
cpgsch (0.8);
|
||||||
sprintf (text, "UT Date: %.23s COSPAR ID: %04d", ff.nfd + 1, ff.cospar);
|
sprintf (text, "UT Date: %.23s COSPAR ID: %04d", ff.nfd + 1, ff.cospar);
|
||||||
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
||||||
sprintf(text,"R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')",ff.ra0,ff.xrms,ff.de0,ff.yrms);
|
sprintf (text, "R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')", ff.ra0,
|
||||||
|
ff.xrms, ff.de0, ff.yrms);
|
||||||
cpgmtxt ("T", 4.8, 0.0, 0.0, text);
|
cpgmtxt ("T", 4.8, 0.0, 0.0, text);
|
||||||
sprintf(text,"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d",ff.naxis1*sqrt(ff.a[1]*ff.a[1]+ff.b[1]*ff.b[1])/3600.0,ff.naxis2*sqrt(ff.a[2]*ff.a[2]+ff.b[2]*ff.b[2])/3600.0,sqrt(ff.a[1]*ff.a[1]+ff.b[1]*ff.b[1]),sqrt(ff.a[2]*ff.a[2]+ff.b[2]*ff.b[2]));
|
sprintf (text,
|
||||||
|
"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d",
|
||||||
|
ff.naxis1 * sqrt (ff.a[1] * ff.a[1] + ff.b[1] * ff.b[1]) / 3600.0,
|
||||||
|
ff.naxis2 * sqrt (ff.a[2] * ff.a[2] + ff.b[2] * ff.b[2]) / 3600.0,
|
||||||
|
sqrt (ff.a[1] * ff.a[1] + ff.b[1] * ff.b[1]),
|
||||||
|
sqrt (ff.a[2] * ff.a[2] + ff.b[2] * ff.b[2]));
|
||||||
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
||||||
|
|
||||||
cpgsch (1.0);
|
cpgsch (1.0);
|
||||||
|
@ -798,7 +881,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
zmin = 0.0;
|
zmin = 0.0;
|
||||||
zmax = 150.0;
|
zmax = 150.0;
|
||||||
cpgimag(ff.zmax,ff.naxis1,ff.naxis2,1,ff.naxis1,1,ff.naxis2,zmin,zmax,tr);
|
cpgimag (ff.zmax, ff.naxis1, ff.naxis2, 1, ff.naxis1, 1, ff.naxis2, zmin,
|
||||||
|
zmax, tr);
|
||||||
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
||||||
cpgstbg (1);
|
cpgstbg (1);
|
||||||
overlay_predictions (fitsfile, ff);
|
overlay_predictions (fitsfile, ff);
|
||||||
|
@ -806,21 +890,27 @@ int main(int argc,char *argv[])
|
||||||
// Open measurements file
|
// Open measurements file
|
||||||
sprintf (filename, "%s.det", fitsfile);
|
sprintf (filename, "%s.det", fitsfile);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file!=NULL) {
|
if (file != NULL)
|
||||||
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
if (i%4==1) {
|
{
|
||||||
sscanf(line,"# %f %f %f %f %f %f %f %f %f",&x[0],&y[0],&t[0],&x[1],&y[1],&t[1],&x[2],&y[2],&t[2]);
|
if (i % 4 == 1)
|
||||||
|
{
|
||||||
|
sscanf (line, "# %f %f %f %f %f %f %f %f %f", &x[0], &y[0],
|
||||||
|
&t[0], &x[1], &y[1], &t[1], &x[2], &y[2], &t[2]);
|
||||||
cpgsci (5);
|
cpgsci (5);
|
||||||
cpgpt1 (x[0], y[0], 4);
|
cpgpt1 (x[0], y[0], 4);
|
||||||
cpgmove (x[1], y[1]);
|
cpgmove (x[1], y[1]);
|
||||||
cpgdraw (x[2], y[2]);
|
cpgdraw (x[2], y[2]);
|
||||||
}
|
}
|
||||||
if (i%4==2) {
|
if (i % 4 == 2)
|
||||||
|
{
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
sprintf (catalog, "%s.dat", line + 2);
|
sprintf (catalog, "%s.dat", line + 2);
|
||||||
}
|
}
|
||||||
if (i%4==3) {
|
if (i % 4 == 3)
|
||||||
|
{
|
||||||
line[strlen (line) - 1] = ' ';
|
line[strlen (line) - 1] = ' ';
|
||||||
cpgstbg (0);
|
cpgstbg (0);
|
||||||
cpgsch (0.8);
|
cpgsch (0.8);
|
||||||
|
@ -833,7 +923,8 @@ int main(int argc,char *argv[])
|
||||||
cpgcurs (&x0, &y0, &c);
|
cpgcurs (&x0, &y0, &c);
|
||||||
|
|
||||||
// Accept
|
// Accept
|
||||||
if (c=='a') {
|
if (c == 'a')
|
||||||
|
{
|
||||||
outfile = fopen (catalog, "a");
|
outfile = fopen (catalog, "a");
|
||||||
fprintf (outfile, "%s\n", line);
|
fprintf (outfile, "%s\n", line);
|
||||||
fclose (outfile);
|
fclose (outfile);
|
||||||
|
@ -861,7 +952,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits fourframe
|
// Read fits fourframe
|
||||||
struct fourframe read_fits(char *filename)
|
struct fourframe
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -903,7 +995,8 @@ struct fourframe read_fits(char *filename)
|
||||||
|
|
||||||
// Timestamps
|
// Timestamps
|
||||||
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
||||||
for (i=0;i<img.nframes;i++) {
|
for (i = 0; i < img.nframes; i++)
|
||||||
|
{
|
||||||
sprintf (key, "DT%04d", i);
|
sprintf (key, "DT%04d", i);
|
||||||
img.dt[i] = atof (qfits_query_hdr (filename, key));
|
img.dt[i] = atof (qfits_query_hdr (filename, key));
|
||||||
}
|
}
|
||||||
|
@ -928,7 +1021,8 @@ struct fourframe read_fits(char *filename)
|
||||||
ql.filename = filename;
|
ql.filename = filename;
|
||||||
|
|
||||||
// Loop over planes
|
// Loop over planes
|
||||||
for (k=0;k<img.naxis3;k++) {
|
for (k = 0; k < img.naxis3; k++)
|
||||||
|
{
|
||||||
ql.pnum = k;
|
ql.pnum = k;
|
||||||
|
|
||||||
// Initialize load
|
// Initialize load
|
||||||
|
@ -940,16 +1034,27 @@ struct fourframe read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
if (k==1) img.zstd[l]=ql.fbuf[l];
|
for (j = 0; j < img.naxis2; j++)
|
||||||
if (k==2) img.zmax[l]=ql.fbuf[l];
|
{
|
||||||
if (k==3) img.znum[l]=ql.fbuf[l];
|
if (k == 1)
|
||||||
if (img.naxis3==5) {
|
img.zstd[l] = ql.fbuf[l];
|
||||||
if (k==0) img.ztrk[l]=ql.fbuf[l];
|
if (k == 2)
|
||||||
if (k==4) img.zavg[l]=ql.fbuf[l];
|
img.zmax[l] = ql.fbuf[l];
|
||||||
} else {
|
if (k == 3)
|
||||||
if (k==0) img.zavg[l]=ql.fbuf[l];
|
img.znum[l] = ql.fbuf[l];
|
||||||
|
if (img.naxis3 == 5)
|
||||||
|
{
|
||||||
|
if (k == 0)
|
||||||
|
img.ztrk[l] = ql.fbuf[l];
|
||||||
|
if (k == 4)
|
||||||
|
img.zavg[l] = ql.fbuf[l];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (k == 0)
|
||||||
|
img.zavg[l] = ql.fbuf[l];
|
||||||
}
|
}
|
||||||
|
|
||||||
l++;
|
l++;
|
||||||
|
@ -962,4 +1067,3 @@ struct fourframe read_fits(char *filename)
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ double mjd2doy(double mjd,int *yr);
|
||||||
void format_tle (orbit_t orb, char *line1, char *line2);
|
void format_tle (orbit_t orb, char *line1, char *line2);
|
||||||
double modulo (double x, double y);
|
double modulo (double x, double y);
|
||||||
|
|
||||||
void convert(char *line)
|
void
|
||||||
|
convert (char *line)
|
||||||
{
|
{
|
||||||
int no, so;
|
int no, so;
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
|
@ -36,7 +37,10 @@ void convert(char *line)
|
||||||
dm = 5.0 * log10 (1000.0 / 40000.0);
|
dm = 5.0 * log10 (1000.0 / 40000.0);
|
||||||
|
|
||||||
// Read line
|
// Read line
|
||||||
sscanf(line,"%4d,%6d,%2d%2d%4d,%2d%2d%4d %2d%2d%2d,%4d,%f,%f,%f,%f,%f,%f,%f,%f",&no,&so,&fod,&fom,&foy,&day,&month,&year,&hour,&min,&sec,&gap,&sma,&incl,&raan,&ecc,&argl,&argp,&a2m,&mag);
|
sscanf (line,
|
||||||
|
"%4d,%6d,%2d%2d%4d,%2d%2d%4d %2d%2d%2d,%4d,%f,%f,%f,%f,%f,%f,%f,%f",
|
||||||
|
&no, &so, &fod, &fom, &foy, &day, &month, &year, &hour, &min, &sec,
|
||||||
|
&gap, &sma, &incl, &raan, &ecc, &argl, &argp, &a2m, &mag);
|
||||||
|
|
||||||
// Use date of first observed as a designation
|
// Use date of first observed as a designation
|
||||||
mjd = date2mjd (foy, fom, fod);
|
mjd = date2mjd (foy, fom, fod);
|
||||||
|
@ -47,7 +51,8 @@ void convert(char *line)
|
||||||
sprintf (orb.desig, "%02d%3.0fA", foy - 1900, doy + 500);
|
sprintf (orb.desig, "%02d%3.0fA", foy - 1900, doy + 500);
|
||||||
|
|
||||||
// Find epoch
|
// Find epoch
|
||||||
mjd=date2mjd(year,month,day+hour/24.0+min/1440.0+sec/86400.0);
|
mjd =
|
||||||
|
date2mjd (year, month, day + hour / 24.0 + min / 1440.0 + sec / 86400.0);
|
||||||
orb.ep_day = mjd2doy (mjd, &orb.ep_year);
|
orb.ep_day = mjd2doy (mjd, &orb.ep_year);
|
||||||
|
|
||||||
// Set values
|
// Set values
|
||||||
|
@ -68,7 +73,9 @@ void convert(char *line)
|
||||||
perigee = sma * (1.0 - ecc) - XKMPER;
|
perigee = sma * (1.0 - ecc) - XKMPER;
|
||||||
apogee = sma * (1.0 + ecc) - XKMPER;
|
apogee = sma * (1.0 + ecc) - XKMPER;
|
||||||
|
|
||||||
sprintf(line0,"SO %6d %4.1f %7.0fkm x%7.0fkm",so,mag+dm,perigee,apogee);
|
sprintf (line0,
|
||||||
|
"SO %6d %4.1f %7.0fkm x%7.0fkm",
|
||||||
|
so, mag + dm, perigee, apogee);
|
||||||
|
|
||||||
// Format line
|
// Format line
|
||||||
format_tle (orb, line1, line2);
|
format_tle (orb, line1, line2);
|
||||||
|
@ -77,15 +84,18 @@ void convert(char *line)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[LIM], *fname;
|
char line[LIM], *fname;
|
||||||
int arg = 0;
|
int arg = 0;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"f:"))!=-1) {
|
while ((arg = getopt (argc, argv, "f:")) != -1)
|
||||||
switch(arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
fname = optarg;
|
fname = optarg;
|
||||||
|
@ -105,7 +115,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -118,7 +129,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -131,7 +143,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -155,12 +168,14 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -168,17 +183,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -188,7 +209,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -196,30 +218,44 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.desig,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1, "1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev);
|
orb.satno, orb.desig, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -231,10 +267,12 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
18
src/dec2s.c
18
src/dec2s.c
|
@ -4,7 +4,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int h = 0;
|
int h = 0;
|
||||||
double sec, deg, min;
|
double sec, deg, min;
|
||||||
|
@ -12,8 +13,10 @@ int main(int argc,char *argv[])
|
||||||
double x;
|
double x;
|
||||||
char s[14];
|
char s[14];
|
||||||
|
|
||||||
if (argc==1) {
|
if (argc == 1)
|
||||||
printf("Usage: dec2s [options] <x>\n\nCompute sexagesimal from decimal input x.\n");
|
{
|
||||||
|
printf
|
||||||
|
("Usage: dec2s [options] <x>\n\nCompute sexagesimal from decimal input x.\n");
|
||||||
printf ("Options: -r gives hours instead of degrees\n");
|
printf ("Options: -r gives hours instead of degrees\n");
|
||||||
printf (" -d<a> uses character a as delimiter\n");
|
printf (" -d<a> uses character a as delimiter\n");
|
||||||
printf (" -h uses hms as delimiters\n");
|
printf (" -h uses hms as delimiters\n");
|
||||||
|
@ -27,8 +30,10 @@ int main(int argc,char *argv[])
|
||||||
sign = (x < 0 ? '-' : ' ');
|
sign = (x < 0 ? '-' : ' ');
|
||||||
|
|
||||||
// Get Options
|
// Get Options
|
||||||
while (--argc > 0 && (*++argv)[0] == '-') {
|
while (--argc > 0 && (*++argv)[0] == '-')
|
||||||
while (c = *++argv[0]) {
|
{
|
||||||
|
while (c = *++argv[0])
|
||||||
|
{
|
||||||
if (c == 'r')
|
if (c == 'r')
|
||||||
x /= 15.;
|
x /= 15.;
|
||||||
if (c == 's')
|
if (c == 's')
|
||||||
|
@ -49,7 +54,8 @@ int main(int argc,char *argv[])
|
||||||
deg = x;
|
deg = x;
|
||||||
|
|
||||||
if (h == 0)
|
if (h == 0)
|
||||||
printf("%c%02i%c%02i%c%06.3f\n",sign,(int) deg,d,(int) min,d,(float) sec);
|
printf ("%c%02i%c%02i%c%06.3f\n", sign, (int) deg, d, (int) min, d,
|
||||||
|
(float) sec);
|
||||||
else
|
else
|
||||||
printf ("%c%02ih%02im%06.3fs\n", sign, (int) deg, (int) min, (float) sec);
|
printf ("%c%02ih%02im%06.3fs\n", sign, (int) deg, (int) min, (float) sec);
|
||||||
|
|
||||||
|
|
194
src/deep.c
194
src/deep.c
|
@ -55,7 +55,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static const char SCCSid[] = "@(#)deep.c 3.04 (C) 1995 psc SatLib: Deep Space effects";
|
static const char SCCSid[] =
|
||||||
|
"@(#)deep.c 3.04 (C) 1995 psc SatLib: Deep Space effects";
|
||||||
|
|
||||||
#ifndef NO_DEEP_SPACE
|
#ifndef NO_DEEP_SPACE
|
||||||
|
|
||||||
|
@ -156,7 +157,8 @@ static real pgh0, ph0, pe0, pinc0, pl0; /* Added terms to save the epoch values
|
||||||
|
|
||||||
================================================================== */
|
================================================================== */
|
||||||
|
|
||||||
sgdp4_mode_t SGDP4_dpinit(double epoch, real omegao, real xnodeo, real xmo,
|
sgdp4_mode_t
|
||||||
|
SGDP4_dpinit (double epoch, real omegao, real xnodeo, real xmo,
|
||||||
real orb_eo, real orb_xincl, real aodp, double xlldot,
|
real orb_eo, real orb_xincl, real aodp, double xlldot,
|
||||||
real omgdot, real xnodot, double xnodp)
|
real omgdot, real xnodot, double xnodp)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +175,8 @@ LOCAL_REAL z1, z2, z3, z11, z12, z13, z21, z22, z23, z31, z32, z33;
|
||||||
LOCAL_REAL s1, s2, s3, s4, s5, s6, s7, cc, ao, eq, se, shdq, si, sl;
|
LOCAL_REAL s1, s2, s3, s4, s5, s6, s7, cc, ao, eq, se, shdq, si, sl;
|
||||||
LOCAL_REAL zx, zy, ze, zn;
|
LOCAL_REAL zx, zy, ze, zn;
|
||||||
LOCAL_REAL g201, g211, g310, g300, g322, g410, g422, g520, g533, g521, g532;
|
LOCAL_REAL g201, g211, g310, g300, g322, g410, g422, g520, g533, g521, g532;
|
||||||
LOCAL_REAL f220, f221, f311, f321, f322, f330, f441, f442, f522, f523, f542, f543;
|
LOCAL_REAL f220, f221, f311, f321, f322, f330, f441, f442, f522, f523, f542,
|
||||||
|
f543;
|
||||||
real siniq, cosiq;
|
real siniq, cosiq;
|
||||||
real temp0, temp1;
|
real temp0, temp1;
|
||||||
int ls;
|
int ls;
|
||||||
|
@ -189,12 +192,14 @@ int ishq;
|
||||||
|
|
||||||
/* Decide on direct or Lyddane Lunar-Solar perturbations. */
|
/* Decide on direct or Lyddane Lunar-Solar perturbations. */
|
||||||
ilsd = 0;
|
ilsd = 0;
|
||||||
if(xincl >= (real)0.2) ilsd = 1;
|
if (xincl >= (real) 0.2)
|
||||||
|
ilsd = 1;
|
||||||
|
|
||||||
/* Drop some terms below 3 deg inclination. */
|
/* Drop some terms below 3 deg inclination. */
|
||||||
ishq = 0;
|
ishq = 0;
|
||||||
#define SHQT 0.052359877
|
#define SHQT 0.052359877
|
||||||
if (xincl >= (real)SHQT) ishq = 1; /* As per reoprt #3. */
|
if (xincl >= (real) SHQT)
|
||||||
|
ishq = 1; /* As per reoprt #3. */
|
||||||
|
|
||||||
SINCOS (omegao, &sinomo, &cosomo);
|
SINCOS (omegao, &sinomo, &cosomo);
|
||||||
SINCOS (xnodeo, &sinq, &cosq);
|
SINCOS (xnodeo, &sinq, &cosq);
|
||||||
|
@ -289,15 +294,23 @@ int ishq;
|
||||||
z11 = a1 * (real) - 6.0 * a5 + eqsq * (x1 * (real) - 24.0 * x7 - x3 *
|
z11 = a1 * (real) - 6.0 * a5 + eqsq * (x1 * (real) - 24.0 * x7 - x3 *
|
||||||
(real) 6.0 * x5);
|
(real) 6.0 * x5);
|
||||||
z12 = (a1 * a6 + a3 * a5) * (real) - 6.0 + eqsq * ((x2 * x7 +
|
z12 = (a1 * a6 + a3 * a5) * (real) - 6.0 + eqsq * ((x2 * x7 +
|
||||||
x1 * x8) * (real)-24.0 - (x3 * x6 + x4 * x5) * (real)6.0);
|
x1 * x8) * (real) -
|
||||||
z13 = a3 * (real)-6.0 * a6 + eqsq * (x2 * (real)-24.0 * x8 - x4 *
|
24.0 - (x3 * x6 +
|
||||||
(real)6.0 * x6);
|
x4 * x5) *
|
||||||
z21 = a2 * (real)6.0 * a5 + eqsq * (x1 * (real)24.0 * x5 -
|
(real) 6.0);
|
||||||
|
z13 =
|
||||||
|
a3 * (real) - 6.0 * a6 + eqsq * (x2 * (real) - 24.0 * x8 -
|
||||||
|
x4 * (real) 6.0 * x6);
|
||||||
|
z21 =
|
||||||
|
a2 * (real) 6.0 *a5 + eqsq * (x1 * (real) 24.0 * x5 -
|
||||||
x3 * (real) 6.0 * x7);
|
x3 * (real) 6.0 * x7);
|
||||||
z22 = (a4 * a5 + a2 * a6) * (real)6.0 + eqsq * ((x2 * x5 + x1 * x6) *
|
z22 =
|
||||||
(real)24.0 - (x4 * x7 + x3 * x8) * (real)6.0);
|
(a4 * a5 + a2 * a6) * (real) 6.0 +
|
||||||
z23 = a4 * (real)6.0 * a6 + eqsq * (x2 * (real)24.0 * x6 - x4 *
|
eqsq * ((x2 * x5 + x1 * x6) * (real) 24.0 -
|
||||||
(real)6.0 * x8);
|
(x4 * x7 + x3 * x8) * (real) 6.0);
|
||||||
|
z23 =
|
||||||
|
a4 * (real) 6.0 *a6 + eqsq * (x2 * (real) 24.0 * x6 -
|
||||||
|
x4 * (real) 6.0 * x8);
|
||||||
z1 = z1 + z1 + bsq * z31;
|
z1 = z1 + z1 + bsq * z31;
|
||||||
z2 = z2 + z2 + bsq * z32;
|
z2 = z2 + z2 + bsq * z32;
|
||||||
z3 = z3 + z3 + bsq * z33;
|
z3 = z3 + z3 + bsq * z33;
|
||||||
|
@ -333,7 +346,8 @@ int ishq;
|
||||||
xh2 = s2 * (real) - 2.0 * z22;
|
xh2 = s2 * (real) - 2.0 * z22;
|
||||||
xh3 = s2 * (real) - 2.0 * (z23 - z21);
|
xh3 = s2 * (real) - 2.0 * (z23 - z21);
|
||||||
|
|
||||||
if (ls == 1) break;
|
if (ls == 1)
|
||||||
|
break;
|
||||||
|
|
||||||
/* DO LUNAR TERMS */
|
/* DO LUNAR TERMS */
|
||||||
|
|
||||||
|
@ -381,7 +395,9 @@ int ishq;
|
||||||
g300 = eqsq * (eqsq * (real) 6.60937 - (real) 6.0) + (real) 1.0;
|
g300 = eqsq * (eqsq * (real) 6.60937 - (real) 6.0) + (real) 1.0;
|
||||||
f220 = (cosiq + (real) 1.0) * (real) 0.75 *(cosiq + (real) 1.0);
|
f220 = (cosiq + (real) 1.0) * (real) 0.75 *(cosiq + (real) 1.0);
|
||||||
f311 = siniq * (real) 0.9375 *siniq * (cosiq * (real) 3.0 +
|
f311 = siniq * (real) 0.9375 *siniq * (cosiq * (real) 3.0 +
|
||||||
(real)1.0) - (cosiq + (real)1.0) * (real)0.75;
|
(real) 1.0) - (cosiq +
|
||||||
|
(real) 1.0) *
|
||||||
|
(real) 0.75;
|
||||||
f330 = cosiq + (real) 1.0;
|
f330 = cosiq + (real) 1.0;
|
||||||
f330 = f330 * (real) 1.875 *f330 * f330;
|
f330 = f330 * (real) 1.875 *f330 * f330;
|
||||||
del1 = (real) 3.0 *(real) (xnq * xnq * aqnv * aqnv);
|
del1 = (real) 3.0 *(real) (xnq * xnq * aqnv * aqnv);
|
||||||
|
@ -406,61 +422,107 @@ int ishq;
|
||||||
if (eq <= (real) 0.65)
|
if (eq <= (real) 0.65)
|
||||||
{
|
{
|
||||||
g211 = (real) 3.616 - eq * (real) 13.247 + eqsq * (real) 16.29;
|
g211 = (real) 3.616 - eq * (real) 13.247 + eqsq * (real) 16.29;
|
||||||
g310 = eq * (real)117.39 - (real)19.302 - eqsq * (real)228.419 + eoc * (real)156.591;
|
g310 =
|
||||||
g322 = eq * (real)109.7927 - (real)18.9068 - eqsq * (real)214.6334 + eoc * (real)146.5816;
|
eq * (real) 117.39 - (real) 19.302 - eqsq * (real) 228.419 +
|
||||||
g410 = eq * (real)242.694 - (real)41.122 - eqsq * (real)471.094 + eoc * (real)313.953;
|
eoc * (real) 156.591;
|
||||||
g422 = eq * (real)841.88 - (real)146.407 - eqsq * (real)1629.014 + eoc * (real)1083.435;
|
g322 =
|
||||||
g520 = eq * (real)3017.977 - (real)532.114 - eqsq * 5740.032 + eoc * (real)3708.276;
|
eq * (real) 109.7927 - (real) 18.9068 - eqsq * (real) 214.6334 +
|
||||||
|
eoc * (real) 146.5816;
|
||||||
|
g410 =
|
||||||
|
eq * (real) 242.694 - (real) 41.122 - eqsq * (real) 471.094 +
|
||||||
|
eoc * (real) 313.953;
|
||||||
|
g422 =
|
||||||
|
eq * (real) 841.88 - (real) 146.407 - eqsq * (real) 1629.014 +
|
||||||
|
eoc * (real) 1083.435;
|
||||||
|
g520 =
|
||||||
|
eq * (real) 3017.977 - (real) 532.114 - eqsq * 5740.032 +
|
||||||
|
eoc * (real) 3708.276;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g211 = eq * (real)331.819 - (real)72.099 - eqsq * (real)508.738 + eoc * (real)266.724;
|
g211 =
|
||||||
g310 = eq * (real)1582.851 - (real)346.844 - eqsq * (real)2415.925 + eoc * (real)1246.113;
|
eq * (real) 331.819 - (real) 72.099 - eqsq * (real) 508.738 +
|
||||||
g322 = eq * (real)1554.908 - (real)342.585 - eqsq * (real)2366.899 + eoc * (real)1215.972;
|
eoc * (real) 266.724;
|
||||||
g410 = eq * (real)4758.686 - (real)1052.797 - eqsq * (real)7193.992 + eoc * (real)3651.957;
|
g310 =
|
||||||
g422 = eq * (real)16178.11 - (real)3581.69 - eqsq * (real)24462.77 + eoc * (real)12422.52;
|
eq * (real) 1582.851 - (real) 346.844 - eqsq * (real) 2415.925 +
|
||||||
|
eoc * (real) 1246.113;
|
||||||
|
g322 =
|
||||||
|
eq * (real) 1554.908 - (real) 342.585 - eqsq * (real) 2366.899 +
|
||||||
|
eoc * (real) 1215.972;
|
||||||
|
g410 =
|
||||||
|
eq * (real) 4758.686 - (real) 1052.797 - eqsq * (real) 7193.992 +
|
||||||
|
eoc * (real) 3651.957;
|
||||||
|
g422 =
|
||||||
|
eq * (real) 16178.11 - (real) 3581.69 - eqsq * (real) 24462.77 +
|
||||||
|
eoc * (real) 12422.52;
|
||||||
|
|
||||||
if (eq <= (real) 0.715)
|
if (eq <= (real) 0.715)
|
||||||
{
|
{
|
||||||
g520 = (real)1464.74 - eq * (real)4664.75 + eqsq * (real)3763.64;
|
g520 =
|
||||||
|
(real) 1464.74 - eq * (real) 4664.75 + eqsq * (real) 3763.64;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g520 = eq * (real)29936.92 - (real)5149.66 - eqsq * (real)54087.36 + eoc * (real)31324.56;
|
g520 =
|
||||||
|
eq * (real) 29936.92 - (real) 5149.66 -
|
||||||
|
eqsq * (real) 54087.36 + eoc * (real) 31324.56;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eq < (real) 0.7)
|
if (eq < (real) 0.7)
|
||||||
{
|
{
|
||||||
g533 = eq * (real)4988.61 - (real)919.2277 - eqsq * (real)9064.77 + eoc * (real)5542.21;
|
g533 =
|
||||||
g521 = eq * (real)4568.6173 - (real)822.71072 - eqsq * (real)8491.4146 + eoc * (real)5337.524;
|
eq * (real) 4988.61 - (real) 919.2277 - eqsq * (real) 9064.77 +
|
||||||
g532 = eq * (real)4690.25 - (real)853.666 - eqsq * (real)8624.77 + eoc * (real)5341.4;
|
eoc * (real) 5542.21;
|
||||||
|
g521 =
|
||||||
|
eq * (real) 4568.6173 - (real) 822.71072 -
|
||||||
|
eqsq * (real) 8491.4146 + eoc * (real) 5337.524;
|
||||||
|
g532 =
|
||||||
|
eq * (real) 4690.25 - (real) 853.666 - eqsq * (real) 8624.77 +
|
||||||
|
eoc * (real) 5341.4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g533 = eq * (real)161616.52 - (real)37995.78 - eqsq * (real)229838.2 + eoc * (real)109377.94;
|
g533 =
|
||||||
g521 = eq * (real)218913.95 - (real)51752.104 - eqsq * (real)309468.16 + eoc * (real)146349.42;
|
eq * (real) 161616.52 - (real) 37995.78 - eqsq * (real) 229838.2 +
|
||||||
g532 = eq * (real)170470.89 - (real)40023.88 - eqsq * (real)242699.48 + eoc * (real)115605.82;
|
eoc * (real) 109377.94;
|
||||||
|
g521 =
|
||||||
|
eq * (real) 218913.95 - (real) 51752.104 -
|
||||||
|
eqsq * (real) 309468.16 + eoc * (real) 146349.42;
|
||||||
|
g532 =
|
||||||
|
eq * (real) 170470.89 - (real) 40023.88 -
|
||||||
|
eqsq * (real) 242699.48 + eoc * (real) 115605.82;
|
||||||
}
|
}
|
||||||
|
|
||||||
f220 = (cosiq * (real) 2.0 + (real) 1.0 + cosiq2) * (real) 0.75;
|
f220 = (cosiq * (real) 2.0 + (real) 1.0 + cosiq2) * (real) 0.75;
|
||||||
f221 = siniq2 * (real) 1.5;
|
f221 = siniq2 * (real) 1.5;
|
||||||
f321 = siniq * (real)1.875 * ((real)1.0 - cosiq * (real)2.0 - cosiq2 * (real)3.0);
|
f321 =
|
||||||
f322 = siniq * (real)-1.875 * (cosiq * (real)2.0 + (real)1.0 - cosiq2 * (real)3.0);
|
siniq * (real) 1.875 *((real) 1.0 - cosiq * (real) 2.0 -
|
||||||
|
cosiq2 * (real) 3.0);
|
||||||
|
f322 =
|
||||||
|
siniq * (real) - 1.875 * (cosiq * (real) 2.0 + (real) 1.0 -
|
||||||
|
cosiq2 * (real) 3.0);
|
||||||
f441 = siniq2 * (real) 35.0 *f220;
|
f441 = siniq2 * (real) 35.0 *f220;
|
||||||
f442 = siniq2 * (real) 39.375 *siniq2;
|
f442 = siniq2 * (real) 39.375 *siniq2;
|
||||||
f522 = siniq * (real) 9.84375 *(siniq2 * ((real) 1.0 - cosiq *
|
f522 = siniq * (real) 9.84375 *(siniq2 * ((real) 1.0 - cosiq *
|
||||||
(real)2.0 - cosiq2 * (real)5.0) + (cosiq * (real)4.0 -
|
(real) 2.0 -
|
||||||
(real)2.0 + cosiq2 * (real)6.0) * (real)0.33333333);
|
cosiq2 * (real) 5.0) +
|
||||||
f523 = siniq * (siniq2 * (real)4.92187512 * ((real)-2.0 - cosiq *
|
(cosiq * (real) 4.0 - (real) 2.0 +
|
||||||
(real)4.0 + cosiq2 * (real)10.0) + (cosiq * (real)2.0 +
|
cosiq2 * (real) 6.0) *
|
||||||
(real)1.0 - cosiq2 * (real)3.0) * (real)6.56250012);
|
(real) 0.33333333);
|
||||||
f542 = siniq * (real)29.53125 * ((real)2.0 - cosiq * (real)8.0 +
|
f523 =
|
||||||
cosiq2 * (cosiq * (real)8.0 - (real)12.0 + cosiq2 *
|
siniq * (siniq2 * (real) 4.92187512 *
|
||||||
(real)10.0));
|
((real) - 2.0 - cosiq * (real) 4.0 + cosiq2 * (real) 10.0) +
|
||||||
f543 = siniq * (real)29.53125 * ((real)-2.0 - cosiq * (real)8.0 +
|
(cosiq * (real) 2.0 + (real) 1.0 -
|
||||||
cosiq2 * (cosiq * (real)8.0 + (real)12.0 - cosiq2 *
|
cosiq2 * (real) 3.0) * (real) 6.56250012);
|
||||||
(real)10.0));
|
f542 =
|
||||||
|
siniq * (real) 29.53125 *((real) 2.0 - cosiq * (real) 8.0 +
|
||||||
|
cosiq2 * (cosiq * (real) 8.0 - (real) 12.0 +
|
||||||
|
cosiq2 * (real) 10.0));
|
||||||
|
f543 =
|
||||||
|
siniq * (real) 29.53125 *((real) - 2.0 - cosiq * (real) 8.0 +
|
||||||
|
cosiq2 * (cosiq * (real) 8.0 + (real) 12.0 -
|
||||||
|
cosiq2 * (real) 10.0));
|
||||||
xno2 = (real) (xnq * xnq);
|
xno2 = (real) (xnq * xnq);
|
||||||
ainv2 = aqnv * aqnv;
|
ainv2 = aqnv * aqnv;
|
||||||
temp1 = xno2 * (real) 3.0 *ainv2;
|
temp1 = xno2 * (real) 3.0 *ainv2;
|
||||||
|
@ -559,7 +621,8 @@ return imode;
|
||||||
|
|
||||||
===================================================================== */
|
===================================================================== */
|
||||||
|
|
||||||
int SGDP4_dpsec(double *xll, real *omgasm, real *xnodes, real *em,
|
int
|
||||||
|
SGDP4_dpsec (double *xll, real * omgasm, real * xnodes, real * em,
|
||||||
real * xinc, double *xn, double tsince)
|
real * xinc, double *xn, double tsince)
|
||||||
{
|
{
|
||||||
LOCAL_DOUBLE delt, ft, xl;
|
LOCAL_DOUBLE delt, ft, xl;
|
||||||
|
@ -571,7 +634,8 @@ real temp0;
|
||||||
*em += sse * tsince;
|
*em += sse * tsince;
|
||||||
*xinc += ssi * tsince;
|
*xinc += ssi * tsince;
|
||||||
|
|
||||||
if (iresfl == 0) return 0;
|
if (iresfl == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A minor increase in some efficiency can be had by restarting if
|
* A minor increase in some efficiency can be had by restarting if
|
||||||
|
@ -615,7 +679,8 @@ real temp0;
|
||||||
*/
|
*/
|
||||||
delt = (tsince >= atime ? STEP : -STEP);
|
delt = (tsince >= atime ? STEP : -STEP);
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
/* INTEGRATOR (using the last "dot" terms). */
|
/* INTEGRATOR (using the last "dot" terms). */
|
||||||
xli += delt * (xldot + delt * (real) 0.5 * xndot);
|
xli += delt * (xldot + delt * (real) 0.5 * xndot);
|
||||||
xni += delt * (xndot + delt * (real) 0.5 * xnddt);
|
xni += delt * (xndot + delt * (real) 0.5 * xnddt);
|
||||||
|
@ -625,7 +690,8 @@ real temp0;
|
||||||
|
|
||||||
/* Are we close enough now ? */
|
/* Are we close enough now ? */
|
||||||
ft = tsince - atime;
|
ft = tsince - atime;
|
||||||
} while (fabs(ft) >= STEP);
|
}
|
||||||
|
while (fabs (ft) >= STEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
xl = xli + ft * (xldot + ft * (real) 0.5 * xndot);
|
xl = xli + ft * (xldot + ft * (real) 0.5 * xndot);
|
||||||
|
@ -649,7 +715,8 @@ return 0;
|
||||||
|
|
||||||
===================================================================== */
|
===================================================================== */
|
||||||
|
|
||||||
static void dot_terms_calculated(void)
|
static void
|
||||||
|
dot_terms_calculated (void)
|
||||||
{
|
{
|
||||||
LOCAL_DOUBLE x2li, x2omi, xomi;
|
LOCAL_DOUBLE x2li, x2omi, xomi;
|
||||||
|
|
||||||
|
@ -678,8 +745,7 @@ LOCAL_DOUBLE x2li, x2omi, xomi;
|
||||||
+ d5232 * SIN (-xomi + xli - G52)
|
+ d5232 * SIN (-xomi + xli - G52)
|
||||||
+ d4410 * SIN (x2omi + x2li - G44)
|
+ d4410 * SIN (x2omi + x2li - G44)
|
||||||
+ d4422 * SIN (x2li - G44)
|
+ d4422 * SIN (x2li - G44)
|
||||||
+ d5421 * SIN(xomi + x2li - G54)
|
+ d5421 * SIN (xomi + x2li - G54) + d5433 * SIN (-xomi + x2li - G54);
|
||||||
+ d5433 * SIN(-xomi + x2li - G54);
|
|
||||||
|
|
||||||
xnddt = d2201 * COS (x2omi + xli - G22)
|
xnddt = d2201 * COS (x2omi + xli - G22)
|
||||||
+ d2211 * COS (xli - G22)
|
+ d2211 * COS (xli - G22)
|
||||||
|
@ -711,7 +777,8 @@ LOCAL_DOUBLE x2li, x2omi, xomi;
|
||||||
|
|
||||||
===================================================================== */
|
===================================================================== */
|
||||||
|
|
||||||
int SGDP4_dpper(real *em, real *xinc, real *omgasm, real *xnodes,
|
int
|
||||||
|
SGDP4_dpper (real * em, real * xinc, real * omgasm, real * xnodes,
|
||||||
double *xll, double tsince)
|
double *xll, double tsince)
|
||||||
{
|
{
|
||||||
real sinis, cosis;
|
real sinis, cosis;
|
||||||
|
@ -778,7 +845,8 @@ return 0;
|
||||||
code).
|
code).
|
||||||
===================================================================== */
|
===================================================================== */
|
||||||
|
|
||||||
static void compute_LunarSolar(double tsince)
|
static void
|
||||||
|
compute_LunarSolar (double tsince)
|
||||||
{
|
{
|
||||||
LOCAL_REAL sinzf, coszf;
|
LOCAL_REAL sinzf, coszf;
|
||||||
LOCAL_REAL f2, f3, zf, zm;
|
LOCAL_REAL f2, f3, zf, zm;
|
||||||
|
@ -856,7 +924,8 @@ LOCAL_REAL sghs, shs, sghl, shl;
|
||||||
#define FK5R (5.07551419432269442E-15)
|
#define FK5R (5.07551419432269442E-15)
|
||||||
|
|
||||||
|
|
||||||
static void thetag(double ep, real *thegr, double *days50)
|
static void
|
||||||
|
thetag (double ep, real * thegr, double *days50)
|
||||||
{
|
{
|
||||||
double d;
|
double d;
|
||||||
long n, jy;
|
long n, jy;
|
||||||
|
@ -869,7 +938,8 @@ double theta;
|
||||||
/*
|
/*
|
||||||
if (jy < 10) jy += 80;
|
if (jy < 10) jy += 80;
|
||||||
*/
|
*/
|
||||||
if (jy < 50) jy += 100;
|
if (jy < 50)
|
||||||
|
jy += 100;
|
||||||
|
|
||||||
if (jy < 70) /* Fix for leap years ? */
|
if (jy < 70) /* Fix for leap years ? */
|
||||||
n = (jy - 72) / 4;
|
n = (jy - 72) / 4;
|
||||||
|
@ -891,11 +961,14 @@ double theta;
|
||||||
double t_cen, GMST;
|
double t_cen, GMST;
|
||||||
|
|
||||||
t_cen = (jd - UT - 2451545.0) / 36525.0;
|
t_cen = (jd - UT - 2451545.0) / 36525.0;
|
||||||
GMST = 24110.54841 + t_cen * (8640184.812866 + t_cen * (0.093104 - t_cen * 6.2E-6));
|
GMST =
|
||||||
|
24110.54841 + t_cen * (8640184.812866 +
|
||||||
|
t_cen * (0.093104 - t_cen * 6.2E-6));
|
||||||
|
|
||||||
GMST = fmod (GMST + SECDAY * omega_E * UT, SECDAY);
|
GMST = fmod (GMST + SECDAY * omega_E * UT, SECDAY);
|
||||||
|
|
||||||
if(GMST < 0.0) GMST += SECDAY;
|
if (GMST < 0.0)
|
||||||
|
GMST += SECDAY;
|
||||||
|
|
||||||
theta = TWOPI * GMST / SECDAY;
|
theta = TWOPI * GMST / SECDAY;
|
||||||
}
|
}
|
||||||
|
@ -919,7 +992,8 @@ double theta;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
theta = fmod (theta, TWOPI);
|
theta = fmod (theta, TWOPI);
|
||||||
if (theta < 0.0) theta += TWOPI;
|
if (theta < 0.0)
|
||||||
|
theta += TWOPI;
|
||||||
|
|
||||||
*thegr = (real) theta;
|
*thegr = (real) theta;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
#include <jpeglib.h>
|
#include <jpeglib.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int naxis1, naxis2, naxis3;
|
int naxis1, naxis2, naxis3;
|
||||||
float *z;
|
float *z;
|
||||||
float zmin, zmax;
|
float zmin, zmax;
|
||||||
|
@ -21,17 +22,21 @@ struct image {
|
||||||
char nfd[32];
|
char nfd[32];
|
||||||
int cospar;
|
int cospar;
|
||||||
};
|
};
|
||||||
struct jpeg_image {
|
struct jpeg_image
|
||||||
|
{
|
||||||
int nx, ny, nz;
|
int nx, ny, nz;
|
||||||
float *z;
|
float *z;
|
||||||
};
|
};
|
||||||
struct jpeg_image read_jpg (char *filename);
|
struct jpeg_image read_jpg (char *filename);
|
||||||
void write_jpg (char *filename, struct jpeg_image img);
|
void write_jpg (char *filename, struct jpeg_image img);
|
||||||
struct image read_fits (char *filename, int pnum);
|
struct image read_fits (char *filename, int pnum);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de);
|
double *y);
|
||||||
|
void reverse (double ra0, double de0, double x, double y, double *ra,
|
||||||
|
double *de);
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
struct image img;
|
struct image img;
|
||||||
|
@ -44,8 +49,10 @@ int main(int argc,char *argv[])
|
||||||
char *fitsfile, *jpgfile, *outfile;
|
char *fitsfile, *jpgfile, *outfile;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"j:f:o:R:D:s:"))!=-1) {
|
while ((arg = getopt (argc, argv, "j:f:o:R:D:s:")) != -1)
|
||||||
switch(arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'j':
|
case 'j':
|
||||||
jpgfile = optarg;
|
jpgfile = optarg;
|
||||||
|
@ -96,8 +103,10 @@ int main(int argc,char *argv[])
|
||||||
*/
|
*/
|
||||||
out.z = (float *) malloc (sizeof (float) * out.nx * out.ny * out.nz);
|
out.z = (float *) malloc (sizeof (float) * out.nx * out.ny * out.nz);
|
||||||
|
|
||||||
for (i=0;i<out.nx;i++) {
|
for (i = 0; i < out.nx; i++)
|
||||||
for (j=0;j<out.ny;j++) {
|
{
|
||||||
|
for (j = 0; j < out.ny; j++)
|
||||||
|
{
|
||||||
// Set rx,ry
|
// Set rx,ry
|
||||||
rx = drx * (float) (i - 0.5 * out.nx);
|
rx = drx * (float) (i - 0.5 * out.nx);
|
||||||
ry = dry * (float) (j - 0.5 * out.ny);
|
ry = dry * (float) (j - 0.5 * out.ny);
|
||||||
|
@ -114,7 +123,8 @@ int main(int argc,char *argv[])
|
||||||
y = (-rx0 * img.b[1] + ry0 * img.a[1]) / d + img.y0;
|
y = (-rx0 * img.b[1] + ry0 * img.a[1]) / d + img.y0;
|
||||||
|
|
||||||
// Fill image
|
// Fill image
|
||||||
for (k=0;k<jpg.nz;k++) {
|
for (k = 0; k < jpg.nz; k++)
|
||||||
|
{
|
||||||
l = out.nz * (i + out.nx * (out.ny - j - 1)) + k;
|
l = out.nz * (i + out.nx * (out.ny - j - 1)) + k;
|
||||||
m = jpg.nz * ((int) x + jpg.nx * (int) (jpg.ny - y - 1)) + k;
|
m = jpg.nz * ((int) x + jpg.nx * (int) (jpg.ny - y - 1)) + k;
|
||||||
if (x > 0.0 && x < jpg.nx && y > 0.0 && y < jpg.ny)
|
if (x > 0.0 && x < jpg.nx && y > 0.0 && y < jpg.ny)
|
||||||
|
@ -138,7 +148,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename,int pnum)
|
struct image
|
||||||
|
read_fits (char *filename, int pnum)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -195,15 +206,18 @@ struct image read_fits(char *filename,int pnum)
|
||||||
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0,m=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0, m = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
img.z[l] = ql.fbuf[l];
|
img.z[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get levels
|
// Get levels
|
||||||
for (i=0,s1=0.0,s2=0.0;i<img.naxis1*img.naxis2;i++) {
|
for (i = 0, s1 = 0.0, s2 = 0.0; i < img.naxis1 * img.naxis2; i++)
|
||||||
|
{
|
||||||
s1 += img.z[i];
|
s1 += img.z[i];
|
||||||
s2 += img.z[i] * img.z[i];
|
s2 += img.z[i] * img.z[i];
|
||||||
}
|
}
|
||||||
|
@ -215,7 +229,8 @@ struct image read_fits(char *filename,int pnum)
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct jpeg_image read_jpg(char *filename)
|
struct jpeg_image
|
||||||
|
read_jpg (char *filename)
|
||||||
{
|
{
|
||||||
int i = 0, j, k, l, m;
|
int i = 0, j, k, l, m;
|
||||||
unsigned long location = 0;
|
unsigned long location = 0;
|
||||||
|
@ -239,11 +254,15 @@ struct jpeg_image read_jpg(char *filename)
|
||||||
jpeg_start_decompress (&cinfo);
|
jpeg_start_decompress (&cinfo);
|
||||||
|
|
||||||
// Allocate memory
|
// Allocate memory
|
||||||
raw_image=(unsigned char *) malloc(cinfo.output_width*cinfo.output_height*cinfo.num_components);
|
raw_image =
|
||||||
|
(unsigned char *) malloc (cinfo.output_width * cinfo.output_height *
|
||||||
|
cinfo.num_components);
|
||||||
|
|
||||||
// Read image, one scan at a time
|
// Read image, one scan at a time
|
||||||
row_pointer[0]=(unsigned char *) malloc(cinfo.output_width*cinfo.num_components);
|
row_pointer[0] =
|
||||||
while(cinfo.output_scanline<cinfo.image_height) {
|
(unsigned char *) malloc (cinfo.output_width * cinfo.num_components);
|
||||||
|
while (cinfo.output_scanline < cinfo.image_height)
|
||||||
|
{
|
||||||
jpeg_read_scanlines (&cinfo, row_pointer, 1);
|
jpeg_read_scanlines (&cinfo, row_pointer, 1);
|
||||||
for (i = 0; i < cinfo.image_width * cinfo.num_components; i++)
|
for (i = 0; i < cinfo.image_width * cinfo.num_components; i++)
|
||||||
raw_image[location++] = row_pointer[0][i];
|
raw_image[location++] = row_pointer[0][i];
|
||||||
|
@ -259,9 +278,12 @@ struct jpeg_image read_jpg(char *filename)
|
||||||
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
||||||
|
|
||||||
// Fill image
|
// Fill image
|
||||||
for (i=0;i<img.nx;i++) {
|
for (i = 0; i < img.nx; i++)
|
||||||
for (j=0;j<img.ny;j++) {
|
{
|
||||||
for (k=0;k<img.nz;k++) {
|
for (j = 0; j < img.ny; j++)
|
||||||
|
{
|
||||||
|
for (k = 0; k < img.nz; k++)
|
||||||
|
{
|
||||||
l = img.nz * (i + img.nx * j) + k;
|
l = img.nz * (i + img.nx * j) + k;
|
||||||
img.z[l] = (float) raw_image[l];
|
img.z[l] = (float) raw_image[l];
|
||||||
}
|
}
|
||||||
|
@ -279,7 +301,8 @@ struct jpeg_image read_jpg(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write jpg
|
// Write jpg
|
||||||
void write_jpg(char *filename,struct jpeg_image img)
|
void
|
||||||
|
write_jpg (char *filename, struct jpeg_image img)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
struct jpeg_compress_struct cinfo;
|
struct jpeg_compress_struct cinfo;
|
||||||
|
@ -300,20 +323,28 @@ void write_jpg(char *filename,struct jpeg_image img)
|
||||||
jpeg_start_compress (&cinfo, TRUE);
|
jpeg_start_compress (&cinfo, TRUE);
|
||||||
|
|
||||||
// Allocate memory
|
// Allocate memory
|
||||||
raw_image=(unsigned char *) malloc(cinfo.image_width*cinfo.image_height*cinfo.input_components);
|
raw_image =
|
||||||
|
(unsigned char *) malloc (cinfo.image_width * cinfo.image_height *
|
||||||
|
cinfo.input_components);
|
||||||
|
|
||||||
// Fill image
|
// Fill image
|
||||||
for (i=0;i<img.nx;i++) {
|
for (i = 0; i < img.nx; i++)
|
||||||
for (j=0;j<img.ny;j++) {
|
{
|
||||||
for (k=0;k<img.nz;k++) {
|
for (j = 0; j < img.ny; j++)
|
||||||
|
{
|
||||||
|
for (k = 0; k < img.nz; k++)
|
||||||
|
{
|
||||||
l = img.nz * (i + img.nx * j) + k;
|
l = img.nz * (i + img.nx * j) + k;
|
||||||
raw_image[l] = (unsigned char) img.z[l];
|
raw_image[l] = (unsigned char) img.z[l];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(cinfo.next_scanline<cinfo.image_height) {
|
while (cinfo.next_scanline < cinfo.image_height)
|
||||||
row_pointer[0]=&raw_image[cinfo.next_scanline*cinfo.image_width*cinfo.input_components];
|
{
|
||||||
|
row_pointer[0] =
|
||||||
|
&raw_image[cinfo.next_scanline * cinfo.image_width *
|
||||||
|
cinfo.input_components];
|
||||||
jpeg_write_scanlines (&cinfo, row_pointer, 1);
|
jpeg_write_scanlines (&cinfo, row_pointer, 1);
|
||||||
}
|
}
|
||||||
jpeg_finish_compress (&cinfo);
|
jpeg_finish_compress (&cinfo);
|
||||||
|
@ -322,4 +353,3 @@ void write_jpg(char *filename,struct jpeg_image img)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
343
src/detect.c
343
src/detect.c
|
@ -13,7 +13,8 @@
|
||||||
#define D2R M_PI/180.0
|
#define D2R M_PI/180.0
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
|
|
||||||
struct fourframe {
|
struct fourframe
|
||||||
|
{
|
||||||
char filename[64];
|
char filename[64];
|
||||||
int naxis1, naxis2, naxis3, nframes;
|
int naxis1, naxis2, naxis3, nframes;
|
||||||
float *zavg, *zstd, *zmax, *znum, *ztrk, *zsig;
|
float *zavg, *zstd, *zmax, *znum, *ztrk, *zsig;
|
||||||
|
@ -26,7 +27,8 @@ struct fourframe {
|
||||||
char nfd[32];
|
char nfd[32];
|
||||||
int cospar;
|
int cospar;
|
||||||
};
|
};
|
||||||
struct observation {
|
struct observation
|
||||||
|
{
|
||||||
int satno, cospar;
|
int satno, cospar;
|
||||||
char desig[16], conditions, behavior, catalog[32], comment[LIM];
|
char desig[16], conditions, behavior, catalog[32], comment[LIM];
|
||||||
double mjd, ra, de;
|
double mjd, ra, de;
|
||||||
|
@ -43,12 +45,15 @@ struct point
|
||||||
int flag;
|
int flag;
|
||||||
};
|
};
|
||||||
struct fourframe read_fits (char *filename);
|
struct fourframe read_fits (char *filename);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de);
|
double *y);
|
||||||
|
void reverse (double ra0, double de0, double x, double y, double *ra,
|
||||||
|
double *de);
|
||||||
|
|
||||||
|
|
||||||
// Linear least squares fit
|
// Linear least squares fit
|
||||||
float linear_fit(float x[],float y[],float w[],int n,float a[],float sa[])
|
float
|
||||||
|
linear_fit (float x[], float y[], float w[], int n, float a[], float sa[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float sum, sumx, sumy, sumxx, sumxy;
|
float sum, sumx, sumy, sumxx, sumxy;
|
||||||
|
@ -56,7 +61,8 @@ float linear_fit(float x[],float y[],float w[],int n,float a[],float sa[])
|
||||||
|
|
||||||
// Compute sums
|
// Compute sums
|
||||||
sum = sumx = sumy = sumxx = sumxy = 0.;
|
sum = sumx = sumy = sumxx = sumxy = 0.;
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
sum += w[i];
|
sum += w[i];
|
||||||
sumx += x[i] * w[i];
|
sumx += x[i] * w[i];
|
||||||
sumy += y[i] * w[i];
|
sumy += y[i] * w[i];
|
||||||
|
@ -87,12 +93,14 @@ float linear_fit(float x[],float y[],float w[],int n,float a[],float sa[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -100,23 +108,30 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min;
|
int year, month, day, hour, min;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
float sec;
|
float sec;
|
||||||
|
|
||||||
sscanf(date,"'%04d-%02d-%02dT%02d:%02d:%f'",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "'%04d-%02d-%02dT%02d:%02d:%f'", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
|
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -125,7 +140,8 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date)
|
void
|
||||||
|
mjd2date (double mjd, char *date)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -140,7 +156,8 @@ void mjd2date(double mjd,char *date)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -169,13 +186,15 @@ void mjd2date(double mjd,char *date)
|
||||||
x = (x - min) / 60.;
|
x = (x - min) / 60.;
|
||||||
hour = x;
|
hour = x;
|
||||||
fsec = 1000.0 * (sec - floor (sec));
|
fsec = 1000.0 * (sec - floor (sec));
|
||||||
sprintf(date,"%04d%02d%02d%02d%02d%02.0f%03.0f",(int) year,(int) month,(int) day,(int) hour,(int) min,floor(sec),fsec);
|
sprintf (date, "%04d%02d%02d%02d%02d%02.0f%03.0f", (int) year, (int) month,
|
||||||
|
(int) day, (int) hour, (int) min, floor (sec), fsec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
int day;
|
int day;
|
||||||
|
@ -191,7 +210,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -199,7 +219,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Decimal into Sexagesimal
|
// Convert Decimal into Sexagesimal
|
||||||
void dec2s(double x,char *s,int type)
|
void
|
||||||
|
dec2s (double x, char *s, int type)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double sec, deg, min, fmin;
|
double sec, deg, min, fmin;
|
||||||
|
@ -226,7 +247,9 @@ void dec2s(double x,char *s,int type)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce point
|
// Reduce point
|
||||||
void reduce_point(struct observation *obs,struct fourframe img,float tmid,float x,float y)
|
void
|
||||||
|
reduce_point (struct observation *obs, struct fourframe img, float tmid,
|
||||||
|
float x, float y)
|
||||||
{
|
{
|
||||||
int iframe, k;
|
int iframe, k;
|
||||||
double ra, de, rx, ry;
|
double ra, de, rx, ry;
|
||||||
|
@ -261,7 +284,9 @@ void reduce_point(struct observation *obs,struct fourframe img,float tmid,float
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int flag)
|
void
|
||||||
|
fit (struct observation *obs, struct fourframe ff, struct point *p, int np,
|
||||||
|
int flag)
|
||||||
{
|
{
|
||||||
int i, j, k, l, n, m;
|
int i, j, k, l, n, m;
|
||||||
float *t, *dt, *x, *y, *w;
|
float *t, *dt, *x, *y, *w;
|
||||||
|
@ -282,8 +307,10 @@ void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int
|
||||||
w = (float *) malloc (sizeof (float) * n);
|
w = (float *) malloc (sizeof (float) * n);
|
||||||
|
|
||||||
// Fill
|
// Fill
|
||||||
for (i=0,l=0;i<np;i++) {
|
for (i = 0, l = 0; i < np; i++)
|
||||||
if (p[i].flag==flag) {
|
{
|
||||||
|
if (p[i].flag == flag)
|
||||||
|
{
|
||||||
x[l] = p[i].x;
|
x[l] = p[i].x;
|
||||||
y[l] = p[i].y;
|
y[l] = p[i].y;
|
||||||
w[l] = 1.0;
|
w[l] = 1.0;
|
||||||
|
@ -293,13 +320,19 @@ void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find limits in time
|
// Find limits in time
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
if (i==0) {
|
{
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
tmin = t[i];
|
tmin = t[i];
|
||||||
tmax = t[i];
|
tmax = t[i];
|
||||||
} else {
|
}
|
||||||
if (t[i]<tmin) tmin=t[i];
|
else
|
||||||
if (t[i]>tmax) tmax=t[i];
|
{
|
||||||
|
if (t[i] < tmin)
|
||||||
|
tmin = t[i];
|
||||||
|
if (t[i] > tmax)
|
||||||
|
tmax = t[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmid = 0.5 * (tmin + tmax);
|
tmid = 0.5 * (tmin + tmax);
|
||||||
|
@ -315,7 +348,8 @@ void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int
|
||||||
chi2y = linear_fit (dt, y, w, n, ay, say);
|
chi2y = linear_fit (dt, y, w, n, ay, say);
|
||||||
|
|
||||||
// Compute rms
|
// Compute rms
|
||||||
for (i=0,rmsx=0.0,rmsy=0.0;i<n;i++) {
|
for (i = 0, rmsx = 0.0, rmsy = 0.0; i < n; i++)
|
||||||
|
{
|
||||||
rmsx += pow (x[i] - (ax[0] + ax[1] * dt[i]), 2);
|
rmsx += pow (x[i] - (ax[0] + ax[1] * dt[i]), 2);
|
||||||
rmsy += pow (y[i] - (ay[0] + ay[1] * dt[i]), 2);
|
rmsy += pow (y[i] - (ay[0] + ay[1] * dt[i]), 2);
|
||||||
}
|
}
|
||||||
|
@ -348,7 +382,8 @@ void fit(struct observation *obs,struct fourframe ff,struct point *p,int np,int
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void format_iod_line(struct observation *obs)
|
void
|
||||||
|
format_iod_line (struct observation *obs)
|
||||||
{
|
{
|
||||||
int mt, xt, mp, xp;
|
int mt, xt, mp, xp;
|
||||||
char string[10];
|
char string[10];
|
||||||
|
@ -359,32 +394,29 @@ void format_iod_line(struct observation *obs)
|
||||||
xt = atoi (string + 4) + 8;
|
xt = atoi (string + 4) + 8;
|
||||||
|
|
||||||
// Position format
|
// Position format
|
||||||
if (obs->type==2) {
|
if (obs->type == 2)
|
||||||
|
{
|
||||||
sprintf (string, "%7.1e", obs->perr);
|
sprintf (string, "%7.1e", obs->perr);
|
||||||
mp = string[0] - '0';
|
mp = string[0] - '0';
|
||||||
xp = atoi (string + 4) + 8;
|
xp = atoi (string + 4) + 8;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("Position format not implemented!\n");
|
printf ("Position format not implemented!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(obs->iod_line,"%05d %c%c %-6s %04d %c %-17s %d%d %d%d %-14s %d%d %c",
|
sprintf (obs->iod_line,
|
||||||
obs->satno,
|
"%05d %c%c %-6s %04d %c %-17s %d%d %d%d %-14s %d%d %c", obs->satno,
|
||||||
obs->desig[0],obs->desig[1],
|
obs->desig[0], obs->desig[1], obs->desig + 2, obs->cospar,
|
||||||
obs->desig+2,
|
obs->conditions, obs->nfd, mt, xt, obs->type, obs->epoch, obs->pos,
|
||||||
obs->cospar,
|
mp, xp, obs->behavior);
|
||||||
obs->conditions,
|
|
||||||
obs->nfd,
|
|
||||||
mt,xt,
|
|
||||||
obs->type,obs->epoch,
|
|
||||||
obs->pos,
|
|
||||||
mp,xp,
|
|
||||||
obs->behavior);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -398,7 +430,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void find_designation(int satno0,char *desig0)
|
void
|
||||||
|
find_designation (int satno0, char *desig0)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
int satno;
|
int satno;
|
||||||
|
@ -410,13 +443,16 @@ void find_designation(int satno0,char *desig0)
|
||||||
sprintf (filename, "%s/data/desig.txt", env);
|
sprintf (filename, "%s/data/desig.txt", env);
|
||||||
|
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Designation file not found!\n");
|
fprintf (stderr, "Designation file not found!\n");
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fscanf (file, "%d %s", &satno, desig);
|
fscanf (file, "%d %s", &satno, desig);
|
||||||
if (satno==satno0) {
|
if (satno == satno0)
|
||||||
|
{
|
||||||
strcpy (desig0, desig);
|
strcpy (desig0, desig);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -426,7 +462,9 @@ void find_designation(int satno0,char *desig0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void identify_observation(struct observation *obs,char *fileroot,float drmin,float amin)
|
void
|
||||||
|
identify_observation (struct observation *obs, char *fileroot, float drmin,
|
||||||
|
float amin)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
float x0, y0, x1, y1, x, y, texp;
|
float x0, y0, x1, y1, x, y, texp;
|
||||||
|
@ -438,12 +476,15 @@ void identify_observation(struct observation *obs,char *fileroot,float drmin,flo
|
||||||
// Open ID file
|
// Open ID file
|
||||||
sprintf (filename, "%s.id", fileroot);
|
sprintf (filename, "%s.id", fileroot);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "ID file %s not found\n", filename);
|
fprintf (stderr, "ID file %s not found\n", filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
sscanf(line,"%s %f %f %f %f %f %d %s",nfd,&x0,&y0,&x1,&y1,&texp,&satno,catalog);
|
{
|
||||||
|
sscanf (line, "%s %f %f %f %f %f %d %s", nfd, &x0, &y0, &x1, &y1, &texp,
|
||||||
|
&satno, catalog);
|
||||||
|
|
||||||
// Predicted pixel rates
|
// Predicted pixel rates
|
||||||
dxdt = (x1 - x0) / texp;
|
dxdt = (x1 - x0) / texp;
|
||||||
|
@ -463,7 +504,8 @@ void identify_observation(struct observation *obs,char *fileroot,float drmin,flo
|
||||||
angle = 0.0;
|
angle = 0.0;
|
||||||
|
|
||||||
// Identify
|
// Identify
|
||||||
if (dr<drmin && angle<amin) {
|
if (dr < drmin && angle < amin)
|
||||||
|
{
|
||||||
obs->satno = satno;
|
obs->satno = satno;
|
||||||
if (strstr (catalog, "classfd.tle") != NULL)
|
if (strstr (catalog, "classfd.tle") != NULL)
|
||||||
strcpy (obs->catalog, "classfd");
|
strcpy (obs->catalog, "classfd");
|
||||||
|
@ -478,7 +520,8 @@ void identify_observation(struct observation *obs,char *fileroot,float drmin,flo
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_observation(struct observation obs)
|
void
|
||||||
|
write_observation (struct observation obs)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char filename[LIM];
|
char filename[LIM];
|
||||||
|
@ -492,7 +535,8 @@ void write_observation(struct observation obs)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void overlay_predictions(char *fitsfile,struct fourframe ff)
|
void
|
||||||
|
overlay_predictions (char *fitsfile, struct fourframe ff)
|
||||||
{
|
{
|
||||||
float x0, y0, x1, y1, texp;
|
float x0, y0, x1, y1, texp;
|
||||||
int satno, isch;
|
int satno, isch;
|
||||||
|
@ -506,12 +550,15 @@ void overlay_predictions(char *fitsfile,struct fourframe ff)
|
||||||
|
|
||||||
// Open ID file
|
// Open ID file
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "ID file %s not found\n", filename);
|
fprintf (stderr, "ID file %s not found\n", filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
sscanf(line,"%s %f %f %f %f %f %d %s",nfd,&x0,&y0,&x1,&y1,&texp,&satno,catalog);
|
{
|
||||||
|
sscanf (line, "%s %f %f %f %f %f %d %s", nfd, &x0, &y0, &x1, &y1, &texp,
|
||||||
|
&satno, catalog);
|
||||||
|
|
||||||
if (strstr (catalog, "classfd") != NULL)
|
if (strstr (catalog, "classfd") != NULL)
|
||||||
cpgsci (4);
|
cpgsci (4);
|
||||||
|
@ -529,10 +576,12 @@ void overlay_predictions(char *fitsfile,struct fourframe ff)
|
||||||
// plot text
|
// plot text
|
||||||
cpgsch (0.65);
|
cpgsch (0.65);
|
||||||
sprintf (text, " %05d", satno);
|
sprintf (text, " %05d", satno);
|
||||||
for (t=0.0;t<1.0;t+=0.1) {
|
for (t = 0.0; t < 1.0; t += 0.1)
|
||||||
|
{
|
||||||
x = x0 + (x1 - x0) * t;
|
x = x0 + (x1 - x0) * t;
|
||||||
y = y0 + (y1 - y0) * t;
|
y = y0 + (y1 - y0) * t;
|
||||||
if (x>0.0 && y>0.0 && x<ff.naxis1 && y<ff.naxis2) {
|
if (x > 0.0 && y > 0.0 && x < ff.naxis1 && y < ff.naxis2)
|
||||||
|
{
|
||||||
cpgtext (x, y, text);
|
cpgtext (x, y, text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -547,7 +596,9 @@ void overlay_predictions(char *fitsfile,struct fourframe ff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void accumulate(float *z,int nx,int ny,int nz,int *mask,int bx,int by,int bz,int nsel,int *zsel)
|
void
|
||||||
|
accumulate (float *z, int nx, int ny, int nz, int *mask, int bx, int by,
|
||||||
|
int bz, int nsel, int *zsel)
|
||||||
{
|
{
|
||||||
int ix, iy, iz;
|
int ix, iy, iz;
|
||||||
int jx, jy, jz, k;
|
int jx, jy, jz, k;
|
||||||
|
@ -565,8 +616,10 @@ void accumulate(float *z,int nx,int ny,int nz,int *mask,int bx,int by,int bz,int
|
||||||
c[ix] = 0;
|
c[ix] = 0;
|
||||||
|
|
||||||
// Accumulate
|
// Accumulate
|
||||||
for (ix=0;ix<nx;ix++) {
|
for (ix = 0; ix < nx; ix++)
|
||||||
for (iy=0;iy<ny;iy++) {
|
{
|
||||||
|
for (iy = 0; iy < ny; iy++)
|
||||||
|
{
|
||||||
iz = (int) z[ix + nx * iy];
|
iz = (int) z[ix + nx * iy];
|
||||||
jx = ix / bx;
|
jx = ix / bx;
|
||||||
jy = iy / by;
|
jy = iy / by;
|
||||||
|
@ -578,8 +631,10 @@ void accumulate(float *z,int nx,int ny,int nz,int *mask,int bx,int by,int bz,int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply mask
|
// Apply mask
|
||||||
for (ix=0;ix<nx;ix++) {
|
for (ix = 0; ix < nx; ix++)
|
||||||
for (iy=0;iy<ny;iy++) {
|
{
|
||||||
|
for (iy = 0; iy < ny; iy++)
|
||||||
|
{
|
||||||
iz = (int) z[ix + nx * iy];
|
iz = (int) z[ix + nx * iy];
|
||||||
jx = ix / bx;
|
jx = ix / bx;
|
||||||
jy = iy / by;
|
jy = iy / by;
|
||||||
|
@ -595,7 +650,8 @@ void accumulate(float *z,int nx,int ny,int nz,int *mask,int bx,int by,int bz,int
|
||||||
}
|
}
|
||||||
|
|
||||||
// RANSAC line finding
|
// RANSAC line finding
|
||||||
void ransac(struct point *p,int np,float drmin)
|
void
|
||||||
|
ransac (struct point *p, int np, float drmin)
|
||||||
{
|
{
|
||||||
int i = 0, j, k, l, m, n, mmax;
|
int i = 0, j, k, l, m, n, mmax;
|
||||||
const gsl_rng_type *T;
|
const gsl_rng_type *T;
|
||||||
|
@ -611,16 +667,20 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
r = gsl_rng_alloc (T);
|
r = gsl_rng_alloc (T);
|
||||||
|
|
||||||
// Loop over number of lines
|
// Loop over number of lines
|
||||||
for (i=1;i<=4;i++) {
|
for (i = 1; i <= 4; i++)
|
||||||
|
{
|
||||||
// Number of iterations
|
// Number of iterations
|
||||||
for (l=0,mmax=0;l<10000;l++) {
|
for (l = 0, mmax = 0; l < 10000; l++)
|
||||||
|
{
|
||||||
// Get random end points
|
// Get random end points
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
i0 = (int) (np * gsl_rng_uniform (r));
|
i0 = (int) (np * gsl_rng_uniform (r));
|
||||||
if (p[i0].flag == 0)
|
if (p[i0].flag == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
i1 = (int) (np * gsl_rng_uniform (r));
|
i1 = (int) (np * gsl_rng_uniform (r));
|
||||||
if (p[i1].flag == 0)
|
if (p[i1].flag == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -633,7 +693,8 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
by = p[i0].y - ay * p[i0].t;
|
by = p[i0].y - ay * p[i0].t;
|
||||||
|
|
||||||
// Find matches
|
// Find matches
|
||||||
for (k=0,m=0;k<np;k++) {
|
for (k = 0, m = 0; k < np; k++)
|
||||||
|
{
|
||||||
dx = bx + ax * p[k].t - p[k].x;
|
dx = bx + ax * p[k].t - p[k].x;
|
||||||
dy = by + ay * p[k].t - p[k].y;
|
dy = by + ay * p[k].t - p[k].y;
|
||||||
dr = sqrt (dx * dx + dy * dy);
|
dr = sqrt (dx * dx + dy * dy);
|
||||||
|
@ -642,7 +703,8 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store
|
// Store
|
||||||
if (m>mmax) {
|
if (m > mmax)
|
||||||
|
{
|
||||||
mmax = m;
|
mmax = m;
|
||||||
i0max = i0;
|
i0max = i0;
|
||||||
i1max = i1;
|
i1max = i1;
|
||||||
|
@ -656,7 +718,8 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
by = p[i0max].y - ay * p[i0max].t;
|
by = p[i0max].y - ay * p[i0max].t;
|
||||||
|
|
||||||
// Find matches
|
// Find matches
|
||||||
for (k=0;k<np;k++) {
|
for (k = 0; k < np; k++)
|
||||||
|
{
|
||||||
dx = bx + ax * p[k].t - p[k].x;
|
dx = bx + ax * p[k].t - p[k].x;
|
||||||
dy = by + ay * p[k].t - p[k].y;
|
dy = by + ay * p[k].t - p[k].y;
|
||||||
dr = sqrt (dx * dx + dy * dy);
|
dr = sqrt (dx * dx + dy * dy);
|
||||||
|
@ -675,7 +738,8 @@ void ransac(struct point *p,int np,float drmin)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, k, l, m, n, flag = 0, np, nline;
|
int i, j, k, l, m, n, flag = 0, np, nline;
|
||||||
struct fourframe ff;
|
struct fourframe ff;
|
||||||
|
@ -700,9 +764,12 @@ int main(int argc,char *argv[])
|
||||||
int year;
|
int year;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
if (argc>1) {
|
if (argc > 1)
|
||||||
while ((arg=getopt(argc,argv,"f:s:R:r:a:pn:"))!=-1) {
|
{
|
||||||
switch(arg) {
|
while ((arg = getopt (argc, argv, "f:s:R:r:a:pn:")) != -1)
|
||||||
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
fitsfile = optarg;
|
fitsfile = optarg;
|
||||||
|
@ -733,7 +800,9 @@ int main(int argc,char *argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,9 +812,12 @@ int main(int argc,char *argv[])
|
||||||
ff = read_fits (fitsfile);
|
ff = read_fits (fitsfile);
|
||||||
|
|
||||||
// Fill mask
|
// Fill mask
|
||||||
if (ff.naxis1==720 && ff.naxis2==576) {
|
if (ff.naxis1 == 720 && ff.naxis2 == 576)
|
||||||
for (i=0;i<ff.naxis1;i++) {
|
{
|
||||||
for (j=0;j<ff.naxis2;j++) {
|
for (i = 0; i < ff.naxis1; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < ff.naxis2; j++)
|
||||||
|
{
|
||||||
k = i + ff.naxis1 * j;
|
k = i + ff.naxis1 * j;
|
||||||
if (i < 10 || i > ff.naxis1 - 12 || j > ff.naxis2 - 1 || j < 1)
|
if (i < 10 || i > ff.naxis1 - 12 || j > ff.naxis2 - 1 || j < 1)
|
||||||
ff.mask[k] = 0;
|
ff.mask[k] = 0;
|
||||||
|
@ -759,12 +831,17 @@ int main(int argc,char *argv[])
|
||||||
zsel[i] = 0;
|
zsel[i] = 0;
|
||||||
|
|
||||||
// Accumulate
|
// Accumulate
|
||||||
if (ff.nframes==250) {
|
if (ff.nframes == 250)
|
||||||
|
{
|
||||||
// accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,2,2,10,2,zsel);
|
// accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,2,2,10,2,zsel);
|
||||||
accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,4,4,10,8,zsel);
|
accumulate (ff.znum, ff.naxis1, ff.naxis2, ff.nframes, ff.mask, 4, 4,
|
||||||
} else if (ff.nframes==256) {
|
10, 8, zsel);
|
||||||
|
}
|
||||||
|
else if (ff.nframes == 256)
|
||||||
|
{
|
||||||
// accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,2,2,8,2,zsel);
|
// accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,2,2,8,2,zsel);
|
||||||
accumulate(ff.znum,ff.naxis1,ff.naxis2,ff.nframes,ff.mask,4,4,16,6,zsel);
|
accumulate (ff.znum, ff.naxis1, ff.naxis2, ff.nframes, ff.mask, 4, 4,
|
||||||
|
16, 6, zsel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply mask
|
// Apply mask
|
||||||
|
@ -773,17 +850,27 @@ int main(int argc,char *argv[])
|
||||||
ff.zmax[i] = 0.0;
|
ff.zmax[i] = 0.0;
|
||||||
|
|
||||||
// Plot
|
// Plot
|
||||||
if (plot==1) {
|
if (plot == 1)
|
||||||
|
{
|
||||||
cpgopen ("/xs");
|
cpgopen ("/xs");
|
||||||
cpgpap (0., 1.0);
|
cpgpap (0., 1.0);
|
||||||
cpgsvp (0.1, 0.95, 0.1, 0.8);
|
cpgsvp (0.1, 0.95, 0.1, 0.8);
|
||||||
|
|
||||||
cpgsch (0.8);
|
cpgsch (0.8);
|
||||||
sprintf(text,"UT Date: %.23s COSPAR ID: %04d",ff.nfd+1,ff.cospar);
|
sprintf (text, "UT Date: %.23s COSPAR ID: %04d", ff.nfd + 1,
|
||||||
|
ff.cospar);
|
||||||
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
||||||
sprintf(text,"R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')",ff.ra0,ff.xrms,ff.de0,ff.yrms);
|
sprintf (text, "R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')", ff.ra0,
|
||||||
|
ff.xrms, ff.de0, ff.yrms);
|
||||||
cpgmtxt ("T", 4.8, 0.0, 0.0, text);
|
cpgmtxt ("T", 4.8, 0.0, 0.0, text);
|
||||||
sprintf(text,"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d",ff.naxis1*sqrt(ff.a[1]*ff.a[1]+ff.b[1]*ff.b[1])/3600.0,ff.naxis2*sqrt(ff.a[2]*ff.a[2]+ff.b[2]*ff.b[2])/3600.0,sqrt(ff.a[1]*ff.a[1]+ff.b[1]*ff.b[1]),sqrt(ff.a[2]*ff.a[2]+ff.b[2]*ff.b[2]));
|
sprintf (text,
|
||||||
|
"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d",
|
||||||
|
ff.naxis1 * sqrt (ff.a[1] * ff.a[1] +
|
||||||
|
ff.b[1] * ff.b[1]) / 3600.0,
|
||||||
|
ff.naxis2 * sqrt (ff.a[2] * ff.a[2] +
|
||||||
|
ff.b[2] * ff.b[2]) / 3600.0,
|
||||||
|
sqrt (ff.a[1] * ff.a[1] + ff.b[1] * ff.b[1]),
|
||||||
|
sqrt (ff.a[2] * ff.a[2] + ff.b[2] * ff.b[2]));
|
||||||
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
||||||
|
|
||||||
cpgsch (1.0);
|
cpgsch (1.0);
|
||||||
|
@ -792,7 +879,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
zmin = 0.0;
|
zmin = 0.0;
|
||||||
zmax = 100.0;
|
zmax = 100.0;
|
||||||
cpgimag(ff.zmax,ff.naxis1,ff.naxis2,1,ff.naxis1,1,ff.naxis2,zmin,zmax,tr);
|
cpgimag (ff.zmax, ff.naxis1, ff.naxis2, 1, ff.naxis1, 1, ff.naxis2,
|
||||||
|
zmin, zmax, tr);
|
||||||
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
||||||
cpgstbg (1);
|
cpgstbg (1);
|
||||||
overlay_predictions (fitsfile, ff);
|
overlay_predictions (fitsfile, ff);
|
||||||
|
@ -815,10 +903,13 @@ int main(int argc,char *argv[])
|
||||||
p = (struct point *) malloc (sizeof (struct point) * np);
|
p = (struct point *) malloc (sizeof (struct point) * np);
|
||||||
|
|
||||||
// Fill
|
// Fill
|
||||||
for (i=0,l=0;i<ff.naxis1;i++) {
|
for (i = 0, l = 0; i < ff.naxis1; i++)
|
||||||
for (j=0;j<ff.naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < ff.naxis2; j++)
|
||||||
|
{
|
||||||
k = i + ff.naxis1 * j;
|
k = i + ff.naxis1 * j;
|
||||||
if (zsel[k]>0) {
|
if (zsel[k] > 0)
|
||||||
|
{
|
||||||
p[l].x = (float) i;
|
p[l].x = (float) i;
|
||||||
p[l].y = (float) j;
|
p[l].y = (float) j;
|
||||||
p[l].t = ff.dt[(int) ff.znum[k]];
|
p[l].t = ff.dt[(int) ff.znum[k]];
|
||||||
|
@ -832,7 +923,8 @@ int main(int argc,char *argv[])
|
||||||
ransac (p, np, drmin);
|
ransac (p, np, drmin);
|
||||||
|
|
||||||
// Fit lines
|
// Fit lines
|
||||||
for (l=1;l<=4;l++) {
|
for (l = 1; l <= 4; l++)
|
||||||
|
{
|
||||||
// Default observation
|
// Default observation
|
||||||
env = getenv ("ST_COSPAR");
|
env = getenv ("ST_COSPAR");
|
||||||
obs.satno = 99999;
|
obs.satno = 99999;
|
||||||
|
@ -866,9 +958,12 @@ int main(int argc,char *argv[])
|
||||||
identify_observation (&obs, fitsfile, rmin, amin);
|
identify_observation (&obs, fitsfile, rmin, amin);
|
||||||
|
|
||||||
// Find designation
|
// Find designation
|
||||||
if (obs.satno!=99999) {
|
if (obs.satno != 99999)
|
||||||
|
{
|
||||||
find_designation (obs.satno, obs.desig);
|
find_designation (obs.satno, obs.desig);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
mjd = nfd2mjd (ff.nfd);
|
mjd = nfd2mjd (ff.nfd);
|
||||||
doy = mjd2doy (mjd, &year);
|
doy = mjd2doy (mjd, &year);
|
||||||
sprintf (obs.desig, "%02d%03.0lfA", year - 2000, doy + 500);
|
sprintf (obs.desig, "%02d%03.0lfA", year - 2000, doy + 500);
|
||||||
|
@ -878,7 +973,8 @@ int main(int argc,char *argv[])
|
||||||
format_iod_line (&obs);
|
format_iod_line (&obs);
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
if (flag==0) {
|
if (flag == 0)
|
||||||
|
{
|
||||||
sprintf (filename, "%s.det", fitsfile);
|
sprintf (filename, "%s.det", fitsfile);
|
||||||
file = fopen (filename, "w");
|
file = fopen (filename, "w");
|
||||||
flag = 1;
|
flag = 1;
|
||||||
|
@ -886,14 +982,18 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Comment
|
// Comment
|
||||||
fprintf (file, "# %s : line %d, %d points\n", fitsfile, l, m);
|
fprintf (file, "# %s : line %d, %d points\n", fitsfile, l, m);
|
||||||
fprintf(file,"# %7.2f %7.2f %5.2f %7.2f %7.2f %5.2f %7.2f %7.2f %5.2f\n",obs.x[0],obs.y[0],obs.t[0],obs.x[1],obs.y[1],obs.t[1],obs.x[2],obs.y[2],obs.t[2]);
|
fprintf (file,
|
||||||
|
"# %7.2f %7.2f %5.2f %7.2f %7.2f %5.2f %7.2f %7.2f %5.2f\n",
|
||||||
|
obs.x[0], obs.y[0], obs.t[0], obs.x[1], obs.y[1], obs.t[1],
|
||||||
|
obs.x[2], obs.y[2], obs.t[2]);
|
||||||
fprintf (file, "# %s\n", obs.catalog);
|
fprintf (file, "# %s\n", obs.catalog);
|
||||||
fprintf (file, "%s\n", obs.iod_line);
|
fprintf (file, "%s\n", obs.iod_line);
|
||||||
printf ("# %s : line %d, %d points\n", fitsfile, l, m);
|
printf ("# %s : line %d, %d points\n", fitsfile, l, m);
|
||||||
printf ("%s\n", obs.iod_line);
|
printf ("%s\n", obs.iod_line);
|
||||||
|
|
||||||
// Plot observation
|
// Plot observation
|
||||||
if (plot==1) {
|
if (plot == 1)
|
||||||
|
{
|
||||||
cpgsci (5);
|
cpgsci (5);
|
||||||
sprintf (text, " %d: %05d", l, obs.satno);
|
sprintf (text, " %d: %05d", l, obs.satno);
|
||||||
cpgsch (0.65);
|
cpgsch (0.65);
|
||||||
|
@ -927,7 +1027,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits fourframe
|
// Read fits fourframe
|
||||||
struct fourframe read_fits(char *filename)
|
struct fourframe
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -969,7 +1070,8 @@ struct fourframe read_fits(char *filename)
|
||||||
|
|
||||||
// Timestamps
|
// Timestamps
|
||||||
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
||||||
for (i=0;i<img.nframes;i++) {
|
for (i = 0; i < img.nframes; i++)
|
||||||
|
{
|
||||||
sprintf (key, "DT%04d", i);
|
sprintf (key, "DT%04d", i);
|
||||||
img.dt[i] = atof (qfits_query_hdr (filename, key));
|
img.dt[i] = atof (qfits_query_hdr (filename, key));
|
||||||
}
|
}
|
||||||
|
@ -994,7 +1096,8 @@ struct fourframe read_fits(char *filename)
|
||||||
ql.filename = filename;
|
ql.filename = filename;
|
||||||
|
|
||||||
// Loop over planes
|
// Loop over planes
|
||||||
for (k=0;k<img.naxis3;k++) {
|
for (k = 0; k < img.naxis3; k++)
|
||||||
|
{
|
||||||
ql.pnum = k;
|
ql.pnum = k;
|
||||||
|
|
||||||
// Initialize load
|
// Initialize load
|
||||||
|
@ -1006,16 +1109,27 @@ struct fourframe read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
if (k==1) img.zstd[l]=ql.fbuf[l];
|
for (j = 0; j < img.naxis2; j++)
|
||||||
if (k==2) img.zmax[l]=ql.fbuf[l];
|
{
|
||||||
if (k==3) img.znum[l]=ql.fbuf[l];
|
if (k == 1)
|
||||||
if (img.naxis3==5) {
|
img.zstd[l] = ql.fbuf[l];
|
||||||
if (k==0) img.ztrk[l]=ql.fbuf[l];
|
if (k == 2)
|
||||||
if (k==4) img.zavg[l]=ql.fbuf[l];
|
img.zmax[l] = ql.fbuf[l];
|
||||||
} else {
|
if (k == 3)
|
||||||
if (k==0) img.zavg[l]=ql.fbuf[l];
|
img.znum[l] = ql.fbuf[l];
|
||||||
|
if (img.naxis3 == 5)
|
||||||
|
{
|
||||||
|
if (k == 0)
|
||||||
|
img.ztrk[l] = ql.fbuf[l];
|
||||||
|
if (k == 4)
|
||||||
|
img.zavg[l] = ql.fbuf[l];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (k == 0)
|
||||||
|
img.zavg[l] = ql.fbuf[l];
|
||||||
}
|
}
|
||||||
|
|
||||||
l++;
|
l++;
|
||||||
|
@ -1028,4 +1142,3 @@ struct fourframe read_fits(char *filename)
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
60
src/dsmin.c
60
src/dsmin.c
|
@ -7,14 +7,16 @@
|
||||||
#define SWAP(a,b) {(a)+=(b);(b)=(a)-(b);(a)-=(b);}
|
#define SWAP(a,b) {(a)+=(b);(b)=(a)-(b);(a)-=(b);}
|
||||||
|
|
||||||
// Downhill Simplex Minimization
|
// Downhill Simplex Minimization
|
||||||
int dsmin(double **p,double *y,int n,double ftol,double (*func)(double *))
|
int
|
||||||
|
dsmin (double **p, double *y, int n, double ftol, double (*func) (double *))
|
||||||
{
|
{
|
||||||
int i, j, nfunk = 0;
|
int i, j, nfunk = 0;
|
||||||
int ihi, ilo, ise;
|
int ihi, ilo, ise;
|
||||||
double *ptry, *pmid, *psum;
|
double *ptry, *pmid, *psum;
|
||||||
double tol, ytry, rtol, ysave;
|
double tol, ytry, rtol, ysave;
|
||||||
double *vector_sum (double **, int);
|
double *vector_sum (double **, int);
|
||||||
double dsmod(double **,double *,double *,int,double (*func)(double *),int,double);
|
double dsmod (double **, double *, double *, int, double (*func) (double *),
|
||||||
|
int, double);
|
||||||
|
|
||||||
// Allocate memory
|
// Allocate memory
|
||||||
psum = (double *) malloc (sizeof (double) * n);
|
psum = (double *) malloc (sizeof (double) * n);
|
||||||
|
@ -27,26 +29,34 @@ int dsmin(double **p,double *y,int n,double ftol,double (*func)(double *))
|
||||||
psum = vector_sum (p, n);
|
psum = vector_sum (p, n);
|
||||||
|
|
||||||
// Start forever loop
|
// Start forever loop
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
// Find high and low point
|
// Find high and low point
|
||||||
ilo = 0;
|
ilo = 0;
|
||||||
ihi = (y[0] > y[1]) ? (ise = 1, 0) : (ise = 0, 1);
|
ihi = (y[0] > y[1]) ? (ise = 1, 0) : (ise = 0, 1);
|
||||||
for (i=0;i<=n;i++) {
|
for (i = 0; i <= n; i++)
|
||||||
if (y[i]<=y[ilo]) ilo=i;
|
{
|
||||||
if (y[i]>y[ihi]) {
|
if (y[i] <= y[ilo])
|
||||||
|
ilo = i;
|
||||||
|
if (y[i] > y[ihi])
|
||||||
|
{
|
||||||
ise = ihi;
|
ise = ihi;
|
||||||
ihi = i;
|
ihi = i;
|
||||||
} else if (y[i]>y[ise] && i!=ihi) ise=i;
|
}
|
||||||
|
else if (y[i] > y[ise] && i != ihi)
|
||||||
|
ise = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute fractional range from highest to lowest point
|
// Compute fractional range from highest to lowest point
|
||||||
rtol=2.0*fabs(y[ihi]-y[ilo])/(fabs(y[ihi])+fabs(y[ilo])+TINY);
|
rtol =
|
||||||
|
2.0 * fabs (y[ihi] - y[ilo]) / (fabs (y[ihi]) + fabs (y[ilo]) + TINY);
|
||||||
|
|
||||||
// Return if fractional tolerance is acceptable
|
// Return if fractional tolerance is acceptable
|
||||||
if (rtol < ftol)
|
if (rtol < ftol)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (nfunk>=NMAX) {
|
if (nfunk >= NMAX)
|
||||||
|
{
|
||||||
printf ("dsmin: NMAX exceeded!\n");
|
printf ("dsmin: NMAX exceeded!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -57,12 +67,16 @@ int dsmin(double **p,double *y,int n,double ftol,double (*func)(double *))
|
||||||
|
|
||||||
if (ytry <= y[ilo]) // Goes right direction, extrapolate by factor 2
|
if (ytry <= y[ilo]) // Goes right direction, extrapolate by factor 2
|
||||||
ytry = dsmod (p, y, psum, n, func, ihi, 2.0);
|
ytry = dsmod (p, y, psum, n, func, ihi, 2.0);
|
||||||
else if (ytry>=y[ise]) { // 1D contraction
|
else if (ytry >= y[ise])
|
||||||
|
{ // 1D contraction
|
||||||
ysave = y[ihi];
|
ysave = y[ihi];
|
||||||
ytry = dsmod (p, y, psum, n, func, ihi, 0.5);
|
ytry = dsmod (p, y, psum, n, func, ihi, 0.5);
|
||||||
if (ytry>=ysave) {
|
if (ytry >= ysave)
|
||||||
for (i=0;i<=n;i++) {
|
{
|
||||||
if (i!=ilo) {
|
for (i = 0; i <= n; i++)
|
||||||
|
{
|
||||||
|
if (i != ilo)
|
||||||
|
{
|
||||||
for (j = 0; j < n; j++)
|
for (j = 0; j < n; j++)
|
||||||
p[i][j] = psum[j] = 0.5 * (p[i][j] + p[ilo][j]);
|
p[i][j] = psum[j] = 0.5 * (p[i][j] + p[ilo][j]);
|
||||||
y[i] = (*func) (psum);
|
y[i] = (*func) (psum);
|
||||||
|
@ -72,7 +86,9 @@ int dsmin(double **p,double *y,int n,double ftol,double (*func)(double *))
|
||||||
|
|
||||||
psum = vector_sum (p, n);
|
psum = vector_sum (p, n);
|
||||||
}
|
}
|
||||||
} else --nfunk;
|
}
|
||||||
|
else
|
||||||
|
--nfunk;
|
||||||
}
|
}
|
||||||
free (psum);
|
free (psum);
|
||||||
|
|
||||||
|
@ -80,14 +96,16 @@ int dsmin(double **p,double *y,int n,double ftol,double (*func)(double *))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sum vectors
|
// Sum vectors
|
||||||
double *vector_sum(double **p,int n)
|
double *
|
||||||
|
vector_sum (double **p, int n)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
double sum, *psum;
|
double sum, *psum;
|
||||||
|
|
||||||
psum = (double *) malloc (sizeof (double) * n);
|
psum = (double *) malloc (sizeof (double) * n);
|
||||||
|
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
sum = 0.;
|
sum = 0.;
|
||||||
for (j = 0; j <= n; j++)
|
for (j = 0; j <= n; j++)
|
||||||
sum += p[j][i];
|
sum += p[j][i];
|
||||||
|
@ -98,7 +116,9 @@ double *vector_sum(double **p,int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simplex modification
|
// Simplex modification
|
||||||
double dsmod(double **p,double *y,double *psum,int n,double (*func)(double *),int ihi,double fac)
|
double
|
||||||
|
dsmod (double **p, double *y, double *psum, int n, double (*func) (double *),
|
||||||
|
int ihi, double fac)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double fac1, fac2, ytry, *ptry;
|
double fac1, fac2, ytry, *ptry;
|
||||||
|
@ -110,9 +130,11 @@ double dsmod(double **p,double *y,double *psum,int n,double (*func)(double *),in
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
ptry[i] = psum[i] * fac1 - p[ihi][i] * fac2;
|
ptry[i] = psum[i] * fac1 - p[ihi][i] * fac2;
|
||||||
ytry = (*func) (ptry);
|
ytry = (*func) (ptry);
|
||||||
if (ytry<y[ihi]) {
|
if (ytry < y[ihi])
|
||||||
|
{
|
||||||
y[ihi] = ytry;
|
y[ihi] = ytry;
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
psum[i] += ptry[i] - p[ihi][i];
|
psum[i] += ptry[i] - p[ihi][i];
|
||||||
p[ihi][i] = ptry[i];
|
p[ihi][i] = ptry[i];
|
||||||
}
|
}
|
||||||
|
|
182
src/fakeiod.c
182
src/fakeiod.c
|
@ -18,7 +18,8 @@ long Isat=0;
|
||||||
long Isatsel = 0;
|
long Isatsel = 0;
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
struct site {
|
struct site
|
||||||
|
{
|
||||||
int id;
|
int id;
|
||||||
double lng, lat;
|
double lng, lat;
|
||||||
float alt;
|
float alt;
|
||||||
|
@ -30,14 +31,18 @@ double modulo(double x,double y);
|
||||||
double gmst (double mjd);
|
double gmst (double mjd);
|
||||||
double dgmst (double mjd);
|
double dgmst (double mjd);
|
||||||
double date2mjd (int year, int month, double day);
|
double date2mjd (int year, int month, double day);
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de);
|
void precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
void obspos_xyz(double mjd,double lng,double lat,float alt,xyz_t *pos,xyz_t *vel);
|
double *de);
|
||||||
|
void obspos_xyz (double mjd, double lng, double lat, float alt, xyz_t * pos,
|
||||||
|
xyz_t * vel);
|
||||||
void mjd2date (double mjd, char *date);
|
void mjd2date (double mjd, char *date);
|
||||||
double nfd2mjd (char *date);
|
double nfd2mjd (char *date);
|
||||||
void dec2s (double x, char *s, int type);
|
void dec2s (double x, char *s, int type);
|
||||||
double doy2mjd (int year, double doy);
|
double doy2mjd (int year, double doy);
|
||||||
|
|
||||||
void compute_position(double mjd,xyz_t satpos,struct site s,int satno,char *desig,int precess_flag)
|
void
|
||||||
|
compute_position (double mjd, xyz_t satpos, struct site s, int satno,
|
||||||
|
char *desig, int precess_flag)
|
||||||
{
|
{
|
||||||
char sra[15], sde[15], nfd[32];
|
char sra[15], sde[15], nfd[32];
|
||||||
xyz_t obspos, obsvel;
|
xyz_t obspos, obsvel;
|
||||||
|
@ -58,9 +63,12 @@ void compute_position(double mjd,xyz_t satpos,struct site s,int satno,char *desi
|
||||||
de = asin (dz / r) * R2D;
|
de = asin (dz / r) * R2D;
|
||||||
|
|
||||||
// Precess position
|
// Precess position
|
||||||
if (precess_flag==1) {
|
if (precess_flag == 1)
|
||||||
|
{
|
||||||
precess (mjd, ra, de, mjd0, &ra0, &de0);
|
precess (mjd, ra, de, mjd0, &ra0, &de0);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ra0 = ra;
|
ra0 = ra;
|
||||||
de0 = de;
|
de0 = de;
|
||||||
}
|
}
|
||||||
|
@ -73,12 +81,14 @@ void compute_position(double mjd,xyz_t satpos,struct site s,int satno,char *desi
|
||||||
mjd2date (mjd, nfd);
|
mjd2date (mjd, nfd);
|
||||||
|
|
||||||
// Format output
|
// Format output
|
||||||
printf("%05d %.2s %-6s %04d G %s 17 25 %s%s 37 S\n",satno,desig,desig+2,s.id,nfd,sra,sde);
|
printf ("%05d %.2s %-6s %04d G %s 17 25 %s%s 37 S\n", satno, desig,
|
||||||
|
desig + 2, s.id, nfd, sra, sde);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0, satno = 99999;
|
int arg = 0, satno = 99999;
|
||||||
struct site s;
|
struct site s;
|
||||||
|
@ -93,15 +103,20 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Get site
|
// Get site
|
||||||
env = getenv ("ST_COSPAR");
|
env = getenv ("ST_COSPAR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
s = get_site (atoi (env));
|
s = get_site (atoi (env));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_COSPAR environment variable not found.\n");
|
printf ("ST_COSPAR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"t:c:i:s:f:p:d:m:gP"))!=-1) {
|
while ((arg = getopt (argc, argv, "t:c:i:s:f:p:d:m:gP")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (nfd, optarg);
|
strcpy (nfd, optarg);
|
||||||
|
@ -152,7 +167,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get start mjd for finding elset
|
// Get start mjd for finding elset
|
||||||
if (usefile==1 && usepos==0) {
|
if (usefile == 1 && usepos == 0)
|
||||||
|
{
|
||||||
file = fopen (fname, "r");
|
file = fopen (fname, "r");
|
||||||
fgetline (file, line, LIM);
|
fgetline (file, line, LIM);
|
||||||
status = sscanf (line, "%lf", &mjd);
|
status = sscanf (line, "%lf", &mjd);
|
||||||
|
@ -160,55 +176,76 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open catalog
|
// Open catalog
|
||||||
if (usepos==0) {
|
if (usepos == 0)
|
||||||
|
{
|
||||||
file = fopen (tlefile, "r");
|
file = fopen (tlefile, "r");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
fatal_error ("Failed to open %s\n", tlefile);
|
fatal_error ("Failed to open %s\n", tlefile);
|
||||||
|
|
||||||
// Read TLE
|
// Read TLE
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
status = read_twoline (file, satno, &orb);
|
status = read_twoline (file, satno, &orb);
|
||||||
} while (doy2mjd(orb.ep_year,orb.ep_day)<mjd && status!=-1);
|
}
|
||||||
|
while (doy2mjd (orb.ep_year, orb.ep_day) < mjd && status != -1);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
// Check for match
|
// Check for match
|
||||||
if (orb.satno!=satno) {
|
if (orb.satno != satno)
|
||||||
|
{
|
||||||
// fprintf(stderr,"object %d not found in %s\n",p.satno,filename);
|
// fprintf(stderr,"object %d not found in %s\n",p.satno,filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
if (imode==SGDP4_ERROR) {
|
if (imode == SGDP4_ERROR)
|
||||||
|
{
|
||||||
fprintf (stderr, "Error initializing SGDP4\n");
|
fprintf (stderr, "Error initializing SGDP4\n");
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute
|
// Compute
|
||||||
if (usefile==0) {
|
if (usefile == 0)
|
||||||
|
{
|
||||||
satpos_xyz (mjd + 2400000.5, &satpos, &satvel);
|
satpos_xyz (mjd + 2400000.5, &satpos, &satvel);
|
||||||
compute_position(mjd,satpos,s,orb.satno,orb.desig,precess_flag);
|
compute_position (mjd, satpos, s, orb.satno, orb.desig,
|
||||||
} else {
|
precess_flag);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
file = fopen (fname, "r");
|
file = fopen (fname, "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
status = sscanf (line, "%lf", &mjd);
|
status = sscanf (line, "%lf", &mjd);
|
||||||
satpos_xyz (mjd + 2400000.5, &satpos, &satvel);
|
satpos_xyz (mjd + 2400000.5, &satpos, &satvel);
|
||||||
strcpy (orb.desig, "14999A"); // FIX!
|
strcpy (orb.desig, "14999A"); // FIX!
|
||||||
compute_position(mjd,satpos,s,orb.satno,orb.desig,precess_flag);
|
compute_position (mjd, satpos, s, orb.satno, orb.desig,
|
||||||
|
precess_flag);
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
file = fopen (fname, "r");
|
file = fopen (fname, "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
if (!isdigit (line[0]))
|
if (!isdigit (line[0]))
|
||||||
continue;
|
continue;
|
||||||
if (line[10]=='T') {
|
if (line[10] == 'T')
|
||||||
status=sscanf(line,"%s %lf %lf %lf",nfd,&satpos.x,&satpos.y,&satpos.z);
|
{
|
||||||
|
status =
|
||||||
|
sscanf (line, "%s %lf %lf %lf", nfd, &satpos.x, &satpos.y,
|
||||||
|
&satpos.z);
|
||||||
mjd = nfd2mjd (nfd);
|
mjd = nfd2mjd (nfd);
|
||||||
} else {
|
}
|
||||||
status=sscanf(line,"%lf %lf %lf %lf",&mjd,&satpos.x,&satpos.y,&satpos.z);
|
else
|
||||||
|
{
|
||||||
|
status =
|
||||||
|
sscanf (line, "%lf %lf %lf %lf", &mjd, &satpos.x, &satpos.y,
|
||||||
|
&satpos.z);
|
||||||
if (gmat == 1)
|
if (gmat == 1)
|
||||||
mjd += 29999.5;
|
mjd += 29999.5;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +257,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
struct site get_site(int site_id)
|
struct site
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -235,11 +273,13 @@ struct site get_site(int site_id)
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
sprintf (filename, "%s/data/sites.txt", env);
|
sprintf (filename, "%s/data/sites.txt", env);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -248,15 +288,15 @@ struct site get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
// Copy site
|
// Copy site
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
s.lat = lat;
|
s.lat = lat;
|
||||||
s.lng = lng;
|
s.lng = lng;
|
||||||
s.alt = alt;
|
s.alt = alt;
|
||||||
|
@ -269,29 +309,36 @@ struct site get_site(int site_id)
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double dgmst(double mjd)
|
double
|
||||||
|
dgmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, dgmst;
|
double t, dgmst;
|
||||||
|
|
||||||
|
@ -303,7 +350,9 @@ double dgmst(double mjd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observer position
|
// Observer position
|
||||||
void obspos_xyz(double mjd,double lng,double lat,float alt,xyz_t *pos,xyz_t *vel)
|
void
|
||||||
|
obspos_xyz (double mjd, double lng, double lat, float alt, xyz_t * pos,
|
||||||
|
xyz_t * vel)
|
||||||
{
|
{
|
||||||
double ff, gc, gs, theta, s, dtheta;
|
double ff, gc, gs, theta, s, dtheta;
|
||||||
|
|
||||||
|
@ -326,7 +375,9 @@ void obspos_xyz(double mjd,double lng,double lat,float alt,xyz_t *pos,xyz_t *vel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precess a celestial position
|
// Precess a celestial position
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
void
|
||||||
|
precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
double zeta, z, theta;
|
double zeta, z, theta;
|
||||||
|
@ -367,7 +418,8 @@ void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -382,12 +434,14 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -395,17 +449,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date)
|
void
|
||||||
|
mjd2date (double mjd, char *date)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -420,7 +480,8 @@ void mjd2date(double mjd,char *date)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -450,19 +511,22 @@ void mjd2date(double mjd,char *date)
|
||||||
hour = x;
|
hour = x;
|
||||||
sec = floor (1000.0 * sec) / 1000.0;
|
sec = floor (1000.0 * sec) / 1000.0;
|
||||||
|
|
||||||
sprintf(date,"%04d%02d%02d%02d%02d%05.0f",year,month,day,hour,min,sec*1000);
|
sprintf (date, "%04d%02d%02d%02d%02d%05.0f", year, month, day, hour, min,
|
||||||
|
sec * 1000);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min;
|
int year, month, day, hour, min;
|
||||||
float sec;
|
float sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%f",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%f", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -471,7 +535,8 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Decimal into Sexagesimal
|
// Convert Decimal into Sexagesimal
|
||||||
void dec2s(double x,char *s,int type)
|
void
|
||||||
|
dec2s (double x, char *s, int type)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double sec, deg, min, fmin;
|
double sec, deg, min, fmin;
|
||||||
|
@ -498,7 +563,8 @@ void dec2s(double x,char *s,int type)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOY to MJD
|
// DOY to MJD
|
||||||
double doy2mjd(int year,double doy)
|
double
|
||||||
|
doy2mjd (int year, double doy)
|
||||||
{
|
{
|
||||||
int month, k = 2;
|
int month, k = 2;
|
||||||
double day;
|
double day;
|
||||||
|
@ -511,7 +577,9 @@ double doy2mjd(int year,double doy)
|
||||||
if (doy < 32)
|
if (doy < 32)
|
||||||
month = 1;
|
month = 1;
|
||||||
|
|
||||||
day=doy-floor(275.0*month/9.0)+k*floor((month+9.0)/12.0)+30.0;
|
day =
|
||||||
|
doy - floor (275.0 * month / 9.0) + k * floor ((month + 9.0) / 12.0) +
|
||||||
|
30.0;
|
||||||
|
|
||||||
return date2mjd (year, month, day);
|
return date2mjd (year, month, day);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
#define D2R M_PI/180.0
|
#define D2R M_PI/180.0
|
||||||
|
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
void orbit(orbit_t orb,float *aodp,float *perigee,float *apogee,float *period);
|
void orbit (orbit_t orb, float *aodp, float *perigee, float *apogee,
|
||||||
|
float *period);
|
||||||
void format_tle (orbit_t orb, char *line1, char *line2);
|
void format_tle (orbit_t orb, char *line1, char *line2);
|
||||||
double mjd2doy (double mjd, int *yr);
|
double mjd2doy (double mjd, int *yr);
|
||||||
double nfd2mjd (char *date);
|
double nfd2mjd (char *date);
|
||||||
|
@ -25,7 +26,8 @@ void mjd2date(double mjd,int *year,int *month,double *day);
|
||||||
double gmst (double mjd);
|
double gmst (double mjd);
|
||||||
double modulo (double x, double y);
|
double modulo (double x, double y);
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf ("faketle q:Q:i:I:w:t:m:n:d:\n\n");
|
printf ("faketle q:Q:i:I:w:t:m:n:d:\n\n");
|
||||||
|
|
||||||
|
@ -42,7 +44,8 @@ void usage(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
orbit_t orb;
|
orbit_t orb;
|
||||||
float aodp, perigee, apogee, period, dt = 0.0;
|
float aodp, perigee, apogee, period, dt = 0.0;
|
||||||
|
@ -61,8 +64,10 @@ int main(int argc,char *argv[])
|
||||||
orb.ep_year = 2013;
|
orb.ep_year = 2013;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"q:Q:i:I:w:t:m:n:hd:"))!=-1) {
|
while ((arg = getopt (argc, argv, "q:Q:i:I:w:t:m:n:hd:")) != -1)
|
||||||
switch(arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
case 'q':
|
case 'q':
|
||||||
perigee = atof (optarg);
|
perigee = atof (optarg);
|
||||||
break;
|
break;
|
||||||
|
@ -126,7 +131,8 @@ int main(int argc,char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void orbit(orbit_t orb,float *aodp,float *perigee,float *apogee,float *period)
|
void
|
||||||
|
orbit (orbit_t orb, float *aodp, float *perigee, float *apogee, float *period)
|
||||||
{
|
{
|
||||||
float xno, eo, xincl;
|
float xno, eo, xincl;
|
||||||
float a1, betao2, betao, temp0, del1, a0, del0, xnodp;
|
float a1, betao2, betao, temp0, del1, a0, del0, xnodp;
|
||||||
|
@ -153,30 +159,45 @@ void orbit(orbit_t orb,float *aodp,float *perigee,float *apogee,float *period)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1,
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev);
|
"1 %05dU %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
|
orb.satno, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -188,12 +209,14 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -202,12 +225,14 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -215,17 +240,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -235,7 +266,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -243,7 +275,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -256,7 +289,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -280,22 +314,27 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
void fatal_error(const char *format, ...)
|
void
|
||||||
|
fatal_error (const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,15 @@
|
||||||
int fgetline (FILE *, char *, int);
|
int fgetline (FILE *, char *, int);
|
||||||
void rtrim (char *);
|
void rtrim (char *);
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
FILE *fitsfile;
|
FILE *fitsfile;
|
||||||
|
|
||||||
// Usage
|
// Usage
|
||||||
if (argc<2) {
|
if (argc < 2)
|
||||||
|
{
|
||||||
printf ("Usage: %s <fitsfile>\n", argv[0]);
|
printf ("Usage: %s <fitsfile>\n", argv[0]);
|
||||||
printf ("\n\nOutputs the header of <fitsfile>\n");
|
printf ("\n\nOutputs the header of <fitsfile>\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -24,10 +26,12 @@ int main(int argc,char *argv[])
|
||||||
fitsfile = fopen (argv[1], "r");
|
fitsfile = fopen (argv[1], "r");
|
||||||
|
|
||||||
// Loop over file and output
|
// Loop over file and output
|
||||||
while (fgetline(fitsfile,line,LIM)>0) {
|
while (fgetline (fitsfile, line, LIM) > 0)
|
||||||
|
{
|
||||||
rtrim (line);
|
rtrim (line);
|
||||||
printf ("%s\n", line);
|
printf ("%s\n", line);
|
||||||
if (strcmp(line,"END")==0) break;
|
if (strcmp (line, "END") == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close file
|
// Close file
|
||||||
|
@ -37,7 +41,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -50,14 +55,16 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes trailing blanks from string s
|
// Removes trailing blanks from string s
|
||||||
void rtrim(char *s)
|
void
|
||||||
|
rtrim (char *s)
|
||||||
{
|
{
|
||||||
int i, j = 0, n;
|
int i, j = 0, n;
|
||||||
|
|
||||||
n = strlen (s);
|
n = strlen (s);
|
||||||
for (i = n; i >= 0; i--)
|
for (i = n; i >= 0; i--)
|
||||||
if (s[i] != '\0' && s[i] != '\n')
|
if (s[i] != '\0' && s[i] != '\n')
|
||||||
if (!isspace(s[i]) && j==0) j=i;
|
if (!isspace (s[i]) && j == 0)
|
||||||
|
j = i;
|
||||||
s[++j] = '\0';
|
s[++j] = '\0';
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,29 +4,35 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "qfits.h"
|
#include "qfits.h"
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char keyword[FITS_LINESZ + 1];
|
char keyword[FITS_LINESZ + 1];
|
||||||
char *value;
|
char *value;
|
||||||
|
|
||||||
// Usage
|
// Usage
|
||||||
if (argc<3) {
|
if (argc < 3)
|
||||||
|
{
|
||||||
printf ("Usage: %s <filename> [ext] <key1> <key2> etc.\n", argv[0]);
|
printf ("Usage: %s <filename> [ext] <key1> <key2> etc.\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check this is indeed a FITS file
|
// Check this is indeed a FITS file
|
||||||
if (is_fits_file(argv[1])!=1) {
|
if (is_fits_file (argv[1]) != 1)
|
||||||
|
{
|
||||||
printf ("%s is not a FITS file\n", argv[1]);
|
printf ("%s is not a FITS file\n", argv[1]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extension header?
|
// Extension header?
|
||||||
if (atoi(argv[2])==0) {
|
if (atoi (argv[2]) == 0)
|
||||||
|
{
|
||||||
for (i = 2; i < argc; i++)
|
for (i = 2; i < argc; i++)
|
||||||
printf ("%s ", qfits_query_hdr (argv[1], argv[i]));
|
printf ("%s ", qfits_query_hdr (argv[1], argv[i]));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (i = 3; i < argc; i++)
|
for (i = 3; i < argc; i++)
|
||||||
printf ("%s ", qfits_query_ext (argv[1], argv[i], atoi (argv[2])));
|
printf ("%s ", qfits_query_ext (argv[1], argv[i], atoi (argv[2])));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#include <wcslib/cel.h>
|
#include <wcslib/cel.h>
|
||||||
|
|
||||||
// Get a x and y from a RA and Decl
|
// Get a x and y from a RA and Decl
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y)
|
void
|
||||||
|
forward (double ra0, double de0, double ra, double de, double *x, double *y)
|
||||||
{
|
{
|
||||||
int i, status;
|
int i, status;
|
||||||
double phi, theta;
|
double phi, theta;
|
||||||
|
@ -19,7 +20,8 @@ void forward(double ra0,double de0,double ra,double de,double *x,double *y)
|
||||||
cel.flag = 0.;
|
cel.flag = 0.;
|
||||||
strcpy (cel.prj.code, "STG");
|
strcpy (cel.prj.code, "STG");
|
||||||
|
|
||||||
if (celset(&cel)) {
|
if (celset (&cel))
|
||||||
|
{
|
||||||
printf ("Error in Projection (celset)\n");
|
printf ("Error in Projection (celset)\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
83
src/geolon.c
83
src/geolon.c
|
@ -14,7 +14,8 @@
|
||||||
long Isat = 0;
|
long Isat = 0;
|
||||||
long Isatsel = 0;
|
long Isatsel = 0;
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
long satno;
|
long satno;
|
||||||
double mjd;
|
double mjd;
|
||||||
char nfd[LIM], tlefile[LIM], observer[32];
|
char nfd[LIM], tlefile[LIM], observer[32];
|
||||||
|
@ -23,12 +24,14 @@ struct map {
|
||||||
|
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -36,22 +39,29 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -59,7 +69,8 @@ double nfd2mjd(char *date)
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage()
|
void
|
||||||
|
usage ()
|
||||||
{
|
{
|
||||||
printf ("Usage goes here.\n");
|
printf ("Usage goes here.\n");
|
||||||
|
|
||||||
|
@ -68,28 +79,34 @@ void usage()
|
||||||
|
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -98,13 +115,16 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute longitude
|
// Compute longitude
|
||||||
void compute_longitude(char *tlefile,long satno,double mjd)
|
void
|
||||||
|
compute_longitude (char *tlefile, long satno, double mjd)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
orbit_t orb;
|
orbit_t orb;
|
||||||
|
@ -118,10 +138,12 @@ void compute_longitude(char *tlefile,long satno,double mjd)
|
||||||
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
||||||
|
|
||||||
// Loop over elements
|
// Loop over elements
|
||||||
while(read_twoline(fp, satno, &orb) == 0) {
|
while (read_twoline (fp, satno, &orb) == 0)
|
||||||
|
{
|
||||||
Isat = orb.satno;
|
Isat = orb.satno;
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
if(imode == SGDP4_ERROR) continue;
|
if (imode == SGDP4_ERROR)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Skip objects with mean motions outside of 0.8 to 1.2 revs/day
|
// Skip objects with mean motions outside of 0.8 to 1.2 revs/day
|
||||||
if (orb.rev < 0.8 || orb.rev > 1.2)
|
if (orb.rev < 0.8 || orb.rev > 1.2)
|
||||||
|
@ -137,7 +159,9 @@ void compute_longitude(char *tlefile,long satno,double mjd)
|
||||||
h = gmst (mjd);
|
h = gmst (mjd);
|
||||||
|
|
||||||
// Celestial position
|
// Celestial position
|
||||||
r=sqrt(satpos.x*satpos.x+satpos.y*satpos.y+satpos.z*satpos.z);
|
r =
|
||||||
|
sqrt (satpos.x * satpos.x + satpos.y * satpos.y +
|
||||||
|
satpos.z * satpos.z);
|
||||||
l = atan2 (satpos.y, satpos.x) * R2D;
|
l = atan2 (satpos.y, satpos.x) * R2D;
|
||||||
l = modulo (l - h, 360.0);
|
l = modulo (l - h, 360.0);
|
||||||
b = asin (satpos.z / r) * R2D;
|
b = asin (satpos.z / r) * R2D;
|
||||||
|
@ -146,14 +170,16 @@ void compute_longitude(char *tlefile,long satno,double mjd)
|
||||||
if (l < -180.0)
|
if (l < -180.0)
|
||||||
l += 360.0;
|
l += 360.0;
|
||||||
|
|
||||||
printf("%05d %10s %8.3lf %8.3lf %6.0lf\n",orb.satno,orb.desig,l,b,r-XKMPER);
|
printf ("%05d %10s %8.3lf %8.3lf %6.0lf\n", orb.satno, orb.desig, l, b,
|
||||||
|
r - XKMPER);
|
||||||
}
|
}
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0;
|
int arg = 0;
|
||||||
long satno = 0;
|
long satno = 0;
|
||||||
|
@ -165,9 +191,12 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
if (argc>1) {
|
if (argc > 1)
|
||||||
while ((arg=getopt(argc,argv,"t:c:i:h"))!=-1) {
|
{
|
||||||
switch (arg) {
|
while ((arg = getopt (argc, argv, "t:c:i:h")) != -1)
|
||||||
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (nfd, optarg);
|
strcpy (nfd, optarg);
|
||||||
|
@ -192,7 +221,9 @@ int main(int argc,char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
usage ();
|
usage ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
#define D2R M_PI/180.0
|
#define D2R M_PI/180.0
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
|
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
char filename[64];
|
char filename[64];
|
||||||
int naxis1, naxis2;
|
int naxis1, naxis2;
|
||||||
float *zavg;
|
float *zavg;
|
||||||
|
@ -20,7 +21,8 @@ struct image {
|
||||||
char nfd[32];
|
char nfd[32];
|
||||||
int cospar;
|
int cospar;
|
||||||
};
|
};
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
char datadir[LIM], observer[32];
|
char datadir[LIM], observer[32];
|
||||||
double lng, lat;
|
double lng, lat;
|
||||||
float alt;
|
float alt;
|
||||||
|
@ -29,28 +31,35 @@ struct map {
|
||||||
struct image read_fits (char *filename);
|
struct image read_fits (char *filename);
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precess a celestial position
|
// Precess a celestial position
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
void
|
||||||
|
precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
double zeta, z, theta;
|
double zeta, z, theta;
|
||||||
|
@ -91,7 +100,8 @@ void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -103,11 +113,13 @@ void get_site(int site_id)
|
||||||
|
|
||||||
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -116,14 +128,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
@ -138,19 +150,28 @@ void get_site(int site_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert equatorial into horizontal coordinates
|
// Convert equatorial into horizontal coordinates
|
||||||
void equatorial2horizontal(double mjd,double ra,double de,double *azi,double *alt)
|
void
|
||||||
|
equatorial2horizontal (double mjd, double ra, double de, double *azi,
|
||||||
|
double *alt)
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
|
|
||||||
h = gmst (mjd) + m.lng - ra;
|
h = gmst (mjd) + m.lng - ra;
|
||||||
|
|
||||||
*azi=modulo(atan2(sin(h*D2R),cos(h*D2R)*sin(m.lat*D2R)-tan(de*D2R)*cos(m.lat*D2R))*R2D,360.0);
|
*azi =
|
||||||
*alt=asin(sin(m.lat*D2R)*sin(de*D2R)+cos(m.lat*D2R)*cos(de*D2R)*cos(h*D2R))*R2D;
|
modulo (atan2
|
||||||
|
(sin (h * D2R),
|
||||||
|
cos (h * D2R) * sin (m.lat * D2R) -
|
||||||
|
tan (de * D2R) * cos (m.lat * D2R)) * R2D, 360.0);
|
||||||
|
*alt =
|
||||||
|
asin (sin (m.lat * D2R) * sin (de * D2R) +
|
||||||
|
cos (m.lat * D2R) * cos (de * D2R) * cos (h * D2R)) * R2D;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct image img;
|
struct image img;
|
||||||
|
@ -160,9 +181,12 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Get environment variables
|
// Get environment variables
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (m.datadir, env);
|
strcpy (m.datadir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_DATADIR environment variable not found.\n");
|
printf ("ST_DATADIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,13 +216,16 @@ int main(int argc,char *argv[])
|
||||||
// Get horizontal coordinates
|
// Get horizontal coordinates
|
||||||
equatorial2horizontal (img.mjd, ra, de, &azi, &alt);
|
equatorial2horizontal (img.mjd, ra, de, &azi, &alt);
|
||||||
azi = modulo (azi + 180, 360);
|
azi = modulo (azi + 180, 360);
|
||||||
printf("%s %14.8lf %10.6f %10.6f %10.6f %10.6f %.2f %.2f %.1f %.1f\n",argv[1],img.mjd,img.ra0,img.de0,azi,alt,img.xrms,img.yrms,zavg,zstd);
|
printf ("%s %14.8lf %10.6f %10.6f %10.6f %10.6f %.2f %.2f %.1f %.1f\n",
|
||||||
|
argv[1], img.mjd, img.ra0, img.de0, azi, alt, img.xrms, img.yrms,
|
||||||
|
zavg, zstd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename)
|
struct image
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -261,8 +288,10 @@ struct image read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
img.zavg[l] = ql.fbuf[l];
|
img.zavg[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
|
@ -270,4 +299,3 @@ struct image read_fits(char *filename)
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
124
src/jpg2fits.c
124
src/jpg2fits.c
|
@ -7,7 +7,8 @@
|
||||||
#include <libexif/exif-data.h>
|
#include <libexif/exif-data.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int nx, ny, nz;
|
int nx, ny, nz;
|
||||||
float *z;
|
float *z;
|
||||||
double mjd;
|
double mjd;
|
||||||
|
@ -22,7 +23,8 @@ double nfd2mjd(char *date);
|
||||||
void mjd2nfd (double mjd, char *nfd);
|
void mjd2nfd (double mjd, char *nfd);
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename)
|
struct image
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -57,8 +59,10 @@ struct image read_fits(char *filename)
|
||||||
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0,m=0;i<img.nx;i++) {
|
for (i = 0, l = 0, m = 0; i < img.nx; i++)
|
||||||
for (j=0;j<img.ny;j++) {
|
{
|
||||||
|
for (j = 0; j < img.ny; j++)
|
||||||
|
{
|
||||||
img.z[l] = ql.fbuf[l];
|
img.z[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +72,8 @@ struct image read_fits(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct image rebin(struct image raw,int nbin)
|
struct image
|
||||||
|
rebin (struct image raw, int nbin)
|
||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
int ii, jj, kk;
|
int ii, jj, kk;
|
||||||
|
@ -79,12 +84,16 @@ struct image rebin(struct image raw,int nbin)
|
||||||
img.nz = 1;
|
img.nz = 1;
|
||||||
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
||||||
|
|
||||||
for (i=0;i<img.nx;i++) {
|
for (i = 0; i < img.nx; i++)
|
||||||
for (j=0;j<img.ny;j++) {
|
{
|
||||||
|
for (j = 0; j < img.ny; j++)
|
||||||
|
{
|
||||||
k = i + img.nx * j;
|
k = i + img.nx * j;
|
||||||
img.z[k] = 0.0;
|
img.z[k] = 0.0;
|
||||||
for (ii=0;ii<nbin;ii++) {
|
for (ii = 0; ii < nbin; ii++)
|
||||||
for (jj=0;jj<nbin;jj++) {
|
{
|
||||||
|
for (jj = 0; jj < nbin; jj++)
|
||||||
|
{
|
||||||
kk = ii + nbin * i + raw.nx * (jj + nbin * j);
|
kk = ii + nbin * i + raw.nx * (jj + nbin * j);
|
||||||
img.z[k] += raw.z[kk];
|
img.z[k] += raw.z[kk];
|
||||||
}
|
}
|
||||||
|
@ -101,7 +110,8 @@ struct image rebin(struct image raw,int nbin)
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf ("jpg2fits i:t:o:d:Z:c:T:O:b:hF\n\n");
|
printf ("jpg2fits i:t:o:d:Z:c:T:O:b:hF\n\n");
|
||||||
printf ("-i input JPG file\n");
|
printf ("-i input JPG file\n");
|
||||||
|
@ -121,7 +131,8 @@ void usage(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg;
|
int arg;
|
||||||
struct image img, raw;
|
struct image img, raw;
|
||||||
|
@ -133,9 +144,12 @@ int main(int argc,char *argv[])
|
||||||
int flag = 0, nbin = 1, readfits = 0, tracked = 0;
|
int flag = 0, nbin = 1, readfits = 0, tracked = 0;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
if (argc>1) {
|
if (argc > 1)
|
||||||
while ((arg=getopt(argc,argv,"i:t:o:d:Z:c:T:O:b:hFs"))!=-1) {
|
{
|
||||||
switch(arg) {
|
while ((arg = getopt (argc, argv, "i:t:o:d:Z:c:T:O:b:hFs")) != -1)
|
||||||
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
tracked = 1;
|
tracked = 1;
|
||||||
|
@ -192,17 +206,23 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infile!=NULL) {
|
if (infile != NULL)
|
||||||
if (nbin==1) {
|
{
|
||||||
|
if (nbin == 1)
|
||||||
|
{
|
||||||
if (readfits == 0)
|
if (readfits == 0)
|
||||||
img = read_jpg (infile);
|
img = read_jpg (infile);
|
||||||
else
|
else
|
||||||
img = read_fits (infile);
|
img = read_fits (infile);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (readfits == 0)
|
if (readfits == 0)
|
||||||
raw = read_jpg (infile);
|
raw = read_jpg (infile);
|
||||||
else
|
else
|
||||||
|
@ -217,7 +237,8 @@ int main(int argc,char *argv[])
|
||||||
else
|
else
|
||||||
img.tracked = 0;
|
img.tracked = 0;
|
||||||
|
|
||||||
if (nfd!=NULL) {
|
if (nfd != NULL)
|
||||||
|
{
|
||||||
// Compute time
|
// Compute time
|
||||||
mjd = nfd2mjd (nfd);
|
mjd = nfd2mjd (nfd);
|
||||||
mjd += (delay + tz) / 86400.0;
|
mjd += (delay + tz) / 86400.0;
|
||||||
|
@ -247,7 +268,8 @@ int main(int argc,char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct image read_jpg(char *filename)
|
struct image
|
||||||
|
read_jpg (char *filename)
|
||||||
{
|
{
|
||||||
int i = 0, j, k, l, m;
|
int i = 0, j, k, l, m;
|
||||||
unsigned long location = 0;
|
unsigned long location = 0;
|
||||||
|
@ -273,11 +295,15 @@ struct image read_jpg(char *filename)
|
||||||
jpeg_start_decompress (&cinfo);
|
jpeg_start_decompress (&cinfo);
|
||||||
|
|
||||||
// Allocate memory
|
// Allocate memory
|
||||||
raw_image=(unsigned char *) malloc(cinfo.output_width*cinfo.output_height*cinfo.num_components);
|
raw_image =
|
||||||
|
(unsigned char *) malloc (cinfo.output_width * cinfo.output_height *
|
||||||
|
cinfo.num_components);
|
||||||
|
|
||||||
// Read image, one scan at a time
|
// Read image, one scan at a time
|
||||||
row_pointer[0]=(unsigned char *) malloc(cinfo.output_width*cinfo.num_components);
|
row_pointer[0] =
|
||||||
while(cinfo.output_scanline<cinfo.image_height) {
|
(unsigned char *) malloc (cinfo.output_width * cinfo.num_components);
|
||||||
|
while (cinfo.output_scanline < cinfo.image_height)
|
||||||
|
{
|
||||||
jpeg_read_scanlines (&cinfo, row_pointer, 1);
|
jpeg_read_scanlines (&cinfo, row_pointer, 1);
|
||||||
for (i = 0; i < cinfo.image_width * cinfo.num_components; i++)
|
for (i = 0; i < cinfo.image_width * cinfo.num_components; i++)
|
||||||
raw_image[location++] = row_pointer[0][i];
|
raw_image[location++] = row_pointer[0][i];
|
||||||
|
@ -293,11 +319,14 @@ struct image read_jpg(char *filename)
|
||||||
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
||||||
|
|
||||||
// Fill image
|
// Fill image
|
||||||
for (i=0;i<img.nx;i++) {
|
for (i = 0; i < img.nx; i++)
|
||||||
for (j=0;j<img.ny;j++) {
|
{
|
||||||
|
for (j = 0; j < img.ny; j++)
|
||||||
|
{
|
||||||
k = i + (img.ny - j - 1) * img.nx;
|
k = i + (img.ny - j - 1) * img.nx;
|
||||||
img.z[k] = 0.0;
|
img.z[k] = 0.0;
|
||||||
for (l=0;l<img.nz;l++) {
|
for (l = 0; l < img.nz; l++)
|
||||||
|
{
|
||||||
m = img.nz * (i + img.nx * j) + l;
|
m = img.nz * (i + img.nx * j) + l;
|
||||||
img.z[k] += (float) raw_image[m];
|
img.z[k] += (float) raw_image[m];
|
||||||
}
|
}
|
||||||
|
@ -331,7 +360,8 @@ struct image read_jpg(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write fits file
|
// Write fits file
|
||||||
void write_fits(struct image img,char *filename)
|
void
|
||||||
|
write_fits (struct image img, char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l;
|
int i, j, k, l;
|
||||||
int *ibuf;
|
int *ibuf;
|
||||||
|
@ -402,8 +432,10 @@ void write_fits(struct image img,char *filename)
|
||||||
|
|
||||||
// Fill buffer
|
// Fill buffer
|
||||||
ibuf = malloc (img.nx * img.ny * sizeof (int));
|
ibuf = malloc (img.nx * img.ny * sizeof (int));
|
||||||
for (i=0,l=0;i<img.nx;i++) {
|
for (i = 0, l = 0; i < img.nx; i++)
|
||||||
for (j=img.ny-1;j>=0;j--) {
|
{
|
||||||
|
for (j = img.ny - 1; j >= 0; j--)
|
||||||
|
{
|
||||||
ibuf[l] = (int) img.z[l];
|
ibuf[l] = (int) img.z[l];
|
||||||
|
|
||||||
l++;
|
l++;
|
||||||
|
@ -426,12 +458,14 @@ void write_fits(struct image img,char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -439,23 +473,30 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min;
|
int year, month, day, hour, min;
|
||||||
float sec;
|
float sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%f",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%f", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
|
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -464,7 +505,8 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2nfd(double mjd,char *nfd)
|
void
|
||||||
|
mjd2nfd (double mjd, char *nfd)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -479,7 +521,8 @@ void mjd2nfd(double mjd,char *nfd)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -509,7 +552,8 @@ void mjd2nfd(double mjd,char *nfd)
|
||||||
hour = x;
|
hour = x;
|
||||||
sec = floor (1000.0 * sec) / 1000.0;
|
sec = floor (1000.0 * sec) / 1000.0;
|
||||||
|
|
||||||
sprintf(nfd,"%04d-%02d-%02dT%02d:%02d:%06.3f",year,month,day,hour,min,sec);
|
sprintf (nfd, "%04d-%02d-%02dT%02d:%02d:%06.3f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
#define NMAX 1024
|
#define NMAX 1024
|
||||||
|
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int nx, ny, nz;
|
int nx, ny, nz;
|
||||||
float *z;
|
float *z;
|
||||||
};
|
};
|
||||||
|
@ -14,29 +15,34 @@ struct image read_jpg(char *filename);
|
||||||
void write_jpg (char *filename, struct image img);
|
void write_jpg (char *filename, struct image img);
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, flag, n;
|
int i, j, flag, n;
|
||||||
struct image avg, max, raw;
|
struct image avg, max, raw;
|
||||||
|
|
||||||
for (flag=0,i=1,n=0;i<argc;i++,n++) {
|
for (flag = 0, i = 1, n = 0; i < argc; i++, n++)
|
||||||
|
{
|
||||||
printf ("%d %s\n", i, argv[i]);
|
printf ("%d %s\n", i, argv[i]);
|
||||||
// Read image
|
// Read image
|
||||||
raw = read_jpg (argv[i]);
|
raw = read_jpg (argv[i]);
|
||||||
|
|
||||||
// If first image, initialize
|
// If first image, initialize
|
||||||
if (flag==0) {
|
if (flag == 0)
|
||||||
|
{
|
||||||
avg.nx = raw.nx;
|
avg.nx = raw.nx;
|
||||||
avg.ny = raw.ny;
|
avg.ny = raw.ny;
|
||||||
avg.nz = raw.nz;
|
avg.nz = raw.nz;
|
||||||
avg.z=(float *) malloc(sizeof(float)*avg.nx*avg.ny*avg.nz);
|
avg.z =
|
||||||
|
(float *) malloc (sizeof (float) * avg.nx * avg.ny * avg.nz);
|
||||||
for (j = 0; j < avg.nx * avg.ny * avg.nz; j++)
|
for (j = 0; j < avg.nx * avg.ny * avg.nz; j++)
|
||||||
avg.z[j] = 0.0;
|
avg.z[j] = 0.0;
|
||||||
|
|
||||||
max.nx = raw.nx;
|
max.nx = raw.nx;
|
||||||
max.ny = raw.ny;
|
max.ny = raw.ny;
|
||||||
max.nz = raw.nz;
|
max.nz = raw.nz;
|
||||||
max.z=(float *) malloc(sizeof(float)*max.nx*max.ny*max.nz);
|
max.z =
|
||||||
|
(float *) malloc (sizeof (float) * max.nx * max.ny * max.nz);
|
||||||
for (j = 0; j < max.nx * max.ny * max.nz; j++)
|
for (j = 0; j < max.nx * max.ny * max.nz; j++)
|
||||||
max.z[j] = 0.0;
|
max.z[j] = 0.0;
|
||||||
|
|
||||||
|
@ -71,7 +77,8 @@ int main(int argc,char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct image read_jpg(char *filename)
|
struct image
|
||||||
|
read_jpg (char *filename)
|
||||||
{
|
{
|
||||||
int i = 0, j, k, l, m;
|
int i = 0, j, k, l, m;
|
||||||
unsigned long location = 0;
|
unsigned long location = 0;
|
||||||
|
@ -95,11 +102,15 @@ struct image read_jpg(char *filename)
|
||||||
jpeg_start_decompress (&cinfo);
|
jpeg_start_decompress (&cinfo);
|
||||||
|
|
||||||
// Allocate memory
|
// Allocate memory
|
||||||
raw_image=(unsigned char *) malloc(cinfo.output_width*cinfo.output_height*cinfo.num_components);
|
raw_image =
|
||||||
|
(unsigned char *) malloc (cinfo.output_width * cinfo.output_height *
|
||||||
|
cinfo.num_components);
|
||||||
|
|
||||||
// Read image, one scan at a time
|
// Read image, one scan at a time
|
||||||
row_pointer[0]=(unsigned char *) malloc(cinfo.output_width*cinfo.num_components);
|
row_pointer[0] =
|
||||||
while(cinfo.output_scanline<cinfo.image_height) {
|
(unsigned char *) malloc (cinfo.output_width * cinfo.num_components);
|
||||||
|
while (cinfo.output_scanline < cinfo.image_height)
|
||||||
|
{
|
||||||
jpeg_read_scanlines (&cinfo, row_pointer, 1);
|
jpeg_read_scanlines (&cinfo, row_pointer, 1);
|
||||||
for (i = 0; i < cinfo.image_width * cinfo.num_components; i++)
|
for (i = 0; i < cinfo.image_width * cinfo.num_components; i++)
|
||||||
raw_image[location++] = row_pointer[0][i];
|
raw_image[location++] = row_pointer[0][i];
|
||||||
|
@ -115,9 +126,12 @@ struct image read_jpg(char *filename)
|
||||||
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
img.z = (float *) malloc (sizeof (float) * img.nx * img.ny * img.nz);
|
||||||
|
|
||||||
// Fill image
|
// Fill image
|
||||||
for (i=0;i<img.nx;i++) {
|
for (i = 0; i < img.nx; i++)
|
||||||
for (j=0;j<img.ny;j++) {
|
{
|
||||||
for (k=0;k<img.nz;k++) {
|
for (j = 0; j < img.ny; j++)
|
||||||
|
{
|
||||||
|
for (k = 0; k < img.nz; k++)
|
||||||
|
{
|
||||||
l = img.nz * (i + img.nx * j) + k;
|
l = img.nz * (i + img.nx * j) + k;
|
||||||
img.z[l] = (float) raw_image[l];
|
img.z[l] = (float) raw_image[l];
|
||||||
}
|
}
|
||||||
|
@ -135,7 +149,8 @@ struct image read_jpg(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write jpg
|
// Write jpg
|
||||||
void write_jpg(char *filename,struct image img)
|
void
|
||||||
|
write_jpg (char *filename, struct image img)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
struct jpeg_compress_struct cinfo;
|
struct jpeg_compress_struct cinfo;
|
||||||
|
@ -156,20 +171,28 @@ void write_jpg(char *filename,struct image img)
|
||||||
jpeg_start_compress (&cinfo, TRUE);
|
jpeg_start_compress (&cinfo, TRUE);
|
||||||
|
|
||||||
// Allocate memory
|
// Allocate memory
|
||||||
raw_image=(unsigned char *) malloc(cinfo.image_width*cinfo.image_height*cinfo.input_components);
|
raw_image =
|
||||||
|
(unsigned char *) malloc (cinfo.image_width * cinfo.image_height *
|
||||||
|
cinfo.input_components);
|
||||||
|
|
||||||
// Fill image
|
// Fill image
|
||||||
for (i=0;i<img.nx;i++) {
|
for (i = 0; i < img.nx; i++)
|
||||||
for (j=0;j<img.ny;j++) {
|
{
|
||||||
for (k=0;k<img.nz;k++) {
|
for (j = 0; j < img.ny; j++)
|
||||||
|
{
|
||||||
|
for (k = 0; k < img.nz; k++)
|
||||||
|
{
|
||||||
l = img.nz * (i + img.nx * j) + k;
|
l = img.nz * (i + img.nx * j) + k;
|
||||||
raw_image[l] = (unsigned char) img.z[l];
|
raw_image[l] = (unsigned char) img.z[l];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(cinfo.next_scanline<cinfo.image_height) {
|
while (cinfo.next_scanline < cinfo.image_height)
|
||||||
row_pointer[0]=&raw_image[cinfo.next_scanline*cinfo.image_width*cinfo.input_components];
|
{
|
||||||
|
row_pointer[0] =
|
||||||
|
&raw_image[cinfo.next_scanline * cinfo.image_width *
|
||||||
|
cinfo.input_components];
|
||||||
jpeg_write_scanlines (&cinfo, row_pointer, 1);
|
jpeg_write_scanlines (&cinfo, row_pointer, 1);
|
||||||
}
|
}
|
||||||
jpeg_finish_compress (&cinfo);
|
jpeg_finish_compress (&cinfo);
|
||||||
|
|
102
src/launchtle.c
102
src/launchtle.c
|
@ -16,12 +16,14 @@
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -29,22 +31,29 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -53,16 +62,19 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOY to MJD
|
// DOY to MJD
|
||||||
double doy2mjd(int year,double doy)
|
double
|
||||||
|
doy2mjd (int year, double doy)
|
||||||
{
|
{
|
||||||
int month, k = 2;
|
int month, k = 2;
|
||||||
double day;
|
double day;
|
||||||
|
@ -75,25 +87,31 @@ double doy2mjd(int year,double doy)
|
||||||
if (doy < 32.0)
|
if (doy < 32.0)
|
||||||
month = 1;
|
month = 1;
|
||||||
|
|
||||||
day=doy-floor(275.0*month/9.0)+k*floor((month+9.0)/12.0)+30.0;
|
day =
|
||||||
|
doy - floor (275.0 * month / 9.0) + k * floor ((month + 9.0) / 12.0) +
|
||||||
|
30.0;
|
||||||
|
|
||||||
return date2mjd (year, month, day);
|
return date2mjd (year, month, day);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -106,7 +124,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -130,7 +149,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -140,7 +160,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -148,30 +169,44 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.desig,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1, "1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev);
|
orb.satno, orb.desig, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -182,15 +217,18 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf ("launch tle c:i:t:T:I:d:\n\n");
|
printf ("launch tle c:i:t:T:I:d:\n\n");
|
||||||
printf("-c reference tle\n-i reference satno\n-t reference launch time\n-T launch time\n-I output satno\n-d output desig\n");
|
printf
|
||||||
|
("-c reference tle\n-i reference satno\n-t reference launch time\n-T launch time\n-I output satno\n-d output desig\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0, satno = 0, satno1 = 84001;
|
int arg = 0, satno = 0, satno1 = 84001;
|
||||||
char tlefile[LIM];
|
char tlefile[LIM];
|
||||||
|
@ -206,8 +244,10 @@ int main(int argc,char *argv[])
|
||||||
sprintf (tlefile, "%s/classfd.tle", env);
|
sprintf (tlefile, "%s/classfd.tle", env);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"c:i:t:T:I:d:"))!=-1) {
|
while ((arg = getopt (argc, argv, "c:i:t:T:I:d:")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
strcpy (tlefile, optarg);
|
strcpy (tlefile, optarg);
|
||||||
|
|
342
src/measure.c
342
src/measure.c
|
@ -13,12 +13,14 @@
|
||||||
#define D2R M_PI/180.0
|
#define D2R M_PI/180.0
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
|
|
||||||
struct star {
|
struct star
|
||||||
|
{
|
||||||
double ra, de;
|
double ra, de;
|
||||||
float pmra, pmde;
|
float pmra, pmde;
|
||||||
float mag;
|
float mag;
|
||||||
};
|
};
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int naxis1, naxis2, naxis3;
|
int naxis1, naxis2, naxis3;
|
||||||
float *z;
|
float *z;
|
||||||
float zmin, zmax;
|
float zmin, zmax;
|
||||||
|
@ -31,13 +33,15 @@ struct image {
|
||||||
char nfd[32], filename[32];
|
char nfd[32], filename[32];
|
||||||
int cospar, tracked;
|
int cospar, tracked;
|
||||||
};
|
};
|
||||||
struct catalog {
|
struct catalog
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
float x[NMAX], y[NMAX], mag[NMAX];
|
float x[NMAX], y[NMAX], mag[NMAX];
|
||||||
double ra[NMAX], de[NMAX], rx[NMAX], ry[NMAX];
|
double ra[NMAX], de[NMAX], rx[NMAX], ry[NMAX];
|
||||||
int select[NMAX];
|
int select[NMAX];
|
||||||
};
|
};
|
||||||
struct observation {
|
struct observation
|
||||||
|
{
|
||||||
int satno, cospar;
|
int satno, cospar;
|
||||||
char desig[16], conditions, behavior;
|
char desig[16], conditions, behavior;
|
||||||
double mjd, ra, de;
|
double mjd, ra, de;
|
||||||
|
@ -48,15 +52,18 @@ struct observation {
|
||||||
float x[3], y[3];
|
float x[3], y[3];
|
||||||
int state;
|
int state;
|
||||||
};
|
};
|
||||||
struct aperture {
|
struct aperture
|
||||||
|
{
|
||||||
float x, y, r1, r2;
|
float x, y, r1, r2;
|
||||||
};
|
};
|
||||||
struct image read_fits (char *filename, int pnum);
|
struct image read_fits (char *filename, int pnum);
|
||||||
int fgetline (FILE * file, char *s, int lim);
|
int fgetline (FILE * file, char *s, int lim);
|
||||||
int select_nearest (struct catalog c, float x, float y);
|
int select_nearest (struct catalog c, float x, float y);
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de);
|
void reverse (double ra0, double de0, double x, double y, double *ra,
|
||||||
|
double *de);
|
||||||
|
|
||||||
void plot_defects(void)
|
void
|
||||||
|
plot_defects (void)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *env, filename[128];
|
char *env, filename[128];
|
||||||
|
@ -68,13 +75,15 @@ void plot_defects(void)
|
||||||
sprintf (filename, "%s/data/defects.txt", env);
|
sprintf (filename, "%s/data/defects.txt", env);
|
||||||
|
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Defects file not found!\n");
|
fprintf (stderr, "Defects file not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cpgsci (7);
|
cpgsci (7);
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
sscanf (line, "%f %f", &x, &y);
|
sscanf (line, "%f %f", &x, &y);
|
||||||
|
|
||||||
cpgpt1 (x, y, 19);
|
cpgpt1 (x, y, 19);
|
||||||
|
@ -86,7 +95,8 @@ void plot_defects(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_defects(float x,float y)
|
void
|
||||||
|
log_defects (float x, float y)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *env, filename[128];
|
char *env, filename[128];
|
||||||
|
@ -96,7 +106,8 @@ void log_defects(float x,float y)
|
||||||
sprintf (filename, "%s/data/defects.txt", env);
|
sprintf (filename, "%s/data/defects.txt", env);
|
||||||
|
|
||||||
file = fopen (filename, "a");
|
file = fopen (filename, "a");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Defects file not found!\n");
|
fprintf (stderr, "Defects file not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -108,28 +119,34 @@ void log_defects(float x,float y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void plot_objects(char *filename)
|
void
|
||||||
|
plot_objects (char *filename)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -140,8 +157,10 @@ void plot_objects(char *filename)
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return;
|
return;
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
sscanf(line,"%s %f %f %f %f %f %d %s",dummy,&x0,&y0,&x1,&y1,&texp,&id,catalog);
|
{
|
||||||
|
sscanf (line, "%s %f %f %f %f %f %d %s", dummy, &x0, &y0, &x1, &y1,
|
||||||
|
&texp, &id, catalog);
|
||||||
|
|
||||||
cpgsci (0);
|
cpgsci (0);
|
||||||
if (strstr (catalog, "classfd") != NULL)
|
if (strstr (catalog, "classfd") != NULL)
|
||||||
|
@ -164,7 +183,8 @@ void plot_objects(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date)
|
void
|
||||||
|
mjd2date (double mjd, char *date)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -179,7 +199,8 @@ void mjd2date(double mjd,char *date)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -208,13 +229,15 @@ void mjd2date(double mjd,char *date)
|
||||||
x = (x - min) / 60.;
|
x = (x - min) / 60.;
|
||||||
hour = x;
|
hour = x;
|
||||||
fsec = floor (1000.0 * (sec - floor (sec)));
|
fsec = floor (1000.0 * (sec - floor (sec)));
|
||||||
sprintf(date,"%04d%02d%02d%02d%02d%02.0f%03.0f",(int) year,(int) month,(int) day,(int) hour,(int) min,floor(sec),fsec);
|
sprintf (date, "%04d%02d%02d%02d%02d%02.0f%03.0f", (int) year, (int) month,
|
||||||
|
(int) day, (int) hour, (int) min, floor (sec), fsec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Decimal into Sexagesimal
|
// Convert Decimal into Sexagesimal
|
||||||
void dec2s(double x,char *s,int type)
|
void
|
||||||
|
dec2s (double x, char *s, int type)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double sec, deg, min, fmin;
|
double sec, deg, min, fmin;
|
||||||
|
@ -241,12 +264,14 @@ void dec2s(double x,char *s,int type)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -254,17 +279,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
int day;
|
int day;
|
||||||
|
@ -280,7 +311,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -288,13 +320,15 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min;
|
int year, month, day, hour, min;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
float sec;
|
float sec;
|
||||||
|
|
||||||
sscanf(date,"'%04d-%02d-%02dT%02d:%02d:%f'",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "'%04d-%02d-%02dT%02d:%02d:%f'", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
|
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -302,7 +336,8 @@ double nfd2mjd(char *date)
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void format_iod_line(struct observation *obs)
|
void
|
||||||
|
format_iod_line (struct observation *obs)
|
||||||
{
|
{
|
||||||
int mt, xt, mp, xp;
|
int mt, xt, mp, xp;
|
||||||
char string[10];
|
char string[10];
|
||||||
|
@ -313,31 +348,28 @@ void format_iod_line(struct observation *obs)
|
||||||
xt = atoi (string + 4) + 8;
|
xt = atoi (string + 4) + 8;
|
||||||
|
|
||||||
// Position format
|
// Position format
|
||||||
if (obs->type==2) {
|
if (obs->type == 2)
|
||||||
|
{
|
||||||
sprintf (string, "%7.1e", obs->perr);
|
sprintf (string, "%7.1e", obs->perr);
|
||||||
mp = string[0] - '0';
|
mp = string[0] - '0';
|
||||||
xp = atoi (string + 4) + 8;
|
xp = atoi (string + 4) + 8;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("Position format not implemented!\n");
|
printf ("Position format not implemented!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(obs->iod_line,"%05d %c%c %-6s %04d %c %-17s %d%d %d%d %-14s %d%d %c",
|
sprintf (obs->iod_line,
|
||||||
obs->satno,
|
"%05d %c%c %-6s %04d %c %-17s %d%d %d%d %-14s %d%d %c", obs->satno,
|
||||||
obs->desig[0],obs->desig[1],
|
obs->desig[0], obs->desig[1], obs->desig + 2, obs->cospar,
|
||||||
obs->desig+2,
|
obs->conditions, obs->nfd, mt, xt, obs->type, obs->epoch, obs->pos,
|
||||||
obs->cospar,
|
mp, xp, obs->behavior);
|
||||||
obs->conditions,
|
|
||||||
obs->nfd,
|
|
||||||
mt,xt,
|
|
||||||
obs->type,obs->epoch,
|
|
||||||
obs->pos,
|
|
||||||
mp,xp,
|
|
||||||
obs->behavior);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void find_designation(int satno0,char *desig0)
|
void
|
||||||
|
find_designation (int satno0, char *desig0)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
int satno;
|
int satno;
|
||||||
|
@ -349,13 +381,16 @@ void find_designation(int satno0,char *desig0)
|
||||||
sprintf (filename, "%s/data/desig.txt", env);
|
sprintf (filename, "%s/data/desig.txt", env);
|
||||||
|
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Designation file not found!\n");
|
fprintf (stderr, "Designation file not found!\n");
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fscanf (file, "%d %s", &satno, desig);
|
fscanf (file, "%d %s", &satno, desig);
|
||||||
if (satno==satno0) {
|
if (satno == satno0)
|
||||||
|
{
|
||||||
strcpy (desig0, desig);
|
strcpy (desig0, desig);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -365,7 +400,8 @@ void find_designation(int satno0,char *desig0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_observation(struct observation obs)
|
void
|
||||||
|
write_observation (struct observation obs)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
|
@ -378,7 +414,8 @@ void write_observation(struct observation obs)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void aperture_photometry(struct image img,struct aperture ap)
|
void
|
||||||
|
aperture_photometry (struct image img, struct aperture ap)
|
||||||
{
|
{
|
||||||
int i, j, k, n1, n2;
|
int i, j, k, n1, n2;
|
||||||
float s1, ss1, s2, ss2;
|
float s1, ss1, s2, ss2;
|
||||||
|
@ -395,19 +432,24 @@ void aperture_photometry(struct image img,struct aperture ap)
|
||||||
n1 = 0;
|
n1 = 0;
|
||||||
n2 = 0;
|
n2 = 0;
|
||||||
|
|
||||||
for (i=0;i<img.naxis1;i++) {
|
for (i = 0; i < img.naxis1; i++)
|
||||||
|
{
|
||||||
x = (float) i;
|
x = (float) i;
|
||||||
for (j=0;j<img.naxis2;j++) {
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
k = i + img.naxis1 * j;
|
k = i + img.naxis1 * j;
|
||||||
y = (float) j;
|
y = (float) j;
|
||||||
dx = x - ap.x;
|
dx = x - ap.x;
|
||||||
dy = y - ap.y;
|
dy = y - ap.y;
|
||||||
r = sqrt (dx * dx + dy * dy);
|
r = sqrt (dx * dx + dy * dy);
|
||||||
if (r<ap.r1) {
|
if (r < ap.r1)
|
||||||
|
{
|
||||||
s1 += img.z[k];
|
s1 += img.z[k];
|
||||||
ss1 += img.z[k] * img.z[k];
|
ss1 += img.z[k] * img.z[k];
|
||||||
n1++;
|
n1++;
|
||||||
} else if (r>=ap.r1 && r<ap.r2) {
|
}
|
||||||
|
else if (r >= ap.r1 && r < ap.r2)
|
||||||
|
{
|
||||||
s2 += img.z[k];
|
s2 += img.z[k];
|
||||||
ss2 += img.z[k] * img.z[k];
|
ss2 += img.z[k] * img.z[k];
|
||||||
n2++;
|
n2++;
|
||||||
|
@ -417,13 +459,16 @@ void aperture_photometry(struct image img,struct aperture ap)
|
||||||
f1 = s1 / (float) n1;
|
f1 = s1 / (float) n1;
|
||||||
f2 = s2 / (float) n2;
|
f2 = s2 / (float) n2;
|
||||||
|
|
||||||
printf("%lf %8.3f %8.3f %.0f %d %.0f %d %f\n",mjd,ap.x,ap.y,s1,n1,s2,n2,f1-f2);
|
printf ("%lf %8.3f %8.3f %.0f %d %.0f %d %f\n", mjd, ap.x, ap.y, s1, n1, s2,
|
||||||
|
n2, f1 - f2);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce point
|
// Reduce point
|
||||||
void reduce_point(struct observation *obs,struct image img,float tmid,float x,float y)
|
void
|
||||||
|
reduce_point (struct observation *obs, struct image img, float tmid, float x,
|
||||||
|
float y)
|
||||||
{
|
{
|
||||||
int iframe, k;
|
int iframe, k;
|
||||||
double ra, de, rx, ry;
|
double ra, de, rx, ry;
|
||||||
|
@ -439,7 +484,8 @@ void reduce_point(struct observation *obs,struct image img,float tmid,float x,fl
|
||||||
reverse (img.ra0, img.de0, rx, ry, &ra, &de);
|
reverse (img.ra0, img.de0, rx, ry, &ra, &de);
|
||||||
|
|
||||||
// Correct for stationary camera
|
// Correct for stationary camera
|
||||||
if (img.tracked==0) {
|
if (img.tracked == 0)
|
||||||
|
{
|
||||||
mjd1 = img.mjd + 0.5 * (double) img.exptime / 86400.0;
|
mjd1 = img.mjd + 0.5 * (double) img.exptime / 86400.0;
|
||||||
mjd2 = img.mjd + (double) tmid / 86400.0;
|
mjd2 = img.mjd + (double) tmid / 86400.0;
|
||||||
ra += gmst (mjd2) - gmst (mjd1);
|
ra += gmst (mjd2) - gmst (mjd1);
|
||||||
|
@ -459,7 +505,8 @@ void reduce_point(struct observation *obs,struct image img,float tmid,float x,fl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct image maximum_image(struct image *raw,int n)
|
struct image
|
||||||
|
maximum_image (struct image *raw, int n)
|
||||||
{
|
{
|
||||||
int i, j, k, l;
|
int i, j, k, l;
|
||||||
float max, s1, s2;
|
float max, s1, s2;
|
||||||
|
@ -469,7 +516,8 @@ struct image maximum_image(struct image *raw,int n)
|
||||||
img.naxis1 = raw[0].naxis1;
|
img.naxis1 = raw[0].naxis1;
|
||||||
img.naxis2 = raw[0].naxis2;
|
img.naxis2 = raw[0].naxis2;
|
||||||
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
||||||
for (i=0;i<img.naxis1*img.naxis2;i++) {
|
for (i = 0; i < img.naxis1 * img.naxis2; i++)
|
||||||
|
{
|
||||||
for (j = 0, max = 0.0; j < n; j++)
|
for (j = 0, max = 0.0; j < n; j++)
|
||||||
if (raw[j].z[i] > max)
|
if (raw[j].z[i] > max)
|
||||||
max = raw[j].z[i];
|
max = raw[j].z[i];
|
||||||
|
@ -496,7 +544,8 @@ struct image maximum_image(struct image *raw,int n)
|
||||||
img.de0 = 0.0;
|
img.de0 = 0.0;
|
||||||
img.x0 = 0.0;
|
img.x0 = 0.0;
|
||||||
img.y0 = 0.0;
|
img.y0 = 0.0;
|
||||||
for (i=0;i<3;i++) {
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
img.a[i] = 0.0;
|
img.a[i] = 0.0;
|
||||||
img.b[i] = 0.0;
|
img.b[i] = 0.0;
|
||||||
}
|
}
|
||||||
|
@ -507,7 +556,8 @@ struct image maximum_image(struct image *raw,int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read pixel catalog
|
// Read pixel catalog
|
||||||
struct catalog read_pixel_catalog(char *filename)
|
struct catalog
|
||||||
|
read_pixel_catalog (char *filename)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -516,11 +566,13 @@ struct catalog read_pixel_catalog(char *filename)
|
||||||
|
|
||||||
// Read catalog
|
// Read catalog
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "%s not found!\n", filename);
|
fprintf (stderr, "%s not found!\n", filename);
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
if (i >= NMAX)
|
if (i >= NMAX)
|
||||||
break;
|
break;
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
|
@ -535,7 +587,8 @@ struct catalog read_pixel_catalog(char *filename)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, iimg = 0, nimg;
|
int i, iimg = 0, nimg;
|
||||||
float xmin, xmax, ymin, ymax, zmin, zmax;
|
float xmin, xmax, ymin, ymax, zmin, zmax;
|
||||||
|
@ -620,8 +673,10 @@ int main(int argc,char *argv[])
|
||||||
ap.r2 = 10.0;
|
ap.r2 = 10.0;
|
||||||
|
|
||||||
// Forever loop
|
// Forever loop
|
||||||
for (;;) {
|
for (;;)
|
||||||
if (redraw!=0) {
|
{
|
||||||
|
if (redraw != 0)
|
||||||
|
{
|
||||||
if (redraw == 1)
|
if (redraw == 1)
|
||||||
cpgpage ();
|
cpgpage ();
|
||||||
cpgsci (1);
|
cpgsci (1);
|
||||||
|
@ -632,38 +687,62 @@ int main(int argc,char *argv[])
|
||||||
cpgsfs (2);
|
cpgsfs (2);
|
||||||
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
||||||
|
|
||||||
sprintf(text,"File %d: %s; UT Date: %.23s COSPAR ID: %04d",iimg+1,img[iimg].filename,img[iimg].nfd+1,img[iimg].cospar);
|
sprintf (text, "File %d: %s; UT Date: %.23s COSPAR ID: %04d",
|
||||||
|
iimg + 1, img[iimg].filename, img[iimg].nfd + 1,
|
||||||
|
img[iimg].cospar);
|
||||||
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
||||||
sprintf(text,"R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')",img[iimg].ra0,img[iimg].xrms,img[iimg].de0,img[iimg].yrms);
|
sprintf (text, "R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')",
|
||||||
|
img[iimg].ra0, img[iimg].xrms, img[iimg].de0,
|
||||||
|
img[iimg].yrms);
|
||||||
cpgmtxt ("T", 4.8, 0.0, 0.0, text);
|
cpgmtxt ("T", 4.8, 0.0, 0.0, text);
|
||||||
sprintf(text,"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d Fraction: %.1f",img[iimg].naxis1*sqrt(img[iimg].a[1]*img[iimg].a[1]+img[iimg].b[1]*img[iimg].b[1])/3600.0,img[iimg].naxis2*sqrt(img[iimg].a[2]*img[iimg].a[2]+img[iimg].b[2]*img[iimg].b[2])/3600.0,sqrt(img[iimg].a[1]*img[iimg].a[1]+img[iimg].b[1]*img[iimg].b[1]),sqrt(img[iimg].a[2]*img[iimg].a[2]+img[iimg].b[2]*img[iimg].b[2]),frac);
|
sprintf (text,
|
||||||
|
"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d Fraction: %.1f",
|
||||||
|
img[iimg].naxis1 * sqrt (img[iimg].a[1] * img[iimg].a[1] +
|
||||||
|
img[iimg].b[1] * img[iimg].b[1]) /
|
||||||
|
3600.0,
|
||||||
|
img[iimg].naxis2 * sqrt (img[iimg].a[2] * img[iimg].a[2] +
|
||||||
|
img[iimg].b[2] * img[iimg].b[2]) /
|
||||||
|
3600.0,
|
||||||
|
sqrt (img[iimg].a[1] * img[iimg].a[1] +
|
||||||
|
img[iimg].b[1] * img[iimg].b[1]),
|
||||||
|
sqrt (img[iimg].a[2] * img[iimg].a[2] +
|
||||||
|
img[iimg].b[2] * img[iimg].b[2]), frac);
|
||||||
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
||||||
|
|
||||||
zmin = img[iimg].zmin;
|
zmin = img[iimg].zmin;
|
||||||
zmax = img[iimg].zmax;
|
zmax = img[iimg].zmax;
|
||||||
|
|
||||||
cpgimag(img[iimg].z,img[iimg].naxis1,img[iimg].naxis2,1,img[iimg].naxis1,1,img[iimg].naxis2,zmin,zmax,tr);
|
cpgimag (img[iimg].z, img[iimg].naxis1, img[iimg].naxis2, 1,
|
||||||
|
img[iimg].naxis1, 1, img[iimg].naxis2, zmin, zmax, tr);
|
||||||
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
||||||
|
|
||||||
// Plot fit
|
// Plot fit
|
||||||
if (obs.state==1) {
|
if (obs.state == 1)
|
||||||
|
{
|
||||||
cpgsci (4);
|
cpgsci (4);
|
||||||
cpgpt1 (obs.x[0], obs.y[0], 4);
|
cpgpt1 (obs.x[0], obs.y[0], 4);
|
||||||
cpgmove (obs.x[1], obs.y[1]);
|
cpgmove (obs.x[1], obs.y[1]);
|
||||||
cpgdraw (obs.x[2], obs.y[2]);
|
cpgdraw (obs.x[2], obs.y[2]);
|
||||||
cpgsci (1);
|
cpgsci (1);
|
||||||
} else if (obs.state==2) {
|
}
|
||||||
|
else if (obs.state == 2)
|
||||||
|
{
|
||||||
cpgsci (4);
|
cpgsci (4);
|
||||||
cpgpt1 (obs.x[0], obs.y[0], 4);
|
cpgpt1 (obs.x[0], obs.y[0], 4);
|
||||||
cpgsci (1);
|
cpgsci (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plotobj==1) {
|
if (plotobj == 1)
|
||||||
if (iimg<nimg-1) {
|
{
|
||||||
|
if (iimg < nimg - 1)
|
||||||
|
{
|
||||||
sprintf (idfile, "%s.id", img[iimg].filename);
|
sprintf (idfile, "%s.id", img[iimg].filename);
|
||||||
plot_objects (idfile);
|
plot_objects (idfile);
|
||||||
} else if (iimg==nimg-1) {
|
}
|
||||||
for (i=0;i<nimg-1;i++) {
|
else if (iimg == nimg - 1)
|
||||||
|
{
|
||||||
|
for (i = 0; i < nimg - 1; i++)
|
||||||
|
{
|
||||||
sprintf (idfile, "%s.id", img[i].filename);
|
sprintf (idfile, "%s.id", img[i].filename);
|
||||||
plot_objects (idfile);
|
plot_objects (idfile);
|
||||||
}
|
}
|
||||||
|
@ -674,8 +753,10 @@ int main(int argc,char *argv[])
|
||||||
cpgmtxt ("T", 1.0, 0.5, 0.5, obs.iod_line);
|
cpgmtxt ("T", 1.0, 0.5, 0.5, obs.iod_line);
|
||||||
|
|
||||||
// Read pixel catalog
|
// Read pixel catalog
|
||||||
if (plotcat==1) {
|
if (plotcat == 1)
|
||||||
if (iimg<nimg-1) {
|
{
|
||||||
|
if (iimg < nimg - 1)
|
||||||
|
{
|
||||||
sprintf (pixcat, "%s.cat", img[iimg].filename);
|
sprintf (pixcat, "%s.cat", img[iimg].filename);
|
||||||
cat = read_pixel_catalog (pixcat);
|
cat = read_pixel_catalog (pixcat);
|
||||||
|
|
||||||
|
@ -688,7 +769,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plot aperture
|
// Plot aperture
|
||||||
if (ap.x>0.0 && ap.y>0.0) {
|
if (ap.x > 0.0 && ap.y > 0.0)
|
||||||
|
{
|
||||||
cpgsci (3);
|
cpgsci (3);
|
||||||
cpgcirc (ap.x, ap.y, ap.r1);
|
cpgcirc (ap.x, ap.y, ap.r1);
|
||||||
cpgcirc (ap.x, ap.y, ap.r2);
|
cpgcirc (ap.x, ap.y, ap.r2);
|
||||||
|
@ -708,7 +790,8 @@ int main(int argc,char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Change fraction
|
// Change fraction
|
||||||
if (c=='e') {
|
if (c == 'e')
|
||||||
|
{
|
||||||
if (frac > 0.49 && frac < 0.51)
|
if (frac > 0.49 && frac < 0.51)
|
||||||
frac = 1.0;
|
frac = 1.0;
|
||||||
else if (frac > 0.51)
|
else if (frac > 0.51)
|
||||||
|
@ -719,7 +802,8 @@ int main(int argc,char *argv[])
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c=='p' || c=='X') {
|
if (c == 'p' || c == 'X')
|
||||||
|
{
|
||||||
if (plotobj == 1)
|
if (plotobj == 1)
|
||||||
plotobj = 0;
|
plotobj = 0;
|
||||||
else
|
else
|
||||||
|
@ -728,13 +812,15 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark bad pixel
|
// Mark bad pixel
|
||||||
if (c=='t') {
|
if (c == 't')
|
||||||
|
{
|
||||||
log_defects (x, y);
|
log_defects (x, y);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plot catalog
|
// Plot catalog
|
||||||
if (c=='l') {
|
if (c == 'l')
|
||||||
|
{
|
||||||
if (plotcat == 1)
|
if (plotcat == 1)
|
||||||
plotcat = 0;
|
plotcat = 0;
|
||||||
else
|
else
|
||||||
|
@ -743,7 +829,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get designation
|
// Get designation
|
||||||
if (c=='d') {
|
if (c == 'd')
|
||||||
|
{
|
||||||
printf ("Provide satellite number: ");
|
printf ("Provide satellite number: ");
|
||||||
scanf ("%d", &obs.satno);
|
scanf ("%d", &obs.satno);
|
||||||
find_designation (obs.satno, obs.desig);
|
find_designation (obs.satno, obs.desig);
|
||||||
|
@ -752,7 +839,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Center
|
// Center
|
||||||
if (c=='c') {
|
if (c == 'c')
|
||||||
|
{
|
||||||
xmin = x - fx * width;
|
xmin = x - fx * width;
|
||||||
xmax = x + fx * width;
|
xmax = x + fx * width;
|
||||||
ymin = y - fy * width;
|
ymin = y - fy * width;
|
||||||
|
@ -761,7 +849,8 @@ int main(int argc,char *argv[])
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isdigit(c)) {
|
if (isdigit (c))
|
||||||
|
{
|
||||||
width = 1000.0 / (c - '0');
|
width = 1000.0 / (c - '0');
|
||||||
xmin = x - fx * width;
|
xmin = x - fx * width;
|
||||||
xmax = x + fx * width;
|
xmax = x + fx * width;
|
||||||
|
@ -772,7 +861,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cycle through images
|
// Cycle through images
|
||||||
if (c==']' || c=='s') {
|
if (c == ']' || c == 's')
|
||||||
|
{
|
||||||
iimg++;
|
iimg++;
|
||||||
if (iimg >= nimg - 1)
|
if (iimg >= nimg - 1)
|
||||||
iimg = 0;
|
iimg = 0;
|
||||||
|
@ -784,7 +874,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cycle through images
|
// Cycle through images
|
||||||
if (c=='[' || c=='a') {
|
if (c == '[' || c == 'a')
|
||||||
|
{
|
||||||
iimg--;
|
iimg--;
|
||||||
if (iimg < 0)
|
if (iimg < 0)
|
||||||
iimg = nimg - 2;
|
iimg = nimg - 2;
|
||||||
|
@ -796,14 +887,16 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maximum image
|
// Maximum image
|
||||||
if (c=='o') {
|
if (c == 'o')
|
||||||
|
{
|
||||||
iimg = nimg - 1;
|
iimg = nimg - 1;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cycle through image
|
// Cycle through image
|
||||||
if (c=='\t') {
|
if (c == '\t')
|
||||||
|
{
|
||||||
printf ("%d %d\n", ix, iy);
|
printf ("%d %d\n", ix, iy);
|
||||||
|
|
||||||
// Set area
|
// Set area
|
||||||
|
@ -817,11 +910,13 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Increment
|
// Increment
|
||||||
ix++;
|
ix++;
|
||||||
if (width*ix>img[iimg].naxis1) {
|
if (width * ix > img[iimg].naxis1)
|
||||||
|
{
|
||||||
ix = 0;
|
ix = 0;
|
||||||
iy++;
|
iy++;
|
||||||
}
|
}
|
||||||
if (width*iy>img[iimg].naxis2) {
|
if (width * iy > img[iimg].naxis2)
|
||||||
|
{
|
||||||
ix = 0;
|
ix = 0;
|
||||||
iy = 0;
|
iy = 0;
|
||||||
}
|
}
|
||||||
|
@ -832,7 +927,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
|
|
||||||
// Zoom
|
// Zoom
|
||||||
if (c=='z' || c=='+' || c=='=') {
|
if (c == 'z' || c == '+' || c == '=')
|
||||||
|
{
|
||||||
width /= 1.5;
|
width /= 1.5;
|
||||||
xmin = x - fx * width;
|
xmin = x - fx * width;
|
||||||
xmax = x + fx * width;
|
xmax = x + fx * width;
|
||||||
|
@ -843,7 +939,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unzoom
|
// Unzoom
|
||||||
if (c=='x' || c=='-') {
|
if (c == 'x' || c == '-')
|
||||||
|
{
|
||||||
width *= 1.5;
|
width *= 1.5;
|
||||||
xmin = x - fx * width;
|
xmin = x - fx * width;
|
||||||
xmax = x + fx * width;
|
xmax = x + fx * width;
|
||||||
|
@ -854,8 +951,11 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
if (c=='r') {
|
if (c == 'r')
|
||||||
width=(img[iimg].naxis1>img[iimg].naxis2) ? img[iimg].naxis1 : img[iimg].naxis2;
|
{
|
||||||
|
width =
|
||||||
|
(img[iimg].naxis1 >
|
||||||
|
img[iimg].naxis2) ? img[iimg].naxis1 : img[iimg].naxis2;
|
||||||
xmin = 0.0;
|
xmin = 0.0;
|
||||||
xmax = img[iimg].naxis1;
|
xmax = img[iimg].naxis1;
|
||||||
ymin = 0.0;
|
ymin = 0.0;
|
||||||
|
@ -865,8 +965,11 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
if (c=='R') {
|
if (c == 'R')
|
||||||
width=(img[iimg].naxis1>img[iimg].naxis2) ? img[iimg].naxis1 : img[iimg].naxis2;
|
{
|
||||||
|
width =
|
||||||
|
(img[iimg].naxis1 >
|
||||||
|
img[iimg].naxis2) ? img[iimg].naxis1 : img[iimg].naxis2;
|
||||||
xmin = 0.0;
|
xmin = 0.0;
|
||||||
xmax = img[iimg].naxis1;
|
xmax = img[iimg].naxis1;
|
||||||
ymin = 0.0;
|
ymin = 0.0;
|
||||||
|
@ -897,13 +1000,15 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write obs
|
// Write obs
|
||||||
if (c=='w') {
|
if (c == 'w')
|
||||||
|
{
|
||||||
write_observation (obs);
|
write_observation (obs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Measure
|
// Measure
|
||||||
if (c=='m' || c=='D') {
|
if (c == 'm' || c == 'D')
|
||||||
|
{
|
||||||
// istar=select_nearest(cat,x,y);
|
// istar=select_nearest(cat,x,y);
|
||||||
// printf("%f %f -> %f %f %f\n",x,y,cat.x[istar],cat.y[istar],cat.mag[istar]);
|
// printf("%f %f -> %f %f %f\n",x,y,cat.x[istar],cat.y[istar],cat.mag[istar]);
|
||||||
reduce_point (&obs, img[iimg], frac * img[iimg].exptime, x, y);
|
reduce_point (&obs, img[iimg], frac * img[iimg].exptime, x, y);
|
||||||
|
@ -915,7 +1020,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aperture photometry
|
// Aperture photometry
|
||||||
if (c=='g') {
|
if (c == 'g')
|
||||||
|
{
|
||||||
ap.x = x;
|
ap.x = x;
|
||||||
ap.y = y;
|
ap.y = y;
|
||||||
aperture_photometry (img[iimg], ap);
|
aperture_photometry (img[iimg], ap);
|
||||||
|
@ -924,9 +1030,11 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Help
|
// Help
|
||||||
if (c=='h') {
|
if (c == 'h')
|
||||||
|
{
|
||||||
printf ("q Quit\n");
|
printf ("q Quit\n");
|
||||||
printf("e Change of exposure (0.0 = start, 0.5 = middle, 1.0 = end)\n");
|
printf
|
||||||
|
("e Change of exposure (0.0 = start, 0.5 = middle, 1.0 = end)\n");
|
||||||
printf ("p (right) Plot objects\n");
|
printf ("p (right) Plot objects\n");
|
||||||
printf ("l Plot star catalog\n");
|
printf ("l Plot star catalog\n");
|
||||||
printf ("d Set object NORAD designation\n");
|
printf ("d Set object NORAD designation\n");
|
||||||
|
@ -954,7 +1062,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename,int pnum)
|
struct image
|
||||||
|
read_fits (char *filename, int pnum)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -1019,8 +1128,10 @@ struct image read_fits(char *filename,int pnum)
|
||||||
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0,m=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0, m = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
img.z[l] = ql.fbuf[l];
|
img.z[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
|
@ -1041,7 +1152,8 @@ struct image read_fits(char *filename,int pnum)
|
||||||
|
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -1055,14 +1167,17 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
|
|
||||||
|
|
||||||
// Select nearest object
|
// Select nearest object
|
||||||
int select_nearest(struct catalog c,float x,float y)
|
int
|
||||||
|
select_nearest (struct catalog c, float x, float y)
|
||||||
{
|
{
|
||||||
int i, imin;
|
int i, imin;
|
||||||
float r, rmin;
|
float r, rmin;
|
||||||
|
|
||||||
for (i=0;i<c.n;i++) {
|
for (i = 0; i < c.n; i++)
|
||||||
|
{
|
||||||
r = sqrt (pow (x - c.x[i], 2) + pow (y - c.y[i], 2));
|
r = sqrt (pow (x - c.x[i], 2) + pow (y - c.y[i], 2));
|
||||||
if (i==0 || r<rmin) {
|
if (i == 0 || r < rmin)
|
||||||
|
{
|
||||||
imin = i;
|
imin = i;
|
||||||
rmin = r;
|
rmin = r;
|
||||||
}
|
}
|
||||||
|
@ -1070,4 +1185,3 @@ int select_nearest(struct catalog c,float x,float y)
|
||||||
|
|
||||||
return imin;
|
return imin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
src/mvtle.c
54
src/mvtle.c
|
@ -8,7 +8,8 @@
|
||||||
#include "satutl.h"
|
#include "satutl.h"
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -21,30 +22,44 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.desig,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1, "1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f%5ld",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev,orb.norb);
|
orb.satno, orb.desig, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f%5ld",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev, orb.norb);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -55,21 +70,25 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
// while ((arg=getopt(argc,argv,"c:i:I:D:N:h"))!=-1) {
|
// while ((arg=getopt(argc,argv,"c:i:I:D:N:h"))!=-1) {
|
||||||
printf("Usage: mvtle -i OLD_NORAD_ID -I NEW_NORAD_ID -d COSPAR_ID [-N SATELLITE_NAME] [-h]\n\n");
|
printf
|
||||||
|
("Usage: mvtle -i OLD_NORAD_ID -I NEW_NORAD_ID -d COSPAR_ID [-N SATELLITE_NAME] [-h]\n\n");
|
||||||
printf ("Arguments:\n");
|
printf ("Arguments:\n");
|
||||||
printf ("-i OLD_NORAD_ID Old Satellite Catalog Number (NORAD ID)\n");
|
printf ("-i OLD_NORAD_ID Old Satellite Catalog Number (NORAD ID)\n");
|
||||||
printf ("-i NEW_NORAD_ID New Satellite Catalog Number (NORAD ID)\n");
|
printf ("-i NEW_NORAD_ID New Satellite Catalog Number (NORAD ID)\n");
|
||||||
printf ("-d COSPAR_ID International Designator (COSPAR ID)\n");
|
printf ("-d COSPAR_ID International Designator (COSPAR ID)\n");
|
||||||
printf("-N SATELLITE_NAME (New) Satellite Name / TLE Line 0, default: ''\n");
|
printf
|
||||||
|
("-N SATELLITE_NAME (New) Satellite Name / TLE Line 0, default: ''\n");
|
||||||
printf ("-h This help\n");
|
printf ("-h This help\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0;
|
int arg = 0;
|
||||||
char *tlefile;
|
char *tlefile;
|
||||||
|
@ -79,8 +98,10 @@ int main(int argc,char *argv[])
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"c:i:I:D:N:h"))!=-1) {
|
while ((arg = getopt (argc, argv, "c:i:I:D:N:h")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
tlefile = optarg;
|
tlefile = optarg;
|
||||||
|
@ -121,7 +142,8 @@ int main(int argc,char *argv[])
|
||||||
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
||||||
|
|
||||||
// Loop over file
|
// Loop over file
|
||||||
while (read_twoline(file,satno,&orb)==0) {
|
while (read_twoline (file, satno, &orb) == 0)
|
||||||
|
{
|
||||||
// Adjust changes
|
// Adjust changes
|
||||||
if (satno_new != 0)
|
if (satno_new != 0)
|
||||||
orb.satno = satno_new;
|
orb.satno = satno_new;
|
||||||
|
|
134
src/normal.c
134
src/normal.c
|
@ -19,28 +19,33 @@
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
// Dot product
|
// Dot product
|
||||||
float dot(xyz_t a,xyz_t b)
|
float
|
||||||
|
dot (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
double magnitude(xyz_t a)
|
double
|
||||||
|
magnitude (xyz_t a)
|
||||||
{
|
{
|
||||||
return sqrt (dot (a, a));
|
return sqrt (dot (a, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross product
|
// Cross product
|
||||||
xyz_t cross(xyz_t a,xyz_t b)
|
xyz_t
|
||||||
|
cross (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
xyz_t c;
|
xyz_t c;
|
||||||
|
|
||||||
|
@ -52,7 +57,8 @@ xyz_t cross(xyz_t a,xyz_t b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -65,7 +71,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +96,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -99,7 +107,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -107,7 +116,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clasical elements
|
// Clasical elements
|
||||||
orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
orbit_t
|
||||||
|
classel (int ep_year, double ep_day, xyz_t r, xyz_t v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double rm, vm, vm2, rvm, mu = 1.0;;
|
double rm, vm, vm2, rvm, mu = 1.0;;
|
||||||
|
@ -154,7 +164,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
peri += 360.0;
|
peri += 360.0;
|
||||||
|
|
||||||
// Elliptic motion
|
// Elliptic motion
|
||||||
if (ecc<1.0) {
|
if (ecc < 1.0)
|
||||||
|
{
|
||||||
xp = (chi - rm) / ecc;
|
xp = (chi - rm) / ecc;
|
||||||
yp = rvm / ecc * sqrt (chi / mu);
|
yp = rvm / ecc * sqrt (chi / mu);
|
||||||
b = a * sqrt (1.0 - ecc * ecc);
|
b = a * sqrt (1.0 - ecc * ecc);
|
||||||
|
@ -183,7 +194,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
return orb;
|
return orb;
|
||||||
}
|
}
|
||||||
|
|
||||||
orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
orbit_t
|
||||||
|
rv2el (int satno, double mjd, xyz_t r0, xyz_t v0)
|
||||||
{
|
{
|
||||||
int i, imode;
|
int i, imode;
|
||||||
orbit_t orb[5], orb1[5];
|
orbit_t orb[5], orb1[5];
|
||||||
|
@ -200,7 +212,8 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
orb[0] = classel (ep_year, ep_day, r0, v0);
|
orb[0] = classel (ep_year, ep_day, r0, v0);
|
||||||
orb[0].satno = satno;
|
orb[0].satno = satno;
|
||||||
|
|
||||||
for (i=0;i<4;i++) {
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
// Propagate
|
// Propagate
|
||||||
imode = init_sgdp4 (&orb[i]);
|
imode = init_sgdp4 (&orb[i]);
|
||||||
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
||||||
|
@ -236,30 +249,44 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.desig,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1, "1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev);
|
orb.satno, orb.desig, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -271,7 +298,8 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -280,18 +308,22 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -299,22 +331,29 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -322,15 +361,18 @@ double nfd2mjd(char *date)
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf("propagate c:i:t:m:\n\nPropagates orbital elements to a new epoch using the SGP4/SDP4 model.\nDefault operation propagates classfd.tle to now,\n\n-c input catalog\n-i Satellite number\n-t New epoch (YYYY-MM-DDTHH:MM:SS)\n-m New epoch (MJD)\n");
|
printf
|
||||||
|
("propagate c:i:t:m:\n\nPropagates orbital elements to a new epoch using the SGP4/SDP4 model.\nDefault operation propagates classfd.tle to now,\n\n-c input catalog\n-i Satellite number\n-t New epoch (YYYY-MM-DDTHH:MM:SS)\n-m New epoch (MJD)\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int imode, satno = 0, arg, usecatalog = 0, satnomin, flag = 0;
|
int imode, satno = 0, arg, usecatalog = 0, satnomin, flag = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -351,8 +393,10 @@ int main(int argc,char *argv[])
|
||||||
mjd = nfd2mjd (nfd);
|
mjd = nfd2mjd (nfd);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"C:c:i:t:m:he"))!=-1) {
|
while ((arg = getopt (argc, argv, "C:c:i:t:m:he")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (nfd, optarg);
|
strcpy (nfd, optarg);
|
||||||
|
@ -396,7 +440,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (tlefile, "r");
|
file = fopen (tlefile, "r");
|
||||||
while (read_twoline(file,satno,&orb)==0) {
|
while (read_twoline (file, satno, &orb) == 0)
|
||||||
|
{
|
||||||
format_tle (orb, line1, line2);
|
format_tle (orb, line1, line2);
|
||||||
|
|
||||||
// Propagate
|
// Propagate
|
||||||
|
@ -411,16 +456,19 @@ int main(int argc,char *argv[])
|
||||||
de = asin (n.z / magnitude (n)) * R2D;
|
de = asin (n.z / magnitude (n)) * R2D;
|
||||||
|
|
||||||
if (usecatalog == 0)
|
if (usecatalog == 0)
|
||||||
printf("%05d %14.8lf %10.6f %10.6f %10.2f %10.2f %10.2f %10.2f\n",orb.satno,mjd,ra,de,magnitude(n),n.x,n.y,n.z);
|
printf ("%05d %14.8lf %10.6f %10.6f %10.2f %10.2f %10.2f %10.2f\n",
|
||||||
|
orb.satno, mjd, ra, de, magnitude (n), n.x, n.y, n.z);
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
// Match against a catalog
|
// Match against a catalog
|
||||||
if (usecatalog==1) {
|
if (usecatalog == 1)
|
||||||
|
{
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (catalog, "r");
|
file = fopen (catalog, "r");
|
||||||
while (read_twoline(file,0,&orb)==0) {
|
while (read_twoline (file, 0, &orb) == 0)
|
||||||
|
{
|
||||||
format_tle (orb, line1, line2);
|
format_tle (orb, line1, line2);
|
||||||
|
|
||||||
// Propagate
|
// Propagate
|
||||||
|
@ -445,7 +493,8 @@ int main(int argc,char *argv[])
|
||||||
mv.y = v0.y - v.y;
|
mv.y = v0.y - v.y;
|
||||||
mv.z = v0.z - v.z;
|
mv.z = v0.z - v.z;
|
||||||
|
|
||||||
if (flag==0 || dr<drmin) {
|
if (flag == 0 || dr < drmin)
|
||||||
|
{
|
||||||
drmin = dr;
|
drmin = dr;
|
||||||
dmr = magnitude (mr);
|
dmr = magnitude (mr);
|
||||||
dmv = magnitude (mv);
|
dmv = magnitude (mv);
|
||||||
|
@ -453,7 +502,8 @@ int main(int argc,char *argv[])
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%05d %05d %8.2f km %8.2f km %10.6f km/s\n",satno,satnomin,drmin,dmr,dmv);
|
printf ("%05d %05d %8.2f km %8.2f km %10.6f km/s\n", satno, satnomin,
|
||||||
|
drmin, dmr, dmv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
285
src/pass.c
285
src/pass.c
|
@ -20,7 +20,8 @@ long Isatsel=0;
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
int ipass = 0, npass;
|
int ipass = 0, npass;
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
long satno;
|
long satno;
|
||||||
double lat, lng;
|
double lat, lng;
|
||||||
double mjd;
|
double mjd;
|
||||||
|
@ -31,13 +32,15 @@ struct map {
|
||||||
char datadir[LIM], tledir[LIM];
|
char datadir[LIM], tledir[LIM];
|
||||||
int site_id, plot;
|
int site_id, plot;
|
||||||
} m;
|
} m;
|
||||||
struct point {
|
struct point
|
||||||
|
{
|
||||||
double mjd;
|
double mjd;
|
||||||
char nfd[LIM];
|
char nfd[LIM];
|
||||||
xyz_t obspos, satpos, sunpos;
|
xyz_t obspos, satpos, sunpos;
|
||||||
double sra, sde, salt, sazi, azi, alt;
|
double sra, sde, salt, sazi, azi, alt;
|
||||||
} *pt;
|
} *pt;
|
||||||
struct pass {
|
struct pass
|
||||||
|
{
|
||||||
int satno;
|
int satno;
|
||||||
double mjdrise, mjdmax, mjdset;
|
double mjdrise, mjdmax, mjdset;
|
||||||
char line[80], skymap[LIM], radio[80];
|
char line[80], skymap[LIM], radio[80];
|
||||||
|
@ -61,7 +64,8 @@ void equatorial2horizontal(double,double,double,double *,double *);
|
||||||
void horizontal2equatorial (double, double, double, double *, double *);
|
void horizontal2equatorial (double, double, double, double *, double *);
|
||||||
void compute_observer_and_solar_positions (void);
|
void compute_observer_and_solar_positions (void);
|
||||||
|
|
||||||
void compute_track(orbit_t orb)
|
void
|
||||||
|
compute_track (orbit_t orb)
|
||||||
{
|
{
|
||||||
int i, flag = 0;
|
int i, flag = 0;
|
||||||
double jd;
|
double jd;
|
||||||
|
@ -76,7 +80,8 @@ void compute_track(orbit_t orb)
|
||||||
int i1 = -1, i2 = -1, i3 = -1;
|
int i1 = -1, i2 = -1, i3 = -1;
|
||||||
int sunlit, sundown;
|
int sunlit, sundown;
|
||||||
|
|
||||||
for (i=0;i<m.length;i++) {
|
for (i = 0; i < m.length; i++)
|
||||||
|
{
|
||||||
// Sun altitude
|
// Sun altitude
|
||||||
if (pt[i].salt < m.saltmin)
|
if (pt[i].salt < m.saltmin)
|
||||||
sundown = 1;
|
sundown = 1;
|
||||||
|
@ -94,13 +99,17 @@ void compute_track(orbit_t orb)
|
||||||
|
|
||||||
// Distances
|
// Distances
|
||||||
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
||||||
rearth=sqrt(satpos.x*satpos.x+satpos.y*satpos.y+satpos.z*satpos.z);
|
rearth =
|
||||||
|
sqrt (satpos.x * satpos.x + satpos.y * satpos.y +
|
||||||
|
satpos.z * satpos.z);
|
||||||
h = rearth - XKMPER;
|
h = rearth - XKMPER;
|
||||||
|
|
||||||
// Angles
|
// Angles
|
||||||
psun = asin (696.0e3 / rsun) * R2D;
|
psun = asin (696.0e3 / rsun) * R2D;
|
||||||
pearth = asin (6378.135 / rearth) * R2D;
|
pearth = asin (6378.135 / rearth) * R2D;
|
||||||
psat=acos((-dx*satpos.x-dy*satpos.y-dz*satpos.z)/(rsun*rearth))*R2D;
|
psat =
|
||||||
|
acos ((-dx * satpos.x - dy * satpos.y -
|
||||||
|
dz * satpos.z) / (rsun * rearth)) * R2D;
|
||||||
|
|
||||||
// Visibility state
|
// Visibility state
|
||||||
if (psat - pearth < -psun)
|
if (psat - pearth < -psun)
|
||||||
|
@ -125,11 +134,19 @@ void compute_track(orbit_t orb)
|
||||||
de = asin (dz / r) * R2D;
|
de = asin (dz / r) * R2D;
|
||||||
|
|
||||||
// Phase
|
// Phase
|
||||||
phase=acos(((pt[i].obspos.x-satpos.x)*(pt[i].sunpos.x-satpos.x)+(pt[i].obspos.y-satpos.y)*(pt[i].sunpos.y-satpos.y)+(pt[i].obspos.z-satpos.z)*(pt[i].sunpos.z-satpos.z))/(rsun*r))*R2D;
|
phase =
|
||||||
|
acos (((pt[i].obspos.x - satpos.x) * (pt[i].sunpos.x - satpos.x) +
|
||||||
|
(pt[i].obspos.y - satpos.y) * (pt[i].sunpos.y - satpos.y) +
|
||||||
|
(pt[i].obspos.z - satpos.z) * (pt[i].sunpos.z -
|
||||||
|
satpos.z)) / (rsun * r)) * R2D;
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
if (strcmp (state, "sunlit") == 0)
|
if (strcmp (state, "sunlit") == 0)
|
||||||
mag=STDMAG-15.0+5*log10(r)-2.5*log10(sin(phase*D2R)+(M_PI-phase*D2R)*cos(phase*D2R));
|
mag =
|
||||||
|
STDMAG - 15.0 + 5 * log10 (r) - 2.5 * log10 (sin (phase * D2R) +
|
||||||
|
(M_PI -
|
||||||
|
phase * D2R) *
|
||||||
|
cos (phase * D2R));
|
||||||
else
|
else
|
||||||
mag = 15;
|
mag = 15;
|
||||||
|
|
||||||
|
@ -142,49 +159,74 @@ void compute_track(orbit_t orb)
|
||||||
pt[i].azi = modulo (azi + 180.0, 360.0);
|
pt[i].azi = modulo (azi + 180.0, 360.0);
|
||||||
|
|
||||||
// Find all passes
|
// Find all passes
|
||||||
if (m.all==1) {
|
if (m.all == 1)
|
||||||
if (i==0) {
|
{
|
||||||
if (alt>=m.altmin && flag==0) {
|
if (i == 0)
|
||||||
|
{
|
||||||
|
if (alt >= m.altmin && flag == 0)
|
||||||
|
{
|
||||||
irise = i;
|
irise = i;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
if (imax==-1 && flag==1) {
|
if (imax == -1 && flag == 1)
|
||||||
|
{
|
||||||
imax = i;
|
imax = i;
|
||||||
flag = 2;
|
flag = 2;
|
||||||
}
|
}
|
||||||
} else if (i==m.length-1) {
|
}
|
||||||
if (alt>=m.altmin && flag==0) {
|
else if (i == m.length - 1)
|
||||||
|
{
|
||||||
|
if (alt >= m.altmin && flag == 0)
|
||||||
|
{
|
||||||
irise = i;
|
irise = i;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
if (imax==-1 && flag==1) {
|
if (imax == -1 && flag == 1)
|
||||||
|
{
|
||||||
imax = i;
|
imax = i;
|
||||||
flag = 2;
|
flag = 2;
|
||||||
}
|
}
|
||||||
if (alt>=m.altmin && flag==2) {
|
if (alt >= m.altmin && flag == 2)
|
||||||
|
{
|
||||||
iset = i;
|
iset = i;
|
||||||
flag = 3;
|
flag = 3;
|
||||||
}
|
}
|
||||||
} else if (i>0) {
|
}
|
||||||
if (alt1<m.altmin && alt>=m.altmin && flag==0) {
|
else if (i > 0)
|
||||||
|
{
|
||||||
|
if (alt1 < m.altmin && alt >= m.altmin && flag == 0)
|
||||||
|
{
|
||||||
irise = i;
|
irise = i;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
} else if (alt1>m.altmin && alt<=m.altmin && flag==2) {
|
}
|
||||||
|
else if (alt1 > m.altmin && alt <= m.altmin && flag == 2)
|
||||||
|
{
|
||||||
iset = i;
|
iset = i;
|
||||||
flag = 3;
|
flag = 3;
|
||||||
} else if (flag==1 && alt<alt1) {
|
}
|
||||||
|
else if (flag == 1 && alt < alt1)
|
||||||
|
{
|
||||||
imax = i - 1;
|
imax = i - 1;
|
||||||
flag = 2;
|
flag = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (flag==0 && alt>=m.altmin && sundown==1 && sunlit==1) {
|
else
|
||||||
|
{
|
||||||
|
if (flag == 0 && alt >= m.altmin && sundown == 1 && sunlit == 1)
|
||||||
|
{
|
||||||
irise = i;
|
irise = i;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
} else if (flag==1 && (alt<alt1 || !(sundown==1 && sunlit==1))) {
|
}
|
||||||
|
else if (flag == 1
|
||||||
|
&& (alt < alt1 || !(sundown == 1 && sunlit == 1)))
|
||||||
|
{
|
||||||
imax = i - 1;
|
imax = i - 1;
|
||||||
flag = 2;
|
flag = 2;
|
||||||
} else if (flag==2 && !(alt>=m.altmin && sundown==1 && sunlit==1)) {
|
}
|
||||||
|
else if (flag == 2
|
||||||
|
&& !(alt >= m.altmin && sundown == 1 && sunlit == 1))
|
||||||
|
{
|
||||||
iset = i;
|
iset = i;
|
||||||
flag = 3;
|
flag = 3;
|
||||||
}
|
}
|
||||||
|
@ -204,7 +246,8 @@ void compute_track(orbit_t orb)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag==3) {
|
if (flag == 3)
|
||||||
|
{
|
||||||
i1 = irise;
|
i1 = irise;
|
||||||
i2 = imax;
|
i2 = imax;
|
||||||
i3 = iset;
|
i3 = iset;
|
||||||
|
@ -216,12 +259,17 @@ void compute_track(orbit_t orb)
|
||||||
p[ipass].length = 86400.0 * (pt[i3].mjd - pt[i1].mjd);
|
p[ipass].length = 86400.0 * (pt[i3].mjd - pt[i1].mjd);
|
||||||
p[ipass].altmax = pt[i2].alt;
|
p[ipass].altmax = pt[i2].alt;
|
||||||
|
|
||||||
sprintf(p[ipass].line,"%05d | %s %3.0f/%2.0f | %.8s %3.0f/%2.0f | %.8s %3.0f/%2.0f | \n",orb.satno,
|
sprintf (p[ipass].line,
|
||||||
pt[i1].nfd,pt[i1].azi,pt[i1].alt,
|
"%05d | %s %3.0f/%2.0f | %.8s %3.0f/%2.0f | %.8s %3.0f/%2.0f | \n",
|
||||||
pt[i2].nfd+11,pt[i2].azi,pt[i2].alt,
|
orb.satno, pt[i1].nfd, pt[i1].azi, pt[i1].alt,
|
||||||
pt[i3].nfd+11,pt[i3].azi,pt[i3].alt);
|
pt[i2].nfd + 11, pt[i2].azi, pt[i2].alt, pt[i3].nfd + 11,
|
||||||
sprintf(p[ipass].radio,"%05d %s %s %s %4.0f %5.1f\n",orb.satno,pt[i1].nfd,pt[i2].nfd,pt[i3].nfd,p[ipass].length,pt[i2].alt);
|
pt[i3].azi, pt[i3].alt);
|
||||||
sprintf(p[ipass].skymap,"skymap -c %s -i %d -s %d -t %s -l %.0f",m.tlefile,orb.satno,m.site_id,pt[i1].nfd,p[ipass].length);
|
sprintf (p[ipass].radio, "%05d %s %s %s %4.0f %5.1f\n", orb.satno,
|
||||||
|
pt[i1].nfd, pt[i2].nfd, pt[i3].nfd, p[ipass].length,
|
||||||
|
pt[i2].alt);
|
||||||
|
sprintf (p[ipass].skymap, "skymap -c %s -i %d -s %d -t %s -l %.0f",
|
||||||
|
m.tlefile, orb.satno, m.site_id, pt[i1].nfd,
|
||||||
|
p[ipass].length);
|
||||||
|
|
||||||
flag = 0;
|
flag = 0;
|
||||||
irise = -1;
|
irise = -1;
|
||||||
|
@ -240,7 +288,8 @@ void compute_track(orbit_t orb)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int qsort_compare_mjdrise(const void *a,const void *b)
|
int
|
||||||
|
qsort_compare_mjdrise (const void *a, const void *b)
|
||||||
{
|
{
|
||||||
struct pass *pa = (struct pass *) a;
|
struct pass *pa = (struct pass *) a;
|
||||||
struct pass *pb = (struct pass *) b;
|
struct pass *pb = (struct pass *) b;
|
||||||
|
@ -253,7 +302,8 @@ int qsort_compare_mjdrise(const void *a,const void *b)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0, radio = 0;
|
int arg = 0, radio = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -264,8 +314,10 @@ int main(int argc,char *argv[])
|
||||||
initialize_setup ();
|
initialize_setup ();
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"t:c:i:s:l:hS:A:aPqm:RM:"))!=-1) {
|
while ((arg = getopt (argc, argv, "t:c:i:s:l:hS:A:aPqm:RM:")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'R':
|
case 'R':
|
||||||
radio = 1;
|
radio = 1;
|
||||||
|
@ -353,7 +405,8 @@ int main(int argc,char *argv[])
|
||||||
fatal_error ("File open failed for reading %s\n", m.tlefile);
|
fatal_error ("File open failed for reading %s\n", m.tlefile);
|
||||||
|
|
||||||
// Loop over objects
|
// Loop over objects
|
||||||
while (read_twoline(file,m.satno,&orb)==0) {
|
while (read_twoline (file, m.satno, &orb) == 0)
|
||||||
|
{
|
||||||
Isat = orb.satno;
|
Isat = orb.satno;
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
|
|
||||||
|
@ -378,7 +431,8 @@ int main(int argc,char *argv[])
|
||||||
print_header ();
|
print_header ();
|
||||||
|
|
||||||
// Print passes
|
// Print passes
|
||||||
for (ipass=0;ipass<npass;ipass++) {
|
for (ipass = 0; ipass < npass; ipass++)
|
||||||
|
{
|
||||||
if (radio == 0)
|
if (radio == 0)
|
||||||
printf ("%s", p[ipass].line);
|
printf ("%s", p[ipass].line);
|
||||||
else if (radio == 1 && p[ipass].altmax > m.altmax)
|
else if (radio == 1 && p[ipass].altmax > m.altmax)
|
||||||
|
@ -394,12 +448,14 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -407,7 +463,8 @@ double nfd2mjd(char *date)
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage()
|
void
|
||||||
|
usage ()
|
||||||
{
|
{
|
||||||
printf ("pass t:c:i:s:l:hS:A:aPqm:R\n\n");
|
printf ("pass t:c:i:s:l:hS:A:aPqm:R\n\n");
|
||||||
printf ("t date/time (yyyy-mm-ddThh:mm:ss.sss) [default: now]\n");
|
printf ("t date/time (yyyy-mm-ddThh:mm:ss.sss) [default: now]\n");
|
||||||
|
@ -428,7 +485,8 @@ void usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date,int length)
|
void
|
||||||
|
mjd2date (double mjd, char *date, int length)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -443,7 +501,8 @@ void mjd2date(double mjd,char *date,int length)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -474,19 +533,23 @@ void mjd2date(double mjd,char *date,int length)
|
||||||
sec = floor (1000.0 * sec) / 1000.0;
|
sec = floor (1000.0 * sec) / 1000.0;
|
||||||
|
|
||||||
if (length == 3)
|
if (length == 3)
|
||||||
sprintf(date,"%04d-%02d-%02dT%02d:%02d:%06.3f",year,month,day,hour,min,sec);
|
sprintf (date, "%04d-%02d-%02dT%02d:%02d:%06.3f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
else if (length == 0)
|
else if (length == 0)
|
||||||
sprintf(date,"%04d-%02d-%02dT%02d:%02d:%02.0f",year,month,day,hour,min,sec);
|
sprintf (date, "%04d-%02d-%02dT%02d:%02d:%02.0f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -494,17 +557,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize setup
|
// Initialize setup
|
||||||
void initialize_setup(void)
|
void
|
||||||
|
initialize_setup (void)
|
||||||
{
|
{
|
||||||
char *env;
|
char *env;
|
||||||
|
|
||||||
|
@ -526,21 +595,30 @@ void initialize_setup(void)
|
||||||
|
|
||||||
// Get environment variables
|
// Get environment variables
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (m.datadir, env);
|
strcpy (m.datadir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_DATADIR environment variable not found.\n");
|
printf ("ST_DATADIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
env = getenv ("ST_COSPAR");
|
env = getenv ("ST_COSPAR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
get_site (atoi (env));
|
get_site (atoi (env));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_COSPAR environment variable not found.\n");
|
printf ("ST_COSPAR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
env = getenv ("ST_TLEDIR");
|
env = getenv ("ST_TLEDIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (m.tledir, env);
|
strcpy (m.tledir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_TLEDIR environment variable not found.\n");
|
printf ("ST_TLEDIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
sprintf (m.tlefile, "%s/classfd.tle", m.tledir);
|
sprintf (m.tlefile, "%s/classfd.tle", m.tledir);
|
||||||
|
@ -549,7 +627,8 @@ void initialize_setup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -561,11 +640,13 @@ void get_site(int site_id)
|
||||||
|
|
||||||
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -574,14 +655,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
@ -596,7 +677,8 @@ void get_site(int site_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -605,22 +687,27 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print header
|
// Print header
|
||||||
void print_header(void)
|
void
|
||||||
|
print_header (void)
|
||||||
{
|
{
|
||||||
printf("Observer: %s (%04d) [%+.4f, %+.4f, %.0fm]\n",m.observer,m.site_id,m.lat,m.lng,m.alt*1000.0);
|
printf ("Observer: %s (%04d) [%+.4f, %+.4f, %.0fm]\n", m.observer,
|
||||||
|
m.site_id, m.lat, m.lng, m.alt * 1000.0);
|
||||||
printf ("Elements: %s\n", m.tlefile);
|
printf ("Elements: %s\n", m.tlefile);
|
||||||
printf ("UT Date/Time: %s for %g h \n", m.nfd, m.length / 3600.0);
|
printf ("UT Date/Time: %s for %g h \n", m.nfd, m.length / 3600.0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observer position
|
// Observer position
|
||||||
void obspos_xyz(double mjd,xyz_t *pos,xyz_t *vel)
|
void
|
||||||
|
obspos_xyz (double mjd, xyz_t * pos, xyz_t * vel)
|
||||||
{
|
{
|
||||||
double ff, gc, gs, theta, s, dtheta;
|
double ff, gc, gs, theta, s, dtheta;
|
||||||
|
|
||||||
|
@ -643,7 +730,8 @@ void obspos_xyz(double mjd,xyz_t *pos,xyz_t *vel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Solar position
|
// Solar position
|
||||||
void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
void
|
||||||
|
sunpos_xyz (double mjd, xyz_t * pos, double *ra, double *de)
|
||||||
{
|
{
|
||||||
double jd, t, l0, m, e, c, r;
|
double jd, t, l0, m, e, c, r;
|
||||||
double n, s, ecl;
|
double n, s, ecl;
|
||||||
|
@ -660,7 +748,10 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
||||||
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
||||||
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
||||||
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
||||||
ecl=(23.43929111+(-46.8150*t-0.00059*t*t+0.001813*t*t*t)/3600.0+0.00256*cos(n))*D2R;
|
ecl =
|
||||||
|
(23.43929111 +
|
||||||
|
(-46.8150 * t - 0.00059 * t * t + 0.001813 * t * t * t) / 3600.0 +
|
||||||
|
0.00256 * cos (n)) * D2R;
|
||||||
|
|
||||||
*ra = atan2 (cos (ecl) * sin (s), cos (s)) * R2D;
|
*ra = atan2 (cos (ecl) * sin (s), cos (s)) * R2D;
|
||||||
*de = asin (sin (ecl) * sin (s)) * R2D;
|
*de = asin (sin (ecl) * sin (s)) * R2D;
|
||||||
|
@ -673,19 +764,23 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double dgmst(double mjd)
|
double
|
||||||
|
dgmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, dgmst;
|
double t, dgmst;
|
||||||
|
|
||||||
|
@ -697,47 +792,66 @@ double dgmst(double mjd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert equatorial into horizontal coordinates
|
// Convert equatorial into horizontal coordinates
|
||||||
void equatorial2horizontal(double mjd,double ra,double de,double *azi,double *alt)
|
void
|
||||||
|
equatorial2horizontal (double mjd, double ra, double de, double *azi,
|
||||||
|
double *alt)
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
|
|
||||||
h = gmst (mjd) + m.lng - ra;
|
h = gmst (mjd) + m.lng - ra;
|
||||||
|
|
||||||
*azi=modulo(atan2(sin(h*D2R),cos(h*D2R)*sin(m.lat*D2R)-tan(de*D2R)*cos(m.lat*D2R))*R2D,360.0);
|
*azi =
|
||||||
*alt=asin(sin(m.lat*D2R)*sin(de*D2R)+cos(m.lat*D2R)*cos(de*D2R)*cos(h*D2R))*R2D;
|
modulo (atan2
|
||||||
|
(sin (h * D2R),
|
||||||
|
cos (h * D2R) * sin (m.lat * D2R) -
|
||||||
|
tan (de * D2R) * cos (m.lat * D2R)) * R2D, 360.0);
|
||||||
|
*alt =
|
||||||
|
asin (sin (m.lat * D2R) * sin (de * D2R) +
|
||||||
|
cos (m.lat * D2R) * cos (de * D2R) * cos (h * D2R)) * R2D;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert horizontal into equatorial coordinates
|
// Convert horizontal into equatorial coordinates
|
||||||
void horizontal2equatorial(double mjd,double azi,double alt,double *ra,double *de)
|
void
|
||||||
|
horizontal2equatorial (double mjd, double azi, double alt, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
|
|
||||||
h=atan2(sin(azi*D2R),cos(azi*D2R)*sin(m.lat*D2R)+tan(alt*D2R)*cos(m.lat*D2R))*R2D;
|
h =
|
||||||
|
atan2 (sin (azi * D2R),
|
||||||
|
cos (azi * D2R) * sin (m.lat * D2R) +
|
||||||
|
tan (alt * D2R) * cos (m.lat * D2R)) * R2D;
|
||||||
*ra = modulo (gmst (mjd) + m.lng - h, 360.0);
|
*ra = modulo (gmst (mjd) + m.lng - h, 360.0);
|
||||||
*de=asin(sin(m.lat*D2R)*sin(alt*D2R)-cos(m.lat*D2R)*cos(alt*D2R)*cos(azi*D2R))*R2D;
|
*de =
|
||||||
|
asin (sin (m.lat * D2R) * sin (alt * D2R) -
|
||||||
|
cos (m.lat * D2R) * cos (alt * D2R) * cos (azi * D2R)) * R2D;
|
||||||
if (*ra < 0.0)
|
if (*ra < 0.0)
|
||||||
*ra += 360.0;
|
*ra += 360.0;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void compute_observer_and_solar_positions(void)
|
void
|
||||||
|
compute_observer_and_solar_positions (void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
xyz_t obsvel;
|
xyz_t obsvel;
|
||||||
|
|
||||||
for (i=0;i<m.length;i++) {
|
for (i = 0; i < m.length; i++)
|
||||||
|
{
|
||||||
// Compute MJDs
|
// Compute MJDs
|
||||||
pt[i].mjd = m.mjd + (double) i / 86400.0;
|
pt[i].mjd = m.mjd + (double) i / 86400.0;
|
||||||
mjd2date (pt[i].mjd, pt[i].nfd, 0);
|
mjd2date (pt[i].mjd, pt[i].nfd, 0);
|
||||||
|
@ -747,7 +861,8 @@ void compute_observer_and_solar_positions(void)
|
||||||
|
|
||||||
// Solar position
|
// Solar position
|
||||||
sunpos_xyz (pt[i].mjd, &pt[i].sunpos, &pt[i].sra, &pt[i].sde);
|
sunpos_xyz (pt[i].mjd, &pt[i].sunpos, &pt[i].sra, &pt[i].sde);
|
||||||
equatorial2horizontal(pt[i].mjd,pt[i].sra,pt[i].sde,&pt[i].sazi,&pt[i].salt);
|
equatorial2horizontal (pt[i].mjd, pt[i].sra, pt[i].sde, &pt[i].sazi,
|
||||||
|
&pt[i].salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
190
src/pgm2fits.c
190
src/pgm2fits.c
|
@ -6,12 +6,14 @@
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int nx, ny;
|
int nx, ny;
|
||||||
char timestamp[64];
|
char timestamp[64];
|
||||||
unsigned char *c;
|
unsigned char *c;
|
||||||
};
|
};
|
||||||
struct fourframe {
|
struct fourframe
|
||||||
|
{
|
||||||
int nx, ny, nt, nlayer;
|
int nx, ny, nt, nlayer;
|
||||||
char timestamp[64], observer[64];
|
char timestamp[64], observer[64];
|
||||||
double mjd;
|
double mjd;
|
||||||
|
@ -26,7 +28,8 @@ double date2mjd(int year,int month,double day);
|
||||||
void write_pgm (char *filename, struct fourframe ff);
|
void write_pgm (char *filename, struct fourframe ff);
|
||||||
void mjd2date (double mjd, char *date);
|
void mjd2date (double mjd, char *date);
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf ("pgm2fits p:w:h:s:n:Dd:x:y:c:o:gm:t:r:I\n\n");
|
printf ("pgm2fits p:w:h:s:n:Dd:x:y:c:o:gm:t:r:I\n\n");
|
||||||
printf ("-p image prefix\n");
|
printf ("-p image prefix\n");
|
||||||
|
@ -49,9 +52,11 @@ void usage(void)
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i,j,k,l,m,k0=1,status,nt,darkout=0,darkin=0,track=0,maskin=0;
|
int i, j, k, l, m, k0 = 1, status, nt, darkout = 0, darkin = 0, track =
|
||||||
|
0, maskin = 0;
|
||||||
int n, n0, di, dj, npix;
|
int n, n0, di, dj, npix;
|
||||||
struct image *img, drk, msk;
|
struct image *img, drk, msk;
|
||||||
struct fourframe ff;
|
struct fourframe ff;
|
||||||
|
@ -74,9 +79,13 @@ int main(int argc,char *argv[])
|
||||||
ff.type = 0;
|
ff.type = 0;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
if (argc>1) {
|
if (argc > 1)
|
||||||
while ((arg=getopt(argc,argv,"p:w:h:s:n:Dd:x:y:c:o:gm:t:r:I"))!=-1) {
|
{
|
||||||
switch(arg) {
|
while ((arg =
|
||||||
|
getopt (argc, argv, "p:w:h:s:n:Dd:x:y:c:o:gm:t:r:I")) != -1)
|
||||||
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
case 'p':
|
case 'p':
|
||||||
path = optarg;
|
path = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -152,7 +161,9 @@ int main(int argc,char *argv[])
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,21 +189,27 @@ int main(int argc,char *argv[])
|
||||||
msk = read_pgm (maskfile, &status);
|
msk = read_pgm (maskfile, &status);
|
||||||
|
|
||||||
// Loop over files
|
// Loop over files
|
||||||
for (k=0,l=0;k<nt;k++) {
|
for (k = 0, l = 0; k < nt; k++)
|
||||||
|
{
|
||||||
sprintf (filename, "%s%06d.pgm", path, k + k0);
|
sprintf (filename, "%s%06d.pgm", path, k + k0);
|
||||||
img[l] = read_pgm (filename, &status);
|
img[l] = read_pgm (filename, &status);
|
||||||
|
|
||||||
// Reset time
|
// Reset time
|
||||||
if (timereset==1) {
|
if (timereset == 1)
|
||||||
|
{
|
||||||
mjd = mjd0 + (double) (k + k0) / (86400.0 * framerate);
|
mjd = mjd0 + (double) (k + k0) / (86400.0 * framerate);
|
||||||
mjd2date (mjd, img[l].timestamp);
|
mjd2date (mjd, img[l].timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
ff.dt[l]=86400.0*(nfd2mjd(img[l].timestamp)-nfd2mjd(img[0].timestamp));
|
ff.dt[l] =
|
||||||
if (status==0) {
|
86400.0 * (nfd2mjd (img[l].timestamp) - nfd2mjd (img[0].timestamp));
|
||||||
|
if (status == 0)
|
||||||
|
{
|
||||||
printf ("Read %s\n", filename);
|
printf ("Read %s\n", filename);
|
||||||
l++;
|
l++;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,8 +219,10 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
printf ("Accumulating image statistics\n");
|
printf ("Accumulating image statistics\n");
|
||||||
// Loop over pixels
|
// Loop over pixels
|
||||||
for (i=0;i<ff.nx;i++) {
|
for (i = 0; i < ff.nx; i++)
|
||||||
for (j=0;j<ff.ny;j++) {
|
{
|
||||||
|
for (j = 0; j < ff.ny; j++)
|
||||||
|
{
|
||||||
n = i + ff.nx * j;
|
n = i + ff.nx * j;
|
||||||
|
|
||||||
s1 = 0.0;
|
s1 = 0.0;
|
||||||
|
@ -212,14 +231,16 @@ int main(int argc,char *argv[])
|
||||||
cnt = 0.0;
|
cnt = 0.0;
|
||||||
|
|
||||||
// Loop over images
|
// Loop over images
|
||||||
for (k=0;k<ff.nt;k++) {
|
for (k = 0; k < ff.nt; k++)
|
||||||
|
{
|
||||||
if (darkin == 0)
|
if (darkin == 0)
|
||||||
z = (float) img[k].c[n];
|
z = (float) img[k].c[n];
|
||||||
else if (darkin == 1)
|
else if (darkin == 1)
|
||||||
z = (float) (img[k].c[n] - drk.c[n]);
|
z = (float) (img[k].c[n] - drk.c[n]);
|
||||||
s1 += z;
|
s1 += z;
|
||||||
s2 += z * z;
|
s2 += z * z;
|
||||||
if (z>max) {
|
if (z > max)
|
||||||
|
{
|
||||||
max = z;
|
max = z;
|
||||||
cnt = (float) k;
|
cnt = (float) k;
|
||||||
}
|
}
|
||||||
|
@ -230,36 +251,46 @@ int main(int argc,char *argv[])
|
||||||
std = sqrt ((s2 - s1 * avg) / (float) (ff.nt - 2));
|
std = sqrt ((s2 - s1 * avg) / (float) (ff.nt - 2));
|
||||||
|
|
||||||
// Reset masked pixels
|
// Reset masked pixels
|
||||||
if (maskin==1 && msk.c[n]==0.0) {
|
if (maskin == 1 && msk.c[n] == 0.0)
|
||||||
|
{
|
||||||
avg = 0.0;
|
avg = 0.0;
|
||||||
std = 0.0;
|
std = 0.0;
|
||||||
max = 0.0;
|
max = 0.0;
|
||||||
cnt = 128.0;
|
cnt = 128.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (m=0;m<ff.nlayer;m++) {
|
for (m = 0; m < ff.nlayer; m++)
|
||||||
|
{
|
||||||
l = i + (ff.ny - j - 1) * ff.nx + m * ff.nx * ff.ny;
|
l = i + (ff.ny - j - 1) * ff.nx + m * ff.nx * ff.ny;
|
||||||
if (m==0) ff.z[l]=avg;
|
if (m == 0)
|
||||||
if (m==1) ff.z[l]=std;
|
ff.z[l] = avg;
|
||||||
if (m==2) ff.z[l]=max;
|
if (m == 1)
|
||||||
if (m==3) ff.z[l]=cnt;
|
ff.z[l] = std;
|
||||||
if (m==4) ff.z[l]=avg;
|
if (m == 2)
|
||||||
|
ff.z[l] = max;
|
||||||
|
if (m == 3)
|
||||||
|
ff.z[l] = cnt;
|
||||||
|
if (m == 4)
|
||||||
|
ff.z[l] = avg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create tracked layer
|
// Create tracked layer
|
||||||
if (track==1) {
|
if (track == 1)
|
||||||
|
{
|
||||||
printf ("Creating tracked layer\n");
|
printf ("Creating tracked layer\n");
|
||||||
|
|
||||||
// Set weights
|
// Set weights
|
||||||
for (i=0;i<ff.nx*ff.ny;i++) {
|
for (i = 0; i < ff.nx * ff.ny; i++)
|
||||||
|
{
|
||||||
wt[i] = 0;
|
wt[i] = 0;
|
||||||
trk[i] = 0.0;
|
trk[i] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over frames
|
// Loop over frames
|
||||||
for (l=0;l<ff.nt;l++) {
|
for (l = 0; l < ff.nt; l++)
|
||||||
|
{
|
||||||
// Offset
|
// Offset
|
||||||
dx = dxdn * (l - ff.nt / 2);
|
dx = dxdn * (l - ff.nt / 2);
|
||||||
dy = dydn * (l - ff.nt / 2);
|
dy = dydn * (l - ff.nt / 2);
|
||||||
|
@ -269,11 +300,15 @@ int main(int argc,char *argv[])
|
||||||
dj = (int) floor (dy + 0.5);
|
dj = (int) floor (dy + 0.5);
|
||||||
|
|
||||||
// Set
|
// Set
|
||||||
for (i=0;i<ff.nx;i++) {
|
for (i = 0; i < ff.nx; i++)
|
||||||
for (j=0;j<ff.ny;j++) {
|
{
|
||||||
|
for (j = 0; j < ff.ny; j++)
|
||||||
|
{
|
||||||
k = i + ff.nx * j;
|
k = i + ff.nx * j;
|
||||||
k0 = i + di + ff.nx * (j + dj);
|
k0 = i + di + ff.nx * (j + dj);
|
||||||
if (i+di>0 && i+di<ff.nx && j+dj>0 && j+dj<ff.ny) {
|
if (i + di > 0 && i + di < ff.nx && j + dj > 0
|
||||||
|
&& j + dj < ff.ny)
|
||||||
|
{
|
||||||
wt[k] += 1;
|
wt[k] += 1;
|
||||||
trk[k] += (float) img[l].c[k0];
|
trk[k] += (float) img[l].c[k0];
|
||||||
}
|
}
|
||||||
|
@ -281,8 +316,10 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Save layer
|
// Save layer
|
||||||
for (i=0;i<ff.nx;i++) {
|
for (i = 0; i < ff.nx; i++)
|
||||||
for (j=0;j<ff.ny;j++) {
|
{
|
||||||
|
for (j = 0; j < ff.ny; j++)
|
||||||
|
{
|
||||||
k = i + ff.nx * j;
|
k = i + ff.nx * j;
|
||||||
if (guide == 0)
|
if (guide == 0)
|
||||||
l = i + (ff.ny - j - 1) * ff.nx;
|
l = i + (ff.ny - j - 1) * ff.nx;
|
||||||
|
@ -320,7 +357,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read pgm file
|
// Read pgm file
|
||||||
struct image read_pgm(char *filename,int *status)
|
struct image
|
||||||
|
read_pgm (char *filename, int *status)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct image img;
|
struct image img;
|
||||||
|
@ -329,25 +367,30 @@ struct image read_pgm(char *filename,int *status)
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (filename, "rb");
|
file = fopen (filename, "rb");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
*status = 1;
|
*status = 1;
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read PGM format
|
// Read PGM format
|
||||||
fgetline (file, hbuf, 64);
|
fgetline (file, hbuf, 64);
|
||||||
if (strcmp(hbuf,"P5")!=0) {
|
if (strcmp (hbuf, "P5") != 0)
|
||||||
|
{
|
||||||
printf ("Not a valid PGM file!\n");
|
printf ("Not a valid PGM file!\n");
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read timestamp/image size
|
// Read timestamp/image size
|
||||||
fgetline (file, hbuf, 64);
|
fgetline (file, hbuf, 64);
|
||||||
if (strstr(hbuf,"#")!=NULL) {
|
if (strstr (hbuf, "#") != NULL)
|
||||||
|
{
|
||||||
strcpy (img.timestamp, hbuf + 2);
|
strcpy (img.timestamp, hbuf + 2);
|
||||||
fgetline (file, hbuf, 64);
|
fgetline (file, hbuf, 64);
|
||||||
sscanf (hbuf, "%d %d", &img.nx, &img.ny);
|
sscanf (hbuf, "%d %d", &img.nx, &img.ny);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
strcpy (img.timestamp, "2012-01-01T00:00:00");
|
strcpy (img.timestamp, "2012-01-01T00:00:00");
|
||||||
sscanf (hbuf, "%d %d", &img.nx, &img.ny);
|
sscanf (hbuf, "%d %d", &img.nx, &img.ny);
|
||||||
}
|
}
|
||||||
|
@ -367,7 +410,8 @@ struct image read_pgm(char *filename,int *status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get line
|
// Get line
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -381,7 +425,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write fits file
|
// Write fits file
|
||||||
void write_fits(char *filename,struct fourframe ff)
|
void
|
||||||
|
write_fits (char *filename, struct fourframe ff)
|
||||||
{
|
{
|
||||||
int i, j, k, l;
|
int i, j, k, l;
|
||||||
float *fbuf;
|
float *fbuf;
|
||||||
|
@ -449,14 +494,16 @@ void write_fits(char *filename,struct fourframe ff)
|
||||||
qfits_header_add (qh, "OBSERVER", val, " ", NULL);
|
qfits_header_add (qh, "OBSERVER", val, " ", NULL);
|
||||||
|
|
||||||
// Add timestamps
|
// Add timestamps
|
||||||
for (k=0;k<ff.nt;k++) {
|
for (k = 0; k < ff.nt; k++)
|
||||||
|
{
|
||||||
sprintf (key, "DT%04d", k);
|
sprintf (key, "DT%04d", k);
|
||||||
sprintf (val, "%f", ff.dt[k]);
|
sprintf (val, "%f", ff.dt[k]);
|
||||||
qfits_header_add (qh, key, val, " ", NULL);
|
qfits_header_add (qh, key, val, " ", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dummy keywords
|
// Dummy keywords
|
||||||
for (k=0;k<10;k++) {
|
for (k = 0; k < 10; k++)
|
||||||
|
{
|
||||||
sprintf (key, "DUMY%03d", k);
|
sprintf (key, "DUMY%03d", k);
|
||||||
qfits_header_add (qh, key, "0.0", " ", NULL);
|
qfits_header_add (qh, key, "0.0", " ", NULL);
|
||||||
}
|
}
|
||||||
|
@ -473,9 +520,12 @@ void write_fits(char *filename,struct fourframe ff)
|
||||||
// Fill buffer
|
// Fill buffer
|
||||||
fbuf = malloc (ff.nlayer * ff.nx * ff.ny * sizeof (float));
|
fbuf = malloc (ff.nlayer * ff.nx * ff.ny * sizeof (float));
|
||||||
ibuf = malloc (ff.nlayer * ff.nx * ff.ny * sizeof (int));
|
ibuf = malloc (ff.nlayer * ff.nx * ff.ny * sizeof (int));
|
||||||
for (i=0,l=0;i<ff.nx;i++) {
|
for (i = 0, l = 0; i < ff.nx; i++)
|
||||||
for (j=ff.ny-1;j>=0;j--) {
|
{
|
||||||
for (k=0;k<ff.nlayer;k++) {
|
for (j = ff.ny - 1; j >= 0; j--)
|
||||||
|
{
|
||||||
|
for (k = 0; k < ff.nlayer; k++)
|
||||||
|
{
|
||||||
fbuf[l] = ff.z[l];
|
fbuf[l] = ff.z[l];
|
||||||
ibuf[l] = (int) ff.z[l];
|
ibuf[l] = (int) ff.z[l];
|
||||||
|
|
||||||
|
@ -487,11 +537,14 @@ void write_fits(char *filename,struct fourframe ff)
|
||||||
// Set parameters
|
// Set parameters
|
||||||
qd.filename = filename;
|
qd.filename = filename;
|
||||||
qd.npix = ff.nlayer * ff.nx * ff.ny;
|
qd.npix = ff.nlayer * ff.nx * ff.ny;
|
||||||
if (ff.type==1) {
|
if (ff.type == 1)
|
||||||
|
{
|
||||||
qd.ptype = PTYPE_INT;
|
qd.ptype = PTYPE_INT;
|
||||||
qd.ibuf = ibuf;
|
qd.ibuf = ibuf;
|
||||||
qd.out_ptype = BPP_8_UNSIGNED;
|
qd.out_ptype = BPP_8_UNSIGNED;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
qd.ptype = PTYPE_FLOAT;
|
qd.ptype = PTYPE_FLOAT;
|
||||||
qd.fbuf = fbuf;
|
qd.fbuf = fbuf;
|
||||||
qd.out_ptype = -32;
|
qd.out_ptype = -32;
|
||||||
|
@ -507,12 +560,14 @@ void write_fits(char *filename,struct fourframe ff)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -520,23 +575,30 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min;
|
int year, month, day, hour, min;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
float sec;
|
float sec;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%f",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%f", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
|
||||||
|
@ -544,15 +606,18 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write pgm file
|
// Write pgm file
|
||||||
void write_pgm(char *filename,struct fourframe ff)
|
void
|
||||||
|
write_pgm (char *filename, struct fourframe ff)
|
||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
file = fopen (filename, "w");
|
file = fopen (filename, "w");
|
||||||
fprintf (file, "P5\n# 2013-01-01T00:00:00\n%d %d\n255\n", ff.nx, ff.ny);
|
fprintf (file, "P5\n# 2013-01-01T00:00:00\n%d %d\n255\n", ff.nx, ff.ny);
|
||||||
for (j=0;j<ff.ny;j++) {
|
for (j = 0; j < ff.ny; j++)
|
||||||
for (i=0;i<ff.nx;i++) {
|
{
|
||||||
|
for (i = 0; i < ff.nx; i++)
|
||||||
|
{
|
||||||
k = i + (ff.ny - j - 1) * ff.nx;
|
k = i + (ff.ny - j - 1) * ff.nx;
|
||||||
fprintf (file, "%c", (char) ff.z[k]);
|
fprintf (file, "%c", (char) ff.z[k]);
|
||||||
}
|
}
|
||||||
|
@ -563,7 +628,8 @@ void write_pgm(char *filename,struct fourframe ff)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date)
|
void
|
||||||
|
mjd2date (double mjd, char *date)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -578,7 +644,8 @@ void mjd2date(double mjd,char *date)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -607,7 +674,8 @@ void mjd2date(double mjd,char *date)
|
||||||
x = (x - min) / 60.;
|
x = (x - min) / 60.;
|
||||||
hour = x;
|
hour = x;
|
||||||
|
|
||||||
sprintf(date,"%04d-%02d-%02dT%02d:%02d:%06.3f",year,month,day,hour,min,sec);
|
sprintf (date, "%04d-%02d-%02dT%02d:%02d:%06.3f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
296
src/planscan.c
296
src/planscan.c
|
@ -22,7 +22,8 @@
|
||||||
long Isat = 0;
|
long Isat = 0;
|
||||||
long Isatsel = 0;
|
long Isatsel = 0;
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
double lat, lng;
|
double lat, lng;
|
||||||
float alt;
|
float alt;
|
||||||
char observer[32];
|
char observer[32];
|
||||||
|
@ -37,12 +38,15 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de);
|
||||||
double gmst (double mjd);
|
double gmst (double mjd);
|
||||||
double dgmst (double mjd);
|
double dgmst (double mjd);
|
||||||
double modulo (double x, double y);
|
double modulo (double x, double y);
|
||||||
void equatorial2horizontal(double mjd,double ra,double de,double *azi,double *alt);
|
void equatorial2horizontal (double mjd, double ra, double de, double *azi,
|
||||||
|
double *alt);
|
||||||
void mjd2date (double mjd, char *date);
|
void mjd2date (double mjd, char *date);
|
||||||
int properties(kep_t K,xyz_t obspos,xyz_t sunpos,float radius,float t,double *ra,double *de,double *r,float *mag);
|
int properties (kep_t K, xyz_t obspos, xyz_t sunpos, float radius, float t,
|
||||||
|
double *ra, double *de, double *r, float *mag);
|
||||||
void dec2s (double x, char *s, int f, int len);
|
void dec2s (double x, char *s, int f, int len);
|
||||||
|
|
||||||
float semimajoraxis(orbit_t orb)
|
float
|
||||||
|
semimajoraxis (orbit_t orb)
|
||||||
{
|
{
|
||||||
float xno, eo, xincl;
|
float xno, eo, xincl;
|
||||||
float a1, betao2, betao, temp0, del1, a0, del0, xnodp, aodp;
|
float a1, betao2, betao, temp0, del1, a0, del0, xnodp, aodp;
|
||||||
|
@ -65,26 +69,37 @@ float semimajoraxis(orbit_t orb)
|
||||||
return aodp;
|
return aodp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf("planscan -t <UT Date/time> -c <catalog> -s <site> -l <length> -i <NORAD>\n");
|
printf
|
||||||
|
("planscan -t <UT Date/time> -c <catalog> -s <site> -l <length> -i <NORAD>\n");
|
||||||
printf (" -r <altitude> -A <elevation> -S <elevation>\n\n");
|
printf (" -r <altitude> -A <elevation> -S <elevation>\n\n");
|
||||||
printf("-t <UT Date/time> UT Start date/time in yyyy-mm-ddThh:mm:ss [default: now]\n");
|
printf
|
||||||
printf("-c <catalog> Input TLE catalog to use [default: classfd.tle]\n");
|
("-t <UT Date/time> UT Start date/time in yyyy-mm-ddThh:mm:ss [default: now]\n");
|
||||||
|
printf
|
||||||
|
("-c <catalog> Input TLE catalog to use [default: classfd.tle]\n");
|
||||||
printf ("-s <site> Site number from sites.txt [default: 4171]\n");
|
printf ("-s <site> Site number from sites.txt [default: 4171]\n");
|
||||||
printf("-l <length> Search length from UT start in seconds [default: 86400 s]\n");
|
printf
|
||||||
printf("-i <NORAD> NORAD number of satellite to select [default: 41334]\n");
|
("-l <length> Search length from UT start in seconds [default: 86400 s]\n");
|
||||||
printf("-r <altitude> Satellite altitude above surface in km [default: mean orbital altitude]\n");
|
printf
|
||||||
printf("-A <elevation> Minimum satellite elevation in degrees [default: 10 degrees]\n");
|
("-i <NORAD> NORAD number of satellite to select [default: 41334]\n");
|
||||||
printf("-S <elevation> Maximum solar elevation in degrees [default: -6 degrees\n");
|
printf
|
||||||
|
("-r <altitude> Satellite altitude above surface in km [default: mean orbital altitude]\n");
|
||||||
|
printf
|
||||||
|
("-A <elevation> Minimum satellite elevation in degrees [default: 10 degrees]\n");
|
||||||
|
printf
|
||||||
|
("-S <elevation> Maximum solar elevation in degrees [default: -6 degrees\n");
|
||||||
printf ("-d <timestep> Time step in seconds [default: 60s]\n");
|
printf ("-d <timestep> Time step in seconds [default: 60s]\n");
|
||||||
printf("-C Select on culmination instead of maximum brightness\n");
|
printf
|
||||||
|
("-C Select on culmination instead of maximum brightness\n");
|
||||||
printf ("-h Shows this help\n");
|
printf ("-h Shows this help\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0, imode, i;
|
int arg = 0, imode, i;
|
||||||
int satno = -1;
|
int satno = -1;
|
||||||
|
@ -97,7 +112,8 @@ int main(int argc,char *argv[])
|
||||||
kep_t K;
|
kep_t K;
|
||||||
double radius = -1;
|
double radius = -1;
|
||||||
xyz_t obspos, obsvel, sunpos;
|
xyz_t obspos, obsvel, sunpos;
|
||||||
double p,pmin,p0,p1,r,ra,de,azi,alt,sazi,salt,altmin=10.0,saltmin=-6.0,altmax,dp;
|
double p, pmin, p0, p1, r, ra, de, azi, alt, sazi, salt, altmin =
|
||||||
|
10.0, saltmin = -6.0, altmax, dp;
|
||||||
float mag, mmin;
|
float mag, mmin;
|
||||||
int state, pstate, nstate;
|
int state, pstate, nstate;
|
||||||
float t, length = 86400.0, dt = 60.0;
|
float t, length = 86400.0, dt = 60.0;
|
||||||
|
@ -110,8 +126,10 @@ int main(int argc,char *argv[])
|
||||||
get_site (4171);
|
get_site (4171);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"t:c:i:s:l:hS:A:r:d:C"))!=-1) {
|
while ((arg = getopt (argc, argv, "t:c:i:s:l:hS:A:r:d:C")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (nfd, optarg);
|
strcpy (nfd, optarg);
|
||||||
|
@ -172,20 +190,24 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error checking
|
// Error checking
|
||||||
if (satno<=0) {
|
if (satno <= 0)
|
||||||
|
{
|
||||||
fprintf (stderr, "ERROR: NORAD satellite number not provided!\n");
|
fprintf (stderr, "ERROR: NORAD satellite number not provided!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get TLE
|
// Get TLE
|
||||||
fp = fopen (tlefile, "rb");
|
fp = fopen (tlefile, "rb");
|
||||||
if (fp==NULL) {
|
if (fp == NULL)
|
||||||
fprintf(stderr,"ERROR: Failed to open file with TLEs (%s)!\n",tlefile);
|
{
|
||||||
|
fprintf (stderr, "ERROR: Failed to open file with TLEs (%s)!\n",
|
||||||
|
tlefile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read TLE
|
// Read TLE
|
||||||
while (read_twoline(fp,satno,&orb)==0) {
|
while (read_twoline (fp, satno, &orb) == 0)
|
||||||
|
{
|
||||||
Isat = orb.satno;
|
Isat = orb.satno;
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
|
|
||||||
|
@ -196,13 +218,15 @@ int main(int argc,char *argv[])
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
// Object found?
|
// Object found?
|
||||||
if (orb.satno!=satno) {
|
if (orb.satno != satno)
|
||||||
|
{
|
||||||
fprintf (stderr, "ERROR: Object %d not found in %s!\n", satno, tlefile);
|
fprintf (stderr, "ERROR: Object %d not found in %s!\n", satno, tlefile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object found?
|
// Object found?
|
||||||
if (orb.rev<10.0) {
|
if (orb.rev < 10.0)
|
||||||
|
{
|
||||||
fprintf (stderr, "ERROR: Object %d is not in a LEO orbit.\n", satno);
|
fprintf (stderr, "ERROR: Object %d is not in a LEO orbit.\n", satno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -212,18 +236,23 @@ int main(int argc,char *argv[])
|
||||||
radius = semimajoraxis (orb);
|
radius = semimajoraxis (orb);
|
||||||
|
|
||||||
// Print header
|
// Print header
|
||||||
printf("Observer: %s (%04d) [%+.4f, %+.4f, %.0fm]\n",m.observer,m.site_id,m.lat,m.lng,m.alt*1000.0);
|
printf ("Observer: %s (%04d) [%+.4f, %+.4f, %.0fm]\n", m.observer,
|
||||||
|
m.site_id, m.lat, m.lng, m.alt * 1000.0);
|
||||||
printf ("Elements: %s\n", tlefile);
|
printf ("Elements: %s\n", tlefile);
|
||||||
printf ("Object: %d\n", satno);
|
printf ("Object: %d\n", satno);
|
||||||
printf ("Radius: %g km\n", radius);
|
printf ("Radius: %g km\n", radius);
|
||||||
printf ("Start UT Date/Time: %s for %g h \n\n", nfd, length / 3600.0);
|
printf ("Start UT Date/Time: %s for %g h \n\n", nfd, length / 3600.0);
|
||||||
printf("UT Date/Time R.A. Decl. Azi. Alt. Range Mag Sun Alt. Type\n");
|
printf
|
||||||
printf(" (deg) (deg) (km) (deg)\n");
|
("UT Date/Time R.A. Decl. Azi. Alt. Range Mag Sun Alt. Type\n");
|
||||||
printf("=====================================================================================\n");
|
printf
|
||||||
|
(" (deg) (deg) (km) (deg)\n");
|
||||||
|
printf
|
||||||
|
("=====================================================================================\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (t=0.0;t<length;t+=dt) {
|
for (t = 0.0; t < length; t += dt)
|
||||||
|
{
|
||||||
// (Modified) Julian Date
|
// (Modified) Julian Date
|
||||||
mjd = mjd0 + t / 86400.0;
|
mjd = mjd0 + t / 86400.0;
|
||||||
jd = mjd + 2400000.5;
|
jd = mjd + 2400000.5;
|
||||||
|
@ -240,18 +269,25 @@ int main(int argc,char *argv[])
|
||||||
// Rough search first
|
// Rough search first
|
||||||
p0 = 0.0;
|
p0 = 0.0;
|
||||||
p1 = 2.0 * M_PI;
|
p1 = 2.0 * M_PI;
|
||||||
for (i=0,pmin=0.0,mmin=15.0,altmax=0.0;i<MMAX;i++) {
|
for (i = 0, pmin = 0.0, mmin = 15.0, altmax = 0.0; i < MMAX; i++)
|
||||||
|
{
|
||||||
p = p0 + (p1 - p0) * (float) i / (float) (MMAX - 1);
|
p = p0 + (p1 - p0) * (float) i / (float) (MMAX - 1);
|
||||||
state=properties(K,obspos,sunpos,radius,p,&ra,&de,&r,&mag);
|
state =
|
||||||
|
properties (K, obspos, sunpos, radius, p, &ra, &de, &r, &mag);
|
||||||
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
||||||
|
|
||||||
if (opttype==0) {
|
if (opttype == 0)
|
||||||
if (mag<mmin) {
|
{
|
||||||
|
if (mag < mmin)
|
||||||
|
{
|
||||||
pmin = p;
|
pmin = p;
|
||||||
mmin = mag;
|
mmin = mag;
|
||||||
}
|
}
|
||||||
} else if (opttype==1) {
|
}
|
||||||
if (alt>altmax && mag<15.0) {
|
else if (opttype == 1)
|
||||||
|
{
|
||||||
|
if (alt > altmax && mag < 15.0)
|
||||||
|
{
|
||||||
pmin = p;
|
pmin = p;
|
||||||
altmax = alt;
|
altmax = alt;
|
||||||
}
|
}
|
||||||
|
@ -261,18 +297,25 @@ int main(int argc,char *argv[])
|
||||||
// Finer search
|
// Finer search
|
||||||
p0 = pmin - 4.0 * M_PI / (float) MMAX;
|
p0 = pmin - 4.0 * M_PI / (float) MMAX;
|
||||||
p1 = pmin + 4.0 * M_PI / (float) MMAX;
|
p1 = pmin + 4.0 * M_PI / (float) MMAX;
|
||||||
for (i=0,pmin=0.0,mmin=15.0;i<MMAX;i++) {
|
for (i = 0, pmin = 0.0, mmin = 15.0; i < MMAX; i++)
|
||||||
|
{
|
||||||
p = p0 + (p1 - p0) * (float) i / (float) (MMAX - 1);
|
p = p0 + (p1 - p0) * (float) i / (float) (MMAX - 1);
|
||||||
state=properties(K,obspos,sunpos,radius,p,&ra,&de,&r,&mag);
|
state =
|
||||||
|
properties (K, obspos, sunpos, radius, p, &ra, &de, &r, &mag);
|
||||||
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
equatorial2horizontal (mjd, ra, de, &azi, &alt);
|
||||||
|
|
||||||
if (opttype==0) {
|
if (opttype == 0)
|
||||||
if (mag<mmin) {
|
{
|
||||||
|
if (mag < mmin)
|
||||||
|
{
|
||||||
pmin = p;
|
pmin = p;
|
||||||
mmin = mag;
|
mmin = mag;
|
||||||
}
|
}
|
||||||
} else if (opttype==1) {
|
}
|
||||||
if (alt>altmax && mag<15.0) {
|
else if (opttype == 1)
|
||||||
|
{
|
||||||
|
if (alt > altmax && mag < 15.0)
|
||||||
|
{
|
||||||
pmin = p;
|
pmin = p;
|
||||||
altmax = alt;
|
altmax = alt;
|
||||||
}
|
}
|
||||||
|
@ -280,9 +323,14 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get properties before and after maximum
|
// Get properties before and after maximum
|
||||||
pstate=properties(K,obspos,sunpos,radius,pmin-0.01,&ra,&de,&r,&mag);
|
pstate =
|
||||||
nstate=properties(K,obspos,sunpos,radius,pmin+0.01,&ra,&de,&r,&mag);
|
properties (K, obspos, sunpos, radius, pmin - 0.01, &ra, &de, &r,
|
||||||
state=properties(K,obspos,sunpos,radius,pmin,&ra,&de,&r,&mag);
|
&mag);
|
||||||
|
nstate =
|
||||||
|
properties (K, obspos, sunpos, radius, pmin + 0.01, &ra, &de, &r,
|
||||||
|
&mag);
|
||||||
|
state =
|
||||||
|
properties (K, obspos, sunpos, radius, pmin, &ra, &de, &r, &mag);
|
||||||
if (pstate < state && state == nstate)
|
if (pstate < state && state == nstate)
|
||||||
strcpy (type, "Egress");
|
strcpy (type, "Egress");
|
||||||
else if (pstate == state && state > nstate)
|
else if (pstate == state && state > nstate)
|
||||||
|
@ -299,14 +347,16 @@ int main(int argc,char *argv[])
|
||||||
dec2s (ra / 15.0, sra, 0, 2);
|
dec2s (ra / 15.0, sra, 0, 2);
|
||||||
dec2s (de, sde, 0, 2);
|
dec2s (de, sde, 0, 2);
|
||||||
if (alt > altmin && salt < saltmin)
|
if (alt > altmin && salt < saltmin)
|
||||||
printf("%s %s %s %6.2f %6.2f %7.1f %5.2f %6.2f %s\n",nfd,sra,sde,azi,alt,r,mag,salt,type);
|
printf ("%s %s %s %6.2f %6.2f %7.1f %5.2f %6.2f %s\n", nfd, sra,
|
||||||
|
sde, azi, alt, r, mag, salt, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -319,11 +369,14 @@ void get_site(int site_id)
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
sprintf (filename, "%s/data/sites.txt", env);
|
sprintf (filename, "%s/data/sites.txt", env);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
fprintf(stderr,"File with site information not found (%s)!\n",filename);
|
{
|
||||||
|
fprintf (stderr, "File with site information not found (%s)!\n",
|
||||||
|
filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -332,14 +385,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
@ -354,12 +407,14 @@ void get_site(int site_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -368,12 +423,14 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -381,17 +438,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -400,13 +463,16 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observer position
|
// Observer position
|
||||||
void obspos_xyz(double mjd,xyz_t *pos,xyz_t *vel)
|
void
|
||||||
|
obspos_xyz (double mjd, xyz_t * pos, xyz_t * vel)
|
||||||
{
|
{
|
||||||
double ff, gc, gs, theta, s, dtheta;
|
double ff, gc, gs, theta, s, dtheta;
|
||||||
|
|
||||||
|
@ -429,7 +495,8 @@ void obspos_xyz(double mjd,xyz_t *pos,xyz_t *vel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Solar position
|
// Solar position
|
||||||
void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
void
|
||||||
|
sunpos_xyz (double mjd, xyz_t * pos, double *ra, double *de)
|
||||||
{
|
{
|
||||||
double jd, t, l0, m, e, c, r;
|
double jd, t, l0, m, e, c, r;
|
||||||
double n, s, ecl;
|
double n, s, ecl;
|
||||||
|
@ -446,7 +513,10 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
||||||
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
||||||
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
||||||
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
||||||
ecl=(23.43929111+(-46.8150*t-0.00059*t*t+0.001813*t*t*t)/3600.0+0.00256*cos(n))*D2R;
|
ecl =
|
||||||
|
(23.43929111 +
|
||||||
|
(-46.8150 * t - 0.00059 * t * t + 0.001813 * t * t * t) / 3600.0 +
|
||||||
|
0.00256 * cos (n)) * D2R;
|
||||||
|
|
||||||
*ra = atan2 (cos (ecl) * sin (s), cos (s)) * R2D;
|
*ra = atan2 (cos (ecl) * sin (s), cos (s)) * R2D;
|
||||||
*de = asin (sin (ecl) * sin (s)) * R2D;
|
*de = asin (sin (ecl) * sin (s)) * R2D;
|
||||||
|
@ -459,7 +529,8 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double dgmst(double mjd)
|
double
|
||||||
|
dgmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, dgmst;
|
double t, dgmst;
|
||||||
|
|
||||||
|
@ -471,41 +542,55 @@ double dgmst(double mjd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert equatorial into horizontal coordinates
|
// Convert equatorial into horizontal coordinates
|
||||||
void equatorial2horizontal(double mjd,double ra,double de,double *azi,double *alt)
|
void
|
||||||
|
equatorial2horizontal (double mjd, double ra, double de, double *azi,
|
||||||
|
double *alt)
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
|
|
||||||
h = gmst (mjd) + m.lng - ra;
|
h = gmst (mjd) + m.lng - ra;
|
||||||
|
|
||||||
*azi=modulo(atan2(sin(h*D2R),cos(h*D2R)*sin(m.lat*D2R)-tan(de*D2R)*cos(m.lat*D2R))*R2D,360.0);
|
*azi =
|
||||||
*alt=asin(sin(m.lat*D2R)*sin(de*D2R)+cos(m.lat*D2R)*cos(de*D2R)*cos(h*D2R))*R2D;
|
modulo (atan2
|
||||||
|
(sin (h * D2R),
|
||||||
|
cos (h * D2R) * sin (m.lat * D2R) -
|
||||||
|
tan (de * D2R) * cos (m.lat * D2R)) * R2D, 360.0);
|
||||||
|
*alt =
|
||||||
|
asin (sin (m.lat * D2R) * sin (de * D2R) +
|
||||||
|
cos (m.lat * D2R) * cos (de * D2R) * cos (h * D2R)) * R2D;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date)
|
void
|
||||||
|
mjd2date (double mjd, char *date)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -520,7 +605,8 @@ void mjd2date(double mjd,char *date)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -550,12 +636,15 @@ void mjd2date(double mjd,char *date)
|
||||||
hour = x;
|
hour = x;
|
||||||
sec = floor (1000.0 * sec) / 1000.0;
|
sec = floor (1000.0 * sec) / 1000.0;
|
||||||
|
|
||||||
sprintf(date,"%04d-%02d-%02dT%02d:%02d:%02.0f",year,month,day,hour,min,sec);
|
sprintf (date, "%04d-%02d-%02dT%02d:%02d:%02.0f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int properties(kep_t K,xyz_t obspos,xyz_t sunpos,float radius,float t,double *ra,double *de,double *r,float *mag)
|
int
|
||||||
|
properties (kep_t K, xyz_t obspos, xyz_t sunpos, float radius, float t,
|
||||||
|
double *ra, double *de, double *r, float *mag)
|
||||||
{
|
{
|
||||||
double st, ct, sn, cn, si, ci;
|
double st, ct, sn, cn, si, ci;
|
||||||
xyz_t satpos;
|
xyz_t satpos;
|
||||||
|
@ -585,14 +674,17 @@ int properties(kep_t K,xyz_t obspos,xyz_t sunpos,float radius,float t,double *ra
|
||||||
|
|
||||||
// Distances
|
// Distances
|
||||||
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
||||||
rearth=sqrt(satpos.x*satpos.x+satpos.y*satpos.y+satpos.z*satpos.z);
|
rearth =
|
||||||
|
sqrt (satpos.x * satpos.x + satpos.y * satpos.y + satpos.z * satpos.z);
|
||||||
|
|
||||||
// Angles
|
// Angles
|
||||||
psun = asin (696.0e3 / rsun) * R2D;
|
psun = asin (696.0e3 / rsun) * R2D;
|
||||||
pearth = asin (6378.135 / rearth) * R2D;
|
pearth = asin (6378.135 / rearth) * R2D;
|
||||||
|
|
||||||
pearth = asin (6378.135 / rearth) * R2D;
|
pearth = asin (6378.135 / rearth) * R2D;
|
||||||
p=acos((-dx*satpos.x-dy*satpos.y-dz*satpos.z)/(rsun*rearth))*R2D;
|
p =
|
||||||
|
acos ((-dx * satpos.x - dy * satpos.y -
|
||||||
|
dz * satpos.z) / (rsun * rearth)) * R2D;
|
||||||
p -= pearth;
|
p -= pearth;
|
||||||
|
|
||||||
// Position differences
|
// Position differences
|
||||||
|
@ -606,23 +698,36 @@ int properties(kep_t K,xyz_t obspos,xyz_t sunpos,float radius,float t,double *ra
|
||||||
*de = asin (dz / *r) * R2D;
|
*de = asin (dz / *r) * R2D;
|
||||||
|
|
||||||
// Visibility
|
// Visibility
|
||||||
if (p<-psun) {
|
if (p < -psun)
|
||||||
|
{
|
||||||
// strcpy(state,"eclipsed");
|
// strcpy(state,"eclipsed");
|
||||||
state = 0;
|
state = 0;
|
||||||
} else if (p>-psun && p<psun) {
|
}
|
||||||
|
else if (p > -psun && p < psun)
|
||||||
|
{
|
||||||
// strcpy(state,"umbra");
|
// strcpy(state,"umbra");
|
||||||
state = 1;
|
state = 1;
|
||||||
} else if (p>psun) {
|
}
|
||||||
|
else if (p > psun)
|
||||||
|
{
|
||||||
// strcpy(state,"sunlit");
|
// strcpy(state,"sunlit");
|
||||||
state = 2;
|
state = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phase
|
// Phase
|
||||||
phase=acos(((obspos.x-satpos.x)*(sunpos.x-satpos.x)+(obspos.y-satpos.y)*(sunpos.y-satpos.y)+(obspos.z-satpos.z)*(sunpos.z-satpos.z))/(rsun* *r))*R2D;
|
phase =
|
||||||
|
acos (((obspos.x - satpos.x) * (sunpos.x - satpos.x) +
|
||||||
|
(obspos.y - satpos.y) * (sunpos.y - satpos.y) + (obspos.z -
|
||||||
|
satpos.z) *
|
||||||
|
(sunpos.z - satpos.z)) / (rsun * *r)) * R2D;
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
if (state == 2)
|
if (state == 2)
|
||||||
*mag=STDMAG-15.0+5*log10( *r)-2.5*log10(sin(phase*D2R)+(M_PI-phase*D2R)*cos(phase*D2R));
|
*mag =
|
||||||
|
STDMAG - 15.0 + 5 * log10 (*r) - 2.5 * log10 (sin (phase * D2R) +
|
||||||
|
(M_PI -
|
||||||
|
phase * D2R) *
|
||||||
|
cos (phase * D2R));
|
||||||
else
|
else
|
||||||
*mag = 15;
|
*mag = 15;
|
||||||
|
|
||||||
|
@ -630,7 +735,8 @@ int properties(kep_t K,xyz_t obspos,xyz_t sunpos,float radius,float t,double *ra
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Decimal into Sexagesimal
|
// Convert Decimal into Sexagesimal
|
||||||
void dec2s(double x,char *s,int f,int len)
|
void
|
||||||
|
dec2s (double x, char *s, int f, int len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double sec, deg, min;
|
double sec, deg, min;
|
||||||
|
@ -647,11 +753,21 @@ void dec2s(double x,char *s,int f,int len)
|
||||||
// deg=fmod(x,60.);
|
// deg=fmod(x,60.);
|
||||||
deg = x;
|
deg = x;
|
||||||
|
|
||||||
if (len==7) sprintf(s,"%c%02i%c%02i%c%07.4f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
if (len == 7)
|
||||||
if (len==6) sprintf(s,"%c%02i%c%02i%c%06.3f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
sprintf (s, "%c%02i%c%02i%c%07.4f%c", sign, (int) deg, form[f][0],
|
||||||
if (len==5) sprintf(s,"%c%02i%c%02i%c%05.2f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
if (len==4) sprintf(s,"%c%02i%c%02i%c%04.1f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
if (len == 6)
|
||||||
if (len==2) sprintf(s,"%c%02i%c%02i%c%02i%c",sign,(int) deg,form[f][0],(int) min,form[f][1],(int) floor(sec),form[f][2]);
|
sprintf (s, "%c%02i%c%02i%c%06.3f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 5)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%05.2f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 4)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%04.1f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 2)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%02i%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], (int) floor (sec), form[f][2]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
218
src/plotfits.c
218
src/plotfits.c
|
@ -13,12 +13,14 @@
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
#define NMAX 4096
|
#define NMAX 4096
|
||||||
|
|
||||||
struct star {
|
struct star
|
||||||
|
{
|
||||||
double ra, de;
|
double ra, de;
|
||||||
float pmra, pmde;
|
float pmra, pmde;
|
||||||
float mag;
|
float mag;
|
||||||
};
|
};
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int naxis1, naxis2, naxis3;
|
int naxis1, naxis2, naxis3;
|
||||||
float *z;
|
float *z;
|
||||||
float zmin, zmax;
|
float zmin, zmax;
|
||||||
|
@ -27,13 +29,15 @@ struct image {
|
||||||
float a[3], b[3];
|
float a[3], b[3];
|
||||||
double mjd;
|
double mjd;
|
||||||
} img;
|
} img;
|
||||||
struct catalog {
|
struct catalog
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
float x[NMAX], y[NMAX], mag[NMAX];
|
float x[NMAX], y[NMAX], mag[NMAX];
|
||||||
double ra[NMAX], de[NMAX], rx[NMAX], ry[NMAX];
|
double ra[NMAX], de[NMAX], rx[NMAX], ry[NMAX];
|
||||||
int select[NMAX];
|
int select[NMAX];
|
||||||
};
|
};
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
double lat, lng;
|
double lat, lng;
|
||||||
float alt;
|
float alt;
|
||||||
int site_id;
|
int site_id;
|
||||||
|
@ -42,17 +46,21 @@ struct map {
|
||||||
|
|
||||||
struct image read_fits (char *filename, int pnum);
|
struct image read_fits (char *filename, int pnum);
|
||||||
int fgetline (FILE *, char *, int);
|
int fgetline (FILE *, char *, int);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
|
double *y);
|
||||||
void reverse (double, double, double, double, double *, double *);
|
void reverse (double, double, double, double, double *, double *);
|
||||||
void lfit2d (float *x, float *y, float *z, int n, float *a);
|
void lfit2d (float *x, float *y, float *z, int n, float *a);
|
||||||
struct catalog read_pixel_catalog (char *filename);
|
struct catalog read_pixel_catalog (char *filename);
|
||||||
double gmst (double mjd);
|
double gmst (double mjd);
|
||||||
double modulo (double x, double y);
|
double modulo (double x, double y);
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de);
|
void precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de);
|
||||||
double s2dec (char *s);
|
double s2dec (char *s);
|
||||||
|
|
||||||
// Read astrometric catalog
|
// Read astrometric catalog
|
||||||
struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float sy,float angle)
|
struct catalog
|
||||||
|
read_astrometric_catalog (char *filename, float mmin, float sx, float sy,
|
||||||
|
float angle)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -64,18 +72,23 @@ struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float
|
||||||
double mjd0 = 51544.5;
|
double mjd0 = 51544.5;
|
||||||
|
|
||||||
file = fopen (filename, "rb");
|
file = fopen (filename, "rb");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "%s not found!\n", filename);
|
fprintf (stderr, "%s not found!\n", filename);
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fread (&s, sizeof (struct star), 1, file);
|
fread (&s, sizeof (struct star), 1, file);
|
||||||
if (s.mag > mmin)
|
if (s.mag > mmin)
|
||||||
continue;
|
continue;
|
||||||
precess (mjd0, s.ra, s.de, img.mjd, &ra, &de);
|
precess (mjd0, s.ra, s.de, img.mjd, &ra, &de);
|
||||||
forward (img.ra0, img.de0, ra, de, &rx, &ry);
|
forward (img.ra0, img.de0, ra, de, &rx, &ry);
|
||||||
x=img.x0+1.0/sx*(cos(angle*D2R)*rx+sin(angle*D2R)*ry);
|
x =
|
||||||
y=img.y0+1.0/sy*(-sin(angle*D2R)*rx+cos(angle*D2R)*ry);
|
img.x0 + 1.0 / sx * (cos (angle * D2R) * rx + sin (angle * D2R) * ry);
|
||||||
|
y =
|
||||||
|
img.y0 + 1.0 / sy * (-sin (angle * D2R) * rx +
|
||||||
|
cos (angle * D2R) * ry);
|
||||||
/*
|
/*
|
||||||
} else if (t.state==1) {
|
} else if (t.state==1) {
|
||||||
dx=rx-t.a[0];
|
dx=rx-t.a[0];
|
||||||
|
@ -85,7 +98,8 @@ struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float
|
||||||
y=(t.a[1]*dy-t.b[1]*dx)/d;
|
y=(t.a[1]*dy-t.b[1]*dx)/d;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (x>0.0 && x<img.naxis1 && y>0.0 && y<img.naxis2) {
|
if (x > 0.0 && x < img.naxis1 && y > 0.0 && y < img.naxis2)
|
||||||
|
{
|
||||||
c.x[i] = x;
|
c.x[i] = x;
|
||||||
c.y[i] = y;
|
c.y[i] = y;
|
||||||
c.rx[i] = rx;
|
c.rx[i] = rx;
|
||||||
|
@ -104,7 +118,8 @@ struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read astrometric catalog
|
// Read astrometric catalog
|
||||||
struct catalog reread_astrometric_catalog(char *filename,float mmin)
|
struct catalog
|
||||||
|
reread_astrometric_catalog (char *filename, float mmin)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -116,7 +131,8 @@ struct catalog reread_astrometric_catalog(char *filename,float mmin)
|
||||||
double mjd0 = 51544.5;
|
double mjd0 = 51544.5;
|
||||||
|
|
||||||
file = fopen (filename, "rb");
|
file = fopen (filename, "rb");
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
fread (&s, sizeof (struct star), 1, file);
|
fread (&s, sizeof (struct star), 1, file);
|
||||||
if (s.mag > mmin)
|
if (s.mag > mmin)
|
||||||
continue;
|
continue;
|
||||||
|
@ -127,7 +143,8 @@ struct catalog reread_astrometric_catalog(char *filename,float mmin)
|
||||||
d = img.a[1] * img.b[2] - img.a[2] * img.b[1];
|
d = img.a[1] * img.b[2] - img.a[2] * img.b[1];
|
||||||
x = (img.b[2] * dx - img.a[2] * dy) / d + img.x0;
|
x = (img.b[2] * dx - img.a[2] * dy) / d + img.x0;
|
||||||
y = (img.a[1] * dy - img.b[1] * dx) / d + img.y0;
|
y = (img.a[1] * dy - img.b[1] * dx) / d + img.y0;
|
||||||
if (x>0.0 && x<img.naxis1 && y>0.0 && y<img.naxis2) {
|
if (x > 0.0 && x < img.naxis1 && y > 0.0 && y < img.naxis2)
|
||||||
|
{
|
||||||
c.x[i] = x;
|
c.x[i] = x;
|
||||||
c.y[i] = y;
|
c.y[i] = y;
|
||||||
c.rx[i] = rx;
|
c.rx[i] = rx;
|
||||||
|
@ -145,14 +162,17 @@ struct catalog reread_astrometric_catalog(char *filename,float mmin)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int select_nearest(struct catalog c,float x,float y)
|
int
|
||||||
|
select_nearest (struct catalog c, float x, float y)
|
||||||
{
|
{
|
||||||
int i, imin;
|
int i, imin;
|
||||||
float r, rmin;
|
float r, rmin;
|
||||||
|
|
||||||
for (i=0;i<c.n;i++) {
|
for (i = 0; i < c.n; i++)
|
||||||
|
{
|
||||||
r = sqrt (pow (x - c.x[i], 2) + pow (y - c.y[i], 2));
|
r = sqrt (pow (x - c.x[i], 2) + pow (y - c.y[i], 2));
|
||||||
if (i==0 || r<rmin) {
|
if (i == 0 || r < rmin)
|
||||||
|
{
|
||||||
imin = i;
|
imin = i;
|
||||||
rmin = r;
|
rmin = r;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +182,8 @@ int select_nearest(struct catalog c,float x,float y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fit transformation
|
// Fit transformation
|
||||||
void fit_transformation(struct catalog cat,struct catalog ast,int nselect)
|
void
|
||||||
|
fit_transformation (struct catalog cat, struct catalog ast, int nselect)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
float *x, *y, *rx, *ry;
|
float *x, *y, *rx, *ry;
|
||||||
|
@ -172,15 +193,20 @@ void fit_transformation(struct catalog cat,struct catalog ast,int nselect)
|
||||||
rx = (float *) malloc (sizeof (float) * nselect);
|
rx = (float *) malloc (sizeof (float) * nselect);
|
||||||
ry = (float *) malloc (sizeof (float) * nselect);
|
ry = (float *) malloc (sizeof (float) * nselect);
|
||||||
|
|
||||||
for (i=0;i<nselect;i++) {
|
for (i = 0; i < nselect; i++)
|
||||||
for (j=0;j<cat.n;j++) {
|
{
|
||||||
if (cat.select[j]==i+1) {
|
for (j = 0; j < cat.n; j++)
|
||||||
|
{
|
||||||
|
if (cat.select[j] == i + 1)
|
||||||
|
{
|
||||||
x[i] = cat.x[j] - img.x0;
|
x[i] = cat.x[j] - img.x0;
|
||||||
y[i] = cat.y[j] - img.y0;
|
y[i] = cat.y[j] - img.y0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (j=0;j<ast.n;j++) {
|
for (j = 0; j < ast.n; j++)
|
||||||
if (ast.select[j]==i+1) {
|
{
|
||||||
|
if (ast.select[j] == i + 1)
|
||||||
|
{
|
||||||
rx[i] = ast.rx[j];
|
rx[i] = ast.rx[j];
|
||||||
ry[i] = ast.ry[j];
|
ry[i] = ast.ry[j];
|
||||||
}
|
}
|
||||||
|
@ -195,7 +221,8 @@ void fit_transformation(struct catalog cat,struct catalog ast,int nselect)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int match_catalogs(struct catalog *cat,struct catalog *ast,float rmax)
|
int
|
||||||
|
match_catalogs (struct catalog *cat, struct catalog *ast, float rmax)
|
||||||
{
|
{
|
||||||
int i, j, jmin, n, flag = 0;
|
int i, j, jmin, n, flag = 0;
|
||||||
float r, rmin;
|
float r, rmin;
|
||||||
|
@ -208,19 +235,26 @@ int match_catalogs(struct catalog *cat,struct catalog *ast,float rmax)
|
||||||
ast->select[i] = 0;
|
ast->select[i] = 0;
|
||||||
|
|
||||||
file = fopen ("out.dat", "w");
|
file = fopen ("out.dat", "w");
|
||||||
for (i=0,n=0;i<cat->n;i++) {
|
for (i = 0, n = 0; i < cat->n; i++)
|
||||||
for (j=0,flag=0;j<ast->n;j++) {
|
{
|
||||||
|
for (j = 0, flag = 0; j < ast->n; j++)
|
||||||
|
{
|
||||||
if (ast->select[j] != 0)
|
if (ast->select[j] != 0)
|
||||||
continue;
|
continue;
|
||||||
r=sqrt(pow(cat->x[i]-ast->x[j],2)+pow(cat->y[i]-ast->y[j],2));
|
r =
|
||||||
if (flag==0 || r<rmin) {
|
sqrt (pow (cat->x[i] - ast->x[j], 2) +
|
||||||
|
pow (cat->y[i] - ast->y[j], 2));
|
||||||
|
if (flag == 0 || r < rmin)
|
||||||
|
{
|
||||||
rmin = r;
|
rmin = r;
|
||||||
jmin = j;
|
jmin = j;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rmin<rmax) {
|
if (rmin < rmax)
|
||||||
fprintf(file,"%10.4f %10.4f %10.6f %10.6f\n",cat->x[i]-img.x0,cat->y[i]-img.y0,ast->ra[jmin],ast->de[jmin]);
|
{
|
||||||
|
fprintf (file, "%10.4f %10.4f %10.6f %10.6f\n", cat->x[i] - img.x0,
|
||||||
|
cat->y[i] - img.y0, ast->ra[jmin], ast->de[jmin]);
|
||||||
cat->select[i] = n + 1;
|
cat->select[i] = n + 1;
|
||||||
ast->select[jmin] = n + 1;
|
ast->select[jmin] = n + 1;
|
||||||
n++;
|
n++;
|
||||||
|
@ -233,7 +267,8 @@ int match_catalogs(struct catalog *cat,struct catalog *ast,float rmax)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -246,11 +281,13 @@ void get_site(int site_id)
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
sprintf (filename, "%s/data/sites.txt", env);
|
sprintf (filename, "%s/data/sites.txt", env);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -259,14 +296,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
@ -280,7 +317,8 @@ void get_site(int site_id)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float tr[] = { -0.5, 1.0, 0.0, -0.5, 0.0, 1.0 };
|
float tr[] = { -0.5, 1.0, 0.0, -0.5, 0.0, 1.0 };
|
||||||
|
@ -313,15 +351,19 @@ int main(int argc,char *argv[])
|
||||||
printf ("Image read\n");
|
printf ("Image read\n");
|
||||||
|
|
||||||
// Initial transformation
|
// Initial transformation
|
||||||
if (argc==7) {
|
if (argc == 7)
|
||||||
|
{
|
||||||
s = atof (argv[2]);
|
s = atof (argv[2]);
|
||||||
img.ra0 = atof (argv[3]);
|
img.ra0 = atof (argv[3]);
|
||||||
img.de0 = atof (argv[4]);
|
img.de0 = atof (argv[4]);
|
||||||
q = atof (argv[5]);
|
q = atof (argv[5]);
|
||||||
mag = atof (argv[6]);
|
mag = atof (argv[6]);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
file = fopen ("position.txt", "r");
|
file = fopen ("position.txt", "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "No position file found\n");
|
fprintf (stderr, "No position file found\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -334,7 +376,10 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Hour angle
|
// Hour angle
|
||||||
h = gmst (img.mjd) + m.lng - img.ra0;
|
h = gmst (img.mjd) + m.lng - img.ra0;
|
||||||
q=atan2(sin(h*D2R),(tan(m.lat*D2R)*cos(img.de0*D2R)-sin(img.de0*D2R)*cos(h*D2R)))*R2D;
|
q =
|
||||||
|
atan2 (sin (h * D2R),
|
||||||
|
(tan (m.lat * D2R) * cos (img.de0 * D2R) -
|
||||||
|
sin (img.de0 * D2R) * cos (h * D2R))) * R2D;
|
||||||
printf ("Hour angle: %.3f deg, parallactic angle: %.3f deg\n", h, q);
|
printf ("Hour angle: %.3f deg, parallactic angle: %.3f deg\n", h, q);
|
||||||
}
|
}
|
||||||
img.x0 = 0.5 * (float) img.naxis1;
|
img.x0 = 0.5 * (float) img.naxis1;
|
||||||
|
@ -354,15 +399,20 @@ int main(int argc,char *argv[])
|
||||||
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
||||||
|
|
||||||
// For ever loop
|
// For ever loop
|
||||||
for (;;) {
|
for (;;)
|
||||||
if (redraw==1) {
|
{
|
||||||
cpgimag(img.z,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,img.zmin,img.zmax,tr);
|
if (redraw == 1)
|
||||||
|
{
|
||||||
|
cpgimag (img.z, img.naxis1, img.naxis2, 1, img.naxis1, 1,
|
||||||
|
img.naxis2, img.zmin, img.zmax, tr);
|
||||||
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
||||||
|
|
||||||
// Plot catalogs
|
// Plot catalogs
|
||||||
if (plotstars==1) {
|
if (plotstars == 1)
|
||||||
|
{
|
||||||
cpgsci (3);
|
cpgsci (3);
|
||||||
for (i=0;i<cat.n;i++) {
|
for (i = 0; i < cat.n; i++)
|
||||||
|
{
|
||||||
if (cat.select[i] != 0)
|
if (cat.select[i] != 0)
|
||||||
cpgpt1 (cat.x[i], cat.y[i], 6);
|
cpgpt1 (cat.x[i], cat.y[i], 6);
|
||||||
else
|
else
|
||||||
|
@ -370,7 +420,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cpgsci (4);
|
cpgsci (4);
|
||||||
for (i=0;i<ast.n;i++) {
|
for (i = 0; i < ast.n; i++)
|
||||||
|
{
|
||||||
r = rmax - (rmax - rmin) * (ast.mag[i] - mmin) / (mmax - mmin);
|
r = rmax - (rmax - rmin) * (ast.mag[i] - mmin) / (mmax - mmin);
|
||||||
|
|
||||||
// Upscale for image size
|
// Upscale for image size
|
||||||
|
@ -390,20 +441,23 @@ int main(int argc,char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Fit
|
// Fit
|
||||||
if (c=='f' && nselect>=3) {
|
if (c == 'f' && nselect >= 3)
|
||||||
|
{
|
||||||
fit_transformation (cat, ast, nselect);
|
fit_transformation (cat, ast, nselect);
|
||||||
ast = reread_astrometric_catalog (starfile, mag + 1);
|
ast = reread_astrometric_catalog (starfile, mag + 1);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reread
|
// Reread
|
||||||
if (c=='r') {
|
if (c == 'r')
|
||||||
|
{
|
||||||
ast = reread_astrometric_catalog (starfile, mag + 1);
|
ast = reread_astrometric_catalog (starfile, mag + 1);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select pixel catalog
|
// Select pixel catalog
|
||||||
if (c=='a' && click==0) {
|
if (c == 'a' && click == 0)
|
||||||
|
{
|
||||||
i = select_nearest (cat, x, y);
|
i = select_nearest (cat, x, y);
|
||||||
cat.select[i] = nselect + 1;
|
cat.select[i] = nselect + 1;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
|
@ -411,7 +465,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select catalog
|
// Select catalog
|
||||||
if (c=='b' && click==1) {
|
if (c == 'b' && click == 1)
|
||||||
|
{
|
||||||
i = select_nearest (ast, x, y);
|
i = select_nearest (ast, x, y);
|
||||||
ast.select[i] = nselect + 1;
|
ast.select[i] = nselect + 1;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
|
@ -420,7 +475,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
if (c=='p') {
|
if (c == 'p')
|
||||||
|
{
|
||||||
if (plotstars == 1)
|
if (plotstars == 1)
|
||||||
plotstars = 0;
|
plotstars = 0;
|
||||||
else if (plotstars == 0)
|
else if (plotstars == 0)
|
||||||
|
@ -429,7 +485,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match catalogs
|
// Match catalogs
|
||||||
if (c=='m') {
|
if (c == 'm')
|
||||||
|
{
|
||||||
nselect = match_catalogs (&cat, &ast, 10.0);
|
nselect = match_catalogs (&cat, &ast, 10.0);
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +497,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename,int pnum)
|
struct image
|
||||||
|
read_fits (char *filename, int pnum)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -475,15 +533,18 @@ struct image read_fits(char *filename,int pnum)
|
||||||
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
img.z = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0,m=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0, m = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
img.z[l] = ql.fbuf[l];
|
img.z[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get levels
|
// Get levels
|
||||||
for (i=0,s1=0.0,s2=0.0;i<img.naxis1*img.naxis2;i++) {
|
for (i = 0, s1 = 0.0, s2 = 0.0; i < img.naxis1 * img.naxis2; i++)
|
||||||
|
{
|
||||||
s1 += img.z[i];
|
s1 += img.z[i];
|
||||||
s2 += img.z[i] * img.z[i];
|
s2 += img.z[i] * img.z[i];
|
||||||
}
|
}
|
||||||
|
@ -497,7 +558,8 @@ struct image read_fits(char *filename,int pnum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -511,7 +573,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
|
|
||||||
|
|
||||||
// Linear 2D fit
|
// Linear 2D fit
|
||||||
void lfit2d(float *x,float *y,float *z,int n,float *a)
|
void
|
||||||
|
lfit2d (float *x, float *y, float *z, int n, float *a)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double chisq;
|
double chisq;
|
||||||
|
@ -526,7 +589,8 @@ void lfit2d(float *x,float *y,float *z,int n,float *a)
|
||||||
cov = gsl_matrix_alloc (3, 3);
|
cov = gsl_matrix_alloc (3, 3);
|
||||||
|
|
||||||
// Fill matrices
|
// Fill matrices
|
||||||
for(i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
gsl_matrix_set (X, i, 0, 1.0);
|
gsl_matrix_set (X, i, 0, 1.0);
|
||||||
gsl_matrix_set (X, i, 1, x[i]);
|
gsl_matrix_set (X, i, 1, x[i]);
|
||||||
gsl_matrix_set (X, i, 2, y[i]);
|
gsl_matrix_set (X, i, 2, y[i]);
|
||||||
|
@ -554,7 +618,8 @@ void lfit2d(float *x,float *y,float *z,int n,float *a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read pixel catalog
|
// Read pixel catalog
|
||||||
struct catalog read_pixel_catalog(char *filename)
|
struct catalog
|
||||||
|
read_pixel_catalog (char *filename)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -563,11 +628,13 @@ struct catalog read_pixel_catalog(char *filename)
|
||||||
|
|
||||||
// Read catalog
|
// Read catalog
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "%s not found!\n", filename);
|
fprintf (stderr, "%s not found!\n", filename);
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
sscanf (line, "%f %f %f", &c.x[i], &c.y[i], &c.mag[i]);
|
sscanf (line, "%f %f %f", &c.x[i], &c.y[i], &c.mag[i]);
|
||||||
|
@ -581,28 +648,35 @@ struct catalog read_pixel_catalog(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precess a celestial position
|
// Precess a celestial position
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
void
|
||||||
|
precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
double zeta, z, theta;
|
double zeta, z, theta;
|
||||||
|
@ -643,7 +717,8 @@ void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Sexagesimal into Decimal
|
// Convert Sexagesimal into Decimal
|
||||||
double s2dec(char *s)
|
double
|
||||||
|
s2dec (char *s)
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
float deg, min, sec;
|
float deg, min, sec;
|
||||||
|
@ -656,7 +731,8 @@ double s2dec(char *s)
|
||||||
sec = fabs (atof (strtok (NULL, " :")));
|
sec = fabs (atof (strtok (NULL, " :")));
|
||||||
|
|
||||||
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
||||||
if (s[0]=='-') x= -x;
|
if (s[0] == '-')
|
||||||
|
x = -x;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
#define LIM 80
|
#define LIM 80
|
||||||
|
|
||||||
// Cross product
|
// Cross product
|
||||||
xyz_t cross(xyz_t a,xyz_t b)
|
xyz_t
|
||||||
|
cross (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
xyz_t c;
|
xyz_t c;
|
||||||
|
|
||||||
|
@ -21,7 +22,8 @@ xyz_t cross(xyz_t a,xyz_t b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -36,12 +38,14 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -49,17 +53,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOY to MJD
|
// DOY to MJD
|
||||||
double doy2mjd(int year,double doy)
|
double
|
||||||
|
doy2mjd (int year, double doy)
|
||||||
{
|
{
|
||||||
int month, k = 2;
|
int month, k = 2;
|
||||||
double day;
|
double day;
|
||||||
|
@ -72,15 +82,19 @@ double doy2mjd(int year,double doy)
|
||||||
if (doy < 32)
|
if (doy < 32)
|
||||||
month = 1;
|
month = 1;
|
||||||
|
|
||||||
day=doy-floor(275.0*month/9.0)+k*floor((month+9.0)/12.0)+30.0;
|
day =
|
||||||
|
doy - floor (275.0 * month / 9.0) + k * floor ((month + 9.0) / 12.0) +
|
||||||
|
30.0;
|
||||||
|
|
||||||
return date2mjd (year, month, day);
|
return date2mjd (year, month, day);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, arg = 0, imode, n = 100, satno, satname, satno2, imin, flag, status;
|
int i, arg = 0, imode, n = 100, satno, satname, satno2, imin, flag, status;
|
||||||
char catalog1[]="20180121_173045_catalog.txt",catalog2[]="jsc_20180122.txt";
|
char catalog1[] = "20180121_173045_catalog.txt", catalog2[] =
|
||||||
|
"jsc_20180122.txt";
|
||||||
FILE *file1, *file2;
|
FILE *file1, *file2;
|
||||||
orbit_t orb1, orb2;
|
orbit_t orb1, orb2;
|
||||||
double mjd0 = 58140.0, mjd;
|
double mjd0 = 58140.0, mjd;
|
||||||
|
@ -100,7 +114,8 @@ int main(int argc,char *argv[])
|
||||||
file2 = fopen (catalog2, "r");
|
file2 = fopen (catalog2, "r");
|
||||||
|
|
||||||
// Loop over classfd catalog
|
// Loop over classfd catalog
|
||||||
while (read_twoline(file1,0,&orb1)==0) {
|
while (read_twoline (file1, 0, &orb1) == 0)
|
||||||
|
{
|
||||||
// Compute positions
|
// Compute positions
|
||||||
imode = init_sgdp4 (&orb1);
|
imode = init_sgdp4 (&orb1);
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
|
@ -109,14 +124,16 @@ int main(int argc,char *argv[])
|
||||||
// Loop over ISON catalog
|
// Loop over ISON catalog
|
||||||
flag = 0;
|
flag = 0;
|
||||||
rewind (file2);
|
rewind (file2);
|
||||||
while (read_twoline(file2,0,&orb2)==0) {
|
while (read_twoline (file2, 0, &orb2) == 0)
|
||||||
|
{
|
||||||
mjd = doy2mjd (orb2.ep_year, orb2.ep_day);
|
mjd = doy2mjd (orb2.ep_year, orb2.ep_day);
|
||||||
|
|
||||||
imode = init_sgdp4 (&orb2);
|
imode = init_sgdp4 (&orb2);
|
||||||
satpos_xyz (mjd + 2400000.5, &r0, &v0);
|
satpos_xyz (mjd + 2400000.5, &r0, &v0);
|
||||||
|
|
||||||
// Find nearest offset
|
// Find nearest offset
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
d.x = r[i].x - r0.x;
|
d.x = r[i].x - r0.x;
|
||||||
d.y = r[i].y - r0.y;
|
d.y = r[i].y - r0.y;
|
||||||
d.z = r[i].z - r0.z;
|
d.z = r[i].z - r0.z;
|
||||||
|
@ -126,7 +143,8 @@ int main(int argc,char *argv[])
|
||||||
d.z = v[i].z - v0.z;
|
d.z = v[i].z - v0.z;
|
||||||
dv = sqrt (d.x * d.x + d.y * d.y + d.z * d.z);
|
dv = sqrt (d.x * d.x + d.y * d.y + d.z * d.z);
|
||||||
|
|
||||||
if (flag==0 || dr<drmin) {
|
if (flag == 0 || dr < drmin)
|
||||||
|
{
|
||||||
drmin = dr;
|
drmin = dr;
|
||||||
dvmin = dv;
|
dvmin = dv;
|
||||||
satno = orb2.satno;
|
satno = orb2.satno;
|
||||||
|
@ -152,17 +170,21 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Find object name
|
// Find object name
|
||||||
rewind (file2);
|
rewind (file2);
|
||||||
while (fgetline(file2,line0,LIM)>0) {
|
while (fgetline (file2, line0, LIM) > 0)
|
||||||
|
{
|
||||||
fgetline (file2, line1, LIM);
|
fgetline (file2, line1, LIM);
|
||||||
fgetline (file2, line2, LIM);
|
fgetline (file2, line2, LIM);
|
||||||
sscanf (line1, "1 %d", &satno2);
|
sscanf (line1, "1 %d", &satno2);
|
||||||
if (satno==satno2) {
|
if (satno == satno2)
|
||||||
|
{
|
||||||
sscanf (line0, "SO %d", &satname);
|
sscanf (line0, "SO %d", &satname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("%05d %05d %8.2f km %9.5f km/s %6.0lf s %8.0f km\n",orb1.satno,satno,drmin,dvmin,(mjd0+(double) imin/86400.0-mjd)*86400,dn);
|
// printf("%05d %05d %8.2f km %9.5f km/s %6.0lf s %8.0f km\n",orb1.satno,satno,drmin,dvmin,(mjd0+(double) imin/86400.0-mjd)*86400,dn);
|
||||||
printf("%6d %05d %s | %5d %8.2f km %9.5f km/s %6.0lf s %8.0f km\n",satname,orb1.satno,orb1.desig,satno,drmin,dvmin,(mjd0+(double) imin/86400.0-mjd)*86400,dn);
|
printf ("%6d %05d %s | %5d %8.2f km %9.5f km/s %6.0lf s %8.0f km\n",
|
||||||
|
satname, orb1.satno, orb1.desig, satno, drmin, dvmin,
|
||||||
|
(mjd0 + (double) imin / 86400.0 - mjd) * 86400, dn);
|
||||||
}
|
}
|
||||||
fclose (file1);
|
fclose (file1);
|
||||||
fclose (file2);
|
fclose (file2);
|
||||||
|
|
65
src/posvel.c
65
src/posvel.c
|
@ -19,7 +19,8 @@ extern double SGDP4_jd0;
|
||||||
|
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -32,7 +33,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +58,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -66,7 +69,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -75,12 +79,14 @@ double mjd2doy(double mjd,int *yr)
|
||||||
|
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -88,22 +94,29 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -112,7 +125,8 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -121,20 +135,25 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf("propagate c:i:t:m:\n\nPropagates orbital elements to a new epoch using the SGP4/SDP4 model.\nDefault operation propagates classfd.tle to now,\n\n-c input catalog\n-i Satellite number\n-t New epoch (YYYY-MM-DDTHH:MM:SS)\n-m New epoch (MJD)\n");
|
printf
|
||||||
|
("propagate c:i:t:m:\n\nPropagates orbital elements to a new epoch using the SGP4/SDP4 model.\nDefault operation propagates classfd.tle to now,\n\n-c input catalog\n-i Satellite number\n-t New epoch (YYYY-MM-DDTHH:MM:SS)\n-m New epoch (MJD)\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int imode, satno = 0, arg, i;
|
int imode, satno = 0, arg, i;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -154,8 +173,10 @@ int main(int argc,char *argv[])
|
||||||
mjd = nfd2mjd (nfd);
|
mjd = nfd2mjd (nfd);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"c:i:t:l:d:"))!=-1) {
|
while ((arg = getopt (argc, argv, "c:i:t:l:d:")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (nfd, optarg);
|
strcpy (nfd, optarg);
|
||||||
|
@ -194,11 +215,13 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (tlefile, "r");
|
file = fopen (tlefile, "r");
|
||||||
while (read_twoline(file,satno,&orb)==0) {
|
while (read_twoline (file, satno, &orb) == 0)
|
||||||
|
{
|
||||||
// Propagate
|
// Propagate
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
|
|
||||||
for (i=0;i<length;i+=dl) {
|
for (i = 0; i < length; i += dl)
|
||||||
|
{
|
||||||
satpos_xyz (mjd + 2400000.5 + (double) i / 86400.0, &r, &v);
|
satpos_xyz (mjd + 2400000.5 + (double) i / 86400.0, &r, &v);
|
||||||
printf ("%f %f %f %f %f %f\n", r.x, r.y, r.z, v.x, v.y, v.z);
|
printf ("%f %f %f %f %f %f\n", r.x, r.y, r.z, v.x, v.y, v.z);
|
||||||
}
|
}
|
||||||
|
|
126
src/propagate.c
126
src/propagate.c
|
@ -18,28 +18,33 @@
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dot product
|
// Dot product
|
||||||
float dot(xyz_t a,xyz_t b)
|
float
|
||||||
|
dot (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
double magnitude(xyz_t a)
|
double
|
||||||
|
magnitude (xyz_t a)
|
||||||
{
|
{
|
||||||
return sqrt (dot (a, a));
|
return sqrt (dot (a, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross product
|
// Cross product
|
||||||
xyz_t cross(xyz_t a,xyz_t b)
|
xyz_t
|
||||||
|
cross (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
xyz_t c;
|
xyz_t c;
|
||||||
|
|
||||||
|
@ -51,7 +56,8 @@ xyz_t cross(xyz_t a,xyz_t b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -64,7 +70,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +95,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -98,7 +106,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -106,7 +115,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clasical elements
|
// Clasical elements
|
||||||
orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
orbit_t
|
||||||
|
classel (int ep_year, double ep_day, xyz_t r, xyz_t v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double rm, vm, vm2, rvm, mu = 1.0;;
|
double rm, vm, vm2, rvm, mu = 1.0;;
|
||||||
|
@ -153,7 +163,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
peri += 360.0;
|
peri += 360.0;
|
||||||
|
|
||||||
// Elliptic motion
|
// Elliptic motion
|
||||||
if (ecc<1.0) {
|
if (ecc < 1.0)
|
||||||
|
{
|
||||||
xp = (chi - rm) / ecc;
|
xp = (chi - rm) / ecc;
|
||||||
yp = rvm / ecc * sqrt (chi / mu);
|
yp = rvm / ecc * sqrt (chi / mu);
|
||||||
b = a * sqrt (1.0 - ecc * ecc);
|
b = a * sqrt (1.0 - ecc * ecc);
|
||||||
|
@ -182,7 +193,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
return orb;
|
return orb;
|
||||||
}
|
}
|
||||||
|
|
||||||
orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
orbit_t
|
||||||
|
rv2el (int satno, double mjd, xyz_t r0, xyz_t v0)
|
||||||
{
|
{
|
||||||
int i, imode;
|
int i, imode;
|
||||||
orbit_t orb[5], orb1[5];
|
orbit_t orb[5], orb1[5];
|
||||||
|
@ -199,7 +211,8 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
orb[0] = classel (ep_year, ep_day, r0, v0);
|
orb[0] = classel (ep_year, ep_day, r0, v0);
|
||||||
orb[0].satno = satno;
|
orb[0].satno = satno;
|
||||||
|
|
||||||
for (i=0;i<4;i++) {
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
// Propagate
|
// Propagate
|
||||||
imode = init_sgdp4 (&orb[i]);
|
imode = init_sgdp4 (&orb[i]);
|
||||||
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
||||||
|
@ -235,30 +248,44 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.desig,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1, "1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev);
|
orb.satno, orb.desig, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -270,7 +297,8 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -279,18 +307,22 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -298,17 +330,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOY to MJD
|
// DOY to MJD
|
||||||
double doy2mjd(int year,double doy)
|
double
|
||||||
|
doy2mjd (int year, double doy)
|
||||||
{
|
{
|
||||||
int month, k = 2;
|
int month, k = 2;
|
||||||
double day;
|
double day;
|
||||||
|
@ -321,18 +359,22 @@ double doy2mjd(int year,double doy)
|
||||||
if (doy < 32)
|
if (doy < 32)
|
||||||
month = 1;
|
month = 1;
|
||||||
|
|
||||||
day=doy-floor(275.0*month/9.0)+k*floor((month+9.0)/12.0)+30.0;
|
day =
|
||||||
|
doy - floor (275.0 * month / 9.0) + k * floor ((month + 9.0) / 12.0) +
|
||||||
|
30.0;
|
||||||
|
|
||||||
return date2mjd (year, month, day);
|
return date2mjd (year, month, day);
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -340,15 +382,18 @@ double nfd2mjd(char *date)
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf("propagate c:i:t:m:e:d:\n\nPropagates orbital elements to a new epoch using the SGP4/SDP4 model.\nDefault operation propagates classfd.tle to now,\n\n-c input catalog\n-i Satellite number\n-t New epoch (YYYY-MM-DDTHH:MM:SS)\n-m New epoch (MJD)\n-e New epoch (YYDDD.ddddddd)\n-d New COSPAR designation\n");
|
printf
|
||||||
|
("propagate c:i:t:m:e:d:\n\nPropagates orbital elements to a new epoch using the SGP4/SDP4 model.\nDefault operation propagates classfd.tle to now,\n\n-c input catalog\n-i Satellite number\n-t New epoch (YYYY-MM-DDTHH:MM:SS)\n-m New epoch (MJD)\n-e New epoch (YYDDD.ddddddd)\n-d New COSPAR designation\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int imode, satno = 0, arg, desigflag = 0;
|
int imode, satno = 0, arg, desigflag = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -369,8 +414,10 @@ int main(int argc,char *argv[])
|
||||||
mjd = nfd2mjd (nfd);
|
mjd = nfd2mjd (nfd);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"c:i:t:m:he:d:"))!=-1) {
|
while ((arg = getopt (argc, argv, "c:i:t:m:he:d:")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (nfd, optarg);
|
strcpy (nfd, optarg);
|
||||||
|
@ -421,7 +468,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (tlefile, "r");
|
file = fopen (tlefile, "r");
|
||||||
while (read_twoline(file,satno,&orb)==0) {
|
while (read_twoline (file, satno, &orb) == 0)
|
||||||
|
{
|
||||||
format_tle (orb, line1, line2);
|
format_tle (orb, line1, line2);
|
||||||
// printf("Input:\n%s\n%s\n",line1,line2);
|
// printf("Input:\n%s\n%s\n",line1,line2);
|
||||||
if (desigflag == 0)
|
if (desigflag == 0)
|
||||||
|
|
191
src/pstrack.c
191
src/pstrack.c
|
@ -21,13 +21,15 @@ long Isat=0;
|
||||||
long Isatsel = 0;
|
long Isatsel = 0;
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
double lat, lng;
|
double lat, lng;
|
||||||
float alt;
|
float alt;
|
||||||
char observer[32];
|
char observer[32];
|
||||||
int site_id;
|
int site_id;
|
||||||
} m;
|
} m;
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
char filename[64];
|
char filename[64];
|
||||||
int naxis1, naxis2, naxis3, nframes;
|
int naxis1, naxis2, naxis3, nframes;
|
||||||
float *zavg, *zstd, *zmax, *znum, *zd;
|
float *zavg, *zstd, *zmax, *znum, *zd;
|
||||||
|
@ -39,7 +41,8 @@ struct image {
|
||||||
char nfd[32];
|
char nfd[32];
|
||||||
int cospar;
|
int cospar;
|
||||||
};
|
};
|
||||||
struct sat {
|
struct sat
|
||||||
|
{
|
||||||
long Isat;
|
long Isat;
|
||||||
char state[10];
|
char state[10];
|
||||||
float mag;
|
float mag;
|
||||||
|
@ -52,7 +55,8 @@ struct sat {
|
||||||
double azi, alt;
|
double azi, alt;
|
||||||
double rx, ry;
|
double rx, ry;
|
||||||
};
|
};
|
||||||
struct track {
|
struct track
|
||||||
|
{
|
||||||
float x0, y0, x1, y1;
|
float x0, y0, x1, y1;
|
||||||
};
|
};
|
||||||
struct image read_fits (char *filename);
|
struct image read_fits (char *filename);
|
||||||
|
@ -62,11 +66,14 @@ void obspos_xyz(double,xyz_t *,xyz_t *);
|
||||||
void sunpos_xyz (double, xyz_t *);
|
void sunpos_xyz (double, xyz_t *);
|
||||||
double gmst (double);
|
double gmst (double);
|
||||||
double dgmst (double);
|
double dgmst (double);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de);
|
double *y);
|
||||||
|
void reverse (double ra0, double de0, double x, double y, double *ra,
|
||||||
|
double *de);
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -79,11 +86,13 @@ void get_site(int site_id)
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
sprintf (filename, "%s/data/sites.txt", env);
|
sprintf (filename, "%s/data/sites.txt", env);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -92,14 +101,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
@ -114,7 +123,9 @@ void get_site(int site_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precess a celestial position
|
// Precess a celestial position
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
void
|
||||||
|
precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
double zeta, z, theta;
|
double zeta, z, theta;
|
||||||
|
@ -154,7 +165,8 @@ void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
orbit_t find_tle(char *tlefile,struct image img,int satno)
|
orbit_t
|
||||||
|
find_tle (char *tlefile, struct image img, int satno)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
orbit_t orb;
|
orbit_t orb;
|
||||||
|
@ -177,7 +189,8 @@ orbit_t find_tle(char *tlefile,struct image img,int satno)
|
||||||
fatal_error ("File open failed for reading %s\n", tlefile);
|
fatal_error ("File open failed for reading %s\n", tlefile);
|
||||||
|
|
||||||
// Read TLEs
|
// Read TLEs
|
||||||
if (satno!=0) {
|
if (satno != 0)
|
||||||
|
{
|
||||||
read_twoline (fp, satno, &orb);
|
read_twoline (fp, satno, &orb);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
return orb;
|
return orb;
|
||||||
|
@ -186,7 +199,8 @@ orbit_t find_tle(char *tlefile,struct image img,int satno)
|
||||||
read_twoline (fp, 0, &orb);
|
read_twoline (fp, 0, &orb);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
for (i=0,mnan=0.0;mnan<360.0;mnan+=0.01,i++) {
|
for (i = 0, mnan = 0.0; mnan < 360.0; mnan += 0.01, i++)
|
||||||
|
{
|
||||||
orb.mnan = mnan * D2R;
|
orb.mnan = mnan * D2R;
|
||||||
Isat = orb.satno;
|
Isat = orb.satno;
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
|
@ -196,13 +210,18 @@ orbit_t find_tle(char *tlefile,struct image img,int satno)
|
||||||
// Compute apparent position
|
// Compute apparent position
|
||||||
s = apparent_position (mjd);
|
s = apparent_position (mjd);
|
||||||
|
|
||||||
r=acos(sin(img.de0*D2R)*sin(s.de*D2R)+cos(img.de0*D2R)*cos(s.de*D2R)*cos((img.ra0-s.ra)*D2R))*R2D;
|
r =
|
||||||
if (r<10.0) {
|
acos (sin (img.de0 * D2R) * sin (s.de * D2R) +
|
||||||
|
cos (img.de0 * D2R) * cos (s.de * D2R) * cos ((img.ra0 - s.ra) *
|
||||||
|
D2R)) * R2D;
|
||||||
|
if (r < 10.0)
|
||||||
|
{
|
||||||
forward (img.ra0, img.de0, s.ra, s.de, &s.rx, &s.ry);
|
forward (img.ra0, img.de0, s.ra, s.de, &s.rx, &s.ry);
|
||||||
r = sqrt (s.rx * s.rx + s.ry * s.ry) / 3600.0;
|
r = sqrt (s.rx * s.rx + s.ry * s.ry) / 3600.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i==0 || r<rmin) {
|
if (i == 0 || r < rmin)
|
||||||
|
{
|
||||||
mnanmin = mnan;
|
mnanmin = mnan;
|
||||||
rmin = r;
|
rmin = r;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +230,9 @@ orbit_t find_tle(char *tlefile,struct image img,int satno)
|
||||||
|
|
||||||
return orb;
|
return orb;
|
||||||
}
|
}
|
||||||
struct track plot_satellite(orbit_t orb,struct image img)
|
|
||||||
|
struct track
|
||||||
|
plot_satellite (orbit_t orb, struct image img)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct sat s;
|
struct sat s;
|
||||||
|
@ -237,7 +258,8 @@ struct track plot_satellite(orbit_t orb,struct image img)
|
||||||
if (imode == SGDP4_ERROR)
|
if (imode == SGDP4_ERROR)
|
||||||
return trk;
|
return trk;
|
||||||
|
|
||||||
for (flag=0,textflag=0,i=0;i<MMAX;i++) {
|
for (flag = 0, textflag = 0, i = 0; i < MMAX; i++)
|
||||||
|
{
|
||||||
t = img.exptime * (float) i / (float) (MMAX - 1);
|
t = img.exptime * (float) i / (float) (MMAX - 1);
|
||||||
mjd = img.mjd + t / 86400.0;
|
mjd = img.mjd + t / 86400.0;
|
||||||
|
|
||||||
|
@ -245,7 +267,10 @@ struct track plot_satellite(orbit_t orb,struct image img)
|
||||||
s = apparent_position (mjd);
|
s = apparent_position (mjd);
|
||||||
|
|
||||||
// Convert to rx,ry
|
// Convert to rx,ry
|
||||||
r=acos(sin(img.de0*D2R)*sin(s.de*D2R)+cos(img.de0*D2R)*cos(s.de*D2R)*cos((img.ra0-s.ra)*D2R))*R2D;
|
r =
|
||||||
|
acos (sin (img.de0 * D2R) * sin (s.de * D2R) +
|
||||||
|
cos (img.de0 * D2R) * cos (s.de * D2R) * cos ((img.ra0 - s.ra) *
|
||||||
|
D2R)) * R2D;
|
||||||
if (r < 90.0)
|
if (r < 90.0)
|
||||||
forward (img.ra0, img.de0, s.ra, s.de, &s.rx, &s.ry);
|
forward (img.ra0, img.de0, s.ra, s.de, &s.rx, &s.ry);
|
||||||
else
|
else
|
||||||
|
@ -268,7 +293,8 @@ struct track plot_satellite(orbit_t orb,struct image img)
|
||||||
return trk;
|
return trk;
|
||||||
}
|
}
|
||||||
|
|
||||||
void track_image(struct image *img,struct track trk)
|
void
|
||||||
|
track_image (struct image *img, struct track trk)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[LIM], filename[LIM];
|
char line[LIM], filename[LIM];
|
||||||
|
@ -288,13 +314,15 @@ void track_image(struct image *img,struct track trk)
|
||||||
wt = (int *) malloc (sizeof (int) * img->naxis1 * img->naxis2);
|
wt = (int *) malloc (sizeof (int) * img->naxis1 * img->naxis2);
|
||||||
|
|
||||||
// Set to zero
|
// Set to zero
|
||||||
for (i=0;i<img->naxis1*img->naxis2;i++) {
|
for (i = 0; i < img->naxis1 * img->naxis2; i++)
|
||||||
|
{
|
||||||
z[i] = 0.0;
|
z[i] = 0.0;
|
||||||
wt[i] = 0;
|
wt[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over frames
|
// Loop over frames
|
||||||
for (l=0;l<img->nframes;l++) {
|
for (l = 0; l < img->nframes; l++)
|
||||||
|
{
|
||||||
// Offset
|
// Offset
|
||||||
dx = dxdn * (l - img->nframes / 2);
|
dx = dxdn * (l - img->nframes / 2);
|
||||||
dy = dydn * (l - img->nframes / 2);
|
dy = dydn * (l - img->nframes / 2);
|
||||||
|
@ -304,11 +332,15 @@ void track_image(struct image *img,struct track trk)
|
||||||
dj = (int) floor (dy + 0.5);
|
dj = (int) floor (dy + 0.5);
|
||||||
|
|
||||||
// Set
|
// Set
|
||||||
for (i=0;i<img->naxis1;i++) {
|
for (i = 0; i < img->naxis1; i++)
|
||||||
for (j=0;j<img->naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < img->naxis2; j++)
|
||||||
|
{
|
||||||
k = i + img->naxis1 * j;
|
k = i + img->naxis1 * j;
|
||||||
k0 = i + di + img->naxis1 * (j + dj);
|
k0 = i + di + img->naxis1 * (j + dj);
|
||||||
if (i+di>0 && i+di<img->naxis1 && j+dj>0 && j+dj<img->naxis2) {
|
if (i + di > 0 && i + di < img->naxis1 && j + dj > 0
|
||||||
|
&& j + dj < img->naxis2)
|
||||||
|
{
|
||||||
wt[k] += 1;
|
wt[k] += 1;
|
||||||
if (img->znum[k0] == l)
|
if (img->znum[k0] == l)
|
||||||
z[k] += img->zmax[k0];
|
z[k] += img->zmax[k0];
|
||||||
|
@ -320,7 +352,8 @@ void track_image(struct image *img,struct track trk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale
|
// Scale
|
||||||
for (i=0;i<img->naxis1*img->naxis2;i++) {
|
for (i = 0; i < img->naxis1 * img->naxis2; i++)
|
||||||
|
{
|
||||||
if (wt[i] > 0)
|
if (wt[i] > 0)
|
||||||
img->zd[i] = z[i] / (float) wt[i];
|
img->zd[i] = z[i] / (float) wt[i];
|
||||||
else
|
else
|
||||||
|
@ -335,7 +368,8 @@ void track_image(struct image *img,struct track trk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct image img;
|
struct image img;
|
||||||
|
@ -389,9 +423,17 @@ int main(int argc,char *argv[])
|
||||||
cpgsch (0.8);
|
cpgsch (0.8);
|
||||||
sprintf (text, "UT Date: %.23s COSPAR ID: %04d", img.nfd + 1, img.cospar);
|
sprintf (text, "UT Date: %.23s COSPAR ID: %04d", img.nfd + 1, img.cospar);
|
||||||
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
||||||
sprintf(text,"R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')",img.ra0,img.xrms,img.de0,img.yrms);
|
sprintf (text, "R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')", img.ra0,
|
||||||
|
img.xrms, img.de0, img.yrms);
|
||||||
cpgmtxt ("T", 4.8, 0.0, 0.0, text);
|
cpgmtxt ("T", 4.8, 0.0, 0.0, text);
|
||||||
sprintf(text,"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d",img.naxis1*sqrt(img.a[1]*img.a[1]+img.b[1]*img.b[1])/3600.0,img.naxis2*sqrt(img.a[2]*img.a[2]+img.b[2]*img.b[2])/3600.0,sqrt(img.a[1]*img.a[1]+img.b[1]*img.b[1]),sqrt(img.a[2]*img.a[2]+img.b[2]*img.b[2]));
|
sprintf (text,
|
||||||
|
"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d",
|
||||||
|
img.naxis1 * sqrt (img.a[1] * img.a[1] +
|
||||||
|
img.b[1] * img.b[1]) / 3600.0,
|
||||||
|
img.naxis2 * sqrt (img.a[2] * img.a[2] +
|
||||||
|
img.b[2] * img.b[2]) / 3600.0,
|
||||||
|
sqrt (img.a[1] * img.a[1] + img.b[1] * img.b[1]),
|
||||||
|
sqrt (img.a[2] * img.a[2] + img.b[2] * img.b[2]));
|
||||||
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
||||||
sprintf (text, "Stat: %5.1f+-%.1f (%.1f-%.1f)", zavg, zstd, zmin, zmax);
|
sprintf (text, "Stat: %5.1f+-%.1f (%.1f-%.1f)", zavg, zstd, zmin, zmax);
|
||||||
cpgmtxt ("T", 2.4, 0.0, 0.0, text);
|
cpgmtxt ("T", 2.4, 0.0, 0.0, text);
|
||||||
|
@ -402,7 +444,8 @@ int main(int argc,char *argv[])
|
||||||
cpglab ("x (pix)", "y (pix)", " ");
|
cpglab ("x (pix)", "y (pix)", " ");
|
||||||
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
||||||
|
|
||||||
cpgimag(img.zd,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,zmin,zmax,tr);
|
cpgimag (img.zd, img.naxis1, img.naxis2, 1, img.naxis1, 1, img.naxis2, zmin,
|
||||||
|
zmax, tr);
|
||||||
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
||||||
|
|
||||||
cpgstbg (1);
|
cpgstbg (1);
|
||||||
|
@ -413,7 +456,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
sprintf (filename, "%s.id", argv[1]);
|
sprintf (filename, "%s.id", argv[1]);
|
||||||
file = fopen (filename, "w");
|
file = fopen (filename, "w");
|
||||||
fprintf(file,"%.23s %8.3f %8.3f %8.3f %8.3f %8.5f 00001 classfd.tle\n",img.nfd+1,trk.x0,trk.y0,trk.x1,trk.y1,img.exptime);
|
fprintf (file, "%.23s %8.3f %8.3f %8.3f %8.3f %8.5f 00001 classfd.tle\n",
|
||||||
|
img.nfd + 1, trk.x0, trk.y0, trk.x1, trk.y1, img.exptime);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
cpgend ();
|
cpgend ();
|
||||||
|
|
||||||
|
@ -421,7 +465,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename)
|
struct image
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -463,7 +508,8 @@ struct image read_fits(char *filename)
|
||||||
|
|
||||||
// Timestamps
|
// Timestamps
|
||||||
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
||||||
for (i=0;i<img.nframes;i++) {
|
for (i = 0; i < img.nframes; i++)
|
||||||
|
{
|
||||||
sprintf (key, "DT%04d", i);
|
sprintf (key, "DT%04d", i);
|
||||||
//strcpy(val,qfits_query_hdr(filename,key));
|
//strcpy(val,qfits_query_hdr(filename,key));
|
||||||
// sscanf(val+1,"%f",&img.dt[i]);
|
// sscanf(val+1,"%f",&img.dt[i]);
|
||||||
|
@ -485,7 +531,8 @@ struct image read_fits(char *filename)
|
||||||
ql.filename = filename;
|
ql.filename = filename;
|
||||||
|
|
||||||
// Loop over planes
|
// Loop over planes
|
||||||
for (k=0;k<img.naxis3;k++) {
|
for (k = 0; k < img.naxis3; k++)
|
||||||
|
{
|
||||||
ql.pnum = k;;
|
ql.pnum = k;;
|
||||||
|
|
||||||
// Initialize load
|
// Initialize load
|
||||||
|
@ -497,13 +544,20 @@ struct image read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
if (k==0) img.zavg[l]=ql.fbuf[l];
|
for (j = 0; j < img.naxis2; j++)
|
||||||
if (k==1) img.zstd[l]=ql.fbuf[l];
|
{
|
||||||
if (k==2) img.zmax[l]=ql.fbuf[l];
|
if (k == 0)
|
||||||
if (k==3) img.znum[l]=ql.fbuf[l];
|
img.zavg[l] = ql.fbuf[l];
|
||||||
if (k==3) img.zd[l]=ql.fbuf[l];
|
if (k == 1)
|
||||||
|
img.zstd[l] = ql.fbuf[l];
|
||||||
|
if (k == 2)
|
||||||
|
img.zmax[l] = ql.fbuf[l];
|
||||||
|
if (k == 3)
|
||||||
|
img.znum[l] = ql.fbuf[l];
|
||||||
|
if (k == 3)
|
||||||
|
img.zd[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,7 +567,8 @@ struct image read_fits(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Computes apparent position
|
// Computes apparent position
|
||||||
struct sat apparent_position(double mjd)
|
struct sat
|
||||||
|
apparent_position (double mjd)
|
||||||
{
|
{
|
||||||
struct sat s;
|
struct sat s;
|
||||||
double jd, rsun, rearth, rsat;
|
double jd, rsun, rearth, rsat;
|
||||||
|
@ -548,12 +603,15 @@ struct sat apparent_position(double mjd)
|
||||||
|
|
||||||
// Distances
|
// Distances
|
||||||
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
||||||
rearth=sqrt(satpos.x*satpos.x+satpos.y*satpos.y+satpos.z*satpos.z);
|
rearth =
|
||||||
|
sqrt (satpos.x * satpos.x + satpos.y * satpos.y + satpos.z * satpos.z);
|
||||||
|
|
||||||
// Angles
|
// Angles
|
||||||
s.psun = asin (696.0e3 / rsun) * R2D;
|
s.psun = asin (696.0e3 / rsun) * R2D;
|
||||||
s.pearth = asin (6378.135 / rearth) * R2D;
|
s.pearth = asin (6378.135 / rearth) * R2D;
|
||||||
s.p=acos((-dx*satpos.x-dy*satpos.y-dz*satpos.z)/(rsun*rearth))*R2D;
|
s.p =
|
||||||
|
acos ((-dx * satpos.x - dy * satpos.y -
|
||||||
|
dz * satpos.z) / (rsun * rearth)) * R2D;
|
||||||
|
|
||||||
// Visibility state
|
// Visibility state
|
||||||
if (s.p - s.pearth < -s.psun)
|
if (s.p - s.pearth < -s.psun)
|
||||||
|
@ -581,11 +639,19 @@ struct sat apparent_position(double mjd)
|
||||||
precess (mjd, ra, de, mjd0, &s.ra, &s.de);
|
precess (mjd, ra, de, mjd0, &s.ra, &s.de);
|
||||||
|
|
||||||
// Phase
|
// Phase
|
||||||
s.phase=acos(((obspos.x-satpos.x)*(sunpos.x-satpos.x)+(obspos.y-satpos.y)*(sunpos.y-satpos.y)+(obspos.z-satpos.z)*(sunpos.z-satpos.z))/(rsun*s.r))*R2D;
|
s.phase =
|
||||||
|
acos (((obspos.x - satpos.x) * (sunpos.x - satpos.x) +
|
||||||
|
(obspos.y - satpos.y) * (sunpos.y - satpos.y) + (obspos.z -
|
||||||
|
satpos.z) *
|
||||||
|
(sunpos.z - satpos.z)) / (rsun * s.r)) * R2D;
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
if (strcmp (s.state, "sunlit") == 0)
|
if (strcmp (s.state, "sunlit") == 0)
|
||||||
s.mag=STDMAG-15.0+5*log10(s.r)-2.5*log10(sin(s.phase*D2R)+(M_PI-s.phase*D2R)*cos(s.phase*D2R));
|
s.mag =
|
||||||
|
STDMAG - 15.0 + 5 * log10 (s.r) - 2.5 * log10 (sin (s.phase * D2R) +
|
||||||
|
(M_PI -
|
||||||
|
s.phase * D2R) *
|
||||||
|
cos (s.phase * D2R));
|
||||||
else
|
else
|
||||||
s.mag = 15;
|
s.mag = 15;
|
||||||
|
|
||||||
|
@ -602,28 +668,34 @@ struct sat apparent_position(double mjd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observer position
|
// Observer position
|
||||||
void obspos_xyz(double mjd,xyz_t *pos,xyz_t *vel)
|
void
|
||||||
|
obspos_xyz (double mjd, xyz_t * pos, xyz_t * vel)
|
||||||
{
|
{
|
||||||
double ff, gc, gs, theta, s, dtheta;
|
double ff, gc, gs, theta, s, dtheta;
|
||||||
|
|
||||||
|
@ -646,7 +718,8 @@ void obspos_xyz(double mjd,xyz_t *pos,xyz_t *vel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Solar position
|
// Solar position
|
||||||
void sunpos_xyz(double mjd,xyz_t *pos)
|
void
|
||||||
|
sunpos_xyz (double mjd, xyz_t * pos)
|
||||||
{
|
{
|
||||||
double jd, t, l0, m, e, c, r;
|
double jd, t, l0, m, e, c, r;
|
||||||
double n, s, ecl, ra, de;
|
double n, s, ecl, ra, de;
|
||||||
|
@ -663,7 +736,10 @@ void sunpos_xyz(double mjd,xyz_t *pos)
|
||||||
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
||||||
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
||||||
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
||||||
ecl=(23.43929111+(-46.8150*t-0.00059*t*t+0.001813*t*t*t)/3600.0+0.00256*cos(n))*D2R;
|
ecl =
|
||||||
|
(23.43929111 +
|
||||||
|
(-46.8150 * t - 0.00059 * t * t + 0.001813 * t * t * t) / 3600.0 +
|
||||||
|
0.00256 * cos (n)) * D2R;
|
||||||
|
|
||||||
ra = atan2 (cos (ecl) * sin (s), cos (s));
|
ra = atan2 (cos (ecl) * sin (s), cos (s));
|
||||||
de = asin (sin (ecl) * sin (s));
|
de = asin (sin (ecl) * sin (s));
|
||||||
|
@ -676,7 +752,8 @@ void sunpos_xyz(double mjd,xyz_t *pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double dgmst(double mjd)
|
double
|
||||||
|
dgmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, dgmst;
|
double t, dgmst;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
#define LIM 128
|
#define LIM 128
|
||||||
|
|
||||||
int fgetline (FILE * file, char *s, int lim);
|
int fgetline (FILE * file, char *s, int lim);
|
||||||
int find_satno(char *desig0)
|
int
|
||||||
|
find_satno (char *desig0)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
int satno = 99999, status;
|
int satno = 99999, status;
|
||||||
|
@ -17,11 +18,13 @@ int find_satno(char *desig0)
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
sprintf (filename, "%s/data/desig.txt", env);
|
sprintf (filename, "%s/data/desig.txt", env);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Designation file not found!\n");
|
fprintf (stderr, "Designation file not found!\n");
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
status = fscanf (file, "%d %s", &satno, desig);
|
status = fscanf (file, "%d %s", &satno, desig);
|
||||||
if (strcmp (desig, desig0) == 0)
|
if (strcmp (desig, desig0) == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -32,11 +35,13 @@ int find_satno(char *desig0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
int intidy,intido,piece,site,year,month,day,hour,min,sec,fsec,satno;
|
int intidy, intido, piece, site, year, month, day, hour, min, sec, fsec,
|
||||||
|
satno;
|
||||||
char desig[16], pdesig[16];
|
char desig[16], pdesig[16];
|
||||||
int format, epoch, dummy, icsec;
|
int format, epoch, dummy, icsec;
|
||||||
float csec, cang;
|
float csec, cang;
|
||||||
|
@ -46,11 +51,14 @@ int main(int argc,char *argv[])
|
||||||
int lineno = 0;
|
int lineno = 0;
|
||||||
|
|
||||||
file = fopen (argv[1], "r");
|
file = fopen (argv[1], "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
if (strncmp(line,"2420",4)==0 && lineno==0) {
|
{
|
||||||
|
if (strncmp (line, "2420", 4) == 0 && lineno == 0)
|
||||||
|
{
|
||||||
lineno++;
|
lineno++;
|
||||||
sscanf (line, "%04d %02d%02d", &site, &year, &month);
|
sscanf (line, "%04d %02d%02d", &site, &year, &month);
|
||||||
sscanf(line+12,"%1d%1d%1d %3d%1d",&icsec,&dummy,&format,&dummy,&epoch);
|
sscanf (line + 12, "%1d%1d%1d %3d%1d", &icsec, &dummy, &format,
|
||||||
|
&dummy, &epoch);
|
||||||
|
|
||||||
csec = 0.1 * icsec;
|
csec = 0.1 * icsec;
|
||||||
cang = dummy;
|
cang = dummy;
|
||||||
|
@ -69,14 +77,16 @@ int main(int argc,char *argv[])
|
||||||
ax = floor (log10 (cang)) + 8;
|
ax = floor (log10 (cang)) + 8;
|
||||||
am = floor (cang / pow (10.0, ax - 8));
|
am = floor (cang / pow (10.0, ax - 8));
|
||||||
|
|
||||||
if (ax>9.0) {
|
if (ax > 9.0)
|
||||||
|
{
|
||||||
ax = 9.0;
|
ax = 9.0;
|
||||||
am = 9.0;
|
am = 9.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strlen(line)<5 && lineno==1) {
|
if (strlen (line) < 5 && lineno == 1)
|
||||||
|
{
|
||||||
sscanf (line, "%d", &day);
|
sscanf (line, "%d", &day);
|
||||||
if (day == 999)
|
if (day == 999)
|
||||||
break;
|
break;
|
||||||
|
@ -97,17 +107,21 @@ int main(int argc,char *argv[])
|
||||||
sscanf (line + 24, "%c%02d%02d%d", &sign, &ded, &dem, &defm);
|
sscanf (line + 24, "%c%02d%02d%d", &sign, &ded, &dem, &defm);
|
||||||
fsec *= 10.0;
|
fsec *= 10.0;
|
||||||
// Format designation
|
// Format designation
|
||||||
if (piece<26) {
|
if (piece < 26)
|
||||||
|
{
|
||||||
sprintf (desig, "%02d %03d%c", intidy, intido, piece + 'A' - 1);
|
sprintf (desig, "%02d %03d%c", intidy, intido, piece + 'A' - 1);
|
||||||
sprintf (pdesig, "%02d%03d%c", intidy, intido, piece + 'A' - 1);
|
sprintf (pdesig, "%02d%03d%c", intidy, intido, piece + 'A' - 1);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fprintf (stderr, "Failed to understand designation!\n");
|
fprintf (stderr, "Failed to understand designation!\n");
|
||||||
fprintf (stderr, "%s\n", line);
|
fprintf (stderr, "%s\n", line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test data format
|
// Test data format
|
||||||
if (format!=1) {
|
if (format != 1)
|
||||||
|
{
|
||||||
fprintf (stderr, "Angle format %d not implemented!\n", format);
|
fprintf (stderr, "Angle format %d not implemented!\n", format);
|
||||||
fprintf (stderr, "%s\n", line);
|
fprintf (stderr, "%s\n", line);
|
||||||
continue;
|
continue;
|
||||||
|
@ -129,8 +143,12 @@ int main(int argc,char *argv[])
|
||||||
satno = find_satno (pdesig);
|
satno = find_satno (pdesig);
|
||||||
|
|
||||||
// Format IOD line
|
// Format IOD line
|
||||||
printf("%05d %s %04d G %04d%02d%02d%02d%02d%02d%03d %1.0f%1.0f %d%d ",satno,desig,site,year,month,day,hour,min,sec,fsec,tm,tx,format,epoch);
|
printf
|
||||||
printf("%02d%02d%03d%c%02d%02d%02d %1.0f%1.0f\n",rah,ram,rafm,sign,ded,dem,defm,am,ax);
|
("%05d %s %04d G %04d%02d%02d%02d%02d%02d%03d %1.0f%1.0f %d%d ",
|
||||||
|
satno, desig, site, year, month, day, hour, min, sec, fsec, tm, tx,
|
||||||
|
format, epoch);
|
||||||
|
printf ("%02d%02d%03d%c%02d%02d%02d %1.0f%1.0f\n", rah, ram, rafm, sign,
|
||||||
|
ded, dem, defm, am, ax);
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
|
@ -138,7 +156,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -149,4 +168,3 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
s[i] = '\0';
|
s[i] = '\0';
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
636
src/reduce.c
636
src/reduce.c
File diff suppressed because it is too large
Load Diff
182
src/residuals.c
182
src/residuals.c
|
@ -19,20 +19,23 @@ long Isat=0;
|
||||||
long Isatsel = 0;
|
long Isatsel = 0;
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
struct point {
|
struct point
|
||||||
|
{
|
||||||
int flag, satno;
|
int flag, satno;
|
||||||
double mjd, ra, de;
|
double mjd, ra, de;
|
||||||
float st, sr;
|
float st, sr;
|
||||||
char iod_line[LIM];
|
char iod_line[LIM];
|
||||||
xyz_t obspos;
|
xyz_t obspos;
|
||||||
};
|
};
|
||||||
struct site {
|
struct site
|
||||||
|
{
|
||||||
int id;
|
int id;
|
||||||
double lng, lat;
|
double lng, lat;
|
||||||
float alt;
|
float alt;
|
||||||
char observer[64];
|
char observer[64];
|
||||||
};
|
};
|
||||||
struct data {
|
struct data
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
struct point *p;
|
struct point *p;
|
||||||
};
|
};
|
||||||
|
@ -43,13 +46,17 @@ double modulo(double x,double y);
|
||||||
double gmst (double mjd);
|
double gmst (double mjd);
|
||||||
double dgmst (double mjd);
|
double dgmst (double mjd);
|
||||||
double date2mjd (int year, int month, double day);
|
double date2mjd (int year, int month, double day);
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de);
|
void precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de);
|
||||||
void usage ();
|
void usage ();
|
||||||
void obspos_xyz(double mjd,double lng,double lat,float alt,xyz_t *pos,xyz_t *vel);
|
void obspos_xyz (double mjd, double lng, double lat, float alt, xyz_t * pos,
|
||||||
|
xyz_t * vel);
|
||||||
struct data read_data (char *filename);
|
struct data read_data (char *filename);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
|
double *y);
|
||||||
|
|
||||||
void compute_residual(char *filename,struct point p,int satno)
|
void
|
||||||
|
compute_residual (char *filename, struct point p, int satno)
|
||||||
{
|
{
|
||||||
int i, imode;
|
int i, imode;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -74,19 +81,22 @@ void compute_residual(char *filename,struct point p,int satno)
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
// Check for match
|
// Check for match
|
||||||
if (orb.satno!=p.satno && satno==0) {
|
if (orb.satno != p.satno && satno == 0)
|
||||||
|
{
|
||||||
// fprintf(stderr,"object %d not found in %s\n",p.satno,filename);
|
// fprintf(stderr,"object %d not found in %s\n",p.satno,filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
if (imode==SGDP4_ERROR) {
|
if (imode == SGDP4_ERROR)
|
||||||
|
{
|
||||||
fprintf (stderr, "Error initializing SGDP4\n");
|
fprintf (stderr, "Error initializing SGDP4\n");
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0;i<2;i++) {
|
for (i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
jd = p.mjd + 2400000.5 + (double) i / 86400;
|
jd = p.mjd + 2400000.5 + (double) i / 86400;
|
||||||
|
|
||||||
// Compute position
|
// Compute position
|
||||||
|
@ -112,30 +122,36 @@ void compute_residual(char *filename,struct point p,int satno)
|
||||||
dr = sqrt (pow (dry * rx[0] - drx * ry[0], 2) / (drx * drx + dry * dry));
|
dr = sqrt (pow (dry * rx[0] - drx * ry[0], 2) / (drx * drx + dry * dry));
|
||||||
if ((-rx[0] * drx - ry[0] * dry) < 0.0)
|
if ((-rx[0] * drx - ry[0] * dry) < 0.0)
|
||||||
dr *= -1;
|
dr *= -1;
|
||||||
printf("%s | %8.5f deg %9.4f sec %7.3f day, %.1f km\n",p.iod_line,dr,dt,age,r[0]);
|
printf ("%s | %8.5f deg %9.4f sec %7.3f day, %.1f km\n", p.iod_line, dr, dt,
|
||||||
|
age, r[0]);
|
||||||
//printf("%12.8lf %8.3f %8.3f\n",p.mjd,3600*rx[0],3600*ry[0]);
|
//printf("%12.8lf %8.3f %8.3f\n",p.mjd,3600*rx[0],3600*ry[0]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void split_file(struct data d,float dtmax)
|
void
|
||||||
|
split_file (struct data d, float dtmax)
|
||||||
{
|
{
|
||||||
int i, j, flag = 0;
|
int i, j, flag = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char filename[LIM];
|
char filename[LIM];
|
||||||
double mjd0, dt;
|
double mjd0, dt;
|
||||||
|
|
||||||
for (i=0,j=0;i<d.n;i++) {
|
for (i = 0, j = 0; i < d.n; i++)
|
||||||
if (flag==1) {
|
{
|
||||||
|
if (flag == 1)
|
||||||
|
{
|
||||||
dt = 86400 * (d.p[i].mjd - mjd0);
|
dt = 86400 * (d.p[i].mjd - mjd0);
|
||||||
if (dt>dtmax) {
|
if (dt > dtmax)
|
||||||
|
{
|
||||||
if (file != NULL)
|
if (file != NULL)
|
||||||
fclose (file);
|
fclose (file);
|
||||||
flag = 0;
|
flag = 0;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flag==0) {
|
if (flag == 0)
|
||||||
|
{
|
||||||
mjd0 = d.p[i].mjd;
|
mjd0 = d.p[i].mjd;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
sprintf (filename, "split%04d.dat", j + 1);
|
sprintf (filename, "split%04d.dat", j + 1);
|
||||||
|
@ -149,7 +165,8 @@ void split_file(struct data d,float dtmax)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, arg = 0, split = 0;
|
int i, arg = 0, split = 0;
|
||||||
struct data d;
|
struct data d;
|
||||||
|
@ -161,8 +178,10 @@ int main(int argc,char *argv[])
|
||||||
env = getenv ("ST_TLEDIR");
|
env = getenv ("ST_TLEDIR");
|
||||||
sprintf (catalog, "%s/classfd.tle", env);
|
sprintf (catalog, "%s/classfd.tle", env);
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"d:c:hs:vi:"))!=-1) {
|
while ((arg = getopt (argc, argv, "d:c:hs:vi:")) != -1)
|
||||||
switch(arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
case 'd':
|
case 'd':
|
||||||
datafile = optarg;
|
datafile = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -198,15 +217,22 @@ int main(int argc,char *argv[])
|
||||||
// Read data
|
// Read data
|
||||||
d = read_data (datafile);
|
d = read_data (datafile);
|
||||||
|
|
||||||
if (verbose==1) {
|
if (verbose == 1)
|
||||||
for (i=0;i<d.n;i++) {
|
{
|
||||||
printf("%14.8lf %10.4f %10.4f %10.4f %10.6f %10.6f\n",d.p[i].mjd,d.p[i].obspos.x,d.p[i].obspos.y,d.p[i].obspos.z,d.p[i].ra,d.p[i].de);
|
for (i = 0; i < d.n; i++)
|
||||||
|
{
|
||||||
|
printf ("%14.8lf %10.4f %10.4f %10.4f %10.6f %10.6f\n", d.p[i].mjd,
|
||||||
|
d.p[i].obspos.x, d.p[i].obspos.y, d.p[i].obspos.z,
|
||||||
|
d.p[i].ra, d.p[i].de);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split==1) {
|
if (split == 1)
|
||||||
|
{
|
||||||
split_file (d, dt);
|
split_file (d, dt);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (i = 0; i < d.n; i++)
|
for (i = 0; i < d.n; i++)
|
||||||
compute_residual (catalog, d.p[i], satno);
|
compute_residual (catalog, d.p[i], satno);
|
||||||
}
|
}
|
||||||
|
@ -215,7 +241,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode IOD Observations
|
// Decode IOD Observations
|
||||||
struct point decode_iod_observation(char *iod_line)
|
struct point
|
||||||
|
decode_iod_observation (char *iod_line)
|
||||||
{
|
{
|
||||||
int year, month, iday, hour, min;
|
int year, month, iday, hour, min;
|
||||||
int format, epoch, me, xe, sign;
|
int format, epoch, me, xe, sign;
|
||||||
|
@ -243,16 +270,20 @@ struct point decode_iod_observation(char *iod_line)
|
||||||
s = get_site (site_id);
|
s = get_site (site_id);
|
||||||
|
|
||||||
// Skip if site not found
|
// Skip if site not found
|
||||||
if (s.id<0) {
|
if (s.id < 0)
|
||||||
|
{
|
||||||
fprintf (stderr, "Site %d not found!\n", site_id);
|
fprintf (stderr, "Site %d not found!\n", site_id);
|
||||||
p.flag = 0;
|
p.flag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode date/time
|
// Decode date/time
|
||||||
sscanf(iod_line+23,"%4d%2d%2d%2d%2d%5s",&year,&month,&iday,&hour,&min,secbuf);
|
sscanf (iod_line + 23, "%4d%2d%2d%2d%2d%5s", &year, &month, &iday, &hour,
|
||||||
|
&min, secbuf);
|
||||||
sec = atof (secbuf);
|
sec = atof (secbuf);
|
||||||
sec /= pow (10, strlen (secbuf) - 2);
|
sec /= pow (10, strlen (secbuf) - 2);
|
||||||
day=(double) iday+(double) hour/24.0+(double) min/1440.0+(double) sec/86400.0;
|
day =
|
||||||
|
(double) iday + (double) hour / 24.0 + (double) min / 1440.0 +
|
||||||
|
(double) sec / 86400.0;
|
||||||
p.mjd = date2mjd (year, month, day);
|
p.mjd = date2mjd (year, month, day);
|
||||||
|
|
||||||
// Get uncertainty in time
|
// Get uncertainty in time
|
||||||
|
@ -313,15 +344,22 @@ struct point decode_iod_observation(char *iod_line)
|
||||||
ra *= 15.0;
|
ra *= 15.0;
|
||||||
|
|
||||||
// Get precession epoch
|
// Get precession epoch
|
||||||
if (epoch==0) {
|
if (epoch == 0)
|
||||||
|
{
|
||||||
p.ra = ra;
|
p.ra = ra;
|
||||||
p.de = de;
|
p.de = de;
|
||||||
return p;
|
return p;
|
||||||
} else if (epoch==4) {
|
}
|
||||||
|
else if (epoch == 4)
|
||||||
|
{
|
||||||
mjd0 = 33281.9235;
|
mjd0 = 33281.9235;
|
||||||
} else if (epoch==5) {
|
}
|
||||||
|
else if (epoch == 5)
|
||||||
|
{
|
||||||
mjd0 = 51544.5;
|
mjd0 = 51544.5;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fprintf (stderr, "Observing epoch not implemented\n");
|
fprintf (stderr, "Observing epoch not implemented\n");
|
||||||
p.flag = 0;
|
p.flag = 0;
|
||||||
}
|
}
|
||||||
|
@ -333,7 +371,8 @@ struct point decode_iod_observation(char *iod_line)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
struct site get_site(int site_id)
|
struct site
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -348,11 +387,13 @@ struct site get_site(int site_id)
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
sprintf (filename, "%s/data/sites.txt", env);
|
sprintf (filename, "%s/data/sites.txt", env);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -361,15 +402,15 @@ struct site get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
// Copy site
|
// Copy site
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
s.lat = lat;
|
s.lat = lat;
|
||||||
s.lng = lng;
|
s.lng = lng;
|
||||||
s.alt = alt;
|
s.alt = alt;
|
||||||
|
@ -385,29 +426,36 @@ struct site get_site(int site_id)
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double dgmst(double mjd)
|
double
|
||||||
|
dgmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, dgmst;
|
double t, dgmst;
|
||||||
|
|
||||||
|
@ -419,7 +467,9 @@ double dgmst(double mjd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observer position
|
// Observer position
|
||||||
void obspos_xyz(double mjd,double lng,double lat,float alt,xyz_t *pos,xyz_t *vel)
|
void
|
||||||
|
obspos_xyz (double mjd, double lng, double lat, float alt, xyz_t * pos,
|
||||||
|
xyz_t * vel)
|
||||||
{
|
{
|
||||||
double ff, gc, gs, theta, s, dtheta;
|
double ff, gc, gs, theta, s, dtheta;
|
||||||
|
|
||||||
|
@ -442,7 +492,9 @@ void obspos_xyz(double mjd,double lng,double lat,float alt,xyz_t *pos,xyz_t *vel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precess a celestial position
|
// Precess a celestial position
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
void
|
||||||
|
precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
double zeta, z, theta;
|
double zeta, z, theta;
|
||||||
|
@ -483,7 +535,8 @@ void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -497,7 +550,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage()
|
void
|
||||||
|
usage ()
|
||||||
{
|
{
|
||||||
printf ("bla\n");
|
printf ("bla\n");
|
||||||
|
|
||||||
|
@ -505,12 +559,14 @@ void usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -518,17 +574,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
struct data read_data(char *filename)
|
struct data
|
||||||
|
read_data (char *filename)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -537,7 +599,8 @@ struct data read_data(char *filename)
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Failed to open %s\n", filename);
|
fprintf (stderr, "Failed to open %s\n", filename);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
@ -555,7 +618,8 @@ struct data read_data(char *filename)
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
i = 0;
|
i = 0;
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
if (isdigit (line[0]))
|
if (isdigit (line[0]))
|
||||||
d.p[i++] = decode_iod_observation (line);
|
d.p[i++] = decode_iod_observation (line);
|
||||||
}
|
}
|
||||||
|
@ -567,7 +631,8 @@ struct data read_data(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a x and y from a RA and Decl
|
// Get a x and y from a RA and Decl
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y)
|
void
|
||||||
|
forward (double ra0, double de0, double ra, double de, double *x, double *y)
|
||||||
{
|
{
|
||||||
int i, status;
|
int i, status;
|
||||||
double phi, theta;
|
double phi, theta;
|
||||||
|
@ -582,7 +647,8 @@ void forward(double ra0,double de0,double ra,double de,double *x,double *y)
|
||||||
cel.flag = 0.;
|
cel.flag = 0.;
|
||||||
strcpy (cel.prj.code, "TAN");
|
strcpy (cel.prj.code, "TAN");
|
||||||
|
|
||||||
if (celset(&cel)) {
|
if (celset (&cel))
|
||||||
|
{
|
||||||
printf ("Error in Projection (celset)\n");
|
printf ("Error in Projection (celset)\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#include <wcslib/cel.h>
|
#include <wcslib/cel.h>
|
||||||
|
|
||||||
// Get a RA and Decl from x and y
|
// Get a RA and Decl from x and y
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de)
|
void
|
||||||
|
reverse (double ra0, double de0, double x, double y, double *ra, double *de)
|
||||||
{
|
{
|
||||||
int i, status;
|
int i, status;
|
||||||
double phi, theta;
|
double phi, theta;
|
||||||
|
@ -22,7 +23,8 @@ void reverse(double ra0,double de0,double x,double y,double *ra,double *de)
|
||||||
cel.flag = 0.;
|
cel.flag = 0.;
|
||||||
strcpy (cel.prj.code, "STG");
|
strcpy (cel.prj.code, "STG");
|
||||||
|
|
||||||
if (celset(&cel)) {
|
if (celset (&cel))
|
||||||
|
{
|
||||||
printf ("Error in Projection (celset)\n");
|
printf ("Error in Projection (celset)\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
124
src/runsched.c
124
src/runsched.c
|
@ -23,18 +23,21 @@
|
||||||
#define FINISHED 2
|
#define FINISHED 2
|
||||||
|
|
||||||
// Observation struct contains observation time, celestial coords and camera name
|
// Observation struct contains observation time, celestial coords and camera name
|
||||||
struct observation {
|
struct observation
|
||||||
|
{
|
||||||
char stime[32], sra[32], sde[32], camname[15], startstop[10];
|
char stime[32], sra[32], sde[32], camname[15], startstop[10];
|
||||||
time_t ptime;
|
time_t ptime;
|
||||||
float dt;
|
float dt;
|
||||||
};
|
};
|
||||||
|
|
||||||
int fgetline (FILE * file, char *s, int lim);
|
int fgetline (FILE * file, char *s, int lim);
|
||||||
void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname);
|
void send_position (char *sra, char *sde, char *datadir, char *obsdir,
|
||||||
|
char *camname);
|
||||||
void stop_obs (char *datadir, char *obsdir, char *camname);
|
void stop_obs (char *datadir, char *obsdir, char *camname);
|
||||||
time_t decode_time (char *stm);
|
time_t decode_time (char *stm);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i = 0, nobs, flag = 0;
|
int i = 0, nobs, flag = 0;
|
||||||
time_t rawtime, aimtime;
|
time_t rawtime, aimtime;
|
||||||
|
@ -48,27 +51,36 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
// Get environment variables
|
// Get environment variables
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (datadir, env);
|
strcpy (datadir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_DATADIR environment variable not found.\n");
|
printf ("ST_DATADIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get environment variables
|
// Get environment variables
|
||||||
env = getenv ("ST_OBSDIR");
|
env = getenv ("ST_OBSDIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (obsdir, env);
|
strcpy (obsdir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_OBSDIR environment variable not found.\n");
|
printf ("ST_OBSDIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// For ever loop
|
// For ever loop
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
// Read file
|
// Read file
|
||||||
i = 0;
|
i = 0;
|
||||||
file = fopen ("schedule.txt", "r");
|
file = fopen ("schedule.txt", "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
sscanf(line,"%s %s %s %s %s",obs[i].stime,obs[i].sra,obs[i].sde,obs[i].camname,obs[i].startstop);
|
{
|
||||||
|
sscanf (line, "%s %s %s %s %s", obs[i].stime, obs[i].sra,
|
||||||
|
obs[i].sde, obs[i].camname, obs[i].startstop);
|
||||||
obs[i].ptime = decode_time (obs[i].stime);
|
obs[i].ptime = decode_time (obs[i].stime);
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
@ -92,34 +104,46 @@ int main(int argc, char *argv[])
|
||||||
// printf("%s\n",ctime(&rawtime));
|
// printf("%s\n",ctime(&rawtime));
|
||||||
|
|
||||||
// Compute time differences
|
// Compute time differences
|
||||||
for (i=0;i<nobs;i++) {
|
for (i = 0; i < nobs; i++)
|
||||||
|
{
|
||||||
obs[i].dt = difftime (obs[i].ptime, rawtime);
|
obs[i].dt = difftime (obs[i].ptime, rawtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
nextobs = -1;
|
nextobs = -1;
|
||||||
dtnext = 9999999;
|
dtnext = 9999999;
|
||||||
// Loop over observations
|
// Loop over observations
|
||||||
for (i=0;i<nobs;i++) {
|
for (i = 0; i < nobs; i++)
|
||||||
if (obs[i].dt>0.0) {
|
{
|
||||||
if(obs[i].dt < dtnext){
|
if (obs[i].dt > 0.0)
|
||||||
|
{
|
||||||
|
if (obs[i].dt < dtnext)
|
||||||
|
{
|
||||||
nextobs = i;
|
nextobs = i;
|
||||||
dtnext = obs[i].dt;
|
dtnext = obs[i].dt;
|
||||||
}
|
}
|
||||||
// printf("%4.0f %s %s %s %s\n",obs[i].dt,obs[i].stime,obs[i].sra,obs[i].sde,obs[i].startstop);
|
// printf("%4.0f %s %s %s %s\n",obs[i].dt,obs[i].stime,obs[i].sra,obs[i].sde,obs[i].startstop);
|
||||||
// break;
|
// break;
|
||||||
} else if (obs[i].dt==0) {
|
}
|
||||||
if(strstr(obs[i].startstop,"tart")!=NULL){
|
else if (obs[i].dt == 0)
|
||||||
|
{
|
||||||
|
if (strstr (obs[i].startstop, "tart") != NULL)
|
||||||
|
{
|
||||||
//printf("Slewing to %s %s\n",obs[i].sra,obs[i].sde);
|
//printf("Slewing to %s %s\n",obs[i].sra,obs[i].sde);
|
||||||
send_position(obs[i].sra,obs[i].sde,datadir,obsdir,obs[i].camname);
|
send_position (obs[i].sra, obs[i].sde, datadir, obsdir,
|
||||||
} else if(strstr(obs[i].startstop,"top")!=NULL){
|
obs[i].camname);
|
||||||
|
}
|
||||||
|
else if (strstr (obs[i].startstop, "top") != NULL)
|
||||||
|
{
|
||||||
stop_obs (datadir, obsdir, obs[i].camname);
|
stop_obs (datadir, obsdir, obs[i].camname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nextobs>=0){
|
if (nextobs >= 0)
|
||||||
|
{
|
||||||
// print next observation data if any found
|
// print next observation data if any found
|
||||||
printf("%4.0f %s %s %s %s\n",obs[nextobs].dt,obs[nextobs].stime,obs[nextobs].sra,obs[nextobs].sde,obs[nextobs].startstop);
|
printf ("%4.0f %s %s %s %s\n", obs[nextobs].dt, obs[nextobs].stime,
|
||||||
|
obs[nextobs].sra, obs[nextobs].sde, obs[nextobs].startstop);
|
||||||
}
|
}
|
||||||
// Sleep
|
// Sleep
|
||||||
sleep (1);
|
sleep (1);
|
||||||
|
@ -129,7 +153,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -142,22 +167,26 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read data/cameras.txt in search of specified camera name and return complete camera details line
|
// Read data/cameras.txt in search of specified camera name and return complete camera details line
|
||||||
int read_cameras(char *camname,char *datadir,char *camera)
|
int
|
||||||
|
read_cameras (char *camname, char *datadir, char *camera)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[127], filename[127];
|
char line[127], filename[127];
|
||||||
|
|
||||||
sprintf (filename, "%s/data/cameras.txt", datadir);
|
sprintf (filename, "%s/data/cameras.txt", datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with camera information not found!\n");
|
printf ("File with camera information not found!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip commented lines
|
// Skip commented lines
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
if(strstr(line, camname)!=NULL){
|
if (strstr (line, camname) != NULL)
|
||||||
|
{
|
||||||
strcpy (camera, line);
|
strcpy (camera, line);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +197,9 @@ int read_cameras(char *camname,char *datadir,char *camera)
|
||||||
|
|
||||||
|
|
||||||
// Send new position to telescope
|
// Send new position to telescope
|
||||||
void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname)
|
void
|
||||||
|
send_position (char *sra, char *sde, char *datadir, char *obsdir,
|
||||||
|
char *camname)
|
||||||
{
|
{
|
||||||
int skt, port;
|
int skt, port;
|
||||||
struct hostent *he;
|
struct hostent *he;
|
||||||
|
@ -185,13 +216,16 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname)
|
||||||
read_cameras (camname, datadir, camera); // search for camera name
|
read_cameras (camname, datadir, camera); // search for camera name
|
||||||
sscanf (camera, "%s %f %f %f %f %s", s, &f, &f, &f, &f, s);
|
sscanf (camera, "%s %f %f %f %f %s", s, &f, &f, &f, &f, s);
|
||||||
// Look for "fix" string to jump over slewing routines.
|
// Look for "fix" string to jump over slewing routines.
|
||||||
if(strstr(s,"ix")==NULL){
|
if (strstr (s, "ix") == NULL)
|
||||||
|
{
|
||||||
|
|
||||||
// Old packet style
|
// Old packet style
|
||||||
// sprintf(packet,"<newNumberVector device='iEQ' name='EQUATORIAL_EOD_COORD_REQUEST'><oneNumber name='RA'>%s</oneNumber><oneNumber name='DEC'>%s</oneNumber></newNumberVector>",sra,sde);
|
// sprintf(packet,"<newNumberVector device='iEQ' name='EQUATORIAL_EOD_COORD_REQUEST'><oneNumber name='RA'>%s</oneNumber><oneNumber name='DEC'>%s</oneNumber></newNumberVector>",sra,sde);
|
||||||
|
|
||||||
// New packet style (as of 2013-08-20)
|
// New packet style (as of 2013-08-20)
|
||||||
sprintf(packet,"<newNumberVector device='iEQ' name='EQUATORIAL_EOD_COORD'><oneNumber name='RA'>%s</oneNumber><oneNumber name='DEC'>%s</oneNumber></newNumberVector>",sra,sde);
|
sprintf (packet,
|
||||||
|
"<newNumberVector device='iEQ' name='EQUATORIAL_EOD_COORD'><oneNumber name='RA'>%s</oneNumber><oneNumber name='DEC'>%s</oneNumber></newNumberVector>",
|
||||||
|
sra, sde);
|
||||||
|
|
||||||
printf ("Slewing to %s %s\n", sra, sde);
|
printf ("Slewing to %s %s\n", sra, sde);
|
||||||
|
|
||||||
|
@ -202,11 +236,15 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname)
|
||||||
addr.sin_port = htons (port);
|
addr.sin_port = htons (port);
|
||||||
he = gethostbyname (IP);
|
he = gethostbyname (IP);
|
||||||
bcopy (he->h_addr, (struct in_addr *) &addr.sin_addr, he->h_length);
|
bcopy (he->h_addr, (struct in_addr *) &addr.sin_addr, he->h_length);
|
||||||
while((connect(skt,(struct sockaddr *) &addr,sizeof(addr))<0) && (port < MAXPORT)) {
|
while ((connect (skt, (struct sockaddr *) &addr, sizeof (addr)) < 0)
|
||||||
fprintf(stderr,"Connection refused by remote host on port %04d.\n",port);
|
&& (port < MAXPORT))
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
"Connection refused by remote host on port %04d.\n", port);
|
||||||
port++;
|
port++;
|
||||||
// Skip port 7265... used by some other service?
|
// Skip port 7265... used by some other service?
|
||||||
if(port==7265) port++;
|
if (port == 7265)
|
||||||
|
port++;
|
||||||
fprintf (stderr, "Trying port %04d.\n", port);
|
fprintf (stderr, "Trying port %04d.\n", port);
|
||||||
|
|
||||||
addr.sin_port = htons (port);
|
addr.sin_port = htons (port);
|
||||||
|
@ -214,7 +252,8 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname)
|
||||||
bcopy (he->h_addr, (struct in_addr *) &addr.sin_addr, he->h_length);
|
bcopy (he->h_addr, (struct in_addr *) &addr.sin_addr, he->h_length);
|
||||||
|
|
||||||
}
|
}
|
||||||
if(port>=MAXPORT) return;
|
if (port >= MAXPORT)
|
||||||
|
return;
|
||||||
|
|
||||||
printf ("Connected to Indi server on port %04d.\n", port);
|
printf ("Connected to Indi server on port %04d.\n", port);
|
||||||
|
|
||||||
|
@ -227,7 +266,8 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname)
|
||||||
// Set restart
|
// Set restart
|
||||||
sprintf (fname, "%s/control/state.txt", obsdir);
|
sprintf (fname, "%s/control/state.txt", obsdir);
|
||||||
file = fopen (fname, "w");
|
file = fopen (fname, "w");
|
||||||
if (file!=NULL) {
|
if (file != NULL)
|
||||||
|
{
|
||||||
fprintf (file, "restart");
|
fprintf (file, "restart");
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +275,8 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname)
|
||||||
// Set position
|
// Set position
|
||||||
sprintf (fname, "%s/control/position.txt", obsdir);
|
sprintf (fname, "%s/control/position.txt", obsdir);
|
||||||
file = fopen (fname, "w");
|
file = fopen (fname, "w");
|
||||||
if (file!=NULL) {
|
if (file != NULL)
|
||||||
|
{
|
||||||
fprintf (file, "%s %s\n", sra, sde);
|
fprintf (file, "%s %s\n", sra, sde);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
|
@ -243,7 +284,8 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname)
|
||||||
// Set camera
|
// Set camera
|
||||||
sprintf (fname, "%s/control/camera.txt", obsdir);
|
sprintf (fname, "%s/control/camera.txt", obsdir);
|
||||||
file = fopen (fname, "w");
|
file = fopen (fname, "w");
|
||||||
if (file!=NULL) {
|
if (file != NULL)
|
||||||
|
{
|
||||||
fprintf (file, "%s", camera);
|
fprintf (file, "%s", camera);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
|
@ -253,7 +295,8 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname)
|
||||||
|
|
||||||
|
|
||||||
// Send stop observation signal
|
// Send stop observation signal
|
||||||
void stop_obs(char *datadir,char *obsdir,char *camname)
|
void
|
||||||
|
stop_obs (char *datadir, char *obsdir, char *camname)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char camera[128], fname[128];
|
char camera[128], fname[128];
|
||||||
|
@ -270,7 +313,8 @@ void stop_obs(char *datadir,char *obsdir,char *camname)
|
||||||
// Set stop
|
// Set stop
|
||||||
sprintf (fname, "%s/control/state.txt", obsdir);
|
sprintf (fname, "%s/control/state.txt", obsdir);
|
||||||
file = fopen (fname, "w");
|
file = fopen (fname, "w");
|
||||||
if (file!=NULL) {
|
if (file != NULL)
|
||||||
|
{
|
||||||
fprintf (file, "stop");
|
fprintf (file, "stop");
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
|
@ -280,14 +324,16 @@ void stop_obs(char *datadir,char *obsdir,char *camname)
|
||||||
|
|
||||||
|
|
||||||
// Decode time
|
// Decode time
|
||||||
time_t decode_time(char *stm)
|
time_t
|
||||||
|
decode_time (char *stm)
|
||||||
{
|
{
|
||||||
time_t aimtime;
|
time_t aimtime;
|
||||||
struct tm *rtm;
|
struct tm *rtm;
|
||||||
int d;
|
int d;
|
||||||
|
|
||||||
rtm = gmtime (&aimtime);
|
rtm = gmtime (&aimtime);
|
||||||
sscanf(stm,"%04d-%02d-%02dT%02d:%02d:%02d",&rtm->tm_year,&rtm->tm_mon,&rtm->tm_mday,&rtm->tm_hour,&rtm->tm_min,&rtm->tm_sec);
|
sscanf (stm, "%04d-%02d-%02dT%02d:%02d:%02d", &rtm->tm_year, &rtm->tm_mon,
|
||||||
|
&rtm->tm_mday, &rtm->tm_hour, &rtm->tm_min, &rtm->tm_sec);
|
||||||
rtm->tm_year -= 1900;
|
rtm->tm_year -= 1900;
|
||||||
rtm->tm_mon--;
|
rtm->tm_mon--;
|
||||||
aimtime = mktime (rtm);
|
aimtime = mktime (rtm);
|
||||||
|
|
132
src/rv2tle.c
132
src/rv2tle.c
|
@ -18,19 +18,22 @@
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
// Dot product
|
// Dot product
|
||||||
float dot(xyz_t a,xyz_t b)
|
float
|
||||||
|
dot (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
double magnitude(xyz_t a)
|
double
|
||||||
|
magnitude (xyz_t a)
|
||||||
{
|
{
|
||||||
return sqrt (dot (a, a));
|
return sqrt (dot (a, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross product
|
// Cross product
|
||||||
xyz_t cross(xyz_t a,xyz_t b)
|
xyz_t
|
||||||
|
cross (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
xyz_t c;
|
xyz_t c;
|
||||||
|
|
||||||
|
@ -42,16 +45,19 @@ xyz_t cross(xyz_t a,xyz_t b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -64,7 +70,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +95,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -98,7 +106,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -106,7 +115,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clasical elements
|
// Clasical elements
|
||||||
orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
orbit_t
|
||||||
|
classel (int ep_year, double ep_day, xyz_t r, xyz_t v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double rm, vm, vm2, rvm, mu = 1.0;;
|
double rm, vm, vm2, rvm, mu = 1.0;;
|
||||||
|
@ -153,7 +163,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
peri += 360.0;
|
peri += 360.0;
|
||||||
|
|
||||||
// Elliptic motion
|
// Elliptic motion
|
||||||
if (ecc<1.0) {
|
if (ecc < 1.0)
|
||||||
|
{
|
||||||
xp = (chi - rm) / ecc;
|
xp = (chi - rm) / ecc;
|
||||||
yp = rvm / ecc * sqrt (chi / mu);
|
yp = rvm / ecc * sqrt (chi / mu);
|
||||||
b = a * sqrt (1.0 - ecc * ecc);
|
b = a * sqrt (1.0 - ecc * ecc);
|
||||||
|
@ -182,7 +193,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
return orb;
|
return orb;
|
||||||
}
|
}
|
||||||
|
|
||||||
orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
orbit_t
|
||||||
|
rv2el (int satno, double mjd, xyz_t r0, xyz_t v0)
|
||||||
{
|
{
|
||||||
int i, imode;
|
int i, imode;
|
||||||
orbit_t orb[5], orb1[5];
|
orbit_t orb[5], orb1[5];
|
||||||
|
@ -199,7 +211,8 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
orb[0] = classel (ep_year, ep_day, r0, v0);
|
orb[0] = classel (ep_year, ep_day, r0, v0);
|
||||||
orb[0].satno = satno;
|
orb[0].satno = satno;
|
||||||
|
|
||||||
for (i=0;i<5;i++) {
|
for (i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
// Propagate
|
// Propagate
|
||||||
imode = init_sgdp4 (&orb[i]);
|
imode = init_sgdp4 (&orb[i]);
|
||||||
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
||||||
|
@ -235,30 +248,44 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.desig,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1, "1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev);
|
orb.satno, orb.desig, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -270,7 +297,8 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -279,18 +307,22 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -298,22 +330,29 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -321,15 +360,19 @@ double nfd2mjd(char *date)
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf("Usage: rv2tle -p XYZFILE [- i NORADID] [-d COSPARID] [-g] [-h]\n\n");
|
printf
|
||||||
|
("Usage: rv2tle -p XYZFILE [- i NORADID] [-d COSPARID] [-g] [-h]\n\n");
|
||||||
printf ("Arguments:\n");
|
printf ("Arguments:\n");
|
||||||
printf ("-p XYZFILE File with cartesian position and velocity vector\n");
|
printf ("-p XYZFILE File with cartesian position and velocity vector\n");
|
||||||
printf (" Format: '{mjd} {x} {y} {z} {vx} {vy} {vz}'\n");
|
printf (" Format: '{mjd} {x} {y} {z} {vx} {vy} {vz}'\n");
|
||||||
printf (" Units: position in km, velocity in km/s\n");
|
printf (" Units: position in km, velocity in km/s\n");
|
||||||
printf("-i NORADID Satellite Catalog Number (NORAD ID), default: 99000\n");
|
printf
|
||||||
printf("-d COSPARID International Designator (COSPAR ID), default: 14999A\n");
|
("-i NORADID Satellite Catalog Number (NORAD ID), default: 99000\n");
|
||||||
|
printf
|
||||||
|
("-d COSPARID International Designator (COSPAR ID), default: 14999A\n");
|
||||||
printf ("-g Use non-standard / GMAT's Modified Julian Date\n");
|
printf ("-g Use non-standard / GMAT's Modified Julian Date\n");
|
||||||
printf ("-h This help\n");
|
printf ("-h This help\n");
|
||||||
|
|
||||||
|
@ -337,7 +380,8 @@ void usage(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -349,7 +393,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int imode, satno = 99000, arg, gmat = 0;
|
int imode, satno = 99000, arg, gmat = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -361,8 +406,10 @@ int main(int argc,char *argv[])
|
||||||
char *env;
|
char *env;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"p:i:d:gh"))!=-1) {
|
while ((arg = getopt (argc, argv, "p:i:d:gh")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
strcpy (xyzfile, optarg);
|
strcpy (xyzfile, optarg);
|
||||||
|
@ -394,8 +441,10 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (xyzfile, "r");
|
file = fopen (xyzfile, "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
sscanf(line,"%lf %lf %lf %lf %lf %lf %lf",&mjd,&r.x,&r.y,&r.z,&v.x,&v.y,&v.z);
|
{
|
||||||
|
sscanf (line, "%lf %lf %lf %lf %lf %lf %lf", &mjd, &r.x, &r.y, &r.z,
|
||||||
|
&v.x, &v.y, &v.z);
|
||||||
|
|
||||||
// Convert to MJD
|
// Convert to MJD
|
||||||
if (gmat == 1)
|
if (gmat == 1)
|
||||||
|
@ -415,4 +464,3 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/s2dec.c
18
src/s2dec.c
|
@ -5,15 +5,18 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
// Usage: s2dec [options] hh:mm:ss.ss
|
// Usage: s2dec [options] hh:mm:ss.ss
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
int sign = 1;
|
int sign = 1;
|
||||||
float deg, min, sec;
|
float deg, min, sec;
|
||||||
char t[20], c;
|
char t[20], c;
|
||||||
|
|
||||||
if (argc==1) {
|
if (argc == 1)
|
||||||
printf("Usage: s2dec -r <hh:mm:ss.sss>\n -or- <ddd:mm:ss.sss>\nCompute sexagesimal from decimal input x.\n");
|
{
|
||||||
|
printf
|
||||||
|
("Usage: s2dec -r <hh:mm:ss.sss>\n -or- <ddd:mm:ss.sss>\nCompute sexagesimal from decimal input x.\n");
|
||||||
printf ("Options: -r Converts hours into degrees\n");
|
printf ("Options: -r Converts hours into degrees\n");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -21,7 +24,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Get Sexagesimal string
|
// Get Sexagesimal string
|
||||||
strcpy (t, argv[--argc]);
|
strcpy (t, argv[--argc]);
|
||||||
if (t[0]=='-') sign=-1;
|
if (t[0] == '-')
|
||||||
|
sign = -1;
|
||||||
|
|
||||||
deg = fabs (atof (strtok (t, " :,")));
|
deg = fabs (atof (strtok (t, " :,")));
|
||||||
min = fabs (atof (strtok (NULL, " :,")));
|
min = fabs (atof (strtok (NULL, " :,")));
|
||||||
|
@ -30,8 +34,10 @@ int main(int argc,char *argv[])
|
||||||
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
||||||
|
|
||||||
// Get Options
|
// Get Options
|
||||||
while (--argc > 0 && (*++argv)[0] == '-') {
|
while (--argc > 0 && (*++argv)[0] == '-')
|
||||||
while (c = *++argv[0]) {
|
{
|
||||||
|
while (c = *++argv[0])
|
||||||
|
{
|
||||||
if (c == 'r')
|
if (c == 'r')
|
||||||
x *= 15.;
|
x *= 15.;
|
||||||
}
|
}
|
||||||
|
|
736
src/satfit.c
736
src/satfit.c
File diff suppressed because it is too large
Load Diff
211
src/satid.c
211
src/satid.c
|
@ -20,18 +20,21 @@ long Isat=0;
|
||||||
long Isatsel = 0;
|
long Isatsel = 0;
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
double lat, lng;
|
double lat, lng;
|
||||||
float alt;
|
float alt;
|
||||||
char observer[32];
|
char observer[32];
|
||||||
int site_id;
|
int site_id;
|
||||||
} m;
|
} m;
|
||||||
struct point {
|
struct point
|
||||||
|
{
|
||||||
double mjd;
|
double mjd;
|
||||||
xyz_t obspos, sunpos;
|
xyz_t obspos, sunpos;
|
||||||
double zeta, z, theta;
|
double zeta, z, theta;
|
||||||
} p[MMAX];
|
} p[MMAX];
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
char filename[64];
|
char filename[64];
|
||||||
int naxis, naxis1, naxis2, nframes;
|
int naxis, naxis1, naxis2, nframes;
|
||||||
float *zavg, *zstd, *zmax, *znum;
|
float *zavg, *zstd, *zmax, *znum;
|
||||||
|
@ -50,13 +53,18 @@ void obspos_xyz(double,xyz_t *,xyz_t *);
|
||||||
void sunpos_xyz (double, xyz_t *);
|
void sunpos_xyz (double, xyz_t *);
|
||||||
double gmst (double);
|
double gmst (double);
|
||||||
double dgmst (double);
|
double dgmst (double);
|
||||||
void precession_angles(double mjd0,double mjd,double *zeta,double *z,double *theta);
|
void precession_angles (double mjd0, double mjd, double *zeta, double *z,
|
||||||
|
double *theta);
|
||||||
void initialize (struct image img);
|
void initialize (struct image img);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de);
|
double *y);
|
||||||
|
void reverse (double ra0, double de0, double x, double y, double *ra,
|
||||||
|
double *de);
|
||||||
struct sat apparent_position (double mjd);
|
struct sat apparent_position (double mjd);
|
||||||
|
|
||||||
void plot_satellites(char *tlefile,struct image img,long satno,double mjd0,float dt,int color)
|
void
|
||||||
|
plot_satellites (char *tlefile, struct image img, long satno, double mjd0,
|
||||||
|
float dt, int color)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
orbit_t orb;
|
orbit_t orb;
|
||||||
|
@ -89,7 +97,8 @@ void plot_satellites(char *tlefile,struct image img,long satno,double mjd0,float
|
||||||
file = fopen (filename, "a");
|
file = fopen (filename, "a");
|
||||||
|
|
||||||
// Read TLEs
|
// Read TLEs
|
||||||
while (read_twoline(fp,satno,&orb)==0) {
|
while (read_twoline (fp, satno, &orb) == 0)
|
||||||
|
{
|
||||||
Isat = orb.satno;
|
Isat = orb.satno;
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
|
|
||||||
|
@ -99,12 +108,15 @@ void plot_satellites(char *tlefile,struct image img,long satno,double mjd0,float
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Loop over times
|
// Loop over times
|
||||||
for (flag=0,textflag=0,sflag=0,i=0;i<MMAX;i++) {
|
for (flag = 0, textflag = 0, sflag = 0, i = 0; i < MMAX; i++)
|
||||||
|
{
|
||||||
// Satellite position
|
// Satellite position
|
||||||
satpos_xyz (p[i].mjd + 2400000.5, &satpos, &satvel);
|
satpos_xyz (p[i].mjd + 2400000.5, &satpos, &satvel);
|
||||||
|
|
||||||
// Check on radius
|
// Check on radius
|
||||||
r=sqrt(satpos.x*satpos.x+satpos.y*satpos.y+satpos.z*satpos.z);
|
r =
|
||||||
|
sqrt (satpos.x * satpos.x + satpos.y * satpos.y +
|
||||||
|
satpos.z * satpos.z);
|
||||||
if (r > 300000)
|
if (r > 300000)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -121,17 +133,25 @@ void plot_satellites(char *tlefile,struct image img,long satno,double mjd0,float
|
||||||
|
|
||||||
// Correct for precession
|
// Correct for precession
|
||||||
a = cos (de) * sin (ra + p[i].zeta);
|
a = cos (de) * sin (ra + p[i].zeta);
|
||||||
b=cos(p[i].theta)*cos(de)*cos(ra+p[i].zeta)-sin(p[i].theta)*sin(de);
|
b =
|
||||||
c=sin(p[i].theta)*cos(de)*cos(ra+p[i].zeta)+cos(p[i].theta)*sin(de);
|
cos (p[i].theta) * cos (de) * cos (ra + p[i].zeta) -
|
||||||
|
sin (p[i].theta) * sin (de);
|
||||||
|
c =
|
||||||
|
sin (p[i].theta) * cos (de) * cos (ra + p[i].zeta) +
|
||||||
|
cos (p[i].theta) * sin (de);
|
||||||
ra = modulo ((atan2 (a, b) + p[i].z) * R2D, 360.0);
|
ra = modulo ((atan2 (a, b) + p[i].z) * R2D, 360.0);
|
||||||
de = asin (c) * R2D;
|
de = asin (c) * R2D;
|
||||||
|
|
||||||
// Adjust for stationary camera
|
// Adjust for stationary camera
|
||||||
if (img.tracked == 0)
|
if (img.tracked == 0)
|
||||||
ra+=gmst(img.mjd+0.5*img.exptime/86400.0)-gmst(p[i].mjd);
|
ra +=
|
||||||
|
gmst (img.mjd + 0.5 * img.exptime / 86400.0) - gmst (p[i].mjd);
|
||||||
|
|
||||||
// Check if nearby enough
|
// Check if nearby enough
|
||||||
r=acos(sin(img.de0*D2R)*sin(de*D2R)+cos(img.de0*D2R)*cos(de*D2R)*cos((img.ra0-ra)*D2R))*R2D;
|
r =
|
||||||
|
acos (sin (img.de0 * D2R) * sin (de * D2R) +
|
||||||
|
cos (img.de0 * D2R) * cos (de * D2R) * cos ((img.ra0 - ra) *
|
||||||
|
D2R)) * R2D;
|
||||||
if (r < 90.0)
|
if (r < 90.0)
|
||||||
forward (img.ra0, img.de0, ra, de, &rx, &ry);
|
forward (img.ra0, img.de0, ra, de, &rx, &ry);
|
||||||
else
|
else
|
||||||
|
@ -144,22 +164,31 @@ void plot_satellites(char *tlefile,struct image img,long satno,double mjd0,float
|
||||||
|
|
||||||
// Distances
|
// Distances
|
||||||
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
||||||
rearth=sqrt(satpos.x*satpos.x+satpos.y*satpos.y+satpos.z*satpos.z);
|
rearth =
|
||||||
|
sqrt (satpos.x * satpos.x + satpos.y * satpos.y +
|
||||||
|
satpos.z * satpos.z);
|
||||||
|
|
||||||
// Angles
|
// Angles
|
||||||
psun = asin (696.0e3 / rsun) * R2D;
|
psun = asin (696.0e3 / rsun) * R2D;
|
||||||
pearth = asin (6378.135 / rearth) * R2D;
|
pearth = asin (6378.135 / rearth) * R2D;
|
||||||
ptot=acos((-dx*satpos.x-dy*satpos.y-dz*satpos.z)/(rsun*rearth))*R2D;
|
ptot =
|
||||||
|
acos ((-dx * satpos.x - dy * satpos.y -
|
||||||
|
dz * satpos.z) / (rsun * rearth)) * R2D;
|
||||||
|
|
||||||
// Visibility state
|
// Visibility state
|
||||||
if (ptot-pearth<-psun) {
|
if (ptot - pearth < -psun)
|
||||||
|
{
|
||||||
cpgsls (4);
|
cpgsls (4);
|
||||||
strcpy (state, "eclipsed");
|
strcpy (state, "eclipsed");
|
||||||
} else if (ptot-pearth>-psun && ptot-pearth<psun) {
|
}
|
||||||
|
else if (ptot - pearth > -psun && ptot - pearth < psun)
|
||||||
|
{
|
||||||
cpgsls (2);
|
cpgsls (2);
|
||||||
strcpy (state, "umbra");
|
strcpy (state, "umbra");
|
||||||
sflag = 1;
|
sflag = 1;
|
||||||
} else if (ptot-pearth>psun) {
|
}
|
||||||
|
else if (ptot - pearth > psun)
|
||||||
|
{
|
||||||
cpgsls (1);
|
cpgsls (1);
|
||||||
strcpy (state, "sunlit");
|
strcpy (state, "sunlit");
|
||||||
sflag = 1;
|
sflag = 1;
|
||||||
|
@ -172,7 +201,9 @@ void plot_satellites(char *tlefile,struct image img,long satno,double mjd0,float
|
||||||
y = (img.a[1] * dy - img.b[1] * dx) / d + img.y0;
|
y = (img.a[1] * dy - img.b[1] * dx) / d + img.y0;
|
||||||
|
|
||||||
// Print name if in viewport
|
// Print name if in viewport
|
||||||
if (x>0.0 && x<img.naxis1 && y>0.0 && y<img.naxis2 && textflag==0) {
|
if (x > 0.0 && x < img.naxis1 && y > 0.0 && y < img.naxis2
|
||||||
|
&& textflag == 0)
|
||||||
|
{
|
||||||
if (flag != 0)
|
if (flag != 0)
|
||||||
cpgdraw (x, y);
|
cpgdraw (x, y);
|
||||||
cpgsch (0.65);
|
cpgsch (0.65);
|
||||||
|
@ -181,25 +212,34 @@ void plot_satellites(char *tlefile,struct image img,long satno,double mjd0,float
|
||||||
cpgmove (x, y);
|
cpgmove (x, y);
|
||||||
textflag = 1;
|
textflag = 1;
|
||||||
}
|
}
|
||||||
if (i==0) {
|
if (i == 0)
|
||||||
|
{
|
||||||
x0 = x;
|
x0 = x;
|
||||||
y0 = y;
|
y0 = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plot satellites
|
// Plot satellites
|
||||||
if (flag==0) {
|
if (flag == 0)
|
||||||
|
{
|
||||||
cpgpt1 (x, y, 17);
|
cpgpt1 (x, y, 17);
|
||||||
cpgmove (x, y);
|
cpgmove (x, y);
|
||||||
flag = 1;
|
flag = 1;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
cpgdraw (x, y);
|
cpgdraw (x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (textflag==1) {
|
if (textflag == 1)
|
||||||
|
{
|
||||||
if (sflag == 0)
|
if (sflag == 0)
|
||||||
fprintf(file,"%.23s %8.3f %8.3f %8.3f %8.3f %8.5f %s %s eclipsed\n",img.nfd+1,x0,y0,x,y,img.exptime,norad,tlefile);
|
fprintf (file,
|
||||||
|
"%.23s %8.3f %8.3f %8.3f %8.3f %8.5f %s %s eclipsed\n",
|
||||||
|
img.nfd + 1, x0, y0, x, y, img.exptime, norad, tlefile);
|
||||||
else
|
else
|
||||||
fprintf(file,"%.23s %8.3f %8.3f %8.3f %8.3f %8.5f %s %s sunlit\n",img.nfd+1,x0,y0,x,y,img.exptime,norad,tlefile);
|
fprintf (file,
|
||||||
|
"%.23s %8.3f %8.3f %8.3f %8.3f %8.5f %s %s sunlit\n",
|
||||||
|
img.nfd + 1, x0, y0, x, y, img.exptime, norad, tlefile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
@ -210,7 +250,8 @@ void plot_satellites(char *tlefile,struct image img,long satno,double mjd0,float
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct image img;
|
struct image img;
|
||||||
|
@ -234,7 +275,8 @@ int main(int argc,char *argv[])
|
||||||
initialize (img);
|
initialize (img);
|
||||||
|
|
||||||
// Fill buffer
|
// Fill buffer
|
||||||
if (img.naxis==3) {
|
if (img.naxis == 3)
|
||||||
|
{
|
||||||
for (i = 0, zavg = 0.0; i < img.naxis1 * img.naxis2; i++)
|
for (i = 0, zavg = 0.0; i < img.naxis1 * img.naxis2; i++)
|
||||||
zavg += img.zmax[i];
|
zavg += img.zmax[i];
|
||||||
zavg /= (float) img.naxis1 * img.naxis2;
|
zavg /= (float) img.naxis1 * img.naxis2;
|
||||||
|
@ -243,7 +285,9 @@ int main(int argc,char *argv[])
|
||||||
zstd = sqrt (zstd / (float) (img.naxis1 * img.naxis2));
|
zstd = sqrt (zstd / (float) (img.naxis1 * img.naxis2));
|
||||||
zmin = zavg - 2 * zstd;
|
zmin = zavg - 2 * zstd;
|
||||||
zmax = zavg + 6 * zstd;
|
zmax = zavg + 6 * zstd;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (i = 0, zavg = 0.0; i < img.naxis1 * img.naxis2; i++)
|
for (i = 0, zavg = 0.0; i < img.naxis1 * img.naxis2; i++)
|
||||||
zavg += img.zavg[i];
|
zavg += img.zavg[i];
|
||||||
zavg /= (float) img.naxis1 * img.naxis2;
|
zavg /= (float) img.naxis1 * img.naxis2;
|
||||||
|
@ -270,8 +314,10 @@ int main(int argc,char *argv[])
|
||||||
cpgsch (0.8);
|
cpgsch (0.8);
|
||||||
sprintf (text, "UT Date: %.23s COSPAR ID: %04d", img.nfd + 1, img.cospar);
|
sprintf (text, "UT Date: %.23s COSPAR ID: %04d", img.nfd + 1, img.cospar);
|
||||||
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
cpgmtxt ("T", 6.0, 0.0, 0.0, text);
|
||||||
sprintf(text,"R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')",img.ra0,img.xrms,img.de0,img.yrms);
|
sprintf (text, "R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')", img.ra0,
|
||||||
if (img.xrms<1e-3 || img.yrms<1e-3 || img.xrms/sx>2.0 || img.yrms/sy>2.0)
|
img.xrms, img.de0, img.yrms);
|
||||||
|
if (img.xrms < 1e-3 || img.yrms < 1e-3 || img.xrms / sx > 2.0
|
||||||
|
|| img.yrms / sy > 2.0)
|
||||||
cpgsci (2);
|
cpgsci (2);
|
||||||
else
|
else
|
||||||
cpgsci (1);
|
cpgsci (1);
|
||||||
|
@ -279,7 +325,9 @@ int main(int argc,char *argv[])
|
||||||
cpgsci (1);
|
cpgsci (1);
|
||||||
|
|
||||||
|
|
||||||
sprintf(text,"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d",wx,wy,sx,sy);
|
sprintf (text,
|
||||||
|
"FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d",
|
||||||
|
wx, wy, sx, sy);
|
||||||
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
cpgmtxt ("T", 3.6, 0.0, 0.0, text);
|
||||||
sprintf (text, "Stat: %5.1f+-%.1f (%.1f-%.1f)", zavg, zstd, zmin, zmax);
|
sprintf (text, "Stat: %5.1f+-%.1f (%.1f-%.1f)", zavg, zstd, zmin, zmax);
|
||||||
cpgmtxt ("T", 2.4, 0.0, 0.0, text);
|
cpgmtxt ("T", 2.4, 0.0, 0.0, text);
|
||||||
|
@ -291,9 +339,11 @@ int main(int argc,char *argv[])
|
||||||
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
cpgctab (heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5);
|
||||||
|
|
||||||
if (img.naxis == 3)
|
if (img.naxis == 3)
|
||||||
cpgimag(img.zmax,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,zmin,zmax,tr);
|
cpgimag (img.zmax, img.naxis1, img.naxis2, 1, img.naxis1, 1, img.naxis2,
|
||||||
|
zmin, zmax, tr);
|
||||||
else
|
else
|
||||||
cpgimag(img.zavg,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,zmin,zmax,tr);
|
cpgimag (img.zavg, img.naxis1, img.naxis2, 1, img.naxis1, 1, img.naxis2,
|
||||||
|
zmin, zmax, tr);
|
||||||
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
cpgbox ("BCTSNI", 0., 0, "BCTSNI", 0., 0);
|
||||||
|
|
||||||
cpgstbg (1);
|
cpgstbg (1);
|
||||||
|
@ -316,7 +366,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename)
|
struct image
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -366,13 +417,15 @@ struct image read_fits(char *filename)
|
||||||
ql.filename = filename;
|
ql.filename = filename;
|
||||||
|
|
||||||
// Read four-frame info
|
// Read four-frame info
|
||||||
if (img.naxis==3) {
|
if (img.naxis == 3)
|
||||||
|
{
|
||||||
// Number of frames
|
// Number of frames
|
||||||
img.nframes = atoi (qfits_query_hdr (filename, "NFRAMES"));
|
img.nframes = atoi (qfits_query_hdr (filename, "NFRAMES"));
|
||||||
|
|
||||||
// Timestamps
|
// Timestamps
|
||||||
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
||||||
for (i=0;i<img.nframes;i++) {
|
for (i = 0; i < img.nframes; i++)
|
||||||
|
{
|
||||||
sprintf (key, "DT%04d", i);
|
sprintf (key, "DT%04d", i);
|
||||||
strcpy (val, qfits_query_hdr (filename, key));
|
strcpy (val, qfits_query_hdr (filename, key));
|
||||||
sscanf (val + 1, "%f", &img.dt[i]);
|
sscanf (val + 1, "%f", &img.dt[i]);
|
||||||
|
@ -386,7 +439,8 @@ struct image read_fits(char *filename)
|
||||||
img.znum = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
img.znum = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
||||||
|
|
||||||
// Loop over planes
|
// Loop over planes
|
||||||
for (k=0;k<4;k++) {
|
for (k = 0; k < 4; k++)
|
||||||
|
{
|
||||||
ql.pnum = k;
|
ql.pnum = k;
|
||||||
|
|
||||||
// Initialize load
|
// Initialize load
|
||||||
|
@ -398,17 +452,25 @@ struct image read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
if (k==0) img.zavg[l]=ql.fbuf[l];
|
for (j = 0; j < img.naxis2; j++)
|
||||||
if (k==1) img.zstd[l]=ql.fbuf[l];
|
{
|
||||||
if (k==2) img.zmax[l]=ql.fbuf[l];
|
if (k == 0)
|
||||||
if (k==3) img.znum[l]=ql.fbuf[l];
|
img.zavg[l] = ql.fbuf[l];
|
||||||
|
if (k == 1)
|
||||||
|
img.zstd[l] = ql.fbuf[l];
|
||||||
|
if (k == 2)
|
||||||
|
img.zmax[l] = ql.fbuf[l];
|
||||||
|
if (k == 3)
|
||||||
|
img.znum[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Allocate image memory
|
// Allocate image memory
|
||||||
img.zavg = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
img.zavg = (float *) malloc (sizeof (float) * img.naxis1 * img.naxis2);
|
||||||
|
|
||||||
|
@ -423,8 +485,10 @@ struct image read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
img.zavg[l] = ql.fbuf[l];
|
img.zavg[l] = ql.fbuf[l];
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
|
@ -435,7 +499,8 @@ struct image read_fits(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -448,11 +513,13 @@ void get_site(int site_id)
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
sprintf (filename, "%s/data/sites.txt", env);
|
sprintf (filename, "%s/data/sites.txt", env);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -461,14 +528,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
@ -483,19 +550,23 @@ void get_site(int site_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double dgmst(double mjd)
|
double
|
||||||
|
dgmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, dgmst;
|
double t, dgmst;
|
||||||
|
|
||||||
|
@ -507,16 +578,19 @@ double dgmst(double mjd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observer position
|
// Observer position
|
||||||
void obspos_xyz(double mjd,xyz_t *pos,xyz_t *vel)
|
void
|
||||||
|
obspos_xyz (double mjd, xyz_t * pos, xyz_t * vel)
|
||||||
{
|
{
|
||||||
double ff, gc, gs, theta, s, dtheta;
|
double ff, gc, gs, theta, s, dtheta;
|
||||||
|
|
||||||
|
@ -539,7 +613,8 @@ void obspos_xyz(double mjd,xyz_t *pos,xyz_t *vel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Solar position
|
// Solar position
|
||||||
void sunpos_xyz(double mjd,xyz_t *pos)
|
void
|
||||||
|
sunpos_xyz (double mjd, xyz_t * pos)
|
||||||
{
|
{
|
||||||
double jd, t, l0, m, e, c, r;
|
double jd, t, l0, m, e, c, r;
|
||||||
double n, s, ecl, ra, de;
|
double n, s, ecl, ra, de;
|
||||||
|
@ -556,7 +631,10 @@ void sunpos_xyz(double mjd,xyz_t *pos)
|
||||||
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
||||||
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
||||||
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
||||||
ecl=(23.43929111+(-46.8150*t-0.00059*t*t+0.001813*t*t*t)/3600.0+0.00256*cos(n))*D2R;
|
ecl =
|
||||||
|
(23.43929111 +
|
||||||
|
(-46.8150 * t - 0.00059 * t * t + 0.001813 * t * t * t) / 3600.0 +
|
||||||
|
0.00256 * cos (n)) * D2R;
|
||||||
|
|
||||||
ra = atan2 (cos (ecl) * sin (s), cos (s));
|
ra = atan2 (cos (ecl) * sin (s), cos (s));
|
||||||
de = asin (sin (ecl) * sin (s));
|
de = asin (sin (ecl) * sin (s));
|
||||||
|
@ -569,7 +647,9 @@ void sunpos_xyz(double mjd,xyz_t *pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute precession angles
|
// Compute precession angles
|
||||||
void precession_angles(double mjd0,double mjd,double *zeta,double *z,double *theta)
|
void
|
||||||
|
precession_angles (double mjd0, double mjd, double *zeta, double *z,
|
||||||
|
double *theta)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
|
|
||||||
|
@ -592,14 +672,16 @@ void precession_angles(double mjd0,double mjd,double *zeta,double *z,double *the
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize observer and sun position and precession angles
|
// Initialize observer and sun position and precession angles
|
||||||
void initialize(struct image img)
|
void
|
||||||
|
initialize (struct image img)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double t;
|
double t;
|
||||||
xyz_t obsvel;
|
xyz_t obsvel;
|
||||||
|
|
||||||
// Loop over points
|
// Loop over points
|
||||||
for (i=0;i<MMAX;i++) {
|
for (i = 0; i < MMAX; i++)
|
||||||
|
{
|
||||||
// Compute time
|
// Compute time
|
||||||
t = img.exptime * (float) i / (float) (MMAX - 1);
|
t = img.exptime * (float) i / (float) (MMAX - 1);
|
||||||
p[i].mjd = img.mjd + t / 86400.0;
|
p[i].mjd = img.mjd + t / 86400.0;
|
||||||
|
@ -614,4 +696,3 @@ void initialize(struct image img)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
306
src/satmap.c
306
src/satmap.c
|
@ -21,7 +21,8 @@ long Isat=0;
|
||||||
long Isatsel = 0;
|
long Isatsel = 0;
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
long satno;
|
long satno;
|
||||||
double lat, lng;
|
double lat, lng;
|
||||||
double mjd;
|
double mjd;
|
||||||
|
@ -32,11 +33,13 @@ struct map {
|
||||||
int site_id;
|
int site_id;
|
||||||
float l0, b0;
|
float l0, b0;
|
||||||
} m;
|
} m;
|
||||||
struct globe {
|
struct globe
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
float l[MMAX], b[MMAX];
|
float l[MMAX], b[MMAX];
|
||||||
} glb;
|
} glb;
|
||||||
struct sat {
|
struct sat
|
||||||
|
{
|
||||||
long Isat;
|
long Isat;
|
||||||
double jd;
|
double jd;
|
||||||
double dx, dy, dz;
|
double dx, dy, dz;
|
||||||
|
@ -63,7 +66,8 @@ void sunpos_xyz(double,xyz_t *,double *,double *);
|
||||||
void rotate (int axis, float angle, float *x, float *y, float *z);
|
void rotate (int axis, float angle, float *x, float *y, float *z);
|
||||||
void get_site (int site_id);
|
void get_site (int site_id);
|
||||||
|
|
||||||
void plot_terminator(void)
|
void
|
||||||
|
plot_terminator (void)
|
||||||
{
|
{
|
||||||
int i, j, j0, k, flag;
|
int i, j, j0, k, flag;
|
||||||
xyz_t sunpos;
|
xyz_t sunpos;
|
||||||
|
@ -86,8 +90,10 @@ void plot_terminator(void)
|
||||||
l0 -= 360.0;
|
l0 -= 360.0;
|
||||||
|
|
||||||
// Loop over terminator boundaries
|
// Loop over terminator boundaries
|
||||||
for (k=0;k<4;k++) {
|
for (k = 0; k < 4; k++)
|
||||||
for (i=0,j=0,flag=0;i<NMAX;i++,j++) {
|
{
|
||||||
|
for (i = 0, j = 0, flag = 0; i < NMAX; i++, j++)
|
||||||
|
{
|
||||||
theta = 2.0 * M_PI * (float) i / (float) (NMAX - 1);
|
theta = 2.0 * M_PI * (float) i / (float) (NMAX - 1);
|
||||||
|
|
||||||
x = XKMPER * sin (ang[k] * D2R);
|
x = XKMPER * sin (ang[k] * D2R);
|
||||||
|
@ -107,26 +113,34 @@ void plot_terminator(void)
|
||||||
l[j] += 360.0;
|
l[j] += 360.0;
|
||||||
|
|
||||||
// Passing limit left to right
|
// Passing limit left to right
|
||||||
if (l[j]*l[j-1]<0.0 && fabs(l[j])>45.0 && flag==0 && k==0) {
|
if (l[j] * l[j - 1] < 0.0 && fabs (l[j]) > 45.0 && flag == 0
|
||||||
|
&& k == 0)
|
||||||
|
{
|
||||||
l[j + 4] = l[j];
|
l[j + 4] = l[j];
|
||||||
b[j + 4] = b[j];
|
b[j + 4] = b[j];
|
||||||
b[j] = b[j - 1];
|
b[j] = b[j - 1];
|
||||||
b[j + 3] = b[j - 1];
|
b[j + 3] = b[j - 1];
|
||||||
if (l[j-1]<l[j]) {
|
if (l[j - 1] < l[j])
|
||||||
|
{
|
||||||
l[j] = -180.0;
|
l[j] = -180.0;
|
||||||
l[j + 1] = -180.0;
|
l[j + 1] = -180.0;
|
||||||
l[j + 2] = 180.0;
|
l[j + 2] = 180.0;
|
||||||
l[j + 3] = 180.0;
|
l[j + 3] = 180.0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
l[j] = 180.0;
|
l[j] = 180.0;
|
||||||
l[j + 1] = 180.0;
|
l[j + 1] = 180.0;
|
||||||
l[j + 2] = -180.0;
|
l[j + 2] = -180.0;
|
||||||
l[j + 3] = -180.0;
|
l[j + 3] = -180.0;
|
||||||
}
|
}
|
||||||
if (b0<=0.0) {
|
if (b0 <= 0.0)
|
||||||
|
{
|
||||||
b[j + 1] = 90.0;
|
b[j + 1] = 90.0;
|
||||||
b[j + 2] = 90.0;
|
b[j + 2] = 90.0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
b[j + 1] = -90.0;
|
b[j + 1] = -90.0;
|
||||||
b[j + 2] = -90.0;
|
b[j + 2] = -90.0;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +149,8 @@ void plot_terminator(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k==0) {
|
if (k == 0)
|
||||||
|
{
|
||||||
// Set night color
|
// Set night color
|
||||||
cpgscr (16, 0.0, 0.0, 0.2);
|
cpgscr (16, 0.0, 0.0, 0.2);
|
||||||
|
|
||||||
|
@ -147,17 +162,24 @@ void plot_terminator(void)
|
||||||
cpgsci (14);
|
cpgsci (14);
|
||||||
cpgline (NMAX + 4, l, b);
|
cpgline (NMAX + 4, l, b);
|
||||||
cpgsci (1);
|
cpgsci (1);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Plot twilight boundaries
|
// Plot twilight boundaries
|
||||||
cpgsci (14);
|
cpgsci (14);
|
||||||
for (i=0,flag=0;i<NMAX;i++) {
|
for (i = 0, flag = 0; i < NMAX; i++)
|
||||||
if (i>0 && l[i-1]*l[i]<0.0 && fabs(l[i-1]-l[i])>10.0)
|
{
|
||||||
|
if (i > 0 && l[i - 1] * l[i] < 0.0
|
||||||
|
&& fabs (l[i - 1] - l[i]) > 10.0)
|
||||||
flag = 0;
|
flag = 0;
|
||||||
|
|
||||||
if (flag==0) {
|
if (flag == 0)
|
||||||
|
{
|
||||||
cpgmove (l[i], b[i]);
|
cpgmove (l[i], b[i]);
|
||||||
flag = 1;
|
flag = 1;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
cpgdraw (l[i], b[i]);
|
cpgdraw (l[i], b[i]);
|
||||||
cpgmove (l[i], b[i]);
|
cpgmove (l[i], b[i]);
|
||||||
}
|
}
|
||||||
|
@ -173,7 +195,8 @@ void plot_terminator(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_plot(char *psfile,float width,float aspect)
|
void
|
||||||
|
init_plot (char *psfile, float width, float aspect)
|
||||||
{
|
{
|
||||||
|
|
||||||
cpgslw (2);
|
cpgslw (2);
|
||||||
|
@ -182,7 +205,8 @@ void init_plot(char *psfile,float width,float aspect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plot observing sites
|
// Plot observing sites
|
||||||
void plot_sites(void)
|
void
|
||||||
|
plot_sites (void)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -197,11 +221,13 @@ void plot_sites(void)
|
||||||
|
|
||||||
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -210,8 +236,7 @@ void plot_sites(void)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
sprintf (text, " %04d", id);
|
sprintf (text, " %04d", id);
|
||||||
|
@ -228,7 +253,8 @@ void plot_sites(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plot observing sites
|
// Plot observing sites
|
||||||
void plot_launch_sites(void)
|
void
|
||||||
|
plot_launch_sites (void)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -241,11 +267,13 @@ void plot_launch_sites(void)
|
||||||
|
|
||||||
sprintf (filename, "%s/data/launchsites.txt", m.datadir);
|
sprintf (filename, "%s/data/launchsites.txt", m.datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -254,8 +282,7 @@ void plot_launch_sites(void)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%lf %lf",
|
sscanf (line, "%lf %lf", &lat, &lng);
|
||||||
&lat,&lng);
|
|
||||||
strcpy (site, line + 21);
|
strcpy (site, line + 21);
|
||||||
|
|
||||||
cpgsci (2);
|
cpgsci (2);
|
||||||
|
@ -272,7 +299,8 @@ void plot_launch_sites(void)
|
||||||
|
|
||||||
|
|
||||||
// Computes apparent position
|
// Computes apparent position
|
||||||
struct sat apparent_position(double mjd)
|
struct sat
|
||||||
|
apparent_position (double mjd)
|
||||||
{
|
{
|
||||||
struct sat s;
|
struct sat s;
|
||||||
double jd, rsun, rearth;
|
double jd, rsun, rearth;
|
||||||
|
@ -305,17 +333,21 @@ struct sat apparent_position(double mjd)
|
||||||
|
|
||||||
// Distances
|
// Distances
|
||||||
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
rsun = sqrt (dx * dx + dy * dy + dz * dz);
|
||||||
rearth=sqrt(satpos.x*satpos.x+satpos.y*satpos.y+satpos.z*satpos.z);
|
rearth =
|
||||||
|
sqrt (satpos.x * satpos.x + satpos.y * satpos.y + satpos.z * satpos.z);
|
||||||
// Angles
|
// Angles
|
||||||
s.psun = asin (696.0e3 / rsun) * R2D;
|
s.psun = asin (696.0e3 / rsun) * R2D;
|
||||||
s.pearth = asin (6378.135 / rearth) * R2D;
|
s.pearth = asin (6378.135 / rearth) * R2D;
|
||||||
s.p=acos((-dx*satpos.x-dy*satpos.y-dz*satpos.z)/(rsun*rearth))*R2D;
|
s.p =
|
||||||
|
acos ((-dx * satpos.x - dy * satpos.y -
|
||||||
|
dz * satpos.z) / (rsun * rearth)) * R2D;
|
||||||
// s.p=acos(((sunpos.x+satpos.x)*satpos.x+(sunpos.y+satpos.y)*satpos.y+(sunpos.z+satpos.z)*satpos.z)/(rsun*rearth))*R2D;
|
// s.p=acos(((sunpos.x+satpos.x)*satpos.x+(sunpos.y+satpos.y)*satpos.y+(sunpos.z+satpos.z)*satpos.z)/(rsun*rearth))*R2D;
|
||||||
|
|
||||||
s.p -= s.pearth;
|
s.p -= s.pearth;
|
||||||
|
|
||||||
// Celestial position
|
// Celestial position
|
||||||
s.r=sqrt(satpos.x*satpos.x+satpos.y*satpos.y+satpos.z*satpos.z);
|
s.r =
|
||||||
|
sqrt (satpos.x * satpos.x + satpos.y * satpos.y + satpos.z * satpos.z);
|
||||||
s.ra = atan2 (satpos.y, satpos.x) * R2D;
|
s.ra = atan2 (satpos.y, satpos.x) * R2D;
|
||||||
s.de = asin (satpos.z / s.r) * R2D;
|
s.de = asin (satpos.z / s.r) * R2D;
|
||||||
|
|
||||||
|
@ -323,7 +355,8 @@ struct sat apparent_position(double mjd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// plot satellite track
|
// plot satellite track
|
||||||
void track_plot_track(char *tlefile,long satno,double mjd0)
|
void
|
||||||
|
track_plot_track (char *tlefile, long satno, double mjd0)
|
||||||
{
|
{
|
||||||
int i = 0, nstep = 500;
|
int i = 0, nstep = 500;
|
||||||
orbit_t orb;
|
orbit_t orb;
|
||||||
|
@ -342,20 +375,24 @@ void track_plot_track(char *tlefile,long satno,double mjd0)
|
||||||
cpgsci (7);
|
cpgsci (7);
|
||||||
|
|
||||||
fp = fopen (tlefile, "rb");
|
fp = fopen (tlefile, "rb");
|
||||||
if(fp == NULL) {
|
if (fp == NULL)
|
||||||
|
{
|
||||||
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(read_twoline(fp, satno, &orb) == 0) {
|
while (read_twoline (fp, satno, &orb) == 0)
|
||||||
|
{
|
||||||
// print_orb(&orb);
|
// print_orb(&orb);
|
||||||
|
|
||||||
Isat = orb.satno;
|
Isat = orb.satno;
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
|
|
||||||
if(imode == SGDP4_ERROR) continue;
|
if (imode == SGDP4_ERROR)
|
||||||
|
continue;
|
||||||
|
|
||||||
jd = mjd0 + 2400000.5;
|
jd = mjd0 + 2400000.5;
|
||||||
for (i=0;;i++) {
|
for (i = 0;; i++)
|
||||||
|
{
|
||||||
// if(satpos_xyz(jd, &pos, &vel) == SGDP4_ERROR) break;
|
// if(satpos_xyz(jd, &pos, &vel) == SGDP4_ERROR) break;
|
||||||
mjd = jd - 2400000.5;
|
mjd = jd - 2400000.5;
|
||||||
s = apparent_position (mjd);
|
s = apparent_position (mjd);
|
||||||
|
@ -386,7 +423,8 @@ void track_plot_track(char *tlefile,long satno,double mjd0)
|
||||||
cpgsci (7);
|
cpgsci (7);
|
||||||
|
|
||||||
// Plot
|
// Plot
|
||||||
if (i==0) {
|
if (i == 0)
|
||||||
|
{
|
||||||
sprintf (norad, " %ld", Isat);
|
sprintf (norad, " %ld", Isat);
|
||||||
cpgsch (0.6);
|
cpgsch (0.6);
|
||||||
cpgtext (l, b, norad);
|
cpgtext (l, b, norad);
|
||||||
|
@ -418,17 +456,21 @@ void track_plot_track(char *tlefile,long satno,double mjd0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plot_map(void)
|
void
|
||||||
|
plot_map (void)
|
||||||
{
|
{
|
||||||
int redraw = 1;
|
int redraw = 1;
|
||||||
char text[256];
|
char text[256];
|
||||||
float x, y;
|
float x, y;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
for (;;) {
|
for (;;)
|
||||||
if (redraw>0) {
|
{
|
||||||
|
if (redraw > 0)
|
||||||
|
{
|
||||||
// Get present mjd
|
// Get present mjd
|
||||||
if (m.mjd<0.0) {
|
if (m.mjd < 0.0)
|
||||||
|
{
|
||||||
nfd_now (m.nfd);
|
nfd_now (m.nfd);
|
||||||
m.mjd = nfd2mjd (m.nfd);
|
m.mjd = nfd2mjd (m.nfd);
|
||||||
}
|
}
|
||||||
|
@ -492,40 +534,47 @@ void plot_map(void)
|
||||||
cpgcurs (&x, &y, &c);
|
cpgcurs (&x, &y, &c);
|
||||||
|
|
||||||
// Help
|
// Help
|
||||||
if (c=='h') {
|
if (c == 'h')
|
||||||
|
{
|
||||||
interactive_usage ();
|
interactive_usage ();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redraw
|
// Redraw
|
||||||
if (c=='r') {
|
if (c == 'r')
|
||||||
|
{
|
||||||
m.mjd = -1.0;
|
m.mjd = -1.0;
|
||||||
m.length = 60;
|
m.length = 60;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
// Increase/decrease time
|
// Increase/decrease time
|
||||||
if (c=='.') {
|
if (c == '.')
|
||||||
|
{
|
||||||
m.mjd += m.length / 86400.0;
|
m.mjd += m.length / 86400.0;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
if (c==',') {
|
if (c == ',')
|
||||||
|
{
|
||||||
m.mjd -= m.length / 86400.0;
|
m.mjd -= m.length / 86400.0;
|
||||||
redraw = 1;
|
redraw = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increase/decrease step
|
// Increase/decrease step
|
||||||
if (c=='>') {
|
if (c == '>')
|
||||||
|
{
|
||||||
m.length *= 2.0;
|
m.length *= 2.0;
|
||||||
redraw = 2;
|
redraw = 2;
|
||||||
}
|
}
|
||||||
if (c=='<') {
|
if (c == '<')
|
||||||
|
{
|
||||||
m.length /= 2.0;
|
m.length /= 2.0;
|
||||||
redraw = 2;
|
redraw = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit
|
// Exit
|
||||||
if (c=='q' || c=='Q') {
|
if (c == 'q' || c == 'Q')
|
||||||
|
{
|
||||||
cpgend ();
|
cpgend ();
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
@ -536,7 +585,8 @@ void plot_map(void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0;
|
int arg = 0;
|
||||||
|
|
||||||
|
@ -544,8 +594,10 @@ int main(int argc,char *argv[])
|
||||||
initialize_setup ();
|
initialize_setup ();
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"t:c:i:s:l:h"))!=-1) {
|
while ((arg = getopt (argc, argv, "t:c:i:s:l:h")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (m.nfd, optarg);
|
strcpy (m.nfd, optarg);
|
||||||
|
@ -595,7 +647,8 @@ int main(int argc,char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_globe(void)
|
void
|
||||||
|
read_globe (void)
|
||||||
{
|
{
|
||||||
int i, status;
|
int i, status;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -604,7 +657,8 @@ void read_globe(void)
|
||||||
sprintf (filename, "%s/data/globe.dat", m.datadir);
|
sprintf (filename, "%s/data/globe.dat", m.datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
|
|
||||||
for (i=0;i<MMAX;i++) {
|
for (i = 0; i < MMAX; i++)
|
||||||
|
{
|
||||||
status = fscanf (file, "%f %f", &glb.b[i], &glb.l[i]);
|
status = fscanf (file, "%f %f", &glb.b[i], &glb.l[i]);
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
@ -613,19 +667,25 @@ void read_globe(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plot_globe(void)
|
void
|
||||||
|
plot_globe (void)
|
||||||
{
|
{
|
||||||
int i, flag;
|
int i, flag;
|
||||||
|
|
||||||
for (i=0,flag=0;i<glb.n;i++) {
|
for (i = 0, flag = 0; i < glb.n; i++)
|
||||||
if (glb.b[i]==9999.0) {
|
{
|
||||||
|
if (glb.b[i] == 9999.0)
|
||||||
|
{
|
||||||
flag = 0;
|
flag = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (flag==0) {
|
if (flag == 0)
|
||||||
|
{
|
||||||
cpgmove (glb.l[i], glb.b[i]);
|
cpgmove (glb.l[i], glb.b[i]);
|
||||||
flag = 1;
|
flag = 1;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
cpgdraw (glb.l[i], glb.b[i]);
|
cpgdraw (glb.l[i], glb.b[i]);
|
||||||
cpgmove (glb.l[i], glb.b[i]);
|
cpgmove (glb.l[i], glb.b[i]);
|
||||||
}
|
}
|
||||||
|
@ -635,7 +695,8 @@ void plot_globe(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize setup
|
// Initialize setup
|
||||||
void initialize_setup(void)
|
void
|
||||||
|
initialize_setup (void)
|
||||||
{
|
{
|
||||||
char *env;
|
char *env;
|
||||||
|
|
||||||
|
@ -652,21 +713,30 @@ void initialize_setup(void)
|
||||||
|
|
||||||
// Get environment variables
|
// Get environment variables
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (m.datadir, env);
|
strcpy (m.datadir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_DATADIR environment variable not found.\n");
|
printf ("ST_DATADIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
env = getenv ("ST_COSPAR");
|
env = getenv ("ST_COSPAR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
get_site (atoi (env));
|
get_site (atoi (env));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_COSPAR environment variable not found.\n");
|
printf ("ST_COSPAR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
env = getenv ("ST_TLEDIR");
|
env = getenv ("ST_TLEDIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (m.tledir, env);
|
strcpy (m.tledir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_TLEDIR environment variable not found.\n");
|
printf ("ST_TLEDIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
sprintf (m.tlefile, "%s/classfd.tle", m.tledir);
|
sprintf (m.tlefile, "%s/classfd.tle", m.tledir);
|
||||||
|
@ -675,7 +745,8 @@ void initialize_setup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -684,18 +755,22 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -703,13 +778,16 @@ double nfd2mjd(char *date)
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage()
|
void
|
||||||
|
usage ()
|
||||||
{
|
{
|
||||||
printf("usage: satmap -c TLEFILE [-t TIMESTAMP] [-s COSPARID] [-i SATNO]\n");
|
printf
|
||||||
|
("usage: satmap -c TLEFILE [-t TIMESTAMP] [-s COSPARID] [-i SATNO]\n");
|
||||||
printf (" [-l LENGTH] [-h]\n");
|
printf (" [-l LENGTH] [-h]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void interactive_usage()
|
void
|
||||||
|
interactive_usage ()
|
||||||
{
|
{
|
||||||
printf ("Interactive help:");
|
printf ("Interactive help:");
|
||||||
printf ("r Redraw\n");
|
printf ("r Redraw\n");
|
||||||
|
@ -725,7 +803,8 @@ void interactive_usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,char *date,int length)
|
void
|
||||||
|
mjd2date (double mjd, char *date, int length)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -740,7 +819,8 @@ void mjd2date(double mjd,char *date,int length)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -771,19 +851,23 @@ void mjd2date(double mjd,char *date,int length)
|
||||||
sec = floor (1000.0 * sec) / 1000.0;
|
sec = floor (1000.0 * sec) / 1000.0;
|
||||||
|
|
||||||
if (length == 3)
|
if (length == 3)
|
||||||
sprintf(date,"%04d-%02d-%02dT%02d:%02d:%06.3f",year,month,day,hour,min,sec);
|
sprintf (date, "%04d-%02d-%02dT%02d:%02d:%06.3f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
else if (length == 0)
|
else if (length == 0)
|
||||||
sprintf(date,"%04d-%02d-%02dT%02d:%02d:%02.0f",year,month,day,hour,min,sec);
|
sprintf (date, "%04d-%02d-%02dT%02d:%02d:%02.0f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -791,17 +875,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Solar position
|
// Solar position
|
||||||
void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
void
|
||||||
|
sunpos_xyz (double mjd, xyz_t * pos, double *ra, double *de)
|
||||||
{
|
{
|
||||||
double jd, t, l0, m, e, c, r;
|
double jd, t, l0, m, e, c, r;
|
||||||
double n, s, ecl;
|
double n, s, ecl;
|
||||||
|
@ -818,7 +908,10 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
||||||
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
r = 1.000001018 * (1.0 - e * e) / (1.0 + e * cos (m + c));
|
||||||
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
n = modulo (125.04 - 1934.136 * t, 360.0) * D2R;
|
||||||
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
s = l0 + c + (-0.00569 - 0.00478 * sin (n)) * D2R;
|
||||||
ecl=(23.43929111+(-46.8150*t-0.00059*t*t+0.001813*t*t*t)/3600.0+0.00256*cos(n))*D2R;
|
ecl =
|
||||||
|
(23.43929111 +
|
||||||
|
(-46.8150 * t - 0.00059 * t * t + 0.001813 * t * t * t) / 3600.0 +
|
||||||
|
0.00256 * cos (n)) * D2R;
|
||||||
|
|
||||||
*ra = atan2 (cos (ecl) * sin (s), cos (s)) * R2D;
|
*ra = atan2 (cos (ecl) * sin (s), cos (s)) * R2D;
|
||||||
*de = asin (sin (ecl) * sin (s)) * R2D;
|
*de = asin (sin (ecl) * sin (s)) * R2D;
|
||||||
|
@ -831,19 +924,23 @@ void sunpos_xyz(double mjd,xyz_t *pos,double *ra,double *de)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double dgmst(double mjd)
|
double
|
||||||
|
dgmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, dgmst;
|
double t, dgmst;
|
||||||
|
|
||||||
|
@ -855,16 +952,19 @@ double dgmst(double mjd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate vector
|
// rotate vector
|
||||||
void rotate(int axis,float angle,float *x,float *y,float *z)
|
void
|
||||||
|
rotate (int axis, float angle, float *x, float *y, float *z)
|
||||||
{
|
{
|
||||||
float xx, yy, zz;
|
float xx, yy, zz;
|
||||||
float ca, sa;
|
float ca, sa;
|
||||||
|
@ -872,17 +972,20 @@ void rotate(int axis,float angle,float *x,float *y,float *z)
|
||||||
ca = cos (angle * D2R);
|
ca = cos (angle * D2R);
|
||||||
sa = sin (angle * D2R);
|
sa = sin (angle * D2R);
|
||||||
|
|
||||||
if (axis==0) {
|
if (axis == 0)
|
||||||
|
{
|
||||||
xx = *x;
|
xx = *x;
|
||||||
yy = *y * ca - *z * sa;
|
yy = *y * ca - *z * sa;
|
||||||
zz = *z * ca + *y * sa;
|
zz = *z * ca + *y * sa;
|
||||||
}
|
}
|
||||||
if (axis==1) {
|
if (axis == 1)
|
||||||
|
{
|
||||||
xx = *x * ca - *z * sa;
|
xx = *x * ca - *z * sa;
|
||||||
yy = *y;
|
yy = *y;
|
||||||
zz = *z * ca + *x * sa;
|
zz = *z * ca + *x * sa;
|
||||||
}
|
}
|
||||||
if (axis==2) {
|
if (axis == 2)
|
||||||
|
{
|
||||||
xx = *x * ca - *y * sa;
|
xx = *x * ca - *y * sa;
|
||||||
yy = *y * ca + *x * sa;
|
yy = *y * ca + *x * sa;
|
||||||
zz = *z;
|
zz = *z;
|
||||||
|
@ -896,7 +999,8 @@ void rotate(int axis,float angle,float *x,float *y,float *z)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -909,11 +1013,13 @@ void get_site(int site_id)
|
||||||
|
|
||||||
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -922,14 +1028,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
|
588
src/satorbit.c
588
src/satorbit.c
File diff suppressed because it is too large
Load Diff
64
src/satutl.c
64
src/satutl.c
|
@ -15,7 +15,8 @@ static double d_read(char *str, int start, int stop);
|
||||||
Read a string from key board, remove CR/LF etc.
|
Read a string from key board, remove CR/LF etc.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
void read_kb(char *buf)
|
void
|
||||||
|
read_kb (char *buf)
|
||||||
{
|
{
|
||||||
int ii;
|
int ii;
|
||||||
|
|
||||||
|
@ -38,7 +39,8 @@ int ii;
|
||||||
next elements of whatever sort.
|
next elements of whatever sort.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
int read_twoline(FILE *fp, long search_satno, orbit_t *orb)
|
int
|
||||||
|
read_twoline (FILE * fp, long search_satno, orbit_t * orb)
|
||||||
{
|
{
|
||||||
static char search[ST_SIZE];
|
static char search[ST_SIZE];
|
||||||
static char line1[ST_SIZE];
|
static char line1[ST_SIZE];
|
||||||
|
@ -53,42 +55,54 @@ int read_twoline(FILE *fp, long search_satno, orbit_t *orb)
|
||||||
st1 = line1;
|
st1 = line1;
|
||||||
st2 = line2;
|
st2 = line2;
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
if (fgets (line1, ST_SIZE - 1, fp) == NULL)
|
if (fgets (line1, ST_SIZE - 1, fp) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
st1 = st_start (line1);
|
st1 = st_start (line1);
|
||||||
} while(st1[0] != '1');
|
}
|
||||||
|
while (st1[0] != '1');
|
||||||
|
|
||||||
if(search_satno > 0) {
|
if (search_satno > 0)
|
||||||
|
{
|
||||||
found = 0;
|
found = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
found = 1;
|
found = 1;
|
||||||
search_satno = atol (st1 + 2);
|
search_satno = atol (st1 + 2);
|
||||||
}
|
}
|
||||||
sprintf (search, "1 %05ld", search_satno);
|
sprintf (search, "1 %05ld", search_satno);
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
st1 = st_start (line1);
|
st1 = st_start (line1);
|
||||||
if(strncmp(st1, search, 7) == 0) {
|
if (strncmp (st1, search, 7) == 0)
|
||||||
|
{
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while(fgets(line1, ST_SIZE-1, fp) != NULL);
|
}
|
||||||
|
while (fgets (line1, ST_SIZE - 1, fp) != NULL);
|
||||||
|
|
||||||
sprintf (search, "2 %05ld", search_satno);
|
sprintf (search, "2 %05ld", search_satno);
|
||||||
|
|
||||||
if(found) {
|
if (found)
|
||||||
|
{
|
||||||
fgets (line2, ST_SIZE - 1, fp);
|
fgets (line2, ST_SIZE - 1, fp);
|
||||||
st2 = st_start (line2);
|
st2 = st_start (line2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found || strncmp(st2, search, 7) != 0) {
|
if (!found || strncmp (st2, search, 7) != 0)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
orb->ep_year = (int) i_read (st1, 19, 20);
|
orb->ep_year = (int) i_read (st1, 19, 20);
|
||||||
|
|
||||||
if(orb->ep_year < 57) orb->ep_year += 2000;
|
if (orb->ep_year < 57)
|
||||||
else orb->ep_year += 1900;
|
orb->ep_year += 2000;
|
||||||
|
else
|
||||||
|
orb->ep_year += 1900;
|
||||||
|
|
||||||
orb->ep_day = d_read (st1, 21, 32);
|
orb->ep_day = d_read (st1, 21, 32);
|
||||||
|
|
||||||
|
@ -121,11 +135,14 @@ int read_twoline(FILE *fp, long search_satno, orbit_t *orb)
|
||||||
Locate the first non-white space character, return location.
|
Locate the first non-white space character, return location.
|
||||||
================================================================== */
|
================================================================== */
|
||||||
|
|
||||||
static char *st_start(char *buf)
|
static char *
|
||||||
|
st_start (char *buf)
|
||||||
{
|
{
|
||||||
if(buf == NULL) return buf;
|
if (buf == NULL)
|
||||||
|
return buf;
|
||||||
|
|
||||||
while(*buf != '\0' && isspace(*buf)) buf++;
|
while (*buf != '\0' && isspace (*buf))
|
||||||
|
buf++;
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +152,8 @@ return buf;
|
||||||
characters to buffer then convert.
|
characters to buffer then convert.
|
||||||
================================================================== */
|
================================================================== */
|
||||||
|
|
||||||
static long i_read(char *str, int start, int stop)
|
static long
|
||||||
|
i_read (char *str, int start, int stop)
|
||||||
{
|
{
|
||||||
long itmp = 0;
|
long itmp = 0;
|
||||||
char *buf, *tmp;
|
char *buf, *tmp;
|
||||||
|
@ -163,7 +181,8 @@ return itmp;
|
||||||
characters to buffer then convert.
|
characters to buffer then convert.
|
||||||
================================================================== */
|
================================================================== */
|
||||||
|
|
||||||
static double d_read(char *str, int start, int stop)
|
static double
|
||||||
|
d_read (char *str, int start, int stop)
|
||||||
{
|
{
|
||||||
double dtmp = 0;
|
double dtmp = 0;
|
||||||
char *buf, *tmp;
|
char *buf, *tmp;
|
||||||
|
@ -190,7 +209,8 @@ return dtmp;
|
||||||
Allocate and check an all-zero array of memory (storage vector).
|
Allocate and check an all-zero array of memory (storage vector).
|
||||||
================================================================== */
|
================================================================== */
|
||||||
|
|
||||||
void *vector(size_t num, size_t size)
|
void *
|
||||||
|
vector (size_t num, size_t size)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
|
@ -207,7 +227,8 @@ return ptr;
|
||||||
Print out orbital parameters.
|
Print out orbital parameters.
|
||||||
================================================================== */
|
================================================================== */
|
||||||
|
|
||||||
void print_orb(orbit_t *orb)
|
void
|
||||||
|
print_orb (orbit_t * orb)
|
||||||
{
|
{
|
||||||
printf ("# Satellite ID = %ld\n", (long) orb->satno);
|
printf ("# Satellite ID = %ld\n", (long) orb->satno);
|
||||||
printf ("# Satellite designation = %s\n", orb->desig);
|
printf ("# Satellite designation = %s\n", orb->desig);
|
||||||
|
@ -216,7 +237,8 @@ void print_orb(orbit_t *orb)
|
||||||
printf ("# Equatorial inclination = %.4f deg\n", DEG (orb->eqinc));
|
printf ("# Equatorial inclination = %.4f deg\n", DEG (orb->eqinc));
|
||||||
printf ("# Argument of perigee = %.4f deg\n", DEG (orb->argp));
|
printf ("# Argument of perigee = %.4f deg\n", DEG (orb->argp));
|
||||||
printf ("# Mean anomaly = %.4f deg\n", DEG (orb->mnan));
|
printf ("# Mean anomaly = %.4f deg\n", DEG (orb->mnan));
|
||||||
printf("# Right Ascension of Ascending Node = %.4f deg\n", DEG(orb->ascn));
|
printf ("# Right Ascension of Ascending Node = %.4f deg\n",
|
||||||
|
DEG (orb->ascn));
|
||||||
printf ("# Mean Motion (number of rev/day) = %.8f\n", orb->rev);
|
printf ("# Mean Motion (number of rev/day) = %.8f\n", orb->rev);
|
||||||
printf ("# First derivative of mean motion = %e\n", orb->ndot2);
|
printf ("# First derivative of mean motion = %e\n", orb->ndot2);
|
||||||
printf ("# Second derivative of mean motion = %e\n", orb->nddot6);
|
printf ("# Second derivative of mean motion = %e\n", orb->nddot6);
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
#define ST_SIZE 256
|
#define ST_SIZE 256
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** satutl.c **/
|
/** satutl.c **/
|
||||||
|
|
121
src/sgdp4.c
121
src/sgdp4.c
|
@ -63,7 +63,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char SCCSid[] = "@(#)sgdp4.c 3.04 (C) 1995 psc SatLib: Orbital Model";
|
static const char SCCSid[] =
|
||||||
|
"@(#)sgdp4.c 3.04 (C) 1995 psc SatLib: Orbital Model";
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -163,7 +164,8 @@ int Set_LS_zero = 0; /* Set to 1 to zero Lunar-Solar terms at epoch. */
|
||||||
The return value indicates the orbital model used.
|
The return value indicates the orbital model used.
|
||||||
======================================================================= */
|
======================================================================= */
|
||||||
|
|
||||||
sgdp4_mode_t init_sgdp4(orbit_t *orb)
|
sgdp4_mode_t
|
||||||
|
init_sgdp4 (orbit_t * orb)
|
||||||
{
|
{
|
||||||
LOCAL_REAL theta2, theta4, xhdot1, x1m5th;
|
LOCAL_REAL theta2, theta4, xhdot1, x1m5th;
|
||||||
LOCAL_REAL s4, del1, del0;
|
LOCAL_REAL s4, del1, del0;
|
||||||
|
@ -218,21 +220,25 @@ long iday, iyear;
|
||||||
|
|
||||||
if (eo < (real) 0.0 || eo > ECC_LIMIT_HIGH)
|
if (eo < (real) 0.0 || eo > ECC_LIMIT_HIGH)
|
||||||
{
|
{
|
||||||
fatal_error("init_sgdp4: Eccentricity out of range for %ld (%le)", Isat, (double)eo);
|
fatal_error ("init_sgdp4: Eccentricity out of range for %ld (%le)",
|
||||||
|
Isat, (double) eo);
|
||||||
imode = SGDP4_ERROR;
|
imode = SGDP4_ERROR;
|
||||||
return imode;
|
return imode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xno < 0.035 * TWOPI / XMNPDA || xno > 18.0 * TWOPI / XMNPDA)
|
if (xno < 0.035 * TWOPI / XMNPDA || xno > 18.0 * TWOPI / XMNPDA)
|
||||||
{
|
{
|
||||||
fatal_error("init_sgdp4: Mean motion out of range %ld (%le)", Isat, xno);
|
fatal_error ("init_sgdp4: Mean motion out of range %ld (%le)", Isat,
|
||||||
|
xno);
|
||||||
imode = SGDP4_ERROR;
|
imode = SGDP4_ERROR;
|
||||||
return imode;
|
return imode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xincl < (real) 0.0 || xincl > (real) PI)
|
if (xincl < (real) 0.0 || xincl > (real) PI)
|
||||||
{
|
{
|
||||||
fatal_error("init_sgdp4: Equatorial inclination out of range %ld (%le)", Isat, DEG(xincl));
|
fatal_error
|
||||||
|
("init_sgdp4: Equatorial inclination out of range %ld (%le)", Isat,
|
||||||
|
DEG (xincl));
|
||||||
imode = SGDP4_ERROR;
|
imode = SGDP4_ERROR;
|
||||||
return imode;
|
return imode;
|
||||||
}
|
}
|
||||||
|
@ -276,10 +282,13 @@ long iday, iyear;
|
||||||
*/
|
*/
|
||||||
if (perigee <= 0.0)
|
if (perigee <= 0.0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "# Satellite %ld sub-orbital (apogee = %.1f km, perigee = %.1f km)\n", Isat, apogee, perigee);
|
fprintf (stderr,
|
||||||
|
"# Satellite %ld sub-orbital (apogee = %.1f km, perigee = %.1f km)\n",
|
||||||
|
Isat, apogee, perigee);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imode == SGDP4_ZERO_ECC) return imode;
|
if (imode == SGDP4_ZERO_ECC)
|
||||||
|
return imode;
|
||||||
|
|
||||||
if (period >= 225.0 && Set_LS_zero < 2)
|
if (period >= 225.0 && Set_LS_zero < 2)
|
||||||
{
|
{
|
||||||
|
@ -308,12 +317,16 @@ long iday, iyear;
|
||||||
|
|
||||||
if (s4 < (real) 20.0)
|
if (s4 < (real) 20.0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "# Very low s4 constant for sat %ld (perigee = %.2f)\n", Isat, perigee);
|
fprintf (stderr,
|
||||||
|
"# Very low s4 constant for sat %ld (perigee = %.2f)\n",
|
||||||
|
Isat, perigee);
|
||||||
s4 = (real) 20.0;
|
s4 = (real) 20.0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "# Changing s4 constant for sat %ld (perigee = %.2f)\n", Isat, perigee);
|
fprintf (stderr,
|
||||||
|
"# Changing s4 constant for sat %ld (perigee = %.2f)\n",
|
||||||
|
Isat, perigee);
|
||||||
}
|
}
|
||||||
|
|
||||||
qoms24 = POW4 ((real) ((120.0 - s4) * (AE / XKMPER)));
|
qoms24 = POW4 ((real) ((120.0 - s4) * (AE / XKMPER)));
|
||||||
|
@ -335,18 +348,42 @@ long iday, iyear;
|
||||||
coef1 = coef / POW (psisq, 3.5);
|
coef1 = coef / POW (psisq, 3.5);
|
||||||
|
|
||||||
c2 = coef1 * (real) xnodp *(aodp *
|
c2 = coef1 * (real) xnodp *(aodp *
|
||||||
((real)1.0 + (real)1.5 * etasq + eeta * ((real)4.0 + etasq)) +
|
((real) 1.0 + (real) 1.5 * etasq +
|
||||||
|
eeta * ((real) 4.0 + etasq)) +
|
||||||
(real) (0.75 * CK2) * tsi / psisq * x3thm1 *
|
(real) (0.75 * CK2) * tsi / psisq * x3thm1 *
|
||||||
((real)8.0 + (real)3.0 * etasq * ((real)8.0 + etasq)));
|
((real) 8.0 +
|
||||||
|
(real) 3.0 * etasq * ((real) 8.0 + etasq)));
|
||||||
|
|
||||||
c1 = bstar * c2;
|
c1 = bstar * c2;
|
||||||
|
|
||||||
c4 = (real) 2.0 *(real) xnodp *coef1 * aodp * betao2 * (eta *
|
c4 = (real) 2.0 *(real) xnodp *coef1 * aodp * betao2 * (eta *
|
||||||
((real)2.0 + (real)0.5 * etasq) + eo * ((real)0.5 + (real)2.0 *
|
((real) 2.0 +
|
||||||
etasq) - (real)(2.0 * CK2) * tsi / (aodp * psisq) * ((real)-3.0 *
|
(real) 0.5 *
|
||||||
x3thm1 * ((real)1.0 - (real)2.0 * eeta + etasq *
|
etasq) +
|
||||||
((real)1.5 - (real)0.5 * eeta)) + (real)0.75 * x1mth2 * ((real)2.0 *
|
eo * ((real) 0.5 +
|
||||||
etasq - eeta * ((real)1.0 + etasq)) * COS((real)2.0 * omegao)));
|
(real) 2.0 *
|
||||||
|
etasq) -
|
||||||
|
(real) (2.0 * CK2) *
|
||||||
|
tsi / (aodp *
|
||||||
|
psisq) *
|
||||||
|
((real) -
|
||||||
|
3.0 * x3thm1 *
|
||||||
|
((real) 1.0 -
|
||||||
|
(real) 2.0 *
|
||||||
|
eeta +
|
||||||
|
etasq *
|
||||||
|
((real) 1.5 -
|
||||||
|
(real) 0.5 *
|
||||||
|
eeta)) +
|
||||||
|
(real) 0.75 *
|
||||||
|
x1mth2 *
|
||||||
|
((real) 2.0 *
|
||||||
|
etasq -
|
||||||
|
eeta *
|
||||||
|
((real) 1.0 +
|
||||||
|
etasq)) *
|
||||||
|
COS ((real) 2.0 *
|
||||||
|
omegao)));
|
||||||
|
|
||||||
c5 = c3 = omgcof = (real) 0.0;
|
c5 = c3 = omgcof = (real) 0.0;
|
||||||
|
|
||||||
|
@ -379,8 +416,10 @@ long iday, iyear;
|
||||||
temp3 * ((real) 3.0 - (real) 36.0 * theta2 + (real) 49.0 * theta4);
|
temp3 * ((real) 3.0 - (real) 36.0 * theta2 + (real) 49.0 * theta4);
|
||||||
|
|
||||||
xhdot1 = -temp1 * cosIO;
|
xhdot1 = -temp1 * cosIO;
|
||||||
xnodot = xhdot1 + ((real)0.5 * temp2 * ((real)4.0 - (real)19.0 * theta2) +
|
xnodot =
|
||||||
(real)2.0 * temp3 * ((real)3.0 - (real)7.0 * theta2)) * cosIO;
|
xhdot1 + ((real) 0.5 * temp2 * ((real) 4.0 - (real) 19.0 * theta2) +
|
||||||
|
(real) 2.0 * temp3 * ((real) 3.0 -
|
||||||
|
(real) 7.0 * theta2)) * cosIO;
|
||||||
|
|
||||||
xmcof = (real) 0.0;
|
xmcof = (real) 0.0;
|
||||||
if (eo > ECC_ALL)
|
if (eo > ECC_ALL)
|
||||||
|
@ -394,7 +433,8 @@ long iday, iyear;
|
||||||
/* Check for possible divide-by-zero for X/(1+cosIO) when calculating xlcof */
|
/* Check for possible divide-by-zero for X/(1+cosIO) when calculating xlcof */
|
||||||
temp0 = (real) 1.0 + cosIO;
|
temp0 = (real) 1.0 + cosIO;
|
||||||
|
|
||||||
if(fabs(temp0) < EPS_COSIO) temp0 = (real)SIGN(EPS_COSIO, temp0);
|
if (fabs (temp0) < EPS_COSIO)
|
||||||
|
temp0 = (real) SIGN (EPS_COSIO, temp0);
|
||||||
|
|
||||||
xlcof = (real) 0.125 *a3ovk2 * sinIO *
|
xlcof = (real) 0.125 *a3ovk2 * sinIO *
|
||||||
((real) 3.0 + (real) 5.0 * cosIO) / temp0;
|
((real) 3.0 + (real) 5.0 * cosIO) / temp0;
|
||||||
|
@ -416,8 +456,8 @@ long iday, iyear;
|
||||||
t4cof = (real) 0.25 *((real) 3.0 * d3 + c1 * ((real) 12.0 * d2 +
|
t4cof = (real) 0.25 *((real) 3.0 * d3 + c1 * ((real) 12.0 * d2 +
|
||||||
(real) 10.0 * c1sq));
|
(real) 10.0 * c1sq));
|
||||||
t5cof = (real) 0.2 *((real) 3.0 * d4 + (real) 12.0 * c1 * d3 +
|
t5cof = (real) 0.2 *((real) 3.0 * d4 + (real) 12.0 * c1 * d3 +
|
||||||
(real)6.0 * d2 * d2 + (real)15.0 * c1sq * ((real)2.0 *
|
(real) 6.0 * d2 * d2 +
|
||||||
d2 + c1sq));
|
(real) 15.0 * c1sq * ((real) 2.0 * d2 + c1sq));
|
||||||
}
|
}
|
||||||
else if (imode == SGDP4_DEEP_NORM)
|
else if (imode == SGDP4_DEEP_NORM)
|
||||||
{
|
{
|
||||||
|
@ -455,7 +495,8 @@ return imode;
|
||||||
|
|
||||||
======================================================================= */
|
======================================================================= */
|
||||||
|
|
||||||
sgdp4_mode_t sgdp4(double tsince, int withvel, kep_t *kep)
|
sgdp4_mode_t
|
||||||
|
sgdp4 (double tsince, int withvel, kep_t * kep)
|
||||||
{
|
{
|
||||||
LOCAL_REAL rk, uk, xnodek, xinck, em, xinc;
|
LOCAL_REAL rk, uk, xnodek, xinck, em, xinc;
|
||||||
LOCAL_REAL xnode, delm, axn, ayn, omega;
|
LOCAL_REAL xnode, delm, axn, ayn, omega;
|
||||||
|
@ -572,7 +613,8 @@ real ts = (real)tsince;
|
||||||
/* Check for possible divide-by-zero for X/(1+cosIO) when calculating xlcof */
|
/* Check for possible divide-by-zero for X/(1+cosIO) when calculating xlcof */
|
||||||
temp0 = (real) 1.0 + cosIO;
|
temp0 = (real) 1.0 + cosIO;
|
||||||
|
|
||||||
if(fabs(temp0) < EPS_COSIO) temp0 = (real)SIGN(EPS_COSIO, temp0);
|
if (fabs (temp0) < EPS_COSIO)
|
||||||
|
temp0 = (real) SIGN (EPS_COSIO, temp0);
|
||||||
|
|
||||||
xlcof = (real) 0.125 *a3ovk2 * sinIO *
|
xlcof = (real) 0.125 *a3ovk2 * sinIO *
|
||||||
((real) 3.0 + (real) 5.0 * cosIO) / temp0;
|
((real) 3.0 + (real) 5.0 * cosIO) / temp0;
|
||||||
|
@ -590,13 +632,17 @@ real ts = (real)tsince;
|
||||||
|
|
||||||
if (a < (real) 1.0)
|
if (a < (real) 1.0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "sgdp4: Satellite %05ld crashed at %.3f (a = %.3f Earth radii)\n", Isat, ts, a);
|
fprintf (stderr,
|
||||||
|
"sgdp4: Satellite %05ld crashed at %.3f (a = %.3f Earth radii)\n",
|
||||||
|
Isat, ts, a);
|
||||||
return SGDP4_ERROR;
|
return SGDP4_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e < ECC_LIMIT_LOW)
|
if (e < ECC_LIMIT_LOW)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "sgdp4: Satellite %05ld modified eccentricity too low (ts = %.3f, e = %e < %e)\n", Isat, ts, e, ECC_LIMIT_LOW);
|
fprintf (stderr,
|
||||||
|
"sgdp4: Satellite %05ld modified eccentricity too low (ts = %.3f, e = %e < %e)\n",
|
||||||
|
Isat, ts, e, ECC_LIMIT_LOW);
|
||||||
return SGDP4_ERROR;
|
return SGDP4_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,7 +670,9 @@ real ts = (real)tsince;
|
||||||
elsq = axn * axn + ayn * ayn;
|
elsq = axn * axn + ayn * ayn;
|
||||||
if (elsq >= (real) 1.0)
|
if (elsq >= (real) 1.0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "sgdp4: SQR(e) >= 1 (%.3f at tsince = %.3f for sat %05ld)\n", elsq, tsince, Isat);
|
fprintf (stderr,
|
||||||
|
"sgdp4: SQR(e) >= 1 (%.3f at tsince = %.3f for sat %05ld)\n",
|
||||||
|
elsq, tsince, Isat);
|
||||||
return SGDP4_ERROR;
|
return SGDP4_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -654,7 +702,8 @@ real ts = (real)tsince;
|
||||||
esinE = axn * sinEPW - ayn * cosEPW;
|
esinE = axn * sinEPW - ayn * cosEPW;
|
||||||
|
|
||||||
f = capu - epw + esinE;
|
f = capu - epw + esinE;
|
||||||
if (fabs(f) < NR_EPS) break;
|
if (fabs (f) < NR_EPS)
|
||||||
|
break;
|
||||||
|
|
||||||
df = (real) 1.0 - ecosE;
|
df = (real) 1.0 - ecosE;
|
||||||
|
|
||||||
|
@ -692,7 +741,9 @@ real ts = (real)tsince;
|
||||||
|
|
||||||
/* Update for short term periodics to position terms. */
|
/* Update for short term periodics to position terms. */
|
||||||
|
|
||||||
rk = r * ((real)1.0 - (real)1.5 * temp2 * betal * x3thm1) + (real)0.5 * temp1 * x1mth2 * cos2u;
|
rk =
|
||||||
|
r * ((real) 1.0 - (real) 1.5 * temp2 * betal * x3thm1) +
|
||||||
|
(real) 0.5 *temp1 * x1mth2 * cos2u;
|
||||||
uk = u - (real) 0.25 *temp2 * x7thm1 * sin2u;
|
uk = u - (real) 0.25 *temp2 * x7thm1 * sin2u;
|
||||||
xnodek = xnode + (real) 1.5 *temp2 * cosIO * sin2u;
|
xnodek = xnode + (real) 1.5 *temp2 * cosIO * sin2u;
|
||||||
xinck = xinc + (real) 1.5 *temp2 * cosIO * sinIO * cos2u;
|
xinck = xinc + (real) 1.5 *temp2 * cosIO * sinIO * cos2u;
|
||||||
|
@ -700,7 +751,9 @@ real ts = (real)tsince;
|
||||||
if (rk < (real) 1.0)
|
if (rk < (real) 1.0)
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
fprintf(stderr, "sgdp4: Satellite %05ld crashed at %.3f (rk = %.3f Earth radii)\n", Isat, ts, rk);
|
fprintf (stderr,
|
||||||
|
"sgdp4: Satellite %05ld crashed at %.3f (rk = %.3f Earth radii)\n",
|
||||||
|
Isat, ts, rk);
|
||||||
#endif
|
#endif
|
||||||
return SGDP4_ERROR;
|
return SGDP4_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -719,9 +772,7 @@ real ts = (real)tsince;
|
||||||
temp0 = SQRT (a);
|
temp0 = SQRT (a);
|
||||||
temp2 = (real) XKE / (a * temp0);
|
temp2 = (real) XKE / (a * temp0);
|
||||||
|
|
||||||
kep->rdotk = ((real)XKE * temp0 * esinE * invR -
|
kep->rdotk = ((real) XKE * temp0 * esinE * invR - temp2 * temp1 * x1mth2 * sin2u) * (XKMPER / AE * XMNPDA / 86400.0); /* Into km/sec */
|
||||||
temp2 * temp1 * x1mth2 * sin2u) *
|
|
||||||
(XKMPER/AE*XMNPDA/86400.0); /* Into km/sec */
|
|
||||||
|
|
||||||
kep->rfdotk = ((real) XKE * SQRT (pl) * invR + temp2 * temp1 *
|
kep->rfdotk = ((real) XKE * SQRT (pl) * invR + temp2 * temp1 *
|
||||||
(x1mth2 * cos2u + (real) 1.5 * x3thm1)) *
|
(x1mth2 * cos2u + (real) 1.5 * x3thm1)) *
|
||||||
|
@ -752,7 +803,8 @@ return imode;
|
||||||
|
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
void kep2xyz(kep_t *K, xyz_t *pos, xyz_t *vel)
|
void
|
||||||
|
kep2xyz (kep_t * K, xyz_t * pos, xyz_t * vel)
|
||||||
{
|
{
|
||||||
real xmx, xmy;
|
real xmx, xmy;
|
||||||
real ux, uy, uz, vx, vy, vz;
|
real ux, uy, uz, vx, vy, vz;
|
||||||
|
@ -806,7 +858,8 @@ real sinT, cosT, sinI, cosI, sinS, cosS;
|
||||||
|
|
||||||
====================================================================== */
|
====================================================================== */
|
||||||
|
|
||||||
sgdp4_mode_t satpos_xyz(double jd, xyz_t *pos, xyz_t *vel)
|
sgdp4_mode_t
|
||||||
|
satpos_xyz (double jd, xyz_t * pos, xyz_t * vel)
|
||||||
{
|
{
|
||||||
kep_t K;
|
kep_t K;
|
||||||
int withvel;
|
int withvel;
|
||||||
|
|
160
src/sgdp4h.h
160
src/sgdp4h.h
|
@ -133,31 +133,142 @@ void sincos(double x, double *s, double *c); /* declared where? */
|
||||||
* All other compilers can have static inline functions.
|
* All other compilers can have static inline functions.
|
||||||
* (SQR is used badly here: do_cal.c, glat2lat.c, satpos.c, vmath.h).
|
* (SQR is used badly here: do_cal.c, glat2lat.c, satpos.c, vmath.h).
|
||||||
*/
|
*/
|
||||||
static INLINE int NINT(double a) { return (int)(a > 0 ? a+0.5 : a-0.5); }
|
static INLINE int
|
||||||
static INLINE long NLONG(double a) { return (long)(a > 0 ? a+0.5 : a-0.5); }
|
NINT (double a)
|
||||||
|
{
|
||||||
|
return (int) (a > 0 ? a + 0.5 : a - 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
static INLINE double DSQR(double a) { return(a*a); }
|
static INLINE long
|
||||||
static INLINE float FSQR(float a) { return(a*a); }
|
NLONG (double a)
|
||||||
static INLINE int ISQR(int a) { return(a*a); }
|
{
|
||||||
|
return (long) (a > 0 ? a + 0.5 : a - 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
static INLINE double DCUBE(double a) { return(a*a*a); }
|
static INLINE double
|
||||||
static INLINE float FCUBE(float a) { return(a*a*a); }
|
DSQR (double a)
|
||||||
static INLINE int ICUBE(int a) { return(a*a*a); }
|
{
|
||||||
|
return (a * a);
|
||||||
|
}
|
||||||
|
|
||||||
static INLINE double DPOW4(double a) { a*=a; return(a*a); }
|
static INLINE float
|
||||||
static INLINE float FPOW4(float a) { a*=a; return(a*a); }
|
FSQR (float a)
|
||||||
static INLINE int IPOW4(int a) { a*=a; return(a*a); }
|
{
|
||||||
|
return (a * a);
|
||||||
|
}
|
||||||
|
|
||||||
static INLINE double DMAX(double a,double b) { if (a>b) return a; else return b; }
|
static INLINE int
|
||||||
static INLINE float FMAX(float a, float b) { if (a>b) return a; else return b; }
|
ISQR (int a)
|
||||||
static INLINE int IMAX(int a, int b) { if (a>b) return a; else return b; }
|
{
|
||||||
|
return (a * a);
|
||||||
|
}
|
||||||
|
|
||||||
static INLINE double DMIN(double a,double b) { if (a<b) return a; else return b; }
|
static INLINE double
|
||||||
static INLINE float FMIN(float a, float b) { if (a<b) return a; else return b; }
|
DCUBE (double a)
|
||||||
static INLINE int IMIN(int a, int b) { if (a<b) return a; else return b; }
|
{
|
||||||
|
return (a * a * a);
|
||||||
|
}
|
||||||
|
|
||||||
static INLINE double MOD2PI(double a) { a=fmod(a, TWOPI); return a < 0.0 ? a+TWOPI : a; }
|
static INLINE float
|
||||||
static INLINE double MOD360(double a) { a=fmod(a, 360.0); return a < 0.0 ? a+360.0 : a; }
|
FCUBE (float a)
|
||||||
|
{
|
||||||
|
return (a * a * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE int
|
||||||
|
ICUBE (int a)
|
||||||
|
{
|
||||||
|
return (a * a * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE double
|
||||||
|
DPOW4 (double a)
|
||||||
|
{
|
||||||
|
a *= a;
|
||||||
|
return (a * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE float
|
||||||
|
FPOW4 (float a)
|
||||||
|
{
|
||||||
|
a *= a;
|
||||||
|
return (a * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE int
|
||||||
|
IPOW4 (int a)
|
||||||
|
{
|
||||||
|
a *= a;
|
||||||
|
return (a * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE double
|
||||||
|
DMAX (double a, double b)
|
||||||
|
{
|
||||||
|
if (a > b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE float
|
||||||
|
FMAX (float a, float b)
|
||||||
|
{
|
||||||
|
if (a > b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE int
|
||||||
|
IMAX (int a, int b)
|
||||||
|
{
|
||||||
|
if (a > b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE double
|
||||||
|
DMIN (double a, double b)
|
||||||
|
{
|
||||||
|
if (a < b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE float
|
||||||
|
FMIN (float a, float b)
|
||||||
|
{
|
||||||
|
if (a < b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE int
|
||||||
|
IMIN (int a, int b)
|
||||||
|
{
|
||||||
|
if (a < b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE double
|
||||||
|
MOD2PI (double a)
|
||||||
|
{
|
||||||
|
a = fmod (a, TWOPI);
|
||||||
|
return a < 0.0 ? a + TWOPI : a;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE double
|
||||||
|
MOD360 (double a)
|
||||||
|
{
|
||||||
|
a = fmod (a, 360.0);
|
||||||
|
return a < 0.0 ? a + 360.0 : a;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unless you have higher than default optimisation the Sun compiler
|
* Unless you have higher than default optimisation the Sun compiler
|
||||||
|
@ -336,7 +447,8 @@ void sincosf(float, float *, float *);
|
||||||
|
|
||||||
/* SGDP4 function return values. */
|
/* SGDP4 function return values. */
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
SGDP4_ERROR = (-1),
|
SGDP4_ERROR = (-1),
|
||||||
SGDP4_NOT_INIT = 0,
|
SGDP4_NOT_INIT = 0,
|
||||||
SGDP4_ZERO_ECC = 1,
|
SGDP4_ZERO_ECC = 1,
|
||||||
|
@ -352,14 +464,16 @@ typedef enum {
|
||||||
/* ======================= Function prototypes ====================== */
|
/* ======================= Function prototypes ====================== */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** deep.c **/
|
/** deep.c **/
|
||||||
|
|
||||||
sgdp4_mode_t SGDP4_dpinit (double epoch, real omegao, real xnodeo, real xmo,
|
sgdp4_mode_t SGDP4_dpinit (double epoch, real omegao, real xnodeo, real xmo,
|
||||||
real orb_eo, real orb_xincl, real aodp, double xlldot,
|
real orb_eo, real orb_xincl, real aodp,
|
||||||
real omgdot, real xnodot, double xnodp);
|
double xlldot, real omgdot, real xnodot,
|
||||||
|
double xnodp);
|
||||||
|
|
||||||
int SGDP4_dpsec (double *xll, real * omgasm, real * xnodes, real * em,
|
int SGDP4_dpsec (double *xll, real * omgasm, real * xnodes, real * em,
|
||||||
real * xinc, double *xn, double tsince);
|
real * xinc, double *xn, double tsince);
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
double **simplex(int n,double *a,double *da)
|
double **
|
||||||
|
simplex (int n, double *a, double *da)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
double **p;
|
double **p;
|
||||||
|
@ -15,14 +16,18 @@ double **simplex(int n,double *a,double *da)
|
||||||
p[i] = (double *) malloc (sizeof (double) * (n + 1) * n);
|
p[i] = (double *) malloc (sizeof (double) * (n + 1) * n);
|
||||||
|
|
||||||
// Fill simplex
|
// Fill simplex
|
||||||
for (i=0;i<=n;i++) {
|
for (i = 0; i <= n; i++)
|
||||||
for (j=0;j<n;j++) {
|
{
|
||||||
if (i<j) p[i][j]=a[j];
|
for (j = 0; j < n; j++)
|
||||||
if (i==j) p[i][j]=a[j]+da[j];
|
{
|
||||||
if (i>j) p[i][j]=a[j]-da[j];
|
if (i < j)
|
||||||
|
p[i][j] = a[j];
|
||||||
|
if (i == j)
|
||||||
|
p[i][j] = a[j] + da[j];
|
||||||
|
if (i > j)
|
||||||
|
p[i][j] = a[j] - da[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
188
src/slewto.c
188
src/slewto.c
|
@ -20,7 +20,8 @@
|
||||||
#define PORT 7624
|
#define PORT 7624
|
||||||
#define IP "127.0.0.1"
|
#define IP "127.0.0.1"
|
||||||
|
|
||||||
struct map {
|
struct map
|
||||||
|
{
|
||||||
double alpha0, delta0, ra0, de0, azi0, alt0, q;
|
double alpha0, delta0, ra0, de0, azi0, alt0, q;
|
||||||
char orientation[LIM];
|
char orientation[LIM];
|
||||||
char nfd[LIM];
|
char nfd[LIM];
|
||||||
|
@ -31,14 +32,16 @@ struct map {
|
||||||
int site_id;
|
int site_id;
|
||||||
} m;
|
} m;
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2nfd(double mjd,char *nfd)
|
void
|
||||||
|
mjd2nfd (double mjd, char *nfd)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -53,7 +56,8 @@ void mjd2nfd(double mjd,char *nfd)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -83,13 +87,15 @@ void mjd2nfd(double mjd,char *nfd)
|
||||||
hour = x;
|
hour = x;
|
||||||
sec = floor (1000.0 * sec) / 1000.0;
|
sec = floor (1000.0 * sec) / 1000.0;
|
||||||
|
|
||||||
sprintf(nfd,"%04d-%02d-%02dT%02d:%02d:%06.3f",year,month,day,hour,min,sec);
|
sprintf (nfd, "%04d-%02d-%02dT%02d:%02d:%06.3f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send new position to telescope
|
// Send new position to telescope
|
||||||
void send_position(char *sra,char *sde)
|
void
|
||||||
|
send_position (char *sra, char *sde)
|
||||||
{
|
{
|
||||||
int skt;
|
int skt;
|
||||||
struct hostent *he;
|
struct hostent *he;
|
||||||
|
@ -102,7 +108,9 @@ void send_position(char *sra,char *sde)
|
||||||
// sprintf(packet,"<newNumberVector device='Celestron GPS' name='EQUATORIAL_EOD_COORD_REQUEST'><oneNumber name='RA'>%s</oneNumber><oneNumber name='DEC'>%s</oneNumber></newNumberVector>",sra,sde);
|
// sprintf(packet,"<newNumberVector device='Celestron GPS' name='EQUATORIAL_EOD_COORD_REQUEST'><oneNumber name='RA'>%s</oneNumber><oneNumber name='DEC'>%s</oneNumber></newNumberVector>",sra,sde);
|
||||||
|
|
||||||
// New packet style (as of 2013-08-20)
|
// New packet style (as of 2013-08-20)
|
||||||
sprintf(packet,"<newNumberVector device='iEQ' name='EQUATORIAL_EOD_COORD'><oneNumber name='RA'>%s</oneNumber><oneNumber name='DEC'>%s</oneNumber></newNumberVector>",sra,sde);
|
sprintf (packet,
|
||||||
|
"<newNumberVector device='iEQ' name='EQUATORIAL_EOD_COORD'><oneNumber name='RA'>%s</oneNumber><oneNumber name='DEC'>%s</oneNumber></newNumberVector>",
|
||||||
|
sra, sde);
|
||||||
|
|
||||||
// Send TCP packet
|
// Send TCP packet
|
||||||
skt = socket (AF_INET, SOCK_STREAM, 0);
|
skt = socket (AF_INET, SOCK_STREAM, 0);
|
||||||
|
@ -110,7 +118,8 @@ void send_position(char *sra,char *sde)
|
||||||
addr.sin_port = htons (PORT);
|
addr.sin_port = htons (PORT);
|
||||||
he = gethostbyname (IP);
|
he = gethostbyname (IP);
|
||||||
bcopy (he->h_addr, (struct in_addr *) &addr.sin_addr, he->h_length);
|
bcopy (he->h_addr, (struct in_addr *) &addr.sin_addr, he->h_length);
|
||||||
if(connect(skt,(struct sockaddr *) &addr,sizeof(addr))<0) {
|
if (connect (skt, (struct sockaddr *) &addr, sizeof (addr)) < 0)
|
||||||
|
{
|
||||||
fprintf (stderr, "Connection refused by remote host.\n");
|
fprintf (stderr, "Connection refused by remote host.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +144,8 @@ void send_position(char *sra,char *sde)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get observing site
|
// Get observing site
|
||||||
void get_site(int site_id)
|
void
|
||||||
|
get_site (int site_id)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -147,11 +157,13 @@ void get_site(int site_id)
|
||||||
|
|
||||||
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
sprintf (filename, "%s/data/sites.txt", m.datadir);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
printf ("File with site information not found!\n");
|
printf ("File with site information not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets(line,LIM,file)!=NULL) {
|
while (fgets (line, LIM, file) != NULL)
|
||||||
|
{
|
||||||
// Skip
|
// Skip
|
||||||
if (strstr (line, "#") != NULL)
|
if (strstr (line, "#") != NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -160,14 +172,14 @@ void get_site(int site_id)
|
||||||
line[strlen (line) - 1] = '\0';
|
line[strlen (line) - 1] = '\0';
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
sscanf(line,"%4d %2s %lf %lf %f",
|
sscanf (line, "%4d %2s %lf %lf %f", &id, abbrev, &lat, &lng, &alt);
|
||||||
&id,abbrev,&lat,&lng,&alt);
|
|
||||||
strcpy (observer, line + 38);
|
strcpy (observer, line + 38);
|
||||||
|
|
||||||
// Change to km
|
// Change to km
|
||||||
alt /= 1000.0;
|
alt /= 1000.0;
|
||||||
|
|
||||||
if (id==site_id) {
|
if (id == site_id)
|
||||||
|
{
|
||||||
m.lat = lat;
|
m.lat = lat;
|
||||||
m.lng = lng;
|
m.lng = lng;
|
||||||
m.alt = alt;
|
m.alt = alt;
|
||||||
|
@ -181,7 +193,8 @@ void get_site(int site_id)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize(void)
|
void
|
||||||
|
initialize (void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *env;
|
char *env;
|
||||||
|
@ -199,15 +212,21 @@ void initialize(void)
|
||||||
|
|
||||||
// Get environment variables
|
// Get environment variables
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
strcpy (m.datadir, env);
|
strcpy (m.datadir, env);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_DATADIR environment variable not found.\n");
|
printf ("ST_DATADIR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
env = getenv ("ST_COSPAR");
|
env = getenv ("ST_COSPAR");
|
||||||
if (env!=NULL) {
|
if (env != NULL)
|
||||||
|
{
|
||||||
get_site (atoi (env));
|
get_site (atoi (env));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf ("ST_COSPAR environment variable not found.\n");
|
printf ("ST_COSPAR environment variable not found.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,29 +235,35 @@ void initialize(void)
|
||||||
|
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greenwich Mean Sidereal Time
|
// Greenwich Mean Sidereal Time
|
||||||
double gmst(double mjd)
|
double
|
||||||
|
gmst (double mjd)
|
||||||
{
|
{
|
||||||
double t, gmst;
|
double t, gmst;
|
||||||
|
|
||||||
t = (mjd - 51544.5) / 36525.0;
|
t = (mjd - 51544.5) / 36525.0;
|
||||||
|
|
||||||
gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0);
|
gmst =
|
||||||
|
modulo (280.46061837 + 360.98564736629 * (mjd - 51544.5) +
|
||||||
|
t * t * (0.000387933 - t / 38710000), 360.0);
|
||||||
|
|
||||||
return gmst;
|
return gmst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Convert Sexagesimal into Decimal
|
// Convert Sexagesimal into Decimal
|
||||||
double s2dec(char *s)
|
double
|
||||||
|
s2dec (char *s)
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
float deg, min, sec;
|
float deg, min, sec;
|
||||||
|
@ -251,18 +276,21 @@ double s2dec(char *s)
|
||||||
sec = fabs (atof (strtok (NULL, " :")));
|
sec = fabs (atof (strtok (NULL, " :")));
|
||||||
|
|
||||||
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
x = (double) deg + (double) min / 60. + (double) sec / 3600.;
|
||||||
if (s[0]=='-') x= -x;
|
if (s[0] == '-')
|
||||||
|
x = -x;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -270,17 +298,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -289,18 +323,22 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -309,13 +347,20 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert horizontal into equatorial coordinates
|
// Convert horizontal into equatorial coordinates
|
||||||
void horizontal2equatorial(double mjd,double azi,double alt,double *ra,double *de)
|
void
|
||||||
|
horizontal2equatorial (double mjd, double azi, double alt, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
|
|
||||||
h=atan2(sin(azi*D2R),cos(azi*D2R)*sin(m.lat*D2R)+tan(alt*D2R)*cos(m.lat*D2R))*R2D;
|
h =
|
||||||
|
atan2 (sin (azi * D2R),
|
||||||
|
cos (azi * D2R) * sin (m.lat * D2R) +
|
||||||
|
tan (alt * D2R) * cos (m.lat * D2R)) * R2D;
|
||||||
*ra = modulo (gmst (mjd) + m.lng - h, 360.0);
|
*ra = modulo (gmst (mjd) + m.lng - h, 360.0);
|
||||||
*de=asin(sin(m.lat*D2R)*sin(alt*D2R)-cos(m.lat*D2R)*cos(alt*D2R)*cos(azi*D2R))*R2D;
|
*de =
|
||||||
|
asin (sin (m.lat * D2R) * sin (alt * D2R) -
|
||||||
|
cos (m.lat * D2R) * cos (alt * D2R) * cos (azi * D2R)) * R2D;
|
||||||
if (*ra < 0.0)
|
if (*ra < 0.0)
|
||||||
*ra += 360.0;
|
*ra += 360.0;
|
||||||
|
|
||||||
|
@ -323,31 +368,44 @@ void horizontal2equatorial(double mjd,double azi,double alt,double *ra,double *d
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert equatorial into horizontal coordinates
|
// Convert equatorial into horizontal coordinates
|
||||||
void equatorial2horizontal(double mjd,double ra,double de,double *azi,double *alt)
|
void
|
||||||
|
equatorial2horizontal (double mjd, double ra, double de, double *azi,
|
||||||
|
double *alt)
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
|
|
||||||
h = gmst (mjd) + m.lng - ra;
|
h = gmst (mjd) + m.lng - ra;
|
||||||
|
|
||||||
*azi=modulo(atan2(sin(h*D2R),cos(h*D2R)*sin(m.lat*D2R)-tan(de*D2R)*cos(m.lat*D2R))*R2D,360.0);
|
*azi =
|
||||||
*alt=asin(sin(m.lat*D2R)*sin(de*D2R)+cos(m.lat*D2R)*cos(de*D2R)*cos(h*D2R))*R2D;
|
modulo (atan2
|
||||||
|
(sin (h * D2R),
|
||||||
|
cos (h * D2R) * sin (m.lat * D2R) -
|
||||||
|
tan (de * D2R) * cos (m.lat * D2R)) * R2D, 360.0);
|
||||||
|
*alt =
|
||||||
|
asin (sin (m.lat * D2R) * sin (de * D2R) +
|
||||||
|
cos (m.lat * D2R) * cos (de * D2R) * cos (h * D2R)) * R2D;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double parallactic_angle(double mjd,double ra,double de)
|
double
|
||||||
|
parallactic_angle (double mjd, double ra, double de)
|
||||||
{
|
{
|
||||||
double h, q;
|
double h, q;
|
||||||
|
|
||||||
h = gmst (mjd) + m.lng - ra;
|
h = gmst (mjd) + m.lng - ra;
|
||||||
|
|
||||||
q=atan2(sin(h*D2R),(tan(m.lat*D2R)*cos(de*D2R)-sin(de*D2R)*cos(h*D2R)))*R2D;
|
q =
|
||||||
|
atan2 (sin (h * D2R),
|
||||||
|
(tan (m.lat * D2R) * cos (de * D2R) -
|
||||||
|
sin (de * D2R) * cos (h * D2R))) * R2D;
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Decimal into Sexagesimal
|
// Convert Decimal into Sexagesimal
|
||||||
void dec2s(double x,char *s,int f,int len)
|
void
|
||||||
|
dec2s (double x, char *s, int f, int len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double sec, deg, min;
|
double sec, deg, min;
|
||||||
|
@ -364,17 +422,28 @@ void dec2s(double x,char *s,int f,int len)
|
||||||
// deg=fmod(x,60.);
|
// deg=fmod(x,60.);
|
||||||
deg = x;
|
deg = x;
|
||||||
|
|
||||||
if (len==7) sprintf(s,"%c%02i%c%02i%c%07.4f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
if (len == 7)
|
||||||
if (len==6) sprintf(s,"%c%02i%c%02i%c%06.3f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
sprintf (s, "%c%02i%c%02i%c%07.4f%c", sign, (int) deg, form[f][0],
|
||||||
if (len==5) sprintf(s,"%c%02i%c%02i%c%05.2f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
if (len==4) sprintf(s,"%c%02i%c%02i%c%04.1f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
|
if (len == 6)
|
||||||
if (len==2) sprintf(s,"%c%02i%c%02i%c%02i%c",sign,(int) deg,form[f][0],(int) min,form[f][1],(int) floor(sec),form[f][2]);
|
sprintf (s, "%c%02i%c%02i%c%06.3f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 5)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%05.2f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 4)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%04.1f%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], sec, form[f][2]);
|
||||||
|
if (len == 2)
|
||||||
|
sprintf (s, "%c%02i%c%02i%c%02i%c", sign, (int) deg, form[f][0],
|
||||||
|
(int) min, form[f][1], (int) floor (sec), form[f][2]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg = 0, haflag = 0, dry = 0;
|
int arg = 0, haflag = 0, dry = 0;
|
||||||
char sra[16], sde[16];
|
char sra[16], sde[16];
|
||||||
|
@ -389,8 +458,10 @@ int main(int argc,char *argv[])
|
||||||
m.mjd = nfd2mjd (m.nfd);
|
m.mjd = nfd2mjd (m.nfd);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"m:t:H:R:D:A:E:hn"))!=-1) {
|
while ((arg = getopt (argc, argv, "m:t:H:R:D:A:E:hn")) != -1)
|
||||||
switch(arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
dry = 1;
|
dry = 1;
|
||||||
|
@ -444,9 +515,12 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute RA from HA
|
// Compute RA from HA
|
||||||
if (haflag==1) {
|
if (haflag == 1)
|
||||||
|
{
|
||||||
m.ra0 = modulo (gmst (m.mjd) + m.lng - ha, 360.0);
|
m.ra0 = modulo (gmst (m.mjd) + m.lng - ha, 360.0);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ha = modulo (gmst (m.mjd) + m.lng - m.ra0, 360.0);
|
ha = modulo (gmst (m.mjd) + m.lng - m.ra0, 360.0);
|
||||||
if (ha > 180.0)
|
if (ha > 180.0)
|
||||||
ha -= 360.0;
|
ha -= 360.0;
|
||||||
|
@ -465,9 +539,11 @@ int main(int argc,char *argv[])
|
||||||
dec2s (m.de0, sde, 0, 4);
|
dec2s (m.de0, sde, 0, 4);
|
||||||
|
|
||||||
// Print to screen
|
// Print to screen
|
||||||
printf("%s R:%s D: %s H: %7.3f A: %6.3f E: %6.3f q: %5.2f\n",m.nfd,sra,sde,ha,modulo(m.azi0-180.0,360.0),m.alt0,m.q);
|
printf ("%s R:%s D: %s H: %7.3f A: %6.3f E: %6.3f q: %5.2f\n", m.nfd, sra,
|
||||||
|
sde, ha, modulo (m.azi0 - 180.0, 360.0), m.alt0, m.q);
|
||||||
|
|
||||||
if (dry==0) {
|
if (dry == 0)
|
||||||
|
{
|
||||||
// Send position
|
// Send position
|
||||||
send_position (sra, sde);
|
send_position (sra, sde);
|
||||||
|
|
||||||
|
|
106
src/stviewer.c
106
src/stviewer.c
|
@ -10,7 +10,8 @@
|
||||||
#define D2R M_PI/180.0
|
#define D2R M_PI/180.0
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
|
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
char filename[64];
|
char filename[64];
|
||||||
int naxis1, naxis2, naxis3, nframes;
|
int naxis1, naxis2, naxis3, nframes;
|
||||||
float *zavg, *zstd, *zmax, *znum, *ztrk;
|
float *zavg, *zstd, *zmax, *znum, *ztrk;
|
||||||
|
@ -26,7 +27,8 @@ struct image read_fits(char *filename);
|
||||||
void write_composite_pgm (char *filename, struct image img);
|
void write_composite_pgm (char *filename, struct image img);
|
||||||
void write_pgm (char *filename, struct image img);
|
void write_pgm (char *filename, struct image img);
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct image img;
|
struct image img;
|
||||||
|
@ -40,7 +42,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename)
|
struct image
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
@ -82,7 +85,8 @@ struct image read_fits(char *filename)
|
||||||
|
|
||||||
// Timestamps
|
// Timestamps
|
||||||
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
img.dt = (float *) malloc (sizeof (float) * img.nframes);
|
||||||
for (i=0;i<img.nframes;i++) {
|
for (i = 0; i < img.nframes; i++)
|
||||||
|
{
|
||||||
sprintf (key, "DT%04d", i);
|
sprintf (key, "DT%04d", i);
|
||||||
strcpy (val, qfits_query_hdr (filename, key));
|
strcpy (val, qfits_query_hdr (filename, key));
|
||||||
sscanf (val + 1, "%f", &img.dt[i]);
|
sscanf (val + 1, "%f", &img.dt[i]);
|
||||||
|
@ -103,7 +107,8 @@ struct image read_fits(char *filename)
|
||||||
ql.filename = filename;
|
ql.filename = filename;
|
||||||
|
|
||||||
// Loop over planes
|
// Loop over planes
|
||||||
for (k=0;k<img.naxis3;k++) {
|
for (k = 0; k < img.naxis3; k++)
|
||||||
|
{
|
||||||
ql.pnum = k;
|
ql.pnum = k;
|
||||||
|
|
||||||
// Initialize load
|
// Initialize load
|
||||||
|
@ -115,16 +120,27 @@ struct image read_fits(char *filename)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
// Fill z array
|
// Fill z array
|
||||||
for (i=0,l=0;i<img.naxis1;i++) {
|
for (i = 0, l = 0; i < img.naxis1; i++)
|
||||||
for (j=0;j<img.naxis2;j++) {
|
{
|
||||||
if (k==1) img.zstd[l]=ql.fbuf[l];
|
for (j = 0; j < img.naxis2; j++)
|
||||||
if (k==2) img.zmax[l]=ql.fbuf[l];
|
{
|
||||||
if (k==3) img.znum[l]=ql.fbuf[l];
|
if (k == 1)
|
||||||
if (img.naxis3==5) {
|
img.zstd[l] = ql.fbuf[l];
|
||||||
if (k==0) img.ztrk[l]=ql.fbuf[l];
|
if (k == 2)
|
||||||
if (k==4) img.zavg[l]=ql.fbuf[l];
|
img.zmax[l] = ql.fbuf[l];
|
||||||
} else {
|
if (k == 3)
|
||||||
if (k==0) img.zavg[l]=ql.fbuf[l];
|
img.znum[l] = ql.fbuf[l];
|
||||||
|
if (img.naxis3 == 5)
|
||||||
|
{
|
||||||
|
if (k == 0)
|
||||||
|
img.ztrk[l] = ql.fbuf[l];
|
||||||
|
if (k == 4)
|
||||||
|
img.zavg[l] = ql.fbuf[l];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (k == 0)
|
||||||
|
img.zavg[l] = ql.fbuf[l];
|
||||||
}
|
}
|
||||||
|
|
||||||
l++;
|
l++;
|
||||||
|
@ -136,7 +152,8 @@ struct image read_fits(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write pgm file
|
// Write pgm file
|
||||||
void write_composite_pgm(char *filename,struct image img)
|
void
|
||||||
|
write_composite_pgm (char *filename, struct image img)
|
||||||
{
|
{
|
||||||
int i, j, k, l, n;
|
int i, j, k, l, n;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -145,33 +162,43 @@ void write_composite_pgm(char *filename,struct image img)
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
|
|
||||||
n = img.naxis1 * img.naxis2;
|
n = img.naxis1 * img.naxis2;
|
||||||
for (j=0;j<3;j++) {
|
for (j = 0; j < 3; j++)
|
||||||
for (i=0,s1=0.0,s2=0.0;i<n;i++) {
|
{
|
||||||
if (j==0) z=img.zavg[i];
|
for (i = 0, s1 = 0.0, s2 = 0.0; i < n; i++)
|
||||||
if (j==1) z=img.zstd[i];
|
{
|
||||||
if (j==2) z=img.zmax[i];
|
if (j == 0)
|
||||||
|
z = img.zavg[i];
|
||||||
|
if (j == 1)
|
||||||
|
z = img.zstd[i];
|
||||||
|
if (j == 2)
|
||||||
|
z = img.zmax[i];
|
||||||
s1 += z;
|
s1 += z;
|
||||||
s2 += z * z;
|
s2 += z * z;
|
||||||
}
|
}
|
||||||
avg = s1 / (float) n;
|
avg = s1 / (float) n;
|
||||||
std = sqrt (s2 / (float) n - avg * avg);
|
std = sqrt (s2 / (float) n - avg * avg);
|
||||||
if (j==0) {
|
if (j == 0)
|
||||||
|
{
|
||||||
zavgmin = avg - 2 * std;
|
zavgmin = avg - 2 * std;
|
||||||
zavgmax = avg + 3 * std;
|
zavgmax = avg + 3 * std;
|
||||||
}
|
}
|
||||||
if (j==1) {
|
if (j == 1)
|
||||||
|
{
|
||||||
zstdmin = avg - 2 * std;
|
zstdmin = avg - 2 * std;
|
||||||
zstdmax = avg + 3 * std;
|
zstdmax = avg + 3 * std;
|
||||||
}
|
}
|
||||||
if (j==2) {
|
if (j == 2)
|
||||||
|
{
|
||||||
zmaxmin = avg - 2 * std;
|
zmaxmin = avg - 2 * std;
|
||||||
zmaxmax = avg + 3 * std;
|
zmaxmax = avg + 3 * std;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer = (unsigned char *) malloc (sizeof (unsigned char) * 4 * n);
|
buffer = (unsigned char *) malloc (sizeof (unsigned char) * 4 * n);
|
||||||
|
|
||||||
for (j=0,l=0;j<img.naxis2;j++) {
|
for (j = 0, l = 0; j < img.naxis2; j++)
|
||||||
for (i=0;i<img.naxis1;i++) {
|
{
|
||||||
|
for (i = 0; i < img.naxis1; i++)
|
||||||
|
{
|
||||||
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
||||||
z = 255.0 * (img.zavg[k] - zavgmin) / (zavgmax - zavgmin);
|
z = 255.0 * (img.zavg[k] - zavgmin) / (zavgmax - zavgmin);
|
||||||
if (z >= 255.0)
|
if (z >= 255.0)
|
||||||
|
@ -180,7 +207,8 @@ void write_composite_pgm(char *filename,struct image img)
|
||||||
z = 0.0;
|
z = 0.0;
|
||||||
buffer[l++] = (unsigned char) z;
|
buffer[l++] = (unsigned char) z;
|
||||||
}
|
}
|
||||||
for (i=0;i<img.naxis1;i++) {
|
for (i = 0; i < img.naxis1; i++)
|
||||||
|
{
|
||||||
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
||||||
z = 255.0 * (img.zstd[k] - zstdmin) / (zstdmax - zstdmin);
|
z = 255.0 * (img.zstd[k] - zstdmin) / (zstdmax - zstdmin);
|
||||||
if (z >= 255.0)
|
if (z >= 255.0)
|
||||||
|
@ -190,8 +218,10 @@ void write_composite_pgm(char *filename,struct image img)
|
||||||
buffer[l++] = (unsigned char) z;
|
buffer[l++] = (unsigned char) z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (j=0;j<img.naxis2;j++) {
|
for (j = 0; j < img.naxis2; j++)
|
||||||
for (i=0;i<img.naxis1;i++) {
|
{
|
||||||
|
for (i = 0; i < img.naxis1; i++)
|
||||||
|
{
|
||||||
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
||||||
z = 255 * (img.zmax[k] - zmaxmin) / (zmaxmax - zmaxmin);
|
z = 255 * (img.zmax[k] - zmaxmin) / (zmaxmax - zmaxmin);
|
||||||
if (z >= 255.0)
|
if (z >= 255.0)
|
||||||
|
@ -200,7 +230,8 @@ void write_composite_pgm(char *filename,struct image img)
|
||||||
z = 0.0;
|
z = 0.0;
|
||||||
buffer[l++] = (unsigned char) z;
|
buffer[l++] = (unsigned char) z;
|
||||||
}
|
}
|
||||||
for (i=0;i<img.naxis1;i++) {
|
for (i = 0; i < img.naxis1; i++)
|
||||||
|
{
|
||||||
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
||||||
z = img.znum[k];
|
z = img.znum[k];
|
||||||
if (z >= 255.0)
|
if (z >= 255.0)
|
||||||
|
@ -219,14 +250,16 @@ void write_composite_pgm(char *filename,struct image img)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write pgm file
|
// Write pgm file
|
||||||
void write_pgm(char *filename,struct image img)
|
void
|
||||||
|
write_pgm (char *filename, struct image img)
|
||||||
{
|
{
|
||||||
int i, j, k, n;
|
int i, j, k, n;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
float s1, s2, z, avg, std, zavgmin, zavgmax;
|
float s1, s2, z, avg, std, zavgmin, zavgmax;
|
||||||
|
|
||||||
n = img.naxis1 * img.naxis2;
|
n = img.naxis1 * img.naxis2;
|
||||||
for (i=0,s1=0.0,s2=0.0;i<n;i++) {
|
for (i = 0, s1 = 0.0, s2 = 0.0; i < n; i++)
|
||||||
|
{
|
||||||
z = img.zavg[i];
|
z = img.zavg[i];
|
||||||
s1 += z;
|
s1 += z;
|
||||||
s2 += z * z;
|
s2 += z * z;
|
||||||
|
@ -237,9 +270,12 @@ void write_pgm(char *filename,struct image img)
|
||||||
zavgmax = avg + 3 * std;
|
zavgmax = avg + 3 * std;
|
||||||
|
|
||||||
file = fopen (filename, "w");
|
file = fopen (filename, "w");
|
||||||
fprintf(file,"P5\n# %.23s\n%d %d\n255\n",img.nfd+1,img.naxis1,img.naxis2);
|
fprintf (file, "P5\n# %.23s\n%d %d\n255\n", img.nfd + 1, img.naxis1,
|
||||||
for (j=0;j<img.naxis2;j++) {
|
img.naxis2);
|
||||||
for (i=0;i<img.naxis1;i++) {
|
for (j = 0; j < img.naxis2; j++)
|
||||||
|
{
|
||||||
|
for (i = 0; i < img.naxis1; i++)
|
||||||
|
{
|
||||||
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
k = i + (img.naxis2 - j - 1) * img.naxis1;
|
||||||
z = 255.0 * (img.zavg[k] - zavgmin) / (zavgmax - zavgmin);
|
z = 255.0 * (img.zavg[k] - zavgmin) / (zavgmax - zavgmin);
|
||||||
if (z > 255.0)
|
if (z > 255.0)
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
#define LIM 256
|
#define LIM 256
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -18,7 +19,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int reverse = 0;
|
int reverse = 0;
|
||||||
char line[LIM], pline[LIM], tlefile[LIM];
|
char line[LIM], pline[LIM], tlefile[LIM];
|
||||||
|
@ -27,8 +29,10 @@ int main(int argc,char *argv[])
|
||||||
int arg = 0;
|
int arg = 0;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"c:rh"))!=-1) {
|
while ((arg = getopt (argc, argv, "c:rh")) != -1)
|
||||||
switch(arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
strcpy (tlefile, optarg);
|
strcpy (tlefile, optarg);
|
||||||
|
@ -45,23 +49,31 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reverse==0) {
|
if (reverse == 0)
|
||||||
|
{
|
||||||
file = fopen (tlefile, "r");
|
file = fopen (tlefile, "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
if (line[0]=='1') {
|
{
|
||||||
|
if (line[0] == '1')
|
||||||
|
{
|
||||||
strcpy (line0, pline);
|
strcpy (line0, pline);
|
||||||
strcpy (line1, line);
|
strcpy (line1, line);
|
||||||
fgetline (file, line, LIM);
|
fgetline (file, line, LIM);
|
||||||
strcpy (line2, line);
|
strcpy (line2, line);
|
||||||
printf ("%s | %s | %s\n", line1, line2, line0);
|
printf ("%s | %s | %s\n", line1, line2, line0);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
strcpy (pline, line);
|
strcpy (pline, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
file = fopen (tlefile, "r");
|
file = fopen (tlefile, "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
printf ("%.70s\n%.70s\n%.70s\n", line + 144, line, line + 72);
|
printf ("%.70s\n%.70s\n%.70s\n", line + 144, line, line + 72);
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
152
src/tle2rv.c
152
src/tle2rv.c
|
@ -18,7 +18,8 @@
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
// Nutation series
|
// Nutation series
|
||||||
static const struct {
|
static const struct
|
||||||
|
{
|
||||||
int nm1, nm, nf, nd, nn;
|
int nm1, nm, nf, nd, nn;
|
||||||
double s, st;
|
double s, st;
|
||||||
double c, ct;
|
double c, ct;
|
||||||
|
@ -132,16 +133,19 @@ static const struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -150,18 +154,22 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -169,22 +177,29 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -193,7 +208,8 @@ double nfd2mjd(char *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nutation
|
// Nutation
|
||||||
void nutation(double mjd,double *dpsi,double *deps,double *eps)
|
void
|
||||||
|
nutation (double mjd, double *dpsi, double *deps, double *eps)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double t, t2, t3;
|
double t, t2, t3;
|
||||||
|
@ -206,17 +222,30 @@ void nutation(double mjd,double *dpsi,double *deps,double *eps)
|
||||||
t3 = t2 * t;
|
t3 = t2 * t;
|
||||||
|
|
||||||
// Angles
|
// Angles
|
||||||
d=modulo(297.85036+445267.111480*t-0.0019142*t2+t3/189474.0,360.0)*D2R;
|
d =
|
||||||
m=modulo(357.52772+35999.050340*t-0.0001603*t2-t3/300000.0,360.0)*D2R;
|
modulo (297.85036 + 445267.111480 * t - 0.0019142 * t2 + t3 / 189474.0,
|
||||||
m1=modulo(134.96298+477198.867398*t+0.0086972*t2+t3/56250.0,360.0)*D2R;
|
360.0) * D2R;
|
||||||
f=modulo(93.27191+483202.017538*t-0.0036825*t2+t3/327270.0,360.0)*D2R;
|
m =
|
||||||
n=modulo(125.04452-1934.136261*t+0.0020708*t2+t3/450000.0,360.0)*D2R;
|
modulo (357.52772 + 35999.050340 * t - 0.0001603 * t2 - t3 / 300000.0,
|
||||||
|
360.0) * D2R;
|
||||||
|
m1 =
|
||||||
|
modulo (134.96298 + 477198.867398 * t + 0.0086972 * t2 + t3 / 56250.0,
|
||||||
|
360.0) * D2R;
|
||||||
|
f =
|
||||||
|
modulo (93.27191 + 483202.017538 * t - 0.0036825 * t2 + t3 / 327270.0,
|
||||||
|
360.0) * D2R;
|
||||||
|
n =
|
||||||
|
modulo (125.04452 - 1934.136261 * t + 0.0020708 * t2 + t3 / 450000.0,
|
||||||
|
360.0) * D2R;
|
||||||
|
|
||||||
// Compute sums
|
// Compute sums
|
||||||
*dpsi = 0.0;
|
*dpsi = 0.0;
|
||||||
*deps = 0.0;
|
*deps = 0.0;
|
||||||
for (i=0;i<106;i++) {
|
for (i = 0; i < 106; i++)
|
||||||
arg=nut[i].nd*d+nut[i].nm*m+nut[i].nm1*m1+nut[i].nf*f+nut[i].nn*n;
|
{
|
||||||
|
arg =
|
||||||
|
nut[i].nd * d + nut[i].nm * m + nut[i].nm1 * m1 + nut[i].nf * f +
|
||||||
|
nut[i].nn * n;
|
||||||
*dpsi += (nut[i].s + nut[i].st * t) * sin (arg);
|
*dpsi += (nut[i].s + nut[i].st * t) * sin (arg);
|
||||||
*deps += (nut[i].c + nut[i].ct * t) * cos (arg);
|
*deps += (nut[i].c + nut[i].ct * t) * cos (arg);
|
||||||
}
|
}
|
||||||
|
@ -229,7 +258,8 @@ void nutation(double mjd,double *dpsi,double *deps,double *eps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precession
|
// Precession
|
||||||
void precess(double mjd0,double mjd,double *zeta,double *z,double *theta)
|
void
|
||||||
|
precess (double mjd0, double mjd, double *zeta, double *z, double *theta)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
|
|
||||||
|
@ -253,12 +283,15 @@ void precess(double mjd0,double mjd,double *zeta,double *z,double *theta)
|
||||||
|
|
||||||
|
|
||||||
// Set identity matrix
|
// Set identity matrix
|
||||||
void identity_matrix(double a[3][3])
|
void
|
||||||
|
identity_matrix (double a[3][3])
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
for (i=0;i<3;i++) {
|
for (i = 0; i < 3; i++)
|
||||||
for (j=0;j<3;j++) {
|
{
|
||||||
|
for (j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
if (i == j)
|
if (i == j)
|
||||||
a[i][j] = 1.0;
|
a[i][j] = 1.0;
|
||||||
else
|
else
|
||||||
|
@ -270,7 +303,8 @@ void identity_matrix(double a[3][3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate around x-axis
|
// Rotate around x-axis
|
||||||
void rotate_x(double phi, double a[3][3])
|
void
|
||||||
|
rotate_x (double phi, double a[3][3])
|
||||||
{
|
{
|
||||||
double s, c, a10, a11, a12, a20, a21, a22;
|
double s, c, a10, a11, a12, a20, a21, a22;
|
||||||
|
|
||||||
|
@ -295,7 +329,8 @@ void rotate_x(double phi, double a[3][3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate around y-axis
|
// Rotate around y-axis
|
||||||
void rotate_y(double phi, double a[3][3])
|
void
|
||||||
|
rotate_y (double phi, double a[3][3])
|
||||||
{
|
{
|
||||||
double s, c, a00, a01, a02, a20, a21, a22;
|
double s, c, a00, a01, a02, a20, a21, a22;
|
||||||
|
|
||||||
|
@ -320,7 +355,8 @@ void rotate_y(double phi, double a[3][3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate around z-axis
|
// Rotate around z-axis
|
||||||
void rotate_z(double phi, double a[3][3])
|
void
|
||||||
|
rotate_z (double phi, double a[3][3])
|
||||||
{
|
{
|
||||||
double s, c, a00, a01, a02, a10, a11, a12;
|
double s, c, a00, a01, a02, a10, a11, a12;
|
||||||
|
|
||||||
|
@ -345,12 +381,15 @@ void rotate_z(double phi, double a[3][3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matrix multiply
|
// Matrix multiply
|
||||||
void matrix_multiply(double a[3][3],double b[3][3],double c[3][3])
|
void
|
||||||
|
matrix_multiply (double a[3][3], double b[3][3], double c[3][3])
|
||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
|
|
||||||
for (i=0;i<3;i++) {
|
for (i = 0; i < 3; i++)
|
||||||
for (j=0;j<3;j++) {
|
{
|
||||||
|
for (j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
c[i][j] = 0.0;
|
c[i][j] = 0.0;
|
||||||
for (k = 0; k < 3; k++)
|
for (k = 0; k < 3; k++)
|
||||||
c[i][j] += a[i][k] * b[k][j];
|
c[i][j] += a[i][k] * b[k][j];
|
||||||
|
@ -361,12 +400,14 @@ void matrix_multiply(double a[3][3],double b[3][3],double c[3][3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vector multiply
|
// Vector multiply
|
||||||
void vector_multiply_in_place(double a[3][3],double b[3])
|
void
|
||||||
|
vector_multiply_in_place (double a[3][3], double b[3])
|
||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
double c[3];
|
double c[3];
|
||||||
|
|
||||||
for (i=0;i<3;i++) {
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
c[i] = 0.0;
|
c[i] = 0.0;
|
||||||
for (j = 0; j < 3; j++)
|
for (j = 0; j < 3; j++)
|
||||||
c[i] += a[i][j] * b[j];
|
c[i] += a[i][j] * b[j];
|
||||||
|
@ -378,11 +419,13 @@ void vector_multiply_in_place(double a[3][3],double b[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vector multiply
|
// Vector multiply
|
||||||
void vector_multiply(double a[3][3],double b[3],double c[3])
|
void
|
||||||
|
vector_multiply (double a[3][3], double b[3], double c[3])
|
||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
|
|
||||||
for (i=0;i<3;i++) {
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
c[i] = 0.0;
|
c[i] = 0.0;
|
||||||
for (j = 0; j < 3; j++)
|
for (j = 0; j < 3; j++)
|
||||||
c[i] += a[i][j] * b[j];
|
c[i] += a[i][j] * b[j];
|
||||||
|
@ -392,7 +435,8 @@ void vector_multiply(double a[3][3],double b[3],double c[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transpose
|
// Transpose
|
||||||
void matrix_transpose(double a[3][3],double b[3][3])
|
void
|
||||||
|
matrix_transpose (double a[3][3], double b[3][3])
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
|
@ -404,19 +448,22 @@ void matrix_transpose(double a[3][3],double b[3][3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dot product
|
// Dot product
|
||||||
double dot_product(double a[3],double b[3])
|
double
|
||||||
|
dot_product (double a[3], double b[3])
|
||||||
{
|
{
|
||||||
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
double magnitude(double a[3])
|
double
|
||||||
|
magnitude (double a[3])
|
||||||
{
|
{
|
||||||
return sqrt (dot_product (a, a));
|
return sqrt (dot_product (a, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross product
|
// Cross product
|
||||||
void cross_product(double a[3],double b[3],double c[3])
|
void
|
||||||
|
cross_product (double a[3], double b[3], double c[3])
|
||||||
{
|
{
|
||||||
c[0] = a[1] * b[2] - a[2] * b[1];
|
c[0] = a[1] * b[2] - a[2] * b[1];
|
||||||
c[1] = a[2] * b[0] - a[0] * b[2];
|
c[1] = a[2] * b[0] - a[0] * b[2];
|
||||||
|
@ -426,7 +473,8 @@ void cross_product(double a[3],double b[3],double c[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// ICRS to TEME conversion
|
// ICRS to TEME conversion
|
||||||
void icrs_to_teme(double mjd,double a[3][3])
|
void
|
||||||
|
icrs_to_teme (double mjd, double a[3][3])
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
double dpsi, deps, eps, z, theta, zeta, h;
|
double dpsi, deps, eps, z, theta, zeta, h;
|
||||||
|
@ -457,7 +505,8 @@ void icrs_to_teme(double mjd,double a[3][3])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf ("tle2rv c:i:t:m:efh\n\n");
|
printf ("tle2rv c:i:t:m:efh\n\n");
|
||||||
printf ("-c Catalog to load [classfd.tle]\n");
|
printf ("-c Catalog to load [classfd.tle]\n");
|
||||||
|
@ -472,7 +521,8 @@ void usage(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int imode, arg, satno = 0, useepoch = 0, format = 0, gmat = 0;
|
int imode, arg, satno = 0, useepoch = 0, format = 0, gmat = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -492,8 +542,10 @@ int main(int argc,char *argv[])
|
||||||
mjd = nfd2mjd (nfd);
|
mjd = nfd2mjd (nfd);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"c:i:t:m:hejg"))!=-1) {
|
while ((arg = getopt (argc, argv, "c:i:t:m:hejg")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (nfd, optarg);
|
strcpy (nfd, optarg);
|
||||||
|
@ -537,7 +589,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (tlefile, "r");
|
file = fopen (tlefile, "r");
|
||||||
while (read_twoline(file,satno,&orb)==0) {
|
while (read_twoline (file, satno, &orb) == 0)
|
||||||
|
{
|
||||||
// Propagate
|
// Propagate
|
||||||
imode = init_sgdp4 (&orb);
|
imode = init_sgdp4 (&orb);
|
||||||
|
|
||||||
|
@ -550,7 +603,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
if (format == 0 && gmat == 0)
|
if (format == 0 && gmat == 0)
|
||||||
printf("%05d %14.8lf %f %f %f %f %f %f TEME\n",orb.satno,mjd,r.x,r.y,r.z,v.x,v.y,v.z);
|
printf ("%05d %14.8lf %f %f %f %f %f %f TEME\n", orb.satno, mjd, r.x,
|
||||||
|
r.y, r.z, v.x, v.y, v.z);
|
||||||
|
|
||||||
// To vectors
|
// To vectors
|
||||||
rr[0] = r.x;
|
rr[0] = r.x;
|
||||||
|
@ -570,10 +624,12 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Output J2000
|
// Output J2000
|
||||||
if (format == 1 && gmat == 0)
|
if (format == 1 && gmat == 0)
|
||||||
printf("%05d %14.8lf %f %f %f %f %f %f J2000\n",orb.satno,mjd,rr[0],rr[1],rr[2],vv[0],vv[1],vv[2]);
|
printf ("%05d %14.8lf %f %f %f %f %f %f J2000\n", orb.satno, mjd,
|
||||||
|
rr[0], rr[1], rr[2], vv[0], vv[1], vv[2]);
|
||||||
|
|
||||||
// GMAT output
|
// GMAT output
|
||||||
if (gmat==1) {
|
if (gmat == 1)
|
||||||
|
{
|
||||||
printf ("UTCModJulian = %14.8lf\n", mjd - 29999.5);
|
printf ("UTCModJulian = %14.8lf\n", mjd - 29999.5);
|
||||||
printf ("CoordinateSystem = EarthMJ2000Eq\n");
|
printf ("CoordinateSystem = EarthMJ2000Eq\n");
|
||||||
printf ("X = %lf\n", rr[0]);
|
printf ("X = %lf\n", rr[0]);
|
||||||
|
|
148
src/tleinfo.c
148
src/tleinfo.c
|
@ -17,18 +17,24 @@
|
||||||
|
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf("usage: tleinfo [-c TLEFILE] [-u] [|-1|-f] [ |-n|-d] [-i SATNO] [-I INTLDESG ] [ |-a|-b] [-H] [-h]\n\n");
|
printf
|
||||||
|
("usage: tleinfo [-c TLEFILE] [-u] [|-1|-f] [ |-n|-d] [-i SATNO] [-I INTLDESG ] [ |-a|-b] [-H] [-h]\n\n");
|
||||||
|
|
||||||
printf("-c TLEFILE The file containing orbital elements in the form of TLEs, 3 lines per object\n");
|
printf
|
||||||
|
("-c TLEFILE The file containing orbital elements in the form of TLEs, 3 lines per object\n");
|
||||||
printf (" default: ./bulk.tle\n");
|
printf (" default: ./bulk.tle\n");
|
||||||
printf("-i SATNO Filter only elements for objects with this NORAD catalog identifier\n");
|
printf
|
||||||
printf("-I INTLDESG Filter only elements for objects with this international designator\n");
|
("-i SATNO Filter only elements for objects with this NORAD catalog identifier\n");
|
||||||
|
printf
|
||||||
|
("-I INTLDESG Filter only elements for objects with this international designator\n");
|
||||||
printf ("-u Show only one object (MODE0 only)\n");
|
printf ("-u Show only one object (MODE0 only)\n");
|
||||||
|
|
||||||
printf ("\nSelect MODE:\n");
|
printf ("\nSelect MODE:\n");
|
||||||
printf(" MODE0: Show TLEs, object names or COSPAR designations\n");
|
printf
|
||||||
|
(" MODE0: Show TLEs, object names or COSPAR designations\n");
|
||||||
printf ("-1 MODE1: Show list of elements (one line per object)\n");
|
printf ("-1 MODE1: Show list of elements (one line per object)\n");
|
||||||
printf ("-f MODE2: Show human-readable parameters\n\n");
|
printf ("-f MODE2: Show human-readable parameters\n\n");
|
||||||
|
|
||||||
|
@ -38,9 +44,11 @@ void usage(void)
|
||||||
printf (" -n Show only the name of the objects\n");
|
printf (" -n Show only the name of the objects\n");
|
||||||
printf (" -d Show only the COSPAR designation of the objects\n\n");
|
printf (" -d Show only the COSPAR designation of the objects\n\n");
|
||||||
printf ("MODE1:\n");
|
printf ("MODE1:\n");
|
||||||
printf(" default SATNO, YEAR, DOY, INCL, ASCN, ARGP, MA, ECC, MM, BSTAR\n");
|
printf
|
||||||
|
(" default SATNO, YEAR, DOY, INCL, ASCN, ARGP, MA, ECC, MM, BSTAR\n");
|
||||||
printf (" -a SATNO, SEMI, PERIGEE, APOGEE, INCL, PERIOD, ECC\n");
|
printf (" -a SATNO, SEMI, PERIGEE, APOGEE, INCL, PERIOD, ECC\n");
|
||||||
printf(" -b SATNO, YEAR, DOY, INCL, ASCN, ARGP, MA, ECC, MM, floor(MJD), LNG_AT_MIDNIGHT\n\n");
|
printf
|
||||||
|
(" -b SATNO, YEAR, DOY, INCL, ASCN, ARGP, MA, ECC, MM, floor(MJD), LNG_AT_MIDNIGHT\n\n");
|
||||||
|
|
||||||
|
|
||||||
printf ("-H Show header (MODE1 only), default: disabled\n");
|
printf ("-H Show header (MODE1 only), default: disabled\n");
|
||||||
|
@ -50,12 +58,14 @@ void usage(void)
|
||||||
double modulo (double x, double y);
|
double modulo (double x, double y);
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -63,17 +73,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOY to MJD
|
// DOY to MJD
|
||||||
double doy2mjd(int year,double doy)
|
double
|
||||||
|
doy2mjd (int year, double doy)
|
||||||
{
|
{
|
||||||
int month, k = 2;
|
int month, k = 2;
|
||||||
double day;
|
double day;
|
||||||
|
@ -86,13 +102,16 @@ double doy2mjd(int year,double doy)
|
||||||
if (doy < 32)
|
if (doy < 32)
|
||||||
month = 1;
|
month = 1;
|
||||||
|
|
||||||
day=doy-floor(275.0*month/9.0)+k*floor((month+9.0)/12.0)+30.0;
|
day =
|
||||||
|
doy - floor (275.0 * month / 9.0) + k * floor ((month + 9.0) / 12.0) +
|
||||||
|
30.0;
|
||||||
|
|
||||||
return date2mjd (year, month, day);
|
return date2mjd (year, month, day);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -104,7 +123,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void orbit(orbit_t orb,float *aodp,float *perigee,float *apogee,float *period)
|
void
|
||||||
|
orbit (orbit_t orb, float *aodp, float *perigee, float *apogee, float *period)
|
||||||
{
|
{
|
||||||
float xno, eo, xincl;
|
float xno, eo, xincl;
|
||||||
float a1, betao2, betao, temp0, del1, a0, del0, xnodp;
|
float a1, betao2, betao, temp0, del1, a0, del0, xnodp;
|
||||||
|
@ -131,7 +151,8 @@ void orbit(orbit_t orb,float *aodp,float *perigee,float *apogee,float *period)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2nfd(double mjd,char *nfd)
|
void
|
||||||
|
mjd2nfd (double mjd, char *nfd)
|
||||||
{
|
{
|
||||||
double f, jd, dday;
|
double f, jd, dday;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -146,7 +167,8 @@ void mjd2nfd(double mjd,char *nfd)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -176,12 +198,14 @@ void mjd2nfd(double mjd,char *nfd)
|
||||||
hour = x;
|
hour = x;
|
||||||
sec = floor (1000.0 * sec) / 1000.0;
|
sec = floor (1000.0 * sec) / 1000.0;
|
||||||
|
|
||||||
sprintf(nfd,"%04d-%02d-%02dT%02d:%02d:%06.3f",year,month,day,hour,min,sec);
|
sprintf (nfd, "%04d-%02d-%02dT%02d:%02d:%06.3f", year, month, day, hour,
|
||||||
|
min, sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float orbital_longitude_at_midnight(orbit_t orb,double mjd0)
|
float
|
||||||
|
orbital_longitude_at_midnight (orbit_t orb, double mjd0)
|
||||||
{
|
{
|
||||||
int rv, imode;
|
int rv, imode;
|
||||||
double jd, tsince, mjd;
|
double jd, tsince, mjd;
|
||||||
|
@ -198,11 +222,14 @@ float orbital_longitude_at_midnight(orbit_t orb,double mjd0)
|
||||||
return modulo (K.theta * R2D, 360.0);
|
return modulo (K.theta * R2D, 360.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int arg=0,satno=0,header=0,oneline=0,no,name=0,desig=0,has_intldesg=0;
|
int arg = 0, satno = 0, header = 0, oneline = 0, no, name = 0, desig =
|
||||||
|
0, has_intldesg = 0;
|
||||||
char tlefile[LIM];
|
char tlefile[LIM];
|
||||||
char line0[LIM],line1[LIM],line2[LIM],nfd[32],intldesg[16]="",desg[16]="";
|
char line0[LIM], line1[LIM], line2[LIM], nfd[32], intldesg[16] =
|
||||||
|
"", desg[16] = "";
|
||||||
FILE *file;
|
FILE *file;
|
||||||
orbit_t orb;
|
orbit_t orb;
|
||||||
float aodp, perigee, apogee, period, lng;
|
float aodp, perigee, apogee, period, lng;
|
||||||
|
@ -214,8 +241,10 @@ int main(int argc,char *argv[])
|
||||||
sprintf (tlefile, "%s/bulk.tle", env);
|
sprintf (tlefile, "%s/bulk.tle", env);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"c:i:I:aH1ftndbu"))!=-1) {
|
while ((arg = getopt (argc, argv, "c:i:I:aH1ftndbu")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
strcpy (tlefile, optarg);
|
strcpy (tlefile, optarg);
|
||||||
|
@ -273,20 +302,24 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oneline==0) {
|
if (oneline == 0)
|
||||||
|
{
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (tlefile, "rb");
|
file = fopen (tlefile, "rb");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
||||||
|
|
||||||
while (fgetline(file,line1,LIM)>0) {
|
while (fgetline (file, line1, LIM) > 0)
|
||||||
|
{
|
||||||
// Find TLE line
|
// Find TLE line
|
||||||
if (line1[0]=='1') {
|
if (line1[0] == '1')
|
||||||
|
{
|
||||||
fgetline (file, line2, LIM);
|
fgetline (file, line2, LIM);
|
||||||
sscanf (line1 + 2, "%d", &no);
|
sscanf (line1 + 2, "%d", &no);
|
||||||
sscanf (line1 + 9, "%s", &desg);
|
sscanf (line1 + 9, "%s", &desg);
|
||||||
|
|
||||||
if ((satno==0 || satno==no) && (has_intldesg==0)) {
|
if ((satno == 0 || satno == no) && (has_intldesg == 0))
|
||||||
|
{
|
||||||
if (name == 1 && desig == 0)
|
if (name == 1 && desig == 0)
|
||||||
printf ("%s\n", line0);
|
printf ("%s\n", line0);
|
||||||
else if (name == 0 && desig == 1)
|
else if (name == 0 && desig == 1)
|
||||||
|
@ -295,8 +328,11 @@ int main(int argc,char *argv[])
|
||||||
printf ("%s\n%s\n%s\n", line0, line1, line2);
|
printf ("%s\n%s\n%s\n", line0, line1, line2);
|
||||||
if (unique == 1)
|
if (unique == 1)
|
||||||
break;
|
break;
|
||||||
} else if (has_intldesg==1) {
|
}
|
||||||
if (strcmp(desg,intldesg)==0) {
|
else if (has_intldesg == 1)
|
||||||
|
{
|
||||||
|
if (strcmp (desg, intldesg) == 0)
|
||||||
|
{
|
||||||
printf ("%s\n%s\n%s\n", line0, line1, line2);
|
printf ("%s\n%s\n%s\n", line0, line1, line2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,35 +367,55 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
fclose (file);
|
fclose (file);
|
||||||
} else if (oneline==1) {
|
}
|
||||||
|
else if (oneline == 1)
|
||||||
|
{
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (tlefile, "rb");
|
file = fopen (tlefile, "rb");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
fatal_error ("File open failed for reading \"%s\"", tlefile);
|
||||||
|
|
||||||
if (header==1) {
|
if (header == 1)
|
||||||
|
{
|
||||||
if (info == 0)
|
if (info == 0)
|
||||||
printf("SATNO YEAR DOY INCL ASCN ARGP MA ECC MM BSTAR\n");
|
printf
|
||||||
|
("SATNO YEAR DOY INCL ASCN ARGP MA ECC MM BSTAR\n");
|
||||||
else if (info == 1)
|
else if (info == 1)
|
||||||
printf ("SATNO SEMI PERIGEE APOGEE PERIOD ECC\n");
|
printf ("SATNO SEMI PERIGEE APOGEE PERIOD ECC\n");
|
||||||
else if (info == 2)
|
else if (info == 2)
|
||||||
printf("SATNO YEAR DOY INCL ASCN ARGP MA ECC MM floor(MJD) LNG_AT_MIDNIGHT\n");
|
printf
|
||||||
|
("SATNO YEAR DOY INCL ASCN ARGP MA ECC MM floor(MJD) LNG_AT_MIDNIGHT\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over file
|
// Loop over file
|
||||||
while (read_twoline(file,satno,&orb)==0) {
|
while (read_twoline (file, satno, &orb) == 0)
|
||||||
|
{
|
||||||
orbit (orb, &aodp, &perigee, &apogee, &period);
|
orbit (orb, &aodp, &perigee, &apogee, &period);
|
||||||
mjd = doy2mjd (orb.ep_year, orb.ep_day);
|
mjd = doy2mjd (orb.ep_year, orb.ep_day);
|
||||||
mjd2nfd (mjd, nfd);
|
mjd2nfd (mjd, nfd);
|
||||||
if (info==0) printf("%05d %10.4lf %8.4f %8.4f %8.4f %8.4f %8.6f %8.5f %e\n",orb.satno,mjd,DEG(orb.eqinc),DEG(orb.ascn),DEG(orb.argp),DEG(orb.mnan),orb.ecc,orb.rev,orb.bstar);
|
if (info == 0)
|
||||||
if (info==1) printf("%05d %6.0f x %6.0f x %6.2f %8.2f %8.6f %14.8lf\n",orb.satno,perigee,apogee,DEG(orb.eqinc),period,orb.ecc,mjd);
|
printf ("%05d %10.4lf %8.4f %8.4f %8.4f %8.4f %8.6f %8.5f %e\n",
|
||||||
if (info==2) {
|
orb.satno, mjd, DEG (orb.eqinc), DEG (orb.ascn),
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.ecc, orb.rev,
|
||||||
|
orb.bstar);
|
||||||
|
if (info == 1)
|
||||||
|
printf ("%05d %6.0f x %6.0f x %6.2f %8.2f %8.6f %14.8lf\n",
|
||||||
|
orb.satno, perigee, apogee, DEG (orb.eqinc), period,
|
||||||
|
orb.ecc, mjd);
|
||||||
|
if (info == 2)
|
||||||
|
{
|
||||||
lng = orbital_longitude_at_midnight (orb, mjd);
|
lng = orbital_longitude_at_midnight (orb, mjd);
|
||||||
printf("%05d %10.4lf %8.4f %8.4f %8.4f %8.4f %8.6f %8.5f %10.4lf %8.4f\n",orb.satno,mjd,DEG(orb.eqinc),DEG(orb.ascn),DEG(orb.argp),DEG(orb.mnan),orb.ecc,orb.rev,floor(mjd),lng);
|
printf
|
||||||
|
("%05d %10.4lf %8.4f %8.4f %8.4f %8.4f %8.6f %8.5f %10.4lf %8.4f\n",
|
||||||
|
orb.satno, mjd, DEG (orb.eqinc), DEG (orb.ascn),
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.ecc, orb.rev,
|
||||||
|
floor (mjd), lng);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
} else if (oneline==2) {
|
}
|
||||||
|
else if (oneline == 2)
|
||||||
|
{
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (tlefile, "rb");
|
file = fopen (tlefile, "rb");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
|
@ -376,10 +432,12 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
62
src/uk2iod.c
62
src/uk2iod.c
|
@ -7,7 +7,8 @@
|
||||||
#define LIM 128
|
#define LIM 128
|
||||||
|
|
||||||
int fgetline (FILE * file, char *s, int lim);
|
int fgetline (FILE * file, char *s, int lim);
|
||||||
int find_satno(char *desig0)
|
int
|
||||||
|
find_satno (char *desig0)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
int satno = 99999, status;
|
int satno = 99999, status;
|
||||||
|
@ -17,11 +18,13 @@ int find_satno(char *desig0)
|
||||||
env = getenv ("ST_DATADIR");
|
env = getenv ("ST_DATADIR");
|
||||||
sprintf (filename, "%s/data/desig.txt", env);
|
sprintf (filename, "%s/data/desig.txt", env);
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Designation file not found!\n");
|
fprintf (stderr, "Designation file not found!\n");
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
while (!feof(file)) {
|
while (!feof (file))
|
||||||
|
{
|
||||||
status = fscanf (file, "%d %s", &satno, desig);
|
status = fscanf (file, "%d %s", &satno, desig);
|
||||||
if (strcmp (desig, desig0) == 0)
|
if (strcmp (desig, desig0) == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -32,11 +35,13 @@ int find_satno(char *desig0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
int intidy,intido,piece,site,year,month,day,hour,min,sec,fsec,satno;
|
int intidy, intido, piece, site, year, month, day, hour, min, sec, fsec,
|
||||||
|
satno;
|
||||||
char desig[16], pdesig[16];
|
char desig[16], pdesig[16];
|
||||||
int format, epoch;
|
int format, epoch;
|
||||||
float csec, cang, x;
|
float csec, cang, x;
|
||||||
|
@ -45,7 +50,8 @@ int main(int argc,char *argv[])
|
||||||
char sign;
|
char sign;
|
||||||
|
|
||||||
file = fopen (argv[1], "r");
|
file = fopen (argv[1], "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
// Skip wrong lines
|
// Skip wrong lines
|
||||||
if (!isdigit (line[0]))
|
if (!isdigit (line[0]))
|
||||||
continue;
|
continue;
|
||||||
|
@ -54,22 +60,18 @@ int main(int argc,char *argv[])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Scan line
|
// Scan line
|
||||||
sscanf(line,"%02d%03d%02d%04d%02d%02d%02d%02d%02d%02d%03d",&intidy,&intido,
|
sscanf (line, "%02d%03d%02d%04d%02d%02d%02d%02d%02d%02d%03d", &intidy,
|
||||||
&piece,
|
&intido, &piece, &site, &year, &month, &day, &hour, &min, &sec,
|
||||||
&site,
|
|
||||||
&year,
|
|
||||||
&month,
|
|
||||||
&day,
|
|
||||||
&hour,
|
|
||||||
&min,
|
|
||||||
&sec,
|
|
||||||
&fsec);
|
&fsec);
|
||||||
sscanf (line + 27, "%f", &csec);
|
sscanf (line + 27, "%f", &csec);
|
||||||
sscanf (line + 33, "%1d", &format);
|
sscanf (line + 33, "%1d", &format);
|
||||||
if (format==2) {
|
if (format == 2)
|
||||||
|
{
|
||||||
sscanf (line + 34, "%02d%02d%d", &rah, &ram, &rafm);
|
sscanf (line + 34, "%02d%02d%d", &rah, &ram, &rafm);
|
||||||
sscanf (line + 42, "%c%02d%02d%d", &sign, &ded, &dem, &defm);
|
sscanf (line + 42, "%c%02d%02d%d", &sign, &ded, &dem, &defm);
|
||||||
} else if (format==3) {
|
}
|
||||||
|
else if (format == 3)
|
||||||
|
{
|
||||||
sscanf (line + 34, "%02d%02d%d", &rah, &ram, &rafm);
|
sscanf (line + 34, "%02d%02d%d", &rah, &ram, &rafm);
|
||||||
sscanf (line + 42, "%c%02d%02d", &sign, &ded, &dem);
|
sscanf (line + 42, "%c%02d%02d", &sign, &ded, &dem);
|
||||||
}
|
}
|
||||||
|
@ -83,21 +85,27 @@ int main(int argc,char *argv[])
|
||||||
year += 2000;
|
year += 2000;
|
||||||
|
|
||||||
// Format designation
|
// Format designation
|
||||||
if (piece<26) {
|
if (piece < 26)
|
||||||
|
{
|
||||||
sprintf (desig, "%02d %03d%c", intidy, intido, piece + 'A' - 1);
|
sprintf (desig, "%02d %03d%c", intidy, intido, piece + 'A' - 1);
|
||||||
sprintf (pdesig, "%02d%03d%c", intidy, intido, piece + 'A' - 1);
|
sprintf (pdesig, "%02d%03d%c", intidy, intido, piece + 'A' - 1);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fprintf (stderr, "Failed to understand designation!\n");
|
fprintf (stderr, "Failed to understand designation!\n");
|
||||||
fprintf (stderr, "%s\n", line);
|
fprintf (stderr, "%s\n", line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test data format
|
// Test data format
|
||||||
if (format==3) {
|
if (format == 3)
|
||||||
|
{
|
||||||
x = dem * 0.6;
|
x = dem * 0.6;
|
||||||
dem = (int) floor (x);
|
dem = (int) floor (x);
|
||||||
defm = (int) (100.0 * (x - dem));
|
defm = (int) (100.0 * (x - dem));
|
||||||
} else if (format!=2) {
|
}
|
||||||
|
else if (format != 2)
|
||||||
|
{
|
||||||
fprintf (stderr, "Angle format not implemented!\n");
|
fprintf (stderr, "Angle format not implemented!\n");
|
||||||
fprintf (stderr, "%s\n", line);
|
fprintf (stderr, "%s\n", line);
|
||||||
continue;
|
continue;
|
||||||
|
@ -141,8 +149,12 @@ int main(int argc,char *argv[])
|
||||||
satno = find_satno (pdesig);
|
satno = find_satno (pdesig);
|
||||||
|
|
||||||
// Format IOD line
|
// Format IOD line
|
||||||
printf("%05d %s %04d G %04d%02d%02d%02d%02d%02d%03d %1.0f%1.0f %d%d ",satno,desig,site,year,month,day,hour,min,sec,fsec,tm,tx,format,epoch);
|
printf
|
||||||
printf("%02d%02d%03d%c%02d%02d%02d %1.0f%1.0f\n",rah,ram,rafm,sign,ded,dem,defm,am,ax);
|
("%05d %s %04d G %04d%02d%02d%02d%02d%02d%03d %1.0f%1.0f %d%d ",
|
||||||
|
satno, desig, site, year, month, day, hour, min, sec, fsec, tm, tx,
|
||||||
|
format, epoch);
|
||||||
|
printf ("%02d%02d%03d%c%02d%02d%02d %1.0f%1.0f\n", rah, ram, rafm, sign,
|
||||||
|
ded, dem, defm, am, ax);
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
|
@ -150,7 +162,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -161,4 +174,3 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
s[i] = '\0';
|
s[i] = '\0';
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
144
src/vadd.c
144
src/vadd.c
|
@ -18,28 +18,33 @@
|
||||||
extern double SGDP4_jd0;
|
extern double SGDP4_jd0;
|
||||||
|
|
||||||
// Dot product
|
// Dot product
|
||||||
float dot(xyz_t a,xyz_t b)
|
float
|
||||||
|
dot (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
double magnitude(xyz_t a)
|
double
|
||||||
|
magnitude (xyz_t a)
|
||||||
{
|
{
|
||||||
return sqrt (dot (a, a));
|
return sqrt (dot (a, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross product
|
// Cross product
|
||||||
xyz_t cross(xyz_t a,xyz_t b)
|
xyz_t
|
||||||
|
cross (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
xyz_t c;
|
xyz_t c;
|
||||||
|
|
||||||
|
@ -51,7 +56,8 @@ xyz_t cross(xyz_t a,xyz_t b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -64,7 +70,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +95,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -98,7 +106,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -106,7 +115,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clasical elements
|
// Clasical elements
|
||||||
orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
orbit_t
|
||||||
|
classel (int ep_year, double ep_day, xyz_t r, xyz_t v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double rm, vm, vm2, rvm, mu = 1.0;;
|
double rm, vm, vm2, rvm, mu = 1.0;;
|
||||||
|
@ -153,7 +163,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
peri += 360.0;
|
peri += 360.0;
|
||||||
|
|
||||||
// Elliptic motion
|
// Elliptic motion
|
||||||
if (ecc<1.0) {
|
if (ecc < 1.0)
|
||||||
|
{
|
||||||
xp = (chi - rm) / ecc;
|
xp = (chi - rm) / ecc;
|
||||||
yp = rvm / ecc * sqrt (chi / mu);
|
yp = rvm / ecc * sqrt (chi / mu);
|
||||||
b = a * sqrt (1.0 - ecc * ecc);
|
b = a * sqrt (1.0 - ecc * ecc);
|
||||||
|
@ -182,7 +193,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
return orb;
|
return orb;
|
||||||
}
|
}
|
||||||
|
|
||||||
orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
orbit_t
|
||||||
|
rv2el (int satno, double mjd, xyz_t r0, xyz_t v0)
|
||||||
{
|
{
|
||||||
int i, imode;
|
int i, imode;
|
||||||
orbit_t orb[5], orb1[5];
|
orbit_t orb[5], orb1[5];
|
||||||
|
@ -199,7 +211,8 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
orb[0] = classel (ep_year, ep_day, r0, v0);
|
orb[0] = classel (ep_year, ep_day, r0, v0);
|
||||||
orb[0].satno = satno;
|
orb[0].satno = satno;
|
||||||
|
|
||||||
for (i=0;i<4;i++) {
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
// Propagate
|
// Propagate
|
||||||
imode = init_sgdp4 (&orb[i]);
|
imode = init_sgdp4 (&orb[i]);
|
||||||
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
||||||
|
@ -235,30 +248,44 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.desig,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1, "1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev);
|
orb.satno, orb.desig, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f 0",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -270,7 +297,8 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present nfd
|
// Present nfd
|
||||||
void nfd_now(char *s)
|
void
|
||||||
|
nfd_now (char *s)
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
|
@ -279,18 +307,22 @@ void nfd_now(char *s)
|
||||||
time (&rawtime);
|
time (&rawtime);
|
||||||
ptm = gmtime (&rawtime);
|
ptm = gmtime (&rawtime);
|
||||||
|
|
||||||
sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
|
sprintf (s, "%04d-%02d-%02dT%02d:%02d:%02d", ptm->tm_year + 1900,
|
||||||
|
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min,
|
||||||
|
ptm->tm_sec);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -298,22 +330,29 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nfd2mjd
|
// nfd2mjd
|
||||||
double nfd2mjd(char *date)
|
double
|
||||||
|
nfd2mjd (char *date)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
double mjd, dday;
|
double mjd, dday;
|
||||||
|
|
||||||
sscanf(date,"%04d-%02d-%02dT%02d:%02d:%02d",&year,&month,&day,&hour,&min,&sec);
|
sscanf (date, "%04d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hour,
|
||||||
|
&min, &sec);
|
||||||
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
dday = day + hour / 24.0 + min / 1440.0 + sec / 86400.0;
|
||||||
|
|
||||||
mjd = date2mjd (year, month, dday);
|
mjd = date2mjd (year, month, dday);
|
||||||
|
@ -321,15 +360,18 @@ double nfd2mjd(char *date)
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void
|
||||||
|
usage (void)
|
||||||
{
|
{
|
||||||
printf("propagate c:i:t:m:\n\nPropagates orbital elements to a new epoch using the SGP4/SDP4 model.\nDefault operation propagates classfd.tle to now,\n\n-c input catalog\n-i Satellite number\n-t New epoch (YYYY-MM-DDTHH:MM:SS)\n-m New epoch (MJD)\n");
|
printf
|
||||||
|
("propagate c:i:t:m:\n\nPropagates orbital elements to a new epoch using the SGP4/SDP4 model.\nDefault operation propagates classfd.tle to now,\n\n-c input catalog\n-i Satellite number\n-t New epoch (YYYY-MM-DDTHH:MM:SS)\n-m New epoch (MJD)\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int imode, satno = 0, arg, satnomin, flag = 0, satnonew = -1;
|
int imode, satno = 0, arg, satnomin, flag = 0, satnonew = -1;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -351,8 +393,10 @@ int main(int argc,char *argv[])
|
||||||
mjd = nfd2mjd (nfd);
|
mjd = nfd2mjd (nfd);
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"c:i:t:m:hv:d:I:"))!=-1) {
|
while ((arg = getopt (argc, argv, "c:i:t:m:hv:d:I:")) != -1)
|
||||||
switch (arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
strcpy (nfd, optarg);
|
strcpy (nfd, optarg);
|
||||||
|
@ -399,7 +443,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (tlefile, "r");
|
file = fopen (tlefile, "r");
|
||||||
while (read_twoline(file,satno,&orb)==0) {
|
while (read_twoline (file, satno, &orb) == 0)
|
||||||
|
{
|
||||||
format_tle (orb, line1, line2);
|
format_tle (orb, line1, line2);
|
||||||
strcpy (desig, orb.desig);
|
strcpy (desig, orb.desig);
|
||||||
|
|
||||||
|
@ -411,19 +456,26 @@ int main(int argc,char *argv[])
|
||||||
n = cross (r, v);
|
n = cross (r, v);
|
||||||
|
|
||||||
// Add velocity
|
// Add velocity
|
||||||
if (strcmp(direction,"prograde")==0) {
|
if (strcmp (direction, "prograde") == 0)
|
||||||
|
{
|
||||||
dv.x = vadd * v.x / magnitude (v);
|
dv.x = vadd * v.x / magnitude (v);
|
||||||
dv.y = vadd * v.y / magnitude (v);
|
dv.y = vadd * v.y / magnitude (v);
|
||||||
dv.z = vadd * v.z / magnitude (v);
|
dv.z = vadd * v.z / magnitude (v);
|
||||||
} else if (strcmp(direction,"radial")==0) {
|
}
|
||||||
|
else if (strcmp (direction, "radial") == 0)
|
||||||
|
{
|
||||||
dv.x = vadd * r.x / magnitude (r);
|
dv.x = vadd * r.x / magnitude (r);
|
||||||
dv.y = vadd * r.y / magnitude (r);
|
dv.y = vadd * r.y / magnitude (r);
|
||||||
dv.z = vadd * r.z / magnitude (r);
|
dv.z = vadd * r.z / magnitude (r);
|
||||||
} else if (strcmp(direction,"normal")==0) {
|
}
|
||||||
|
else if (strcmp (direction, "normal") == 0)
|
||||||
|
{
|
||||||
dv.x = vadd * n.x / magnitude (n);
|
dv.x = vadd * n.x / magnitude (n);
|
||||||
dv.y = vadd * n.y / magnitude (n);
|
dv.y = vadd * n.y / magnitude (n);
|
||||||
dv.z = vadd * n.z / magnitude (n);
|
dv.z = vadd * n.z / magnitude (n);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
dv.x = 0.0;
|
dv.x = 0.0;
|
||||||
dv.y = 0.0;
|
dv.y = 0.0;
|
||||||
dv.z = 0.0;
|
dv.z = 0.0;
|
||||||
|
@ -435,16 +487,20 @@ int main(int argc,char *argv[])
|
||||||
// Convert
|
// Convert
|
||||||
orb = rv2el (orb.satno, mjd, r, v);
|
orb = rv2el (orb.satno, mjd, r, v);
|
||||||
|
|
||||||
if (satnonew==-1) {
|
if (satnonew == -1)
|
||||||
|
{
|
||||||
strcpy (orb.desig, desig);
|
strcpy (orb.desig, desig);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
strcpy (orb.desig, "15999A");
|
strcpy (orb.desig, "15999A");
|
||||||
orb.satno = satnonew;
|
orb.satno = satnonew;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print tle
|
// Print tle
|
||||||
format_tle (orb, line1, line2);
|
format_tle (orb, line1, line2);
|
||||||
printf("%s\n%s\n# %05d + %g m/s %s\n",line1,line2,satno,vadd,direction);
|
printf ("%s\n%s\n# %05d + %g m/s %s\n", line1, line2, satno, vadd,
|
||||||
|
direction);
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,9 @@ double parabolic_root(double,double,double,double);
|
||||||
// tol: tolerance
|
// tol: tolerance
|
||||||
// opt: options
|
// opt: options
|
||||||
// - n: no output
|
// - n: no output
|
||||||
void versafit(int m,int n,double *a,double *da,double (*func)(double *),double dchisq,double tol,char *opt)
|
void
|
||||||
|
versafit (int m, int n, double *a, double *da, double (*func) (double *),
|
||||||
|
double dchisq, double tol, char *opt)
|
||||||
{
|
{
|
||||||
int i, j, k, l, nfunk, kmax = 50;
|
int i, j, k, l, nfunk, kmax = 50;
|
||||||
double chisqmin;
|
double chisqmin;
|
||||||
|
@ -32,19 +34,23 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
double d[2], errcomp;
|
double d[2], errcomp;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
if (strchr(opt,'n')!=NULL) OUTPUT=0;
|
if (strchr (opt, 'n') != NULL)
|
||||||
if (strchr(opt,'e')!=NULL) ERRCOMP=1;
|
OUTPUT = 0;
|
||||||
|
if (strchr (opt, 'e') != NULL)
|
||||||
|
ERRCOMP = 1;
|
||||||
|
|
||||||
// Intialize y
|
// Intialize y
|
||||||
y = (double *) malloc (sizeof (double) * (n + 1));
|
y = (double *) malloc (sizeof (double) * (n + 1));
|
||||||
|
|
||||||
if (dchisq>=0.) {
|
if (dchisq >= 0.)
|
||||||
|
{
|
||||||
// Compute simplex and minimize function
|
// Compute simplex and minimize function
|
||||||
p = simplex (n, a, da);
|
p = simplex (n, a, da);
|
||||||
nfunk = dsmin (p, y, n, tol, func);
|
nfunk = dsmin (p, y, n, tol, func);
|
||||||
|
|
||||||
// Average parameters
|
// Average parameters
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
a[i] = 0.;
|
a[i] = 0.;
|
||||||
for (j = 0; j <= n; j++)
|
for (j = 0; j <= n; j++)
|
||||||
a[i] += p[j][i];
|
a[i] += p[j][i];
|
||||||
|
@ -55,11 +61,13 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
chisqmin = func (a);
|
chisqmin = func (a);
|
||||||
|
|
||||||
// Compute error compensation
|
// Compute error compensation
|
||||||
if (ERRCOMP) errcomp=sqrt(chisqmin/(double) (m-n));
|
if (ERRCOMP)
|
||||||
|
errcomp = sqrt (chisqmin / (double) (m - n));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basic Information
|
// Basic Information
|
||||||
if (OUTPUT) {
|
if (OUTPUT)
|
||||||
|
{
|
||||||
printf ("VersaFIT:\n");
|
printf ("VersaFIT:\n");
|
||||||
if (m != 0)
|
if (m != 0)
|
||||||
printf ("Number of datapoints: %i\n", m);
|
printf ("Number of datapoints: %i\n", m);
|
||||||
|
@ -67,33 +75,40 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
printf ("Chi-squared: %14.5f\n", chisqmin);
|
printf ("Chi-squared: %14.5f\n", chisqmin);
|
||||||
if (m != 0)
|
if (m != 0)
|
||||||
printf ("Reduced Chi-squared: %14.5f\n", chisqmin / (double) (m - n));
|
printf ("Reduced Chi-squared: %14.5f\n", chisqmin / (double) (m - n));
|
||||||
if (ERRCOMP) printf("Error compensation: %.4f\n",errcomp);
|
if (ERRCOMP)
|
||||||
|
printf ("Error compensation: %.4f\n", errcomp);
|
||||||
printf ("Number of iterations: %i\n", nfunk);
|
printf ("Number of iterations: %i\n", nfunk);
|
||||||
|
|
||||||
printf ("\nParameters:\n");
|
printf ("\nParameters:\n");
|
||||||
|
|
||||||
// No error estimation
|
// No error estimation
|
||||||
if (dchisq==0.) {
|
if (dchisq == 0.)
|
||||||
|
{
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
printf (" a(%i): %12.5f\n", i + 1, a[i]);
|
printf (" a(%i): %12.5f\n", i + 1, a[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// With error estimation
|
// With error estimation
|
||||||
if (dchisq!=0.) {
|
if (dchisq != 0.)
|
||||||
|
{
|
||||||
b = (double *) malloc (sizeof (double) * n);
|
b = (double *) malloc (sizeof (double) * n);
|
||||||
db = (double *) malloc (sizeof (double) * n);
|
db = (double *) malloc (sizeof (double) * n);
|
||||||
|
|
||||||
for (i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
if (da[i]!=0.) {
|
{
|
||||||
for (j=0;j<n;j++) {
|
if (da[i] != 0.)
|
||||||
|
{
|
||||||
|
for (j = 0; j < n; j++)
|
||||||
|
{
|
||||||
b[j] = a[j];
|
b[j] = a[j];
|
||||||
db[j] = da[j];
|
db[j] = da[j];
|
||||||
}
|
}
|
||||||
d[0] = -da[i];
|
d[0] = -da[i];
|
||||||
db[i] = 0.;
|
db[i] = 0.;
|
||||||
|
|
||||||
for (k=0;k<kmax;k++) {
|
for (k = 0; k < kmax; k++)
|
||||||
|
{
|
||||||
b[i] = a[i] + d[0];
|
b[i] = a[i] + d[0];
|
||||||
|
|
||||||
// Minimize
|
// Minimize
|
||||||
|
@ -101,7 +116,8 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
nfunk += dsmin (p, y, n, tol, func);
|
nfunk += dsmin (p, y, n, tol, func);
|
||||||
|
|
||||||
// Average parameters
|
// Average parameters
|
||||||
for (l=0;l<n;l++) {
|
for (l = 0; l < n; l++)
|
||||||
|
{
|
||||||
b[l] = 0.;
|
b[l] = 0.;
|
||||||
for (j = 0; j <= n; j++)
|
for (j = 0; j <= n; j++)
|
||||||
b[l] += p[j][l];
|
b[l] += p[j][l];
|
||||||
|
@ -109,13 +125,15 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
}
|
}
|
||||||
d[0] = parabolic_root (d[0], func (b), chisqmin, dchisq);
|
d[0] = parabolic_root (d[0], func (b), chisqmin, dchisq);
|
||||||
|
|
||||||
if (fabs(chisqmin+dchisq-func(b))<tol) break;
|
if (fabs (chisqmin + dchisq - func (b)) < tol)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
d[1] = -d[0];
|
d[1] = -d[0];
|
||||||
db[i] = 0.;
|
db[i] = 0.;
|
||||||
|
|
||||||
for (k=0;k<kmax;k++) {
|
for (k = 0; k < kmax; k++)
|
||||||
|
{
|
||||||
b[i] = a[i] + d[1];
|
b[i] = a[i] + d[1];
|
||||||
|
|
||||||
// Minimize
|
// Minimize
|
||||||
|
@ -123,7 +141,8 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
nfunk += dsmin (p, y, n, tol, func);
|
nfunk += dsmin (p, y, n, tol, func);
|
||||||
|
|
||||||
// Average parameters
|
// Average parameters
|
||||||
for (l=0;l<n;l++) {
|
for (l = 0; l < n; l++)
|
||||||
|
{
|
||||||
b[l] = 0.;
|
b[l] = 0.;
|
||||||
for (j = 0; j <= n; j++)
|
for (j = 0; j <= n; j++)
|
||||||
b[l] += p[j][l];
|
b[l] += p[j][l];
|
||||||
|
@ -131,10 +150,12 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
}
|
}
|
||||||
d[1] = parabolic_root (d[1], func (b), chisqmin, dchisq);
|
d[1] = parabolic_root (d[1], func (b), chisqmin, dchisq);
|
||||||
|
|
||||||
if (fabs(chisqmin+dchisq-func(b))<tol) break;
|
if (fabs (chisqmin + dchisq - func (b)) < tol)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
da[i] = 0.5 * (fabs (d[0]) + fabs (d[1]));
|
da[i] = 0.5 * (fabs (d[0]) + fabs (d[1]));
|
||||||
if (ERRCOMP) da[i]*=errcomp;
|
if (ERRCOMP)
|
||||||
|
da[i] *= errcomp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +163,8 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
printf (" a(%i): %12.5f +- %9.5f\n", i + 1, a[i], da[i]);
|
printf (" a(%i): %12.5f +- %9.5f\n", i + 1, a[i], da[i]);
|
||||||
}
|
}
|
||||||
if (OUTPUT) printf("\nTotal number of iterations: %i\n",nfunk);
|
if (OUTPUT)
|
||||||
|
printf ("\nTotal number of iterations: %i\n", nfunk);
|
||||||
|
|
||||||
// free(p);
|
// free(p);
|
||||||
// free(y);
|
// free(y);
|
||||||
|
@ -153,11 +175,13 @@ void versafit(int m,int n,double *a,double *da,double (*func)(double *),double d
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute root
|
// Compute root
|
||||||
double parabolic_root(double x,double y,double y0,double dy)
|
double
|
||||||
|
parabolic_root (double x, double y, double y0, double dy)
|
||||||
{
|
{
|
||||||
double a;
|
double a;
|
||||||
|
|
||||||
if (fabs(x)<1e-9) {
|
if (fabs (x) < 1e-9)
|
||||||
|
{
|
||||||
printf ("Division by zero in function 'parabolic_root'\n");
|
printf ("Division by zero in function 'parabolic_root'\n");
|
||||||
x = 1e-9;
|
x = 1e-9;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
gettimeofday (&tv, 0);
|
gettimeofday (&tv, 0);
|
||||||
if (tv.tv_usec > 999000)
|
if (tv.tv_usec > 999000)
|
||||||
break;
|
break;
|
||||||
|
|
90
src/wcsfit.c
90
src/wcsfit.c
|
@ -12,7 +12,8 @@
|
||||||
#define R2D 180.0/M_PI
|
#define R2D 180.0/M_PI
|
||||||
#define NMAX 4096
|
#define NMAX 4096
|
||||||
|
|
||||||
struct catalog {
|
struct catalog
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
float x[NMAX], y[NMAX];
|
float x[NMAX], y[NMAX];
|
||||||
double ra[NMAX], de[NMAX];
|
double ra[NMAX], de[NMAX];
|
||||||
|
@ -21,7 +22,8 @@ struct catalog {
|
||||||
float xrms, yrms, rms;
|
float xrms, yrms, rms;
|
||||||
int usage[NMAX];
|
int usage[NMAX];
|
||||||
};
|
};
|
||||||
struct image {
|
struct image
|
||||||
|
{
|
||||||
int naxis1, naxis2, nframes;
|
int naxis1, naxis2, nframes;
|
||||||
float *zavg, *zstd, *zmax, *znum;
|
float *zavg, *zstd, *zmax, *znum;
|
||||||
double ra0, de0;
|
double ra0, de0;
|
||||||
|
@ -30,21 +32,25 @@ struct image {
|
||||||
double mjd;
|
double mjd;
|
||||||
float *dt;
|
float *dt;
|
||||||
};
|
};
|
||||||
struct transformation {
|
struct transformation
|
||||||
|
{
|
||||||
double ra0, de0;
|
double ra0, de0;
|
||||||
float a[3], b[3];
|
float a[3], b[3];
|
||||||
float x0, y0;
|
float x0, y0;
|
||||||
};
|
};
|
||||||
int fgetline (FILE * file, char *s, int lim);
|
int fgetline (FILE * file, char *s, int lim);
|
||||||
void forward(double ra0,double de0,double ra,double de,double *x,double *y);
|
void forward (double ra0, double de0, double ra, double de, double *x,
|
||||||
void reverse(double ra0,double de0,double x,double y,double *ra,double *de);
|
double *y);
|
||||||
|
void reverse (double ra0, double de0, double x, double y, double *ra,
|
||||||
|
double *de);
|
||||||
struct catalog read_catalog (char *filename);
|
struct catalog read_catalog (char *filename);
|
||||||
void lfit2d (float *x, float *y, float *z, int n, float *a);
|
void lfit2d (float *x, float *y, float *z, int n, float *a);
|
||||||
void add_fits_keywords (struct transformation t, char *filename);
|
void add_fits_keywords (struct transformation t, char *filename);
|
||||||
struct image read_fits (char *filename);
|
struct image read_fits (char *filename);
|
||||||
|
|
||||||
// Modify FITS keywords
|
// Modify FITS keywords
|
||||||
void modify_fits_keywords(struct transformation t,char *filename)
|
void
|
||||||
|
modify_fits_keywords (struct transformation t, char *filename)
|
||||||
{
|
{
|
||||||
char card[FITS_LINESZ + 1];
|
char card[FITS_LINESZ + 1];
|
||||||
char key[FITS_LINESZ + 1];
|
char key[FITS_LINESZ + 1];
|
||||||
|
@ -87,7 +93,8 @@ void modify_fits_keywords(struct transformation t,char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
struct catalog c;
|
struct catalog c;
|
||||||
|
@ -114,15 +121,20 @@ int main(int argc,char *argv[])
|
||||||
t.x0 = (float) img.naxis1 / 2.0;
|
t.x0 = (float) img.naxis1 / 2.0;
|
||||||
t.y0 = (float) img.naxis2 / 2.0;
|
t.y0 = (float) img.naxis2 / 2.0;
|
||||||
|
|
||||||
for (l=0;l<10;l++) {
|
for (l = 0; l < 10; l++)
|
||||||
for (j=0;j<5;j++) {
|
{
|
||||||
|
for (j = 0; j < 5; j++)
|
||||||
|
{
|
||||||
// Transform
|
// Transform
|
||||||
for (i=0;i<c.n;i++) {
|
for (i = 0; i < c.n; i++)
|
||||||
|
{
|
||||||
forward (t.ra0, t.de0, c.ra[i], c.de[i], &c.rx[i], &c.ry[i]);
|
forward (t.ra0, t.de0, c.ra[i], c.de[i], &c.rx[i], &c.ry[i]);
|
||||||
}
|
}
|
||||||
// Select
|
// Select
|
||||||
for (i=0,k=0;i<c.n;i++) {
|
for (i = 0, k = 0; i < c.n; i++)
|
||||||
if (c.usage[i]==1) {
|
{
|
||||||
|
if (c.usage[i] == 1)
|
||||||
|
{
|
||||||
x[k] = c.x[i];
|
x[k] = c.x[i];
|
||||||
y[k] = c.y[i];
|
y[k] = c.y[i];
|
||||||
rx[k] = c.rx[i];
|
rx[k] = c.rx[i];
|
||||||
|
@ -134,7 +146,8 @@ int main(int argc,char *argv[])
|
||||||
// Fit
|
// Fit
|
||||||
lfit2d (x, y, rx, k, t.a);
|
lfit2d (x, y, rx, k, t.a);
|
||||||
lfit2d (x, y, ry, k, t.b);
|
lfit2d (x, y, ry, k, t.b);
|
||||||
printf("%f %f %f %f %f %f %f %f\n",t.ra0,t.de0,t.a[0],t.a[1],t.a[2],t.b[0],t.b[1],t.b[2]);
|
printf ("%f %f %f %f %f %f %f %f\n", t.ra0, t.de0, t.a[0], t.a[1],
|
||||||
|
t.a[2], t.b[0], t.b[1], t.b[2]);
|
||||||
|
|
||||||
// Move reference point
|
// Move reference point
|
||||||
reverse (t.ra0, t.de0, t.a[0], t.b[0], &ra0, &de0);
|
reverse (t.ra0, t.de0, t.a[0], t.b[0], &ra0, &de0);
|
||||||
|
@ -143,11 +156,16 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute and plot residuals
|
// Compute and plot residuals
|
||||||
for (i=0,c.xrms=0.0,c.yrms=0.0,m=0;i<c.n;i++) {
|
for (i = 0, c.xrms = 0.0, c.yrms = 0.0, m = 0; i < c.n; i++)
|
||||||
if (c.usage[i]==1) {
|
{
|
||||||
c.xres[i]=c.rx[i]-(t.a[0]+t.a[1]*c.x[i]+t.a[2]*c.y[i]);
|
if (c.usage[i] == 1)
|
||||||
c.yres[i]=c.ry[i]-(t.b[0]+t.b[1]*c.x[i]+t.b[2]*c.y[i]);
|
{
|
||||||
printf("%12.4f %12.4f %12.4f %12.4f %10.4f %10.4f\n",c.x[i],c.y[i],c.rx[i],c.ry[i],c.xres[i],c.yres[i]);
|
c.xres[i] =
|
||||||
|
c.rx[i] - (t.a[0] + t.a[1] * c.x[i] + t.a[2] * c.y[i]);
|
||||||
|
c.yres[i] =
|
||||||
|
c.ry[i] - (t.b[0] + t.b[1] * c.x[i] + t.b[2] * c.y[i]);
|
||||||
|
printf ("%12.4f %12.4f %12.4f %12.4f %10.4f %10.4f\n", c.x[i],
|
||||||
|
c.y[i], c.rx[i], c.ry[i], c.xres[i], c.yres[i]);
|
||||||
c.res[i] = sqrt (c.xres[i] * c.xres[i] + c.yres[i] * c.yres[i]);
|
c.res[i] = sqrt (c.xres[i] * c.xres[i] + c.yres[i] * c.yres[i]);
|
||||||
c.xrms += c.xres[i] * c.xres[i];
|
c.xrms += c.xres[i] * c.xres[i];
|
||||||
c.yrms += c.yres[i] * c.yres[i];
|
c.yrms += c.yres[i] * c.yres[i];
|
||||||
|
@ -160,12 +178,14 @@ int main(int argc,char *argv[])
|
||||||
c.rms = sqrt (c.rms / (float) m);
|
c.rms = sqrt (c.rms / (float) m);
|
||||||
|
|
||||||
// Deselect outliers
|
// Deselect outliers
|
||||||
for (i=0;i<c.n;i++) {
|
for (i = 0; i < c.n; i++)
|
||||||
|
{
|
||||||
if (c.res[i] > 2 * c.rms)
|
if (c.res[i] > 2 * c.rms)
|
||||||
c.usage[i] = 0;
|
c.usage[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%12.8lf %10.6lf %10.6lf %8.4f %8.4f %8.4f %8.4f\n",img.mjd,t.ra0,t.de0,t.a[1],t.a[2],t.b[1],t.b[2]);
|
printf ("%12.8lf %10.6lf %10.6lf %8.4f %8.4f %8.4f %8.4f\n", img.mjd, t.ra0,
|
||||||
|
t.de0, t.a[1], t.a[2], t.b[1], t.b[2]);
|
||||||
printf ("%d/%d %f %f %f\n", m, c.n, c.xrms, c.yrms, c.rms);
|
printf ("%d/%d %f %f %f\n", m, c.n, c.xrms, c.yrms, c.rms);
|
||||||
|
|
||||||
// add_fits_keywords(t,"test.fits");
|
// add_fits_keywords(t,"test.fits");
|
||||||
|
@ -175,7 +195,8 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -188,7 +209,8 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read catalog
|
// Read catalog
|
||||||
struct catalog read_catalog(char *filename)
|
struct catalog
|
||||||
|
read_catalog (char *filename)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -196,7 +218,8 @@ struct catalog read_catalog(char *filename)
|
||||||
struct catalog c;
|
struct catalog c;
|
||||||
|
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
sscanf (line, "%f %f %lf %lf", &c.x[i], &c.y[i], &c.ra[i], &c.de[i]);
|
sscanf (line, "%f %f %lf %lf", &c.x[i], &c.y[i], &c.ra[i], &c.de[i]);
|
||||||
c.usage[i] = 1;
|
c.usage[i] = 1;
|
||||||
|
|
||||||
|
@ -209,7 +232,8 @@ struct catalog read_catalog(char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linear 2D fit
|
// Linear 2D fit
|
||||||
void lfit2d(float *x,float *y,float *z,int n,float *a)
|
void
|
||||||
|
lfit2d (float *x, float *y, float *z, int n, float *a)
|
||||||
{
|
{
|
||||||
int i, j, m;
|
int i, j, m;
|
||||||
double chisq;
|
double chisq;
|
||||||
|
@ -224,7 +248,8 @@ void lfit2d(float *x,float *y,float *z,int n,float *a)
|
||||||
cov = gsl_matrix_alloc (3, 3);
|
cov = gsl_matrix_alloc (3, 3);
|
||||||
|
|
||||||
// Fill matrices
|
// Fill matrices
|
||||||
for(i=0;i<n;i++) {
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
gsl_matrix_set (X, i, 0, 1.0);
|
gsl_matrix_set (X, i, 0, 1.0);
|
||||||
gsl_matrix_set (X, i, 1, x[i]);
|
gsl_matrix_set (X, i, 1, x[i]);
|
||||||
gsl_matrix_set (X, i, 2, y[i]);
|
gsl_matrix_set (X, i, 2, y[i]);
|
||||||
|
@ -252,7 +277,8 @@ void lfit2d(float *x,float *y,float *z,int n,float *a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add FITS keywords
|
// Add FITS keywords
|
||||||
void add_fits_keywords(struct transformation t,char *filename)
|
void
|
||||||
|
add_fits_keywords (struct transformation t, char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
int naxis1, naxis2, naxis3;
|
int naxis1, naxis2, naxis3;
|
||||||
|
@ -278,7 +304,8 @@ void add_fits_keywords(struct transformation t,char *filename)
|
||||||
ql.xtnum = 0;
|
ql.xtnum = 0;
|
||||||
ql.ptype = PTYPE_FLOAT;
|
ql.ptype = PTYPE_FLOAT;
|
||||||
ql.filename = filename;
|
ql.filename = filename;
|
||||||
for (k=0,l=0;k<naxis3;k++) {
|
for (k = 0, l = 0; k < naxis3; k++)
|
||||||
|
{
|
||||||
ql.pnum = k;
|
ql.pnum = k;
|
||||||
// Initialize load
|
// Initialize load
|
||||||
if (qfitsloader_init (&ql) != 0)
|
if (qfitsloader_init (&ql) != 0)
|
||||||
|
@ -288,8 +315,10 @@ void add_fits_keywords(struct transformation t,char *filename)
|
||||||
if (qfits_loadpix (&ql) != 0)
|
if (qfits_loadpix (&ql) != 0)
|
||||||
printf ("Error loading actual data\n");
|
printf ("Error loading actual data\n");
|
||||||
|
|
||||||
for (i=0,m=0;i<naxis1;i++) {
|
for (i = 0, m = 0; i < naxis1; i++)
|
||||||
for (j=0;j<naxis2;j++) {
|
{
|
||||||
|
for (j = 0; j < naxis2; j++)
|
||||||
|
{
|
||||||
fbuf[l] = ql.fbuf[m];
|
fbuf[l] = ql.fbuf[m];
|
||||||
l++;
|
l++;
|
||||||
m++;
|
m++;
|
||||||
|
@ -337,7 +366,8 @@ void add_fits_keywords(struct transformation t,char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fits image
|
// Read fits image
|
||||||
struct image read_fits(char *filename)
|
struct image
|
||||||
|
read_fits (char *filename)
|
||||||
{
|
{
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
qfitsloader ql;
|
qfitsloader ql;
|
||||||
|
|
197
src/xyz2tle.c
197
src/xyz2tle.c
|
@ -17,33 +17,39 @@
|
||||||
#define AE 1.0
|
#define AE 1.0
|
||||||
#define XMNPDA 1440.0
|
#define XMNPDA 1440.0
|
||||||
|
|
||||||
struct data {
|
struct data
|
||||||
|
{
|
||||||
int n, nsel;
|
int n, nsel;
|
||||||
struct point *p;
|
struct point *p;
|
||||||
double chisq, rms;
|
double chisq, rms;
|
||||||
} d;
|
} d;
|
||||||
struct point {
|
struct point
|
||||||
|
{
|
||||||
int flag;
|
int flag;
|
||||||
double mjd;
|
double mjd;
|
||||||
xyz_t r;
|
xyz_t r;
|
||||||
};
|
};
|
||||||
orbit_t orb;
|
orbit_t orb;
|
||||||
void versafit(int m,int n,double *a,double *da,double (*func)(double *),double dchisq,double tol,char *opt);
|
void versafit (int m, int n, double *a, double *da, double (*func) (double *),
|
||||||
|
double dchisq, double tol, char *opt);
|
||||||
|
|
||||||
// Dot product
|
// Dot product
|
||||||
float dot(xyz_t a,xyz_t b)
|
float
|
||||||
|
dot (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magnitude
|
// Magnitude
|
||||||
double magnitude(xyz_t a)
|
double
|
||||||
|
magnitude (xyz_t a)
|
||||||
{
|
{
|
||||||
return sqrt (dot (a, a));
|
return sqrt (dot (a, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross product
|
// Cross product
|
||||||
xyz_t cross(xyz_t a,xyz_t b)
|
xyz_t
|
||||||
|
cross (xyz_t a, xyz_t b)
|
||||||
{
|
{
|
||||||
xyz_t c;
|
xyz_t c;
|
||||||
|
|
||||||
|
@ -55,21 +61,25 @@ xyz_t cross(xyz_t a,xyz_t b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return x modulo y [0,y)
|
// Return x modulo y [0,y)
|
||||||
double modulo(double x,double y)
|
double
|
||||||
|
modulo (double x, double y)
|
||||||
{
|
{
|
||||||
x = fmod (x, y);
|
x = fmod (x, y);
|
||||||
if (x<0.0) x+=y;
|
if (x < 0.0)
|
||||||
|
x += y;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Julian Day from Date
|
// Compute Julian Day from Date
|
||||||
double date2mjd(int year,int month,double day)
|
double
|
||||||
|
date2mjd (int year, int month, double day)
|
||||||
{
|
{
|
||||||
int a, b;
|
int a, b;
|
||||||
double jd;
|
double jd;
|
||||||
|
|
||||||
if (month<3) {
|
if (month < 3)
|
||||||
|
{
|
||||||
year--;
|
year--;
|
||||||
month += 12;
|
month += 12;
|
||||||
}
|
}
|
||||||
|
@ -77,17 +87,23 @@ double date2mjd(int year,int month,double day)
|
||||||
a = floor (year / 100.);
|
a = floor (year / 100.);
|
||||||
b = 2. - a + floor (a / 4.);
|
b = 2. - a + floor (a / 4.);
|
||||||
|
|
||||||
if (year<1582) b=0;
|
if (year < 1582)
|
||||||
if (year==1582 && month<10) b=0;
|
b = 0;
|
||||||
if (year==1582 && month==10 && day<=4) b=0;
|
if (year == 1582 && month < 10)
|
||||||
|
b = 0;
|
||||||
|
if (year == 1582 && month == 10 && day <= 4)
|
||||||
|
b = 0;
|
||||||
|
|
||||||
jd=floor(365.25*(year+4716))+floor(30.6001*(month+1))+day+b-1524.5;
|
jd =
|
||||||
|
floor (365.25 * (year + 4716)) + floor (30.6001 * (month + 1)) + day + b -
|
||||||
|
1524.5;
|
||||||
|
|
||||||
return jd - 2400000.5;
|
return jd - 2400000.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a line of maximum length int lim from file FILE into string s
|
// Read a line of maximum length int lim from file FILE into string s
|
||||||
int fgetline(FILE *file,char *s,int lim)
|
int
|
||||||
|
fgetline (FILE * file, char *s, int lim)
|
||||||
{
|
{
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
|
|
||||||
|
@ -102,30 +118,44 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format TLE
|
// Format TLE
|
||||||
void format_tle(orbit_t orb,char *line1,char *line2)
|
void
|
||||||
|
format_tle (orbit_t orb, char *line1, char *line2)
|
||||||
{
|
{
|
||||||
int i, csum;
|
int i, csum;
|
||||||
char sbstar[] = " 00000-0", bstar[13];
|
char sbstar[] = " 00000-0", bstar[13];
|
||||||
|
|
||||||
// Format Bstar term
|
// Format Bstar term
|
||||||
if (fabs(orb.bstar)>1e-9) {
|
if (fabs (orb.bstar) > 1e-9)
|
||||||
|
{
|
||||||
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
sprintf (bstar, "%11.4e", 10 * orb.bstar);
|
||||||
sbstar[0] = bstar[0]; sbstar[1] = bstar[1]; sbstar[2] = bstar[3]; sbstar[3] = bstar[4];
|
sbstar[0] = bstar[0];
|
||||||
sbstar[4] = bstar[5]; sbstar[5] = bstar[6]; sbstar[6] = bstar[8]; sbstar[7] = bstar[10]; sbstar[8] = '\0';
|
sbstar[1] = bstar[1];
|
||||||
|
sbstar[2] = bstar[3];
|
||||||
|
sbstar[3] = bstar[4];
|
||||||
|
sbstar[4] = bstar[5];
|
||||||
|
sbstar[5] = bstar[6];
|
||||||
|
sbstar[6] = bstar[8];
|
||||||
|
sbstar[7] = bstar[10];
|
||||||
|
sbstar[8] = '\0';
|
||||||
}
|
}
|
||||||
// Print lines
|
// Print lines
|
||||||
sprintf(line1,"1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",orb.satno,orb.desig,orb.ep_year-2000,orb.ep_day,sbstar);
|
sprintf (line1, "1 %05dU %-8s %2d%012.8f .00000000 00000-0 %8s 0 0",
|
||||||
sprintf(line2,"2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f%5ld",orb.satno,DEG(orb.eqinc),DEG(orb.ascn),1E7*orb.ecc,DEG(orb.argp),DEG(orb.mnan),orb.rev,orb.norb);
|
orb.satno, orb.desig, orb.ep_year - 2000, orb.ep_day, sbstar);
|
||||||
|
sprintf (line2, "2 %05d %8.4f %8.4f %07.0f %8.4f %8.4f %11.8f%5ld",
|
||||||
|
orb.satno, DEG (orb.eqinc), DEG (orb.ascn), 1E7 * orb.ecc,
|
||||||
|
DEG (orb.argp), DEG (orb.mnan), orb.rev, orb.norb);
|
||||||
|
|
||||||
// Compute checksums
|
// Compute checksums
|
||||||
for (i=0,csum=0;i<strlen(line1);i++) {
|
for (i = 0, csum = 0; i < strlen (line1); i++)
|
||||||
|
{
|
||||||
if (isdigit (line1[i]))
|
if (isdigit (line1[i]))
|
||||||
csum += line1[i] - '0';
|
csum += line1[i] - '0';
|
||||||
else if (line1[i] == '-')
|
else if (line1[i] == '-')
|
||||||
csum++;
|
csum++;
|
||||||
}
|
}
|
||||||
sprintf (line1, "%s%d", line1, csum % 10);
|
sprintf (line1, "%s%d", line1, csum % 10);
|
||||||
for (i=0,csum=0;i<strlen(line2);i++) {
|
for (i = 0, csum = 0; i < strlen (line2); i++)
|
||||||
|
{
|
||||||
if (isdigit (line2[i]))
|
if (isdigit (line2[i]))
|
||||||
csum += line2[i] - '0';
|
csum += line2[i] - '0';
|
||||||
else if (line2[i] == '-')
|
else if (line2[i] == '-')
|
||||||
|
@ -137,7 +167,9 @@ void format_tle(orbit_t orb,char *line1,char *line2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precess a celestial position
|
// Precess a celestial position
|
||||||
void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
void
|
||||||
|
precess (double mjd0, double ra0, double de0, double mjd, double *ra,
|
||||||
|
double *de)
|
||||||
{
|
{
|
||||||
double t0, t;
|
double t0, t;
|
||||||
double zeta, z, theta;
|
double zeta, z, theta;
|
||||||
|
@ -178,7 +210,8 @@ void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read data file
|
// Read data file
|
||||||
struct data read_data(char *filename,double mjd0)
|
struct data
|
||||||
|
read_data (char *filename, double mjd0)
|
||||||
{
|
{
|
||||||
int i = 0, status;
|
int i = 0, status;
|
||||||
char line[LIM];
|
char line[LIM];
|
||||||
|
@ -190,7 +223,8 @@ struct data read_data(char *filename,double mjd0)
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
file = fopen (filename, "r");
|
file = fopen (filename, "r");
|
||||||
if (file==NULL) {
|
if (file == NULL)
|
||||||
|
{
|
||||||
fprintf (stderr, "Failed to open %s\n", filename);
|
fprintf (stderr, "Failed to open %s\n", filename);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
@ -208,7 +242,8 @@ struct data read_data(char *filename,double mjd0)
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
i = 0;
|
i = 0;
|
||||||
while (fgetline(file,line,LIM)>0) {
|
while (fgetline (file, line, LIM) > 0)
|
||||||
|
{
|
||||||
status = sscanf (line, "%d,%lf,%lf,%lf", &min, &x, &y, &z);
|
status = sscanf (line, "%d,%lf,%lf,%lf", &min, &x, &y, &z);
|
||||||
if (d.n == 1008)
|
if (d.n == 1008)
|
||||||
min *= 10;
|
min *= 10;
|
||||||
|
@ -235,7 +270,8 @@ struct data read_data(char *filename,double mjd0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read tle
|
// Read tle
|
||||||
orbit_t read_tle(char *filename,int satno)
|
orbit_t
|
||||||
|
read_tle (char *filename, int satno)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
@ -253,7 +289,8 @@ orbit_t read_tle(char *filename,int satno)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chi-squared
|
// Chi-squared
|
||||||
double chisq(double *a)
|
double
|
||||||
|
chisq (double *a)
|
||||||
{
|
{
|
||||||
int i, imode, n;
|
int i, imode, n;
|
||||||
double chisq;
|
double chisq;
|
||||||
|
@ -270,10 +307,13 @@ double chisq(double *a)
|
||||||
|
|
||||||
if (a[2] < 0.0)
|
if (a[2] < 0.0)
|
||||||
a[2] = 0.0;
|
a[2] = 0.0;
|
||||||
if (a[0]<0.0) {
|
if (a[0] < 0.0)
|
||||||
|
{
|
||||||
a[0] *= -1;
|
a[0] *= -1;
|
||||||
a[1] += 180.0;
|
a[1] += 180.0;
|
||||||
} else if (a[0]>180.0) {
|
}
|
||||||
|
else if (a[0] > 180.0)
|
||||||
|
{
|
||||||
a[0] = 180.0;
|
a[0] = 180.0;
|
||||||
}
|
}
|
||||||
if (a[5] > 20.0)
|
if (a[5] > 20.0)
|
||||||
|
@ -296,7 +336,8 @@ double chisq(double *a)
|
||||||
printf ("Error\n");
|
printf ("Error\n");
|
||||||
|
|
||||||
// Loop over points
|
// Loop over points
|
||||||
for (i=0,chisq=0.0,n=0;i<d.n;i++) {
|
for (i = 0, chisq = 0.0, n = 0; i < d.n; i++)
|
||||||
|
{
|
||||||
// Skip unflagged positions
|
// Skip unflagged positions
|
||||||
if (d.p[i].flag != 1)
|
if (d.p[i].flag != 1)
|
||||||
continue;
|
continue;
|
||||||
|
@ -320,21 +361,27 @@ double chisq(double *a)
|
||||||
return chisq;
|
return chisq;
|
||||||
}
|
}
|
||||||
|
|
||||||
double decode_filename(char *filename,int *satno)
|
double
|
||||||
|
decode_filename (char *filename, int *satno)
|
||||||
{
|
{
|
||||||
int year, month, day, hour, min, sec;
|
int year, month, day, hour, min, sec;
|
||||||
int status;
|
int status;
|
||||||
double mjd;
|
double mjd;
|
||||||
|
|
||||||
status=sscanf(filename,"%6d_%4d%2d%2d_%2d%2d%2d",satno,&year,&month,&day,&hour,&min,&sec);
|
status =
|
||||||
|
sscanf (filename, "%6d_%4d%2d%2d_%2d%2d%2d", satno, &year, &month, &day,
|
||||||
|
&hour, &min, &sec);
|
||||||
|
|
||||||
mjd=date2mjd(year,month,(double) day+hour/24.0+min/1440.0+sec/86400.0);
|
mjd =
|
||||||
|
date2mjd (year, month,
|
||||||
|
(double) day + hour / 24.0 + min / 1440.0 + sec / 86400.0);
|
||||||
|
|
||||||
return mjd;
|
return mjd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute Date from Julian Day
|
// Compute Date from Julian Day
|
||||||
void mjd2date(double mjd,int *year,int *month,double *day)
|
void
|
||||||
|
mjd2date (double mjd, int *year, int *month, double *day)
|
||||||
{
|
{
|
||||||
double f, jd;
|
double f, jd;
|
||||||
int z, alpha, a, b, c, d, e;
|
int z, alpha, a, b, c, d, e;
|
||||||
|
@ -347,7 +394,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
|
|
||||||
if (z < 2299161)
|
if (z < 2299161)
|
||||||
a = z;
|
a = z;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
alpha = floor ((z - 1867216.25) / 36524.25);
|
alpha = floor ((z - 1867216.25) / 36524.25);
|
||||||
a = z + 1 + alpha - floor (alpha / 4.);
|
a = z + 1 + alpha - floor (alpha / 4.);
|
||||||
}
|
}
|
||||||
|
@ -371,7 +419,8 @@ void mjd2date(double mjd,int *year,int *month,double *day)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MJD to DOY
|
// MJD to DOY
|
||||||
double mjd2doy(double mjd,int *yr)
|
double
|
||||||
|
mjd2doy (double mjd, int *yr)
|
||||||
{
|
{
|
||||||
int year, month, k = 2;
|
int year, month, k = 2;
|
||||||
double day, doy;
|
double day, doy;
|
||||||
|
@ -381,7 +430,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
if (year % 4 == 0 && year % 400 != 0)
|
if (year % 4 == 0 && year % 400 != 0)
|
||||||
k = 1;
|
k = 1;
|
||||||
|
|
||||||
doy=floor(275.0*month/9.0)-k*floor((month+9.0)/12.0)+day-30;
|
doy =
|
||||||
|
floor (275.0 * month / 9.0) - k * floor ((month + 9.0) / 12.0) + day - 30;
|
||||||
|
|
||||||
*yr = year;
|
*yr = year;
|
||||||
|
|
||||||
|
@ -389,7 +439,8 @@ double mjd2doy(double mjd,int *yr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clasical elements
|
// Clasical elements
|
||||||
orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
orbit_t
|
||||||
|
classel (int ep_year, double ep_day, xyz_t r, xyz_t v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double rm, vm, vm2, rvm, mu = 1.0;;
|
double rm, vm, vm2, rvm, mu = 1.0;;
|
||||||
|
@ -436,7 +487,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
peri += 360.0;
|
peri += 360.0;
|
||||||
|
|
||||||
// Elliptic motion
|
// Elliptic motion
|
||||||
if (ecc<1.0) {
|
if (ecc < 1.0)
|
||||||
|
{
|
||||||
xp = (chi - rm) / ecc;
|
xp = (chi - rm) / ecc;
|
||||||
yp = rvm / ecc * sqrt (chi / mu);
|
yp = rvm / ecc * sqrt (chi / mu);
|
||||||
b = a * sqrt (1.0 - ecc * ecc);
|
b = a * sqrt (1.0 - ecc * ecc);
|
||||||
|
@ -466,7 +518,8 @@ orbit_t classel(int ep_year,double ep_day,xyz_t r,xyz_t v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// State vector to SGP4 elements
|
// State vector to SGP4 elements
|
||||||
orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
orbit_t
|
||||||
|
rv2el (int satno, double mjd, xyz_t r0, xyz_t v0)
|
||||||
{
|
{
|
||||||
int i, imode;
|
int i, imode;
|
||||||
orbit_t orb[5], orb1[5];
|
orbit_t orb[5], orb1[5];
|
||||||
|
@ -483,7 +536,8 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
orb[0] = classel (ep_year, ep_day, r0, v0);
|
orb[0] = classel (ep_year, ep_day, r0, v0);
|
||||||
orb[0].satno = satno;
|
orb[0].satno = satno;
|
||||||
|
|
||||||
for (i=0;i<4;i++) {
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
// Propagate
|
// Propagate
|
||||||
imode = init_sgdp4 (&orb[i]);
|
imode = init_sgdp4 (&orb[i]);
|
||||||
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
imode = satpos_xyz (mjd + 2400000.5, &r, &v);
|
||||||
|
@ -519,7 +573,8 @@ orbit_t rv2el(int satno,double mjd,xyz_t r0,xyz_t v0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fit
|
// Fit
|
||||||
void fit(orbit_t orb,int *ia)
|
void
|
||||||
|
fit (orbit_t orb, int *ia)
|
||||||
{
|
{
|
||||||
int i, n;
|
int i, n;
|
||||||
double a[7], da[7];
|
double a[7], da[7];
|
||||||
|
@ -538,7 +593,8 @@ void fit(orbit_t orb,int *ia)
|
||||||
a[5] = orb.rev;
|
a[5] = orb.rev;
|
||||||
a[6] = orb.bstar;
|
a[6] = orb.bstar;
|
||||||
|
|
||||||
for (i=0;i<7;i++) {
|
for (i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
if (ia[i] == 1)
|
if (ia[i] == 1)
|
||||||
da[i] = db[i];
|
da[i] = db[i];
|
||||||
else
|
else
|
||||||
|
@ -574,7 +630,8 @@ void fit(orbit_t orb,int *ia)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, k, arg = 0, satno = 0, satname = 0, usecatalog = 0, imode, m = 10;
|
int i, j, k, arg = 0, satno = 0, satname = 0, usecatalog = 0, imode, m = 10;
|
||||||
long norb;
|
long norb;
|
||||||
|
@ -587,8 +644,10 @@ int main(int argc,char *argv[])
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
// Decode options
|
// Decode options
|
||||||
while ((arg=getopt(argc,argv,"d:c:i:n:m:"))!=-1) {
|
while ((arg = getopt (argc, argv, "d:c:i:n:m:")) != -1)
|
||||||
switch(arg) {
|
{
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
datafile = optarg;
|
datafile = optarg;
|
||||||
|
@ -634,7 +693,8 @@ int main(int argc,char *argv[])
|
||||||
sprintf (filename, "%06d.xyz", satname);
|
sprintf (filename, "%06d.xyz", satname);
|
||||||
file = fopen (filename, "w");
|
file = fopen (filename, "w");
|
||||||
for (i = 0; i < d.n; i++)
|
for (i = 0; i < d.n; i++)
|
||||||
fprintf(file,"%lf %f %f %f\n",d.p[i].mjd,d.p[i].r.x,d.p[i].r.y,d.p[i].r.z);
|
fprintf (file, "%lf %f %f %f\n", d.p[i].mjd, d.p[i].r.x, d.p[i].r.y,
|
||||||
|
d.p[i].r.z);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
// Open elements
|
// Open elements
|
||||||
|
@ -643,7 +703,8 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
// Estimate orbit
|
// Estimate orbit
|
||||||
k = 504;
|
k = 504;
|
||||||
if (usecatalog==0) {
|
if (usecatalog == 0)
|
||||||
|
{
|
||||||
// Set initial state vector
|
// Set initial state vector
|
||||||
r.x = d.p[k].r.x;
|
r.x = d.p[k].r.x;
|
||||||
r.y = d.p[k].r.y;
|
r.y = d.p[k].r.y;
|
||||||
|
@ -656,7 +717,9 @@ int main(int argc,char *argv[])
|
||||||
orb = rv2el (99999, d.p[k].mjd, r, v);
|
orb = rv2el (99999, d.p[k].mjd, r, v);
|
||||||
strcpy (orb.desig, "14999A");
|
strcpy (orb.desig, "14999A");
|
||||||
orb.norb = norb;
|
orb.norb = norb;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Read orbit
|
// Read orbit
|
||||||
orb = read_tle (catalog, satno);
|
orb = read_tle (catalog, satno);
|
||||||
strcpy (desig, orb.desig);
|
strcpy (desig, orb.desig);
|
||||||
|
@ -678,14 +741,22 @@ int main(int argc,char *argv[])
|
||||||
d.p[j].flag = 1;
|
d.p[j].flag = 1;
|
||||||
|
|
||||||
// Fit orbit
|
// Fit orbit
|
||||||
for (j=0;j<10;j++) {
|
for (j = 0; j < 10; j++)
|
||||||
if (j==1) ia[4]=1;
|
{
|
||||||
if (j==2) ia[1]=1;
|
if (j == 1)
|
||||||
if (j==3) ia[0]=1;
|
ia[4] = 1;
|
||||||
if (j==4) ia[5]=1;
|
if (j == 2)
|
||||||
if (j==5) ia[3]=1;
|
ia[1] = 1;
|
||||||
if (j==6) ia[2]=1;
|
if (j == 3)
|
||||||
if (j==7) ia[6]=1;
|
ia[0] = 1;
|
||||||
|
if (j == 4)
|
||||||
|
ia[5] = 1;
|
||||||
|
if (j == 5)
|
||||||
|
ia[3] = 1;
|
||||||
|
if (j == 6)
|
||||||
|
ia[2] = 1;
|
||||||
|
if (j == 7)
|
||||||
|
ia[6] = 1;
|
||||||
fit (orb, ia);
|
fit (orb, ia);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,8 +769,12 @@ int main(int argc,char *argv[])
|
||||||
// Format TLE
|
// Format TLE
|
||||||
format_tle (orb, line1, line2);
|
format_tle (orb, line1, line2);
|
||||||
|
|
||||||
fprintf(file,"SO %6d %4.1f %7.0fkm x%7.0fkm\n%s\n%s\n# %d positions, %.1f km rms\n",satname,mag+dm,perigee,apogee,line1,line2,d.nsel,d.rms);
|
fprintf (file,
|
||||||
printf("SO %6d %4.1f %7.0fkm x%7.0fkm\n%s\n%s\n# %d positions, %.1f km rms\n",satname,mag+dm,perigee,apogee,line1,line2,d.nsel,d.rms);
|
"SO %6d %4.1f %7.0fkm x%7.0fkm\n%s\n%s\n# %d positions, %.1f km rms\n",
|
||||||
|
satname, mag + dm, perigee, apogee, line1, line2, d.nsel, d.rms);
|
||||||
|
printf
|
||||||
|
("SO %6d %4.1f %7.0fkm x%7.0fkm\n%s\n%s\n# %d positions, %.1f km rms\n",
|
||||||
|
satname, mag + dm, perigee, apogee, line1, line2, d.nsel, d.rms);
|
||||||
|
|
||||||
// Close output file
|
// Close output file
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
Loading…
Reference in New Issue