00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_WCS
00029
00030
00031
00032
00033
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <math.h>
00038 #include <float.h>
00039
00040 #include <cpl_wcs.h>
00041 #include <cpl.h>
00042
00043
00044 #define NSK 2
00045 #define NDK 13
00046 #define NIK 3
00047
00048
00049
00050 #define fors_cpl_test(bool) \
00051 ((bool) ? (cpl_msg_debug(__FILE__, \
00052 "OK in line %d (CPL-error state: '%s' in %s): %s",__LINE__, \
00053 cpl_error_get_message(), cpl_error_get_where(), #bool), 0) \
00054 : (cpl_msg_error(__FILE__, \
00055 "Failure in line %d (CPL-error state: '%s' in %s): %s",__LINE__, \
00056 cpl_error_get_message(), cpl_error_get_where(), #bool), 1))
00057
00058
00059
00060
00061
00062 static const char *skeys[NSK] = {"CTYPE1", "CTYPE2"};
00063
00064 static const char *dkeys[NDK] = {"CRVAL1", "CRVAL2", "CRPIX1", "CRPIX2",
00065 "CD1_1", "CD1_2", "CD2_1", "CD2_2", "PV2_1",
00066 "PV2_2", "PV2_3", "PV2_4", "PV2_5"};
00067 static const char *ikeys[NIK] = {"NAXIS","NAXIS1","NAXIS2"};
00068
00069
00070 static const char *svals[NSK] = {"RA---ZPN", "DEC--ZPN"};
00071 static const double dvals[NDK] = {5.57368333333, -72.0576388889, 5401.6, 6860.8,
00072 5.81347849634012E-21, 9.49444444444444E-05,
00073 -9.49444444444444E-05, -5.81347849634012E-21,
00074 1.0, 0.0, 42.0, 0.0, 0.0};
00075 static const int ivals[NIK] = {2, 2048, 2048};
00076
00077 #define NP 2
00078 static double physin[2*NP] = {1024.0, 1024.0, 1025.0, 1023.0};
00079
00080 static double worldout[2*NP] = {3.825029720, -71.636524754,
00081 3.824722171, -71.636616487};
00082 static double stdcout[2] = {-0.554171733, 0.415628800};
00083
00084
00085 static double worldin[2] = {3.824875946, -71.636570620};
00086 static double physout[2] = {1024.5, 1023.5};
00087
00088
00089 int main (void) {
00090 cpl_boolean is_debug;
00091 int i,nfail;
00092 cpl_propertylist *pl;
00093 cpl_wcs *wcs;
00094 cpl_matrix *from,*to;
00095 cpl_array *status;
00096 double d1,d2;
00097
00098
00099
00100 cpl_init(CPL_INIT_DEFAULT);
00101 cpl_msg_set_level(CPL_MSG_WARNING);
00102 cpl_msg_set_level_from_env();
00103 cpl_msg_set_domain_off();
00104 is_debug = cpl_msg_get_level() <= CPL_MSG_DEBUG ? TRUE : FALSE;
00105
00106
00107
00108 pl = cpl_propertylist_new();
00109 for (i = 0; i < NSK; i++)
00110 cpl_propertylist_append_string(pl,skeys[i],svals[i]);
00111 for (i = 0; i < NDK; i++)
00112 cpl_propertylist_append_double(pl,dkeys[i],dvals[i]);
00113
00114
00115
00116
00117 nfail = 0;
00118 wcs = cpl_wcs_new_from_propertylist(NULL);
00119 nfail += fors_cpl_test(cpl_error_get_code() == CPL_ERROR_NULL_INPUT);
00120 nfail += fors_cpl_test(wcs == NULL);
00121 cpl_error_reset();
00122 if (wcs != NULL)
00123 cpl_wcs_delete(wcs);
00124 wcs = cpl_wcs_new_from_propertylist(pl);
00125 nfail += fors_cpl_test(cpl_error_get_code() == CPL_ERROR_NONE);
00126 nfail += fors_cpl_test(wcs != NULL);
00127 cpl_error_reset();
00128 if (wcs != NULL)
00129 cpl_wcs_delete(wcs);
00130
00131
00132
00133 for (i = 0; i < NIK; i++)
00134 cpl_propertylist_append_int(pl,ikeys[i],ivals[i]);
00135
00136
00137
00138 wcs = cpl_wcs_new_from_propertylist(pl);
00139 nfail += fors_cpl_test(wcs != NULL);
00140 cpl_propertylist_delete(pl);
00141
00142
00143
00144 nfail += fors_cpl_test(cpl_wcs_convert(NULL,NULL,&to,&status,
00145 CPL_WCS_PHYS2WORLD) == CPL_ERROR_NULL_INPUT);
00146 cpl_error_reset();
00147 nfail += fors_cpl_test(cpl_wcs_convert(wcs,NULL,&to,&status,
00148 CPL_WCS_PHYS2WORLD) == CPL_ERROR_NULL_INPUT);
00149 cpl_error_reset();
00150
00151
00152
00153 cpl_msg_info("","Transform physical -> world (2 points)");
00154 from = cpl_matrix_wrap(NP,2,physin);
00155 cpl_wcs_convert(wcs,from,&to,&status,CPL_WCS_PHYS2WORLD);
00156 nfail += (cpl_error_get_code() != CPL_ERROR_NONE);
00157 cpl_error_reset();
00158 cpl_matrix_unwrap(from);
00159
00160
00161
00162
00163 for (i = 0; i < NP; i++)
00164 nfail += fors_cpl_test(cpl_array_get_data_int(status)[i] == 0);
00165 d1 = fabs(worldout[0] - cpl_matrix_get(to,0,0));
00166 d2 = fabs(worldout[1] - cpl_matrix_get(to,0,1));
00167 cpl_msg_info("","phys1,phys2: %15.9f %15.9f",physin[0],physin[1]);
00168 cpl_msg_info("","world1,world2: %15.9f %15.9f",worldout[0],worldout[1]);
00169 cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,0,0),
00170 cpl_matrix_get(to,0,1));
00171 cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2);
00172 cpl_msg_info("","status: %d",(cpl_array_get_data_int(status)[0]));
00173 nfail += fors_cpl_test(d1 < 1.0e-6);
00174 nfail += fors_cpl_test(d2 < 1.0e-6);
00175 d1 = fabs(worldout[2] - cpl_matrix_get(to,1,0));
00176 d2 = fabs(worldout[3] - cpl_matrix_get(to,1,1));
00177 cpl_msg_info("","phys1,phys2: %15.9f %15.9f",physin[2],physin[3]);
00178 cpl_msg_info("","world1,world2: %15.9f %15.9f",worldout[2],worldout[3]);
00179 cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,1,0),
00180 cpl_matrix_get(to,1,1));
00181 cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2);
00182 cpl_msg_info("","status: %d",
00183 (cpl_array_get_data_int(status)[1]));
00184 nfail += fors_cpl_test(d1 < 1.0e-6);
00185 nfail += fors_cpl_test(d2 < 1.0e-6);
00186 cpl_matrix_delete(to);
00187 cpl_array_delete(status);
00188
00189
00190
00191 cpl_msg_info("","Transform world -> physical");
00192 from = cpl_matrix_wrap(1,2,worldin);
00193
00194 cpl_wcs_convert(wcs,from,&to,&status,CPL_WCS_WORLD2PHYS);
00195 nfail += (cpl_error_get_code() != CPL_ERROR_NONE);
00196 cpl_error_reset();
00197 cpl_matrix_unwrap(from);
00198
00199
00200
00201 nfail += fors_cpl_test(cpl_array_get_data_int(status)[0] == 0);
00202 d1 = fabs(physout[0] - cpl_matrix_get(to,0,0));
00203 d2 = fabs(physout[1] - cpl_matrix_get(to,0,1));
00204 cpl_msg_info("","world1,world2: %15.9f %15.9f",worldin[0],worldin[1]);
00205 cpl_msg_info("","phys1,phys2: %15.9f %15.9f",physout[0],physout[1]);
00206 cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,0,0),
00207 cpl_matrix_get(to,0,1));
00208 cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2);
00209 cpl_msg_info("","status: %d",(cpl_array_get_data_int(status)[0]));
00210 nfail += fors_cpl_test(d1 < 2.5e-4);
00211 nfail += fors_cpl_test(d2 < 2.5e-4);
00212 cpl_matrix_delete(to);
00213 cpl_array_delete(status);
00214
00215
00216
00217 cpl_msg_info("","Transform physical -> standard");
00218 from = cpl_matrix_wrap(1,2,physin);
00219
00220
00221 cpl_wcs_convert(wcs,from,&to,&status,CPL_WCS_PHYS2STD);
00222 nfail += (cpl_error_get_code() != CPL_ERROR_NONE);
00223 cpl_error_reset();
00224 cpl_matrix_unwrap(from);
00225
00226
00227
00228 nfail += fors_cpl_test(cpl_array_get_data_int(status)[0] == 0);
00229 d1 = fabs(stdcout[0] - cpl_matrix_get(to,0,0));
00230 d2 = fabs(stdcout[1] - cpl_matrix_get(to,0,1));
00231 cpl_msg_info("","phys1,phys2: %15.9f %15.9f",physin[0],physin[1]);
00232 cpl_msg_info("","std1,std2: %15.9f %15.9f",stdcout[0],stdcout[1]);
00233 cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,0,0),
00234 cpl_matrix_get(to,0,1));
00235 cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2);
00236 cpl_msg_info("","status: %d",(cpl_array_get_data_int(status)[0]));
00237 nfail += fors_cpl_test(d1 < 1.7e-9);
00238 nfail += fors_cpl_test(d2 < 1.7e-9);
00239 cpl_matrix_delete(to);
00240 cpl_array_delete(status);
00241
00242
00243
00244 cpl_msg_info("","Transform world -> standard");
00245 from = cpl_matrix_wrap(1,2,worldout);
00246
00247
00248 cpl_wcs_convert(wcs,from,&to,&status,CPL_WCS_WORLD2STD);
00249 nfail += (cpl_error_get_code() != CPL_ERROR_NONE);
00250 cpl_error_reset();
00251 cpl_matrix_unwrap(from);
00252
00253
00254
00255 nfail += fors_cpl_test(cpl_array_get_data_int(status)[0] == 0);
00256 d1 = fabs(stdcout[0] - cpl_matrix_get(to,0,0));
00257 d2 = fabs(stdcout[1] - cpl_matrix_get(to,0,1));
00258 cpl_msg_info("","world1,world2: %15.9f %15.9f",worldout[0],worldout[1]);
00259 cpl_msg_info("","std1,std2: %15.9f %15.9f",stdcout[0],stdcout[1]);
00260 cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,0,0),
00261 cpl_matrix_get(to,0,1));
00262 cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2);
00263 cpl_msg_info("","status: %d",(cpl_array_get_data_int(status)[0]));
00264 nfail += fors_cpl_test(d1 < 1.7e-9);
00265 nfail += fors_cpl_test(d2 < 1.7e-9);
00266 cpl_matrix_delete(to);
00267 cpl_array_delete(status);
00268
00269
00270
00271 cpl_wcs_delete(wcs);
00272
00273
00274
00275
00276 nfail += fors_cpl_test(cpl_memory_is_empty());
00277
00278
00279
00280 cpl_msg_info("","%d test(s) failed",nfail);
00281
00282
00283
00284 if (is_debug || !cpl_memory_is_empty())
00285 cpl_memory_dump();
00286 cpl_end();
00287 return(nfail);
00288 }
00289
00290
00291 #else
00292
00293 #include <test.h>
00294 #include <cpl.h>
00295 #include <stdio.h>
00296 #include <stdlib.h>
00297 int main(void)
00298 {
00299 TEST_INIT;
00300
00301 cpl_msg_info(cpl_func, "WCS module not available");
00302
00303 TEST_END;
00304 }
00305
00306 #endif
00307
00308
00309
00310
00311
00312