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 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030
00037
00040
00041
00042
00043 #include <xsh_error.h>
00044 #include <xsh_msg.h>
00045 #include <xsh_data_instrument.h>
00046 #include <xsh_pfits.h>
00047 #include <tests.h>
00048 #include <cpl.h>
00049 #include <math.h>
00050 #include <time.h>
00051 #include <sys/time.h>
00052 #include <xsh_cpl_size.h>
00053
00054
00055
00056 #define MODULE_ID "XSH_CORRECT_VACUUM_TO_AIR"
00057
00058
00064
00065 int main( int argc, char** argv)
00066 {
00067 int ret = 0;
00068
00069 cpl_table* table_names = NULL;
00070 cpl_table* table_spect = NULL;
00071 cpl_frame* std_catalog = NULL;
00072 cpl_propertylist* phead = NULL;
00073 cpl_propertylist* xhead = NULL;
00074
00075 xsh_instrument* instrument = NULL;
00076 const char* fname_out = "catalog_new.fits";
00077 const char* fname_inp;
00078
00079 int nb_frames = 0;
00080 int next = 0;
00081 int i = 0;
00082 int nrow = 0;
00083 int j = 0;
00084
00085 double* plambda = NULL;
00086 double* pflux = NULL;
00087 double* pbin = NULL;
00088 double c1 = 1.0002735182;
00089 double c2 = 131.4182;
00090 double c4 = 2.76249E8;
00091 double w = 0;
00092 double w2 = 0;
00093 double w4 = 0;
00094 double wair=0;
00095
00096 double nm2AA=10.;
00097
00098 TESTS_INIT( MODULE_ID);
00099 cpl_msg_set_level(CPL_MSG_DEBUG);
00100 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM);
00101
00102 nb_frames = argc - optind;
00103 if (nb_frames == 1) {
00104 fname_inp = argv[optind];
00105 } else {
00106 xsh_msg( "********** NOT ENOUGH INPUT FRAMES **********" );
00107 exit(0);
00108 }
00109
00110 std_catalog = cpl_frame_new();
00111 cpl_frame_set_filename(std_catalog, fname_inp);
00112 next = cpl_frame_get_nextensions(std_catalog);
00113 phead = cpl_propertylist_load(fname_inp, 0);
00114 table_names = cpl_table_load(fname_inp, 1, 0);
00115 xhead = cpl_propertylist_load(fname_inp, 1);
00116 cpl_table_save(table_names, phead, xhead, fname_out, CPL_IO_DEFAULT);
00117
00118 for (i = 2; i <= next; i++) {
00119
00120 table_spect = cpl_table_load(fname_inp, i, 0);
00121 xhead = cpl_propertylist_load(fname_inp, i);
00122 plambda = cpl_table_get_data_double(table_spect, "LAMBDA");
00123 nrow = cpl_table_get_nrow(table_spect);
00124
00125 if (i == 2 || i == 4) {
00126
00127 for (j = 0; j < nrow; j++) {
00128 w = nm2AA * plambda[j];
00129 w2 = w * w;
00130 w4 = w2*w2;
00131 wair = w / (c1 + c2 / w2 + c4 / w4 );
00132 plambda[j] = wair / nm2AA;
00133
00134 }
00135 }
00136 xsh_msg("save out tab on file %s",fname_out);
00137 check(cpl_table_save(table_spect, xhead, NULL, fname_out, CPL_IO_EXTEND));
00138 xsh_free_propertylist(&xhead);
00139 xsh_free_table(&table_spect);
00140
00141 }
00142
00143
00144 cleanup: xsh_free_table(&table_names);
00145 xsh_free_table(&table_spect);
00146 xsh_free_propertylist(&xhead);
00147 xsh_free_propertylist(&phead);
00148 xsh_free_frame(&std_catalog);
00149
00150 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00151 xsh_error_dump(CPL_MSG_ERROR);
00152 ret = 1;
00153 }
00154 return ret;
00155 }
00156