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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 #ifdef HAVE_CONFIG_H
00081 # include <config.h>
00082 #endif
00083
00084 #include <uves_response_utils.h>
00085 #include <uves_utils_wrappers.h>
00086 #include <uves_pfits.h>
00087 #include <uves_error.h>
00088
00089 #include <irplib_test.h>
00090 #include <cpl.h>
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00104
00107
00111
00112 static void
00113 test_3dtable(void)
00114 {
00115
00116 cpl_table *flux_table = NULL;
00117 uves_propertylist *raw_header = NULL;
00118 cpl_array *values = NULL;
00119 int depth = 10;
00120 int nrow = 2;
00121 const char *object[] = {"first std", "another standard star"};
00122 const char *type [] = {"NULL", "type 2"};
00123 const double lambda[] = {8000, 2000};
00124 const double fluxes[] = {1000000, 200};
00125 const double bin_width[] = {0.8, 0.0003};
00126 const double ra[] = {10, 80};
00127 const double dec[] = {-8, 0};
00128
00129 cpl_table *cat_flux = NULL;
00130 char *ref_name = NULL;
00131
00132 int i;
00133
00134
00135 flux_table = cpl_table_new(nrow);
00136
00137 cpl_table_new_column(flux_table, "RA_DEG", CPL_TYPE_DOUBLE);
00138 cpl_table_new_column(flux_table, "DEC_DEG", CPL_TYPE_DOUBLE);
00139
00140 cpl_table_new_column(flux_table, "OBJECT", CPL_TYPE_STRING);
00141 cpl_table_new_column(flux_table, "TYPE", CPL_TYPE_STRING);
00142
00143 cpl_table_new_column(flux_table, "NDATA", CPL_TYPE_INT);
00144
00145 cpl_table_new_column_array(flux_table, "LAMBDA", CPL_TYPE_FLOAT, depth);
00146 cpl_table_new_column_array(flux_table, "BIN_WIDTH", CPL_TYPE_FLOAT, depth);
00147 cpl_table_new_column_array(flux_table, "F_LAMBDA", CPL_TYPE_FLOAT, depth);
00148
00149 values = cpl_array_new(depth, CPL_TYPE_FLOAT);
00150
00151 for (i = 0; i < nrow; i++)
00152 {
00153 cpl_table_set_double(flux_table, "RA_DEG", i, ra[i]);
00154 cpl_table_set_double(flux_table, "DEC_DEG", i, dec[i]);
00155 cpl_table_set_string(flux_table, "OBJECT", i, object[i]);
00156 cpl_table_set_string(flux_table, "TYPE", i, type[i]);
00157 cpl_table_set_int (flux_table, "NDATA", i, depth);
00158
00159 cpl_array_fill_window_float(values, 0, depth, lambda[i]);
00160 cpl_table_set_array(flux_table, "LAMBDA", i, values);
00161
00162 cpl_array_fill_window_float(values, 0, depth, bin_width[i]);
00163 cpl_table_set_array(flux_table, "BIN_WIDTH", i, values);
00164
00165 cpl_array_fill_window_float(values, 0, depth, fluxes[i]);
00166 cpl_table_set_array(flux_table, "F_LAMBDA", i, values);
00167 }
00168
00169
00170 raw_header = uves_propertylist_new();
00171
00172
00173
00174 for (i = 0; i < nrow; i++)
00175 {
00176 double paccuracy = 60;
00177 double residual = 30;
00178
00179 uves_pfits_set_ra (raw_header, ra[i]+residual/3600);
00180 uves_pfits_set_dec(raw_header, dec[i]-residual/3600);
00181
00182 uves_free_table(&cat_flux);
00183 cpl_free(ref_name); ref_name = NULL;
00184 check_nomsg( cat_flux = uves_align(raw_header,
00185 flux_table,
00186 paccuracy,
00187 &ref_name));
00188
00189
00190
00191 while(ref_name[strlen(ref_name)-1] == ' ')
00192 {
00193
00194 ref_name[strlen(ref_name)-1] = '\0';
00195 }
00196
00197
00198
00199 assure( cpl_table_get_nrow(cat_flux) == depth, CPL_ERROR_ILLEGAL_OUTPUT,
00200 "Flux table has %d rows, %d expected",
00201 cpl_table_get_nrow(cat_flux), depth);
00202
00203 assure( strcmp(ref_name, object[i]) == 0, CPL_ERROR_ILLEGAL_OUTPUT,
00204 "Found '%s'; Expected '%s'", ref_name, object[i]);
00205
00206 #if 0
00207 assure( float_equal(cpl_table_get_column_mean(cat_flux, "LAMBDA"),
00208 lambda[i], 0.001),
00209 CPL_ERROR_ILLEGAL_OUTPUT,
00210 "LAMBDA = %f; Expected = %f",
00211 cpl_table_get_column_mean(cat_flux, "LAMBDA"), lambda[i]);
00212
00213 assure( float_equal(cpl_table_get_column_mean(cat_flux, "BIN_WIDTH"),
00214 bin_width[i], 0.001),
00215 CPL_ERROR_ILLEGAL_OUTPUT,
00216 "BIN_WIDTH = %f; Expected = %f",
00217 cpl_table_get_column_mean(cat_flux, "BIN_WIDTH"), bin_width[i]);
00218
00219 assure( float_equal(cpl_table_get_column_mean(cat_flux, "F_LAMBDA"),
00220 fluxes[i], 0.001),
00221 CPL_ERROR_ILLEGAL_OUTPUT,
00222 "F_LAMBDA = %f; Expected = %f",
00223 cpl_table_get_column_mean(cat_flux, "F_LAMBDA"), fluxes[i]);
00224 #endif
00225 irplib_test_rel(cpl_table_get_column_mean(cat_flux, "LAMBDA"),
00226 lambda[i], 0.001);
00227
00228 irplib_test_rel(cpl_table_get_column_mean(cat_flux, "BIN_WIDTH"),
00229 bin_width[i], 0.001);
00230
00231 irplib_test_rel(cpl_table_get_column_mean(cat_flux, "F_LAMBDA"),
00232 fluxes[i], 0.001);
00233 }
00234
00235 cleanup:
00236 uves_free_table(&flux_table);
00237 uves_free_table(&cat_flux);
00238 uves_free_array(&values);
00239 uves_free_propertylist(&raw_header);
00240 cpl_free(ref_name);
00241
00242
00243 return;
00244 }
00245
00246
00250
00251
00252 int main(void)
00253 {
00254 IRPLIB_TEST_INIT;
00255
00256 check_nomsg( test_3dtable() );
00257
00258 cleanup:
00259 IRPLIB_TEST_END;
00260 }
00261