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_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include <string.h>
00037
00038 #include "naco_recipe.h"
00039
00040 #include "naco_spc.h"
00041
00042
00043
00044
00045
00046 #define RECIPE_STRING "naco_util_spc_argon"
00047
00048 #ifndef NACO_SPC_ARGON_SIZE
00049 #define NACO_SPC_ARGON_SIZE 80
00050 #endif
00051
00052
00053
00054
00055
00056 NACO_RECIPE_DEFINE(naco_util_spc_argon, 0,
00057 "Generate FITS table with argon lines",
00058 "The input frame(s) must be tagged "
00059 NACO_SPC_ARGON_ASCII ".\n"
00060 "The file must comprise two columns:"
00061 "the 1st with the line wavelength [Angstrom],\n"
00062 "the 2nd with the line intensity.\n"
00063 "\n"
00064 "The default input ASCII-file is in the catalogs/ "
00065 "directory of the NACO source-code distribution.");
00066
00067 static IRPLIB_UTIL_SET_ROW(naco_util_spc_argon_set_row);
00068 static IRPLIB_UTIL_CHECK(naco_util_spc_argon_check);
00069
00070 static unsigned nzero = 0;
00071
00072
00076
00077
00078
00079
00080
00081
00082
00083
00090
00091 static int naco_util_spc_argon(cpl_frameset * framelist,
00092 const cpl_parameterlist * parlist)
00093 {
00094 irplib_framelist * allframes = NULL;
00095 irplib_framelist * rawframes = NULL;
00096 cpl_frameset * useframes = NULL;
00097 cpl_table * self = NULL;
00098
00099
00100 if (cpl_error_get_code()) return cpl_error_get_code();
00101
00102
00103 skip_if (naco_dfs_set_groups(framelist));
00104
00105
00106
00107
00108 allframes = irplib_framelist_cast(framelist);
00109 bug_if(allframes == NULL);
00110
00111 rawframes = irplib_framelist_extract(allframes, NACO_SPC_ARGON_ASCII);
00112 skip_if (rawframes == NULL);
00113
00114 irplib_framelist_empty(allframes);
00115
00116 useframes = irplib_frameset_cast(rawframes);
00117 bug_if(allframes == NULL);
00118
00119
00120 self = cpl_table_new(irplib_framelist_get_size(rawframes));
00121
00122 irplib_framelist_empty(rawframes);
00123
00124
00125 bug_if (cpl_table_new_column(self, NACO_SPC_LAB_WAVE, CPL_TYPE_DOUBLE));
00126 bug_if (cpl_table_new_column(self, NACO_SPC_LAB_INTENS, CPL_TYPE_DOUBLE));
00127
00128 bug_if(cpl_table_set_column_unit(self, NACO_SPC_LAB_WAVE, "micron"));
00129
00130 skip_if(irplib_dfs_table_convert(self, framelist, useframes,
00131 NACO_SPC_ARGON_SIZE, '#', NULL,
00132 NACO_SPC_ARGON, parlist, RECIPE_STRING,
00133 NULL, NULL, NULL, "NACO", naco_pipe_id,
00134 naco_util_spc_argon_set_row,
00135 naco_util_spc_argon_check));
00136 end_skip;
00137
00138 cpl_table_delete(self);
00139 cpl_frameset_delete(useframes);
00140 irplib_framelist_delete(allframes);
00141 irplib_framelist_delete(rawframes);
00142
00143 return cpl_error_get_code();
00144 }
00145
00146
00158
00159 static
00160 cpl_boolean naco_util_spc_argon_set_row(cpl_table * self,
00161 const char * line,
00162 int irow,
00163 const cpl_frame * rawframe,
00164 const cpl_parameterlist * parlist)
00165 {
00166
00167
00168
00169 #define FORMAT "%lg %lg"
00170
00171 int nvals;
00172 double wlen, intens;
00173
00174
00175 bug_if(0);
00176 bug_if(self == NULL);
00177 bug_if(line == NULL);
00178 bug_if(irow < 0);
00179 bug_if(rawframe == NULL);
00180 bug_if(parlist == NULL);
00181
00182 nvals = sscanf(line, FORMAT, &wlen, &intens);
00183
00184 error_if (nvals != 2, CPL_ERROR_BAD_FILE_FORMAT,
00185 "Line with length=%u has %d not 2 items formatted: %s",
00186 (unsigned)strlen(line), nvals, FORMAT);
00187
00188 error_if (wlen <= 0.0, CPL_ERROR_BAD_FILE_FORMAT,
00189 "Non-positive wavelength %g in line %s", wlen, line);
00190
00191 error_if (intens < 0.0, CPL_ERROR_BAD_FILE_FORMAT,
00192 "Negative intensity %g in line %s", intens, line);
00193
00194 wlen *= 1e-4;
00195
00196 bug_if(cpl_table_set_double(self, NACO_SPC_LAB_WAVE, irow, wlen));
00197 bug_if(cpl_table_set_double(self, NACO_SPC_LAB_INTENS, irow, intens));
00198
00199 if (intens <= 0.0) nzero++;
00200
00201 end_skip;
00202
00203 return CPL_TRUE;
00204
00205 }
00206
00207
00208
00217
00218 static
00219 cpl_error_code naco_util_spc_argon_check(cpl_table * self,
00220 const cpl_frameset * useframes,
00221 const cpl_parameterlist * parlist)
00222 {
00223
00224 cpl_propertylist * reflist = cpl_propertylist_new();
00225
00226
00227 bug_if(0);
00228 bug_if(self == NULL);
00229 bug_if(parlist == NULL);
00230
00231
00232 bug_if(cpl_propertylist_append_bool(reflist, NACO_SPC_LAB_WAVE, 0));
00233
00234 bug_if(cpl_table_sort(self, reflist));
00235
00236 cpl_msg_info(cpl_func, "Created table of %d argon lines (%u with zero "
00237 "intensity) from %d file(s)", cpl_table_get_nrow(self),
00238 nzero, cpl_frameset_get_size(useframes));
00239
00240 end_skip;
00241
00242 cpl_propertylist_delete(reflist);
00243
00244 return cpl_error_get_code();
00245 }
00246