00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <math.h>
00025
00026 #define DTOR (M_PI/180.)
00027
00028
00029 enum staggeredGrids {
00030 COE, CE, CO, TE, PE
00031 };
00032
00033
00034 void sizeofGrid(enum staggeredGrids grid, int n, int m, int *cols, int *rows)
00035 {
00036 switch (grid) {
00037 case COE:
00038 *cols = n + 1; *rows = m + 1;
00039 break;
00040 case CE:
00041 *cols = n; *rows = m;
00042 break;
00043 case CO:
00044 *cols = n - 1; *rows = m - 1;
00045 break;
00046 case TE:
00047 *cols = n; *rows = m + 1;
00048 break;
00049 case PE:
00050 *cols = n + 1; *rows = m;
00051 break;
00052 default:
00053 *cols = n + 1; *rows = m + 1;
00054 break;
00055 }
00056 }
00057
00058
00059
00060
00061
00062 void pdfi2wcs(int n, int m,
00063 enum staggeredGrids grid,
00064 double a, double b, double c, double d,
00065 double *crval1, double *crval2,
00066 double *crpix1, double *crpix2,
00067 double *cdelt1, double *cdelt2)
00068 {
00069 int cols, rows;
00070 sizeofGrid(grid, n, m, &cols, &rows);
00071
00072 double minlat = 90. - b / DTOR;
00073 double maxlat = 90. - a / DTOR;
00074 double minlon = c / DTOR;
00075 double maxlon = d / DTOR;
00076
00077 *crval1 = (minlon + maxlon) / 2.;
00078 *crval2 = (minlat + maxlat) / 2.;
00079 *crpix1 = (1. + cols) / 2.;
00080 *crpix2 = (1. + rows) / 2.;
00081 *cdelt1 = (maxlon - minlon) / (cols - 1.);
00082 *cdelt2 = (maxlat - minlat) / (rows - 1.);
00083 }
00084
00085
00086
00087
00088
00089 void wcs2pdfi(int n, int m,
00090 enum staggeredGrids grid,
00091 double crval1, double crval2,
00092 double crpix1, double crpix2,
00093 double cdelt1, double cdelt2,
00094 double *a, double *b, double *c, double *d)
00095 {
00096 int cols, rows;
00097 sizeofGrid(grid, n, m, &cols, &rows);
00098
00099 double minlat = crval2 + (1. - crpix2) * cdelt2;
00100 double maxlat = crval2 + (rows - crpix2) * cdelt2;
00101 double minlon = crval1 + (1. - crpix1) * cdelt1;
00102 double maxlon = crval1 + (cols - crpix1) * cdelt1;
00103
00104 *a = (90. - maxlat) * DTOR;
00105 *b = (90. - minlat) * DTOR;
00106 *c = minlon * DTOR;
00107 *d = maxlon * DTOR;
00108 }