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
00081
00082
00083
00084
00085
00086
00087
00088
00089 #ifdef HAVE_CONFIG_H
00090 # include <config.h>
00091 #endif
00092
00093 #include <uves_response_utils.h>
00094 #include <uves_utils_wrappers.h>
00095 #include <uves_pfits.h>
00096 #include <uves_error.h>
00097 #include <uves_msg.h>
00098
00099 #include <cpl_test.h>
00100 #include <cpl.h>
00101 #include <string.h>
00102
00103
00104
00105
00106
00107
00108
00109
00110
00114
00116
00120
00121 static void
00122 test_load_3dtable(void)
00123 {
00124 cpl_table *flux_table = NULL;
00125 const char* dir_name="/media/VERBATIM/data7/flames/flames_uves_demo/ref/";
00126 const char* tab_name="flxstd.fits";
00127 char res_name[80];
00128 char ref_name[25];
00129 char ref_type[25];
00130
00131 char full_name[256];
00132 int nraws=0;
00133 int i=0;
00134 double ref_ra=0;
00135 double ref_dec=0;
00136 double dist=0;
00137 uves_propertylist* header=NULL;
00138 const char *columns[3] = {"LAMBDA", "BIN_WIDTH", "F_LAMBDA"};
00139 int ndata;
00140 int j=0;
00141 cpl_table* result=NULL;
00142 sprintf(full_name,"%s%s",dir_name,tab_name);
00143 uves_msg("full name: %s",full_name);
00144 flux_table=cpl_table_load(full_name,1,0);
00145 nraws=cpl_table_get_nrow(flux_table);
00146 header=uves_propertylist_load(full_name,0);
00147
00148 uves_msg("std: name \t type \t ra \t dec");
00149 for(i=0;i<nraws; i++) {
00150
00151 check( ref_ra = cpl_table_get_double(flux_table, "RA_DEG", i, NULL),
00152 "Could not read catalogue star right ascension");
00153
00154 check( ref_dec = cpl_table_get_double(flux_table, "DEC_DEG", i, NULL),
00155 "Could not read catalogue star declination");
00156
00157 check( sprintf(ref_name, cpl_table_get_string(flux_table, "OBJECT", i)),
00158 "Could not read reference object name");
00159
00160 check( sprintf(ref_type,cpl_table_get_string(flux_table, "TYPE", i)),
00161 "Could not read reference object type");
00162
00163 uves_msg("std: %s \t %s \t %f \t %f",ref_name,ref_type,ref_ra,ref_dec);
00164
00165 sprintf(res_name,"%s.fits",ref_name);
00166 check( ndata = cpl_table_get_int(flux_table, "NDATA", i, NULL),
00167 "Error reading length of flux array");
00168
00169 result=cpl_table_new(ndata);
00170 for(j = 0; j < 3; j++)
00171 {
00172 const cpl_array *data;
00173 int indx;
00174
00175 cpl_table_new_column(result, columns[j], CPL_TYPE_DOUBLE);
00176
00177 data = cpl_table_get_array(flux_table, columns[j], i);
00178
00179
00180
00181 uves_msg_debug("3d table array size = %d, ndata = %d",
00182 cpl_array_get_size(data), ndata);
00183
00184 assure( cpl_array_get_size(data) >= ndata,
00185 CPL_ERROR_ILLEGAL_INPUT,
00186 "Flux table row %d: column '%s' depth (%d) "
00187 "is less than NDATA (%d)",
00188 i, columns[j], cpl_array_get_size(data), ndata);
00189
00190 for (indx = 0; indx < ndata; indx++)
00191 {
00192
00193 cpl_table_set_double(result, columns[j], indx,
00194 cpl_array_get_float(data, indx, NULL));
00195 }
00196 }
00197
00198 cpl_table_save(result, header, NULL,res_name, CPL_IO_DEFAULT);
00199 uves_free_table(&result);
00200 }
00201
00202
00203 cleanup:
00204 uves_free_table(&flux_table);
00205 uves_free_propertylist(&header);
00206
00207 return;
00208 }
00209
00210
00214
00215 static void
00216 test_3dtable(void)
00217 {
00218
00219 cpl_table *flux_table = NULL;
00220 uves_propertylist *raw_header = NULL;
00221 cpl_array *values = NULL;
00222 int depth = 10;
00223 int nrow = 2;
00224 const char *object[] = {"first std", "another standard star"};
00225 const char *type [] = {"NULL", "type 2"};
00226 const double lambda[] = {8000, 2000};
00227 const double fluxes[] = {1000000, 200};
00228 const double bin_width[] = {0.8, 0.0003};
00229 const double ra[] = {10, 80};
00230 const double dec[] = {-8, 0};
00231
00232 cpl_table *cat_flux = NULL;
00233 char *ref_name = NULL;
00234
00235 int i;
00236
00237
00238 flux_table = cpl_table_new(nrow);
00239
00240 cpl_table_new_column(flux_table, "RA_DEG", CPL_TYPE_DOUBLE);
00241 cpl_table_new_column(flux_table, "DEC_DEG", CPL_TYPE_DOUBLE);
00242
00243 cpl_table_new_column(flux_table, "OBJECT", CPL_TYPE_STRING);
00244 cpl_table_new_column(flux_table, "TYPE", CPL_TYPE_STRING);
00245
00246 cpl_table_new_column(flux_table, "NDATA", CPL_TYPE_INT);
00247
00248 cpl_table_new_column_array(flux_table, "LAMBDA", CPL_TYPE_FLOAT, depth);
00249 cpl_table_new_column_array(flux_table, "BIN_WIDTH", CPL_TYPE_FLOAT, depth);
00250 cpl_table_new_column_array(flux_table, "F_LAMBDA", CPL_TYPE_FLOAT, depth);
00251
00252 values = cpl_array_new(depth, CPL_TYPE_FLOAT);
00253
00254 for (i = 0; i < nrow; i++)
00255 {
00256 cpl_table_set_double(flux_table, "RA_DEG", i, ra[i]);
00257 cpl_table_set_double(flux_table, "DEC_DEG", i, dec[i]);
00258 cpl_table_set_string(flux_table, "OBJECT", i, object[i]);
00259 cpl_table_set_string(flux_table, "TYPE", i, type[i]);
00260 cpl_table_set_int (flux_table, "NDATA", i, depth);
00261
00262 cpl_array_fill_window_float(values, 0, depth, lambda[i]);
00263 cpl_table_set_array(flux_table, "LAMBDA", i, values);
00264
00265 cpl_array_fill_window_float(values, 0, depth, bin_width[i]);
00266 cpl_table_set_array(flux_table, "BIN_WIDTH", i, values);
00267
00268 cpl_array_fill_window_float(values, 0, depth, fluxes[i]);
00269 cpl_table_set_array(flux_table, "F_LAMBDA", i, values);
00270 }
00271
00272
00273 raw_header = uves_propertylist_new();
00274
00275
00276
00277 for (i = 0; i < nrow; i++)
00278 {
00279 double paccuracy = 60;
00280 double residual = 30;
00281
00282 uves_pfits_set_ra (raw_header, ra[i]+residual/3600);
00283 uves_pfits_set_dec(raw_header, dec[i]-residual/3600);
00284
00285 uves_free_table(&cat_flux);
00286 cpl_free(ref_name); ref_name = NULL;
00287 check_nomsg( cat_flux = uves_align(raw_header,
00288 flux_table,
00289 paccuracy,
00290 &ref_name));
00291
00292
00293
00294 while(ref_name[strlen(ref_name)-1] == ' ')
00295 {
00296
00297 ref_name[strlen(ref_name)-1] = '\0';
00298 }
00299
00300
00301
00302 assure( cpl_table_get_nrow(cat_flux) == depth, CPL_ERROR_ILLEGAL_OUTPUT,
00303 "Flux table has %d rows, %d expected",
00304 cpl_table_get_nrow(cat_flux), depth);
00305
00306 assure( strcmp(ref_name, object[i]) == 0, CPL_ERROR_ILLEGAL_OUTPUT,
00307 "Found '%s'; Expected '%s'", ref_name, object[i]);
00308
00309 #if 0
00310 assure( float_equal(cpl_table_get_column_mean(cat_flux, "LAMBDA"),
00311 lambda[i], 0.001),
00312 CPL_ERROR_ILLEGAL_OUTPUT,
00313 "LAMBDA = %f; Expected = %f",
00314 cpl_table_get_column_mean(cat_flux, "LAMBDA"), lambda[i]);
00315
00316 assure( float_equal(cpl_table_get_column_mean(cat_flux, "BIN_WIDTH"),
00317 bin_width[i], 0.001),
00318 CPL_ERROR_ILLEGAL_OUTPUT,
00319 "BIN_WIDTH = %f; Expected = %f",
00320 cpl_table_get_column_mean(cat_flux, "BIN_WIDTH"), bin_width[i]);
00321
00322 assure( float_equal(cpl_table_get_column_mean(cat_flux, "F_LAMBDA"),
00323 fluxes[i], 0.001),
00324 CPL_ERROR_ILLEGAL_OUTPUT,
00325 "F_LAMBDA = %f; Expected = %f",
00326 cpl_table_get_column_mean(cat_flux, "F_LAMBDA"), fluxes[i]);
00327 #endif
00328 cpl_test_rel(cpl_table_get_column_mean(cat_flux, "LAMBDA"),
00329 lambda[i], 0.001);
00330
00331 cpl_test_rel(cpl_table_get_column_mean(cat_flux, "BIN_WIDTH"),
00332 bin_width[i], 0.001);
00333
00334 cpl_test_rel(cpl_table_get_column_mean(cat_flux, "F_LAMBDA"),
00335 fluxes[i], 0.001);
00336 }
00337
00338 cleanup:
00339 uves_free_table(&flux_table);
00340 uves_free_table(&cat_flux);
00341 uves_free_array(&values);
00342 uves_free_propertylist(&raw_header);
00343 cpl_free(ref_name);
00344
00345
00346 return;
00347 }
00348
00349
00353
00354
00355 int main(void)
00356 {
00357 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00358
00359 check_nomsg( test_3dtable() );
00360
00361
00362 cleanup:
00363 return cpl_test_end(0);
00364 }
00365